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.

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