How can i activate a second joyride tour - javascript

I have a problem with my joyride tour ,When i finsish one tour i want to start a second one .What i try to do is execute a seconde tour in the postRideCallback ,but i end up looping the first tour .Does somebody knows how to fix this?
function preview(){
$('#joyRideTipContent').joyride({
autoStart : true,
preStepCallback : function(index, tip) {
console.log(index);
},
postStepCallback : function(index, tip) {
},
postRideCallback : function(index, tip) {
console.log("stop1");
preview2();
console.log("stop1.1");
},
tipLocation:"left",
modal : true,
expose : true
});
}
function preview2(){
console.log("stop2.0");
$('#joyRideTipContent2').joyride({
preStepCallback : function(index, tip) {
console.log("stop21.0");
},
postStepCallback : function(index, tip) {
console.log("stop22.0");
},
postRideCallback : function(index, tip) {
console.log("stop23");
alert("tada")
},
tipLocation:"left",
modal : true,
expose : true
});
console.log("stop2.1");
}
in my code (see above) preview is the function that i use to start the joyride tour and the console.log's are just for testing and do not hava a specific meaning

I know this is an old question, but I added a check that calls joyride's destroy method to remove the previous tutorial contents before starting another one.
function tutorial1(){
if($('.joyride-tip-content')) {
$.fn.joyride('destroy')
}
$('#joyRideTutorial1').joyride({
modal:true,
autoStart : true,
expose: true
});
}
function tutorial2(){
if($('.joyride-tip-content')) {
$.fn.joyride('destroy')
}
$('#joyRideTutorial2').joyride({
modal:true,
autoStart : true,
expose: true
});
}
Seems to be working well so far.

Where are you starting joyride?
Can you post all your source code?
If you did not do that, try:
function preview(){
$('#joyRideTipContent').joyride({
autoStart : true,
preStepCallback : function(index, tip) {
console.log(index);
},
postStepCallback : function(index, tip) {
},
postRideCallback : function(index, tip) {
console.log("stop1");
preview2();
console.log("stop1.1");
},
tipLocation:"left",
modal : true,
expose : true
}).foundation('joyride', 'start');
}

Why don't you just add a query variable to your pages URL? e.g.
yoursite.com/page?tour=1
yoursite.com/page?tour=2
When you finish tour 1, you can have a link on your last tour popup that links to ...?tour=2.
What you will need to do is check the query variable on your server (assuming this is where your html is generated) and do a simple if/else to output the relevant code in your html page e.g.
if ($tour == 1) {
// add tour 1 markup and script here
}
elseif ($tour == 2){
// add your 2 markup and script here
}
This will mean that the html output will only ever have one tours info. The way you are doing it now is a little messy as the tours are clashing with each other. Using this simple method will ensure that only one tour is ever loaded into your html

Related

Adding auto complete to jstree input node

I am creating a JsTree which has an input box Node. I want to enable auto-complete for this input box. The application is in angular4, but the file i am using for creating the jstree is a .js file.
inst.create_node(obj, {
li_attr : {
'class' : 'child-menu listener-menu'
},
a_attr:{
'ondragover' : 'allowDropSR(event,"widgets")',
'ondrop' : 'dropSR(event,"widgets")'
},
text : "<span>Enter Country here</span>"
},
"last", function(new_node) {
new_node.data = {
file : true,
stopDrilldown : true,
hasParent : true
};
setTimeout(function () {
inst.edit(new_node);
$('.jstree-rename-input').attr();
},0);
});
$('.widget-list-tab a').tab('show');
$('.jstree-clicked').next('ul').find('li:last').find('a').focus();
},
Best approach would have been to write your own jsTree plugin. You can possibly hook the keydown event of jsTree for edit box to populate your list of items as a autocomplete suggestion and using jQuery UI autocomplete feature.
.bind("keydown.jstree", function(e) {
if(e.target.tagName && e.target.tagName.toLowerCase() === "input"
&& e.target.className.toLowerCase() === "jstree-rename-input" ) {
$(".jstree-rename-input").autocomplete({
// AJAX can be used for list here
source: countries
});
}
});
countries: is the list suggestion.
You can see in more details at https://everyething.com/jsTree-with-AutoComplete-Box

