You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

11 lines
15 KiB

/*!
* # Semantic UI 2.0.0 - Sidebar
* http://github.com/semantic-org/semantic-ui/
*
*
* Copyright 2015 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
!function(e,i,n,t){"use strict";e.fn.sidebar=function(o){var r,s=e(this),a=e(i),l=e(n),c=e("html"),u=e("head"),d=s.selector||"",f=(new Date).getTime(),m=[],g=arguments[0],b="string"==typeof g,h=[].slice.call(arguments,1),v=i.requestAnimationFrame||i.mozRequestAnimationFrame||i.webkitRequestAnimationFrame||i.msRequestAnimationFrame||function(e){setTimeout(e,0)};return s.each(function(){var s,p,y,w,C,k,x=e.isPlainObject(o)?e.extend(!0,{},e.fn.sidebar.settings,o):e.extend({},e.fn.sidebar.settings),T=x.selector,S=x.className,A=x.namespace,P=x.regExp,F=x.error,O="."+A,E="module-"+A,H=e(this),L=e(x.context),j=H.children(T.sidebar),D=L.children(T.fixed),z=L.children(T.pusher),M=this,R=H.data(E);k={initialize:function(){k.debug("Initializing sidebar",o),k.create.id(),C=k.get.transitionEvent(),("auto"==x.useLegacy&&k.is.legacy()||x.useLegacy===!0)&&(x.transition="overlay",x.useLegacy=!0),k.is.ios()&&k.set.ios(),x.delaySetup?v(k.setup.layout):k.setup.layout(),v(function(){k.setup.cache()}),k.instantiate()},instantiate:function(){k.verbose("Storing instance of module",k),R=k,H.data(E,k)},create:{id:function(){y=(Math.random().toString(16)+"000000000").substr(2,8),p="."+y,k.verbose("Creating unique id for element",y)}},destroy:function(){k.verbose("Destroying previous module for",H),k.remove.direction(),H.off(O).removeData(E),k.is.ios()&&k.remove.ios(),L.off(p),a.off(p),l.off(p)},event:{clickaway:function(e){var i=z.find(e.target).length>0||z.is(e.target),n=L.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){M.scrollTop<=0&&(M.scrollTop=1),M.scrollTop+M.offsetHeight>=M.scrollHeight&&(M.scrollTop=M.scrollHeight-M.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",L),x.closable&&L.on("click"+p,k.event.clickaway).on("touchend"+p,k.event.clickaway)},scrollLock:function(){x.scrollLock&&(k.debug("Disabling page scroll"),a.on("DOMMouseScroll"+p,k.event.scroll)),k.verbose("Adding events to contain sidebar scroll"),l.on("touchmove"+p,k.event.touch),H.on("scroll"+O,k.event.containScroll)}},unbind:{clickaway:function(){k.verbose("Removing clickaway events from context",L),L.off(p)},scrollLock:function(){k.verbose("Removing scroll lock from page"),l.off(p),a.off(p),H.off("scroll"+O)}},add:{inlineCSS:function(){var i,n=k.cache.width||H.outerWidth(),t=k.cache.height||H.outerHeight(),o=k.is.rtl(),r=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"===r||"right"===r?(k.debug("Adding CSS rules for animation distance",n),i+=" .ui.visible."+r+".sidebar ~ .fixed, .ui.visible."+r+".sidebar ~ .pusher { -webkit-transform: translate3d("+a[r]+"px, 0, 0); transform: translate3d("+a[r]+"px, 0, 0); }"):("top"===r||"bottom"==r)&&(i+=" .ui.visible."+r+".sidebar ~ .fixed, .ui.visible."+r+".sidebar ~ .pusher { -webkit-transform: translate3d(0, "+a[r]+"px, 0); transform: translate3d(0, "+a[r]+"px, 0); }"),k.is.ie()&&("left"===r||"right"===r?(k.debug("Adding CSS rules for animation distance",n),i+=" body.pushable > .ui.visible."+r+".sidebar ~ .pusher:after { -webkit-transform: translate3d("+a[r]+"px, 0, 0); transform: translate3d("+a[r]+"px, 0, 0); }"):("top"===r||"bottom"==r)&&(i+=" body.pushable > .ui.visible."+r+".sidebar ~ .pusher:after { -webkit-transform: translate3d(0, "+a[r]+"px, 0); transform: translate3d(0, "+a[r]+"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>",s=e(i).appendTo(u),k.debug("Adding sizing css to head",s)}},refresh:function(){k.verbose("Refreshing selector cache"),L=e(x.context),j=L.children(T.sidebar),z=L.children(T.pusher),D=L.children(T.fixed),k.clear.cache()},refreshSidebars:function(){k.verbose("Refreshing other sidebars"),j=L.children(T.sidebar)},repaint:function(){k.verbose("Forcing repaint event"),M.style.display="none";M.offsetHeight;M.scrollTop=M.scrollTop,M.style.display=""},setup:{cache:function(){k.cache={width:H.outerWidth(),height:H.outerHeight(),rtl:"rtl"==H.css("direction")}},layout:function(){0===L.children(T.pusher).length&&(k.debug("Adding wrapper element for sidebar"),k.error(F.pusher),z=e('<div class="pusher" />'),L.children().not(T.omitted).not(j).wrapAll(z),k.refresh()),(0===H.nextAll(T.pusher).length||H.nextAll(T.pusher)[0]!==z[0])&&(k.debug("Moved sidebar to correct parent element"),k.error(F.movedSidebar,M),H.detach().prependTo(L),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){var n=x.useLegacy===!0?k.legacyPushPage:k.pushPage;if(i=e.isFunction(i)?i:function(){},k.is.hidden()){if(k.refreshSidebars(),x.overlay&&(k.error(F.overlay),x.transition="overlay"),k.refresh(),k.othersActive())if(k.debug("Other sidebars currently visible"),x.exclusive){if("overlay"!=x.transition)return void k.hideOthers(k.show);k.hideOthers()}else x.transition="overlay";n(function(){i.call(M),x.onShow.call(M)}),x.onChange.call(M),x.onVisible.call(M)}else k.debug("Sidebar is already visible")},hide:function(i){var n=x.useLegacy===!0?k.legacyPullPage:k.pullPage;i=e.isFunction(i)?i:function(){},(k.is.visible()||k.is.animating())&&(k.debug("Hiding sidebar",i),k.refreshSidebars(),n(function(){i.call(M),x.onHidden.call(M)}),x.onChange.call(M),x.onHide.call(M))},othersAnimating:function(){return j.not(H).filter("."+S.animating).length>0},othersVisible:function(){return j.not(H).filter("."+S.visible).length>0},othersActive:function(){return k.othersVisible()||k.othersAnimating()},hideOthers:function(e){var i=j.not(H).filter("."+S.visible),n=i.length,t=0;e=e||function(){},i.sidebar("hide",function(){t++,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="safe"==r?L:"overlay"===r||k.othersActive()?H:z;i=e.isFunction(i)?i:function(){},"scale down"==x.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+p,o),k.remove.animating(),k.bind.scrollLock(),i.call(M))},s.off(C+p),s.on(C+p,o),v(n),x.dimPage&&!k.othersVisible()&&v(t)},pullPage:function(i){var n,t,o=k.get.transition(),r="safe"==o?L:"overlay"==o||k.othersActive()?H:z;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(),x.dimPage&&!k.othersVisible()&&z.removeClass(S.dimmed)},t=function(e){e.target==r[0]&&(r.off(C+p,t),k.remove.animating(),k.remove.transition(),k.remove.inlineCSS(),("scale down"==o||x.returnScroll&&k.is.mobile())&&k.scrollBack(),i.call(M))},r.off(C+p),r.on(C+p,t),v(n)},legacyPushPage:function(i){var n=H.width(),t=k.get.direction(),o={};n=n||H.width(),i=e.isFunction(i)?i:function(){},o[t]=n,k.debug("Using javascript to push context",o),k.set.visible(),k.set.transition(),k.set.animating(),x.dimPage&&z.addClass(S.dimmed),L.css("position","relative").animate(o,x.duration,x.easing,function(){k.remove.animating(),k.bind.clickaway(),i.call(M)})},legacyPullPage:function(i){var n=0,t=k.get.direction(),o={};n=n||H.width(),i=e.isFunction(i)?i:function(){},o[t]="0px",k.debug("Using javascript to pull context",o),k.unbind.clickaway(),k.set.animating(),k.remove.visible(),x.dimPage&&!k.othersActive()&&z.removeClass(S.dimmed),L.css("position","relative").animate(o,x.duration,x.easing,function(){k.remove.animating(),i.call(M)})},scrollToTop:function(){k.verbose("Scrolling to top of page to avoid animation issues"),w=e(i).scrollTop(),H.scrollTop(0),i.scrollTo(0,0)},scrollBack:function(){k.verbose("Scrolling back to original page position"),i.scrollTo(0,w)},clear:{cache:function(){k.verbose("Clearing cached dimensions"),k.cache={}}},set:{ios:function(){c.addClass(S.ios)},pushed:function(){L.addClass(S.pushed)},pushable:function(){L.addClass(S.pushable)},dimmed:function(){z.addClass(S.dimmed)},active:function(){H.addClass(S.active)},animating:function(){H.addClass(S.animating)},transition:function(e){e=e||k.get.transition(),H.addClass(e)},direction:function(e){e=e||k.get.direction(),H.addClass(S[e])},visible:function(){H.addClass(S.visible)},overlay:function(){H.addClass(S.overlay)}},remove:{inlineCSS:function(){k.debug("Removing inline css styles",s),s&&s.length>0&&s.remove()},ios:function(){c.removeClass(S.ios)},pushed:function(){L.removeClass(S.pushed)},pushable:function(){L.removeClass(S.pushable)},active:function(){H.removeClass(S.active)},animating:function(){H.removeClass(S.animating)},transition:function(e){e=e||k.get.transition(),H.removeClass(e)},direction:function(e){e=e||k.get.direction(),H.removeClass(S[e])},visible:function(){H.removeClass(S.visible)},overlay:function(){H.removeClass(S.overlay)}},get:{direction:function(){return H.hasClass(S.top)?S.top:H.hasClass(S.right)?S.right:H.hasClass(S.bottom)?S.bottom:S.left},transition:function(){var e,i=k.get.direction();return e=k.is.mobile()?"auto"==x.mobileTransition?x.defaultTransition.mobile[i]:x.mobileTransition:"auto"==x.transition?x.defaultTransition.computer[i]:x.transition,k.verbose("Determined transition",e),e},transitionEvent:function(){var e,i=n.createElement("element"),o={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(e in o)if(i.style[e]!==t)return o[e]}},is:{ie:function(){var e=!i.ActiveXObject&&"ActiveXObject"in i,n="ActiveXObject"in i;return e||n},legacy:function(){var e,o=n.createElement("div"),r={webkitTransform:"-webkit-transform",OTransform:"-o-transform",msTransform:"-ms-transform",MozTransform:"-moz-transform",transform:"transform"};n.body.insertBefore(o,null);for(var s in r)o.style[s]!==t&&(o.style[s]="translate3d(1px,1px,1px)",e=i.getComputedStyle(o).getPropertyValue(r[s]));return n.body.removeChild(o),!(e!==t&&e.length>0&&"none"!==e)},ios:function(){var e=navigator.userAgent,i=e.match(P.ios),n=e.match(P.mobileChrome);return i&&!n?(k.verbose("Browser was found to be iOS",e),!0):!1},mobile:function(){var e=navigator.userAgent,i=e.match(P.mobile);return i?(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 H.hasClass(S.visible)},open:function(){return k.is.visible()},closed:function(){return k.is.hidden()},vertical:function(){return H.hasClass(S.top)},animating:function(){return L.hasClass(S.animating)},rtl:function(){return k.cache.rtl===t&&(k.cache.rtl="rtl"==H.css("direction")),k.cache.rtl}},setting:function(i,n){if(k.debug("Changing setting",i,n),e.isPlainObject(i))e.extend(!0,x,i);else{if(n===t)return x[i];x[i]=n}},internal:function(i,n){if(e.isPlainObject(i))e.extend(!0,k,i);else{if(n===t)return k[i];k[i]=n}},debug:function(){x.debug&&(x.performance?k.performance.log(arguments):(k.debug=Function.prototype.bind.call(console.info,console,x.name+":"),k.debug.apply(console,arguments)))},verbose:function(){x.verbose&&x.debug&&(x.performance?k.performance.log(arguments):(k.verbose=Function.prototype.bind.call(console.info,console,x.name+":"),k.verbose.apply(console,arguments)))},error:function(){k.error=Function.prototype.bind.call(console.error,console,x.name+":"),k.error.apply(console,arguments)},performance:{log:function(e){var i,n,t;x.performance&&(i=(new Date).getTime(),t=f||i,n=i-t,f=i,m.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:M,"Execution Time":n})),clearTimeout(k.performance.timer),k.performance.timer=setTimeout(k.performance.display,500)},display:function(){var i=x.name+":",n=0;f=!1,clearTimeout(k.performance.timer),e.each(m,function(e,i){n+=i["Execution Time"]}),i+=" "+n+"ms",d&&(i+=" '"+d+"'"),(console.group!==t||console.table!==t)&&m.length>0&&(console.groupCollapsed(i),console.table?console.table(m):e.each(m,function(e,i){console.log(i.Name+": "+i["Execution Time"]+"ms")}),console.groupEnd()),m=[]}},invoke:function(i,n,o){var s,a,l,c=R;return n=n||h,o=M||o,"string"==typeof i&&c!==t&&(i=i.split(/[\. ]/),s=i.length-1,e.each(i,function(n,o){var r=n!=s?o+i[n+1].charAt(0).toUpperCase()+i[n+1].slice(1):i;if(e.isPlainObject(c[r])&&n!=s)c=c[r];else{if(c[r]!==t)return a=c[r],!1;if(!e.isPlainObject(c[o])||n==s)return c[o]!==t?(a=c[o],!1):(k.error(F.method,i),!1);c=c[o]}})),e.isFunction(a)?l=a.apply(o,n):a!==t&&(l=a),e.isArray(r)?r.push(l):r!==t?r=[r,l]:l!==t&&(r=l),a}},b?(R===t&&k.initialize(),k.invoke(g)):(R!==t&&k.invoke("destroy"),k.initialize())}),r!==t?r:this},e.fn.sidebar.settings={name:"Sidebar",namespace:"sidebar",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,useLegacy:!1,duration:500,easing:"easeInOutQuint",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"}},e.extend(e.easing,{easeInOutQuint:function(e,i,n,t,o){return(i/=o/2)<1?t/2*i*i*i*i*i+n:t/2*((i-=2)*i*i*i*i+2)+n}})}(jQuery,window,document);