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.

1023 lines
32 KiB

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