jquery.resizable_wev8.js
2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/// <reference path="jquery_wev8.js"/>
/*
* resizable
* version: 1.0.0 (05/15/2009)
* @ jQuery v1.2.*
*
* Licensed under the GPL:
* http://gplv3.fsf.org
*
* Copyright 2008, 2009 Jericho [ thisnamemeansnothing[at]gmail.com ]
*/
//(function($) {
$.extend($.fn, {
getCss: function(key) {
var v = parseInt(this.css(key));
if (isNaN(v))
return false;
return v;
}
});
$.fn.resizable = function(opts) {
var ps = $.extend({
handler: null,
min: { width: 0, height: 0 },
max: { width: $(document).width(), height: $(document).height() },
onResize: function() { },
onStop: function() { }
}, opts);
var resize = {
resize: function(e) {
var resizeData = e.data.resizeData;
var w = Math.min(Math.max(e.pageX - resizeData.offLeft + resizeData.width, resizeData.min.width), ps.max.width);
var h = Math.min(Math.max(e.pageY - resizeData.offTop + resizeData.height, resizeData.min.height), ps.max.height);
resizeData.target.css({
width: w,
height: h
});
resizeData.onResize(e);
},
stop: function(e) {
e.data.resizeData.onStop(e);
document.body.onselectstart = function() { return true; }
e.data.resizeData.target.css('-moz-user-select', '');
$().unbind('mousemove', resize.resize)
.unbind('mouseup', resize.stop);
}
}
return this.each(function() {
var me = this;
var handler = null;
if (typeof ps.handler == 'undefined' || ps.handler == null)
handler = $(me);
else
handler = (typeof ps.handler == 'string' ? $(ps.handler, this) : ps.handle);
handler.bind('mousedown', { e: me }, function(s) {
var target = $(s.data.e);
var resizeData = {
width: target.width() || target.getCss('width'),
height: target.height() || target.getCss('height'),
offLeft: s.pageX,
offTop: s.pageY,
onResize: ps.onResize,
onStop: ps.onStop,
target: target,
min: ps.min,
max: ps.max
}
document.body.onselectstart = function() { return false; }
target.css('-moz-user-select', 'none');
$().bind('mousemove', { resizeData: resizeData }, resize.resize)
.bind('mouseup', { resizeData: resizeData }, resize.stop);
});
});
}
//})(jQuery);