351ae0ca0cab57650f3e36a3aac3573be97f1a09f4ee23c6c6f618a90ee7e8edd7cbe8efbc230d70cb9cbaf47a46eb49b8eab2918c9512020c424dab592922 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. exports.__esModule = true;
  3. exports.default = jQueryWrapper;
  4. function jQueryWrapper(Handsontable) {
  5. var jQuery = typeof window === 'undefined' ? false : window.jQuery;
  6. if (!jQuery) {
  7. return;
  8. }
  9. jQuery.fn.handsontable = function (action) {
  10. var $this = this.first(); // Use only first element from list
  11. var instance = $this.data('handsontable');
  12. // Init case
  13. if (typeof action !== 'string') {
  14. var userSettings = action || {};
  15. if (instance) {
  16. instance.updateSettings(userSettings);
  17. } else {
  18. instance = new Handsontable.Core($this[0], userSettings);
  19. $this.data('handsontable', instance);
  20. instance.init();
  21. }
  22. return $this;
  23. }
  24. // Action case
  25. var args = [];
  26. var output = void 0;
  27. if (arguments.length > 1) {
  28. for (var i = 1, ilen = arguments.length; i < ilen; i++) {
  29. args.push(arguments[i]);
  30. }
  31. }
  32. if (instance) {
  33. if (typeof instance[action] !== 'undefined') {
  34. output = instance[action].apply(instance, args);
  35. if (action === 'destroy') {
  36. $this.removeData();
  37. }
  38. } else {
  39. throw new Error('Handsontable do not provide action: ' + action);
  40. }
  41. }
  42. return output;
  43. };
  44. };