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.

1022 lines
32 KiB

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