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.

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