sidebar.js 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. /*!
  2. * # Semantic UI 2.2.6 - Sidebar
  3. * http://github.com/semantic-org/semantic-ui/
  4. *
  5. *
  6. * Released under the MIT license
  7. * http://opensource.org/licenses/MIT
  8. *
  9. */
  10. ;(function ($, window, document, undefined) {
  11. "use strict";
  12. window = (typeof window != 'undefined' && window.Math == Math)
  13. ? window
  14. : (typeof self != 'undefined' && self.Math == Math)
  15. ? self
  16. : Function('return this')()
  17. ;
  18. $.fn.sidebar = function(parameters) {
  19. var
  20. $allModules = $(this),
  21. $window = $(window),
  22. $document = $(document),
  23. $html = $('html'),
  24. $head = $('head'),
  25. moduleSelector = $allModules.selector || '',
  26. time = new Date().getTime(),
  27. performance = [],
  28. query = arguments[0],
  29. methodInvoked = (typeof query == 'string'),
  30. queryArguments = [].slice.call(arguments, 1),
  31. requestAnimationFrame = window.requestAnimationFrame
  32. || window.mozRequestAnimationFrame
  33. || window.webkitRequestAnimationFrame
  34. || window.msRequestAnimationFrame
  35. || function(callback) { setTimeout(callback, 0); },
  36. returnedValue
  37. ;
  38. $allModules
  39. .each(function() {
  40. var
  41. settings = ( $.isPlainObject(parameters) )
  42. ? $.extend(true, {}, $.fn.sidebar.settings, parameters)
  43. : $.extend({}, $.fn.sidebar.settings),
  44. selector = settings.selector,
  45. className = settings.className,
  46. namespace = settings.namespace,
  47. regExp = settings.regExp,
  48. error = settings.error,
  49. eventNamespace = '.' + namespace,
  50. moduleNamespace = 'module-' + namespace,
  51. $module = $(this),
  52. $context = $(settings.context),
  53. $sidebars = $module.children(selector.sidebar),
  54. $fixed = $context.children(selector.fixed),
  55. $pusher = $context.children(selector.pusher),
  56. $style,
  57. element = this,
  58. instance = $module.data(moduleNamespace),
  59. elementNamespace,
  60. id,
  61. currentScroll,
  62. transitionEvent,
  63. module
  64. ;
  65. module = {
  66. initialize: function() {
  67. module.debug('Initializing sidebar', parameters);
  68. module.create.id();
  69. transitionEvent = module.get.transitionEvent();
  70. if(module.is.ios()) {
  71. module.set.ios();
  72. }
  73. // avoids locking rendering if initialized in onReady
  74. if(settings.delaySetup) {
  75. requestAnimationFrame(module.setup.layout);
  76. }
  77. else {
  78. module.setup.layout();
  79. }
  80. requestAnimationFrame(function() {
  81. module.setup.cache();
  82. });
  83. module.instantiate();
  84. },
  85. instantiate: function() {
  86. module.verbose('Storing instance of module', module);
  87. instance = module;
  88. $module
  89. .data(moduleNamespace, module)
  90. ;
  91. },
  92. create: {
  93. id: function() {
  94. id = (Math.random().toString(16) + '000000000').substr(2,8);
  95. elementNamespace = '.' + id;
  96. module.verbose('Creating unique id for element', id);
  97. }
  98. },
  99. destroy: function() {
  100. module.verbose('Destroying previous module for', $module);
  101. $module
  102. .off(eventNamespace)
  103. .removeData(moduleNamespace)
  104. ;
  105. if(module.is.ios()) {
  106. module.remove.ios();
  107. }
  108. // bound by uuid
  109. $context.off(elementNamespace);
  110. $window.off(elementNamespace);
  111. $document.off(elementNamespace);
  112. },
  113. event: {
  114. clickaway: function(event) {
  115. var
  116. clickedInPusher = ($pusher.find(event.target).length > 0 || $pusher.is(event.target)),
  117. clickedContext = ($context.is(event.target))
  118. ;
  119. if(clickedInPusher) {
  120. module.verbose('User clicked on dimmed page');
  121. module.hide();
  122. }
  123. if(clickedContext) {
  124. module.verbose('User clicked on dimmable context (scaled out page)');
  125. module.hide();
  126. }
  127. },
  128. touch: function(event) {
  129. //event.stopPropagation();
  130. },
  131. containScroll: function(event) {
  132. if(element.scrollTop <= 0) {
  133. element.scrollTop = 1;
  134. }
  135. if((element.scrollTop + element.offsetHeight) >= element.scrollHeight) {
  136. element.scrollTop = element.scrollHeight - element.offsetHeight - 1;
  137. }
  138. },
  139. scroll: function(event) {
  140. if( $(event.target).closest(selector.sidebar).length === 0 ) {
  141. event.preventDefault();
  142. }
  143. }
  144. },
  145. bind: {
  146. clickaway: function() {
  147. module.verbose('Adding clickaway events to context', $context);
  148. if(settings.closable) {
  149. $context
  150. .on('click' + elementNamespace, module.event.clickaway)
  151. .on('touchend' + elementNamespace, module.event.clickaway)
  152. ;
  153. }
  154. },
  155. scrollLock: function() {
  156. if(settings.scrollLock) {
  157. module.debug('Disabling page scroll');
  158. $window
  159. .on('DOMMouseScroll' + elementNamespace, module.event.scroll)
  160. ;
  161. }
  162. module.verbose('Adding events to contain sidebar scroll');
  163. $document
  164. .on('touchmove' + elementNamespace, module.event.touch)
  165. ;
  166. $module
  167. .on('scroll' + eventNamespace, module.event.containScroll)
  168. ;
  169. }
  170. },
  171. unbind: {
  172. clickaway: function() {
  173. module.verbose('Removing clickaway events from context', $context);
  174. $context.off(elementNamespace);
  175. },
  176. scrollLock: function() {
  177. module.verbose('Removing scroll lock from page');
  178. $document.off(elementNamespace);
  179. $window.off(elementNamespace);
  180. $module.off('scroll' + eventNamespace);
  181. }
  182. },
  183. add: {
  184. inlineCSS: function() {
  185. var
  186. width = module.cache.width || $module.outerWidth(),
  187. height = module.cache.height || $module.outerHeight(),
  188. isRTL = module.is.rtl(),
  189. direction = module.get.direction(),
  190. distance = {
  191. left : width,
  192. right : -width,
  193. top : height,
  194. bottom : -height
  195. },
  196. style
  197. ;
  198. if(isRTL){
  199. module.verbose('RTL detected, flipping widths');
  200. distance.left = -width;
  201. distance.right = width;
  202. }
  203. style = '<style>';
  204. if(direction === 'left' || direction === 'right') {
  205. module.debug('Adding CSS rules for animation distance', width);
  206. style += ''
  207. + ' .ui.visible.' + direction + '.sidebar ~ .fixed,'
  208. + ' .ui.visible.' + direction + '.sidebar ~ .pusher {'
  209. + ' -webkit-transform: translate3d('+ distance[direction] + 'px, 0, 0);'
  210. + ' transform: translate3d('+ distance[direction] + 'px, 0, 0);'
  211. + ' }'
  212. ;
  213. }
  214. else if(direction === 'top' || direction == 'bottom') {
  215. style += ''
  216. + ' .ui.visible.' + direction + '.sidebar ~ .fixed,'
  217. + ' .ui.visible.' + direction + '.sidebar ~ .pusher {'
  218. + ' -webkit-transform: translate3d(0, ' + distance[direction] + 'px, 0);'
  219. + ' transform: translate3d(0, ' + distance[direction] + 'px, 0);'
  220. + ' }'
  221. ;
  222. }
  223. /* IE is only browser not to create context with transforms */
  224. /* https://www.w3.org/Bugs/Public/show_bug.cgi?id=16328 */
  225. if( module.is.ie() ) {
  226. if(direction === 'left' || direction === 'right') {
  227. module.debug('Adding CSS rules for animation distance', width);
  228. style += ''
  229. + ' body.pushable > .ui.visible.' + direction + '.sidebar ~ .pusher:after {'
  230. + ' -webkit-transform: translate3d('+ distance[direction] + 'px, 0, 0);'
  231. + ' transform: translate3d('+ distance[direction] + 'px, 0, 0);'
  232. + ' }'
  233. ;
  234. }
  235. else if(direction === 'top' || direction == 'bottom') {
  236. style += ''
  237. + ' body.pushable > .ui.visible.' + direction + '.sidebar ~ .pusher:after {'
  238. + ' -webkit-transform: translate3d(0, ' + distance[direction] + 'px, 0);'
  239. + ' transform: translate3d(0, ' + distance[direction] + 'px, 0);'
  240. + ' }'
  241. ;
  242. }
  243. /* opposite sides visible forces content overlay */
  244. style += ''
  245. + ' body.pushable > .ui.visible.left.sidebar ~ .ui.visible.right.sidebar ~ .pusher:after,'
  246. + ' body.pushable > .ui.visible.right.sidebar ~ .ui.visible.left.sidebar ~ .pusher:after {'
  247. + ' -webkit-transform: translate3d(0px, 0, 0);'
  248. + ' transform: translate3d(0px, 0, 0);'
  249. + ' }'
  250. ;
  251. }
  252. style += '</style>';
  253. $style = $(style)
  254. .appendTo($head)
  255. ;
  256. module.debug('Adding sizing css to head', $style);
  257. }
  258. },
  259. refresh: function() {
  260. module.verbose('Refreshing selector cache');
  261. $context = $(settings.context);
  262. $sidebars = $context.children(selector.sidebar);
  263. $pusher = $context.children(selector.pusher);
  264. $fixed = $context.children(selector.fixed);
  265. module.clear.cache();
  266. },
  267. refreshSidebars: function() {
  268. module.verbose('Refreshing other sidebars');
  269. $sidebars = $context.children(selector.sidebar);
  270. },
  271. repaint: function() {
  272. module.verbose('Forcing repaint event');
  273. element.style.display = 'none';
  274. var ignored = element.offsetHeight;
  275. element.scrollTop = element.scrollTop;
  276. element.style.display = '';
  277. },
  278. setup: {
  279. cache: function() {
  280. module.cache = {
  281. width : $module.outerWidth(),
  282. height : $module.outerHeight(),
  283. rtl : ($module.css('direction') == 'rtl')
  284. };
  285. },
  286. layout: function() {
  287. if( $context.children(selector.pusher).length === 0 ) {
  288. module.debug('Adding wrapper element for sidebar');
  289. module.error(error.pusher);
  290. $pusher = $('<div class="pusher" />');
  291. $context
  292. .children()
  293. .not(selector.omitted)
  294. .not($sidebars)
  295. .wrapAll($pusher)
  296. ;
  297. module.refresh();
  298. }
  299. if($module.nextAll(selector.pusher).length === 0 || $module.nextAll(selector.pusher)[0] !== $pusher[0]) {
  300. module.debug('Moved sidebar to correct parent element');
  301. module.error(error.movedSidebar, element);
  302. $module.detach().prependTo($context);
  303. module.refresh();
  304. }
  305. module.clear.cache();
  306. module.set.pushable();
  307. module.set.direction();
  308. }
  309. },
  310. attachEvents: function(selector, event) {
  311. var
  312. $toggle = $(selector)
  313. ;
  314. event = $.isFunction(module[event])
  315. ? module[event]
  316. : module.toggle
  317. ;
  318. if($toggle.length > 0) {
  319. module.debug('Attaching sidebar events to element', selector, event);
  320. $toggle
  321. .on('click' + eventNamespace, event)
  322. ;
  323. }
  324. else {
  325. module.error(error.notFound, selector);
  326. }
  327. },
  328. show: function(callback) {
  329. callback = $.isFunction(callback)
  330. ? callback
  331. : function(){}
  332. ;
  333. if(module.is.hidden()) {
  334. module.refreshSidebars();
  335. if(settings.overlay) {
  336. module.error(error.overlay);
  337. settings.transition = 'overlay';
  338. }
  339. module.refresh();
  340. if(module.othersActive()) {
  341. module.debug('Other sidebars currently visible');
  342. if(settings.exclusive) {
  343. // if not overlay queue animation after hide
  344. if(settings.transition != 'overlay') {
  345. module.hideOthers(module.show);
  346. return;
  347. }
  348. else {
  349. module.hideOthers();
  350. }
  351. }
  352. else {
  353. settings.transition = 'overlay';
  354. }
  355. }
  356. module.pushPage(function() {
  357. callback.call(element);
  358. settings.onShow.call(element);
  359. });
  360. settings.onChange.call(element);
  361. settings.onVisible.call(element);
  362. }
  363. else {
  364. module.debug('Sidebar is already visible');
  365. }
  366. },
  367. hide: function(callback) {
  368. callback = $.isFunction(callback)
  369. ? callback
  370. : function(){}
  371. ;
  372. if(module.is.visible() || module.is.animating()) {
  373. module.debug('Hiding sidebar', callback);
  374. module.refreshSidebars();
  375. module.pullPage(function() {
  376. callback.call(element);
  377. settings.onHidden.call(element);
  378. });
  379. settings.onChange.call(element);
  380. settings.onHide.call(element);
  381. }
  382. },
  383. othersAnimating: function() {
  384. return ($sidebars.not($module).filter('.' + className.animating).length > 0);
  385. },
  386. othersVisible: function() {
  387. return ($sidebars.not($module).filter('.' + className.visible).length > 0);
  388. },
  389. othersActive: function() {
  390. return(module.othersVisible() || module.othersAnimating());
  391. },
  392. hideOthers: function(callback) {
  393. var
  394. $otherSidebars = $sidebars.not($module).filter('.' + className.visible),
  395. sidebarCount = $otherSidebars.length,
  396. callbackCount = 0
  397. ;
  398. callback = callback || function(){};
  399. $otherSidebars
  400. .sidebar('hide', function() {
  401. callbackCount++;
  402. if(callbackCount == sidebarCount) {
  403. callback();
  404. }
  405. })
  406. ;
  407. },
  408. toggle: function() {
  409. module.verbose('Determining toggled direction');
  410. if(module.is.hidden()) {
  411. module.show();
  412. }
  413. else {
  414. module.hide();
  415. }
  416. },
  417. pushPage: function(callback) {
  418. var
  419. transition = module.get.transition(),
  420. $transition = (transition === 'overlay' || module.othersActive())
  421. ? $module
  422. : $pusher,
  423. animate,
  424. dim,
  425. transitionEnd
  426. ;
  427. callback = $.isFunction(callback)
  428. ? callback
  429. : function(){}
  430. ;
  431. if(settings.transition == 'scale down') {
  432. module.scrollToTop();
  433. }
  434. module.set.transition(transition);
  435. module.repaint();
  436. animate = function() {
  437. module.bind.clickaway();
  438. module.add.inlineCSS();
  439. module.set.animating();
  440. module.set.visible();
  441. };
  442. dim = function() {
  443. module.set.dimmed();
  444. };
  445. transitionEnd = function(event) {
  446. if( event.target == $transition[0] ) {
  447. $transition.off(transitionEvent + elementNamespace, transitionEnd);
  448. module.remove.animating();
  449. module.bind.scrollLock();
  450. callback.call(element);
  451. }
  452. };
  453. $transition.off(transitionEvent + elementNamespace);
  454. $transition.on(transitionEvent + elementNamespace, transitionEnd);
  455. requestAnimationFrame(animate);
  456. if(settings.dimPage && !module.othersVisible()) {
  457. requestAnimationFrame(dim);
  458. }
  459. },
  460. pullPage: function(callback) {
  461. var
  462. transition = module.get.transition(),
  463. $transition = (transition == 'overlay' || module.othersActive())
  464. ? $module
  465. : $pusher,
  466. animate,
  467. transitionEnd
  468. ;
  469. callback = $.isFunction(callback)
  470. ? callback
  471. : function(){}
  472. ;
  473. module.verbose('Removing context push state', module.get.direction());
  474. module.unbind.clickaway();
  475. module.unbind.scrollLock();
  476. animate = function() {
  477. module.set.transition(transition);
  478. module.set.animating();
  479. module.remove.visible();
  480. if(settings.dimPage && !module.othersVisible()) {
  481. $pusher.removeClass(className.dimmed);
  482. }
  483. };
  484. transitionEnd = function(event) {
  485. if( event.target == $transition[0] ) {
  486. $transition.off(transitionEvent + elementNamespace, transitionEnd);
  487. module.remove.animating();
  488. module.remove.transition();
  489. module.remove.inlineCSS();
  490. if(transition == 'scale down' || (settings.returnScroll && module.is.mobile()) ) {
  491. module.scrollBack();
  492. }
  493. callback.call(element);
  494. }
  495. };
  496. $transition.off(transitionEvent + elementNamespace);
  497. $transition.on(transitionEvent + elementNamespace, transitionEnd);
  498. requestAnimationFrame(animate);
  499. },
  500. scrollToTop: function() {
  501. module.verbose('Scrolling to top of page to avoid animation issues');
  502. currentScroll = $(window).scrollTop();
  503. $module.scrollTop(0);
  504. window.scrollTo(0, 0);
  505. },
  506. scrollBack: function() {
  507. module.verbose('Scrolling back to original page position');
  508. window.scrollTo(0, currentScroll);
  509. },
  510. clear: {
  511. cache: function() {
  512. module.verbose('Clearing cached dimensions');
  513. module.cache = {};
  514. }
  515. },
  516. set: {
  517. // ios only (scroll on html not document). This prevent auto-resize canvas/scroll in ios
  518. ios: function() {
  519. $html.addClass(className.ios);
  520. },
  521. // container
  522. pushed: function() {
  523. $context.addClass(className.pushed);
  524. },
  525. pushable: function() {
  526. $context.addClass(className.pushable);
  527. },
  528. // pusher
  529. dimmed: function() {
  530. $pusher.addClass(className.dimmed);
  531. },
  532. // sidebar
  533. active: function() {
  534. $module.addClass(className.active);
  535. },
  536. animating: function() {
  537. $module.addClass(className.animating);
  538. },
  539. transition: function(transition) {
  540. transition = transition || module.get.transition();
  541. $module.addClass(transition);
  542. },
  543. direction: function(direction) {
  544. direction = direction || module.get.direction();
  545. $module.addClass(className[direction]);
  546. },
  547. visible: function() {
  548. $module.addClass(className.visible);
  549. },
  550. overlay: function() {
  551. $module.addClass(className.overlay);
  552. }
  553. },
  554. remove: {
  555. inlineCSS: function() {
  556. module.debug('Removing inline css styles', $style);
  557. if($style && $style.length > 0) {
  558. $style.remove();
  559. }
  560. },
  561. // ios scroll on html not document
  562. ios: function() {
  563. $html.removeClass(className.ios);
  564. },
  565. // context
  566. pushed: function() {
  567. $context.removeClass(className.pushed);
  568. },
  569. pushable: function() {
  570. $context.removeClass(className.pushable);
  571. },
  572. // sidebar
  573. active: function() {
  574. $module.removeClass(className.active);
  575. },
  576. animating: function() {
  577. $module.removeClass(className.animating);
  578. },
  579. transition: function(transition) {
  580. transition = transition || module.get.transition();
  581. $module.removeClass(transition);
  582. },
  583. direction: function(direction) {
  584. direction = direction || module.get.direction();
  585. $module.removeClass(className[direction]);
  586. },
  587. visible: function() {
  588. $module.removeClass(className.visible);
  589. },
  590. overlay: function() {
  591. $module.removeClass(className.overlay);
  592. }
  593. },
  594. get: {
  595. direction: function() {
  596. if($module.hasClass(className.top)) {
  597. return className.top;
  598. }
  599. else if($module.hasClass(className.right)) {
  600. return className.right;
  601. }
  602. else if($module.hasClass(className.bottom)) {
  603. return className.bottom;
  604. }
  605. return className.left;
  606. },
  607. transition: function() {
  608. var
  609. direction = module.get.direction(),
  610. transition
  611. ;
  612. transition = ( module.is.mobile() )
  613. ? (settings.mobileTransition == 'auto')
  614. ? settings.defaultTransition.mobile[direction]
  615. : settings.mobileTransition
  616. : (settings.transition == 'auto')
  617. ? settings.defaultTransition.computer[direction]
  618. : settings.transition
  619. ;
  620. module.verbose('Determined transition', transition);
  621. return transition;
  622. },
  623. transitionEvent: function() {
  624. var
  625. element = document.createElement('element'),
  626. transitions = {
  627. 'transition' :'transitionend',
  628. 'OTransition' :'oTransitionEnd',
  629. 'MozTransition' :'transitionend',
  630. 'WebkitTransition' :'webkitTransitionEnd'
  631. },
  632. transition
  633. ;
  634. for(transition in transitions){
  635. if( element.style[transition] !== undefined ){
  636. return transitions[transition];
  637. }
  638. }
  639. }
  640. },
  641. is: {
  642. ie: function() {
  643. var
  644. isIE11 = (!(window.ActiveXObject) && 'ActiveXObject' in window),
  645. isIE = ('ActiveXObject' in window)
  646. ;
  647. return (isIE11 || isIE);
  648. },
  649. ios: function() {
  650. var
  651. userAgent = navigator.userAgent,
  652. isIOS = userAgent.match(regExp.ios),
  653. isMobileChrome = userAgent.match(regExp.mobileChrome)
  654. ;
  655. if(isIOS && !isMobileChrome) {
  656. module.verbose('Browser was found to be iOS', userAgent);
  657. return true;
  658. }
  659. else {
  660. return false;
  661. }
  662. },
  663. mobile: function() {
  664. var
  665. userAgent = navigator.userAgent,
  666. isMobile = userAgent.match(regExp.mobile)
  667. ;
  668. if(isMobile) {
  669. module.verbose('Browser was found to be mobile', userAgent);
  670. return true;
  671. }
  672. else {
  673. module.verbose('Browser is not mobile, using regular transition', userAgent);
  674. return false;
  675. }
  676. },
  677. hidden: function() {
  678. return !module.is.visible();
  679. },
  680. visible: function() {
  681. return $module.hasClass(className.visible);
  682. },
  683. // alias
  684. open: function() {
  685. return module.is.visible();
  686. },
  687. closed: function() {
  688. return module.is.hidden();
  689. },
  690. vertical: function() {
  691. return $module.hasClass(className.top);
  692. },
  693. animating: function() {
  694. return $context.hasClass(className.animating);
  695. },
  696. rtl: function () {
  697. if(module.cache.rtl === undefined) {
  698. module.cache.rtl = ($module.css('direction') == 'rtl');
  699. }
  700. return module.cache.rtl;
  701. }
  702. },
  703. setting: function(name, value) {
  704. module.debug('Changing setting', name, value);
  705. if( $.isPlainObject(name) ) {
  706. $.extend(true, settings, name);
  707. }
  708. else if(value !== undefined) {
  709. if($.isPlainObject(settings[name])) {
  710. $.extend(true, settings[name], value);
  711. }
  712. else {
  713. settings[name] = value;
  714. }
  715. }
  716. else {
  717. return settings[name];
  718. }
  719. },
  720. internal: function(name, value) {
  721. if( $.isPlainObject(name) ) {
  722. $.extend(true, module, name);
  723. }
  724. else if(value !== undefined) {
  725. module[name] = value;
  726. }
  727. else {
  728. return module[name];
  729. }
  730. },
  731. debug: function() {
  732. if(!settings.silent && settings.debug) {
  733. if(settings.performance) {
  734. module.performance.log(arguments);
  735. }
  736. else {
  737. module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
  738. module.debug.apply(console, arguments);
  739. }
  740. }
  741. },
  742. verbose: function() {
  743. if(!settings.silent && settings.verbose && settings.debug) {
  744. if(settings.performance) {
  745. module.performance.log(arguments);
  746. }
  747. else {
  748. module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
  749. module.verbose.apply(console, arguments);
  750. }
  751. }
  752. },
  753. error: function() {
  754. if(!settings.silent) {
  755. module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
  756. module.error.apply(console, arguments);
  757. }
  758. },
  759. performance: {
  760. log: function(message) {
  761. var
  762. currentTime,
  763. executionTime,
  764. previousTime
  765. ;
  766. if(settings.performance) {
  767. currentTime = new Date().getTime();
  768. previousTime = time || currentTime;
  769. executionTime = currentTime - previousTime;
  770. time = currentTime;
  771. performance.push({
  772. 'Name' : message[0],
  773. 'Arguments' : [].slice.call(message, 1) || '',
  774. 'Element' : element,
  775. 'Execution Time' : executionTime
  776. });
  777. }
  778. clearTimeout(module.performance.timer);
  779. module.performance.timer = setTimeout(module.performance.display, 500);
  780. },
  781. display: function() {
  782. var
  783. title = settings.name + ':',
  784. totalTime = 0
  785. ;
  786. time = false;
  787. clearTimeout(module.performance.timer);
  788. $.each(performance, function(index, data) {
  789. totalTime += data['Execution Time'];
  790. });
  791. title += ' ' + totalTime + 'ms';
  792. if(moduleSelector) {
  793. title += ' \'' + moduleSelector + '\'';
  794. }
  795. if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
  796. console.groupCollapsed(title);
  797. if(console.table) {
  798. console.table(performance);
  799. }
  800. else {
  801. $.each(performance, function(index, data) {
  802. console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
  803. });
  804. }
  805. console.groupEnd();
  806. }
  807. performance = [];
  808. }
  809. },
  810. invoke: function(query, passedArguments, context) {
  811. var
  812. object = instance,
  813. maxDepth,
  814. found,
  815. response
  816. ;
  817. passedArguments = passedArguments || queryArguments;
  818. context = element || context;
  819. if(typeof query == 'string' && object !== undefined) {
  820. query = query.split(/[\. ]/);
  821. maxDepth = query.length - 1;
  822. $.each(query, function(depth, value) {
  823. var camelCaseValue = (depth != maxDepth)
  824. ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
  825. : query
  826. ;
  827. if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
  828. object = object[camelCaseValue];
  829. }
  830. else if( object[camelCaseValue] !== undefined ) {
  831. found = object[camelCaseValue];
  832. return false;
  833. }
  834. else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
  835. object = object[value];
  836. }
  837. else if( object[value] !== undefined ) {
  838. found = object[value];
  839. return false;
  840. }
  841. else {
  842. module.error(error.method, query);
  843. return false;
  844. }
  845. });
  846. }
  847. if ( $.isFunction( found ) ) {
  848. response = found.apply(context, passedArguments);
  849. }
  850. else if(found !== undefined) {
  851. response = found;
  852. }
  853. if($.isArray(returnedValue)) {
  854. returnedValue.push(response);
  855. }
  856. else if(returnedValue !== undefined) {
  857. returnedValue = [returnedValue, response];
  858. }
  859. else if(response !== undefined) {
  860. returnedValue = response;
  861. }
  862. return found;
  863. }
  864. }
  865. ;
  866. if(methodInvoked) {
  867. if(instance === undefined) {
  868. module.initialize();
  869. }
  870. module.invoke(query);
  871. }
  872. else {
  873. if(instance !== undefined) {
  874. module.invoke('destroy');
  875. }
  876. module.initialize();
  877. }
  878. });
  879. return (returnedValue !== undefined)
  880. ? returnedValue
  881. : this
  882. ;
  883. };
  884. $.fn.sidebar.settings = {
  885. name : 'Sidebar',
  886. namespace : 'sidebar',
  887. silent : false,
  888. debug : false,
  889. verbose : false,
  890. performance : true,
  891. transition : 'auto',
  892. mobileTransition : 'auto',
  893. defaultTransition : {
  894. computer: {
  895. left : 'uncover',
  896. right : 'uncover',
  897. top : 'overlay',
  898. bottom : 'overlay'
  899. },
  900. mobile: {
  901. left : 'uncover',
  902. right : 'uncover',
  903. top : 'overlay',
  904. bottom : 'overlay'
  905. }
  906. },
  907. context : 'body',
  908. exclusive : false,
  909. closable : true,
  910. dimPage : true,
  911. scrollLock : false,
  912. returnScroll : false,
  913. delaySetup : false,
  914. duration : 500,
  915. onChange : function(){},
  916. onShow : function(){},
  917. onHide : function(){},
  918. onHidden : function(){},
  919. onVisible : function(){},
  920. className : {
  921. active : 'active',
  922. animating : 'animating',
  923. dimmed : 'dimmed',
  924. ios : 'ios',
  925. pushable : 'pushable',
  926. pushed : 'pushed',
  927. right : 'right',
  928. top : 'top',
  929. left : 'left',
  930. bottom : 'bottom',
  931. visible : 'visible'
  932. },
  933. selector: {
  934. fixed : '.fixed',
  935. omitted : 'script, link, style, .ui.modal, .ui.dimmer, .ui.nag, .ui.fixed',
  936. pusher : '.pusher',
  937. sidebar : '.ui.sidebar'
  938. },
  939. regExp: {
  940. ios : /(iPad|iPhone|iPod)/g,
  941. mobileChrome : /(CriOS)/g,
  942. 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
  943. },
  944. error : {
  945. method : 'The method you called is not defined.',
  946. pusher : 'Had to add pusher element. For optimal performance make sure body content is inside a pusher element',
  947. movedSidebar : 'Had to move sidebar. For optimal performance make sure sidebar and pusher are direct children of your body tag',
  948. overlay : 'The overlay setting is no longer supported, use animation: overlay',
  949. notFound : 'There were no elements that matched the specified selector'
  950. }
  951. };
  952. })( jQuery, window, document );