editlist.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. (function (global, factory) {
  2. if (typeof define === "function" && define.amd) {
  3. define("/Plugin/editlist", ["exports", "jquery", "Plugin"], factory);
  4. } else if (typeof exports !== "undefined") {
  5. factory(exports, require("jquery"), require("Plugin"));
  6. } else {
  7. var mod = {
  8. exports: {}
  9. };
  10. factory(mod.exports, global.jQuery, global.Plugin);
  11. global.PluginEditlist = mod.exports;
  12. }
  13. })(this, function (_exports, _jquery, _Plugin2) {
  14. "use strict";
  15. Object.defineProperty(_exports, "__esModule", {
  16. value: true
  17. });
  18. _exports.default = void 0;
  19. _jquery = babelHelpers.interopRequireDefault(_jquery);
  20. _Plugin2 = babelHelpers.interopRequireDefault(_Plugin2);
  21. var pluginName = 'editlist';
  22. var defaults = {};
  23. var editlist =
  24. /*#__PURE__*/
  25. function () {
  26. function editlist(element, options) {
  27. babelHelpers.classCallCheck(this, editlist);
  28. this.element = element;
  29. this.$element = (0, _jquery.default)(element);
  30. this.$content = this.$element.find('.list-content');
  31. this.$text = this.$element.find('.list-text');
  32. this.$editable = this.$element.find('.list-editable');
  33. this.$editBtn = this.$element.find('[data-toggle=list-editable]');
  34. this.$delBtn = this.$element.find('[data-toggle=list-delete]');
  35. this.$closeBtn = this.$element.find('[data-toggle=list-editable-close]');
  36. this.$input = this.$element.find('input');
  37. this.options = _jquery.default.extend({}, _Plugin2.default.defaults, options, this.$element.data());
  38. this.init();
  39. }
  40. babelHelpers.createClass(editlist, [{
  41. key: "init",
  42. value: function init() {
  43. this.bind();
  44. }
  45. }, {
  46. key: "bind",
  47. value: function bind() {
  48. var self = this;
  49. this.$editBtn.on('click', function () {
  50. self.enable();
  51. });
  52. this.$closeBtn.on('click', function () {
  53. self.disable();
  54. });
  55. this.$delBtn.on('click', function () {
  56. if (typeof bootbox === 'undefined') {
  57. return;
  58. }
  59. bootbox.dialog({
  60. message: 'Do you want to delete the contact?',
  61. buttons: {
  62. success: {
  63. label: 'Delete',
  64. className: 'btn-danger',
  65. callback: function callback() {
  66. self.$element.remove();
  67. }
  68. }
  69. }
  70. });
  71. });
  72. this.$input.on('keydown', function (e) {
  73. var keycode = e.keyCode ? e.keyCode : e.which;
  74. if (keycode === 13 || keycode === 27) {
  75. if (keycode === 13) {
  76. self.$text.html(self.$input.val());
  77. } else {
  78. self.$input.val(self.$text.text());
  79. }
  80. self.disable();
  81. }
  82. });
  83. }
  84. }, {
  85. key: "enable",
  86. value: function enable() {
  87. this.$content.hide();
  88. this.$editable.show();
  89. this.$input.focus().select();
  90. }
  91. }, {
  92. key: "disable",
  93. value: function disable() {
  94. this.$content.show();
  95. this.$editable.hide();
  96. }
  97. }], [{
  98. key: "_jQueryInterface",
  99. value: function _jQueryInterface(options) {
  100. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  101. args[_key - 1] = arguments[_key];
  102. }
  103. if (typeof options === 'string') {
  104. var method = options;
  105. if (/^\_/.test(method)) {
  106. return false;
  107. } else if (/^(get)$/.test(method)) {
  108. var api = this.first().data(pluginName);
  109. if (api && typeof api[method] === 'function') {
  110. return api[method].apply(api, args);
  111. }
  112. } else {
  113. return this.each(function () {
  114. var api = _jquery.default.data(this, pluginName);
  115. if (api && typeof api[method] === 'function') {
  116. api[method].apply(api, args);
  117. }
  118. });
  119. }
  120. } else {
  121. return this.each(function () {
  122. if (!_jquery.default.data(this, pluginName)) {
  123. _jquery.default.data(this, pluginName, new editlist(this, options));
  124. }
  125. });
  126. }
  127. }
  128. }]);
  129. return editlist;
  130. }();
  131. _jquery.default.fn[pluginName] = editlist._jQueryInterface;
  132. _jquery.default.fn[pluginName].constructor = editlist;
  133. _jquery.default.fn[pluginName].noConflict = function () {
  134. _jquery.default.fn[pluginName] = window.JQUERY_NO_CONFLICT;
  135. return editlist._jQueryInterface;
  136. };
  137. var Editlist =
  138. /*#__PURE__*/
  139. function (_Plugin) {
  140. babelHelpers.inherits(Editlist, _Plugin);
  141. function Editlist() {
  142. babelHelpers.classCallCheck(this, Editlist);
  143. return babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(Editlist).apply(this, arguments));
  144. }
  145. babelHelpers.createClass(Editlist, [{
  146. key: "getName",
  147. value: function getName() {
  148. return pluginName;
  149. }
  150. }], [{
  151. key: "getDefaults",
  152. value: function getDefaults() {
  153. return defaults;
  154. }
  155. }]);
  156. return Editlist;
  157. }(_Plugin2.default);
  158. _Plugin2.default.register(pluginName, Editlist);
  159. var _default = Editlist;
  160. _exports.default = _default;
  161. });