jqDnR.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * jqDnR - Minimalistic Drag'n'Resize for jQuery.
  3. *
  4. * Copyright (c) 2007 Brice Burgess <bhb@iceburg.net>, http://www.iceburg.net
  5. * Licensed under the MIT License:
  6. * http://www.opensource.org/licenses/mit-license.php
  7. *
  8. * $Version: 2007.08.19 +r2
  9. */
  10. /*jshint eqeqeq:false */
  11. /*global jQuery, define */
  12. (function( factory ) {
  13. "use strict";
  14. if ( typeof define === "function" && define.amd ) {
  15. // AMD. Register as an anonymous module.
  16. define([
  17. "jquery"
  18. ], factory );
  19. } else {
  20. // Browser globals
  21. factory( jQuery );
  22. }
  23. } (function( $ ) {
  24. "use strict";
  25. //module begin
  26. $.fn.jqDrag=function(h){return i(this,h,'d');};
  27. $.fn.jqResize=function(h,ar){return i(this,h,'r',ar);};
  28. $.jqDnR={
  29. dnr:{},
  30. e:0,
  31. drag:function(v){
  32. if(M.k == 'd'){E.css({left:M.X+v.pageX-M.pX,top:M.Y+v.pageY-M.pY});}
  33. else {
  34. E.css({width:Math.max(v.pageX-M.pX+M.W,0),height:Math.max(v.pageY-M.pY+M.H,0)});
  35. if(M1){E1.css({width:Math.max(v.pageX-M1.pX+M1.W,0),height:Math.max(v.pageY-M1.pY+M1.H,0)});}
  36. }
  37. return false;
  38. },
  39. stop:function(){
  40. //E.css('opacity',M.o);
  41. $(document).off('mousemove',J.drag).off('mouseup',J.stop);
  42. }
  43. };
  44. var J=$.jqDnR,M=J.dnr,E=J.e,E1,M1,
  45. i=function(e,h,k,aR){
  46. return e.each(function(){
  47. h=(h)?$(h,e):e;
  48. h.on('mousedown',{e:e,k:k},function(v){
  49. var d=v.data,p={};E=d.e;E1 = aR ? $(aR) : false;
  50. // attempt utilization of dimensions plugin to fix IE issues
  51. if(E.css('position') != 'relative'){try{E.position(p);}catch(e){}}
  52. M={
  53. X:p.left||f('left')||0,
  54. Y:p.top||f('top')||0,
  55. W:f('width')||E[0].scrollWidth||0,
  56. H:f('height')||E[0].scrollHeight||0,
  57. pX:v.pageX,
  58. pY:v.pageY,
  59. k:d.k
  60. //o:E.css('opacity')
  61. };
  62. // also resize
  63. if(E1 && d.k != 'd'){
  64. M1={
  65. X:p.left||f1('left')||0,
  66. Y:p.top||f1('top')||0,
  67. W:E1[0].offsetWidth||f1('width')||0,
  68. H:E1[0].offsetHeight||f1('height')||0,
  69. pX:v.pageX,
  70. pY:v.pageY,
  71. k:d.k
  72. };
  73. } else {M1 = false;}
  74. //E.css({opacity:0.8});
  75. if($("input.hasDatepicker",E[0])[0]) {
  76. try {$("input.hasDatepicker",E[0]).datepicker('hide');}catch (dpe){}
  77. }
  78. $(document).mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);
  79. return false;
  80. });
  81. });
  82. },
  83. f=function(k){return parseInt(E.css(k),10)||false;},
  84. f1=function(k){return parseInt(E1.css(k),10)||false;};
  85. /*
  86. jQuery tinyDraggable v1.0.2
  87. Copyright (c) 2014 Simon Steinberger / Pixabay
  88. GitHub: https://github.com/Pixabay/jQuery-tinyDraggable
  89. More info: https://pixabay.com/blog/posts/p-52/
  90. License: http://www.opensource.org/licenses/mit-license.php
  91. */
  92. $.fn.tinyDraggable = function(options){
  93. var settings = $.extend({ handle: 0, exclude: 0 }, options);
  94. return this.each(function(){
  95. var dx, dy, el = $(this), handle = settings.handle ? $(settings.handle, el) : el;
  96. handle.on({
  97. mousedown: function(e){
  98. if (settings.exclude && ~$.inArray(e.target, $(settings.exclude, el))) { return; }
  99. e.preventDefault();
  100. var os = el.offset(); dx = e.pageX-os.left, dy = e.pageY-os.top;
  101. $(document).on('mousemove.drag', function(e){ el.offset({top: e.pageY-dy, left: e.pageX-dx}); });
  102. },
  103. mouseup: function(e){ $(document).off('mousemove.drag'); }
  104. });
  105. });
  106. };
  107. //module end
  108. }));