editlist.js 5.3 KB

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