jqueryHOT.js 1.4 KB

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