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.

10 lines
11 KiB

10 years ago
10 years ago
  1. /*
  2. * # Semantic UI
  3. * git://github.com/Semantic-Org/Semantic-UI.git#1.0
  4. *
  5. *
  6. * Copyright 2014 Contributors
  7. * Released under the MIT license
  8. * http://opensource.org/licenses/MIT
  9. *
  10. */
  11. !function(e,n,i,t){"use strict";e.fn.sidebar=function(o){var r,a=e(this),s=(e("head"),a.selector||""),l=(new Date).getTime(),c=[],u=arguments[0],d="string"==typeof u,f=[].slice.call(arguments,1),m=n.requestAnimationFrame||n.mozRequestAnimationFrame||n.webkitRequestAnimationFrame||n.msRequestAnimationFrame||function(e){setTimeout(e,0)};return a.each(function(){var a,v,g,p=e.isPlainObject(o)?e.extend(!0,{},e.fn.sidebar.settings,o):e.extend({},e.fn.sidebar.settings),b=p.selector,h=p.className,y=p.namespace,w=p.error,x="."+y,C="module-"+y,T=e(this),k=e(p.context),P=e("style[title="+y+"]"),F=k.children(b.sidebar),A=k.children(b.pusher),z=A.children(b.page),O=A.find(b.fixed),E=this,S=T.data(C);g={initialize:function(){g.debug("Initializing sidebar",T),v=g.get.transitionEvent(),g.is.legacy()&&(p.useLegacy=!0),g.setup.context(),m(g.setup.layout),g.instantiate()},instantiate:function(){g.verbose("Storing instance of module",g),S=g,T.data(C,g)},destroy:function(){g.verbose("Destroying previous module for",T),T.off(x).removeData(C)},event:{clickaway:function(n){0===T.find(n.target).size()&&0===e(n.target).filter(T).size()&&(g.verbose("User clicked on dimmed page"),g.hide())},scroll:function(n){0===T.find(n.target).size()&&0===e(n.target).filter(T).size()&&n.preventDefault()}},bind:{clickaway:function(){p.scrollLock&&e(n).on("DOMMouseScroll"+x,g.event.scroll),k.on("click"+x,g.event.clickaway).on("touchend"+x,g.event.clickaway)}},unbind:{clickaway:function(){k.off(x),p.scrollLock&&e(n).off("DOMMouseScroll"+x)}},refresh:function(){g.verbose("Refreshing selector cache"),k=e(p.context),P=e("style[title="+y+"]"),F=k.children(b.sidebar),A=k.children(b.pusher),z=A.children(b.page),O=A.find(b.fixed)},repaint:function(){g.verbose("Forcing repaint event");k[0].offsetWidth},setup:{layout:function(){0===k.find(b.pusher).size()&&(g.debug("Adding wrapper element for sidebar"),A=e('<div class="pusher" />'),z=e('<div class="page" />'),A.append(z),k.children().not(b.omitted).not(F).wrapAll(A)),T.prevAll(z)[0]!==z[0]&&(g.debug("Moved sidebar to correct parent element"),T.detach().prependTo(k)),g.refresh()},context:function(){g.verbose("Adding pusshable class to wrapper"),k.addClass(h.pushable)}},attachEvents:function(n,i){var t=e(n);i=e.isFunction(g[i])?g[i]:g.toggle,t.size()>0?(g.debug("Attaching sidebar events to element",n,i),t.on("click"+x,i)):g.error(w.notFound,n)},show:function(n){var i=p.useLegacy?g.legacyPushPage:g.pushPage;n=e.isFunction(n)?n:function(){},g.is.closed()||g.is.outward()?(p.overlay&&(g.error(w.overlay),p.transition="overlay"),"overlay"!==p.transition&&g.hideAll(),i(function(){e.proxy(n,E)(),e.proxy(p.onShow,E)()}),e.proxy(p.onChange,E)(),e.proxy(p.onVisible,E)()):g.debug("Sidebar is already visible")},hide:function(n){var i=p.useLegacy?g.legacyPullPage:g.pullPage;n=e.isFunction(n)?n:function(){},(g.is.visible()||g.is.inward())&&(g.debug("Hiding sidebar",n),i(function(){e.proxy(n,E)(),e.proxy(p.onHidden,E)()}),e.proxy(p.onChange,E)(),e.proxy(p.onHide,E)())},hideAll:function(){var e=F.find("."+h.visible);e.sidebar("hide")},toggle:function(){g.verbose("Determining toggled direction"),g.is.closed()||g.is.outward()?g.show():g.hide()},pushPage:function(i){var t,o=g.get.transition(),r="safe"==o?k:"overlay"==o?T:A;i=e.isFunction(i)?i:function(){},t=function(){g.remove.outward(),g.set.visible(),g.set.transition(),g.set.direction(),m(function(){g.set.inward(),g.set.pushed()})},r.off(v+x).on(v+x,function(n){n.target==r[0]&&(r.off(v+x),g.remove.inward(),g.bind.clickaway(),g.set.active(),e.proxy(i,E)())}),g.verbose("Adding context push state",k),"overlay"===o?m(t):(("scale down"==p.transition||g.is.mobile())&&(T.scrollTop(0),a=e(n).scrollTop(),n.scrollTo(0,0)),g.remove.allVisible(),m(t))},pullPage:function(i){var t=g.get.transition(),o="safe"==t?k:"overlay"==t?T:A;i=e.isFunction(i)?i:function(){},g.verbose("Removing context push state",g.get.direction()),g.unbind.clickaway(),o.off(v+x).on(v+x,function(r){r.target==o[0]&&(o.off(v+x),g.remove.transition(),g.remove.direction(),g.remove.outward(),g.remove.visible(),("scale down"==t||p.returnSc