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.

1037 lines
33 KiB

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