jqGrid unable to set filter value in first charge [duplicate]

This question has been as a lot so please forgive me asking again.
I have a grid loaded from a url.
I use loadonce: true
I use filtertoolbar:
$("#status").jqGrid('filterToolbar', { stringResult:true, searchOnEnter:false, autosearch: true, defaultSearch: "cn" });
I have a dropdown search list from which I can select what I'm looking for. Works great.
I have a navbutton I click to initiate a reload every 30 seconds. Works great.
$("#status").jqGrid('navButtonAdd','#statuspager', { caption: '', buttonicon: 'ui-icon-play', onClickButton: function ()
{
stint = setInterval (function() {
postfilt = $("#status").jqGrid('getGridParam', 'postData').filter;
$("#status").jqGrid('setGridParam',{
url: './ar_status.cgi?systemtype=' + systype,
datatype: "json",
postData: postfilt,
search: true,
loadtext: "Refreshing grid...",
loadonce: true,
loadui: "block"
});
$("#status").jqGrid().trigger("reloadGrid");
}, 30000);
},
title: 'Start Auto Refresh (every 30 sec.)'
});
Using google chrome I can see the filters that were specified being posted to the server:
systemtype:production
_search:true
nd:1358887757603
rows:1000
page:1
sidx:system
sord:asc
totalrows:700
filters:{"groupOp":"AND","rules":[{"field":"system","op":"eq","data":"ATTDA02"}]}
I can change the filter between reloads and see the new, even multiple filters:
systemtype:production
_search:true
nd:1358887847592
rows:1000
page:1
sidx:system
sord:asc
totalrows:700
filters:{"groupOp":"AND","rules":[{"field":"system","op":"eq","data":"ATTDA02"},{"field":"dow","op":"cn","data":"MO"}]}
I am using multipleSearch: true on the initial load. I'm pretty sure that's retained on reload
On the grid, the filtertoolbar retains my filter criteria, both text and selects, but when the grid reloads, the filters are ignored and the entire dataset is diplayed in the grid.
I've tried many examples posted here on SO. I've tried adding [{current:true}] to the reloadGrid call - no difference. I can't seem to retain and apply the filters on a reload.
I would like the reload to always return the full dataset from the server (which happens fine), and allow the current filter settings to control what is shown after the reload. I do not want to use the postdata to build a new SQL select statement - server side filtering, because at any time the user may want to click the pause button, select a new filter and view something else from the entire dataset without another reload.
$("#status").jqGrid('navButtonAdd','#statuspager', { caption: '', buttonicon: 'ui-icon-pause', onClickButton: function ()
{
clearInterval(stint);
},
title: 'End Auto Refresh'
});
How can this be done without using cookies, as I saw in one post?
I could try using jqGridExport'ing the postfilt var, and then jqGridImport'ing it but was hoping for a more direct approach. I'm not even sure this would help since I already have everything I need right here in the grid via postData.
As a side note, in my setGridParam above, the loadtext I specify is never displayed. Instead, the default "Loading..." is displayed. All of the other parameters are working.
Many thanks in advance,
Mike
Solution. The complete loadComplete to retain filters, sort index and sort order after a [json] reload from the server:
loadComplete: function() {
var $this = $(this);
postfilt = $this.jqGrid('getGridParam','postData').filters;
postsord = $this.jqGrid('getGridParam','postData').sord;
postsort = $this.jqGrid('getGridParam','postData').sidx;
if ($this.jqGrid("getGridParam", "datatype") === "json") {
setTimeout(function () {
$this.jqGrid("setGridParam", {
datatype: "local",
postData: {filters: postfilt, sord: postsord, sidx: postsort},
search: true
});
$this.trigger("reloadGrid");
}, 50);
}
}
Thanks very much!!!!
I only added a bit to your solution to retain the page number as well:
loadComplete: function () {
var $this = $(this);
var postfilt = $this.jqGrid('getGridParam', 'postData').filters;
var postsord = $this.jqGrid('getGridParam', 'postData').sord;
var postsort = $this.jqGrid('getGridParam', 'postData').sidx;
var postpage = $this.jqGrid('getGridParam', 'postData').page;
if ($this.jqGrid("getGridParam", "datatype") === "json") {
setTimeout(function () {
$this.jqGrid("setGridParam", {
datatype: "local",
postData: { filters: postfilt, sord: postsord, sidx: postsort },
search: true
});
$this.trigger("reloadGrid", [{ page: postpage}]);
}, 25);
}
}
I am not sure, but I suppose that the origin of your first problem could be mixing postData.filters and postData and usage filter property instead of filters``. You use
postfilt = $("#status").jqGrid('getGridParam', 'postData').filter;
to get filter property instead of filters. You get undefined value. So the setting postData to postfilt means nothing.
The next problem is that the server response contains non-filtered data. To force filtering the data locally you have to reload the grid once after the loading from the server have finished. You can do this inside of loadComplete. Exactly here you can set postData.filter if required, set search: true and trigger reloadGrid event. It's important only to do this once to have no recursion and you must don't set datatype back to "json" in the case. The datatype will be changed to "local" and the end of loading from the server in case of usage loadonce: true option. If you want apply filtering locally you have to reload grid once with options datatype: "local", search: true and postData having filters specifying the filter which need by applied. See the code from the answer or another one which do another things, but the code which you need will be very close.

