jquery.droppable.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * EasyUI for jQuery 1.5.5.6
  3. *
  4. * Copyright (c) 2009-2018 www.jeasyui.com. All rights reserved.
  5. *
  6. * Licensed under the freeware license: http://www.jeasyui.com/license_freeware.php
  7. * To use it on other terms please contact us: info@jeasyui.com
  8. *
  9. */
  10. /**
  11. * droppable - EasyUI for jQuery
  12. *
  13. */
  14. (function($){
  15. function init(target){
  16. $(target).addClass('droppable');
  17. $(target).bind('_dragenter', function(e, source){
  18. $.data(target, 'droppable').options.onDragEnter.apply(target, [e, source]);
  19. });
  20. $(target).bind('_dragleave', function(e, source){
  21. $.data(target, 'droppable').options.onDragLeave.apply(target, [e, source]);
  22. });
  23. $(target).bind('_dragover', function(e, source){
  24. $.data(target, 'droppable').options.onDragOver.apply(target, [e, source]);
  25. });
  26. $(target).bind('_drop', function(e, source){
  27. $.data(target, 'droppable').options.onDrop.apply(target, [e, source]);
  28. });
  29. }
  30. $.fn.droppable = function(options, param){
  31. if (typeof options == 'string'){
  32. return $.fn.droppable.methods[options](this, param);
  33. }
  34. options = options || {};
  35. return this.each(function(){
  36. var state = $.data(this, 'droppable');
  37. if (state){
  38. $.extend(state.options, options);
  39. } else {
  40. init(this);
  41. $.data(this, 'droppable', {
  42. options: $.extend({}, $.fn.droppable.defaults, $.fn.droppable.parseOptions(this), options)
  43. });
  44. }
  45. });
  46. };
  47. $.fn.droppable.methods = {
  48. options: function(jq){
  49. return $.data(jq[0], 'droppable').options;
  50. },
  51. enable: function(jq){
  52. return jq.each(function(){
  53. $(this).droppable({disabled:false});
  54. });
  55. },
  56. disable: function(jq){
  57. return jq.each(function(){
  58. $(this).droppable({disabled:true});
  59. });
  60. }
  61. };
  62. $.fn.droppable.parseOptions = function(target){
  63. var t = $(target);
  64. return $.extend({}, $.parser.parseOptions(target, ['accept']), {
  65. disabled: (t.attr('disabled') ? true : undefined)
  66. });
  67. };
  68. $.fn.droppable.defaults = {
  69. accept:null,
  70. disabled:false,
  71. onDragEnter:function(e, source){},
  72. onDragOver:function(e, source){},
  73. onDragLeave:function(e, source){},
  74. onDrop:function(e, source){}
  75. };
  76. })(jQuery);