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.

935 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
  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.set.transition();
  333. module.repaint();
  334. animate = function() {
  335. module.add.bodyCSS();
  336. module.set.animating();
  337. module.set.visible();
  338. if(!module.othersActive()) {
  339. if(settings.dimPage) {
  340. $pusher.addClass(className.dimmed);
  341. }
  342. }
  343. };
  344. transitionEnd = function(event) {
  345. if( event.target == $transition[0] ) {
  346. $transition.off(transitionEvent + eventNamespace, transitionEnd);
  347. module.remove.animating();
  348. module.bind.clickaway();
  349. $.proxy(callback, element)();
  350. }
  351. };
  352. $transition.on(transitionEvent + eventNamespace, transitionEnd);
  353. requestAnimationFrame(animate);
  354. },
  355. pullPage: function(callback) {
  356. var
  357. transition = module.get.transition(),
  358. $transition = (transition == 'safe')
  359. ? $context
  360. : (transition == 'overlay' || module.othersActive())
  361. ? $module
  362. : $pusher,
  363. animate,
  364. transitionEnd
  365. ;
  366. callback = $.isFunction(callback)
  367. ? callback
  368. : function(){}
  369. ;
  370. module.verbose('Removing context push state', module.get.direction());
  371. if(!module.othersActive()) {
  372. module.unbind.clickaway();
  373. }
  374. animate = function() {
  375. module.set.animating();
  376. module.remove.visible();
  377. if(settings.dimPage && !module.othersActive()) {
  378. $pusher.removeClass(className.dimmed);
  379. }
  380. };
  381. transitionEnd = function(event) {
  382. if( event.target == $transition[0] ) {
  383. $transition.off(transitionEvent + eventNamespace, transitionEnd);
  384. module.remove.animating();
  385. module.remove.transition();
  386. module.remove.bodyCSS();
  387. if(transition == 'scale down' || (settings.returnScroll && module.is.mobile()) ) {
  388. module.scrollBack();
  389. }
  390. $.proxy(callback, element)();
  391. }
  392. };
  393. $transition.on(transitionEvent + eventNamespace, transitionEnd);
  394. requestAnimationFrame(animate);
  395. },
  396. legacyPushPage: function(callback) {
  397. var
  398. distance = $module.width(),
  399. direction = module.get.direction(),
  400. properties = {}
  401. ;
  402. distance = distance || $module.width();
  403. callback = $.isFunction(callback)
  404. ? callback
  405. : function(){}
  406. ;
  407. properties[direction] = distance;
  408. module.debug('Using javascript to push context', properties);
  409. module.set.visible();
  410. module.set.transition();
  411. module.set.animating();
  412. if(settings.dimPage) {
  413. $pusher.addClass(className.dimmed);
  414. }
  415. $context
  416. .css('position', 'relative')
  417. .animate(properties, settings.duration, settings.easing, function() {
  418. module.remove.animating();
  419. module.bind.clickaway();
  420. $.proxy(callback, module)();
  421. })
  422. ;
  423. },
  424. legacyPullPage: function(callback) {
  425. var
  426. distance = 0,
  427. direction = module.get.direction(),
  428. properties = {}
  429. ;
  430. distance = distance || $module.width();
  431. callback = $.isFunction(callback)
  432. ? callback
  433. : function(){}
  434. ;
  435. properties[direction] = '0px';
  436. module.debug('Using javascript to pull context', properties);
  437. module.unbind.clickaway();
  438. module.set.animating();
  439. module.remove.visible();
  440. if(settings.dimPage && !module.othersVisible()) {
  441. $pusher.removeClass(className.dimmed);
  442. }
  443. $context
  444. .css('position', 'relative')
  445. .animate(properties, settings.duration, settings.easing, function() {
  446. module.remove.animating();
  447. $.proxy(callback, module)();
  448. })
  449. ;
  450. },
  451. scrollToTop: function() {
  452. module.verbose('Scrolling to top of page to avoid animation issues');
  453. currentScroll = $(window).scrollTop();
  454. $module.scrollTop(0);
  455. window.scrollTo(0, 0);
  456. },
  457. scrollBack: function() {
  458. module.verbose('Scrolling back to original page position');
  459. window.scrollTo(0, currentScroll);
  460. },
  461. set: {
  462. // container
  463. pushed: function() {
  464. $context.addClass(className.pushed);
  465. },
  466. pushable: function() {
  467. $context.addClass(className.pushable);
  468. },
  469. // sidebar
  470. active: function() {
  471. $module.addClass(className.active);
  472. },
  473. animating: function() {
  474. $module.addClass(className.animating);
  475. },
  476. transition: function(transition) {
  477. transition = transition || module.get.transition();
  478. $module.addClass(transition);
  479. },
  480. direction: function(direction) {
  481. direction = direction || module.get.direction();
  482. $module.addClass(className[direction]);
  483. },
  484. visible: function() {
  485. $module.addClass(className.visible);
  486. },
  487. overlay: function() {
  488. $module.addClass(className.overlay);
  489. }
  490. },
  491. remove: {
  492. bodyCSS: function() {
  493. module.debug('Removing body css styles', $style);
  494. if($style.size() > 0) {
  495. $style.remove();
  496. }
  497. },
  498. // context
  499. pushed: function() {
  500. $context.removeClass(className.pushed);
  501. },
  502. pushable: function() {
  503. $context.removeClass(className.pushable);
  504. },
  505. // sidebar
  506. active: function() {
  507. $module.removeClass(className.active);
  508. },
  509. animating: function() {
  510. $module.removeClass(className.animating);
  511. },
  512. transition: function(transition) {
  513. transition = transition || module.get.transition();
  514. $module.removeClass(transition);
  515. },
  516. direction: function(direction) {
  517. direction = direction || module.get.direction();
  518. $module.removeClass(className[direction]);
  519. },
  520. visible: function() {
  521. $module.removeClass(className.visible);
  522. },
  523. overlay: function() {
  524. $module.removeClass(className.overlay);
  525. }
  526. },
  527. get: {
  528. direction: function() {
  529. if($module.hasClass(className.top)) {
  530. return className.top;
  531. }
  532. else if($module.hasClass(className.right)) {
  533. return className.right;
  534. }
  535. else if($module.hasClass(className.bottom)) {
  536. return className.bottom;
  537. }
  538. return className.left;
  539. },
  540. transition: function() {
  541. var
  542. direction = module.get.direction(),
  543. transition
  544. ;
  545. return ( module.is.mobile() )
  546. ? (settings.mobileTransition == 'auto')
  547. ? settings.defaultTransition.mobile[direction]
  548. : settings.mobileTransition
  549. : (settings.transition == 'auto')
  550. ? settings.defaultTransition.computer[direction]
  551. : settings.transition
  552. ;
  553. },
  554. transitionEvent: function() {
  555. var
  556. element = document.createElement('element'),
  557. transitions = {
  558. 'transition' :'transitionend',
  559. 'OTransition' :'oTransitionEnd',
  560. 'MozTransition' :'transitionend',
  561. 'WebkitTransition' :'webkitTransitionEnd'
  562. },
  563. transition
  564. ;
  565. for(transition in transitions){
  566. if( element.style[transition] !== undefined ){
  567. return transitions[transition];
  568. }
  569. }
  570. }
  571. },
  572. is: {
  573. legacy: function() {
  574. var
  575. element = document.createElement('div'),
  576. transforms = {
  577. 'webkitTransform' :'-webkit-transform',
  578. 'OTransform' :'-o-transform',
  579. 'msTransform' :'-ms-transform',
  580. 'MozTransform' :'-moz-transform',
  581. 'transform' :'transform'
  582. },
  583. has3D
  584. ;
  585. // Add it to the body to get the computed style.
  586. document.body.insertBefore(element, null);
  587. for (var transform in transforms) {
  588. if (element.style[transform] !== undefined) {
  589. element.style[transform] = "translate3d(1px,1px,1px)";
  590. has3D = window.getComputedStyle(element).getPropertyValue(transforms[transform]);
  591. }
  592. }
  593. document.body.removeChild(element);
  594. return !(has3D !== undefined && has3D.length > 0 && has3D !== 'none');
  595. },
  596. mobile: function() {
  597. var
  598. userAgent = navigator.userAgent,
  599. 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/,
  600. isMobile = mobileRegExp.test(userAgent)
  601. ;
  602. if(isMobile) {
  603. module.verbose('Browser was found to be mobile', userAgent);
  604. return true;
  605. }
  606. else {
  607. module.verbose('Browser is not mobile, using regular transition', userAgent);
  608. return false;
  609. }
  610. },
  611. closed: function() {
  612. return !module.is.visible();
  613. },
  614. visible: function() {
  615. return $module.hasClass(className.visible);
  616. },
  617. vertical: function() {
  618. return $module.hasClass(className.top);
  619. },
  620. animating: function() {
  621. return $context.hasClass(className.animating);
  622. }
  623. },
  624. setting: function(name, value) {
  625. module.debug('Changing setting', name, value);
  626. if( $.isPlainObject(name) ) {
  627. $.extend(true, settings, name);
  628. }
  629. else if(value !== undefined) {
  630. settings[name] = value;
  631. }
  632. else {
  633. return settings[name];
  634. }
  635. },
  636. internal: function(name, value) {
  637. if( $.isPlainObject(name) ) {
  638. $.extend(true, module, name);
  639. }
  640. else if(value !== undefined) {
  641. module[name] = value;
  642. }
  643. else {
  644. return module[name];
  645. }
  646. },
  647. debug: function() {
  648. if(settings.debug) {
  649. if(settings.performance) {
  650. module.performance.log(arguments);
  651. }
  652. else {
  653. module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
  654. module.debug.apply(console, arguments);
  655. }
  656. }
  657. },
  658. verbose: function() {
  659. if(settings.verbose && settings.debug) {
  660. if(settings.performance) {
  661. module.performance.log(arguments);
  662. }
  663. else {
  664. module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
  665. module.verbose.apply(console, arguments);
  666. }
  667. }
  668. },
  669. error: function() {
  670. module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
  671. module.error.apply(console, arguments);
  672. },
  673. performance: {
  674. log: function(message) {
  675. var
  676. currentTime,
  677. executionTime,
  678. previousTime
  679. ;
  680. if(settings.performance) {
  681. currentTime = new Date().getTime();
  682. previousTime = time || currentTime;
  683. executionTime = currentTime - previousTime;
  684. time = currentTime;
  685. performance.push({
  686. 'Name' : message[0],
  687. 'Arguments' : [].slice.call(message, 1) || '',
  688. 'Element' : element,
  689. 'Execution Time' : executionTime
  690. });
  691. }
  692. clearTimeout(module.performance.timer);
  693. module.performance.timer = setTimeout(module.performance.display, 100);
  694. },
  695. display: function() {
  696. var
  697. title = settings.name + ':',
  698. totalTime = 0
  699. ;
  700. time = false;
  701. clearTimeout(module.performance.timer);
  702. $.each(performance, function(index, data) {
  703. totalTime += data['Execution Time'];
  704. });
  705. title += ' ' + totalTime + 'ms';
  706. if(moduleSelector) {
  707. title += ' \'' + moduleSelector + '\'';
  708. }
  709. if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
  710. console.groupCollapsed(title);
  711. if(console.table) {
  712. console.table(performance);
  713. }
  714. else {
  715. $.each(performance, function(index, data) {
  716. console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
  717. });
  718. }
  719. console.groupEnd();
  720. }
  721. performance = [];
  722. }
  723. },
  724. invoke: function(query, passedArguments, context) {
  725. var
  726. object = instance,
  727. maxDepth,
  728. found,
  729. response
  730. ;
  731. passedArguments = passedArguments || queryArguments;
  732. context = element || context;
  733. if(typeof query == 'string' && object !== undefined) {
  734. query = query.split(/[\. ]/);
  735. maxDepth = query.length - 1;
  736. $.each(query, function(depth, value) {
  737. var camelCaseValue = (depth != maxDepth)
  738. ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
  739. : query
  740. ;
  741. if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
  742. object = object[camelCaseValue];
  743. }
  744. else if( object[camelCaseValue] !== undefined ) {
  745. found = object[camelCaseValue];
  746. return false;
  747. }
  748. else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
  749. object = object[value];
  750. }
  751. else if( object[value] !== undefined ) {
  752. found = object[value];
  753. return false;
  754. }
  755. else {
  756. module.error(error.method, query);
  757. return false;
  758. }
  759. });
  760. }
  761. if ( $.isFunction( found ) ) {
  762. response = found.apply(context, passedArguments);
  763. }
  764. else if(found !== undefined) {
  765. response = found;
  766. }
  767. if($.isArray(returnedValue)) {
  768. returnedValue.push(response);
  769. }
  770. else if(returnedValue !== undefined) {
  771. returnedValue = [returnedValue, response];
  772. }
  773. else if(response !== undefined) {
  774. returnedValue = response;
  775. }
  776. return found;
  777. }
  778. }
  779. ;
  780. if(methodInvoked) {
  781. if(instance === undefined) {
  782. module.initialize();
  783. }
  784. module.invoke(query);
  785. }
  786. else {
  787. if(instance !== undefined) {
  788. module.invoke('destroy');
  789. }
  790. module.initialize();
  791. }
  792. });
  793. return (returnedValue !== undefined)
  794. ? returnedValue
  795. : this
  796. ;
  797. };
  798. $.fn.sidebar.settings = {
  799. name : 'Sidebar',
  800. namespace : 'sidebar',
  801. debug : false,
  802. verbose : true,
  803. performance : true,
  804. transition : 'auto',
  805. mobileTransition : 'auto',
  806. defaultTransition : {
  807. computer: {
  808. left : 'push',
  809. right : 'push',
  810. top : 'overlay',
  811. bottom : 'overlay'
  812. },
  813. mobile: {
  814. left : 'push',
  815. right : 'push',
  816. top : 'overlay',
  817. bottom : 'overlay'
  818. }
  819. },
  820. context : 'body',
  821. exclusive : false,
  822. closable : true,
  823. dimPage : true,
  824. scrollLock : false,
  825. returnScroll : false,
  826. useLegacy : false,
  827. duration : 500,
  828. easing : 'easeInOutQuint',
  829. onChange : function(){},
  830. onShow : function(){},
  831. onHide : function(){},
  832. onHidden : function(){},
  833. onVisible : function(){},
  834. className : {
  835. active : 'active',
  836. animating : 'animating',
  837. dimmed : 'dimmed',
  838. pushable : 'pushable',
  839. pushed : 'pushed',
  840. right : 'right',
  841. top : 'top',
  842. left : 'left',
  843. bottom : 'bottom',
  844. visible : 'visible'
  845. },
  846. selector: {
  847. fixed : '.fixed',
  848. omitted : 'script, link, style, .ui.modal, .ui.dimmer, .ui.nag, .ui.fixed',
  849. pusher : '.pusher',
  850. sidebar : '.ui.sidebar'
  851. },
  852. error : {
  853. method : 'The method you called is not defined.',
  854. pusher : 'Had to add pusher element. For optimal performance make sure body content is inside a pusher element',
  855. movedSidebar : 'Had to move sidebar. For optimal performance make sure sidebar and pusher are direct children of your body tag',
  856. overlay : 'The overlay setting is no longer supported, use animation: overlay',
  857. notFound : 'There were no elements that matched the specified selector'
  858. }
  859. };
  860. // Adds easing
  861. $.extend( $.easing, {
  862. easeInOutQuint: function (x, t, b, c, d) {
  863. if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
  864. return c/2*((t-=2)*t*t*t*t + 2) + b;
  865. }
  866. });
  867. })( jQuery, window , document );