checkbox.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. /*!
  2. * # Fomantic-UI - Checkbox
  3. * http://github.com/fomantic/Fomantic-UI/
  4. *
  5. *
  6. * Released under the MIT license
  7. * http://opensource.org/licenses/MIT
  8. *
  9. */
  10. ;(function ($, window, document, undefined) {
  11. 'use strict';
  12. $.isFunction = $.isFunction || function(obj) {
  13. return typeof obj === "function" && typeof obj.nodeType !== "number";
  14. };
  15. window = (typeof window != 'undefined' && window.Math == Math)
  16. ? window
  17. : (typeof self != 'undefined' && self.Math == Math)
  18. ? self
  19. : Function('return this')()
  20. ;
  21. $.fn.checkbox = function(parameters) {
  22. var
  23. $allModules = $(this),
  24. moduleSelector = $allModules.selector || '',
  25. time = new Date().getTime(),
  26. performance = [],
  27. query = arguments[0],
  28. methodInvoked = (typeof query == 'string'),
  29. queryArguments = [].slice.call(arguments, 1),
  30. returnedValue
  31. ;
  32. $allModules
  33. .each(function() {
  34. var
  35. settings = $.extend(true, {}, $.fn.checkbox.settings, parameters),
  36. className = settings.className,
  37. namespace = settings.namespace,
  38. selector = settings.selector,
  39. error = settings.error,
  40. eventNamespace = '.' + namespace,
  41. moduleNamespace = 'module-' + namespace,
  42. $module = $(this),
  43. $label = $(this).children(selector.label),
  44. $input = $(this).children(selector.input),
  45. input = $input[0],
  46. initialLoad = false,
  47. shortcutPressed = false,
  48. instance = $module.data(moduleNamespace),
  49. observer,
  50. element = this,
  51. module
  52. ;
  53. module = {
  54. initialize: function() {
  55. module.verbose('Initializing checkbox', settings);
  56. module.create.label();
  57. module.bind.events();
  58. module.set.tabbable();
  59. module.hide.input();
  60. module.observeChanges();
  61. module.instantiate();
  62. module.setup();
  63. },
  64. instantiate: function() {
  65. module.verbose('Storing instance of module', module);
  66. instance = module;
  67. $module
  68. .data(moduleNamespace, module)
  69. ;
  70. },
  71. destroy: function() {
  72. module.verbose('Destroying module');
  73. module.unbind.events();
  74. module.show.input();
  75. $module.removeData(moduleNamespace);
  76. },
  77. fix: {
  78. reference: function() {
  79. if( $module.is(selector.input) ) {
  80. module.debug('Behavior called on <input> adjusting invoked element');
  81. $module = $module.closest(selector.checkbox);
  82. module.refresh();
  83. }
  84. }
  85. },
  86. setup: function() {
  87. module.set.initialLoad();
  88. if( module.is.indeterminate() ) {
  89. module.debug('Initial value is indeterminate');
  90. module.indeterminate();
  91. }
  92. else if( module.is.checked() ) {
  93. module.debug('Initial value is checked');
  94. module.check();
  95. }
  96. else {
  97. module.debug('Initial value is unchecked');
  98. module.uncheck();
  99. }
  100. module.remove.initialLoad();
  101. },
  102. refresh: function() {
  103. $label = $module.children(selector.label);
  104. $input = $module.children(selector.input);
  105. input = $input[0];
  106. },
  107. hide: {
  108. input: function() {
  109. module.verbose('Modifying <input> z-index to be unselectable');
  110. $input.addClass(className.hidden);
  111. }
  112. },
  113. show: {
  114. input: function() {
  115. module.verbose('Modifying <input> z-index to be selectable');
  116. $input.removeClass(className.hidden);
  117. }
  118. },
  119. observeChanges: function() {
  120. if('MutationObserver' in window) {
  121. observer = new MutationObserver(function(mutations) {
  122. module.debug('DOM tree modified, updating selector cache');
  123. module.refresh();
  124. });
  125. observer.observe(element, {
  126. childList : true,
  127. subtree : true
  128. });
  129. module.debug('Setting up mutation observer', observer);
  130. }
  131. },
  132. attachEvents: function(selector, event) {
  133. var
  134. $element = $(selector)
  135. ;
  136. event = $.isFunction(module[event])
  137. ? module[event]
  138. : module.toggle
  139. ;
  140. if($element.length > 0) {
  141. module.debug('Attaching checkbox events to element', selector, event);
  142. $element
  143. .on('click' + eventNamespace, event)
  144. ;
  145. }
  146. else {
  147. module.error(error.notFound);
  148. }
  149. },
  150. preventDefaultOnInputTarget: function() {
  151. if(typeof event !== 'undefined' && event !== null && $(event.target).is(selector.input)) {
  152. module.verbose('Preventing default check action after manual check action');
  153. event.preventDefault();
  154. }
  155. },
  156. event: {
  157. change: function(event) {
  158. if( !module.should.ignoreCallbacks() ) {
  159. settings.onChange.call(input);
  160. }
  161. },
  162. click: function(event) {
  163. var
  164. $target = $(event.target)
  165. ;
  166. if( $target.is(selector.input) ) {
  167. module.verbose('Using default check action on initialized checkbox');
  168. return;
  169. }
  170. if( $target.is(selector.link) ) {
  171. module.debug('Clicking link inside checkbox, skipping toggle');
  172. return;
  173. }
  174. module.toggle();
  175. $input.focus();
  176. event.preventDefault();
  177. },
  178. keydown: function(event) {
  179. var
  180. key = event.which,
  181. keyCode = {
  182. enter : 13,
  183. space : 32,
  184. escape : 27,
  185. left : 37,
  186. up : 38,
  187. right : 39,
  188. down : 40
  189. }
  190. ;
  191. var r = module.get.radios(),
  192. rIndex = r.index($module),
  193. rLen = r.length,
  194. checkIndex = false;
  195. if(key == keyCode.left || key == keyCode.up) {
  196. checkIndex = (rIndex === 0 ? rLen : rIndex) - 1;
  197. } else if(key == keyCode.right || key == keyCode.down) {
  198. checkIndex = rIndex === rLen-1 ? 0 : rIndex+1;
  199. }
  200. if (!module.should.ignoreCallbacks() && checkIndex !== false) {
  201. if(settings.beforeUnchecked.apply(input)===false) {
  202. module.verbose('Option not allowed to be unchecked, cancelling key navigation');
  203. return false;
  204. }
  205. if (settings.beforeChecked.apply($(r[checkIndex]).children(selector.input)[0])===false) {
  206. module.verbose('Next option should not allow check, cancelling key navigation');
  207. return false;
  208. }
  209. }
  210. if(key == keyCode.escape) {
  211. module.verbose('Escape key pressed blurring field');
  212. $input.blur();
  213. shortcutPressed = true;
  214. }
  215. else if(!event.ctrlKey && ( key == keyCode.space || (key == keyCode.enter && settings.enableEnterKey)) ) {
  216. module.verbose('Enter/space key pressed, toggling checkbox');
  217. module.toggle();
  218. shortcutPressed = true;
  219. }
  220. else {
  221. shortcutPressed = false;
  222. }
  223. },
  224. keyup: function(event) {
  225. if(shortcutPressed) {
  226. event.preventDefault();
  227. }
  228. }
  229. },
  230. check: function() {
  231. if( !module.should.allowCheck() ) {
  232. return;
  233. }
  234. module.debug('Checking checkbox', $input);
  235. module.set.checked();
  236. if( !module.should.ignoreCallbacks() ) {
  237. settings.onChecked.call(input);
  238. module.trigger.change();
  239. }
  240. module.preventDefaultOnInputTarget();
  241. },
  242. uncheck: function() {
  243. if( !module.should.allowUncheck() ) {
  244. return;
  245. }
  246. module.debug('Unchecking checkbox');
  247. module.set.unchecked();
  248. if( !module.should.ignoreCallbacks() ) {
  249. settings.onUnchecked.call(input);
  250. module.trigger.change();
  251. }
  252. module.preventDefaultOnInputTarget();
  253. },
  254. indeterminate: function() {
  255. if( module.should.allowIndeterminate() ) {
  256. module.debug('Checkbox is already indeterminate');
  257. return;
  258. }
  259. module.debug('Making checkbox indeterminate');
  260. module.set.indeterminate();
  261. if( !module.should.ignoreCallbacks() ) {
  262. settings.onIndeterminate.call(input);
  263. module.trigger.change();
  264. }
  265. },
  266. determinate: function() {
  267. if( module.should.allowDeterminate() ) {
  268. module.debug('Checkbox is already determinate');
  269. return;
  270. }
  271. module.debug('Making checkbox determinate');
  272. module.set.determinate();
  273. if( !module.should.ignoreCallbacks() ) {
  274. settings.onDeterminate.call(input);
  275. module.trigger.change();
  276. }
  277. },
  278. enable: function() {
  279. if( module.is.enabled() ) {
  280. module.debug('Checkbox is already enabled');
  281. return;
  282. }
  283. module.debug('Enabling checkbox');
  284. module.set.enabled();
  285. if( !module.should.ignoreCallbacks() ) {
  286. settings.onEnable.call(input);
  287. // preserve legacy callbacks
  288. settings.onEnabled.call(input);
  289. module.trigger.change();
  290. }
  291. },
  292. disable: function() {
  293. if( module.is.disabled() ) {
  294. module.debug('Checkbox is already disabled');
  295. return;
  296. }
  297. module.debug('Disabling checkbox');
  298. module.set.disabled();
  299. if( !module.should.ignoreCallbacks() ) {
  300. settings.onDisable.call(input);
  301. // preserve legacy callbacks
  302. settings.onDisabled.call(input);
  303. module.trigger.change();
  304. }
  305. },
  306. get: {
  307. radios: function() {
  308. var
  309. name = module.get.name()
  310. ;
  311. return $('input[name="' + name + '"]').closest(selector.checkbox);
  312. },
  313. otherRadios: function() {
  314. return module.get.radios().not($module);
  315. },
  316. name: function() {
  317. return $input.attr('name');
  318. }
  319. },
  320. is: {
  321. initialLoad: function() {
  322. return initialLoad;
  323. },
  324. radio: function() {
  325. return ($input.hasClass(className.radio) || $input.attr('type') == 'radio');
  326. },
  327. indeterminate: function() {
  328. return $input.prop('indeterminate') !== undefined && $input.prop('indeterminate');
  329. },
  330. checked: function() {
  331. return $input.prop('checked') !== undefined && $input.prop('checked');
  332. },
  333. disabled: function() {
  334. return $input.prop('disabled') !== undefined && $input.prop('disabled');
  335. },
  336. enabled: function() {
  337. return !module.is.disabled();
  338. },
  339. determinate: function() {
  340. return !module.is.indeterminate();
  341. },
  342. unchecked: function() {
  343. return !module.is.checked();
  344. }
  345. },
  346. should: {
  347. allowCheck: function() {
  348. if(module.is.determinate() && module.is.checked() && !module.is.initialLoad() ) {
  349. module.debug('Should not allow check, checkbox is already checked');
  350. return false;
  351. }
  352. if(!module.should.ignoreCallbacks() && settings.beforeChecked.apply(input) === false) {
  353. module.debug('Should not allow check, beforeChecked cancelled');
  354. return false;
  355. }
  356. return true;
  357. },
  358. allowUncheck: function() {
  359. if(module.is.determinate() && module.is.unchecked() && !module.is.initialLoad() ) {
  360. module.debug('Should not allow uncheck, checkbox is already unchecked');
  361. return false;
  362. }
  363. if(!module.should.ignoreCallbacks() && settings.beforeUnchecked.apply(input) === false) {
  364. module.debug('Should not allow uncheck, beforeUnchecked cancelled');
  365. return false;
  366. }
  367. return true;
  368. },
  369. allowIndeterminate: function() {
  370. if(module.is.indeterminate() && !module.is.initialLoad() ) {
  371. module.debug('Should not allow indeterminate, checkbox is already indeterminate');
  372. return false;
  373. }
  374. if(!module.should.ignoreCallbacks() && settings.beforeIndeterminate.apply(input) === false) {
  375. module.debug('Should not allow indeterminate, beforeIndeterminate cancelled');
  376. return false;
  377. }
  378. return true;
  379. },
  380. allowDeterminate: function() {
  381. if(module.is.determinate() && !module.is.initialLoad() ) {
  382. module.debug('Should not allow determinate, checkbox is already determinate');
  383. return false;
  384. }
  385. if(!module.should.ignoreCallbacks() && settings.beforeDeterminate.apply(input) === false) {
  386. module.debug('Should not allow determinate, beforeDeterminate cancelled');
  387. return false;
  388. }
  389. return true;
  390. },
  391. ignoreCallbacks: function() {
  392. return (initialLoad && !settings.fireOnInit);
  393. }
  394. },
  395. can: {
  396. change: function() {
  397. return !( $module.hasClass(className.disabled) || $module.hasClass(className.readOnly) || $input.prop('disabled') || $input.prop('readonly') );
  398. },
  399. uncheck: function() {
  400. return (typeof settings.uncheckable === 'boolean')
  401. ? settings.uncheckable
  402. : !module.is.radio()
  403. ;
  404. }
  405. },
  406. set: {
  407. initialLoad: function() {
  408. initialLoad = true;
  409. },
  410. checked: function() {
  411. module.verbose('Setting class to checked');
  412. $module
  413. .removeClass(className.indeterminate)
  414. .addClass(className.checked)
  415. ;
  416. if( module.is.radio() ) {
  417. module.uncheckOthers();
  418. }
  419. if(!module.is.indeterminate() && module.is.checked()) {
  420. module.debug('Input is already checked, skipping input property change');
  421. return;
  422. }
  423. module.verbose('Setting state to checked', input);
  424. $input
  425. .prop('indeterminate', false)
  426. .prop('checked', true)
  427. ;
  428. },
  429. unchecked: function() {
  430. module.verbose('Removing checked class');
  431. $module
  432. .removeClass(className.indeterminate)
  433. .removeClass(className.checked)
  434. ;
  435. if(!module.is.indeterminate() && module.is.unchecked() ) {
  436. module.debug('Input is already unchecked');
  437. return;
  438. }
  439. module.debug('Setting state to unchecked');
  440. $input
  441. .prop('indeterminate', false)
  442. .prop('checked', false)
  443. ;
  444. },
  445. indeterminate: function() {
  446. module.verbose('Setting class to indeterminate');
  447. $module
  448. .addClass(className.indeterminate)
  449. ;
  450. if( module.is.indeterminate() ) {
  451. module.debug('Input is already indeterminate, skipping input property change');
  452. return;
  453. }
  454. module.debug('Setting state to indeterminate');
  455. $input
  456. .prop('indeterminate', true)
  457. ;
  458. },
  459. determinate: function() {
  460. module.verbose('Removing indeterminate class');
  461. $module
  462. .removeClass(className.indeterminate)
  463. ;
  464. if( module.is.determinate() ) {
  465. module.debug('Input is already determinate, skipping input property change');
  466. return;
  467. }
  468. module.debug('Setting state to determinate');
  469. $input
  470. .prop('indeterminate', false)
  471. ;
  472. },
  473. disabled: function() {
  474. module.verbose('Setting class to disabled');
  475. $module
  476. .addClass(className.disabled)
  477. ;
  478. if( module.is.disabled() ) {
  479. module.debug('Input is already disabled, skipping input property change');
  480. return;
  481. }
  482. module.debug('Setting state to disabled');
  483. $input
  484. .prop('disabled', 'disabled')
  485. ;
  486. },
  487. enabled: function() {
  488. module.verbose('Removing disabled class');
  489. $module.removeClass(className.disabled);
  490. if( module.is.enabled() ) {
  491. module.debug('Input is already enabled, skipping input property change');
  492. return;
  493. }
  494. module.debug('Setting state to enabled');
  495. $input
  496. .prop('disabled', false)
  497. ;
  498. },
  499. tabbable: function() {
  500. module.verbose('Adding tabindex to checkbox');
  501. if( $input.attr('tabindex') === undefined) {
  502. $input.attr('tabindex', 0);
  503. }
  504. }
  505. },
  506. remove: {
  507. initialLoad: function() {
  508. initialLoad = false;
  509. }
  510. },
  511. trigger: {
  512. change: function() {
  513. var
  514. events = document.createEvent('HTMLEvents'),
  515. inputElement = $input[0]
  516. ;
  517. if(inputElement) {
  518. module.verbose('Triggering native change event');
  519. events.initEvent('change', true, false);
  520. inputElement.dispatchEvent(events);
  521. }
  522. }
  523. },
  524. create: {
  525. label: function() {
  526. if($input.prevAll(selector.label).length > 0) {
  527. $input.prev(selector.label).detach().insertAfter($input);
  528. module.debug('Moving existing label', $label);
  529. }
  530. else if( !module.has.label() ) {
  531. $label = $('<label>').insertAfter($input);
  532. module.debug('Creating label', $label);
  533. }
  534. }
  535. },
  536. has: {
  537. label: function() {
  538. return ($label.length > 0);
  539. }
  540. },
  541. bind: {
  542. events: function() {
  543. module.verbose('Attaching checkbox events');
  544. $module
  545. .on('click' + eventNamespace, module.event.click)
  546. .on('change' + eventNamespace, module.event.change)
  547. .on('keydown' + eventNamespace, selector.input, module.event.keydown)
  548. .on('keyup' + eventNamespace, selector.input, module.event.keyup)
  549. ;
  550. }
  551. },
  552. unbind: {
  553. events: function() {
  554. module.debug('Removing events');
  555. $module
  556. .off(eventNamespace)
  557. ;
  558. }
  559. },
  560. uncheckOthers: function() {
  561. var
  562. $radios = module.get.otherRadios()
  563. ;
  564. module.debug('Unchecking other radios', $radios);
  565. $radios.removeClass(className.checked);
  566. },
  567. toggle: function() {
  568. if( !module.can.change() ) {
  569. if(!module.is.radio()) {
  570. module.debug('Checkbox is read-only or disabled, ignoring toggle');
  571. }
  572. return;
  573. }
  574. if( module.is.indeterminate() || module.is.unchecked() ) {
  575. module.debug('Currently unchecked');
  576. module.check();
  577. }
  578. else if( module.is.checked() && module.can.uncheck() ) {
  579. module.debug('Currently checked');
  580. module.uncheck();
  581. }
  582. },
  583. setting: function(name, value) {
  584. module.debug('Changing setting', name, value);
  585. if( $.isPlainObject(name) ) {
  586. $.extend(true, settings, name);
  587. }
  588. else if(value !== undefined) {
  589. if($.isPlainObject(settings[name])) {
  590. $.extend(true, settings[name], value);
  591. }
  592. else {
  593. settings[name] = value;
  594. }
  595. }
  596. else {
  597. return settings[name];
  598. }
  599. },
  600. internal: function(name, value) {
  601. if( $.isPlainObject(name) ) {
  602. $.extend(true, module, name);
  603. }
  604. else if(value !== undefined) {
  605. module[name] = value;
  606. }
  607. else {
  608. return module[name];
  609. }
  610. },
  611. debug: function() {
  612. if(!settings.silent && settings.debug) {
  613. if(settings.performance) {
  614. module.performance.log(arguments);
  615. }
  616. else {
  617. module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
  618. module.debug.apply(console, arguments);
  619. }
  620. }
  621. },
  622. verbose: function() {
  623. if(!settings.silent && settings.verbose && settings.debug) {
  624. if(settings.performance) {
  625. module.performance.log(arguments);
  626. }
  627. else {
  628. module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
  629. module.verbose.apply(console, arguments);
  630. }
  631. }
  632. },
  633. error: function() {
  634. if(!settings.silent) {
  635. module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
  636. module.error.apply(console, arguments);
  637. }
  638. },
  639. performance: {
  640. log: function(message) {
  641. var
  642. currentTime,
  643. executionTime,
  644. previousTime
  645. ;
  646. if(settings.performance) {
  647. currentTime = new Date().getTime();
  648. previousTime = time || currentTime;
  649. executionTime = currentTime - previousTime;
  650. time = currentTime;
  651. performance.push({
  652. 'Name' : message[0],
  653. 'Arguments' : [].slice.call(message, 1) || '',
  654. 'Element' : element,
  655. 'Execution Time' : executionTime
  656. });
  657. }
  658. clearTimeout(module.performance.timer);
  659. module.performance.timer = setTimeout(module.performance.display, 500);
  660. },
  661. display: function() {
  662. var
  663. title = settings.name + ':',
  664. totalTime = 0
  665. ;
  666. time = false;
  667. clearTimeout(module.performance.timer);
  668. $.each(performance, function(index, data) {
  669. totalTime += data['Execution Time'];
  670. });
  671. title += ' ' + totalTime + 'ms';
  672. if(moduleSelector) {
  673. title += ' \'' + moduleSelector + '\'';
  674. }
  675. if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
  676. console.groupCollapsed(title);
  677. if(console.table) {
  678. console.table(performance);
  679. }
  680. else {
  681. $.each(performance, function(index, data) {
  682. console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
  683. });
  684. }
  685. console.groupEnd();
  686. }
  687. performance = [];
  688. }
  689. },
  690. invoke: function(query, passedArguments, context) {
  691. var
  692. object = instance,
  693. maxDepth,
  694. found,
  695. response
  696. ;
  697. passedArguments = passedArguments || queryArguments;
  698. context = element || context;
  699. if(typeof query == 'string' && object !== undefined) {
  700. query = query.split(/[\. ]/);
  701. maxDepth = query.length - 1;
  702. $.each(query, function(depth, value) {
  703. var camelCaseValue = (depth != maxDepth)
  704. ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
  705. : query
  706. ;
  707. if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
  708. object = object[camelCaseValue];
  709. }
  710. else if( object[camelCaseValue] !== undefined ) {
  711. found = object[camelCaseValue];
  712. return false;
  713. }
  714. else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
  715. object = object[value];
  716. }
  717. else if( object[value] !== undefined ) {
  718. found = object[value];
  719. return false;
  720. }
  721. else {
  722. module.error(error.method, query);
  723. return false;
  724. }
  725. });
  726. }
  727. if ( $.isFunction( found ) ) {
  728. response = found.apply(context, passedArguments);
  729. }
  730. else if(found !== undefined) {
  731. response = found;
  732. }
  733. if(Array.isArray(returnedValue)) {
  734. returnedValue.push(response);
  735. }
  736. else if(returnedValue !== undefined) {
  737. returnedValue = [returnedValue, response];
  738. }
  739. else if(response !== undefined) {
  740. returnedValue = response;
  741. }
  742. return found;
  743. }
  744. };
  745. if(methodInvoked) {
  746. if(instance === undefined) {
  747. module.initialize();
  748. }
  749. module.invoke(query);
  750. }
  751. else {
  752. if(instance !== undefined) {
  753. instance.invoke('destroy');
  754. }
  755. module.initialize();
  756. }
  757. })
  758. ;
  759. return (returnedValue !== undefined)
  760. ? returnedValue
  761. : this
  762. ;
  763. };
  764. $.fn.checkbox.settings = {
  765. name : 'Checkbox',
  766. namespace : 'checkbox',
  767. silent : false,
  768. debug : false,
  769. verbose : true,
  770. performance : true,
  771. // delegated event context
  772. uncheckable : 'auto',
  773. fireOnInit : false,
  774. enableEnterKey : true,
  775. onChange : function(){},
  776. beforeChecked : function(){},
  777. beforeUnchecked : function(){},
  778. beforeDeterminate : function(){},
  779. beforeIndeterminate : function(){},
  780. onChecked : function(){},
  781. onUnchecked : function(){},
  782. onDeterminate : function() {},
  783. onIndeterminate : function() {},
  784. onEnable : function(){},
  785. onDisable : function(){},
  786. // preserve misspelled callbacks (will be removed in 3.0)
  787. onEnabled : function(){},
  788. onDisabled : function(){},
  789. className : {
  790. checked : 'checked',
  791. indeterminate : 'indeterminate',
  792. disabled : 'disabled',
  793. hidden : 'hidden',
  794. radio : 'radio',
  795. readOnly : 'read-only'
  796. },
  797. error : {
  798. method : 'The method you called is not defined'
  799. },
  800. selector : {
  801. checkbox : '.ui.checkbox',
  802. label : 'label, .box',
  803. input : 'input[type="checkbox"], input[type="radio"]',
  804. link : 'a[href]'
  805. }
  806. };
  807. })( jQuery, window, document );