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.

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