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.

1008 lines
31 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
  1. /*
  2. * # Semantic - Dropdown
  3. * http://github.com/jlukic/semantic-ui/
  4. *
  5. *
  6. * Copyright 2014 Contributors
  7. * Released under the MIT license
  8. * http://opensource.org/licenses/MIT
  9. *
  10. */
  11. ;(function ( $, window, document, undefined ) {
  12. module.exports = function(parameters) {
  13. var _module = module;
  14. var
  15. $allModules = $(this),
  16. $document = $(document),
  17. moduleSelector = $allModules.selector || '',
  18. hasTouch = ('ontouchstart' in document.documentElement),
  19. time = new Date().getTime(),
  20. performance = [],
  21. query = arguments[0],
  22. methodInvoked = (typeof query == 'string'),
  23. queryArguments = [].slice.call(arguments, 1),
  24. returnedValue
  25. ;
  26. $allModules
  27. .each(function() {
  28. var
  29. settings = ( $.isPlainObject(parameters) )
  30. ? $.extend(true, {}, _module.exports.settings, parameters)
  31. : $.extend({}, _module.exports.settings),
  32. className = settings.className,
  33. metadata = settings.metadata,
  34. namespace = settings.namespace,
  35. selector = settings.selector,
  36. error = settings.error,
  37. eventNamespace = '.' + namespace,
  38. moduleNamespace = 'module-' + namespace,
  39. $module = $(this),
  40. $item = $module.find(selector.item),
  41. $text = $module.find(selector.text),
  42. $input = $module.find(selector.input),
  43. $menu = $module.children(selector.menu),
  44. element = this,
  45. instance = $module.data(moduleNamespace),
  46. module
  47. ;
  48. module = {
  49. initialize: function() {
  50. module.debug('Initializing dropdown', settings);
  51. module.save.defaults();
  52. module.set.selected();
  53. if(hasTouch) {
  54. module.bind.touchEvents();
  55. }
  56. module.bind.mouseEvents();
  57. module.bind.keyboardEvents();
  58. module.instantiate();
  59. },
  60. instantiate: function() {
  61. module.verbose('Storing instance of dropdown', module);
  62. instance = module;
  63. $module
  64. .data(moduleNamespace, module)
  65. ;
  66. },
  67. destroy: function() {
  68. module.verbose('Destroying previous dropdown for', $module);
  69. $item
  70. .off(eventNamespace)
  71. ;
  72. $module
  73. .off(eventNamespace)
  74. .removeData(moduleNamespace)
  75. ;
  76. },
  77. bind: {
  78. keyboardEvents: function() {
  79. module.debug('Binding keyboard events');
  80. $module
  81. .on('keydown' + eventNamespace, module.handleKeyboard)
  82. ;
  83. $module
  84. .on('focus' + eventNamespace, module.show)
  85. ;
  86. },
  87. touchEvents: function() {
  88. module.debug('Touch device detected binding touch events');
  89. $module
  90. .on('touchstart' + eventNamespace, module.event.test.toggle)
  91. ;
  92. $item
  93. .on('touchstart' + eventNamespace, module.event.item.mouseenter)
  94. .on('touchstart' + eventNamespace, module.event.item.click)
  95. ;
  96. },
  97. mouseEvents: function() {
  98. module.verbose('Mouse detected binding mouse events');
  99. if(settings.on == 'click') {
  100. $module
  101. .on('click' + eventNamespace, module.event.test.toggle)
  102. ;
  103. }
  104. else if(settings.on == 'hover') {
  105. $module
  106. .on('mouseenter' + eventNamespace, module.delay.show)
  107. .on('mouseleave' + eventNamespace, module.delay.hide)
  108. ;
  109. }
  110. else {
  111. $module
  112. .on(settings.on + eventNamespace, module.toggle)
  113. ;
  114. }
  115. $item
  116. .on('mouseenter' + eventNamespace, module.event.item.mouseenter)
  117. .on('mouseleave' + eventNamespace, module.event.item.mouseleave)
  118. .on('click' + eventNamespace, module.event.item.click)
  119. ;
  120. },
  121. intent: function() {
  122. module.verbose('Binding hide intent event to document');
  123. if(hasTouch) {
  124. $document
  125. .on('touchstart' + eventNamespace, module.event.test.touch)
  126. .on('touchmove' + eventNamespace, module.event.test.touch)
  127. ;
  128. }
  129. $document
  130. .on('click' + eventNamespace, module.event.test.hide)
  131. ;
  132. }
  133. },
  134. unbind: {
  135. intent: function() {
  136. module.verbose('Removing hide intent event from document');
  137. if(hasTouch) {
  138. $document
  139. .off('touchstart' + eventNamespace)
  140. .off('touchmove' + eventNamespace)
  141. ;
  142. }
  143. $document
  144. .off('click' + eventNamespace)
  145. ;
  146. }
  147. },
  148. handleKeyboard: function(event) {
  149. var
  150. $selectedItem = $item.filter('.' + className.selected),
  151. pressedKey = event.which,
  152. keys = {
  153. enter : 13,
  154. escape : 27,
  155. upArrow : 38,
  156. downArrow : 40
  157. },
  158. selectedClass = className.selected,
  159. currentIndex = $item.index( $selectedItem ),
  160. hasSelectedItem = ($selectedItem.size() > 0),
  161. resultSize = $item.size(),
  162. newIndex
  163. ;
  164. // close shortcuts
  165. if(pressedKey == keys.escape) {
  166. module.verbose('Escape key pressed, closing dropdown');
  167. module.hide();
  168. }
  169. // result shortcuts
  170. if(module.is.visible()) {
  171. if(pressedKey == keys.enter && hasSelectedItem) {
  172. module.verbose('Enter key pressed, choosing selected item');
  173. $.proxy(module.event.item.click, $item.filter('.' + selectedClass) )(event);
  174. event.preventDefault();
  175. return false;
  176. }
  177. else if(pressedKey == keys.upArrow) {
  178. module.verbose('Up key pressed, changing active item');
  179. newIndex = (currentIndex - 1 < 0)
  180. ? currentIndex
  181. : currentIndex - 1
  182. ;
  183. $item
  184. .removeClass(selectedClass)
  185. .eq(newIndex)
  186. .addClass(selectedClass)
  187. ;
  188. event.preventDefault();
  189. }
  190. else if(pressedKey == keys.downArrow) {
  191. module.verbose('Down key pressed, changing active item');
  192. newIndex = (currentIndex + 1 >= resultSize)
  193. ? currentIndex
  194. : currentIndex + 1
  195. ;
  196. $item
  197. .removeClass(selectedClass)
  198. .eq(newIndex)
  199. .addClass(selectedClass)
  200. ;
  201. event.preventDefault();
  202. }
  203. }
  204. else {
  205. if(pressedKey == keys.enter) {
  206. module.show();
  207. }
  208. }
  209. },
  210. event: {
  211. test: {
  212. toggle: function(event) {
  213. if( module.determine.intent(event, module.toggle) ) {
  214. event.preventDefault();
  215. }
  216. },
  217. touch: function(event) {
  218. module.determine.intent(event, function() {
  219. if(event.type == 'touchstart') {
  220. module.timer = setTimeout(module.hide, settings.delay.touch);
  221. }
  222. else if(event.type == 'touchmove') {
  223. clearTimeout(module.timer);
  224. }
  225. });
  226. event.stopPropagation();
  227. },
  228. hide: function(event) {
  229. module.determine.intent(event, module.hide);
  230. }
  231. },
  232. item: {
  233. mouseenter: function(event) {
  234. var
  235. $currentMenu = $(this).find(selector.submenu),
  236. $otherMenus = $(this).siblings(selector.item).children(selector.menu)
  237. ;
  238. if($currentMenu.length > 0 || $otherMenus.length > 0) {
  239. clearTimeout(module.itemTimer);
  240. module.itemTimer = setTimeout(function() {
  241. if($otherMenus.length > 0) {
  242. module.animate.hide(false, $otherMenus.filter(':visible'));
  243. }
  244. if($currentMenu.length > 0) {
  245. module.verbose('Showing sub-menu', $currentMenu);
  246. module.animate.show(false, $currentMenu);
  247. }
  248. }, settings.delay.show * 2);
  249. event.preventDefault();
  250. event.stopPropagation();
  251. }
  252. },
  253. mouseleave: function(event) {
  254. var
  255. $currentMenu = $(this).find(selector.menu)
  256. ;
  257. if($currentMenu.size() > 0) {
  258. clearTimeout(module.itemTimer);
  259. module.itemTimer = setTimeout(function() {
  260. module.verbose('Hiding sub-menu', $currentMenu);
  261. module.animate.hide(false, $currentMenu);
  262. }, settings.delay.hide);
  263. }
  264. },
  265. click: function (event) {
  266. var
  267. $choice = $(this),
  268. text = ( $choice.data(metadata.text) !== undefined )
  269. ? $choice.data(metadata.text)
  270. : $choice.text(),
  271. value = ( $choice.data(metadata.value) !== undefined)
  272. ? $choice.data(metadata.value)
  273. : (typeof text === 'string')
  274. ? text.toLowerCase()
  275. : text,
  276. callback = function() {
  277. module.determine.selectAction(text, value);
  278. $.proxy(settings.onChange, element)(value, text);
  279. }
  280. ;
  281. if( $choice.find(selector.menu).size() === 0 ) {
  282. if(event.type == 'touchstart') {
  283. $choice.one('click', callback);
  284. }
  285. else {
  286. callback();
  287. }
  288. }
  289. }
  290. },
  291. resetStyle: function() {
  292. $(this).removeAttr('style');
  293. }
  294. },
  295. determine: {
  296. selectAction: function(text, value) {
  297. module.verbose('Determining action', settings.action);
  298. if( $.isFunction( module.action[settings.action] ) ) {
  299. module.verbose('Triggering preset action', settings.action, text, value);
  300. module.action[ settings.action ](text, value);
  301. }
  302. else if( $.isFunction(settings.action) ) {
  303. module.verbose('Triggering user action', settings.action, text, value);
  304. settings.action(text, value);
  305. }
  306. else {
  307. module.error(error.action, settings.action);
  308. }
  309. },
  310. intent: function(event, callback) {
  311. module.debug('Determining whether event occurred in dropdown', event.target);
  312. callback = callback || function(){};
  313. if( $(event.target).closest($menu).size() === 0 ) {
  314. module.verbose('Triggering event', callback);
  315. callback();
  316. return true;
  317. }
  318. else {
  319. module.verbose('Event occurred in dropdown, canceling callback');
  320. return false;
  321. }
  322. }
  323. },
  324. action: {
  325. nothing: function() {},
  326. hide: function() {
  327. module.hide();
  328. },
  329. activate: function(text, value) {
  330. value = (value !== undefined)
  331. ? value
  332. : text
  333. ;
  334. module.set.selected(value);
  335. module.set.value(value);
  336. module.hide();
  337. },
  338. /* Deprecated */
  339. auto: function(text, value) {
  340. value = (value !== undefined)
  341. ? value
  342. : text
  343. ;
  344. module.set.selected(value);
  345. module.set.value(value);
  346. module.hide();
  347. },
  348. /* Deprecated */
  349. changeText: function(text, value) {
  350. value = (value !== undefined)
  351. ? value
  352. : text
  353. ;
  354. module.set.selected(value);
  355. module.hide();
  356. },
  357. /* Deprecated */
  358. updateForm: function(text, value) {
  359. value = (value !== undefined)
  360. ? value
  361. : text
  362. ;
  363. module.set.selected(value);
  364. module.set.value(value);
  365. module.hide();
  366. }
  367. },
  368. get: {
  369. text: function() {
  370. return $text.text();
  371. },
  372. value: function() {
  373. return ($input.size() > 0)
  374. ? $input.val()
  375. : $module.data(metadata.value)
  376. ;
  377. },
  378. item: function(value, strict) {
  379. var
  380. $selectedItem = false
  381. ;
  382. value = (value !== undefined)
  383. ? value
  384. : ( module.get.value() !== undefined)
  385. ? module.get.value()
  386. : module.get.text()
  387. ;
  388. if(strict === undefined && value === '') {
  389. module.debug('Ambiguous dropdown value using strict type check', value);
  390. strict = true;
  391. }
  392. else {
  393. strict = strict || false;
  394. }
  395. if(value !== undefined) {
  396. $item
  397. .each(function() {
  398. var
  399. $choice = $(this),
  400. optionText = ( $choice.data(metadata.text) !== undefined )
  401. ? $choice.data(metadata.text)
  402. : $choice.text(),
  403. optionValue = ( $choice.data(metadata.value) !== undefined )
  404. ? $choice.data(metadata.value)
  405. : (typeof optionText === 'string')
  406. ? optionText.toLowerCase()
  407. : optionText
  408. ;
  409. if(strict) {
  410. if( optionValue === value ) {
  411. $selectedItem = $(this);
  412. }
  413. else if( !$selectedItem && optionText === value ) {
  414. $selectedItem = $(this);
  415. }
  416. }
  417. else {
  418. if( optionValue == value ) {
  419. $selectedItem = $(this);
  420. }
  421. else if( !$selectedItem && optionText == value ) {
  422. $selectedItem = $(this);
  423. }
  424. }
  425. })
  426. ;
  427. }
  428. else {
  429. value = module.get.text();
  430. }
  431. return $selectedItem || false;
  432. }
  433. },
  434. restore: {
  435. defaults: function() {
  436. module.restore.defaultText();
  437. module.restore.defaultValue();
  438. },
  439. defaultText: function() {
  440. var
  441. defaultText = $module.data(metadata.defaultText)
  442. ;
  443. module.debug('Restoring default text', defaultText);
  444. module.set.text(defaultText);
  445. },
  446. defaultValue: function() {
  447. var
  448. defaultValue = $module.data(metadata.defaultValue)
  449. ;
  450. if(defaultValue !== undefined) {
  451. module.debug('Restoring default value', defaultValue);
  452. module.set.selected(defaultValue);
  453. module.set.value(defaultValue);
  454. }
  455. }
  456. },
  457. save: {
  458. defaults: function() {
  459. module.save.defaultText();
  460. module.save.defaultValue();
  461. },
  462. defaultValue: function() {
  463. $module.data(metadata.defaultValue, module.get.value() );
  464. },
  465. defaultText: function() {
  466. $module.data(metadata.defaultText, $text.text() );
  467. }
  468. },
  469. set: {
  470. text: function(text) {
  471. module.debug('Changing text', text, $text);
  472. $text.removeClass(className.placeholder);
  473. $text.text(text);
  474. },
  475. value: function(value) {
  476. module.debug('Adding selected value to hidden input', value, $input);
  477. if($input.size() > 0) {
  478. $input
  479. .val(value)
  480. .trigger('change')
  481. ;
  482. }
  483. else {
  484. $module.data(metadata.value, value);
  485. }
  486. },
  487. active: function() {
  488. $module.addClass(className.active);
  489. },
  490. visible: function() {
  491. $module.addClass(className.visible);
  492. },
  493. selected: function(value) {
  494. var
  495. $selectedItem = module.get.item(value),
  496. selectedText
  497. ;
  498. if($selectedItem) {
  499. module.debug('Setting selected menu item to', $selectedItem);
  500. selectedText = ($selectedItem.data(metadata.text) !== undefined)
  501. ? $selectedItem.data(metadata.text)
  502. : $selectedItem.text()
  503. ;
  504. $item
  505. .removeClass(className.active)
  506. ;
  507. $selectedItem
  508. .addClass(className.active)
  509. ;
  510. module.set.text(selectedText);
  511. }
  512. }
  513. },
  514. remove: {
  515. active: function() {
  516. $module.removeClass(className.active);
  517. },
  518. visible: function() {
  519. $module.removeClass(className.visible);
  520. }
  521. },
  522. is: {
  523. selection: function() {
  524. return $module.hasClass(className.selection);
  525. },
  526. animated: function($subMenu) {
  527. return ($subMenu)
  528. ? $subMenu.is(':animated') || $subMenu.transition && $subMenu.transition('is animating')
  529. : $menu.is(':animated') || $menu.transition && $menu.transition('is animating')
  530. ;
  531. },
  532. visible: function($subMenu) {
  533. return ($subMenu)
  534. ? $subMenu.is(':visible')
  535. : $menu.is(':visible')
  536. ;
  537. },
  538. hidden: function($subMenu) {
  539. return ($subMenu)
  540. ? $subMenu.is(':not(:visible)')
  541. : $menu.is(':not(:visible)')
  542. ;
  543. }
  544. },
  545. can: {
  546. click: function() {
  547. return (hasTouch || settings.on == 'click');
  548. },
  549. show: function() {
  550. return !$module.hasClass(className.disabled);
  551. }
  552. },
  553. animate: {
  554. show: function(callback, $subMenu) {
  555. var
  556. $currentMenu = $subMenu || $menu
  557. ;
  558. callback = callback || function(){};
  559. if( module.is.hidden($currentMenu) ) {
  560. module.verbose('Doing menu show animation', $currentMenu);
  561. if(settings.transition == 'none') {
  562. callback();
  563. }
  564. else if($.fn.transition !== undefined && $module.transition('is supported')) {
  565. $currentMenu
  566. .transition({
  567. animation : settings.transition + ' in',
  568. duration : settings.duration,
  569. complete : callback,
  570. queue : false
  571. })
  572. ;
  573. }
  574. else if(settings.transition == 'slide down') {
  575. $currentMenu
  576. .hide()
  577. .clearQueue()
  578. .children()
  579. .clearQueue()
  580. .css('opacity', 0)
  581. .delay(50)
  582. .animate({
  583. opacity : 1
  584. }, settings.duration, 'easeOutQuad', module.event.resetStyle)
  585. .end()
  586. .slideDown(100, 'easeOutQuad', function() {
  587. $.proxy(module.event.resetStyle, this)();
  588. callback();
  589. })
  590. ;
  591. }
  592. else if(settings.transition == 'fade') {
  593. $currentMenu
  594. .hide()
  595. .clearQueue()
  596. .fadeIn(settings.duration, function() {
  597. $.proxy(module.event.resetStyle, this)();
  598. callback();
  599. })
  600. ;
  601. }
  602. else {
  603. module.error(error.transition, settings.transition);
  604. }
  605. }
  606. },
  607. hide: function(callback, $subMenu) {
  608. var
  609. $currentMenu = $subMenu || $menu
  610. ;
  611. callback = callback || function(){};
  612. if(module.is.visible($currentMenu) ) {
  613. module.verbose('Doing menu hide animation', $currentMenu);
  614. if($.fn.transition !== undefined && $module.transition('is supported')) {
  615. $currentMenu
  616. .transition({
  617. animation : settings.transition + ' out',
  618. duration : settings.duration,
  619. complete : callback,
  620. queue : false
  621. })
  622. ;
  623. }
  624. else if(settings.transition == 'none') {
  625. callback();
  626. }
  627. else if(settings.transition == 'slide down') {
  628. $currentMenu
  629. .show()
  630. .clearQueue()
  631. .children()
  632. .clearQueue()
  633. .css('opacity', 1)
  634. .animate({
  635. opacity : 0
  636. }, 100, 'easeOutQuad', module.event.resetStyle)
  637. .end()
  638. .delay(50)
  639. .slideUp(100, 'easeOutQuad', function() {
  640. $.proxy(module.event.resetStyle, this)();
  641. callback();
  642. })
  643. ;
  644. }
  645. else if(settings.transition == 'fade') {
  646. $currentMenu
  647. .show()
  648. .clearQueue()
  649. .fadeOut(150, function() {
  650. $.proxy(module.event.resetStyle, this)();
  651. callback();
  652. })
  653. ;
  654. }
  655. else {
  656. module.error(error.transition);
  657. }
  658. }
  659. }
  660. },
  661. show: function() {
  662. module.debug('Checking if dropdown can show');
  663. if( module.is.hidden() ) {
  664. module.hideOthers();
  665. module.set.active();
  666. module.animate.show(function() {
  667. if( module.can.click() ) {
  668. module.bind.intent();
  669. }
  670. module.set.visible();
  671. });
  672. $.proxy(settings.onShow, element)();
  673. }
  674. },
  675. hide: function() {
  676. if( !module.is.animated() && module.is.visible() ) {
  677. module.debug('Hiding dropdown');
  678. if( module.can.click() ) {
  679. module.unbind.intent();
  680. }
  681. module.remove.active();
  682. module.animate.hide(module.remove.visible);
  683. $.proxy(settings.onHide, element)();
  684. }
  685. },
  686. delay: {
  687. show: function() {
  688. module.verbose('Delaying show event to ensure user intent');
  689. clearTimeout(module.timer);
  690. module.timer = setTimeout(module.show, settings.delay.show);
  691. },
  692. hide: function() {
  693. module.verbose('Delaying hide event to ensure user intent');
  694. clearTimeout(module.timer);
  695. module.timer = setTimeout(module.hide, settings.delay.hide);
  696. }
  697. },
  698. hideOthers: function() {
  699. module.verbose('Finding other dropdowns to hide');
  700. $allModules
  701. .not($module)
  702. .has(selector.menu + ':visible')
  703. .dropdown('hide')
  704. ;
  705. },
  706. toggle: function() {
  707. module.verbose('Toggling menu visibility');
  708. if( module.is.hidden() ) {
  709. module.show();
  710. }
  711. else {
  712. module.hide();
  713. }
  714. },
  715. setting: function(name, value) {
  716. if( $.isPlainObject(name) ) {
  717. $.extend(true, settings, name);
  718. }
  719. else if(value !== undefined) {
  720. settings[name] = value;
  721. }
  722. else {
  723. return settings[name];
  724. }
  725. },
  726. internal: function(name, value) {
  727. if( $.isPlainObject(name) ) {
  728. $.extend(true, module, name);
  729. }
  730. else if(value !== undefined) {
  731. module[name] = value;
  732. }
  733. else {
  734. return module[name];
  735. }
  736. },
  737. debug: function() {
  738. if(settings.debug) {
  739. if(settings.performance) {
  740. module.performance.log(arguments);
  741. }
  742. else {
  743. module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
  744. module.debug.apply(console, arguments);
  745. }
  746. }
  747. },
  748. verbose: function() {
  749. if(settings.verbose && settings.debug) {
  750. if(settings.performance) {
  751. module.performance.log(arguments);
  752. }
  753. else {
  754. module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
  755. module.verbose.apply(console, arguments);
  756. }
  757. }
  758. },
  759. error: function() {
  760. module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
  761. module.error.apply(console, arguments);
  762. },
  763. performance: {
  764. log: function(message) {
  765. var
  766. currentTime,
  767. executionTime,
  768. previousTime
  769. ;
  770. if(settings.performance) {
  771. currentTime = new Date().getTime();
  772. previousTime = time || currentTime;
  773. executionTime = currentTime - previousTime;
  774. time = currentTime;
  775. performance.push({
  776. 'Element' : element,
  777. 'Name' : message[0],
  778. 'Arguments' : [].slice.call(message, 1) || '',
  779. 'Execution Time' : executionTime
  780. });
  781. }
  782. clearTimeout(module.performance.timer);
  783. module.performance.timer = setTimeout(module.performance.display, 100);
  784. },
  785. display: function() {
  786. var
  787. title = settings.name + ':',
  788. totalTime = 0
  789. ;
  790. time = false;
  791. clearTimeout(module.performance.timer);
  792. $.each(performance, function(index, data) {
  793. totalTime += data['Execution Time'];
  794. });
  795. title += ' ' + totalTime + 'ms';
  796. if(moduleSelector) {
  797. title += ' \'' + moduleSelector + '\'';
  798. }
  799. if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
  800. console.groupCollapsed(title);
  801. if(console.table) {
  802. console.table(performance);
  803. }
  804. else {
  805. $.each(performance, function(index, data) {
  806. console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
  807. });
  808. }
  809. console.groupEnd();
  810. }
  811. performance = [];
  812. }
  813. },
  814. invoke: function(query, passedArguments, context) {
  815. var
  816. object = instance,
  817. maxDepth,
  818. found,
  819. response
  820. ;
  821. passedArguments = passedArguments || queryArguments;
  822. context = element || context;
  823. if(typeof query == 'string' && object !== undefined) {
  824. query = query.split(/[\. ]/);
  825. maxDepth = query.length - 1;
  826. $.each(query, function(depth, value) {
  827. var camelCaseValue = (depth != maxDepth)
  828. ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
  829. : query
  830. ;
  831. if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
  832. object = object[camelCaseValue];
  833. }
  834. else if( object[camelCaseValue] !== undefined ) {
  835. found = object[camelCaseValue];
  836. return false;
  837. }
  838. else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
  839. object = object[value];
  840. }
  841. else if( object[value] !== undefined ) {
  842. found = object[value];
  843. return false;
  844. }
  845. else {
  846. module.error(error.method, query);
  847. return false;
  848. }
  849. });
  850. }
  851. if ( $.isFunction( found ) ) {
  852. response = found.apply(context, passedArguments);
  853. }
  854. else if(found !== undefined) {
  855. response = found;
  856. }
  857. if($.isArray(returnedValue)) {
  858. returnedValue.push(response);
  859. }
  860. else if(returnedValue !== undefined) {
  861. returnedValue = [returnedValue, response];
  862. }
  863. else if(response !== undefined) {
  864. returnedValue = response;
  865. }
  866. return found;
  867. }
  868. };
  869. if(methodInvoked) {
  870. if(instance === undefined) {
  871. module.initialize();
  872. }
  873. module.invoke(query);
  874. }
  875. else {
  876. if(instance !== undefined) {
  877. module.destroy();
  878. }
  879. module.initialize();
  880. }
  881. })
  882. ;
  883. return (returnedValue !== undefined)
  884. ? returnedValue
  885. : this
  886. ;
  887. };
  888. module.exports.settings = {
  889. name : 'Dropdown',
  890. namespace : 'dropdown',
  891. debug : false,
  892. verbose : true,
  893. performance : true,
  894. on : 'click',
  895. action : 'activate',
  896. delay: {
  897. show : 200,
  898. hide : 300,
  899. touch : 50
  900. },
  901. transition : 'slide down',
  902. duration : 250,
  903. onChange : function(value, text){},
  904. onShow : function(){},
  905. onHide : function(){},
  906. error : {
  907. action : 'You called a dropdown action that was not defined',
  908. method : 'The method you called is not defined.',
  909. transition : 'The requested transition was not found'
  910. },
  911. metadata: {
  912. defaultText : 'defaultText',
  913. defaultValue : 'defaultValue',
  914. text : 'text',
  915. value : 'value'
  916. },
  917. selector : {
  918. menu : '.menu',
  919. submenu : '> .menu',
  920. item : '.menu > .item',
  921. text : '> .text',
  922. input : '> input[type="hidden"]'
  923. },
  924. className : {
  925. active : 'active',
  926. placeholder : 'default',
  927. disabled : 'disabled',
  928. visible : 'visible',
  929. selected : 'selected',
  930. selection : 'selection'
  931. }
  932. };
  933. // Adds easing
  934. $.extend( $.easing, {
  935. easeOutQuad: function (x, t, b, c, d) {
  936. return -c *(t/=d)*(t-2) + b;
  937. }
  938. });
  939. })( require("jquery"), window , document );