osu-wayback/static/components/sidebar.min.js
2018-01-12 23:16:10 +01:00

1 line
13 KiB
JavaScript

!function(e,i,n,t){"use strict";i=void 0!==i&&i.Math==Math?i:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),e.fn.sidebar=function(t){var o,r=e(this),s=e(i),a=e(n),l=e("html"),c=e("head"),d=r.selector||"",u=(new Date).getTime(),f=[],b=arguments[0],h="string"==typeof b,m=[].slice.call(arguments,1),v=i.requestAnimationFrame||i.mozRequestAnimationFrame||i.webkitRequestAnimationFrame||i.msRequestAnimationFrame||function(e){setTimeout(e,0)};return r.each(function(){var r,g,p,y,C,k,w=e.isPlainObject(t)?e.extend(!0,{},e.fn.sidebar.settings,t):e.extend({},e.fn.sidebar.settings),T=w.selector,x=w.className,S=w.namespace,A=w.regExp,F=w.error,O="."+S,P="module-"+S,E=e(this),H=e(w.context),M=E.children(T.sidebar),D=H.children(T.fixed),j=H.children(T.pusher),R=this,z=E.data(P);k={initialize:function(){k.debug("Initializing sidebar",t),k.create.id(),C=k.get.transitionEvent(),w.delaySetup?v(k.setup.layout):k.setup.layout(),v(function(){k.setup.cache()}),k.instantiate()},instantiate:function(){k.verbose("Storing instance of module",k),z=k,E.data(P,k)},create:{id:function(){p=(Math.random().toString(16)+"000000000").substr(2,8),g="."+p,k.verbose("Creating unique id for element",p)}},destroy:function(){k.verbose("Destroying previous module for",E),E.off(O).removeData(P),k.is.ios()&&k.remove.ios(),H.off(g),s.off(g),a.off(g)},event:{clickaway:function(e){var i=j.find(e.target).length>0||j.is(e.target),n=H.is(e.target);i&&(k.verbose("User clicked on dimmed page"),k.hide()),n&&(k.verbose("User clicked on dimmable context (scaled out page)"),k.hide())},touch:function(e){},containScroll:function(e){R.scrollTop<=0&&(R.scrollTop=1),R.scrollTop+R.offsetHeight>=R.scrollHeight&&(R.scrollTop=R.scrollHeight-R.offsetHeight-1)},scroll:function(i){0===e(i.target).closest(T.sidebar).length&&i.preventDefault()}},bind:{clickaway:function(){k.verbose("Adding clickaway events to context",H),w.closable&&H.on("click"+g,k.event.clickaway).on("touchend"+g,k.event.clickaway)},scrollLock:function(){w.scrollLock&&(k.debug("Disabling page scroll"),s.on("DOMMouseScroll"+g,k.event.scroll)),k.verbose("Adding events to contain sidebar scroll"),a.on("touchmove"+g,k.event.touch),E.on("scroll"+O,k.event.containScroll)}},unbind:{clickaway:function(){k.verbose("Removing clickaway events from context",H),H.off(g)},scrollLock:function(){k.verbose("Removing scroll lock from page"),a.off(g),s.off(g),E.off("scroll"+O)}},add:{inlineCSS:function(){var i,n=k.cache.width||E.outerWidth(),t=k.cache.height||E.outerHeight(),o=k.is.rtl(),s=k.get.direction(),a={left:n,right:-n,top:t,bottom:-t};o&&(k.verbose("RTL detected, flipping widths"),a.left=-n,a.right=n),i="<style>","left"===s||"right"===s?(k.debug("Adding CSS rules for animation distance",n),i+=" .ui.visible."+s+".sidebar ~ .fixed, .ui.visible."+s+".sidebar ~ .pusher { -webkit-transform: translate3d("+a[s]+"px, 0, 0); transform: translate3d("+a[s]+"px, 0, 0); }"):"top"!==s&&"bottom"!=s||(i+=" .ui.visible."+s+".sidebar ~ .fixed, .ui.visible."+s+".sidebar ~ .pusher { -webkit-transform: translate3d(0, "+a[s]+"px, 0); transform: translate3d(0, "+a[s]+"px, 0); }"),k.is.ie()&&("left"===s||"right"===s?(k.debug("Adding CSS rules for animation distance",n),i+=" body.pushable > .ui.visible."+s+".sidebar ~ .pusher:after { -webkit-transform: translate3d("+a[s]+"px, 0, 0); transform: translate3d("+a[s]+"px, 0, 0); }"):"top"!==s&&"bottom"!=s||(i+=" body.pushable > .ui.visible."+s+".sidebar ~ .pusher:after { -webkit-transform: translate3d(0, "+a[s]+"px, 0); transform: translate3d(0, "+a[s]+"px, 0); }"),i+=" body.pushable > .ui.visible.left.sidebar ~ .ui.visible.right.sidebar ~ .pusher:after, body.pushable > .ui.visible.right.sidebar ~ .ui.visible.left.sidebar ~ .pusher:after { -webkit-transform: translate3d(0px, 0, 0); transform: translate3d(0px, 0, 0); }"),i+="</style>",r=e(i).appendTo(c),k.debug("Adding sizing css to head",r)}},refresh:function(){k.verbose("Refreshing selector cache"),H=e(w.context),M=H.children(T.sidebar),j=H.children(T.pusher),D=H.children(T.fixed),k.clear.cache()},refreshSidebars:function(){k.verbose("Refreshing other sidebars"),M=H.children(T.sidebar)},repaint:function(){k.verbose("Forcing repaint event"),R.style.display="none";R.offsetHeight;R.scrollTop=R.scrollTop,R.style.display=""},setup:{cache:function(){k.cache={width:E.outerWidth(),height:E.outerHeight(),rtl:"rtl"==E.css("direction")}},layout:function(){0===H.children(T.pusher).length&&(k.debug("Adding wrapper element for sidebar"),k.error(F.pusher),j=e('<div class="pusher" />'),H.children().not(T.omitted).not(M).wrapAll(j),k.refresh()),0!==E.nextAll(T.pusher).length&&E.nextAll(T.pusher)[0]===j[0]||(k.debug("Moved sidebar to correct parent element"),k.error(F.movedSidebar,R),E.detach().prependTo(H),k.refresh()),k.clear.cache(),k.set.pushable(),k.set.direction()}},attachEvents:function(i,n){var t=e(i);n=e.isFunction(k[n])?k[n]:k.toggle,t.length>0?(k.debug("Attaching sidebar events to element",i,n),t.on("click"+O,n)):k.error(F.notFound,i)},show:function(i){if(i=e.isFunction(i)?i:function(){},k.is.hidden()){if(k.refreshSidebars(),w.overlay&&(k.error(F.overlay),w.transition="overlay"),k.refresh(),k.othersActive())if(k.debug("Other sidebars currently visible"),w.exclusive){if("overlay"!=w.transition)return void k.hideOthers(k.show);k.hideOthers()}else w.transition="overlay";k.pushPage(function(){i.call(R),w.onShow.call(R)}),w.onChange.call(R),w.onVisible.call(R)}else k.debug("Sidebar is already visible")},hide:function(i){i=e.isFunction(i)?i:function(){},(k.is.visible()||k.is.animating())&&(k.debug("Hiding sidebar",i),k.refreshSidebars(),k.pullPage(function(){i.call(R),w.onHidden.call(R)}),w.onChange.call(R),w.onHide.call(R))},othersAnimating:function(){return M.not(E).filter("."+x.animating).length>0},othersVisible:function(){return M.not(E).filter("."+x.visible).length>0},othersActive:function(){return k.othersVisible()||k.othersAnimating()},hideOthers:function(e){var i=M.not(E).filter("."+x.visible),n=i.length,t=0;e=e||function(){},i.sidebar("hide",function(){++t==n&&e()})},toggle:function(){k.verbose("Determining toggled direction"),k.is.hidden()?k.show():k.hide()},pushPage:function(i){var n,t,o,r=k.get.transition(),s="overlay"===r||k.othersActive()?E:j;i=e.isFunction(i)?i:function(){},"scale down"==w.transition&&k.scrollToTop(),k.set.transition(r),k.repaint(),n=function(){k.bind.clickaway(),k.add.inlineCSS(),k.set.animating(),k.set.visible()},t=function(){k.set.dimmed()},o=function(e){e.target==s[0]&&(s.off(C+g,o),k.remove.animating(),k.bind.scrollLock(),i.call(R))},s.off(C+g),s.on(C+g,o),v(n),w.dimPage&&!k.othersVisible()&&v(t)},pullPage:function(i){var n,t,o=k.get.transition(),r="overlay"==o||k.othersActive()?E:j;i=e.isFunction(i)?i:function(){},k.verbose("Removing context push state",k.get.direction()),k.unbind.clickaway(),k.unbind.scrollLock(),n=function(){k.set.transition(o),k.set.animating(),k.remove.visible(),w.dimPage&&!k.othersVisible()&&j.removeClass(x.dimmed)},t=function(e){e.target==r[0]&&(r.off(C+g,t),k.remove.animating(),k.remove.transition(),k.remove.inlineCSS(),("scale down"==o||w.returnScroll&&k.is.mobile())&&k.scrollBack(),i.call(R))},r.off(C+g),r.on(C+g,t),v(n)},scrollToTop:function(){k.verbose("Scrolling to top of page to avoid animation issues"),y=e(i).scrollTop(),E.scrollTop(0),i.scrollTo(0,0)},scrollBack:function(){k.verbose("Scrolling back to original page position"),i.scrollTo(0,y)},clear:{cache:function(){k.verbose("Clearing cached dimensions"),k.cache={}}},set:{ios:function(){l.addClass(x.ios)},pushed:function(){H.addClass(x.pushed)},pushable:function(){H.addClass(x.pushable)},dimmed:function(){j.addClass(x.dimmed)},active:function(){E.addClass(x.active)},animating:function(){E.addClass(x.animating)},transition:function(e){e=e||k.get.transition(),E.addClass(e)},direction:function(e){e=e||k.get.direction(),E.addClass(x[e])},visible:function(){E.addClass(x.visible)},overlay:function(){E.addClass(x.overlay)}},remove:{inlineCSS:function(){k.debug("Removing inline css styles",r),r&&r.length>0&&r.remove()},ios:function(){l.removeClass(x.ios)},pushed:function(){H.removeClass(x.pushed)},pushable:function(){H.removeClass(x.pushable)},active:function(){E.removeClass(x.active)},animating:function(){E.removeClass(x.animating)},transition:function(e){e=e||k.get.transition(),E.removeClass(e)},direction:function(e){e=e||k.get.direction(),E.removeClass(x[e])},visible:function(){E.removeClass(x.visible)},overlay:function(){E.removeClass(x.overlay)}},get:{direction:function(){return E.hasClass(x.top)?x.top:E.hasClass(x.right)?x.right:E.hasClass(x.bottom)?x.bottom:x.left},transition:function(){var e,i=k.get.direction();return e=k.is.mobile()?"auto"==w.mobileTransition?w.defaultTransition.mobile[i]:w.mobileTransition:"auto"==w.transition?w.defaultTransition.computer[i]:w.transition,k.verbose("Determined transition",e),e},transitionEvent:function(){var e,i=n.createElement("element"),t={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(e in t)if(void 0!==i.style[e])return t[e]}},is:{ie:function(){var e=!i.ActiveXObject&&"ActiveXObject"in i,n="ActiveXObject"in i;return e||n},ios:function(){var e=navigator.userAgent,i=e.match(A.ios),n=e.match(A.mobileChrome);return!(!i||n)&&(k.verbose("Browser was found to be iOS",e),!0)},mobile:function(){var e=navigator.userAgent;return e.match(A.mobile)?(k.verbose("Browser was found to be mobile",e),!0):(k.verbose("Browser is not mobile, using regular transition",e),!1)},hidden:function(){return!k.is.visible()},visible:function(){return E.hasClass(x.visible)},open:function(){return k.is.visible()},closed:function(){return k.is.hidden()},vertical:function(){return E.hasClass(x.top)},animating:function(){return H.hasClass(x.animating)},rtl:function(){return void 0===k.cache.rtl&&(k.cache.rtl="rtl"==E.css("direction")),k.cache.rtl}},setting:function(i,n){if(k.debug("Changing setting",i,n),e.isPlainObject(i))e.extend(!0,w,i);else{if(void 0===n)return w[i];e.isPlainObject(w[i])?e.extend(!0,w[i],n):w[i]=n}},internal:function(i,n){if(e.isPlainObject(i))e.extend(!0,k,i);else{if(void 0===n)return k[i];k[i]=n}},debug:function(){!w.silent&&w.debug&&(w.performance?k.performance.log(arguments):(k.debug=Function.prototype.bind.call(console.info,console,w.name+":"),k.debug.apply(console,arguments)))},verbose:function(){!w.silent&&w.verbose&&w.debug&&(w.performance?k.performance.log(arguments):(k.verbose=Function.prototype.bind.call(console.info,console,w.name+":"),k.verbose.apply(console,arguments)))},error:function(){w.silent||(k.error=Function.prototype.bind.call(console.error,console,w.name+":"),k.error.apply(console,arguments))},performance:{log:function(e){var i,n,t;w.performance&&(i=(new Date).getTime(),t=u||i,n=i-t,u=i,f.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:R,"Execution Time":n})),clearTimeout(k.performance.timer),k.performance.timer=setTimeout(k.performance.display,500)},display:function(){var i=w.name+":",n=0;u=!1,clearTimeout(k.performance.timer),e.each(f,function(e,i){n+=i["Execution Time"]}),i+=" "+n+"ms",d&&(i+=" '"+d+"'"),(void 0!==console.group||void 0!==console.table)&&f.length>0&&(console.groupCollapsed(i),console.table?console.table(f):e.each(f,function(e,i){console.log(i.Name+": "+i["Execution Time"]+"ms")}),console.groupEnd()),f=[]}},invoke:function(i,n,t){var r,s,a,l=z;return n=n||m,t=R||t,"string"==typeof i&&void 0!==l&&(i=i.split(/[\. ]/),r=i.length-1,e.each(i,function(n,t){var o=n!=r?t+i[n+1].charAt(0).toUpperCase()+i[n+1].slice(1):i;if(e.isPlainObject(l[o])&&n!=r)l=l[o];else{if(void 0!==l[o])return s=l[o],!1;if(!e.isPlainObject(l[t])||n==r)return void 0!==l[t]?(s=l[t],!1):(k.error(F.method,i),!1);l=l[t]}})),e.isFunction(s)?a=s.apply(t,n):void 0!==s&&(a=s),e.isArray(o)?o.push(a):void 0!==o?o=[o,a]:void 0!==a&&(o=a),s}},h?(void 0===z&&k.initialize(),k.invoke(b)):(void 0!==z&&k.invoke("destroy"),k.initialize())}),void 0!==o?o:this},e.fn.sidebar.settings={name:"Sidebar",namespace:"sidebar",silent:!1,debug:!1,verbose:!1,performance:!0,transition:"auto",mobileTransition:"auto",defaultTransition:{computer:{left:"uncover",right:"uncover",top:"overlay",bottom:"overlay"},mobile:{left:"uncover",right:"uncover",top:"overlay",bottom:"overlay"}},context:"body",exclusive:!1,closable:!0,dimPage:!0,scrollLock:!1,returnScroll:!1,delaySetup:!1,duration:500,onChange:function(){},onShow:function(){},onHide:function(){},onHidden:function(){},onVisible:function(){},className:{active:"active",animating:"animating",dimmed:"dimmed",ios:"ios",pushable:"pushable",pushed:"pushed",right:"right",top:"top",left:"left",bottom:"bottom",visible:"visible"},selector:{fixed:".fixed",omitted:"script, link, style, .ui.modal, .ui.dimmer, .ui.nag, .ui.fixed",pusher:".pusher",sidebar:".ui.sidebar"},regExp:{ios:/(iPad|iPhone|iPod)/g,mobileChrome:/(CriOS)/g,mobile:/Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/g},error:{method:"The method you called is not defined.",pusher:"Had to add pusher element. For optimal performance make sure body content is inside a pusher element",movedSidebar:"Had to move sidebar. For optimal performance make sure sidebar and pusher are direct children of your body tag",overlay:"The overlay setting is no longer supported, use animation: overlay",notFound:"There were no elements that matched the specified selector"}}}(jQuery,window,document);