mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-11 05:49:31 -06:00
16 lines
4.7 KiB
JavaScript
16 lines
4.7 KiB
JavaScript
/*
|
|
MIT License {@link http://creativecommons.org/licenses/MIT/}
|
|
MIT License {@link http://creativecommons.org/licenses/MIT/}
|
|
*/
|
|
"undefined"===typeof window.console&&(window.console={});
|
|
"undefined"===typeof window.console.emulated&&("function"===typeof window.console.log?window.console.hasLog=!0:("undefined"===typeof window.console.log&&(window.console.log=function(){}),window.console.hasLog=!1),"function"===typeof window.console.debug?window.console.hasDebug=!0:("undefined"===typeof window.console.debug&&(window.console.debug=!window.console.hasLog?function(){}:function(){for(var b=["console.debug:"],a=0;a<arguments.length;a++)b.push(arguments[a]);window.console.log.apply(window.console,
|
|
b)}),window.console.hasDebug=!1),"function"===typeof window.console.warn?window.console.hasWarn=!0:("undefined"===typeof window.console.warn&&(window.console.warn=!window.console.hasLog?function(){}:function(){for(var b=["console.warn:"],a=0;a<arguments.length;a++)b.push(arguments[a]);window.console.log.apply(window.console,b)}),window.console.hasWarn=!1),"function"===typeof window.console.error?window.console.hasError=!0:("undefined"===typeof window.console.error&&(window.console.error=function(){var b=
|
|
"An error has occured.";if(window.console.hasLog){for(var b=["console.error:"],a=0;a<arguments.length;a++)b.push(arguments[a]);window.console.log.apply(window.console,b);b="An error has occured. More information is available in your browser's javascript console."}for(a=0;a<arguments.length;++a){if(typeof arguments[a]!=="string")break;b=b+("\n"+arguments[a])}if(typeof Error!=="undefined")throw Error(b);throw b;}),window.console.hasError=!1),"function"===typeof window.console.trace?window.console.hasTrace=
|
|
!0:("undefined"===typeof window.console.trace&&(window.console.trace=function(){window.console.error("console.trace does not exist")}),window.console.hasTrace=!1),window.console.emulated=!0);
|
|
(function(b){if(b.History)window.console.warn("$.History has already been defined...");else{b.History={options:{debug:false},state:"",$window:null,$iframe:null,handlers:{generic:[],specific:{}},extractHash:function(a){return a.replace(/^[^#]*#/,"").replace(/^#+|#+$/,"")},getState:function(){return b.History.state},setState:function(a){var c=b.History,a=c.extractHash(a);c.state=a;return c.state},getHash:function(){return b.History.extractHash(window.location.hash||location.hash)},setHash:function(a){a=
|
|
b.History.extractHash(a);if(typeof window.location.hash!=="undefined"){if(window.location.hash!==a)window.location.hash=a}else if(location.hash!==a)location.hash=a;return a},go:function(a){var c=b.History,a=c.extractHash(a),d=c.getHash(),f=c.getState();if(a!==d)c.setHash(a);else{a!==f&&c.setState(a);c.trigger()}return true},hashchange:function(){var a=b.History,c=a.getHash();a.go(c);return true},bind:function(a,c){var d=b.History;if(c){typeof d.handlers.specific[a]==="undefined"&&(d.handlers.specific[a]=
|
|
[]);d.handlers.specific[a].push(c)}else d.handlers.generic.push(a);return true},trigger:function(a){var c=b.History;typeof a==="undefined"&&(a=c.getState());var d,f,g,e;if(typeof c.handlers.specific[a]!=="undefined"){e=c.handlers.specific[a];d=0;for(f=e.length;d<f;++d){g=e[d];g(a)}}e=c.handlers.generic;d=0;for(f=e.length;d<f;++d){g=e[d];g(a)}return true},construct:function(){var a=b.History;b(document).ready(function(){a.domReady()});return true},configure:function(a){var c=b.History;c.options=b.extend(c.options,
|
|
a);return true},domReadied:false,domReady:function(){var a=b.History;if(!a.domRedied){a.domRedied=true;a.$window=b(window);a.$window.bind("hashchange",this.hashchange);setTimeout(a.hashchangeLoader,200);return true}},nativeSupport:function(a){var a=a||b.browser,c=a.version,d=parseInt(c,10),f=c.split(/[^0-9]/g),c=parseInt(f[0],10),g=parseInt(f[1],10),f=parseInt(f[2],10),e=false;a.msie&&d>=8?e=true:a.webkit&&d>=528?e=true:a.mozilla?c>1?e=true:c===1&&(g>9?e=true:g===9&&f>=2&&(e=true)):a.opera&&(c>10?
|
|
e=true:c===10&&g>=60&&(e=true));return e},hashchangeLoader:function(){var a=b.History;if(a.nativeSupport())a.getHash()&&a.$window.trigger("hashchange");else{var c;if(b.browser.msie){a.$iframe=b('<iframe id="jquery-history-iframe" style="display: none;"></$iframe>').prependTo(document.body)[0];a.$iframe.contentWindow.document.open();a.$iframe.contentWindow.document.close();var d=false;c=function(){var b=a.getHash(),c=a.getState(),e=a.extractHash(a.$iframe.contentWindow.document.location.hash);if(c!==
|
|
b){if(!d){a.$iframe.contentWindow.document.open();a.$iframe.contentWindow.document.close();a.$iframe.contentWindow.document.location.hash=b}d=false;a.$window.trigger("hashchange")}else if(c!==e){d=true;a.setHash(e)}}}else c=function(){var b=a.getHash();a.getState()!==b&&a.$window.trigger("hashchange")};setInterval(c,200)}return true}};b.History.construct()}})(jQuery);
|