Allow infinitescroll.js to run X times, then load more posts

I'm using the infinitescroll.js script and it works really well. I've found out how to replace the default functionality with a load more button, using this code:
$(window).unbind('.infscr');
$('.js-next-reports').click(function() {
$grid.infinitescroll('retrieve');
return false;
});
$(document).ajaxError(function(e, xhr, opt) {
if (xhr.status == 404) $('.js-next-reports').remove();
});
However, what I'd like to do is allow infinite scroll to run 3/4 times and then show the .js-next-reports button. I'm not sure how to keep track of how many times infinite scroll has run though. I know there is a currPage var but using console.log I can't work out how I can reference it.
There is also a maxPage option for infinitescroll, which limits it to run only X times, so I could maybe tap into that somehow? I'm not sure how to get a console.log of the options though. Here is my init code if that helps ($grid is just a ref to a div)
$grid.infinitescroll({
// selector for the paged navigation (it will be hidden)
navSelector : ".pagination",
// selector for the NEXT link (to page 2)
nextSelector : ".pagination .next",
// selector for all items you'll retrieve
itemSelector : ".infinite-scroll-post",
contentSelector : "#infinite-scrollable",
debug: true,
// finished message
loading: {
img: "ajax-loader.gif",
msgText: "Loading more projects...",
finishedMsg: 'No more pages to load.',
}
},
});
Maybe something like: ?
if ( .currPage == "3" ) {
$(window).unbind('.infscr');
$('.js-next-reports').click(function() {
$grid.infinitescroll('retrieve');
return false;
});
$(document).ajaxError(function(e, xhr, opt) {
if (xhr.status == 404) $('.js-next-reports').remove();
});
}
But I don't know how to either count the scrolls or access currPage.
Thanks
A JSFiddle would help testing the code, but from what I've read on their documentation, there's a callback that allows you to access currPage inside the state object. Your code should look something like this:
$grid.infinitescroll({
// selector for the paged navigation (it will be hidden)
navSelector : ".pagination",
// selector for the NEXT link (to page 2)
nextSelector : ".pagination .next",
// selector for all items you'll retrieve
itemSelector : ".infinite-scroll-post",
contentSelector : "#infinite-scrollable",
debug: true,
// finished message
loading: {
img: "ajax-loader.gif",
msgText: "Loading more projects...",
finishedMsg: 'No more pages to load.',
},
appendCallback: false
}, function(newitems, opts) {
if(opts.state.currPage == 3) {
$(window).unbind('.infscr');
}
}
});

