sidebar.js 33 KB

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