No regular expressions were active.
|
|
1 |
|
(function(
$) {
|
|
|
2 |
|
|
|
|
3 |
|
$.fn.e
xtend({
|
|
|
4 |
|
dr
aggable: f
unction(op
tions) {
|
|
|
5 |
|
var args
= Array.p
rototype.s
lice.call(
arguments,
1);
|
|
|
6 |
|
|
|
|
7 |
|
return t
his.each(f
unction()
{
|
|
|
8 |
|
if (
typeof opt
ions == "s
tring") {
|
|
|
9 |
|
var drag =
$.data(th
is, "ui-dr
aggable");
|
|
|
10 |
|
drag[optio
ns].apply(
drag, args
);
|
|
|
11 |
|
|
|
|
12 |
|
} el
se if(!$.d
ata(this,
"ui-dragga
ble"))
|
|
|
13 |
|
new $.ui.d
raggable(t
his, optio
ns);
|
|
|
14 |
|
});
|
|
|
15 |
|
}
|
|
|
16 |
|
});
|
|
|
17 |
|
|
|
|
18 |
|
$.ui.d
raggable =
function(
element, o
ptions) {
|
|
|
19 |
|
//
Initialize
needed co
nstants
|
|
|
20 |
|
va
r self = t
his;
|
|
|
21 |
|
|
|
|
22 |
|
th
is.element
= $(eleme
nt);
|
|
|
23 |
|
|
|
|
24 |
|
$.
data(eleme
nt, "ui-dr
aggable",
this);
|
|
|
25 |
|
th
is.element
.addClass(
"ui-dragga
ble");
|
|
|
26 |
|
|
|
|
27 |
|
//
Prepare th
e passed o
ptions
|
|
|
28 |
|
th
is.options
= $.exten
d({}, opti
ons);
|
|
|
29 |
|
va
r o = this
.options;
|
|
|
30 |
|
$.
extend(o,
{
|
|
|
31 |
|
helper:
o.ghosting
== true ?
'clone' :
(o.helper
|| 'origi
nal'),
|
|
|
32 |
|
handle :
o.handle
? ($(o.han
dle, eleme
nt)[0] ? $
(o.handle,
element)
: this.ele
ment) : th
is.element
,
|
|
|
33 |
|
appendTo
: o.append
To || 'par
ent'
|
|
|
34 |
|
})
;
|
|
|
35 |
|
|
|
|
36 |
|
$(
element).b
ind("setDa
ta.draggab
le", funct
ion(event,
key, valu
e){
|
|
|
37 |
|
self.opt
ions[key]
= value;
|
|
|
38 |
|
})
.bind("get
Data.dragg
able", fun
ction(even
t, key){
|
|
|
39 |
|
return s
elf.option
s[key];
|
|
|
40 |
|
})
;
|
|
|
41 |
|
|
|
|
42 |
|
//
Initialize
mouse eve
nts for in
teraction
|
|
|
43 |
|
$(
o.handle).
mouseInter
action({
|
|
|
44 |
|
executor
: this,
|
|
|
45 |
|
delay: o
.delay,
|
|
|
46 |
|
distance
: o.distan
ce || 0,
|
|
|
47 |
|
dragPrev
ention: o.
prevention
? o.preve
ntion.toLo
werCase().
split(',')
: ['input
','textare
a','button
','select'
,'option']
,
|
|
|
48 |
|
start: t
his.start,
|
|
|
49 |
|
stop: th
is.stop,
|
|
|
50 |
|
drag: th
is.drag,
|
|
|
51 |
|
conditio
n: functio
n(e) { ret
urn !(e.ta
rget.class
Name.index
Of("ui-res
izable-han
dle") != -
1 || this.
disabled);
}
|
|
|
52 |
|
})
;
|
|
|
53 |
|
|
|
|
54 |
|
//
Position t
he node
|
|
|
55 |
|
if
(o.helper
== 'origin
al' && (th
is.element
.css('posi
tion') ==
'static' |
| this.ele
ment.css('
position')
== ''))
|
|
|
56 |
|
this.ele
ment.css('
position',
'relative
');
|
|
|
57 |
|
|
|
|
58 |
|
};
|
|
|
59 |
|
|
|
|
60 |
|
$.exte
nd($.ui.dr
aggable.pr
ototype, {
|
|
|
61 |
|
pl
ugins: {},
|
|
|
62 |
|
ui
: function
(e) {
|
|
|
63 |
|
return {
|
|
|
64 |
|
help
er: this.h
elper,
|
|
|
65 |
|
posi
tion: this
.position,
|
|
|
66 |
|
abso
lutePositi
on: this.p
ositionAbs
,
|
|
|
67 |
|
inst
ance: this
,
|
|
|
68 |
|
opti
ons: this.
options
|
|
|
69 |
|
};
|
|
|
70 |
|
},
|
|
|
71 |
|
pr
opagate: f
unction(n,
e) {
|
|
|
72 |
|
$.ui.plu
gin.call(t
his, n, [e
, this.ui(
)]);
|
|
|
73 |
|
return t
his.elemen
t.triggerH
andler(n =
= "drag" ?
n : "drag
"+n, [e, t
his.ui()],
this.opti
ons[n]);
|
|
|
74 |
|
},
|
|
|
75 |
|
de
stroy: fun
ction() {
|
|
|
76 |
|
this.han
dle.remove
MouseInter
action();
|
|
|
77 |
|
this.ele
ment
|
|
|
78 |
|
.rem
oveClass("
ui-draggab
le ui-drag
gable-disa
bled")
|
|
|
79 |
|
.rem
oveData("u
i-draggabl
e")
|
|
|
80 |
|
.unb
ind(".drag
gable");
|
|
|
81 |
|
},
|
|
|
82 |
|
en
able: func
tion() {
|
|
|
83 |
|
this.ele
ment.remov
eClass("ui
-draggable
-disabled"
);
|
|
|
84 |
|
this.dis
abled = fa
lse;
|
|
|
85 |
|
},
|
|
|
86 |
|
di
sable: fun
ction() {
|
|
|
87 |
|
this.ele
ment.addCl
ass("ui-dr
aggable-di
sabled");
|
|
|
88 |
|
this.dis
abled = tr
ue;
|
|
|
89 |
|
},
|
|
|
90 |
|
re
callOffset
: function
(e) {
|
|
|
91 |
|
|
|
|
92 |
|
var elem
entPositio
n = { left
: this.ele
mentOffset
.left - th
is.offsetP
arentOffse
t.left, to
p: this.el
ementOffse
t.top - th
is.offsetP
arentOffse
t.top };
|
|
|
93 |
|
var r =
this.helpe
r.css('pos
ition') ==
'relative
';
|
|
|
94 |
|
|
|
|
95 |
|
//Genera
te the ori
ginal posi
tion
|
|
|
96 |
|
this.ori
ginalPosit
ion = {
|
|
|
97 |
|
left
: (r ? par
seInt(this
.helper.cs
s('left'),
10) || 0 :
elementPo
sition.lef
t + (this.
offsetPare
nt[0] == d
ocument.bo
dy ? 0 : t
his.offset
Parent[0].
scrollLeft
)),
|
|
|
98 |
|
top:
(r ? pars
eInt(this.
helper.css
('top'),10
) || 0 : e
lementPosi
tion.top +
(this.off
setParent[
0] == docu
ment.body
? 0 : this
.offsetPar
ent[0].scr
ollTop))
|
|
|
99 |
|
};
|
|
|
100 |
|
|
|
|
101 |
|
//Genera
te a flexi
ble offset
that will
later be
subtracted
from e.pa
geX/Y
|
|
|
102 |
|
this.off
set = {lef
t: this._p
ageX - thi
s.original
Position.l
eft, top:
this._page
Y - this.o
riginalPos
ition.top
};
|
|
|
103 |
|
|
|
|
104 |
|
},
|
|
|
105 |
|
st
art: funct
ion(e) {
|
|
|
106 |
|
|
|
|
107 |
|
var o =
this.optio
ns;
|
|
|
108 |
|
if($.ui.
ddmanager)
$.ui.ddma
nager.curr
ent = this
;
|
|
|
109 |
|
|
|
|
110 |
|
//Create
and appen
d the visi
ble helper
|
|
|
111 |
|
this.hel
per = type
of o.helpe
r == 'func
tion' ? $(
o.helper.a
pply(this.
element[0]
, [e])) :
(o.helper
== 'clone'
? this.el
ement.clon
e().append
To((o.appe
ndTo == 'p
arent' ? t
his.elemen
t[0].paren
tNode : o.
appendTo))
: this.el
ement);
|
|
|
112 |
|
if(this.
helper[0]
!= this.el
ement[0])
this.helpe
r.css('pos
ition', 'a
bsolute');
|
|
|
113 |
|
if(!this
.helper.pa
rents('bod
y').length
) this.hel
per.append
To((o.appe
ndTo == 'p
arent' ? t
his.elemen
t[0].paren
tNode : o.
appendTo))
;
|
|
|
114 |
|
|
|
|
115 |
|
//Find o
ut the nex
t position
ed parent
|
|
|
116 |
|
this.off
setParent
= (functio
n(cp) {
|
|
|
117 |
|
whil
e(cp) {
|
|
|
118 |
|
if(cp.styl
e && (/(ab
solute|rel
ative|fixe
d)/).test(
$.css(cp,'
position')
)) return
$(cp);
|
|
|
119 |
|
cp = cp.pa
rentNode ?
cp.parent
Node : nul
l;
|
|
|
120 |
|
}; r
eturn $("b
ody");
|
|
|
121 |
|
})(this.
helper[0].
parentNode
);
|
|
|
122 |
|
|
|
|
123 |
|
//Prepar
e variable
s for posi
tion gener
ation
|
|
|
124 |
|
this.ele
mentOffset
= this.el
ement.offs
et();
|
|
|
125 |
|
this.off
setParentO
ffset = th
is.offsetP
arent.offs
et();
|
|
|
126 |
|
var elem
entPositio
n = { left
: this.ele
mentOffset
.left - th
is.offsetP
arentOffse
t.left, to
p: this.el
ementOffse
t.top - th
is.offsetP
arentOffse
t.top };
|
|
|
127 |
|
this._pa
geX = e.pa
geX; this.
_pageY = e
.pageY;
|
|
|
128 |
|
this.cli
ckOffset =
{ left: e
.pageX - t
his.elemen
tOffset.le
ft, top: e
.pageY - t
his.elemen
tOffset.to
p };
|
|
|
129 |
|
var r =
this.helpe
r.css('pos
ition') ==
'relative
';
|
|
|
130 |
|
|
|
|
131 |
|
//Genera
te the ori
ginal posi
tion
|
|
|
132 |
|
this.ori
ginalPosit
ion = {
|
|
|
133 |
|
left
: (r ? par
seInt(this
.helper.cs
s('left'),
10) || 0 :
elementPo
sition.lef
t + (this.
offsetPare
nt[0] == d
ocument.bo
dy ? 0 : t
his.offset
Parent[0].
scrollLeft
)),
|
|
|
134 |
|
top:
(r ? pars
eInt(this.
helper.css
('top'),10
) || 0 : e
lementPosi
tion.top +
(this.off
setParent[
0] == docu
ment.body
? 0 : this
.offsetPar
ent[0].scr
ollTop))
|
|
|
135 |
|
};
|
|
|
136 |
|
|
|
|
137 |
|
//If we
have a fix
ed element
, we must
subtract t
he scroll
offset aga
in
|
|
|
138 |
|
if(this.
element.cs
s('positio
n') == 'fi
xed') {
|
|
|
139 |
|
this
.originalP
osition.to
p -= this.
offsetPare
nt[0] == d
ocument.bo
dy ? $(doc
ument).scr
ollTop() :
this.offs
etParent[0
].scrollTo
p;
|
|
|
140 |
|
this
.originalP
osition.le
ft -= this
.offsetPar
ent[0] ==
document.b
ody ? $(do
cument).sc
rollLeft()
: this.of
fsetParent
[0].scroll
Left;
|
|
|
141 |
|
}
|
|
|
142 |
|
|
|
|
143 |
|
//Genera
te a flexi
ble offset
that will
later be
subtracted
from e.pa
geX/Y
|
|
|
144 |
|
this.off
set = {lef
t: e.pageX
- this.or
iginalPosi
tion.left,
top: e.pa
geY - this
.originalP
osition.to
p };
|
|
|
145 |
|
|
|
|
146 |
|
//Call p
lugins and
callbacks
|
|
|
147 |
|
this.pro
pagate("st
art", e);
|
|
|
148 |
|
|
|
|
149 |
|
this.hel
perProport
ions = { w
idth: this
.helper.ou
terWidth()
, height:
this.helpe
r.outerHei
ght() };
|
|
|
150 |
|
if ($.ui
.ddmanager
&& !o.dro
pBehaviour
) $.ui.ddm
anager.pre
pareOffset
s(this, e)
;
|
|
|
151 |
|
|
|
|
152 |
|
//If we
have somet
hing in cu
rsorAt, we
'll use it
|
|
|
153 |
|
if(o.cur
sorAt) {
|
|
|
154 |
|
if(o
.cursorAt.
top != und
efined ||
o.cursorAt
.bottom !=
undefined
) {
|
|
|
155 |
|
this.offse
t.top -= t
his.clickO
ffset.top
- (o.curso
rAt.top !=
undefined
? o.curso
rAt.top :
(this.help
erProporti
ons.height
- o.curso
rAt.bottom
));
|
|
|
156 |
|
this.click
Offset.top
= (o.curs
orAt.top !
= undefine
d ? o.curs
orAt.top :
(this.hel
perProport
ions.heigh
t - o.curs
orAt.botto
m));
|
|
|
157 |
|
}
|
|
|
158 |
|
if(o
.cursorAt.
left != un
defined ||
o.cursorA
t.right !=
undefined
) {
|
|
|
159 |
|
this.offse
t.left -=
this.click
Offset.lef
t - (o.cur
sorAt.left
!= undefi
ned ? o.cu
rsorAt.lef
t : (this.
helperProp
ortions.wi
dth - o.cu
rsorAt.rig
ht));
|
|
|
160 |
|
this.click
Offset.lef
t = (o.cur
sorAt.left
!= undefi
ned ? o.cu
rsorAt.lef
t : (this.
helperProp
ortions.wi
dth - o.cu
rsorAt.rig
ht));
|
|
|
161 |
|
}
|
|
|
162 |
|
}
|
|
|
163 |
|
|
|
|
164 |
|
return f
alse;
|
|
|
165 |
|
|
|
|
166 |
|
},
|
|
|
167 |
|
cl
ear: funct
ion() {
|
|
|
168 |
|
if($.ui.
ddmanager)
$.ui.ddma
nager.curr
ent = null
;
|
|
|
169 |
|
this.hel
per = null
;
|
|
|
170 |
|
},
|
|
|
171 |
|
st
op: functi
on(e) {
|
|
|
172 |
|
|
|
|
173 |
|
//If we
are using
droppables
, inform t
he manager
about the
drop
|
|
|
174 |
|
if ($.ui
.ddmanager
&& !this.
options.dr
opBehaviou
r)
|
|
|
175 |
|
$.ui
.ddmanager
.drop(this
, e);
|
|
|
176 |
|
|
|
|
177 |
|
//Call p
lugins and
trigger c
allbacks
|
|
|
178 |
|
this.pro
pagate("st
op", e);
|
|
|
179 |
|
|
|
|
180 |
|
if(this.
cancelHelp
erRemoval)
return fa
lse;
|
|
|
181 |
|
if(this.
options.he
lper != 'o
riginal')
this.helpe
r.remove()
;
|
|
|
182 |
|
this.cle
ar();
|
|
|
183 |
|
|
|
|
184 |
|
return f
alse;
|
|
|
185 |
|
},
|
|
|
186 |
|
dr
ag: functi
on(e) {
|
|
|
187 |
|
|
|
|
188 |
|
//Comput
e the help
ers positi
on
|
|
|
189 |
|
this.pos
ition = {
top: e.pag
eY - this.
offset.top
, left: e.
pageX - th
is.offset.
left };
|
|
|
190 |
|
this.pos
itionAbs =
{ left: e
.pageX - t
his.clickO
ffset.left
, top: e.p
ageY - thi
s.clickOff
set.top };
|
|
|
191 |
|
|
|
|
192 |
|
//Call p
lugins and
callbacks
|
|
|
193 |
|
this.pos
ition = th
is.propaga
te("drag",
e) || thi
s.position
;
|
|
|
194 |
|
|
|
|
195 |
|
this.hel
per.css({
left: this
.position.
left+'px',
top: this
.position.
top+'px' }
); // Stic
k the help
er to the
cursor
|
|
|
196 |
|
if($.ui.
ddmanager)
$.ui.ddma
nager.drag
(this, e);
|
|
|
197 |
|
return f
alse;
|
|
|
198 |
|
|
|
|
199 |
|
}
|
|
|
200 |
|
});
|
|
|
201 |
|
|
|
|
202 |
|
})(jQuery)
;
|