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.

1089 lines
35 KiB

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