jquery-selective.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  1. /**
  2. * jQuery Selective v0.3.5
  3. * https://github.com/amazingSurge/jquery-selective
  4. *
  5. * Copyright (c) amazingSurge
  6. * Released under the LGPL-3.0 license
  7. */
  8. (
  9. function(global, factory) {
  10. if (typeof define === "function" && define.amd) {
  11. define(['jquery'], factory);
  12. } else if (typeof exports !== "undefined") {
  13. factory(require('jquery'));
  14. } else {
  15. var mod = {
  16. exports: {}
  17. };
  18. factory(global.jQuery);
  19. global.jquerySelectiveEs = mod.exports;
  20. }
  21. }
  22. )(this,
  23. function(_jquery) {
  24. 'use strict';
  25. var _jquery2 = _interopRequireDefault(_jquery);
  26. function _interopRequireDefault(obj) {
  27. return obj && obj.__esModule ? obj : {
  28. default: obj
  29. };
  30. }
  31. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ?
  32. function(obj) {
  33. return typeof obj;
  34. }
  35. :
  36. function(obj) {
  37. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  38. };
  39. function _classCallCheck(instance, Constructor) {
  40. if (!(instance instanceof Constructor)) {
  41. throw new TypeError("Cannot call a class as a function");
  42. }
  43. }
  44. var _createClass = function() {
  45. function defineProperties(target, props) {
  46. for (var i = 0; i < props.length; i++) {
  47. var descriptor = props[i];
  48. descriptor.enumerable = descriptor.enumerable || false;
  49. descriptor.configurable = true;
  50. if ("value" in descriptor)
  51. descriptor.writable = true;
  52. Object.defineProperty(target, descriptor.key, descriptor);
  53. }
  54. }
  55. return function(Constructor, protoProps, staticProps) {
  56. if (protoProps)
  57. defineProperties(Constructor.prototype, protoProps);
  58. if (staticProps)
  59. defineProperties(Constructor, staticProps);
  60. return Constructor;
  61. };
  62. }();
  63. /*eslint no-empty-function: "off"*/
  64. var DEFAULTS = {
  65. namespace: 'selective',
  66. buildFromHtml: true,
  67. closeOnSelect: false,
  68. local: null,
  69. selected: null,
  70. withSearch: false,
  71. searchType: null, //'change' or 'keyup'
  72. ajax: {
  73. work: false,
  74. url: null,
  75. quietMills: null,
  76. loadMore: false,
  77. pageSize: null
  78. },
  79. query: function query() {}, //function(api, search_text, page) {},
  80. tpl: {
  81. frame: function frame() {
  82. return '<div class="' + this.namespace + '"><div class="' + this.namespace + '-trigger">' + this.options.tpl.triggerButton.call(this) + '<div class="' + this.namespace + '-trigger-dropdown"><div class="' + this.namespace + '-list-wrap">' + this.options.tpl.list.call(this) + '</div></div></div>' + this.options.tpl.items.call(this) + '</div>';
  83. },
  84. search: function search() {
  85. return '<input class="' + this.namespace + '-search" type="text" placeholder="Search...">';
  86. },
  87. select: function select() {
  88. return '<select class="' + this.namespace + '-select" name="' + this.namespace + '" multiple="multiple"></select>';
  89. },
  90. optionValue: function optionValue(data) {
  91. if ('name' in data) {
  92. return data.name;
  93. }
  94. return data;
  95. },
  96. option: function option(content) {
  97. return '<option value="' + this.options.tpl.optionValue.call(this) + '">' + content + '</option>';
  98. },
  99. items: function items() {
  100. return '<ul class="' + this.namespace + '-items"></ul>';
  101. },
  102. item: function item(content) {
  103. return '<li class="' + this.namespace + '-item">' + content + this.options.tpl.itemRemove.call(this) + '</li>';
  104. },
  105. itemRemove: function itemRemove() {
  106. return '<span class="' + this.namespace + '-remove">x</span>';
  107. },
  108. triggerButton: function triggerButton() {
  109. return '<div class="' + this.namespace + '-trigger-button">Add</div>';
  110. },
  111. list: function list() {
  112. return '<ul class="' + this.namespace + '-list"></ul>';
  113. },
  114. listItem: function listItem(content) {
  115. return '<li class="' + this.namespace + '-list-item">' + content + '</li>';
  116. }
  117. },
  118. onBeforeShow: null,
  119. onAfterShow: null,
  120. onBeforeHide: null,
  121. onAfterHide: null,
  122. onBeforeSearch: null,
  123. onAfterSearch: null,
  124. onBeforeSelected: null,
  125. onAfterSelected: null,
  126. onBeforeUnselect: null,
  127. onAfterUnselect: null,
  128. onBeforeItemRemove: null,
  129. onAfterItemRemove: null,
  130. onBeforeItemAdd: null,
  131. onAfterItemAdd: null
  132. };
  133. var Options = function() {
  134. function Options(instance) {
  135. _classCallCheck(this, Options);
  136. this.instance = instance;
  137. }
  138. _createClass(Options, [{
  139. key: 'getOptions',
  140. value: function getOptions() {
  141. this.instance.$options = this.instance.$select.find('option');
  142. return this.instance.$options;
  143. }
  144. }, {
  145. key: 'select',
  146. value: function select(opt) {
  147. $(opt).prop('selected', true);
  148. return this.instance;
  149. }
  150. }, {
  151. key: 'unselect',
  152. value: function unselect(opt) {
  153. $(opt).prop('selected', false);
  154. return this.instance;
  155. }
  156. }, {
  157. key: 'add',
  158. value: function add(data) {
  159. /*eslint consistent-return: "off"*/
  160. if (this.instance.options.buildFromHtml === false && this.instance.getItem('option', this.instance.$select, this.instance.options.tpl.optionValue(data)) === undefined) {
  161. var $option = $(this.instance.options.tpl.option.call(this.instance, data));
  162. this.instance.setIndex($option, data);
  163. this.instance.$select.append($option);
  164. return $option;
  165. }
  166. }
  167. }, {
  168. key: 'remove',
  169. value: function remove(opt) {
  170. $(opt).remove();
  171. return this.instance;
  172. }
  173. }]);
  174. return Options;
  175. }();
  176. var List = function() {
  177. function List(instance) {
  178. _classCallCheck(this, List);
  179. this.instance = instance;
  180. }
  181. _createClass(List, [{
  182. key: 'build',
  183. value: function build(data) {
  184. var _this = this;
  185. var $list = $('<ul></ul>');
  186. var $options = this.instance._options.getOptions();
  187. if (this.instance.options.buildFromHtml === true) {
  188. if ($options.length !== 0) {
  189. $.each($options,
  190. function(i, n) {
  191. var $li = $(_this.instance.options.tpl.listItem.call(_this.instance, n.text));
  192. var $n = $(n);
  193. _this.instance.setIndex($li, $n);
  194. if ($n.attr('selected') !== undefined) {
  195. _this.instance.select($li);
  196. }
  197. $list.append($li);
  198. }
  199. );
  200. }
  201. } else if (data !== null) {
  202. $.each(data,
  203. function(i) {
  204. var $li = $(_this.instance.options.tpl.listItem.call(_this.instance, data[i]));
  205. _this.instance.setIndex($li, data[i]);
  206. $list.append($li);
  207. }
  208. );
  209. if ($options.length !== 0) {
  210. $.each($options,
  211. function(i, n) {
  212. var $n = $(n);
  213. var li = _this.instance.getItem('li', $list, _this.instance.options.tpl.optionValue($n.data('selective_index')));
  214. if (li !== undefined) {
  215. _this.instance._list.select(li);
  216. }
  217. }
  218. );
  219. }
  220. }
  221. this.instance.$list.append($list.children('li'));
  222. return this.instance;
  223. }
  224. }, {
  225. key: 'buildSearch',
  226. value: function buildSearch() {
  227. if (this.instance.options.withSearch === true) {
  228. this.instance.$triggerDropdown.prepend(this.instance.options.tpl.search.call(this.instance));
  229. this.instance.$search = this.instance.$triggerDropdown.find('.' + this.instance.namespace + '-search');
  230. }
  231. return this.instance;
  232. }
  233. }, {
  234. key: 'select',
  235. value: function select(obj) {
  236. this.instance._trigger("beforeSelected");
  237. $(obj).addClass(this.instance.namespace + '-selected');
  238. this.instance._trigger("afterSelected");
  239. return this.instance;
  240. }
  241. }, {
  242. key: 'unselect',
  243. value: function unselect(obj) {
  244. this.instance._trigger("beforeUnselected");
  245. $(obj).removeClass(this.instance.namespace + '-selected');
  246. this.instance._trigger("afterUnselected");
  247. return this.instance;
  248. }
  249. }, {
  250. key: 'click',
  251. value: function click() {
  252. var that = this;
  253. this.instance.$list.on('click', 'li',
  254. function() {
  255. var $this = $(this);
  256. if (!$this.hasClass(that.instance.namespace + '-selected')) {
  257. that.instance.select($this);
  258. }
  259. }
  260. );
  261. }
  262. }, {
  263. key: 'filter',
  264. value: function filter(val) {
  265. $.expr[':'].Contains = function(a, i, m) {
  266. return jQuery(a).text().toUpperCase().includes(m[3].toUpperCase());
  267. }
  268. ;
  269. if (val) {
  270. this.instance.$list.find('li:not(:Contains(' + val + '))').slideUp();
  271. this.instance.$list.find('li:Contains(' + val + ')').slideDown();
  272. } else {
  273. this.instance.$list.children('li').slideDown();
  274. }
  275. return this.instance;
  276. }
  277. }, {
  278. key: 'loadMore',
  279. value: function loadMore() {
  280. var _this2 = this;
  281. var pageMax = this.instance.options.ajax.pageSize || 9999;
  282. this.instance.$listWrap.on('scroll.selective',
  283. function() {
  284. if (pageMax > _this2.instance.page) {
  285. var listHeight = _this2.instance.$list.outerHeight(true);
  286. var wrapHeight = _this2.instance.$listWrap.outerHeight();
  287. var wrapScrollTop = _this2.instance.$listWrap.scrollTop();
  288. var below = listHeight - wrapHeight - wrapScrollTop;
  289. if (below === 0) {
  290. _this2.instance.options.query(_this2.instance, _this2.instance.$search.val(), ++_this2.instance.page);
  291. }
  292. }
  293. }
  294. );
  295. return this.instance;
  296. }
  297. }, {
  298. key: 'loadMoreRemove',
  299. value: function loadMoreRemove() {
  300. this.instance.$listWrap.off('scroll.selective');
  301. return this.instance;
  302. }
  303. }]);
  304. return List;
  305. }();
  306. var Search = function() {
  307. function Search(instance) {
  308. _classCallCheck(this, Search);
  309. this.instance = instance;
  310. }
  311. _createClass(Search, [{
  312. key: 'change',
  313. value: function change() {
  314. var _this3 = this;
  315. this.instance.$search.change(
  316. function() {
  317. _this3.instance._trigger("beforeSearch");
  318. if (_this3.instance.options.buildFromHtml === true) {
  319. _this3.instance._list.filter(_this3.instance.$search.val());
  320. } else if (_this3.instance.$search.val() !== '') {
  321. _this3.instance.page = 1;
  322. _this3.instance.options.query(_this3.instance, _this3.instance.$search.val(), _this3.instance.page);
  323. } else {
  324. _this3.instance.update(_this3.instance.options.local);
  325. }
  326. _this3.instance._trigger("afterSearch");
  327. }
  328. );
  329. }
  330. }, {
  331. key: 'keyup',
  332. value: function keyup() {
  333. var _this4 = this;
  334. var quietMills = this.instance.options.ajax.quietMills || 1000;
  335. var oldValue = '';
  336. var currentValue = '';
  337. var timeout = void 0;
  338. this.instance.$search.on('keyup',
  339. function(e) {
  340. _this4.instance._trigger("beforeSearch");
  341. currentValue = _this4.instance.$search.val();
  342. if (_this4.instance.options.buildFromHtml === true) {
  343. if (currentValue !== oldValue) {
  344. _this4.instance._list.filter(currentValue);
  345. }
  346. } else if (currentValue !== oldValue || e.keyCode === 13) {
  347. window.clearTimeout(timeout);
  348. timeout = window.setTimeout(
  349. function() {
  350. if (currentValue !== '') {
  351. _this4.instance.page = 1;
  352. _this4.instance.options.query(_this4.instance, currentValue, _this4.instance.page);
  353. } else {
  354. _this4.instance.update(_this4.instance.options.local);
  355. }
  356. }
  357. , quietMills);
  358. }
  359. oldValue = currentValue;
  360. _this4.instance._trigger("afterSearch");
  361. }
  362. );
  363. }
  364. }, {
  365. key: 'bind',
  366. value: function bind(type) {
  367. if (type === 'change') {
  368. this.change();
  369. } else if (type === 'keyup') {
  370. this.keyup();
  371. }
  372. }
  373. }]);
  374. return Search;
  375. }();
  376. var Items = function() {
  377. function Items(instance) {
  378. _classCallCheck(this, Items);
  379. this.instance = instance;
  380. }
  381. _createClass(Items, [{
  382. key: 'withDefaults',
  383. value: function withDefaults(data) {
  384. var _this5 = this;
  385. if (data !== null) {
  386. $.each(data,
  387. function(i) {
  388. _this5.instance._options.add(data[i]);
  389. _this5.instance._options.select(_this5.instance.getItem('option', _this5.instance.$select, _this5.instance.options.tpl.optionValue(data[i])));
  390. _this5.instance._items.add(data[i]);
  391. }
  392. );
  393. }
  394. }
  395. }, {
  396. key: 'add',
  397. value: function add(data, content) {
  398. var $item = void 0;
  399. var fill = void 0;
  400. if (this.instance.options.buildFromHtml === true) {
  401. fill = content;
  402. } else {
  403. fill = data;
  404. }
  405. $item = $(this.instance.options.tpl.item.call(this.instance, fill));
  406. this.instance.setIndex($item, data);
  407. this.instance.$items.append($item);
  408. }
  409. }, {
  410. key: 'remove',
  411. value: function remove(obj) {
  412. obj = $(obj);
  413. var $li = void 0;
  414. var $option = void 0;
  415. if (this.instance.options.buildFromHtml === true) {
  416. this.instance._list.unselect(obj.data('selective_index'));
  417. this.instance._options.unselect(obj.data('selective_index').data('selective_index'));
  418. } else {
  419. $li = this.instance.getItem('li', this.instance.$list, this.instance.options.tpl.optionValue(obj.data('selective_index')));
  420. if ($li !== undefined) {
  421. this.instance._list.unselect($li);
  422. }
  423. $option = this.instance.getItem('option', this.instance.$select, this.instance.options.tpl.optionValue(obj.data('selective_index')));
  424. this.instance._options.unselect($option)._options.remove($option);
  425. }
  426. obj.remove();
  427. return this.instance;
  428. }
  429. }, {
  430. key: 'click',
  431. value: function click() {
  432. var that = this;
  433. this.instance.$items.on('click', '.' + this.instance.namespace + '-remove',
  434. function() {
  435. var $this = $(this);
  436. var $item = $this.parents('li');
  437. that.instance.itemRemove($item);
  438. }
  439. );
  440. }
  441. }]);
  442. return Items;
  443. }();
  444. var NAMESPACE$1 = 'selective';
  445. /**
  446. * Plugin constructor
  447. **/
  448. var Selective = function() {
  449. function Selective(element) {
  450. var _this6 = this;
  451. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  452. _classCallCheck(this, Selective);
  453. this.element = element;
  454. this.$element = (0, _jquery2.default)(element).hide() || (0, _jquery2.default)('<select></select>');
  455. this.options = _jquery2.default.extend(true, {}, DEFAULTS, options);
  456. this.namespace = this.options.namespace;
  457. var $frame = (0, _jquery2.default)(this.options.tpl.frame.call(this));
  458. //get the select
  459. var _build = function _build() {
  460. _this6.$element.html(_this6.options.tpl.select.call(_this6));
  461. return _this6.$element.children('select');
  462. };
  463. this.$select = this.$element.is('select') === true ? this.$element : _build();
  464. this.$element.after($frame);
  465. this.init();
  466. this.opened = false;
  467. }
  468. _createClass(Selective, [{
  469. key: 'init',
  470. value: function init() {
  471. var _this7 = this;
  472. this.$selective = this.$element.next('.' + this.namespace);
  473. this.$items = this.$selective.find('.' + this.namespace + '-items');
  474. this.$trigger = this.$selective.find('.' + this.namespace + '-trigger');
  475. this.$triggerButton = this.$selective.find('.' + this.namespace + '-trigger-button');
  476. this.$triggerDropdown = this.$selective.find('.' + this.namespace + '-trigger-dropdown');
  477. this.$listWrap = this.$selective.find('.' + this.namespace + '-list-wrap');
  478. this.$list = this.$selective.find('.' + this.namespace + '-list');
  479. this._list = new List(this);
  480. this._options = new Options(this);
  481. this._search = new Search(this);
  482. this._items = new Items(this);
  483. this._items.withDefaults(this.options.selected);
  484. this.update(this.options.local)._list.buildSearch();
  485. this.$triggerButton.on('click',
  486. function() {
  487. if (_this7.opened === false) {
  488. _this7.show();
  489. } else {
  490. _this7.hide();
  491. }
  492. }
  493. );
  494. this._list.click(this);
  495. this._items.click(this);
  496. if (this.options.withSearch === true) {
  497. this._search.bind(this.options.searchType);
  498. }
  499. this._trigger('ready');
  500. }
  501. }, {
  502. key: '_trigger',
  503. value: function _trigger(eventType) {
  504. for (var _len = arguments.length, params = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  505. params[_key - 1] = arguments[_key];
  506. }
  507. var data = [this].concat(params);
  508. // event
  509. this.$element.trigger(NAMESPACE$1 + '::' + eventType, data);
  510. // callback
  511. eventType = eventType.replace(/\b\w+\b/g,
  512. function(word) {
  513. return word.substring(0, 1).toUpperCase() + word.substring(1);
  514. }
  515. );
  516. var onFunction = 'on' + eventType;
  517. if (typeof this.options[onFunction] === 'function') {
  518. this.options[onFunction].apply(this, params);
  519. }
  520. }
  521. }, {
  522. key: '_show',
  523. value: function _show() {
  524. var _this8 = this;
  525. (0, _jquery2.default)(document).on('click.selective',
  526. function(e) {
  527. if (_this8.options.closeOnSelect === true) {
  528. if ((0, _jquery2.default)(e.target).closest(_this8.$triggerButton).length === 0 && (0, _jquery2.default)(e.target).closest(_this8.$search).length === 0) {
  529. _this8._hide();
  530. }
  531. } else if ((0, _jquery2.default)(e.target).closest(_this8.$trigger).length === 0) {
  532. _this8._hide();
  533. }
  534. }
  535. );
  536. this.$trigger.addClass(this.namespace + '-active');
  537. this.opened = true;
  538. if (this.options.ajax.loadMore === true) {
  539. this._list.loadMore();
  540. }
  541. return this;
  542. }
  543. }, {
  544. key: '_hide',
  545. value: function _hide() {
  546. (0, _jquery2.default)(document).off('click.selective');
  547. this.$trigger.removeClass(this.namespace + '-active');
  548. this.opened = false;
  549. if (this.options.ajax.loadMore === true) {
  550. this._list.loadMoreRemove();
  551. }
  552. return this;
  553. }
  554. }, {
  555. key: 'show',
  556. value: function show() {
  557. this._trigger("beforeShow");
  558. this._show();
  559. this._trigger("afterShow");
  560. return this;
  561. }
  562. }, {
  563. key: 'hide',
  564. value: function hide() {
  565. this._trigger("beforeHide");
  566. this._hide();
  567. this._trigger("afterHide");
  568. return this;
  569. }
  570. }, {
  571. key: 'select',
  572. value: function select($li) {
  573. this._list.select($li);
  574. var data = $li.data('selective_index');
  575. if (this.options.buildFromHtml === true) {
  576. this._options.select(data);
  577. this.itemAdd($li, data.text());
  578. } else {
  579. this._options.add(data);
  580. this._options.select(this.getItem('option', this.$select, this.options.tpl.optionValue(data)));
  581. this.itemAdd(data);
  582. }
  583. return this;
  584. }
  585. }, {
  586. key: 'unselect',
  587. value: function unselect($li) {
  588. this._list.unselect($li);
  589. return this;
  590. }
  591. }, {
  592. key: 'setIndex',
  593. value: function setIndex(obj, index) {
  594. obj.data('selective_index', index);
  595. return this;
  596. }
  597. }, {
  598. key: 'getItem',
  599. value: function getItem(type, $list, index) {
  600. var $items = $list.children(type);
  601. var position = '';
  602. for (var i = 0; i < $items.length; i++) {
  603. if (this.options.tpl.optionValue($items.eq(i).data('selective_index')) === index) {
  604. position = i;
  605. }
  606. }
  607. return position === '' ? undefined : $items.eq(position);
  608. }
  609. }, {
  610. key: 'itemAdd',
  611. value: function itemAdd(data, content) {
  612. this._trigger("beforeItemAdd");
  613. this._items.add(data, content);
  614. this._trigger("afterItemAdd");
  615. return this;
  616. }
  617. }, {
  618. key: 'itemRemove',
  619. value: function itemRemove($li) {
  620. this._trigger("beforeItemRemove");
  621. this._items.remove($li);
  622. this._trigger("afterItemRemove");
  623. return this;
  624. }
  625. }, {
  626. key: 'optionAdd',
  627. value: function optionAdd(data) {
  628. this._options.add(data);
  629. return this;
  630. }
  631. }, {
  632. key: 'optionRemove',
  633. value: function optionRemove(opt) {
  634. this._options.remove(opt);
  635. return this;
  636. }
  637. }, {
  638. key: 'update',
  639. value: function update(data) {
  640. this.$list.empty();
  641. this.page = 1;
  642. if (data !== null) {
  643. this._list.build(data);
  644. } else {
  645. this._list.build();
  646. }
  647. return this;
  648. }
  649. }, {
  650. key: 'destroy',
  651. value: function destroy() {
  652. this.$selective.remove();
  653. this.$element.show();
  654. (0, _jquery2.default)(document).off('click.selective');
  655. this._trigger('destroy');
  656. }
  657. }], [{
  658. key: 'setDefaults',
  659. value: function setDefaults(options) {
  660. _jquery2.default.extend(true, DEFAULTS, _jquery2.default.isPlainObject(options) && options);
  661. }
  662. }]);
  663. return Selective;
  664. }();
  665. var info = {
  666. version: '0.3.5'
  667. };
  668. var NAMESPACE = 'selective';
  669. var OtherSelective = _jquery2.default.fn.selective;
  670. var jQuerySelective = function jQuerySelective(options) {
  671. var _this9 = this;
  672. for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  673. args[_key2 - 1] = arguments[_key2];
  674. }
  675. if (typeof options === 'string') {
  676. var _ret = function() {
  677. var method = options;
  678. if (/^_/.test(method)) {
  679. return {
  680. v: false
  681. };
  682. } else if (/^(get)/.test(method)) {
  683. var instance = _this9.first().data(NAMESPACE);
  684. if (instance && typeof instance[method] === 'function') {
  685. return {
  686. v: instance[method].apply(instance, args)
  687. };
  688. }
  689. } else {
  690. return {
  691. v: _this9.each(
  692. function() {
  693. var instance = _jquery2.default.data(this, NAMESPACE);
  694. if (instance && typeof instance[method] === 'function') {
  695. instance[method].apply(instance, args);
  696. }
  697. }
  698. )
  699. };
  700. }
  701. }();
  702. if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object")
  703. return _ret.v;
  704. }
  705. return this.each(
  706. function() {
  707. if (!(0, _jquery2.default)(this).data(NAMESPACE)) {
  708. (0, _jquery2.default)(this).data(NAMESPACE, new Selective(this, options));
  709. }
  710. }
  711. );
  712. };
  713. _jquery2.default.fn.selective = jQuerySelective;
  714. _jquery2.default.selective = _jquery2.default.extend({
  715. setDefaults: Selective.setDefaults,
  716. noConflict: function noConflict() {
  717. _jquery2.default.fn.selective = OtherSelective;
  718. return jQuerySelective;
  719. }
  720. }, info);
  721. }
  722. );