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.

937 lines
30 KiB

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