No regular expressions were active.
|
|
1 |
|
if (window
.Node && N
ode.protot
ype && !No
de.prototy
pe.contain
s) {
|
|
|
2 |
|
Node.p
rototype.c
ontains =
function (
arg) {
|
|
|
3 |
|
re
turn !!(th
is.compare
DocumentPo
sition(arg
) & 16)
|
|
|
4 |
|
}
|
|
|
5 |
|
}
|
|
|
6 |
|
|
|
|
7 |
|
(function(
$) {
|
|
|
8 |
|
|
|
|
9 |
|
//Make
nodes sel
ectable by
expressio
n
|
|
|
10 |
|
$.exte
nd($.expr[
':'], { so
rtable: "(
' '+a.clas
sName+' ')
.indexOf('
ui-sortab
le ')" });
|
|
|
11 |
|
|
|
|
12 |
|
$.fn.s
ortable =
function(o
) {
|
|
|
13 |
|
re
turn this.
each(funct
ion() {
|
|
|
14 |
|
new $.ui
.sortable(
this,o);
|
|
|
15 |
|
})
;
|
|
|
16 |
|
}
|
|
|
17 |
|
|
|
|
18 |
|
//Macr
os for ext
ernal meth
ods that s
upport cha
ining
|
|
|
19 |
|
var me
thods = "d
estroy,ena
ble,disabl
e,refresh"
.split(","
);
|
|
|
20 |
|
for(va
r i=0;i<me
thods.leng
th;i++) {
|
|
|
21 |
|
va
r cur = me
thods[i],
f;
|
|
|
22 |
|
ev
al('f = fu
nction() {
var a = a
rguments;
return thi
s.each(fun
ction() {
if(jQuery(
this).is("
.ui-sortab
le")) jQue
ry.data(th
is, "ui-so
rtable")["
'+cur+'"](
a); }); }'
);
|
|
|
23 |
|
$.
fn["sortab
le"+cur.su
bstr(0,1).
toUpperCas
e()+cur.su
bstr(1)] =
f;
|
|
|
24 |
|
};
|
|
|
25 |
|
|
|
|
26 |
|
//get
instance m
ethod
|
|
|
27 |
|
$.fn.s
ortableIns
tance = fu
nction() {
|
|
|
28 |
|
if
($(this[0]
).is(".ui-
sortable")
) return $
.data(this
[0], "ui-s
ortable");
|
|
|
29 |
|
re
turn false
;
|
|
|
30 |
|
};
|
|
|
31 |
|
|
|
|
32 |
|
$.ui.s
ortable =
function(e
l,o) {
|
|
|
33 |
|
|
|
|
34 |
|
th
is.element
= el;
|
|
|
35 |
|
th
is.set = [
];
|
|
|
36 |
|
va
r options
= {};
|
|
|
37 |
|
va
r self = t
his;
|
|
|
38 |
|
$.
data(this.
element, "
ui-sortabl
e", this);
|
|
|
39 |
|
$(
el).addCla
ss("ui-sor
table");
|
|
|
40 |
|
|
|
|
41 |
|
$.
extend(opt
ions, o);
|
|
|
42 |
|
$.
extend(opt
ions, {
|
|
|
43 |
|
items: o
ptions.ite
ms || '> l
i',
|
|
|
44 |
|
smooth:
options.sm
ooth != un
defined ?
options.sm
ooth : tru
e,
|
|
|
45 |
|
helper:
'clone',
|
|
|
46 |
|
containm
ent: optio
ns.contain
ment ? (op
tions.cont
ainment ==
'sortable
' ? el : o
ptions.con
tainment)
: null,
|
|
|
47 |
|
zIndex:
options.zI
ndex || 10
00,
|
|
|
48 |
|
_start:
function(h
,p,c,t,e)
{
|
|
|
49 |
|
self
.start.app
ly(t, [sel
f, e]); //
Trigger t
he onStart
callback
|
|
|
50 |
|
},
|
|
|
51 |
|
_beforeS
top: funct
ion(h,p,c,
t,e) {
|
|
|
52 |
|
self
.stop.appl
y(t, [self
, e]); //
Trigger th
e onStart
callback
|
|
|
53 |
|
},
|
|
|
54 |
|
_drag: f
unction(h,
p,c,t,e) {
|
|
|
55 |
|
self
.drag.appl
y(t, [self
, e]); //
Trigger th
e onStart
callback
|
|
|
56 |
|
},
|
|
|
57 |
|
startCon
dition: fu
nction() {
|
|
|
58 |
|
retu
rn !self.d
isabled;
|
|
|
59 |
|
}
|
|
|
60 |
|
})
;
|
|
|
61 |
|
|
|
|
62 |
|
//
Get the it
ems
|
|
|
63 |
|
va
r items =
$(options.
items, el)
;
|
|
|
64 |
|
|
|
|
65 |
|
//
Let's dete
rmine the
floating m
ode
|
|
|
66 |
|
op
tions.floa
ting = /le
ft|right/.
test(items
.css('floa
t'));
|
|
|
67 |
|
|
|
|
68 |
|
//
Let's dete
rmine the
parent's o
ffset
|
|
|
69 |
|
if
($(el).css
('position
') == 'sta
tic') $(el
).css('pos
ition', 'r
elative');
|
|
|
70 |
|
op
tions.offs
et = $(el)
.offset({
border: fa
lse });
|
|
|
71 |
|
|
|
|
72 |
|
it
ems.each(f
unction()
{
|
|
|
73 |
|
new $.ui
.mouseInte
raction(th
is,options
);
|
|
|
74 |
|
})
;
|
|
|
75 |
|
|
|
|
76 |
|
//
Add curren
t items to
the set
|
|
|
77 |
|
it
ems.each(f
unction()
{
|
|
|
78 |
|
self.set
.push([thi
s,null]);
|
|
|
79 |
|
})
;
|
|
|
80 |
|
|
|
|
81 |
|
th
is.options
= options
;
|
|
|
82 |
|
}
|
|
|
83 |
|
|
|
|
84 |
|
$.exte
nd($.ui.so
rtable.pro
totype, {
|
|
|
85 |
|
pl
ugins: {},
|
|
|
86 |
|
cu
rrentTarge
t: null,
|
|
|
87 |
|
la
stTarget:
null,
|
|
|
88 |
|
pr
epareCallb
ackObj: fu
nction(sel
f, that) {
|
|
|
89 |
|
return {
|
|
|
90 |
|
help
er: self.h
elper,
|
|
|
91 |
|
posi
tion: { le
ft: self.p
os[0], top
: self.pos
[1] },
|
|
|
92 |
|
offs
et: self.o
ptions.cur
sorAt,
|
|
|
93 |
|
drag
gable: sel
f,
|
|
|
94 |
|
curr
ent: that,
|
|
|
95 |
|
opti
ons: self.
options
|
|
|
96 |
|
}
|
|
|
97 |
|
},
|
|
|
98 |
|
re
fresh: fun
ction() {
|
|
|
99 |
|
|
|
|
100 |
|
//Get th
e items
|
|
|
101 |
|
var self
= this;
|
|
|
102 |
|
var item
s = $(this
.options.i
tems, this
.element);
|
|
|
103 |
|
|
|
|
104 |
|
var uniq
ue = [];
|
|
|
105 |
|
items.ea
ch(functio
n() {
|
|
|
106 |
|
old
= false;
|
|
|
107 |
|
for(
var i=0;i<
self.set.l
ength;i++)
{ if(self
.set[i][0]
== this)
old = true
; }
|
|
|
108 |
|
if(!
old) uniqu
e.push(thi
s);
|
|
|
109 |
|
});
|
|
|
110 |
|
|
|
|
111 |
|
for(var
i=0;i<uniq
ue.length;
i++) {
|
|
|
112 |
|
new
$.ui.mouse
Interactio
n(unique[i
],self.opt
ions);
|
|
|
113 |
|
}
|
|
|
114 |
|
|
|
|
115 |
|
//Add cu
rrent item
s to the s
et
|
|
|
116 |
|
this.set
= [];
|
|
|
117 |
|
items.ea
ch(functio
n() {
|
|
|
118 |
|
self
.set.push(
[this,null
]);
|
|
|
119 |
|
});
|
|
|
120 |
|
|
|
|
121 |
|
},
|
|
|
122 |
|
de
stroy: fun
ction() {
|
|
|
123 |
|
$(this.e
lement).re
moveClass(
"ui-sortab
le").remov
eClass("ui
-sortable-
disabled")
;
|
|
|
124 |
|
$(this.o
ptions.ite
ms, this.e
lement).mo
useInterac
tionDestro
y();
|
|
|
125 |
|
|
|
|
126 |
|
},
|
|
|
127 |
|
en
able: func
tion() {
|
|
|
128 |
|
$(this.e
lement).re
moveClass(
"ui-sortab
le-disable
d");
|
|
|
129 |
|
this.dis
abled = fa
lse;
|
|
|
130 |
|
},
|
|
|
131 |
|
di
sable: fun
ction() {
|
|
|
132 |
|
$(this.e
lement).ad
dClass("ui
-sortable-
disabled")
;
|
|
|
133 |
|
this.dis
abled = tr
ue;
|
|
|
134 |
|
},
|
|
|
135 |
|
st
art: funct
ion(that,
e) {
|
|
|
136 |
|
|
|
|
137 |
|
var o =
this.optio
ns;
|
|
|
138 |
|
|
|
|
139 |
|
if(o.hov
erClass) {
|
|
|
140 |
|
that
.helper =
$('<div cl
ass="'+o.h
overClass+
'"></div>'
).appendTo
('body').c
ss({
|
|
|
141 |
|
height: th
is.element
.offsetHei
ght+'px',
|
|
|
142 |
|
width: thi
s.element.
offsetWidt
h+'px',
|
|
|
143 |
|
position:
'absolute'
|
|
|
144 |
|
});
|
|
|
145 |
|
}
|
|
|
146 |
|
|
|
|
147 |
|
if(o.zIn
dex) {
|
|
|
148 |
|
if($
(this.help
er).css("z
Index")) o
.ozIndex =
$(this.he
lper).css(
"zIndex");
|
|
|
149 |
|
$(th
is.helper)
.css('zInd
ex', o.zIn
dex);
|
|
|
150 |
|
}
|
|
|
151 |
|
|
|
|
152 |
|
that.fir
stSibling
= $(this.e
lement).pr
ev()[0];
|
|
|
153 |
|
|
|
|
154 |
|
$(this.e
lement).tr
iggerHandl
er("sortst
art", [e,
that.prepa
reCallback
Obj(this)]
, o.start)
;
|
|
|
155 |
|
$(this.e
lement).cs
s('visibil
ity', 'hid
den');
|
|
|
156 |
|
|
|
|
157 |
|
return f
alse;
|
|
|
158 |
|
|
|
|
159 |
|
},
|
|
|
160 |
|
st
op: functi
on(that, e
) {
|
|
|
161 |
|
|
|
|
162 |
|
var o =
this.optio
ns;
|
|
|
163 |
|
var self
= this;
|
|
|
164 |
|
|
|
|
165 |
|
|
|
|
166 |
|
if(o.smo
oth) {
|
|
|
167 |
|
var
os = $(thi
s.element)
.offset();
|
|
|
168 |
|
o.be
QuietAtEnd
= true;
|
|
|
169 |
|
$(th
is.helper)
.animate({
left: os.
left - o.p
o.left, to
p: os.top
- o.po.top
}, 500, s
topIt);
|
|
|
170 |
|
} else {
|
|
|
171 |
|
stop
It();
|
|
|
172 |
|
}
|
|
|
173 |
|
|
|
|
174 |
|
function
stopIt()
{
|
|
|
175 |
|
|
|
|
176 |
|
$(se
lf.element
).css('vis
ibility',
'');
|
|
|
177 |
|
if(t
hat.helper
) that.hel
per.remove
();
|
|
|
178 |
|
if(s
elf.helper
!= self.e
lement) $(
self.helpe
r).remove(
);
|
|
|
179 |
|
|
|
|
180 |
|
if(o
.ozIndex)
|
|
|
181 |
|
$(self.hel
per).css('
zIndex', o
.ozIndex);
|
|
|
182 |
|
|
|
|
183 |
|
|
|
|
184 |
|
//Le
t's see if
the posit
ion in DOM
has chang
ed
|
|
|
185 |
|
if($
(self.elem
ent).prev(
)[0] != th
at.firstSi
bling) {
|
|
|
186 |
|
//$(self.e
lement).tr
iggerHandl
er("sortup
date", [e,
that.prep
areCallbac
kObj(self,
that)], o
.update);
|
|
|
187 |
|
}
|
|
|
188 |
|
|
|
|
189 |
|
}
|
|
|
190 |
|
|
|
|
191 |
|
|
|
|
192 |
|
$(this.e
lement).tr
iggerHandl
er("sortst
op", [e, t
hat.prepar
eCallbackO
bj(this)],
o.stop);
|
|
|
193 |
|
return f
alse;
|
|
|
194 |
|
|
|
|
195 |
|
},
|
|
|
196 |
|
dr
ag: functi
on(that, e
) {
|
|
|
197 |
|
|
|
|
198 |
|
var o =
this.optio
ns;
|
|
|
199 |
|
|
|
|
200 |
|
this.pos
= [this.p
os[0]-(o.c
ursorAt.le
ft ? o.cur
sorAt.left
: 0), thi
s.pos[1]-(
o.cursorAt
.top ? o.c
ursorAt.to
p : 0)];
|
|
|
201 |
|
var nv =
$(this.e
lement).tr
iggerHandl
er("sort",
[e, that.
prepareCal
lbackObj(t
his)], o.s
ort);
|
|
|
202 |
|
var nl =
(nv && nv
.left) ? n
v.left :
this.pos[0
];
|
|
|
203 |
|
var nt =
(nv && nv
.top) ? nv
.top : th
is.pos[1];
|
|
|
204 |
|
|
|
|
205 |
|
|
|
|
206 |
|
var m =
that.set;
|
|
|
207 |
|
var p =
this.pos[1
];
|
|
|
208 |
|
|
|
|
209 |
|
for(var
i=0;i<m.le
ngth;i++)
{
|
|
|
210 |
|
|
|
|
211 |
|
var
ci = $(m[i
][0]); var
cio = m[i
][0];
|
|
|
212 |
|
if(t
his.elemen
t.contains
(cio)) con
tinue;
|
|
|
213 |
|
var
cO = ci.of
fset(); //
TODO: Cach
ing
|
|
|
214 |
|
cO =
{ top: cO
.top, left
: cO.left
};
|
|
|
215 |
|
|
|
|
216 |
|
var
mb = funct
ion(e) { i
f(true ||
o.lba != c
io) { ci.b
efore(e);
o.lba = ci
o; } }
|
|
|
217 |
|
var
ma = funct
ion(e) { i
f(true ||
o.laa != c
io) { ci.a
fter(e); o
.laa = cio
; } }
|
|
|
218 |
|
|
|
|
219 |
|
if(o
.floating)
{
|
|
|
220 |
|
|
|
|
221 |
|
var overla
p = ((cO.l
eft - (thi
s.pos[0]+(
this.optio
ns.po ? th
is.options
.po.left :
0)))/this
.helper.of
fsetWidth)
;
|
|
|
222 |
|
|
|
|
223 |
|
if(!(cO.to
p < this.p
os[1]+(thi
s.options.
po ? this.
options.po
.top : 0)
+ cio.offs
etHeight/2
&& cO.top
+ cio.off
setHeight
> this.pos
[1]+(this.
options.po
? this.op
tions.po.t
op : 0) +
cio.offset
Height/2))
continue;
|
|
|
224 |
|
|
|
|
225 |
|
} el
se {
|
|
|
226 |
|
|
|
|
227 |
|
var overla
p = ((cO.t
op - (this
.pos[1]+(t
his.option
s.po ? thi
s.options.
po.top : 0
)))/this.h
elper.offs
etHeight);
|
|
|
228 |
|
|
|
|
229 |
|
if(!(cO.le
ft < this.
pos[0]+(th
is.options
.po ? this
.options.p
o.left : 0
) + cio.of
fsetWidth/
2 && cO.le
ft + cio.o
ffsetWidth
> this.po
s[0]+(this
.options.p
o ? this.o
ptions.po.
left : 0)
+ cio.offs
etWidth/2)
) continue
;
|
|
|
230 |
|
|
|
|
231 |
|
}
|
|
|
232 |
|
|
|
|
233 |
|
if(o
verlap >=
0 && overl
ap <= 0.5)
{ //Overl
apping at
top
|
|
|
234 |
|
ci.prev().
length ? m
a(this.ele
ment) : mb
(this.elem
ent);
|
|
|
235 |
|
}
|
|
|
236 |
|
|
|
|
237 |
|
if(o
verlap < 0
&& overla
p > -0.5)
{ //Overla
pping at b
ottom
|
|
|
238 |
|
ci.next()[
0] == this
.element ?
mb(this.e
lement) :
ma(this.el
ement);
|
|
|
239 |
|
}
|
|
|
240 |
|
|
|
|
241 |
|
}
|
|
|
242 |
|
|
|
|
243 |
|
//Let's
see if the
position
in DOM has
changed
|
|
|
244 |
|
if($(thi
s.element)
.prev()[0]
!= that.l
astSibling
) {
|
|
|
245 |
|
$(th
is.element
).triggerH
andler("so
rtchange",
[e, that.
prepareCal
lbackObj(t
his, that)
], this.op
tions.chan
ge);
|
|
|
246 |
|
that
.lastSibli
ng = $(thi
s.element)
.prev()[0]
;
|
|
|
247 |
|
}
|
|
|
248 |
|
|
|
|
249 |
|
if(that.
helper) {
//repositi
on helper
if availab
le
|
|
|
250 |
|
var
to = $(thi
s.element)
.offset();
|
|
|
251 |
|
that
.helper.cs
s({
|
|
|
252 |
|
top: to.to
p+'px',
|
|
|
253 |
|
left: to.l
eft+'px'
|
|
|
254 |
|
});
|
|
|
255 |
|
}
|
|
|
256 |
|
|
|
|
257 |
|
$(this.h
elper).css
('left', n
l+'px').cs
s('top', n
t+'px'); /
/ Stick th
e helper t
o the curs
or
|
|
|
258 |
|
return f
alse;
|
|
|
259 |
|
|
|
|
260 |
|
}
|
|
|
261 |
|
});
|
|
|
262 |
|
|
|
|
263 |
|
})($);
|