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.

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