Template:Team:HokkaidoU Japan/Book/JS
From 2014.igem.org
(Difference between revisions)
Line 34: | Line 34: | ||
*/ | */ | ||
(function(a){function d(b){var c=b||window.event,d=[].slice.call(arguments,1),e=0,f=!0,g=0,h=0;return b=a.event.fix(c),b.type="mousewheel",c.wheelDelta&&(e=c.wheelDelta/120),c.detail&&(e=-c.detail/3),h=e,c.axis!==undefined&&c.axis===c.HORIZONTAL_AXIS&&(h=0,g=-1*e),c.wheelDeltaY!==undefined&&(h=c.wheelDeltaY/120),c.wheelDeltaX!==undefined&&(g=-1*c.wheelDeltaX/120),d.unshift(b,e,g,h),(a.event.dispatch||a.event.handle).apply(this,d)}var b=["DOMMouseScroll","mousewheel"];if(a.event.fixHooks)for(var c=b.length;c;)a.event.fixHooks[b[--c]]=a.event.mouseHooks;a.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=b.length;a;)this.addEventListener(b[--a],d,!1);else this.onmousewheel=d},teardown:function(){if(this.removeEventListener)for(var a=b.length;a;)this.removeEventListener(b[--a],d,!1);else this.onmousewheel=null}},a.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery) | (function(a){function d(b){var c=b||window.event,d=[].slice.call(arguments,1),e=0,f=!0,g=0,h=0;return b=a.event.fix(c),b.type="mousewheel",c.wheelDelta&&(e=c.wheelDelta/120),c.detail&&(e=-c.detail/3),h=e,c.axis!==undefined&&c.axis===c.HORIZONTAL_AXIS&&(h=0,g=-1*e),c.wheelDeltaY!==undefined&&(h=c.wheelDeltaY/120),c.wheelDeltaX!==undefined&&(g=-1*c.wheelDeltaX/120),d.unshift(b,e,g,h),(a.event.dispatch||a.event.handle).apply(this,d)}var b=["DOMMouseScroll","mousewheel"];if(a.event.fixHooks)for(var c=b.length;c;)a.event.fixHooks[b[--c]]=a.event.mouseHooks;a.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=b.length;a;)this.addEventListener(b[--a],d,!1);else this.onmousewheel=d},teardown:function(){if(this.removeEventListener)for(var a=b.length;a;)this.removeEventListener(b[--a],d,!1);else this.onmousewheel=null}},a.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery) | ||
+ | |||
+ | /** | ||
+ | * hash.js | ||
+ | * | ||
+ | * Copyright (C) 2012 Emmanuel Garcia | ||
+ | * MIT Licensed | ||
+ | * | ||
+ | * **************************************** | ||
+ | * | ||
+ | * Hash.pushState(true); | ||
+ | * | ||
+ | * Hash.on('/page/([0-9]+)$', | ||
+ | * {yep: function(path, parts) { }, nop: function() { }}, | ||
+ | * 'Page $1'); | ||
+ | * | ||
+ | * Hash.go('/page/1'); | ||
+ | **/ | ||
+ | |||
+ | (function() { | ||
+ | |||
+ | 'use strict'; | ||
+ | |||
+ | var hashes = {}, | ||
+ | regexp = {}, | ||
+ | history = [], | ||
+ | freq = 100, | ||
+ | num = 0, | ||
+ | pushState = false, | ||
+ | timer = null, | ||
+ | currentUrl = null, | ||
+ | |||
+ | freeze = function(obj) { | ||
+ | if (Object.freeze) return Object.freeze(obj); | ||
+ | return obj; | ||
+ | }, | ||
+ | |||
+ | getHashParts = function() { | ||
+ | return window.location.href.split('#'); | ||
+ | }, | ||
+ | |||
+ | startTimer = function() { | ||
+ | |||
+ | if (!timer) | ||
+ | timer = setInterval(function() { | ||
+ | if (num>0 && currentUrl!=window.location.href) { | ||
+ | currentUrl = window.location.href; | ||
+ | window.Hash.check(); | ||
+ | } | ||
+ | }, freq); | ||
+ | |||
+ | }, | ||
+ | |||
+ | stopTimer = function() { | ||
+ | |||
+ | if (timer) { | ||
+ | clearInterval(timer); | ||
+ | timer = null; | ||
+ | } | ||
+ | |||
+ | }; | ||
+ | |||
+ | window.Hash = freeze({ | ||
+ | |||
+ | pushState: function(yes) { | ||
+ | |||
+ | if (window.history && window.history.pushState) | ||
+ | pushState = yes; | ||
+ | |||
+ | return this; | ||
+ | }, | ||
+ | |||
+ | fragment: function() { | ||
+ | |||
+ | var hash = getHashParts(); | ||
+ | return (pushState) ? | ||
+ | window.location.pathname + ((hash[1]) ? '#' + hash[1] : '') | ||
+ | : hash[1] || ''; | ||
+ | |||
+ | }, | ||
+ | |||
+ | get: function(path, params) { | ||
+ | |||
+ | var p, fragment = '', parameters = []; | ||
+ | |||
+ | for(p in params) { | ||
+ | if (!Object.prototype.hasOwnProperty(p)) | ||
+ | continue; | ||
+ | parameters.push(encodeURIComponent(p) + '=' + encodeURIComponent(params[p])); | ||
+ | } | ||
+ | |||
+ | if (parameters.length>0) | ||
+ | parameters = '?' + parameters.join('&'); | ||
+ | |||
+ | return (pushState) ? path + parameters : | ||
+ | getHashParts()[0] + '#' + path + parameters; | ||
+ | |||
+ | }, | ||
+ | |||
+ | go: function(hash, params) { | ||
+ | |||
+ | if (this.fragment()!=hash) { | ||
+ | var to = this.get(hash, params); | ||
+ | |||
+ | if (pushState) | ||
+ | window.history.pushState(null, document.title, to); | ||
+ | else | ||
+ | window.location.href = to; | ||
+ | } | ||
+ | |||
+ | return this; | ||
+ | }, | ||
+ | |||
+ | update: function () { | ||
+ | |||
+ | currentUrl = window.location.href; | ||
+ | return this; | ||
+ | |||
+ | }, | ||
+ | |||
+ | on: function(hash, callback, title) { | ||
+ | |||
+ | if (!hashes[hash]) | ||
+ | hashes[hash] = {title: title, listeners: []}; | ||
+ | |||
+ | hashes[hash].listeners.push(callback); | ||
+ | num++; | ||
+ | startTimer(); | ||
+ | |||
+ | return this; | ||
+ | }, | ||
+ | |||
+ | check: function() { | ||
+ | |||
+ | var i, | ||
+ | hash, | ||
+ | parts, | ||
+ | fragment = this.fragment(); | ||
+ | |||
+ | |||
+ | for (hash in hashes) { | ||
+ | if (!Object.prototype.hasOwnProperty.call(hashes, hash)) | ||
+ | continue; | ||
+ | |||
+ | hashes[hash].regexp = hashes[hash].regexp || new RegExp(hash); | ||
+ | |||
+ | if ((parts = hashes[hash].regexp.exec(fragment))) { | ||
+ | if (hashes[hash].title) | ||
+ | document.title = hashes[hash].title; | ||
+ | |||
+ | for (i = 0; i<hashes[hash].listeners.length; i++) | ||
+ | if (hashes[hash].listeners[i].yep) | ||
+ | hashes[hash].listeners[i].yep(fragment, parts); | ||
+ | } else { | ||
+ | for (i = 0; i<hashes[hash].listeners.length; i++) | ||
+ | if (hashes[hash].listeners[i].nop) | ||
+ | hashes[hash].listeners[i].nop(fragment); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | return this; | ||
+ | } | ||
+ | }); | ||
+ | |||
+ | })(); | ||
+ | |||
Revision as of 04:26, 14 September 2014