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.

1073 lines
34 KiB

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