├── README.md ├── example ├── article.html ├── css │ ├── .DS_Store │ └── custom.css ├── index.html ├── js │ ├── .DS_Store │ ├── example.js │ ├── modernizr.js │ └── navigate.js └── list.html ├── navigate.js └── navigate.min.js /README.md: -------------------------------------------------------------------------------- 1 | ## Overview 2 | 3 | jQuery Navigate is a jQuery plugin which goal is to transform any website into a single-page website. It transforms links into turbolinks, it is transparent for the backend and is SEO complient. 4 | 5 | The plugin itself is divided into two submodules : 6 | 7 | * the refresh plugin : basically the ajax engine 8 | * the navigate plugin : add the html5 history navigation and transform links into turbolinks. 9 | 10 | ## refresh plugin 11 | 12 | The goal of refresh plugin is to simply refresh through an automatic ajax call any element of the page. 13 | 14 | ### News 15 | 16 | The website Interflora mobile using a previous version of jquery-navigate recieved the 2012 Google prize for mobile website in the distribution sector mainly for the speed of the website. 17 | 18 | ### Attributes 19 | 20 | Here are all the optional attribute an element that will call the refresh() method can have : 21 | 22 | ```html 23 |
24 | ``` 25 | 26 | * `refresh-url` : the url to get the refresh content from (by default : current url) 27 | * `refresh-id` : if both remote and local refresh-id exists and are the same trigger the `cancelrefresh` event 28 | * `insert-function` : the function that will insert the new content and trigger `finishrefreshinsert` event when ready 29 | * `refresh-status` : if different from current div `refresh-status` will trigger the `refreshstatuschanged` event 30 | * `refresh-interval` : if set, there will be an automatic refresh called each `refresh-interval` millisecond. 31 | 32 | ### refresh function 33 | 34 | All the parameters are optional. 35 | 36 | ```javascript 37 | $("#my-id").refresh({ 38 | refresh : true, 39 | resetInterval : true, 40 | url : null, 41 | insertFunction:'html', //or any function / inline function, remember to trigger "finishrefreshinsert" event 42 | content:targetSelector, 43 | clickedSelector:null, 44 | callback:function(){}, 45 | html : null, /* simulate direct html response without any ajax call */ 46 | }); 47 | ``` 48 | 49 | * 1 - $("#my-id") trigger the event `startrefresh` 50 | * 2 - if the parameter `refresh` is true : if the parameter `html` != null skip this step as we have the response already otherwise make the ajax call to the parameter `url` or the attribute `refresh-url` or the current url 51 | * 3 - if fail the ajax call or element not accessible in specified url, $("#my-id") trigger the event `failrefresh` 52 | * 4 - if the attribute `refresh-status` of the element is currently defined and has changed or disapeared trigger the event `refreshstatuschanged` 53 | * 5 if the attribute `refresh-interval` is set and the parameter resetInterval is true and there is a current refresh intervel : stop the current interval 54 | * if the attribute `refresh-interval` is set : set it. 55 | * trigger the event `donerefresh` 56 | 57 | ### stopRefresh function 58 | 59 | * clear the interval refresh of the element 60 | * trigger the event `stoprefresh` 61 | 62 | ## Automatic ajax jquery navigation, mobile friendly 63 | 64 | Navigate depends on refresh,thus we included it in the file. 65 | The goal of the jQuery plugin Navigate is to 66 | 67 | * Automatically transform regular links into ajax calls (using href, ajax-target, title and ajax-content attribute) 68 | * For mobile browsers, avoid showing address bar on link clicks, smoothing the user experience 69 | * Listen to the `startrefresh`, `donerefresh`, and `stoprefresh` events to make cool transitions between states 70 | * Manage atomatically the History throwing events logically (old state target throw `stoprefresh`, new state target throw `startrefresh` and then `donerefresh`). 71 | 72 | ### BASIC 73 | simply include your 74 | 75 | ```html 76 | 77 | ``` 78 | 79 | after the include to jquery (1.7+) and add the code : 80 | ```javascript 81 | $(document).ready(function() { 82 | $.navigate.init(); 83 | }); 84 | ``` 85 | 86 | and the plugin will ajax-navigate automaticaly in your website. 87 | 88 | ### customization 89 | 90 | There are various possibility of optional customization : 91 | 92 | #### in the links : 93 | ```html 94 | link 95 | ``` 96 | 97 | * href : url to be used by the ajax call 98 | * title : the future document title 99 | * ajax-content : (optional) only the content of specified element in href's page will be inserted otherwise all body content 100 | * ajax-target : (optional) the content will be inserted into the target element of the current page 101 | * insert-function : (optional) the function that insert the ajax gotten content 102 | 103 | #### or during the initialization : 104 | 105 | just go to the last lines of the plugin, and modify the $.navigate.init() call as described there, you can change the 106 | 107 | * the default function that replace the old content from the new ajax-gotten content. 108 | 109 | ```javascript 110 | //how to create a custom function : 111 | (function($) { 112 | $.fn.insertPageHtml = function(options) { 113 | //the option is an array : {html:the ajax html, scripts: the scripts that already are in the html, customData:any data you associated to this state during navigate} 114 | //switch elements 115 | $('#my-content').html($("#my-content", options.html).html()); 116 | $(this).trigger({type:"finishrefreshinsert"}); 117 | }; 118 | })(jQuery); 119 | 120 | //and then in your init function you do : 121 | $(document).ready(function() { 122 | $.navigate.init({ 123 | defaultInsertFunction:'insertPageHtml' 124 | }); 125 | }); 126 | ``` 127 | 128 | ``` 129 | be aware that if you select a subpart of the html : $("#my-content", options.html) 130 | that remove the inline scripts of the given html, that is why I added the second element 131 | in the parameters : options.scripts which are thos scripts if needed. 132 | ``` 133 | 134 | * selector for the links to have an ajax behaviour : 135 | 136 | ```javascript 137 | //by default ajax links are : 'a:not(.noAjax)[rel!="external"][target!="_blank"], .ajaxLink' 138 | //you can change it example : 139 | $(document).ready(function() { 140 | $.navigate.init({ 141 | ajaxLinks:'a.ajax' 142 | }); 143 | }); 144 | ``` 145 | 146 | * selector for the links to have a discrete link behaviour (no url bar shown) : 147 | 148 | ```javascript 149 | //by default discreteLinks are : 'a:not(.noAjax)[rel!="external"][target!="_blank"], .ajaxLink' 150 | //you can change it example : 151 | $(document).ready(function() { 152 | $.navigate.init({ 153 | discreteLinks:'a' 154 | }); 155 | }); 156 | ``` 157 | 158 | ### Scripts and ajax navigation 159 | 160 | * basically, you will insert all you js in the head of the page 161 | * You can add anyway any inline script you want thay will be inserted 162 | * However, if you want to have scripts using jquery inside your page do the following : 163 | 164 | ```html 165 | 174 | ``` 175 | ### Add any js object to each state you can take back during your refreshInsertFunction 176 | 177 | 178 | ```javascript 179 | var originalNavigateMethod = $.fn.navigate; 180 | $.fn.navigate = function(options) { 181 | if(!options) options = {}; 182 | options.customData = Math.random(); // = your object stored for this state you have back in you insertFunction 183 | originalNavigateMethod.call($(this),options); 184 | return false; 185 | }; 186 | ``` 187 | 188 | ### Add correct google analytics stats 189 | 190 | ```javascript 191 | $.navigate.currentReferrer = null; 192 | $.navigate.currentPage = document.location.pathname; 193 | $("html").on("donerefresh", 'body',function(e) { 194 | if(_gaq) { 195 | if($.navigate.currentReferrer==null) $.navigate.currentReferrer = document.referrer; 196 | else $.navigate.currentReferrer = ''+$.navigate.currentPage; 197 | $.navigate.currentPage = ''+document.location.pathname; 198 | _gaq.push(['_setReferrerOverride',$.navigate.currentReferrer]); 199 | _gaq.push(['_trackPageview', $.navigate.currentPage]); 200 | } 201 | }); 202 | ``` 203 | 204 | ## HAVE REQUESTS, ISSUES, FEEDBACK ? 205 | don't hesitate : bastien [[at]] binarymind [[dot]] org or submit issue in github 206 | ## CREDITS 207 | Use of Modernizr and Balupton History.js (https://github.com/balupton/History.js) 208 | -------------------------------------------------------------------------------- /example/article.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Home 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 |
27 | 32 |
33 |
34 |
35 |

An Article

36 |

37 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non 38 |

39 |

40 | tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna 41 |

42 |

43 | consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum so 44 |

45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /example/css/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binarymind/jquery-navigate/0cc549344c52fa15d375e78cf2f9cff379c37bfd/example/css/.DS_Store -------------------------------------------------------------------------------- /example/css/custom.css: -------------------------------------------------------------------------------- 1 | /* body loading animation */ 2 | html { -webkit-font-smoothing: antialiased; } 3 | @keyframes bodyLoading { 4 | 0% {transform:scale(1.5,1.5);opacity:0;} 5 | 100% {transform:scale(1,1);opacity:1;} 6 | } 7 | @-webkit-keyframes bodyLoading { 8 | 0% {-webkit-transform:scale3d(1.5,1.5,1.5);opacity:0;} 9 | 100% {-webkit-transform:scale3d(1,1,1);opacity:1;} 10 | } 11 | @-moz-keyframes bodyLoading { 12 | 0% {-moz-transform:scale3d(1.5,1.5,1.5);opacity:0;} 13 | 100% {-moz-transform:scale3d(1,1,1);opacity:1;} 14 | } 15 | @-ms-keyframes bodyLoading { 16 | 0% {-ms-transform:scale(1.5,1.5);opacity:0;} 17 | 100% {-ms-transform:scale(1,1);opacity:1;} 18 | } 19 | body {-webkit-animation:bodyLoading 0.4s ease-in-out forwards;-moz-animation:bodyLoading 0.4s ease-out 0s 1 alternate forwards;} 20 | 21 | .header {height:40px;} 22 | 23 | /* HEADER */ 24 | #logo {position:absolute;left:4px;top:4px;background:url("http://www.jquery-css.com/i/logo.gif") no-repeat scroll left center transparent;width:31px;height:31px;display:block} 25 | #headerContent {padding:10px 5px 5px 50px;text-align:left;} 26 | 27 | /* MAIN NAVIGATION BAR */ 28 | #mainNav ul {background:#F4F4F4;border-style:solid;border-width:1px 0;border-color:white white #CCC white;padding:8px 0} 29 | 30 | /* PAGE CONTENT */ 31 | .article {padding:10px;text-align:left;background:white;box-shadow:-10px 0 10px #CCC} 32 | 33 | -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Home 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 |
27 | 34 |
35 |
36 |

Welcome to the navigate example

37 | 79 |
80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /example/js/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binarymind/jquery-navigate/0cc549344c52fa15d375e78cf2f9cff379c37bfd/example/js/.DS_Store -------------------------------------------------------------------------------- /example/js/example.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function() { 2 | //**** OPTIONAL **** 3 | // Example of a custom ajax insert function 4 | (function($) { 5 | $.fn.fadeInsert = function(options) { 6 | console.log(options); 7 | //the option is an array : {html:the ajax html, scripts: the scripts that already are in the html, customData:any data you associated to this state during navigate} 8 | var that = $(this); 9 | that.fadeOut(300, function(){ 10 | that.html(options.html); 11 | that.fadeIn(300, function(){ 12 | that.trigger({type:"finishrefreshinsert"}); 13 | }); 14 | }); 15 | return this; 16 | }; 17 | })(jQuery); 18 | 19 | //show you the events of navigate 20 | $("html") 21 | .on('donerefresh', "body", function(){ 22 | $("#info").html(document.location.href+" loaded"); 23 | }) 24 | .on('startrefresh', "body", function(){ 25 | $("#info").html('loading....'); 26 | }) 27 | .on('failrefresh', "body", function(){ 28 | $("#info").html('Error loading....'); 29 | }); 30 | //**** /OPTIONAL **** 31 | 32 | //THIS IS THE ONLY NEEDED LINE 33 | //Just init navigate and any link without target="_blank" will become an ajax link 34 | $.navigate.init(); 35 | }); -------------------------------------------------------------------------------- /example/js/modernizr.js: -------------------------------------------------------------------------------- 1 | /* Modernizr 2.6.2 (Custom Build) | MIT & BSD 2 | * Build: http://modernizr.com/download/#-backgroundsize-boxshadow-cssanimations-cssgradients-csstransforms3d-csstransitions-draganddrop-history-input-inputtypes-geolocation-touch-shiv-cssclasses-teststyles-testprop-testallprops-hasevent-prefixes-domprefixes-forms_placeholder-load 3 | */ 4 | ;window.Modernizr=function(a,b,c){function B(a){j.cssText=a}function C(a,b){return B(n.join(a+";")+(b||""))}function D(a,b){return typeof a===b}function E(a,b){return!!~(""+a).indexOf(b)}function F(a,b){for(var d in a){var e=a[d];if(!E(e,"-")&&j[e]!==c)return b=="pfx"?e:!0}return!1}function G(a,b,d){for(var e in a){var f=b[a[e]];if(f!==c)return d===!1?a[e]:D(f,"function")?f.bind(d||b):f}return!1}function H(a,b,c){var d=a.charAt(0).toUpperCase()+a.slice(1),e=(a+" "+p.join(d+" ")+d).split(" ");return D(b,"string")||D(b,"undefined")?F(e,b):(e=(a+" "+q.join(d+" ")+d).split(" "),G(e,b,c))}function I(){e.input=function(c){for(var d=0,e=c.length;d',a,""].join(""),l.id=h,(m?l:n).innerHTML+=f,n.appendChild(l),m||(n.style.background="",n.style.overflow="hidden",k=g.style.overflow,g.style.overflow="hidden",g.appendChild(n)),i=c(l,a),m?l.parentNode.removeChild(l):(n.parentNode.removeChild(n),g.style.overflow=k),!!i},y=function(){function d(d,e){e=e||b.createElement(a[d]||"div"),d="on"+d;var f=d in e;return f||(e.setAttribute||(e=b.createElement("div")),e.setAttribute&&e.removeAttribute&&(e.setAttribute(d,""),f=D(e[d],"function"),D(e[d],"undefined")||(e[d]=c),e.removeAttribute(d))),e=null,f}var a={select:"input",change:"input",submit:"form",reset:"form",error:"img",load:"img",abort:"img"};return d}(),z={}.hasOwnProperty,A;!D(z,"undefined")&&!D(z.call,"undefined")?A=function(a,b){return z.call(a,b)}:A=function(a,b){return b in a&&D(a.constructor.prototype[b],"undefined")},Function.prototype.bind||(Function.prototype.bind=function(b){var c=this;if(typeof c!="function")throw new TypeError;var d=v.call(arguments,1),e=function(){if(this instanceof e){var a=function(){};a.prototype=c.prototype;var f=new a,g=c.apply(f,d.concat(v.call(arguments)));return Object(g)===g?g:f}return c.apply(b,d.concat(v.call(arguments)))};return e}),r.touch=function(){var c;return"ontouchstart"in a||a.DocumentTouch&&b instanceof DocumentTouch?c=!0:x(["@media (",n.join("touch-enabled),("),h,")","{#modernizr{top:9px;position:absolute}}"].join(""),function(a){c=a.offsetTop===9}),c},r.geolocation=function(){return"geolocation"in navigator},r.history=function(){return!!a.history&&!!history.pushState},r.draganddrop=function(){var a=b.createElement("div");return"draggable"in a||"ondragstart"in a&&"ondrop"in a},r.backgroundsize=function(){return H("backgroundSize")},r.boxshadow=function(){return H("boxShadow")},r.cssanimations=function(){return H("animationName")},r.cssgradients=function(){var a="background-image:",b="gradient(linear,left top,right bottom,from(#9f9),to(white));",c="linear-gradient(left top,#9f9, white);";return B((a+"-webkit- ".split(" ").join(b+a)+n.join(c+a)).slice(0,-a.length)),E(j.backgroundImage,"gradient")},r.csstransforms3d=function(){var a=!!H("perspective");return a&&"webkitPerspective"in g.style&&x("@media (transform-3d),(-webkit-transform-3d){#modernizr{left:9px;position:absolute;height:3px;}}",function(b,c){a=b.offsetLeft===9&&b.offsetHeight===3}),a},r.csstransitions=function(){return H("transition")};for(var J in r)A(r,J)&&(w=J.toLowerCase(),e[w]=r[J](),u.push((e[w]?"":"no-")+w));return e.input||I(),e.addTest=function(a,b){if(typeof a=="object")for(var d in a)A(a,d)&&e.addTest(d,a[d]);else{a=a.toLowerCase();if(e[a]!==c)return e;b=typeof b=="function"?b():b,typeof f!="undefined"&&f&&(g.className+=" "+(b?"":"no-")+a),e[a]=b}return e},B(""),i=k=null,function(a,b){function k(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function l(){var a=r.elements;return typeof a=="string"?a.split(" "):a}function m(a){var b=i[a[g]];return b||(b={},h++,a[g]=h,i[h]=b),b}function n(a,c,f){c||(c=b);if(j)return c.createElement(a);f||(f=m(c));var g;return f.cache[a]?g=f.cache[a].cloneNode():e.test(a)?g=(f.cache[a]=f.createElem(a)).cloneNode():g=f.createElem(a),g.canHaveChildren&&!d.test(a)?f.frag.appendChild(g):g}function o(a,c){a||(a=b);if(j)return a.createDocumentFragment();c=c||m(a);var d=c.frag.cloneNode(),e=0,f=l(),g=f.length;for(;e",f="hidden"in a,j=a.childNodes.length==1||function(){b.createElement("a");var a=b.createDocumentFragment();return typeof a.cloneNode=="undefined"||typeof a.createDocumentFragment=="undefined"||typeof a.createElement=="undefined"}()}catch(c){f=!0,j=!0}})();var r={elements:c.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video",shivCSS:c.shivCSS!==!1,supportsUnknownElements:j,shivMethods:c.shivMethods!==!1,type:"default",shivDocument:q,createElement:n,createDocumentFragment:o};a.html5=r,q(b)}(this,b),e._version=d,e._prefixes=n,e._domPrefixes=q,e._cssomPrefixes=p,e.hasEvent=y,e.testProp=function(a){return F([a])},e.testAllProps=H,e.testStyles=x,g.className=g.className.replace(/(^|\s)no-js(\s|$)/,"$1$2")+(f?" js "+u.join(" "):""),e}(this,this.document),function(a,b,c){function d(a){return"[object Function]"==o.call(a)}function e(a){return"string"==typeof a}function f(){}function g(a){return!a||"loaded"==a||"complete"==a||"uninitialized"==a}function h(){var a=p.shift();q=1,a?a.t?m(function(){("c"==a.t?B.injectCss:B.injectJs)(a.s,0,a.a,a.x,a.e,1)},0):(a(),h()):q=0}function i(a,c,d,e,f,i,j){function k(b){if(!o&&g(l.readyState)&&(u.r=o=1,!q&&h(),l.onload=l.onreadystatechange=null,b)){"img"!=a&&m(function(){t.removeChild(l)},50);for(var d in y[c])y[c].hasOwnProperty(d)&&y[c][d].onload()}}var j=j||B.errorTimeout,l=b.createElement(a),o=0,r=0,u={t:d,s:c,e:f,a:i,x:j};1===y[c]&&(r=1,y[c]=[]),"object"==a?l.data=c:(l.src=c,l.type=a),l.width=l.height="0",l.onerror=l.onload=l.onreadystatechange=function(){k.call(this,r)},p.splice(e,0,u),"img"!=a&&(r||2===y[c]?(t.insertBefore(l,s?null:n),m(k,j)):y[c].push(l))}function j(a,b,c,d,f){return q=0,b=b||"j",e(a)?i("c"==b?v:u,a,b,this.i++,c,d,f):(p.splice(this.i++,0,a),1==p.length&&h()),this}function k(){var a=B;return a.loader={load:j,i:0},a}var l=b.documentElement,m=a.setTimeout,n=b.getElementsByTagName("script")[0],o={}.toString,p=[],q=0,r="MozAppearance"in l.style,s=r&&!!b.createRange().compareNode,t=s?l:n.parentNode,l=a.opera&&"[object Opera]"==o.call(a.opera),l=!!b.attachEvent&&!l,u=r?"object":l?"script":"img",v=l?"script":u,w=Array.isArray||function(a){return"[object Array]"==o.call(a)},x=[],y={},z={timeout:function(a,b){return b.length&&(a.timeout=b[0]),a}},A,B;B=function(a){function b(a){var a=a.split("!"),b=x.length,c=a.pop(),d=a.length,c={url:c,origUrl:c,prefixes:a},e,f,g;for(f=0;f/; 99 | var check=data.match(re); 100 | if(check && check.length>0) { 101 | check=check[0].replace(/^$/, 'div>'); 103 | } else check=data; 104 | 105 | //GET THE HEAD 106 | var re = //; 107 | var headHtml=data.match(re); 108 | if(headHtml && headHtml.length>0) { 109 | headHtml=headHtml[0].replace(/^$/, 'div>'); 111 | headHtml = $(headHtml).html() 112 | } else headHtml=""; 113 | //Remove the scripts tags 114 | //------------------------------------------------------------------------- 115 | check = check.replace(new RegExp('', 'g'),'div>'); 117 | 118 | //get the wanted content 119 | //------------------------------------------------------------------------- 120 | if(options.content != 'body') { 121 | var element=$(options.content, '
'+check+'
');//check).find(State.data.content); 122 | } else { 123 | var element=$(check); 124 | } 125 | 126 | var newRefreshId = element.attr("refresh-id"); 127 | 128 | if(myRefreshId && newRefreshId && myRefreshId==newRefreshId) { 129 | target.trigger({type:"cancelrefresh", clickedSelector:options.clickedSelector}); 130 | return; 131 | } 132 | var myHtml = ''; 133 | 134 | //add again the inline scripts to the wanted html 135 | //------------------------------------------------------------------------- 136 | var myScripts = element.find(".temp-script").remove(); 137 | element.each(function() {myHtml+=$(this).html();}); 138 | myScriptsHtml = ''; 139 | myScripts.each(function(){ 140 | myScriptsHtml +=''; 141 | }); 142 | myHtml += myScriptsHtml; 143 | if(!myHtml) { 144 | target.trigger({type:"failrefresh", clickedSelector:options.clickedSelector}); 145 | return; 146 | } 147 | 148 | //GET THE REFRESH INSERT METHOD 149 | var insertFunction = target.attr('refresh-insert-function'); 150 | if(!insertFunction) insertFunction=options.refreshInsertFunction;//"html"; 151 | 152 | //SWITCH CONTENT 153 | target.off("finishrefreshinsert").one("finishrefreshinsert", function() { 154 | //check status 155 | var newRefreshStatus = element.attr("refresh-status"); 156 | var currentStatus = target.attr("refresh-status"); 157 | if(newRefreshStatus && currentStatus != newRefreshStatus) { 158 | target.trigger({ 159 | type:"refreshstatuschanged", 160 | clickedSelector:options.clickedSelector, 161 | oldStatus:currentStatus, 162 | newStatus:newRefreshStatus 163 | }); 164 | //target.trigger("refreshstatuschanged", options.clickedSelector); 165 | } 166 | 167 | target.trigger({type:"donerefresh", clickedSelector:options.clickedSelector}); 168 | options.callback({ 169 | clickedSelector:options.clickedSelector 170 | }); 171 | }); 172 | if(target[insertFunction]) { 173 | //manage standard jQuery insertion functions 174 | 175 | if(insertFunction=="append" ||insertFunction=="prepend"||insertFunction=="html") { 176 | target[insertFunction](myHtml); 177 | target.trigger({type:"finishrefreshinsert"}); 178 | } else if(insertFunction == "appendTo" || insertFunction=="prependTo") { 179 | $('
'+myHtml+'
').children().each(function(){ 180 | $(this)[insertFunction](target); 181 | }); 182 | target.trigger({type:"finishrefreshinsert"}); 183 | } else { 184 | target[insertFunction]({html:myHtml, head:headHtml, scripts:myScriptsHtml, customData:options.customData}); 185 | } 186 | } 187 | else if(window[insertFunction]) { 188 | window[insertFunction]({html:myHtml, head:headHtml, scripts:myScripts, customData:options.customData}); 189 | } 190 | }; 191 | 192 | if(!options.html) 193 | currentCall= $.ajax({ 194 | type: "GET", 195 | cache:options.cache, 196 | context:target, 197 | url: targetUrl, 198 | timeout:8000, 199 | dataType: "html"}) 200 | .done(myDoneFunc) 201 | .fail(function(){ 202 | currentCall.abort(); 203 | currentCall=null; 204 | $(this).trigger({type:"failrefresh", clickedSelector:options.clickedSelector}); 205 | }); 206 | else myDoneFunc(options.html); 207 | } else { 208 | target.trigger({type:"donerefresh", clickedSelector:options.clickedSelector}); 209 | } 210 | 211 | //CLEAN CURRENT TIMER IF MANUAL FORCE REFRESH 212 | //---------------------------------------------------------------------- 213 | var refreshTimer = $.refresh.refreshTimers[targetSelector]; 214 | if(options.resetInterval && refreshTimer) { 215 | //if we force the refresh and a timer exists, we clear the current timer 216 | clearInterval(refreshTimer); 217 | delete refreshTimer; 218 | } 219 | 220 | //CHECK IF WE SET A REFRESH INTERVAL TIMER 221 | //---------------------------------------------------------------------- 222 | var refreshTimerTime = target.attr('refresh-interval'); 223 | if(!refreshTimerTime) return; 224 | refreshTimerTime = parseInt(refreshTimerTime); 225 | if(options.resetInterval && refreshTimerTime>0) { 226 | 227 | //set timer refresh for this target 228 | $.refresh.refreshTimers[targetSelector] = setInterval(function(){ 229 | target.refresh({refresh:true, resetInterval : false}); 230 | },refreshTimerTime); 231 | } 232 | 233 | }; 234 | })(jQuery); 235 | 236 | // ------------------------------------------------------------------- 237 | // NAVIGATE 238 | // ------------------------------------------------------------------- 239 | // by default, ajax navigate only if history is taken in charge by html5 240 | window.JSON||(window.JSON={}),function(){function f(a){return a<10?"0"+a:a}function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return typeof b=="string"?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g=gap,h,i=b[a];i&&typeof i=="object"&&typeof i.toJSON=="function"&&(i=i.toJSON(a)),typeof rep=="function"&&(i=rep.call(b,a,i));switch(typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";gap+=indent,h=[];if(Object.prototype.toString.apply(i)==="[object Array]"){f=i.length;for(c=0;c")&&c[0]);return a>4?a:!1}();return a},m.isInternetExplorer=function(){var a=m.isInternetExplorer.cached=typeof m.isInternetExplorer.cached!="undefined"?m.isInternetExplorer.cached:Boolean(m.getInternetExplorerMajorVersion());return a},m.emulated={pushState:!Boolean(a.history&&a.history.pushState&&a.history.replaceState&&!/ Mobile\/([1-7][a-z]|(8([abcde]|f(1[0-8]))))/i.test(e.userAgent)&&!/AppleWebKit\/5([0-2]|3[0-2])/i.test(e.userAgent)),hashChange:Boolean(!("onhashchange"in a||"onhashchange"in d)||m.isInternetExplorer()&&m.getInternetExplorerMajorVersion()<8)},m.enabled=!m.emulated.pushState,m.bugs={setHash:Boolean(!m.emulated.pushState&&e.vendor==="Apple Computer, Inc."&&/AppleWebKit\/5([0-2]|3[0-3])/.test(e.userAgent)),safariPoll:Boolean(!m.emulated.pushState&&e.vendor==="Apple Computer, Inc."&&/AppleWebKit\/5([0-2]|3[0-3])/.test(e.userAgent)),ieDoubleCheck:Boolean(m.isInternetExplorer()&&m.getInternetExplorerMajorVersion()<8),hashEscape:Boolean(m.isInternetExplorer()&&m.getInternetExplorerMajorVersion()<7)},m.isEmptyObject=function(a){for(var b in a)return!1;return!0},m.cloneObject=function(a){var b,c;return a?(b=k.stringify(a),c=k.parse(b)):c={},c},m.getRootUrl=function(){var a=d.location.protocol+"//"+(d.location.hostname||d.location.host);if(d.location.port||!1)a+=":"+d.location.port;return a+="/",a},m.getBaseHref=function(){var a=d.getElementsByTagName("base"),b=null,c="";return a.length===1&&(b=a[0],c=b.href.replace(/[^\/]+$/,"")),c=c.replace(/\/+$/,""),c&&(c+="/"),c},m.getBaseUrl=function(){var a=m.getBaseHref()||m.getBasePageUrl()||m.getRootUrl();return a},m.getPageUrl=function(){var a=m.getState(!1,!1),b=(a||{}).url||d.location.href,c;return c=b.replace(/\/+$/,"").replace(/[^\/]+$/,function(a,b,c){return/\./.test(a)?a:a+"/"}),c},m.getBasePageUrl=function(){var a=d.location.href.replace(/[#\?].*/,"").replace(/[^\/]+$/,function(a,b,c){return/[^\/]$/.test(a)?"":a}).replace(/\/+$/,"")+"/";return a},m.getFullUrl=function(a,b){var c=a,d=a.substring(0,1);return b=typeof b=="undefined"?!0:b,/[a-z]+\:\/\//.test(a)||(d==="/"?c=m.getRootUrl()+a.replace(/^\/+/,""):d==="#"?c=m.getPageUrl().replace(/#.*/,"")+a:d==="?"?c=m.getPageUrl().replace(/[\?#].*/,"")+a:b?c=m.getBaseUrl()+a.replace(/^(\.\/)+/,""):c=m.getBasePageUrl()+a.replace(/^(\.\/)+/,"")),c.replace(/\#$/,"")},m.getShortUrl=function(a){var b=a,c=m.getBaseUrl(),d=m.getRootUrl();return m.emulated.pushState&&(b=b.replace(c,"")),b=b.replace(d,"/"),m.isTraditionalAnchor(b)&&(b="./"+b),b=b.replace(/^(\.\/)+/g,"./").replace(/\#$/,""),b},m.store={},m.idToState=m.idToState||{},m.stateToId=m.stateToId||{},m.urlToId=m.urlToId||{},m.storedStates=m.storedStates||[],m.savedStates=m.savedStates||[],m.normalizeStore=function(){m.store.idToState=m.store.idToState||{},m.store.urlToId=m.store.urlToId||{},m.store.stateToId=m.store.stateToId||{}},m.getState=function(a,b){typeof a=="undefined"&&(a=!0),typeof b=="undefined"&&(b=!0);var c=m.getLastSavedState();return!c&&b&&(c=m.createStateObject()),a&&(c=m.cloneObject(c),c.url=c.cleanUrl||c.url),c},m.getIdByState=function(a){var b=m.extractId(a.url),c;if(!b){c=m.getStateString(a);if(typeof m.stateToId[c]!="undefined")b=m.stateToId[c];else if(typeof m.store.stateToId[c]!="undefined")b=m.store.stateToId[c];else{for(;;){b=(new Date).getTime()+String(Math.random()).replace(/\D/g,"");if(typeof m.idToState[b]=="undefined"&&typeof m.store.idToState[b]=="undefined")break}m.stateToId[c]=b,m.idToState[b]=a}}return b},m.normalizeState=function(a){var b,c;if(!a||typeof a!="object")a={};if(typeof a.normalized!="undefined")return a;if(!a.data||typeof a.data!="object")a.data={};b={},b.normalized=!0,b.title=a.title||"",b.url=m.getFullUrl(m.unescapeString(a.url||d.location.href)),b.hash=m.getShortUrl(b.url),b.data=m.cloneObject(a.data),b.id=m.getIdByState(b),b.cleanUrl=b.url.replace(/\??\&_suid.*/,""),b.url=b.cleanUrl,c=!m.isEmptyObject(b.data);if(b.title||c)b.hash=m.getShortUrl(b.url).replace(/\??\&_suid.*/,""),/\?/.test(b.hash)||(b.hash+="?"),b.hash+="&_suid="+b.id;return b.hashedUrl=m.getFullUrl(b.hash),(m.emulated.pushState||m.bugs.safariPoll)&&m.hasUrlDuplicate(b)&&(b.url=b.hashedUrl),b},m.createStateObject=function(a,b,c){var d={data:a,title:b,url:c};return d=m.normalizeState(d),d},m.getStateById=function(a){a=String(a);var c=m.idToState[a]||m.store.idToState[a]||b;return c},m.getStateString=function(a){var b,c,d;return b=m.normalizeState(a),c={data:b.data,title:a.title,url:a.url},d=k.stringify(c),d},m.getStateId=function(a){var b,c;return b=m.normalizeState(a),c=b.id,c},m.getHashByState=function(a){var b,c;return b=m.normalizeState(a),c=b.hash,c},m.extractId=function(a){var b,c,d;return c=/(.*)\&_suid=([0-9]+)$/.exec(a),d=c?c[1]||a:a,b=c?String(c[2]||""):"",b||!1},m.isTraditionalAnchor=function(a){var b=!/[\/\?\.]/.test(a);return b},m.extractState=function(a,b){var c=null,d,e;return b=b||!1,d=m.extractId(a),d&&(c=m.getStateById(d)),c||(e=m.getFullUrl(a),d=m.getIdByUrl(e)||!1,d&&(c=m.getStateById(d)),!c&&b&&!m.isTraditionalAnchor(a)&&(c=m.createStateObject(null,null,e))),c},m.getIdByUrl=function(a){var c=m.urlToId[a]||m.store.urlToId[a]||b;return c},m.getLastSavedState=function(){return m.savedStates[m.savedStates.length-1]||b},m.getLastStoredState=function(){return m.storedStates[m.storedStates.length-1]||b},m.hasUrlDuplicate=function(a){var b=!1,c;return c=m.extractState(a.url),b=c&&c.id!==a.id,b},m.storeState=function(a){return m.urlToId[a.url]=a.id,m.storedStates.push(m.cloneObject(a)),a},m.isLastSavedState=function(a){var b=!1,c,d,e;return m.savedStates.length&&(c=a.id,d=m.getLastSavedState(),e=d.id,b=c===e),b},m.saveState=function(a){return m.isLastSavedState(a)?!1:(m.savedStates.push(m.cloneObject(a)),!0)},m.getStateByIndex=function(a){var b=null;return typeof a=="undefined"?b=m.savedStates[m.savedStates.length-1]:a<0?b=m.savedStates[m.savedStates.length+a]:b=m.savedStates[a],b},m.getHash=function(){var a=m.unescapeHash(d.location.hash);return a},m.unescapeString=function(b){var c=b,d;for(;;){d=a.unescape(c);if(d===c)break;c=d}return c},m.unescapeHash=function(a){var b=m.normalizeHash(a);return b=m.unescapeString(b),b},m.normalizeHash=function(a){var b=a.replace(/[^#]*#/,"").replace(/#.*/,"");return b},m.setHash=function(a,b){var c,e,f;return b!==!1&&m.busy()?(m.pushQueue({scope:m,callback:m.setHash,args:arguments,queue:b}),!1):(c=m.escapeHash(a),m.busy(!0),e=m.extractState(a,!0),e&&!m.emulated.pushState?m.pushState(e.data,e.title,e.url,!1):d.location.hash!==c&&(m.bugs.setHash?(f=m.getPageUrl(),m.pushState(null,null,f+"#"+c,!1)):d.location.hash=c),m)},m.escapeHash=function(b){var c=m.normalizeHash(b);return c=a.escape(c),m.bugs.hashEscape||(c=c.replace(/\%21/g,"!").replace(/\%26/g,"&").replace(/\%3D/g,"=").replace(/\%3F/g,"?")),c},m.getHashByUrl=function(a){var b=String(a).replace(/([^#]*)#?([^#]*)#?(.*)/,"$2");return b=m.unescapeHash(b),b},m.setTitle=function(a){var b=a.title,c;b||(c=m.getStateByIndex(0),c&&c.url===a.url&&(b=c.title||m.options.initialTitle));try{d.getElementsByTagName("title")[0].innerHTML=b.replace("<","<").replace(">",">").replace(" & "," & ")}catch(e){}return d.title=b,m},m.queues=[],m.busy=function(a){typeof a!="undefined"?m.busy.flag=a:typeof m.busy.flag=="undefined"&&(m.busy.flag=!1);if(!m.busy.flag){h(m.busy.timeout);var b=function(){var a,c,d;if(m.busy.flag)return;for(a=m.queues.length-1;a>=0;--a){c=m.queues[a];if(c.length===0)continue;d=c.shift(),m.fireQueueItem(d),m.busy.timeout=g(b,m.options.busyDelay)}};m.busy.timeout=g(b,m.options.busyDelay)}return m.busy.flag},m.busy.flag=!1,m.fireQueueItem=function(a){return a.callback.apply(a.scope||m,a.args||[])},m.pushQueue=function(a){return m.queues[a.queue||0]=m.queues[a.queue||0]||[],m.queues[a.queue||0].push(a),m},m.queue=function(a,b){return typeof a=="function"&&(a={callback:a}),typeof b!="undefined"&&(a.queue=b),m.busy()?m.pushQueue(a):m.fireQueueItem(a),m},m.clearQueue=function(){return m.busy.flag=!1,m.queues=[],m},m.stateChanged=!1,m.doubleChecker=!1,m.doubleCheckComplete=function(){return m.stateChanged=!0,m.doubleCheckClear(),m},m.doubleCheckClear=function(){return m.doubleChecker&&(h(m.doubleChecker),m.doubleChecker=!1),m},m.doubleCheck=function(a){return m.stateChanged=!1,m.doubleCheckClear(),m.bugs.ieDoubleCheck&&(m.doubleChecker=g(function(){return m.doubleCheckClear(),m.stateChanged||a(),!0},m.options.doubleCheckInterval)),m},m.safariStatePoll=function(){var b=m.extractState(d.location.href),c;if(!m.isLastSavedState(b))c=b;else return;return c||(c=m.createStateObject()),m.Adapter.trigger(a,"popstate"),m},m.back=function(a){return a!==!1&&m.busy()?(m.pushQueue({scope:m,callback:m.back,args:arguments,queue:a}),!1):(m.busy(!0),m.doubleCheck(function(){m.back(!1)}),n.go(-1),!0)},m.forward=function(a){return a!==!1&&m.busy()?(m.pushQueue({scope:m,callback:m.forward,args:arguments,queue:a}),!1):(m.busy(!0),m.doubleCheck(function(){m.forward(!1)}),n.go(1),!0)},m.go=function(a,b){var c;if(a>0)for(c=1;c<=a;++c)m.forward(b);else{if(!(a<0))throw new Error("History.go: History.go requires a positive or negative integer passed.");for(c=-1;c>=a;--c)m.back(b)}return m};if(m.emulated.pushState){var o=function(){};m.pushState=m.pushState||o,m.replaceState=m.replaceState||o}else m.onPopState=function(b,c){var e=!1,f=!1,g,h;return m.doubleCheckComplete(),g=m.getHash(),g?(h=m.extractState(g||d.location.href,!0),h?m.replaceState(h.data,h.title,h.url,!1):(m.Adapter.trigger(a,"anchorchange"),m.busy(!1)),m.expectedStateId=!1,!1):(e=m.Adapter.extractEventData("state",b,c)||!1,e?f=m.getStateById(e):m.expectedStateId?f=m.getStateById(m.expectedStateId):f=m.extractState(d.location.href),f||(f=m.createStateObject(null,null,d.location.href)),m.expectedStateId=!1,m.isLastSavedState(f)?(m.busy(!1),!1):(m.storeState(f),m.saveState(f),m.setTitle(f),m.Adapter.trigger(a,"statechange"),m.busy(!1),!0))},m.Adapter.bind(a,"popstate",m.onPopState),m.pushState=function(b,c,d,e){if(m.getHashByUrl(d)&&m.emulated.pushState)throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(e!==!1&&m.busy())return m.pushQueue({scope:m,callback:m.pushState,args:arguments,queue:e}),!1;m.busy(!0);var f=m.createStateObject(b,c,d);return m.isLastSavedState(f)?m.busy(!1):(m.storeState(f),m.expectedStateId=f.id,n.pushState(f.id,f.title,f.url),m.Adapter.trigger(a,"popstate")),!0},m.replaceState=function(b,c,d,e){if(m.getHashByUrl(d)&&m.emulated.pushState)throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(e!==!1&&m.busy())return m.pushQueue({scope:m,callback:m.replaceState,args:arguments,queue:e}),!1;m.busy(!0);var f=m.createStateObject(b,c,d);return m.isLastSavedState(f)?m.busy(!1):(m.storeState(f),m.expectedStateId=f.id,n.replaceState(f.id,f.title,f.url),m.Adapter.trigger(a,"popstate")),!0};if(f){try{m.store=k.parse(f.getItem("History.store"))||{}}catch(p){m.store={}}m.normalizeStore()}else m.store={},m.normalizeStore();m.Adapter.bind(a,"beforeunload",m.clearAllIntervals),m.Adapter.bind(a,"unload",m.clearAllIntervals),m.saveState(m.storeState(m.extractState(d.location.href,!0))),f&&(m.onUnload=function(){var a,b;try{a=k.parse(f.getItem("History.store"))||{}}catch(c){a={}}a.idToState=a.idToState||{},a.urlToId=a.urlToId||{},a.stateToId=a.stateToId||{};for(b in m.idToState){if(!m.idToState.hasOwnProperty(b))continue;a.idToState[b]=m.idToState[b]}for(b in m.urlToId){if(!m.urlToId.hasOwnProperty(b))continue;a.urlToId[b]=m.urlToId[b]}for(b in m.stateToId){if(!m.stateToId.hasOwnProperty(b))continue;a.stateToId[b]=m.stateToId[b]}m.store=a,m.normalizeStore(),f.setItem("History.store",k.stringify(a))},m.intervalList.push(i(m.onUnload,m.options.storeInterval)),m.Adapter.bind(a,"beforeunload",m.onUnload),m.Adapter.bind(a,"unload",m.onUnload));if(!m.emulated.pushState){m.bugs.safariPoll&&m.intervalList.push(i(m.safariStatePoll,m.options.safariPollInterval));if(e.vendor==="Apple Computer, Inc."||(e.appCodeName||"")==="Mozilla")m.Adapter.bind(a,"hashchange",function(){m.Adapter.trigger(a,"popstate")}),m.getHash()&&m.Adapter.onDomLoad(function(){m.Adapter.trigger(a,"hashchange")})}},m.init()}(window) 241 | 242 | jQuery.navigate = { 243 | active:false, 244 | historyStates : new Array(), 245 | defaultCache:true, 246 | ajaxLinks : 'a:not(.noAjax)[rel!="external"][target!="_blank"], .ajaxLink', 247 | discreteLinks : 'a:not(.noAjax)[rel!="external"][target!="_blank"], .ajaxLink', 248 | defaultInsertFunction:'defaultRefreshInsert', 249 | stateChanged : function(event){ // Note: We are using statechange instead of popstate 250 | var State = History.getState(false, false); 251 | var reverse = History.getState().internal == false; 252 | 253 | //get target and content 254 | var target = State.data.target ? $(State.data.target) : $("body"); 255 | var content = State.data.content ? ' '+State.data.content : ''; 256 | 257 | //get previous state 258 | var previousState = null; 259 | if(History.savedStates.length>1) 260 | previousState = History.getStateByIndex(-2); 261 | 262 | if(previousState ==null) { 263 | //first load 264 | //transform clicks to discrete clicks 265 | $("body").find($.navigate.discreteLinks).each(function(){ 266 | $(this).discreteClick(); 267 | }); 268 | $("body").refresh({refresh:false}); 269 | return; 270 | } else { 271 | var previousTarget = previousState.data.target ? $(previousState.data.target) : $("body"); 272 | previousTarget.stopRefresh(); 273 | } 274 | var myOptions = { 275 | refresh:true, 276 | url:State.url, 277 | content:State.data.content, 278 | status:State.data.status, 279 | html:State.data.html, 280 | clickedSelector:State.data.clickedSelector, 281 | callback:function() { 282 | target.find($.navigate.discreteLinks).each(function(){ 283 | $(this).discreteClick(); 284 | }); 285 | }, 286 | cache:$.navigate.defaultCache, 287 | customData:State.data.customData 288 | }; 289 | if(State.data.insert) myOptions.refreshInsertFunction = State.data.insert; 290 | target.refresh(myOptions); 291 | 292 | //done 293 | return false; 294 | }, 295 | init:function(options) { 296 | options = $.extend( 297 | { 298 | ajaxLinks : this.ajaxLinks, 299 | discreteLinks : this.discreteLinks, 300 | defaultInsertFunction:$.navigate.defaultInsertFunction 301 | },options); 302 | this.active = options.active; 303 | this.defaultInsertFunction = options.defaultInsertFunction; 304 | this.ajaxLinks = options.ajaxLinks; 305 | this.discreteLinks = options.discreteLinks; 306 | 307 | if(typeof options.active == "undefined") { 308 | if(typeof Modernizr == "undefined") { 309 | console.log('if not specified any other "active" parameter, navigate tests Modernizr.history to get active, Modernizr undefined => navigate will not get active') 310 | this.active = false; 311 | } else { 312 | this.active = Modernizr.history; 313 | } 314 | } 315 | if(!this.active) { 316 | $("body").trigger("donerefresh"); 317 | return; 318 | } 319 | // Prepare HISTORY 320 | var History = window.History; // Note: We are using a capital H instead of a lower h 321 | if ( !History.enabled ) { 322 | // History.js is disabled for this browser. 323 | // This is because we can optionally choose to support HTML4 browsers or not. 324 | return false; 325 | } 326 | //Navigate when click 327 | $("html").on("click",$.navigate.ajaxLinks, function(e) { 328 | var that = $(this); 329 | return that.navigate(); 330 | }); 331 | 332 | // Bind to StateChange Event 333 | History.Adapter.bind(window,'statechange',$.navigate.stateChanged); 334 | 335 | //push the first state 336 | $.navigate.stateChanged(); 337 | } 338 | }; 339 | (function($) { 340 | // get unique selector as #id if have id otherwise create id and return the proper selector 341 | $.fn.getSelector = function(){ 342 | var me=$(this); 343 | if(me.is("body")) {return 'body';} else 344 | if(!$.isWindow(me[0])){ 345 | var toReturn = me.attr('id'); if(!toReturn){toReturn = "me-" + Math.floor(Math.random()*1000000); me.attr('id', toReturn);} 346 | me=null; 347 | return '#'+toReturn; 348 | } else {me=null;return window;} //this is the window 349 | }; 350 | $.fn.discreteClick = function(){ 351 | var that = $(this); 352 | if(that.attr("href") !="javascript://") { 353 | that.attr("ajax-href", that.attr("href")); 354 | that.attr("href", "javascript://"); 355 | } 356 | }; 357 | 358 | /** 359 | * This function navigate in ajax thanks to the data of this element 360 | * target : the jquery selector in which we insert the data 361 | * href : the url from which we take the data 362 | * content : the jquery selector in the href page from which we take the data 363 | * title : the page new title 364 | **/ 365 | $.fn.navigate = function(options){ 366 | var me = $(this); 367 | var baseOptions = { 368 | html:null 369 | }; 370 | 371 | /* get the href */ 372 | //cancel if this is a js link only 373 | var href=me.attr('ajax-href'); 374 | if(!href) href=me.attr('href'); 375 | 376 | if(href =="javascript://") return true; 377 | if(!href) href = document.location.href; 378 | 379 | 380 | //ie add the absolute location on href attribute 381 | var base = window.location.href.substring(0, window.location.href.lastIndexOf("/") + 1); 382 | href = href.replace(base, ""); 383 | 384 | 385 | //don't do anything on links with rel="external" or target = blank or target of potential other domain 386 | baseOptions.url = href; 387 | 388 | /* get the ajax content */ 389 | var content = me.attr('ajax-content'); 390 | if(!content) content = 'body'; 391 | baseOptions.content = content; 392 | 393 | /* get the target */ 394 | var target = me.attr('ajax-target'); 395 | if(!target) target = me.attr("target"); 396 | if(!target) target = "body"; 397 | baseOptions.target = target; 398 | 399 | /* get the title */ 400 | var title = me.attr('title'); 401 | if(!title) title=document.title; 402 | baseOptions.title = title; 403 | 404 | /* get the status */ 405 | var status = $(target).attr('refresh-status'); 406 | if(!status) status=null; 407 | baseOptions.status = status; 408 | 409 | /* get the insert method */ 410 | var insert = me.attr('refresh-insert-function'); 411 | if(!insert) insert = me.attr('ajax-insert') 412 | if(!insert) insert=null; 413 | baseOptions.insert = insert; 414 | 415 | options = $.extend(baseOptions,options); 416 | History.pushState( 417 | { 418 | target:options.target, 419 | content:options.content, 420 | insert:options.insert, 421 | status:options.status, 422 | clickedSelector:null, 423 | html:options.html, 424 | customData : options.customData 425 | }, 426 | options.title, options.url 427 | ); 428 | 429 | return false; 430 | }; 431 | })(jQuery); 432 | /* 433 | $(document).ready(function() { 434 | //normal use : 435 | $.navigate.init(); 436 | 437 | //you can add these parameters : 438 | //$.navigate.init({ 439 | // active: any test you want returning a boolean (by default : Modernizr.history), 440 | // ajaxLinks : 'any selector you want for your ajax links', 441 | // defaultInsertFunction:'any jquery object attached function you want' 442 | //}); 443 | }); */ 444 | -------------------------------------------------------------------------------- /example/list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | List 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 |
27 | 32 |
33 |
34 |

List

35 | 72 |
73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /navigate.js: -------------------------------------------------------------------------------- 1 | // by default, ajax navigate only if history is taken in charge by html5 2 | window.JSON||(window.JSON={}),function(){function f(a){return a<10?"0"+a:a}function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return typeof b=="string"?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g=gap,h,i=b[a];i&&typeof i=="object"&&typeof i.toJSON=="function"&&(i=i.toJSON(a)),typeof rep=="function"&&(i=rep.call(b,a,i));switch(typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";gap+=indent,h=[];if(Object.prototype.toString.apply(i)==="[object Array]"){f=i.length;for(c=0;c")&&c[0]);return a>4?a:!1}();return a},m.isInternetExplorer=function(){var a=m.isInternetExplorer.cached=typeof m.isInternetExplorer.cached!="undefined"?m.isInternetExplorer.cached:Boolean(m.getInternetExplorerMajorVersion());return a},m.emulated={pushState:!Boolean(a.history&&a.history.pushState&&a.history.replaceState&&!/ Mobile\/([1-7][a-z]|(8([abcde]|f(1[0-8]))))/i.test(e.userAgent)&&!/AppleWebKit\/5([0-2]|3[0-2])/i.test(e.userAgent)),hashChange:Boolean(!("onhashchange"in a||"onhashchange"in d)||m.isInternetExplorer()&&m.getInternetExplorerMajorVersion()<8)},m.enabled=!m.emulated.pushState,m.bugs={setHash:Boolean(!m.emulated.pushState&&e.vendor==="Apple Computer, Inc."&&/AppleWebKit\/5([0-2]|3[0-3])/.test(e.userAgent)),safariPoll:Boolean(!m.emulated.pushState&&e.vendor==="Apple Computer, Inc."&&/AppleWebKit\/5([0-2]|3[0-3])/.test(e.userAgent)),ieDoubleCheck:Boolean(m.isInternetExplorer()&&m.getInternetExplorerMajorVersion()<8),hashEscape:Boolean(m.isInternetExplorer()&&m.getInternetExplorerMajorVersion()<7)},m.isEmptyObject=function(a){for(var b in a)return!1;return!0},m.cloneObject=function(a){var b,c;return a?(b=k.stringify(a),c=k.parse(b)):c={},c},m.getRootUrl=function(){var a=d.location.protocol+"//"+(d.location.hostname||d.location.host);if(d.location.port||!1)a+=":"+d.location.port;return a+="/",a},m.getBaseHref=function(){var a=d.getElementsByTagName("base"),b=null,c="";return a.length===1&&(b=a[0],c=b.href.replace(/[^\/]+$/,"")),c=c.replace(/\/+$/,""),c&&(c+="/"),c},m.getBaseUrl=function(){var a=m.getBaseHref()||m.getBasePageUrl()||m.getRootUrl();return a},m.getPageUrl=function(){var a=m.getState(!1,!1),b=(a||{}).url||d.location.href,c;return c=b.replace(/\/+$/,"").replace(/[^\/]+$/,function(a,b,c){return/\./.test(a)?a:a+"/"}),c},m.getBasePageUrl=function(){var a=d.location.href.replace(/[#\?].*/,"").replace(/[^\/]+$/,function(a,b,c){return/[^\/]$/.test(a)?"":a}).replace(/\/+$/,"")+"/";return a},m.getFullUrl=function(a,b){var c=a,d=a.substring(0,1);return b=typeof b=="undefined"?!0:b,/[a-z]+\:\/\//.test(a)||(d==="/"?c=m.getRootUrl()+a.replace(/^\/+/,""):d==="#"?c=m.getPageUrl().replace(/#.*/,"")+a:d==="?"?c=m.getPageUrl().replace(/[\?#].*/,"")+a:b?c=m.getBaseUrl()+a.replace(/^(\.\/)+/,""):c=m.getBasePageUrl()+a.replace(/^(\.\/)+/,"")),c.replace(/\#$/,"")},m.getShortUrl=function(a){var b=a,c=m.getBaseUrl(),d=m.getRootUrl();return m.emulated.pushState&&(b=b.replace(c,"")),b=b.replace(d,"/"),m.isTraditionalAnchor(b)&&(b="./"+b),b=b.replace(/^(\.\/)+/g,"./").replace(/\#$/,""),b},m.store={},m.idToState=m.idToState||{},m.stateToId=m.stateToId||{},m.urlToId=m.urlToId||{},m.storedStates=m.storedStates||[],m.savedStates=m.savedStates||[],m.normalizeStore=function(){m.store.idToState=m.store.idToState||{},m.store.urlToId=m.store.urlToId||{},m.store.stateToId=m.store.stateToId||{}},m.getState=function(a,b){typeof a=="undefined"&&(a=!0),typeof b=="undefined"&&(b=!0);var c=m.getLastSavedState();return!c&&b&&(c=m.createStateObject()),a&&(c=m.cloneObject(c),c.url=c.cleanUrl||c.url),c},m.getIdByState=function(a){var b=m.extractId(a.url),c;if(!b){c=m.getStateString(a);if(typeof m.stateToId[c]!="undefined")b=m.stateToId[c];else if(typeof m.store.stateToId[c]!="undefined")b=m.store.stateToId[c];else{for(;;){b=(new Date).getTime()+String(Math.random()).replace(/\D/g,"");if(typeof m.idToState[b]=="undefined"&&typeof m.store.idToState[b]=="undefined")break}m.stateToId[c]=b,m.idToState[b]=a}}return b},m.normalizeState=function(a){var b,c;if(!a||typeof a!="object")a={};if(typeof a.normalized!="undefined")return a;if(!a.data||typeof a.data!="object")a.data={};b={},b.normalized=!0,b.title=a.title||"",b.url=m.getFullUrl(m.unescapeString(a.url||d.location.href)),b.hash=m.getShortUrl(b.url),b.data=m.cloneObject(a.data),b.id=m.getIdByState(b),b.cleanUrl=b.url.replace(/\??\&_suid.*/,""),b.url=b.cleanUrl,c=!m.isEmptyObject(b.data);if(b.title||c)b.hash=m.getShortUrl(b.url).replace(/\??\&_suid.*/,""),/\?/.test(b.hash)||(b.hash+="?"),b.hash+="&_suid="+b.id;return b.hashedUrl=m.getFullUrl(b.hash),(m.emulated.pushState||m.bugs.safariPoll)&&m.hasUrlDuplicate(b)&&(b.url=b.hashedUrl),b},m.createStateObject=function(a,b,c){var d={data:a,title:b,url:c};return d=m.normalizeState(d),d},m.getStateById=function(a){a=String(a);var c=m.idToState[a]||m.store.idToState[a]||b;return c},m.getStateString=function(a){var b,c,d;return b=m.normalizeState(a),c={data:b.data,title:a.title,url:a.url},d=k.stringify(c),d},m.getStateId=function(a){var b,c;return b=m.normalizeState(a),c=b.id,c},m.getHashByState=function(a){var b,c;return b=m.normalizeState(a),c=b.hash,c},m.extractId=function(a){var b,c,d;return c=/(.*)\&_suid=([0-9]+)$/.exec(a),d=c?c[1]||a:a,b=c?String(c[2]||""):"",b||!1},m.isTraditionalAnchor=function(a){var b=!/[\/\?\.]/.test(a);return b},m.extractState=function(a,b){var c=null,d,e;return b=b||!1,d=m.extractId(a),d&&(c=m.getStateById(d)),c||(e=m.getFullUrl(a),d=m.getIdByUrl(e)||!1,d&&(c=m.getStateById(d)),!c&&b&&!m.isTraditionalAnchor(a)&&(c=m.createStateObject(null,null,e))),c},m.getIdByUrl=function(a){var c=m.urlToId[a]||m.store.urlToId[a]||b;return c},m.getLastSavedState=function(){return m.savedStates[m.savedStates.length-1]||b},m.getLastStoredState=function(){return m.storedStates[m.storedStates.length-1]||b},m.hasUrlDuplicate=function(a){var b=!1,c;return c=m.extractState(a.url),b=c&&c.id!==a.id,b},m.storeState=function(a){return m.urlToId[a.url]=a.id,m.storedStates.push(m.cloneObject(a)),a},m.isLastSavedState=function(a){var b=!1,c,d,e;return m.savedStates.length&&(c=a.id,d=m.getLastSavedState(),e=d.id,b=c===e),b},m.saveState=function(a){return m.isLastSavedState(a)?!1:(m.savedStates.push(m.cloneObject(a)),!0)},m.getStateByIndex=function(a){var b=null;return typeof a=="undefined"?b=m.savedStates[m.savedStates.length-1]:a<0?b=m.savedStates[m.savedStates.length+a]:b=m.savedStates[a],b},m.getHash=function(){var a=m.unescapeHash(d.location.hash);return a},m.unescapeString=function(b){var c=b,d;for(;;){d=a.unescape(c);if(d===c)break;c=d}return c},m.unescapeHash=function(a){var b=m.normalizeHash(a);return b=m.unescapeString(b),b},m.normalizeHash=function(a){var b=a.replace(/[^#]*#/,"").replace(/#.*/,"");return b},m.setHash=function(a,b){var c,e,f;return b!==!1&&m.busy()?(m.pushQueue({scope:m,callback:m.setHash,args:arguments,queue:b}),!1):(c=m.escapeHash(a),m.busy(!0),e=m.extractState(a,!0),e&&!m.emulated.pushState?m.pushState(e.data,e.title,e.url,!1):d.location.hash!==c&&(m.bugs.setHash?(f=m.getPageUrl(),m.pushState(null,null,f+"#"+c,!1)):d.location.hash=c),m)},m.escapeHash=function(b){var c=m.normalizeHash(b);return c=a.escape(c),m.bugs.hashEscape||(c=c.replace(/\%21/g,"!").replace(/\%26/g,"&").replace(/\%3D/g,"=").replace(/\%3F/g,"?")),c},m.getHashByUrl=function(a){var b=String(a).replace(/([^#]*)#?([^#]*)#?(.*)/,"$2");return b=m.unescapeHash(b),b},m.setTitle=function(a){var b=a.title,c;b||(c=m.getStateByIndex(0),c&&c.url===a.url&&(b=c.title||m.options.initialTitle));try{d.getElementsByTagName("title")[0].innerHTML=b.replace("<","<").replace(">",">").replace(" & "," & ")}catch(e){}return d.title=b,m},m.queues=[],m.busy=function(a){typeof a!="undefined"?m.busy.flag=a:typeof m.busy.flag=="undefined"&&(m.busy.flag=!1);if(!m.busy.flag){h(m.busy.timeout);var b=function(){var a,c,d;if(m.busy.flag)return;for(a=m.queues.length-1;a>=0;--a){c=m.queues[a];if(c.length===0)continue;d=c.shift(),m.fireQueueItem(d),m.busy.timeout=g(b,m.options.busyDelay)}};m.busy.timeout=g(b,m.options.busyDelay)}return m.busy.flag},m.busy.flag=!1,m.fireQueueItem=function(a){return a.callback.apply(a.scope||m,a.args||[])},m.pushQueue=function(a){return m.queues[a.queue||0]=m.queues[a.queue||0]||[],m.queues[a.queue||0].push(a),m},m.queue=function(a,b){return typeof a=="function"&&(a={callback:a}),typeof b!="undefined"&&(a.queue=b),m.busy()?m.pushQueue(a):m.fireQueueItem(a),m},m.clearQueue=function(){return m.busy.flag=!1,m.queues=[],m},m.stateChanged=!1,m.doubleChecker=!1,m.doubleCheckComplete=function(){return m.stateChanged=!0,m.doubleCheckClear(),m},m.doubleCheckClear=function(){return m.doubleChecker&&(h(m.doubleChecker),m.doubleChecker=!1),m},m.doubleCheck=function(a){return m.stateChanged=!1,m.doubleCheckClear(),m.bugs.ieDoubleCheck&&(m.doubleChecker=g(function(){return m.doubleCheckClear(),m.stateChanged||a(),!0},m.options.doubleCheckInterval)),m},m.safariStatePoll=function(){var b=m.extractState(d.location.href),c;if(!m.isLastSavedState(b))c=b;else return;return c||(c=m.createStateObject()),m.Adapter.trigger(a,"popstate"),m},m.back=function(a){return a!==!1&&m.busy()?(m.pushQueue({scope:m,callback:m.back,args:arguments,queue:a}),!1):(m.busy(!0),m.doubleCheck(function(){m.back(!1)}),n.go(-1),!0)},m.forward=function(a){return a!==!1&&m.busy()?(m.pushQueue({scope:m,callback:m.forward,args:arguments,queue:a}),!1):(m.busy(!0),m.doubleCheck(function(){m.forward(!1)}),n.go(1),!0)},m.go=function(a,b){var c;if(a>0)for(c=1;c<=a;++c)m.forward(b);else{if(!(a<0))throw new Error("History.go: History.go requires a positive or negative integer passed.");for(c=-1;c>=a;--c)m.back(b)}return m};if(m.emulated.pushState){var o=function(){};m.pushState=m.pushState||o,m.replaceState=m.replaceState||o}else m.onPopState=function(b,c){var e=!1,f=!1,g,h;return m.doubleCheckComplete(),g=m.getHash(),g?(h=m.extractState(g||d.location.href,!0),h?m.replaceState(h.data,h.title,h.url,!1):(m.Adapter.trigger(a,"anchorchange"),m.busy(!1)),m.expectedStateId=!1,!1):(e=m.Adapter.extractEventData("state",b,c)||!1,e?f=m.getStateById(e):m.expectedStateId?f=m.getStateById(m.expectedStateId):f=m.extractState(d.location.href),f||(f=m.createStateObject(null,null,d.location.href)),m.expectedStateId=!1,m.isLastSavedState(f)?(m.busy(!1),!1):(m.storeState(f),m.saveState(f),m.setTitle(f),m.Adapter.trigger(a,"statechange"),m.busy(!1),!0))},m.Adapter.bind(a,"popstate",m.onPopState),m.pushState=function(b,c,d,e){if(m.getHashByUrl(d)&&m.emulated.pushState)throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(e!==!1&&m.busy())return m.pushQueue({scope:m,callback:m.pushState,args:arguments,queue:e}),!1;m.busy(!0);var f=m.createStateObject(b,c,d);return m.isLastSavedState(f)?m.busy(!1):(m.storeState(f),m.expectedStateId=f.id,n.pushState(f.id,f.title,f.url),m.Adapter.trigger(a,"popstate")),!0},m.replaceState=function(b,c,d,e){if(m.getHashByUrl(d)&&m.emulated.pushState)throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(e!==!1&&m.busy())return m.pushQueue({scope:m,callback:m.replaceState,args:arguments,queue:e}),!1;m.busy(!0);var f=m.createStateObject(b,c,d);return m.isLastSavedState(f)?m.busy(!1):(m.storeState(f),m.expectedStateId=f.id,n.replaceState(f.id,f.title,f.url),m.Adapter.trigger(a,"popstate")),!0};if(f){try{m.store=k.parse(f.getItem("History.store"))||{}}catch(p){m.store={}}m.normalizeStore()}else m.store={},m.normalizeStore();m.Adapter.bind(a,"beforeunload",m.clearAllIntervals),m.Adapter.bind(a,"unload",m.clearAllIntervals),m.saveState(m.storeState(m.extractState(d.location.href,!0))),f&&(m.onUnload=function(){var a,b;try{a=k.parse(f.getItem("History.store"))||{}}catch(c){a={}}a.idToState=a.idToState||{},a.urlToId=a.urlToId||{},a.stateToId=a.stateToId||{};for(b in m.idToState){if(!m.idToState.hasOwnProperty(b))continue;a.idToState[b]=m.idToState[b]}for(b in m.urlToId){if(!m.urlToId.hasOwnProperty(b))continue;a.urlToId[b]=m.urlToId[b]}for(b in m.stateToId){if(!m.stateToId.hasOwnProperty(b))continue;a.stateToId[b]=m.stateToId[b]}m.store=a,m.normalizeStore(),f.setItem("History.store",k.stringify(a))},m.intervalList.push(i(m.onUnload,m.options.storeInterval)),m.Adapter.bind(a,"beforeunload",m.onUnload),m.Adapter.bind(a,"unload",m.onUnload));if(!m.emulated.pushState){m.bugs.safariPoll&&m.intervalList.push(i(m.safariStatePoll,m.options.safariPollInterval));if(e.vendor==="Apple Computer, Inc."||(e.appCodeName||"")==="Mozilla")m.Adapter.bind(a,"hashchange",function(){m.Adapter.trigger(a,"popstate")}),m.getHash()&&m.Adapter.onDomLoad(function(){m.Adapter.trigger(a,"hashchange")})}},m.init()}(window) 3 | 4 | //------------------------------------------------------------------- 5 | //REFRESH 6 | //------------------------------------------------------------------- 7 | jQuery.refresh = { 8 | ajaxCalls : new Array(), 9 | refreshTimers : new Array(), 10 | defaultCache : false 11 | }; 12 | (function($) { 13 | // get unique selector as #id if have id otherwise create id and return the proper selector 14 | $.fn.getSelector = function(){ 15 | var me=$(this); 16 | if(me.is("body")) {return 'body';} else 17 | if(!$.isWindow(me[0])){ 18 | var toReturn = me.attr('id'); if(!toReturn){toReturn = "me-" + Math.floor(Math.random()*1000000); me.attr('id', toReturn);} 19 | me=null; 20 | return '#'+toReturn; 21 | } else {me=null;return window;} //this is the window 22 | }; 23 | $.fn.stopRefresh = function(options){ 24 | var target = $(this); 25 | target.trigger("stoprefresh"); 26 | var targetSelector = target.getSelector(); 27 | var targetRefreshTimer = $.refresh.refreshTimers[targetSelector]; 28 | //first reset the timer 29 | if(targetRefreshTimer) { 30 | clearInterval(targetRefreshTimer); 31 | delete targetRefreshTimer; 32 | } 33 | //then reset the current call 34 | var currentCall = $.refresh.ajaxCalls[targetSelector]; 35 | if(currentCall) { 36 | currentCall.abort(); 37 | delete currentCall; 38 | } 39 | }; 40 | $.fn.defaultRefreshInsert = function(options) { 41 | //options = {html:value, scripts:value} 42 | $(this).html(options.html); 43 | $(this).trigger({type:"finishrefreshinsert"}); 44 | 45 | }; 46 | $.fn.refresh = function(options){ 47 | var target = $(this); 48 | var targetSelector = target.getSelector(); 49 | if(typeof options == "boolean") { 50 | options = {refresh:options}; 51 | //force refresh : options=true or options.refresh==true 52 | } 53 | //else if(typeof options=="undefined") options = {}; 54 | options = $.extend( 55 | { 56 | html : null, 57 | refresh : target, 58 | resetInterval : true, 59 | url : null, 60 | content:targetSelector, 61 | clickedSelector:$(this).getSelector(), 62 | callback:function(){}, 63 | cache:$.refresh.defaultCache, 64 | insertFunction:$.navigate.defaultInsertFunction, 65 | customData:null, 66 | timeout:8000 67 | },options); 68 | 69 | 70 | //WE REFRESH OR NOT 71 | //---------------------------------------------------------------------- 72 | //check if we do have to refresh 73 | var refreshFunction = target.attr("data-refresh-function"); 74 | if(typeof refreshFunction != "undefined") { 75 | //SWITCH CONTENT 76 | if(target[refreshFunction]) target[refreshFunction](); 77 | else refreshFunction(); 78 | } else if(options.refresh) { 79 | var currentCall = $.refresh.ajaxCalls[targetSelector]; 80 | if(currentCall) { 81 | target.trigger("stoprefresh"); 82 | currentCall.abort(); 83 | } 84 | 85 | //get the url to call, in order : 86 | //1 - the option 87 | //2 - the refresh-url attribute 88 | //3 - the current location 89 | var targetUrl = options.url; 90 | if(!targetUrl) { 91 | var refreshUrl = target.attr("data-refresh-url"); 92 | if(refreshUrl) targetUrl = refreshUrl; 93 | else targetUrl = window.location.href; 94 | } 95 | var myRefreshId = target.attr("data-refresh-id"); 96 | target.trigger({type:"startrefresh", clickedSelector:options.clickedSelector}); 97 | 98 | var myDoneFunc = function(data) { 99 | currentCall = null; 100 | //Remove the body tag not to load all scripts and header of the loaded page 101 | //------------------------------------------------------------------------- 102 | var re = //; 103 | var check=data.match(re); 104 | if(check && check.length>0) { 105 | check=check[0].replace(/^$/, 'div>'); 107 | } else check=data; 108 | 109 | //GET THE HEAD 110 | var re = //; 111 | var headHtml=data.match(re); 112 | if(headHtml && headHtml.length>0) { 113 | headHtml=headHtml[0].replace(/^$/, 'div>'); 115 | headHtml = $(headHtml).html() 116 | } else headHtml=""; 117 | 118 | //Remove the scripts tags 119 | //------------------------------------------------------------------------- 120 | var noscripts = check.match(/]*>([\s\S]*?)<\/noscript>/gm); 121 | check = check.replace(new RegExp('', 'g'),'div>'); 123 | 124 | var scripts = check.match(/]*>([\s\S]*?)<\/script>/gm); 125 | check = check.replace(new RegExp('', 'g'),'div>'); 127 | 128 | //get the wanted content 129 | //------------------------------------------------------------------------- 130 | if(options.content != 'body') { 131 | var element=$(options.content, '
'+check+'
');//check).find(State.data.content); 132 | } else { 133 | var element=$(check); 134 | } 135 | 136 | var newRefreshId = element.attr("data-refresh-id"); 137 | 138 | if(myRefreshId && newRefreshId && myRefreshId==newRefreshId) { 139 | target.trigger({type:"cancelrefresh", clickedSelector:options.clickedSelector}); 140 | return; 141 | } 142 | var myHtml = ''; 143 | 144 | //add again the inline scripts to the wanted html 145 | //------------------------------------------------------------------------- 146 | var myScripts = element.find(".temp-script").remove(); 147 | element.each(function() {myHtml+=$(this).html();}); 148 | myScriptsHtml = ''; 149 | if(scripts) 150 | for(var i=0;i'+myHtml+'').children().each(function(){ 199 | $(this)[insertFunction](target); 200 | }); 201 | target.trigger({type:"finishrefreshinsert"}); 202 | } else { 203 | target[insertFunction]({ 204 | html:myHtml, 205 | head:headHtml, 206 | scripts:myScriptsHtml, 207 | customData:options.customData, 208 | class:element.attr("class") 209 | }); 210 | } 211 | } 212 | else if(window[insertFunction]) { 213 | window[insertFunction]({ 214 | html:myHtml, 215 | head:headHtml, 216 | scripts:myScripts, 217 | customData:options.customData, 218 | class:element.attr("class") 219 | }); 220 | } 221 | }; 222 | 223 | if(!options.html) 224 | currentCall= $.ajax({ 225 | type: "GET", 226 | cache:options.cache, 227 | context:target, 228 | url: targetUrl, 229 | timeout:options.timeout, 230 | dataType: "html"}) 231 | .done(myDoneFunc) 232 | .fail(function(jqXHR, textStatus){ 233 | currentCall.abort(); 234 | currentCall=null; 235 | $(this).trigger({type:"failrefresh", clickedSelector:options.clickedSelector, status:textStatus}); 236 | }); 237 | else myDoneFunc(options.html); 238 | } else { 239 | target.trigger({type:"donerefresh", clickedSelector:options.clickedSelector}); 240 | } 241 | 242 | //CLEAN CURRENT TIMER IF MANUAL FORCE REFRESH 243 | //---------------------------------------------------------------------- 244 | var refreshTimer = $.refresh.refreshTimers[targetSelector]; 245 | if(options.resetInterval && refreshTimer) { 246 | //if we force the refresh and a timer exists, we clear the current timer 247 | clearInterval(refreshTimer); 248 | delete refreshTimer; 249 | } 250 | 251 | //CHECK IF WE SET A REFRESH INTERVAL TIMER 252 | //---------------------------------------------------------------------- 253 | var refreshTimerTime = target.attr('data-refresh-interval'); 254 | if(!refreshTimerTime) return; 255 | refreshTimerTime = parseInt(refreshTimerTime); 256 | if(options.resetInterval && refreshTimerTime>0) { 257 | 258 | //set timer refresh for this target 259 | $.refresh.refreshTimers[targetSelector] = setInterval(function(){ 260 | target.refresh({refresh:true, resetInterval : false}); 261 | },refreshTimerTime); 262 | } 263 | 264 | }; 265 | })(jQuery); 266 | 267 | // ------------------------------------------------------------------- 268 | // NAVIGATE 269 | // ------------------------------------------------------------------- 270 | 271 | jQuery.navigate = { 272 | active:false, 273 | historyStates : new Array(), 274 | defaultCache:true, 275 | ajaxLinks : 'a:not(.noAjax)[rel!="external"][target!="_blank"], .ajaxLink', 276 | discreteLinks : 'a:not(.noAjax)[rel!="external"][target!="_blank"], .ajaxLink', 277 | defaultInsertFunction:'defaultRefreshInsert', 278 | stateChanged : function(event){ // Note: We are using statechange instead of popstate 279 | var State = History.getState(false, false); 280 | var reverse = History.getState().internal == false; 281 | 282 | //get target and content 283 | var target = State.data.target ? $(State.data.target) : $("body"); 284 | var content = State.data.content ? ' '+State.data.content : ''; 285 | 286 | //get previous state 287 | var previousState = null; 288 | if(History.savedStates.length>1) 289 | previousState = History.getStateByIndex(-2); 290 | 291 | if(previousState ==null) { 292 | //first load 293 | //transform clicks to discrete clicks 294 | if(typeof Modernizr == 'undefined' || Modernizr.touch) { 295 | $("body").find($.navigate.discreteLinks).each(function(){ 296 | $(this).discreteClick(); 297 | }); 298 | } 299 | $("body").refresh({refresh:false}); 300 | return; 301 | } else { 302 | var previousTarget = previousState.data.target ? $(previousState.data.target) : $("body"); 303 | previousTarget.stopRefresh(); 304 | } 305 | var myOptions = { 306 | refresh:true, 307 | url:State.url, 308 | content:State.data.content, 309 | status:State.data.status, 310 | html:State.data.html, 311 | clickedSelector:State.data.clickedSelector, 312 | callback:function() { 313 | if(typeof Modernizr == 'undefined' || Modernizr.touch) { 314 | target.find($.navigate.discreteLinks).each(function(){ 315 | $(this).discreteClick(); 316 | }); 317 | } 318 | }, 319 | cache:$.navigate.defaultCache, 320 | customData:State.data.customData, 321 | timeout:$.navigate.timeout 322 | }; 323 | if(State.data.insertFunction) myOptions.insertFunction = State.data.insertFunction; 324 | target.refresh(myOptions); 325 | 326 | //done 327 | return false; 328 | }, 329 | init:function(options) { 330 | options = $.extend( 331 | { 332 | ajaxLinks : this.ajaxLinks, 333 | discreteLinks : this.discreteLinks, 334 | defaultInsertFunction:$.navigate.defaultInsertFunction, 335 | timeout:8000 336 | },options); 337 | this.active = options.active; 338 | this.defaultInsertFunction = options.defaultInsertFunction; 339 | this.ajaxLinks = options.ajaxLinks; 340 | this.discreteLinks = options.discreteLinks; 341 | this.timeout = options.timeout; 342 | if(typeof options.active == "undefined") { 343 | if(typeof Modernizr == "undefined") { 344 | console.log('if not specified any other "active" parameter, navigate tests Modernizr.history to get active, Modernizr undefined => navigate will not get active') 345 | this.active = false; 346 | } else { 347 | this.active = Modernizr.history; 348 | } 349 | } 350 | if(!this.active) { 351 | $("body").trigger("donerefresh"); 352 | return; 353 | } 354 | // Prepare HISTORY 355 | var History = window.History; // Note: We are using a capital H instead of a lower h 356 | if ( !History.enabled ) { 357 | // History.js is disabled for this browser. 358 | // This is because we can optionally choose to support HTML4 browsers or not. 359 | return false; 360 | } 361 | //Navigate when click 362 | $("html").on("click",$.navigate.ajaxLinks, function(e) { 363 | var that = $(this); 364 | return that.navigate(); 365 | }); 366 | 367 | // Bind to StateChange Event 368 | History.Adapter.bind(window,'statechange',$.navigate.stateChanged); 369 | 370 | //push the first state 371 | $.navigate.stateChanged(); 372 | } 373 | }; 374 | (function($) { 375 | // get unique selector as #id if have id otherwise create id and return the proper selector 376 | $.fn.getSelector = function(){ 377 | var me=$(this); 378 | if(me.is("body")) {return 'body';} else 379 | if(!$.isWindow(me[0])){ 380 | var toReturn = me.attr('id'); if(!toReturn){toReturn = "me-" + Math.floor(Math.random()*1000000); me.attr('id', toReturn);} 381 | me=null; 382 | return '#'+toReturn; 383 | } else {me=null;return window;} //this is the window 384 | }; 385 | $.fn.discreteClick = function(){ 386 | var that = $(this); 387 | if(that.attr("href") !="javascript://") { 388 | that.attr("data-ajax-href", that.attr("href")); 389 | that.attr("href", "javascript://"); 390 | } 391 | }; 392 | 393 | /** 394 | * This function navigate in ajax thanks to the data of this element 395 | * target : the jquery selector in which we insert the data 396 | * href : the url from which we take the data 397 | * content : the jquery selector in the href page from which we take the data 398 | * title : the page new title 399 | **/ 400 | $.fn.navigate = function(options){ 401 | var me = $(this); 402 | var baseOptions = { 403 | html:null 404 | }; 405 | 406 | /* get the href */ 407 | //cancel if this is a js link only 408 | var href=me.attr('data-ajax-href'); 409 | if(!href) href=me.attr('href'); 410 | 411 | if(href =="javascript://") return true; 412 | if(!href) href = document.location.href; 413 | 414 | 415 | //ie add the absolute location on href attribute 416 | var base = window.location.href.substring(0, window.location.href.lastIndexOf("/") + 1); 417 | href = href.replace(base, ""); 418 | 419 | 420 | //don't do anything on links with rel="external" or target = blank or target of potential other domain 421 | baseOptions.url = href; 422 | 423 | /* get the ajax content */ 424 | var content = me.attr('data-ajax-content'); 425 | if(!content) content = 'body'; 426 | baseOptions.content = content; 427 | 428 | /* get the target */ 429 | var target = me.attr('data-ajax-target'); 430 | if(!target) target = me.attr("data-target"); 431 | if(!target) target = "body"; 432 | baseOptions.target = target; 433 | 434 | /* get the title */ 435 | var title = me.attr('title'); 436 | if(!title) title=document.title; 437 | baseOptions.title = title; 438 | 439 | /* get the status */ 440 | var status = $(target).attr('data-refresh-status'); 441 | if(!status) status=null; 442 | baseOptions.status = status; 443 | 444 | /* get the insert method */ 445 | //TODO to delete there after, backward compatibility only 446 | var insertFunction = me.attr('data-refresh-insert-function'); 447 | if(!insertFunction) insertFunction = me.attr('data-ajax-insert'); 448 | // /TODO 449 | if(!insertFunction) insertFunction = me.attr('data-insert-function'); 450 | 451 | if(!insertFunction) insertFunction=null; 452 | baseOptions.insertFunction = insertFunction; 453 | 454 | options = $.extend(baseOptions,options); 455 | History.pushState( 456 | { 457 | target:options.target, 458 | content:options.content, 459 | insertFunction:options.insertFunction, 460 | status:options.status, 461 | clickedSelector:$(this).getSelector(), 462 | html:options.html, 463 | customData : options.customData 464 | }, 465 | options.title, options.url 466 | ); 467 | 468 | return false; 469 | }; 470 | })(jQuery); 471 | 472 | /* 473 | $(document).ready(function() { 474 | //normal use : 475 | $.navigate.init(); 476 | 477 | //you can add these parameters : 478 | //$.navigate.init({ 479 | // active: any test you want returning a boolean (by default : Modernizr.history), 480 | // ajaxLinks : 'any selector you want for your ajax links', 481 | // defaultInsertFunction:'any jquery object attached function you want' 482 | //}); 483 | }); */ 484 | -------------------------------------------------------------------------------- /navigate.min.js: -------------------------------------------------------------------------------- 1 | // navigate.min.js from https://github.com/gebeer/jquery-navigate 2 | window.JSON||(window.JSON={}),function(){function f(e){return 10>e?"0"+e:e}function quote(e){return escapable.lastIndex=0,escapable.test(e)?'"'+e.replace(escapable,function(e){var t=meta[e];return"string"==typeof t?t:"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function str(e,t){var r,a,n,i,o,s=gap,u=t[e];switch(u&&"object"==typeof u&&"function"==typeof u.toJSON&&(u=u.toJSON(e)),"function"==typeof rep&&(u=rep.call(t,e,u)),typeof u){case"string":return quote(u);case"number":return isFinite(u)?String(u):"null";case"boolean":case"null":return String(u);case"object":if(!u)return"null";if(gap+=indent,o=[],"[object Array]"===Object.prototype.toString.apply(u)){for(i=u.length,r=0;i>r;r+=1)o[r]=str(r,u)||"null";return n=0===o.length?"[]":gap?"[\n"+gap+o.join(",\n"+gap)+"\n"+s+"]":"["+o.join(",")+"]",gap=s,n}if(rep&&"object"==typeof rep)for(i=rep.length,r=0;i>r;r+=1)a=rep[r],"string"==typeof a&&(n=str(a,u),n&&o.push(quote(a)+(gap?": ":":")+n));else for(a in u)Object.hasOwnProperty.call(u,a)&&(n=str(a,u),n&&o.push(quote(a)+(gap?": ":":")+n));return n=0===o.length?"{}":gap?"{\n"+gap+o.join(",\n"+gap)+"\n"+s+"}":"{"+o.join(",")+"}",gap=s,n}}"function"!=typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()});var JSON=window.JSON,cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;"function"!=typeof JSON.stringify&&(JSON.stringify=function(e,t,r){var a;if(gap="",indent="","number"==typeof r)for(a=0;r>a;a+=1)indent+=" ";else"string"==typeof r&&(indent=r);if(rep=t,!t||"function"==typeof t||"object"==typeof t&&"number"==typeof t.length)return str("",{"":e});throw new Error("JSON.stringify")}),"function"!=typeof JSON.parse&&(JSON.parse=function(text,reviver){function walk(e,t){var r,a,n=e[t];if(n&&"object"==typeof n)for(r in n)Object.hasOwnProperty.call(n,r)&&(a=walk(n,r),void 0!==a?n[r]=a:delete n[r]);return reviver.call(e,t,n)}var j;if(text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})),/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return j=eval("("+text+")"),"function"==typeof reviver?walk({"":j},""):j;throw new SyntaxError("JSON.parse")})}(),function(e,t){"use strict";var r=e.History=e.History||{},a=e.jQuery;if("undefined"!=typeof r.Adapter)throw new Error("History.js Adapter has already been loaded...");r.Adapter={bind:function(e,t,r){a(e).bind(t,r)},trigger:function(e,t,r){a(e).trigger(t,r)},extractEventData:function(e,r,a){var n=r&&r.originalEvent&&r.originalEvent[e]||a&&a[e]||t;return n},onDomLoad:function(e){a(e)}},"undefined"!=typeof r.init&&r.init()}(window),function(e){"use strict";var t=e.document,r=e.setTimeout||r,a=e.clearTimeout||a,n=e.setInterval||n,i=e.History=e.History||{};if("undefined"!=typeof i.initHtml4)throw new Error("History.js HTML4 Support has already been loaded...");i.initHtml4=function(){return"undefined"!=typeof i.initHtml4.initialized?!1:(i.initHtml4.initialized=!0,i.enabled=!0,i.savedHashes=[],i.isLastHash=function(e){var t,r=i.getHashByIndex();return t=e===r},i.saveHash=function(e){return i.isLastHash(e)?!1:(i.savedHashes.push(e),!0)},i.getHashByIndex=function(e){var t=null;return t="undefined"==typeof e?i.savedHashes[i.savedHashes.length-1]:0>e?i.savedHashes[i.savedHashes.length+e]:i.savedHashes[e]},i.discardedHashes={},i.discardedStates={},i.discardState=function(e,t,r){var a,n=i.getHashByState(e);return a={discardedState:e,backState:r,forwardState:t},i.discardedStates[n]=a,!0},i.discardHash=function(e,t,r){var a={discardedHash:e,backState:r,forwardState:t};return i.discardedHashes[e]=a,!0},i.discardedState=function(e){var t,r=i.getHashByState(e);return t=i.discardedStates[r]||!1},i.discardedHash=function(e){var t=i.discardedHashes[e]||!1;return t},i.recycleState=function(e){var t=i.getHashByState(e);return i.discardedState(e)&&delete i.discardedStates[t],!0},i.emulated.hashChange&&(i.hashChangeInit=function(){i.checkerFunction=null;var r,a,o,s,u="";return i.isInternetExplorer()?(r="historyjs-iframe",a=t.createElement("iframe"),a.setAttribute("id",r),a.style.display="none",t.body.appendChild(a),a.contentWindow.document.open(),a.contentWindow.document.close(),o="",s=!1,i.checkerFunction=function(){if(s)return!1;s=!0;var t=i.getHash()||"",r=i.unescapeHash(a.contentWindow.document.location.hash)||"";return t!==u?(u=t,r!==t&&(o=r=t,a.contentWindow.document.open(),a.contentWindow.document.close(),a.contentWindow.document.location.hash=i.escapeHash(t)),i.Adapter.trigger(e,"hashchange")):r!==o&&(o=r,i.setHash(r,!1)),s=!1,!0}):i.checkerFunction=function(){var t=i.getHash();return t!==u&&(u=t,i.Adapter.trigger(e,"hashchange")),!0},i.intervalList.push(n(i.checkerFunction,i.options.hashChangeInterval)),!0},i.Adapter.onDomLoad(i.hashChangeInit)),i.emulated.pushState&&(i.onHashChange=function(r){var a,n=r&&r.newURL||t.location.href,o=i.getHashByUrl(n),s=null,u=null;return i.isLastHash(o)?(i.busy(!1),!1):(i.doubleCheckComplete(),i.saveHash(o),o&&i.isTraditionalAnchor(o)?(i.Adapter.trigger(e,"anchorchange"),i.busy(!1),!1):(s=i.extractState(i.getFullUrl(o||t.location.href,!1),!0),i.isLastSavedState(s)?(i.busy(!1),!1):(u=i.getHashByState(s),a=i.discardedState(s),a?(i.getHashByIndex(-2)===i.getHashByState(a.forwardState)?i.back(!1):i.forward(!1),!1):(i.pushState(s.data,s.title,s.url,!1),!0))))},i.Adapter.bind(e,"hashchange",i.onHashChange),i.pushState=function(r,a,n,o){if(i.getHashByUrl(n))throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(o!==!1&&i.busy())return i.pushQueue({scope:i,callback:i.pushState,args:arguments,queue:o}),!1;i.busy(!0);var s=i.createStateObject(r,a,n),u=i.getHashByState(s),l=i.getState(!1),c=i.getHashByState(l),d=i.getHash();return i.storeState(s),i.expectedStateId=s.id,i.recycleState(s),i.setTitle(s),u===c?(i.busy(!1),!1):u!==d&&u!==i.getShortUrl(t.location.href)?(i.setHash(u,!1),!1):(i.saveState(s),i.Adapter.trigger(e,"statechange"),i.busy(!1),!0)},i.replaceState=function(e,t,r,a){if(i.getHashByUrl(r))throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(a!==!1&&i.busy())return i.pushQueue({scope:i,callback:i.replaceState,args:arguments,queue:a}),!1;i.busy(!0);var n=i.createStateObject(e,t,r),o=i.getState(!1),s=i.getStateByIndex(-2);return i.discardState(o,n,s),i.pushState(n.data,n.title,n.url,!1),!0}),i.emulated.pushState&&i.getHash()&&!i.emulated.hashChange&&i.Adapter.onDomLoad(function(){i.Adapter.trigger(e,"hashchange")}),void 0)},"undefined"!=typeof i.init&&i.init()}(window),function(e,t){"use strict";var r=e.console||t,a=e.document,n=e.navigator,i=e.sessionStorage||!1,o=e.setTimeout,s=e.clearTimeout,u=e.setInterval,l=e.clearInterval,c=e.JSON,d=e.alert,f=e.History=e.History||{},h=e.history;if(c.stringify=c.stringify||c.encode,c.parse=c.parse||c.decode,"undefined"!=typeof f.init)throw new Error("History.js Core has already been loaded...");f.init=function(){return"undefined"==typeof f.Adapter?!1:("undefined"!=typeof f.initCore&&f.initCore(),"undefined"!=typeof f.initHtml4&&f.initHtml4(),!0)},f.initCore=function(){if("undefined"!=typeof f.initCore.initialized)return!1;if(f.initCore.initialized=!0,f.options=f.options||{},f.options.hashChangeInterval=f.options.hashChangeInterval||100,f.options.safariPollInterval=f.options.safariPollInterval||500,f.options.doubleCheckInterval=f.options.doubleCheckInterval||500,f.options.storeInterval=f.options.storeInterval||1e3,f.options.busyDelay=f.options.busyDelay||250,f.options.debug=f.options.debug||!1,f.options.initialTitle=f.options.initialTitle||a.title,f.intervalList=[],f.clearAllIntervals=function(){var e,t=f.intervalList;if("undefined"!=typeof t&&null!==t){for(e=0;et;++t){if(o=arguments[t],"object"==typeof o&&"undefined"!=typeof c)try{o=c.stringify(o)}catch(l){}e+="\n"+o+"\n"}return u?(u.value+=e+"\n-----\n",u.scrollTop=u.scrollHeight-u.clientHeight):s||d(e),!0},f.getInternetExplorerMajorVersion=function(){var e=f.getInternetExplorerMajorVersion.cached="undefined"!=typeof f.getInternetExplorerMajorVersion.cached?f.getInternetExplorerMajorVersion.cached:function(){for(var e=3,t=a.createElement("div"),r=t.getElementsByTagName("i");(t.innerHTML="")&&r[0];);return e>4?e:!1}();return e},f.isInternetExplorer=function(){var e=f.isInternetExplorer.cached="undefined"!=typeof f.isInternetExplorer.cached?f.isInternetExplorer.cached:Boolean(f.getInternetExplorerMajorVersion());return e},f.emulated={pushState:!Boolean(e.history&&e.history.pushState&&e.history.replaceState&&!/ Mobile\/([1-7][a-z]|(8([abcde]|f(1[0-8]))))/i.test(n.userAgent)&&!/AppleWebKit\/5([0-2]|3[0-2])/i.test(n.userAgent)),hashChange:Boolean(!("onhashchange"in e||"onhashchange"in a)||f.isInternetExplorer()&&f.getInternetExplorerMajorVersion()<8)},f.enabled=!f.emulated.pushState,f.bugs={setHash:Boolean(!f.emulated.pushState&&"Apple Computer, Inc."===n.vendor&&/AppleWebKit\/5([0-2]|3[0-3])/.test(n.userAgent)),safariPoll:Boolean(!f.emulated.pushState&&"Apple Computer, Inc."===n.vendor&&/AppleWebKit\/5([0-2]|3[0-3])/.test(n.userAgent)),ieDoubleCheck:Boolean(f.isInternetExplorer()&&f.getInternetExplorerMajorVersion()<8),hashEscape:Boolean(f.isInternetExplorer()&&f.getInternetExplorerMajorVersion()<7)},f.isEmptyObject=function(e){for(var t in e)return!1;return!0},f.cloneObject=function(e){var t,r;return e?(t=c.stringify(e),r=c.parse(t)):r={},r},f.getRootUrl=function(){var e=a.location.protocol+"//"+(a.location.hostname||a.location.host);return a.location.port&&(e+=":"+a.location.port),e+="/"},f.getBaseHref=function(){var e=a.getElementsByTagName("base"),t=null,r="";return 1===e.length&&(t=e[0],r=t.href.replace(/[^\/]+$/,"")),r=r.replace(/\/+$/,""),r&&(r+="/"),r},f.getBaseUrl=function(){var e=f.getBaseHref()||f.getBasePageUrl()||f.getRootUrl();return e},f.getPageUrl=function(){var e,t=f.getState(!1,!1),r=(t||{}).url||a.location.href;return e=r.replace(/\/+$/,"").replace(/[^\/]+$/,function(e){return/\./.test(e)?e:e+"/"})},f.getBasePageUrl=function(){var e=a.location.href.replace(/[#\?].*/,"").replace(/[^\/]+$/,function(e){return/[^\/]$/.test(e)?"":e}).replace(/\/+$/,"")+"/";return e},f.getFullUrl=function(e,t){var r=e,a=e.substring(0,1);return t="undefined"==typeof t?!0:t,/[a-z]+\:\/\//.test(e)||(r="/"===a?f.getRootUrl()+e.replace(/^\/+/,""):"#"===a?f.getPageUrl().replace(/#.*/,"")+e:"?"===a?f.getPageUrl().replace(/[\?#].*/,"")+e:t?f.getBaseUrl()+e.replace(/^(\.\/)+/,""):f.getBasePageUrl()+e.replace(/^(\.\/)+/,"")),r.replace(/\#$/,"")},f.getShortUrl=function(e){var t=e,r=f.getBaseUrl(),a=f.getRootUrl();return f.emulated.pushState&&(t=t.replace(r,"")),t=t.replace(a,"/"),f.isTraditionalAnchor(t)&&(t="./"+t),t=t.replace(/^(\.\/)+/g,"./").replace(/\#$/,"")},f.store={},f.idToState=f.idToState||{},f.stateToId=f.stateToId||{},f.urlToId=f.urlToId||{},f.storedStates=f.storedStates||[],f.savedStates=f.savedStates||[],f.normalizeStore=function(){f.store.idToState=f.store.idToState||{},f.store.urlToId=f.store.urlToId||{},f.store.stateToId=f.store.stateToId||{}},f.getState=function(e,t){"undefined"==typeof e&&(e=!0),"undefined"==typeof t&&(t=!0);var r=f.getLastSavedState();return!r&&t&&(r=f.createStateObject()),e&&(r=f.cloneObject(r),r.url=r.cleanUrl||r.url),r},f.getIdByState=function(e){var t,r=f.extractId(e.url);if(!r)if(t=f.getStateString(e),"undefined"!=typeof f.stateToId[t])r=f.stateToId[t];else if("undefined"!=typeof f.store.stateToId[t])r=f.store.stateToId[t];else{for(;r=(new Date).getTime()+String(Math.random()).replace(/\D/g,""),"undefined"!=typeof f.idToState[r]||"undefined"!=typeof f.store.idToState[r];);f.stateToId[t]=r,f.idToState[r]=e}return r},f.normalizeState=function(e){var t,r;return e&&"object"==typeof e||(e={}),"undefined"!=typeof e.normalized?e:(e.data&&"object"==typeof e.data||(e.data={}),t={},t.normalized=!0,t.title=e.title||"",t.url=f.getFullUrl(f.unescapeString(e.url||a.location.href)),t.hash=f.getShortUrl(t.url),t.data=f.cloneObject(e.data),t.id=f.getIdByState(t),t.cleanUrl=t.url.replace(/\??\&_suid.*/,""),t.url=t.cleanUrl,r=!f.isEmptyObject(t.data),(t.title||r)&&(t.hash=f.getShortUrl(t.url).replace(/\??\&_suid.*/,""),/\?/.test(t.hash)||(t.hash+="?"),t.hash+="&_suid="+t.id),t.hashedUrl=f.getFullUrl(t.hash),(f.emulated.pushState||f.bugs.safariPoll)&&f.hasUrlDuplicate(t)&&(t.url=t.hashedUrl),t)},f.createStateObject=function(e,t,r){var a={data:e,title:t,url:r};return a=f.normalizeState(a)},f.getStateById=function(e){e=String(e);var r=f.idToState[e]||f.store.idToState[e]||t;return r},f.getStateString=function(e){var t,r,a;return t=f.normalizeState(e),r={data:t.data,title:e.title,url:e.url},a=c.stringify(r)},f.getStateId=function(e){var t,r;return t=f.normalizeState(e),r=t.id},f.getHashByState=function(e){var t,r;return t=f.normalizeState(e),r=t.hash},f.extractId=function(e){var t,r,a;return r=/(.*)\&_suid=([0-9]+)$/.exec(e),a=r?r[1]||e:e,t=r?String(r[2]||""):"",t||!1},f.isTraditionalAnchor=function(e){var t=!/[\/\?\.]/.test(e);return t},f.extractState=function(e,t){var r,a,n=null;return t=t||!1,r=f.extractId(e),r&&(n=f.getStateById(r)),n||(a=f.getFullUrl(e),r=f.getIdByUrl(a)||!1,r&&(n=f.getStateById(r)),!n&&t&&!f.isTraditionalAnchor(e)&&(n=f.createStateObject(null,null,a))),n},f.getIdByUrl=function(e){var r=f.urlToId[e]||f.store.urlToId[e]||t;return r},f.getLastSavedState=function(){return f.savedStates[f.savedStates.length-1]||t},f.getLastStoredState=function(){return f.storedStates[f.storedStates.length-1]||t},f.hasUrlDuplicate=function(e){var t,r=!1;return t=f.extractState(e.url),r=t&&t.id!==e.id},f.storeState=function(e){return f.urlToId[e.url]=e.id,f.storedStates.push(f.cloneObject(e)),e},f.isLastSavedState=function(e){var t,r,a,n=!1;return f.savedStates.length&&(t=e.id,r=f.getLastSavedState(),a=r.id,n=t===a),n},f.saveState=function(e){return f.isLastSavedState(e)?!1:(f.savedStates.push(f.cloneObject(e)),!0)},f.getStateByIndex=function(e){var t=null;return t="undefined"==typeof e?f.savedStates[f.savedStates.length-1]:0>e?f.savedStates[f.savedStates.length+e]:f.savedStates[e]},f.getHash=function(){var e=f.unescapeHash(a.location.hash);return e},f.unescapeString=function(t){for(var r,a=t;r=e.unescape(a),r!==a;)a=r;return a},f.unescapeHash=function(e){var t=f.normalizeHash(e);return t=f.unescapeString(t)},f.normalizeHash=function(e){var t=e.replace(/[^#]*#/,"").replace(/#.*/,"");return t},f.setHash=function(e,t){var r,n,i;return t!==!1&&f.busy()?(f.pushQueue({scope:f,callback:f.setHash,args:arguments,queue:t}),!1):(r=f.escapeHash(e),f.busy(!0),n=f.extractState(e,!0),n&&!f.emulated.pushState?f.pushState(n.data,n.title,n.url,!1):a.location.hash!==r&&(f.bugs.setHash?(i=f.getPageUrl(),f.pushState(null,null,i+"#"+r,!1)):a.location.hash=r),f)},f.escapeHash=function(t){var r=f.normalizeHash(t);return r=e.escape(r),f.bugs.hashEscape||(r=r.replace(/\%21/g,"!").replace(/\%26/g,"&").replace(/\%3D/g,"=").replace(/\%3F/g,"?")),r},f.getHashByUrl=function(e){var t=String(e).replace(/([^#]*)#?([^#]*)#?(.*)/,"$2");return t=f.unescapeHash(t)},f.setTitle=function(e){var t,r=e.title;r||(t=f.getStateByIndex(0),t&&t.url===e.url&&(r=t.title||f.options.initialTitle));try{a.getElementsByTagName("title")[0].innerHTML=r.replace("<","<").replace(">",">").replace(" & "," & ")}catch(n){}return a.title=r,f},f.queues=[],f.busy=function(e){if("undefined"!=typeof e?f.busy.flag=e:"undefined"==typeof f.busy.flag&&(f.busy.flag=!1),!f.busy.flag){s(f.busy.timeout);var t=function(){var e,r,a;if(!f.busy.flag)for(e=f.queues.length-1;e>=0;--e)r=f.queues[e],0!==r.length&&(a=r.shift(),f.fireQueueItem(a),f.busy.timeout=o(t,f.options.busyDelay))};f.busy.timeout=o(t,f.options.busyDelay)}return f.busy.flag},f.busy.flag=!1,f.fireQueueItem=function(e){return e.callback.apply(e.scope||f,e.args||[])},f.pushQueue=function(e){return f.queues[e.queue||0]=f.queues[e.queue||0]||[],f.queues[e.queue||0].push(e),f},f.queue=function(e,t){return"function"==typeof e&&(e={callback:e}),"undefined"!=typeof t&&(e.queue=t),f.busy()?f.pushQueue(e):f.fireQueueItem(e),f},f.clearQueue=function(){return f.busy.flag=!1,f.queues=[],f},f.stateChanged=!1,f.doubleChecker=!1,f.doubleCheckComplete=function(){return f.stateChanged=!0,f.doubleCheckClear(),f},f.doubleCheckClear=function(){return f.doubleChecker&&(s(f.doubleChecker),f.doubleChecker=!1),f},f.doubleCheck=function(e){return f.stateChanged=!1,f.doubleCheckClear(),f.bugs.ieDoubleCheck&&(f.doubleChecker=o(function(){return f.doubleCheckClear(),f.stateChanged||e(),!0},f.options.doubleCheckInterval)),f},f.safariStatePoll=function(){var t,r=f.extractState(a.location.href);if(!f.isLastSavedState(r))return t=r,t||(t=f.createStateObject()),f.Adapter.trigger(e,"popstate"),f},f.back=function(e){return e!==!1&&f.busy()?(f.pushQueue({scope:f,callback:f.back,args:arguments,queue:e}),!1):(f.busy(!0),f.doubleCheck(function(){f.back(!1)}),h.go(-1),!0)},f.forward=function(e){return e!==!1&&f.busy()?(f.pushQueue({scope:f,callback:f.forward,args:arguments,queue:e}),!1):(f.busy(!0),f.doubleCheck(function(){f.forward(!1)}),h.go(1),!0)},f.go=function(e,t){var r;if(e>0)for(r=1;e>=r;++r)f.forward(t);else{if(!(0>e))throw new Error("History.go: History.go requires a positive or negative integer passed.");for(r=-1;r>=e;--r)f.back(t)}return f},f.emulated.pushState){var p=function(){};f.pushState=f.pushState||p,f.replaceState=f.replaceState||p}else f.onPopState=function(t,r){var n,i,o=!1,s=!1;return f.doubleCheckComplete(),n=f.getHash(),n?(i=f.extractState(n||a.location.href,!0),i?f.replaceState(i.data,i.title,i.url,!1):(f.Adapter.trigger(e,"anchorchange"),f.busy(!1)),f.expectedStateId=!1,!1):(o=f.Adapter.extractEventData("state",t,r)||!1,s=o?f.getStateById(o):f.expectedStateId?f.getStateById(f.expectedStateId):f.extractState(a.location.href),s||(s=f.createStateObject(null,null,a.location.href)),f.expectedStateId=!1,f.isLastSavedState(s)?(f.busy(!1),!1):(f.storeState(s),f.saveState(s),f.setTitle(s),f.Adapter.trigger(e,"statechange"),f.busy(!1),!0))},f.Adapter.bind(e,"popstate",f.onPopState),f.pushState=function(t,r,a,n){if(f.getHashByUrl(a)&&f.emulated.pushState)throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(n!==!1&&f.busy())return f.pushQueue({scope:f,callback:f.pushState,args:arguments,queue:n}),!1;f.busy(!0);var i=f.createStateObject(t,r,a);return f.isLastSavedState(i)?f.busy(!1):(f.storeState(i),f.expectedStateId=i.id,h.pushState(i.id,i.title,i.url),f.Adapter.trigger(e,"popstate")),!0},f.replaceState=function(t,r,a,n){if(f.getHashByUrl(a)&&f.emulated.pushState)throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(n!==!1&&f.busy())return f.pushQueue({scope:f,callback:f.replaceState,args:arguments,queue:n}),!1;f.busy(!0);var i=f.createStateObject(t,r,a);return f.isLastSavedState(i)?f.busy(!1):(f.storeState(i),f.expectedStateId=i.id,h.replaceState(i.id,i.title,i.url),f.Adapter.trigger(e,"popstate")),!0};if(i){try{f.store=c.parse(i.getItem("History.store"))||{}}catch(g){f.store={}}f.normalizeStore()}else f.store={},f.normalizeStore();f.Adapter.bind(e,"beforeunload",f.clearAllIntervals),f.Adapter.bind(e,"unload",f.clearAllIntervals),f.saveState(f.storeState(f.extractState(a.location.href,!0))),i&&(f.onUnload=function(){var e,t;try{e=c.parse(i.getItem("History.store"))||{}}catch(r){e={}}e.idToState=e.idToState||{},e.urlToId=e.urlToId||{},e.stateToId=e.stateToId||{};for(t in f.idToState)f.idToState.hasOwnProperty(t)&&(e.idToState[t]=f.idToState[t]);for(t in f.urlToId)f.urlToId.hasOwnProperty(t)&&(e.urlToId[t]=f.urlToId[t]);for(t in f.stateToId)f.stateToId.hasOwnProperty(t)&&(e.stateToId[t]=f.stateToId[t]);f.store=e,f.normalizeStore(),i.setItem("History.store",c.stringify(e))},f.intervalList.push(u(f.onUnload,f.options.storeInterval)),f.Adapter.bind(e,"beforeunload",f.onUnload),f.Adapter.bind(e,"unload",f.onUnload)),f.emulated.pushState||(f.bugs.safariPoll&&f.intervalList.push(u(f.safariStatePoll,f.options.safariPollInterval)),("Apple Computer, Inc."===n.vendor||"Mozilla"===(n.appCodeName||""))&&(f.Adapter.bind(e,"hashchange",function(){f.Adapter.trigger(e,"popstate")}),f.getHash()&&f.Adapter.onDomLoad(function(){f.Adapter.trigger(e,"hashchange")})))},f.init()}(window),jQuery.refresh={ajaxCalls:new Array,refreshTimers:new Array,defaultCache:!1},function(e){e.fn.getSelector=function(){var t=e(this);if(t.is("body"))return"body";if(e.isWindow(t[0]))return t=null,window;var r=t.attr("id");return r||(r="me-"+Math.floor(1e6*Math.random()),t.attr("id",r)),t=null,"#"+r},e.fn.stopRefresh=function(){var t=e(this);t.trigger("stoprefresh");var r=t.getSelector(),a=e.refresh.refreshTimers[r];a&&(clearInterval(a),delete a);var n=e.refresh.ajaxCalls[r];n&&(n.abort(),delete n)},e.fn.defaultRefreshInsert=function(t){e(this).html(t.html),e(this).trigger({type:"finishrefreshinsert"})},e.fn.refresh=function(t){var r=e(this),a=r.getSelector();"boolean"==typeof t&&(t={refresh:t}),t=e.extend({html:null,refresh:r,resetInterval:!0,url:null,content:a,clickedSelector:e(this).getSelector(),callback:function(){},cache:e.refresh.defaultCache,insertFunction:e.navigate.defaultInsertFunction,customData:null,timeout:8e3},t);var n=r.attr("data-refresh-function");if("undefined"!=typeof n)r[n]?r[n]():n();else if(t.refresh){var i=e.refresh.ajaxCalls[a];i&&(r.trigger("stoprefresh"),i.abort());var o=t.url;if(!o){var s=r.attr("data-refresh-url");o=s?s:window.location.href}var u=r.attr("data-refresh-id");r.trigger({type:"startrefresh",clickedSelector:t.clickedSelector});var l=function(a){i=null;var n=//,o=a.match(n);o&&o.length>0?(o=o[0].replace(/^$/,"div>")):o=a;var n=//,s=a.match(n);s&&s.length>0?(s=s[0].replace(/^$/,"div>"),s=e(s).html()):s="";var l=o.match(/]*>([\s\S]*?)<\/noscript>/gm);o=o.replace(new RegExp("","g"),"div>");var c=o.match(/]*>([\s\S]*?)<\/script>/gm);if(o=o.replace(new RegExp("","g"),"div>"),"body"!=t.content)var d=e(t.content,"
"+o+"
");else var d=e(o);var f=d.attr("data-refresh-id");if(u&&f&&u==f)return void r.trigger({type:"cancelrefresh",clickedSelector:t.clickedSelector});var h="",p=d.find(".temp-script").remove();if(d.each(function(){h+=e(this).html()}),myScriptsHtml="",c)for(var g=0;g"+h+"").children().each(function(){e(this)[S](r)}),r.trigger({type:"finishrefreshinsert"})):r[S]({html:h,head:s,scripts:myScriptsHtml,customData:t.customData,"class":d.attr("class")}):window[S]&&window[S]({html:h,head:s,scripts:p,customData:t.customData,"class":d.attr("class")})};t.html?l(t.html):i=e.ajax({type:"GET",cache:t.cache,context:r,url:o,timeout:t.timeout,dataType:"html"}).done(l).fail(function(r,a){i.abort(),i=null,e(this).trigger({type:"failrefresh",clickedSelector:t.clickedSelector,status:a})})}else r.trigger({type:"donerefresh",clickedSelector:t.clickedSelector});var c=e.refresh.refreshTimers[a];t.resetInterval&&c&&(clearInterval(c),delete c);var d=r.attr("data-refresh-interval");d&&(d=parseInt(d),t.resetInterval&&d>0&&(e.refresh.refreshTimers[a]=setInterval(function(){r.refresh({refresh:!0,resetInterval:!1})},d)))}}(jQuery),jQuery.navigate={active:!1,historyStates:new Array,defaultCache:!0,ajaxLinks:'a:not(.noAjax)[rel!="external"][target!="_blank"], .ajaxLink',discreteLinks:'a:not(.noAjax)[rel!="external"][target!="_blank"], .ajaxLink',defaultInsertFunction:"defaultRefreshInsert",stateChanged:function(){var e=History.getState(!1,!1),t=(0==History.getState().internal,$(e.data.target?e.data.target:"body")),r=(e.data.content?" "+e.data.content:"",null);if(History.savedStates.length>1&&(r=History.getStateByIndex(-2)),null==r)return("undefined"==typeof Modernizr||Modernizr.touch)&&$("body").find($.navigate.discreteLinks).each(function(){$(this).discreteClick()}),void $("body").refresh({refresh:!1});var a=$(r.data.target?r.data.target:"body");a.stopRefresh();var n={refresh:!0,url:e.url,content:e.data.content,status:e.data.status,html:e.data.html,clickedSelector:e.data.clickedSelector,callback:function(){("undefined"==typeof Modernizr||Modernizr.touch)&&t.find($.navigate.discreteLinks).each(function(){$(this).discreteClick()})},cache:$.navigate.defaultCache,customData:e.data.customData,timeout:$.navigate.timeout};return e.data.insertFunction&&(n.insertFunction=e.data.insertFunction),t.refresh(n),!1},init:function(e){if(e=$.extend({ajaxLinks:this.ajaxLinks,discreteLinks:this.discreteLinks,defaultInsertFunction:$.navigate.defaultInsertFunction,timeout:8e3},e),this.active=e.active,this.defaultInsertFunction=e.defaultInsertFunction,this.ajaxLinks=e.ajaxLinks,this.discreteLinks=e.discreteLinks,this.timeout=e.timeout,"undefined"==typeof e.active&&("undefined"==typeof Modernizr?(console.log('if not specified any other "active" parameter, navigate tests Modernizr.history to get active, Modernizr undefined => navigate will not get active'),this.active=!1):this.active=Modernizr.history),!this.active)return void $("body").trigger("donerefresh");var t=window.History;return t.enabled?($("html").on("click",$.navigate.ajaxLinks,function(){var e=$(this);return e.navigate()}),t.Adapter.bind(window,"statechange",$.navigate.stateChanged),void $.navigate.stateChanged()):!1}},function(e){e.fn.getSelector=function(){var t=e(this);if(t.is("body"))return"body";if(e.isWindow(t[0]))return t=null,window;var r=t.attr("id");return r||(r="me-"+Math.floor(1e6*Math.random()),t.attr("id",r)),t=null,"#"+r},e.fn.discreteClick=function(){var t=e(this);"javascript://"!=t.attr("href")&&(t.attr("data-ajax-href",t.attr("href")),t.attr("href","javascript://"))},e.fn.navigate=function(t){var r=e(this),a={html:null},n=r.attr("data-ajax-href");if(n||(n=r.attr("href")),"javascript://"==n)return!0;n||(n=document.location.href);var i=window.location.href.substring(0,window.location.href.lastIndexOf("/")+1);n=n.replace(i,""),a.url=n;var o=r.attr("data-ajax-content");o||(o="body"),a.content=o;var s=r.attr("data-ajax-target");s||(s=r.attr("data-target")),s||(s="body"),a.target=s;var u=r.attr("title");u||(u=document.title),a.title=u;var l=e(s).attr("data-refresh-status");l||(l=null),a.status=l;var c=r.attr("data-refresh-insert-function");return c||(c=r.attr("data-ajax-insert")),c||(c=r.attr("data-insert-function")),c||(c=null),a.insertFunction=c,t=e.extend(a,t),History.pushState({target:t.target,content:t.content,insertFunction:t.insertFunction,status:t.status,clickedSelector:e(this).getSelector(),html:t.html,customData:t.customData},t.title,t.url),!1}}(jQuery); 3 | --------------------------------------------------------------------------------