提交 | 用户 | age
|
25ab64
|
1 |
// ----------------------------------------------------------------------------------------------------------- |
F |
2 |
// Functions for responsive design |
|
3 |
// ----------------------------------------------------------------------------------------------------------- |
|
4 |
TGP.ApplyMedia = function(){ } |
|
5 |
// ----------------------------------------------------------------------------------------------------------- |
|
6 |
MS.Media; |
|
7 |
// ----------------------------------------------------------------------------------------------------------- |
|
8 |
// Applies actual media rules for the grid |
|
9 |
// media can be "print" or "export" |
|
10 |
TGP.ApplyMedia = function(norender,media,recur){ |
|
11 |
var MM = this.Media; if(!MM.length||this.Hidden||this.EditMode) return; |
|
12 |
if(Grids.OnMediaApply && Grids.OnMediaApply(this,this.Loading)) return 0; |
|
13 |
if(!media&&this.Print) media = "print"; |
|
14 |
|
|
15 |
var D = {}, chg = 0, alt = this.Alternate, U = Grids.OnMediaUse!=null, osize = this.Size, MA = this.MediaAttrs, omaxheight = this.MaxHeight; if(MA) MA = MA.split(","); |
|
16 |
|
|
17 |
for(var i=0;i<MM.length;i++){ |
|
18 |
var M = MM[i], A = M.Attrs, N = M.Media; |
|
19 |
|
|
20 |
var no = (A && ( |
|
21 |
N && (A.MaxWidth&&(N.Width>A.MaxWidth||!N.Width||media) || A.MinWidth&&(N.Width<A.MinWidth||media) || A.Width&&(N.Width!=A.Width||media) |
|
22 |
|| A.MaxHeight&&(N.Height>A.MaxHeight||!N.Height||media) || A.MinHeight&&(N.Height<A.MinHeight||media) || A.Height&&(N.Height!=A.Height||media)) |
|
23 |
|| A.Style&&!A.Style[this.Img.Style] || A.GanttStyle&&!A.GanttStyle[this.Img.GanttStyle] || A.Media&&media&&A.Media!=media || A.Media=="tablet"&&!Grids.Tablet&&!media || A.Media=="desktop"&&Grids.Tablet&&!media |
|
24 |
|| A.Media&&!media&&(A.Media=="print"||A.Media=="export") || A.Rtl!=null&&!A.Rtl!=!this.Rtl |
|
25 |
|| A.Size&&this.Size.search(A.Size)!=0 |
|
26 |
|| A.Language&&this.Language.search(A.Language)!=0 |
|
27 |
)); |
|
28 |
if(!no&&MA&&A) for(var j=0;j<MA.length;j++) if(A[MA[j]]!=null&&A[MA[j]]!=this[MA[j]]) { no = 1; break; } |
|
29 |
if(no ? !U||!Grids.OnMediaUse(this,M,0) : U&&Grids.OnMediaUse(this,M,1)==0) continue; |
|
30 |
for(var m in M){ |
|
31 |
if(m=="Attrs") continue; |
|
32 |
var O = D[m], Q = M[m]; if(!O) { O = {}; D[m] = O; } |
|
33 |
if(m=="Cols"||m=="Rows"||m=="Def"||m=="Lang"||m=="Pagers"){ |
|
34 |
for(var n in Q) { |
|
35 |
var OO = O[n], QQ = Q[n]; if(!OO) { OO = {}; O[n] = OO; } |
|
36 |
for(var a in QQ) OO[a] = QQ[a]; |
|
37 |
} |
|
38 |
} |
|
39 |
else for(var n in Q) O[n] = Q[n]; |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
43 |
var dw = this.Img.SpaceWidth&&!this.Loading?this.Img.SpaceWidth:1; |
|
44 |
for(var m in D){ |
|
45 |
if(m=="Attrs" || m=="Media" || m=="Grids") continue; |
|
46 |
var W = m=="Cfg"?this:this[m]; if(!W) continue; |
|
47 |
var Q = D[m]; |
|
48 |
if(m=="Cols"||m=="Rows"||m=="Def"||m=="Lang"||m=="Pagers"){ |
|
49 |
var isrow = m=="Rows", NQ = {}; |
|
50 |
for(var i=0;i<2;i++){ |
|
51 |
if(i==1) Q = NQ; |
|
52 |
for(var n in Q) { |
|
53 |
var WW = isrow ? this.GetRowById(n):W[n]; |
|
54 |
if(!WW) { |
|
55 |
if(n.charAt(0)=="*"){ |
|
56 |
var d = n.split("*"); |
|
57 |
for(var nn in W) if(W[nn][d[1]]==d[2]) NQ["#"+nn+"#"+d[1]+"#"+d[2]] = Q[n]; |
|
58 |
continue; |
|
59 |
} |
|
60 |
else if(n.charAt(0)=="#"){ |
|
61 |
WW = W[n.split("#")[1]]; if(!WW) continue; |
|
62 |
} |
|
63 |
else continue; |
|
64 |
} |
|
65 |
var QQ = Q[n]; |
|
66 |
for(var a in QQ) { |
|
67 |
if(isrow && QQ[a]==null && (a=="Visible"||a=="Expanded")) { |
|
68 |
if(WW[a]!=null && WW[a]!=WW.Def[a]) { WW[a] = WW.Def[a]; chg++; } |
|
69 |
} |
|
70 |
else if(isrow && WW.Space && a.indexOf("Left")>0 && WW.Cells.join && (","+WW.Cells.join(",")+",").indexOf(","+a+",")>=0){ |
|
71 |
var w = Math.round(QQ[a]*dw); if(WW[a+"Width"]!=w) { WW[a+"Width"] = w; chg++; } |
|
72 |
} |
|
73 |
else if(isrow && WW.Space && dw!=1 && a.indexOf("Width")>0){ |
|
74 |
var w = Math.round(QQ[a]*dw); if(WW[a]!=w) { WW[a] = w; chg++; } |
|
75 |
} |
|
76 |
else if(a=="Width"&&WW.OldWidth) { |
|
77 |
if(WW.OldWidth!=QQ[a]) WW.OldWidth = QQ[a]; |
|
78 |
} |
|
79 |
else if(WW[a]!=QQ[a]&&a!=(isrow?"id":"Name")) { WW[a] = QQ[a]; chg++; } |
|
80 |
} |
|
81 |
} |
|
82 |
} |
|
83 |
} |
|
84 |
else for(var n in Q) if(W[n]!=Q[n]) { W[n] = Q[n]; chg++; } |
|
85 |
} |
|
86 |
|
|
87 |
if(Grids.OnMediaApplied && Grids.OnMediaApplied(this,chg,this.Loading)) return 0; |
|
88 |
var DCfg = D.Cfg?D.Cfg:{}, mchg = 0; |
|
89 |
if(DCfg.MainTagHeight!=null && !(this.ResizedMain&1) && !this.MaxHeight) { this.MainTag.style.height = DCfg.MainTagHeight+"px"; this.TagHeight = DCfg.MainTagHeight; mchg |= 1; } |
|
90 |
if(DCfg.MainTagWidth!=null && !(this.ResizedMain&2)) { this.MainTag.style.width = DCfg.MainTagWidth+"px"; this.TagWidth = DCfg.MainTagWidth; mchg |= 2; } |
|
91 |
var styl = DCfg.hasOwnProperty("Style"); if(styl && !DCfg.hasOwnProperty("CSS")) { this.CSS = null; this.DialogCSS = null; } |
|
92 |
var gstyl = DCfg.hasOwnProperty("GanttStyle"); if(gstyl && !DCfg.hasOwnProperty("GanttCSS")) this.GanttCSS = null; |
|
93 |
var rtl = DCfg.hasOwnProperty("Rtl"), size = DCfg.hasOwnProperty("Size"), scale = DCfg.hasOwnProperty("Scale"); |
|
94 |
if(size){ var S = ParseObject(this.Sizes); if(S[this.Size]) this.Size = S[this.Size]; if(osize==this.Size) { size = 0; if(DCfg.Size!=this.Size) chg--; } } |
|
95 |
MS.Group; if(this.Group&&this.Grouped&&this.MainCol&&this.Cols[this.MainCol]&&this.Cols[this.MainCol].GroupWidth) this.UpdateGroupCol(); ME.Group; |
|
96 |
if(alt&&!this.Alternate){ this.Alternate = 1e16; this.ReColor(); this.Alternate = 0; } |
|
97 |
var max = null; |
|
98 |
if(DCfg.NoVScroll){ if(this.MaxHeight) { this.ScrollMediaMaxHeight = 1; max = 0; } } |
|
99 |
else if(this.ScrollMediaMaxHeight) { this.ScrollMediaMaxHeight = null; max = 1; } |
|
100 |
else if(omaxheight!=this.MaxHeight) max = this.MaxHeight; |
|
101 |
if(max!=null) { this.SetMaxHeight(max,1); chg = 1; } |
|
102 |
this.ScrollMedia = (DCfg.NoHScroll?2:0) + (DCfg.NoVScroll?1:0); |
|
103 |
if(this.WinScrollMainTag){ |
|
104 |
if(this.NoHScroll==null) { this.SetNoHScroll(1); chg--; } |
|
105 |
if(this.NoVScroll==null) { this.SetNoVScroll(1); chg--; } |
|
106 |
} |
|
107 |
if(!norender&&chg){ |
|
108 |
if(!this.Loading&&this.MediaChange){ |
|
109 |
this.UpdateMediaTag(); |
|
110 |
|
|
111 |
if(this.MediaMainHeight!=null && (DCfg.hasOwnProperty("NoVScroll")||DCfg.hasOwnProperty("MaxVScroll")||DCfg.hasOwnProperty("MaxHeight")||DCfg.hasOwnProperty("MainTagHeight")) && DCfg.MainTagHeight==null && this.MainTag.style.height!=this.MediaMainHeight && !(this.ResizedMain&1) && (!this.MaxHeight||DCfg.hasOwnProperty("MaxHeight"))) { |
|
112 |
this.MainTag.style.height = this.MediaMainHeight; this.TagHeight = this.MainTag.offsetHeight; |
|
113 |
mchg |= 1; |
|
114 |
} |
|
115 |
if(this.MediaMainWidth!=null && (DCfg.hasOwnProperty("NoHScroll")||DCfg.hasOwnProperty("MaxHScroll")||DCfg.hasOwnProperty("MaxWidth")||DCfg.hasOwnProperty("MainTagWidth")) && DCfg.MainTagWidth==null && this.MainTag.style.width!=this.MediaMainWidth && !(this.ResizedMain&2)) { |
|
116 |
this.MainTag.style.width = this.MediaMainWidth; this.TagWidth = this.MainTag.offsetWidth; |
|
117 |
mchg |= 2; |
|
118 |
} |
c35f05
|
119 |
if(size) for(var i=0;i<MM.length;i++) if(MM[i].Attrs&&MM[i].Attrs.Size) mchg |= 4; |
25ab64
|
120 |
if(mchg&&!recur) { |
F |
121 |
var M = Grids.MediaObjects["MT_"+this.id], MM = Grids.MediaObjects["MT2_"+this.id];; |
|
122 |
if(M||MM){ |
|
123 |
if(M){ var w = M.Width, h = M.Height; if(mchg&1) M.Height = this.TagHeight; if(mchg&2) M.Width = this.TagWidth; } |
|
124 |
if(MM){ var ww = MM.Width, hh = MM.Height; if(mchg&1) MM.Height = this.TagHeight; if(mchg&2) MM.Width = this.TagWidth; } |
|
125 |
var ret = this.ApplyMedia(1,media,1); |
|
126 |
if(M) { M.Width = w; M.Height = h; } |
c35f05
|
127 |
if(MM) { MM.Width = ww; MM.Height = hh; this.UpdateMediaTag(); } |
25ab64
|
128 |
if(ret==3) styl = 1; else if(ret==2) size = 1; |
F |
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
this.CalculateSpaces(); |
|
133 |
if(styl||gstyl||rtl) { |
|
134 |
this.SetStyle(null,null,null,null,null,1,3,0,1); |
|
135 |
} |
|
136 |
else { |
|
137 |
MS.Sync; if(scale) for(var i=0,M=this.GetSyncStyle();i<M.length;i++) M[i].SetScale(this.Scale,0,1); ME.Sync; |
|
138 |
if(size){ |
|
139 |
this.MeasureHTML(); if(this.Gantt) this.MeasureGanttHTML(); this.AfterSetStyle(1); |
|
140 |
MS.Sync; for(var i=0,M=this.GetSyncStyle();i<M.length;i++) M[i].SetSize(this.Size,0,1); ME.Sync; |
|
141 |
} |
|
142 |
else if(this.MediaChange&1) { if(this.Gantt) this.RefreshGantt(254); this.Render(); } |
|
143 |
if(this.MediaChange&2 || BIPAD&&this.MediaChange&1) this.Update(); |
|
144 |
} |
|
145 |
} |
|
146 |
else if(styl||gstyl||rtl) this.SetStyle(null,null,null,null,null,!this.Loading,3,0,1); |
|
147 |
else if(size){ |
|
148 |
this.MeasureHTML(); if(this.Gantt) this.MeasureGanttHTML(); |
|
149 |
MS.Sync; for(var i=0,M=this.GetSyncStyle();i<M.length;i++) M[i].SetSize(this.Size,0,1); ME.Sync; |
|
150 |
} |
|
151 |
else if(scale){ MS.Sync; for(var i=0,M=this.GetSyncStyle();i<M.length;i++) M[i].SetScale(this.Scale,0,1); ME.Sync; } |
|
152 |
} |
|
153 |
if(DCfg.hasOwnProperty("NoTreeLines")||rtl){ |
|
154 |
var I = this.Img; |
|
155 |
I.Line = this.NoTreeLines||this.Rtl ? I.LineN : I.LineL; |
|
156 |
I.Tree = this.NoTreeLines||this.Rtl ? I.TreeN : I.TreeL; |
|
157 |
} |
|
158 |
return !chg ? 0 : styl||gstyl||rtl ? 3 : size ? 2 : 1; |
|
159 |
} |
|
160 |
// ----------------------------------------------------------------------------------------------------------- |
|
161 |
// Saves all attribute in all media to the first media with default values |
|
162 |
TGP.DefaultMedia = function(){ |
|
163 |
if(this.Hidden) return; |
|
164 |
if(Grids.OnMediaInit) Grids.OnMediaInit(this,this.Media); |
|
165 |
var MM = this.Media; if(!MM.length) return; |
|
166 |
for(var i=0,N={},has=0,NN=[];i<MM.length;i++){ |
|
167 |
var A = MM[i].Attrs; if(!A || A.Updated) continue; |
|
168 |
A.Updated = 1; |
|
169 |
NN[NN.length] = MM[i]; |
|
170 |
if(A.Def) { MM[i].Default = A.Def; delete A.Def; } |
|
171 |
if(A.Default) { MM[i].Default = A.Default; delete A.Default; } |
|
172 |
if(A.Media) A.Media = (A.Media+"").toLowerCase(); |
|
173 |
if(MM[i].Default) has = 1; |
|
174 |
if(A.Name){ |
|
175 |
N[A.Name] = MM[i]; |
|
176 |
var del = 1; for(var n in A) if(n!="Name"&&(n!="Media"||A.Media!="none")) { del = 0; break; } |
|
177 |
if(del) MM.splice(i--,1); |
|
178 |
} |
|
179 |
if(A.Style && typeof(A.Style)!="object") { |
|
180 |
var s = A.Style.split(","); A.Style = {}; |
|
181 |
for(var j=0;j<s.length;j++) A.Style[s[j]] = 1; |
|
182 |
} |
|
183 |
if(A.GanttStyle && typeof(A.GanttStyle)!="object") { |
|
184 |
var s = A.GanttStyle.split(","); A.GanttStyle = {}; |
|
185 |
for(var j=0;j<s.length;j++) A.GanttStyle[s[j]] = 1; |
|
186 |
} |
|
187 |
if(A.Size && typeof(A.Size)!="object") A.Size = new RegExp(A.Size.replace(/\,/g,"|")); |
|
188 |
if(A.Language && typeof(A.Language)!="object") A.Language = new RegExp(A.Language.replace(/\,/g,"|")); |
|
189 |
} |
|
190 |
if(has) for(var i=0;i<MM.length;i++){ |
|
191 |
if(MM[i].Default) this.UpdateDef(MM[i],N,"Default"); |
|
192 |
} |
|
193 |
|
|
194 |
var Def = null, D = MM[0]; if(D.Attrs) { D = {}; this.Media.splice(0,0,D); } |
|
195 |
for(var i=0;i<NN.length;i++){ |
|
196 |
var M = NN[i]; |
|
197 |
for(var m in M){ |
|
198 |
if(m=="Attrs") continue; |
|
199 |
var W = m=="Cfg"?this:this[m]; if(!W) continue; |
|
200 |
var O = D[m], Q = M[m]; if(!O) { O = {}; D[m] = O; } |
|
201 |
if(m=="Cols"||m=="Rows"||m=="Def"||m=="Lang"||m=="Pagers"){ |
|
202 |
for(var n in Q) { |
|
203 |
var WW = m=="Rows" ? this.GetRowById(n):W[n]; if(!WW) continue; |
|
204 |
if(m=="Def" && !WW.Updated) { |
|
205 |
if(Def==null) { Def = {}; for(var nn in W) Def[nn] = W[nn].Def; } |
|
206 |
this.UpdateDef(WW,W,"Def"); |
|
207 |
} |
|
208 |
var OO = O[n], QQ = Q[n]; if(!OO) { OO = {}; O[n] = OO; } |
|
209 |
for(var a in QQ) if(OO[a]==null) OO[a] = WW[a]; |
|
210 |
} |
|
211 |
} |
|
212 |
else for(var n in Q) if(O[n]==null) O[n] = W[n]; |
|
213 |
} |
|
214 |
} |
|
215 |
if(Def!=null) for(var n in Def) Def[n] = this.Def[n].Def = Def[n]; |
|
216 |
if(D.Cfg){ |
|
217 |
if(D.Cfg.hasOwnProperty("NoVScroll")||D.Cfg.hasOwnProperty("MaxVScroll")||D.Cfg.hasOwnProperty("MaxHeight")||D.Cfg.hasOwnProperty("MainTagHeight")) this.MediaMainHeight = this.MainTag.style.height; |
|
218 |
if(D.Cfg.hasOwnProperty("NoHScroll")||D.Cfg.hasOwnProperty("MaxHScroll")||D.Cfg.hasOwnProperty("MaxWidth")||D.Cfg.hasOwnProperty("MainTagWidth")) this.MediaMainWidth = this.MainTag.style.width; |
|
219 |
} |
|
220 |
} |
|
221 |
// ----------------------------------------------------------------------------------------------------------- |
|
222 |
TGP.SetMediaTag = function(always){ |
|
223 |
var NN = this.Media, GM = Grids.MediaObjects, AL = always ? {} : null; if(!GM){ GM = {}; Grids.MediaObjects = GM; } |
|
224 |
for(var i=NN[0]&&!NN[0].Attrs?1:0;i<NN.length;i++){ |
|
225 |
var M = NN[i], tag = M.Attrs ? M.Attrs.Tag : null, spec = 0, name = ""; if(tag==null) tag = this.MediaTag; |
|
226 |
if(tag==1) { name = "MT_"+this.id; tag = this.MainTag; } |
|
227 |
else if(tag==2) { name = "MT2_"+this.id; tag = this.MainTag; spec = 1; } |
|
228 |
else if(tag) { name = tag; tag = GetElem(tag); if(!tag) name = ""; } |
|
229 |
if(!GM[name]||AL&&!AL[name]){ |
|
230 |
if(!tag) GM[name] = { Width:window.innerWidth, Height:window.innerHeight }; |
|
231 |
else if(tag.clientHeight) GM[name] = { Tag:tag, Width:tag.clientWidth, Height:tag.clientHeight }; |
|
232 |
else GM[name] = { Tag:tag, Width:tag.offsetWidth, Height:tag.offsetHeight }; |
|
233 |
GM[name].Grids = {}; |
|
234 |
if(spec) { GM[name].WW = this.NoHScroll ? window.innerWidth : 0; GM[name].WH = this.NoVScroll ? window.innerHeight : 0; } |
|
235 |
if(AL) AL[name] = 1; |
|
236 |
} |
|
237 |
GM[name].Grids[this.Index] = 1; |
|
238 |
M.Media = GM[name]; |
|
239 |
} |
|
240 |
} |
|
241 |
// ----------------------------------------------------------------------------------------------------------- |
|
242 |
// Returns given tag of default media |
|
243 |
TGP.UpdateMedia = function(tag,attr,value,subtag,media){ |
|
244 |
var MM = this.Media, D = null, U = Grids.OnMediaUse!=null; if(!MM.length) return; |
|
245 |
var MA = this.MediaAttrs; if(MA) MA = MA.split(","); |
|
246 |
if(!media&&this.Print) media = "print"; |
|
247 |
for(var i=0;i<MM.length;i++){ |
|
248 |
var M = MM[i], A = M.Attrs, N = M.Media; |
|
249 |
|
|
250 |
M = M[tag]; if(!M) continue; |
|
251 |
if(subtag) { M = M[subtag]; if(!M) continue; } |
|
252 |
if(M[attr]==null) continue; |
|
253 |
var no = (A && ( |
|
254 |
N && (A.MaxWidth&&(N.Width>A.MaxWidth||!N.Width||media) || A.MinWidth&&(N.Width<A.MinWidth||media) || A.Width&&(N.Width!=A.Width||media) |
|
255 |
|| A.MaxHeight&&(N.Height>A.MaxHeight||!N.Height||media) || A.MinHeight&&(N.Height<A.MinHeight||media) || A.Height&&(N.Height!=A.Height||media)) |
|
256 |
|| A.Style&&!A.Style[this.Img.Style] || A.GanttStyle&&!A.GanttStyle[this.Img.GanttStyle] || A.Media&&media&&A.Media!=media || A.Media=="tablet"&&!Grids.Tablet&&!media || A.Media=="desktop"&&Grids.Tablet&&!media |
|
257 |
|| A.Media&&!media&&(A.Media=="print"||A.Media=="export") || A.Rtl!=null&&!A.Rtl!=!this.Rtl |
|
258 |
|| A.Size&&this.Size.search(A.Size)!=0 |
|
259 |
|| A.Language&&this.Language.search(A.Language)!=0 |
|
260 |
)); |
|
261 |
if(!no&&MA&&A) for(var j=0;j<MA.length;j++) if(A[MA[j]]!=null&&A[MA[j]]!=this[MA[j]]) { no = 1; break; } |
|
262 |
if(no ? !U||!Grids.OnMediaUse(this,M,0) : U&&Grids.OnMediaUse(this,M,1)==0) continue; |
|
263 |
if(A) { M[attr] = value; D = null; } |
|
264 |
else D = M; |
|
265 |
} |
|
266 |
if(D) D[attr] = value; |
|
267 |
} |
|
268 |
// ----------------------------------------------------------------------------------------------------------- |
|
269 |
ME.Media; |
|
270 |
|
|
271 |
// ----------------------------------------------------------------------------------------------------------- |
|
272 |
// Upravi Tag=2 pri zmene NoVScroll / NoHScroll |
|
273 |
TGP.UpdateMediaTag = function(){ |
|
274 |
MS.Media; |
|
275 |
var M = Grids.MediaObjects["MT2_"+this.id]; |
|
276 |
if(M){ |
|
277 |
if(this.NoHScroll&&!M.WW) M.WW = window.innerWidth; else if(!this.NoHScroll&&M.WW) M.WW = 0; |
|
278 |
if(this.NoVScroll&&!M.WH) M.WH = window.innerHeight; else if(!this.NoVScroll&&M.WH) M.WH = 0; |
|
279 |
} |
|
280 |
ME.Media; |
|
281 |
} |
|
282 |
// ----------------------------------------------------------------------------------------------------------- |