Putting 'document' vs 'the selector itself' in jQuery?

Guys I have 2 questions which is i think related in some ways I guess. First:
What is the difference between these two:
$(document).on('click','#someselector', function() {
//do something
});
vs this
$('#selector')on('click', function(){
/do something
});
Sometimes both works, sometimes it doesn't.
Number 2 question:
I created a jQuery UI dialog like this:
function this_dialog(id) {
$("#div-id-for-the-dialog").dialog({
autoOpen : false,
modal : true,
draggable : false,
width : 400,
buttons : [{
id : id,
text : 'Ok'
},{
text : 'Cancel',
click : function () {
$("#div-id-for-the-dialog").dialog('close');
}
}]
});
}
So as you can see, the id is passed to the function, many will call this dialog and pass a unique id to it. The id will then be assigned only to the Ok button.
So when i call this function to load a unique dialog:
add_section_complete_reopen_dialog('my-unique-dialog-id'); //passing the id
$('#div-id-for-the-dialog').html("I have a unique dialog now? ok?");
When i press ok with this code:
$(document).on('click','#my-unique-dialog-id', function () {
//Do some ajax call here
});
I get this JS error: TypeError: s is undefined
But the ajax is successful. I just want to know what that error is.
So when I say it is related to the first question is because when i replace the click code with this:
$('#my-unique-dialog-id').on('click', function () {
//Do some ajax call here
});
It doesn't work anymore.
Thanks
$(document).on('click', 'someselector', function() ...);
is delegation syntax. It allows you to bind a handler to elements that may not exist at the time that you execute the code. See:
Event binding on dynamically created elements?
$('someselector').on('click', function() ...);
only binds the handler to the element(s) matching the selector at the time you execute this code.
I marked the first answer correct because I know I did not put enough info on how to debug the second question, but In case someone might encounter the same error i had, I found out why. So when you initialize your jQuery UI dialog like this:
function this_dialog(id) {
$("#div-id-for-the-dialog").dialog({
autoOpen : false,
modal : true,
draggable : false,
width : 400,
buttons : [{
id : id,
text : 'Ok'
},{
text : 'Cancel',
click : function () {
$("#div-id-for-the-dialog").dialog('close');
}
}]
});
}
Make sure to include the click event of the buttons like this:
function this_dialog(id) {
$("#div-id-for-the-dialog").dialog({
autoOpen : false,
modal : true,
draggable : false,
width : 400,
buttons : [{
id : id,
text : 'Ok',
click : function () {
//include the click event, even if you have nothing to put here.
}
},{
text : 'Cancel',
click : function () {
$("#div-id-for-the-dialog").dialog('close');
}
}]
});
}

link is not working in IE8

i am using the jquery for developing my system.
for particular functionality i am sending link through json data to have link for each row
of jqgrid table.
as
"<a href='#' class='ui-icon ui-icon-pencil' onclick='EditClick(\"" + {MYPRIMARY KEY}+ "\");return false;'>Edit</a>"
in javasript i have function as
function EditClick(param)
{
$('#mainDiv').load('/contoller/action/' + param, function() {
});
return false;
}
here action returns the view().
in this EditClick function i am loading another page in my main div.
This runs on IE7,firefox smoothly,but using it on IE8 sometimes its works sometimes not.
i mean sometime required page loads in main div sometimes not.
i realy dont understand the problem.
please guide me through this.
thank you.
I had a few problems working with jgGrid events a row.
What I did was to add a custom button:
jQuery("myGrid").navGrid('#myPager', { edit: false, add: false, del: false, search: false }, {}, {}, {})
.navButtonAdd('#myPager', { caption: "Do something", buttonicon: "ui-icon-note",
onClickButton: function() { var rowid = jQuery("myGrid").jqGrid('getGridParam', 'selrow');
if ((rowid == null) || (rowid == 0)) {
alert("Select a row before!"); }
else {
EditClick(rowid);
}
}, position: "last" })
As you can see the function EditClick is triggered only if you've selected one row in the grid. rowid should be your primary key.
Hope it helps.

Categories