Mercurial > hg > mgallery
annotate mgallery.js @ 151:4e25150aa868
Change js_path configuration setting to js_file.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 06 Sep 2017 17:34:36 +0300 |
parents | b4751909c48f |
children | 606b05c31d5e |
rev | line source |
---|---|
149
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 // |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 // Yet Another Image Gallery |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 // -- Main Javascript utility functions file |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 // Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 // (C) Copyright 2015-2017 Tecnic Software productions (TNSP) |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 // |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 function mgalAddEvent(evobj, evtype, evcallback) |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 { |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 if (evobj == null || typeof(evobj) == 'undefined') |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 return; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 if (evobj.addEventListener) |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 evobj.addEventListener(evtype, evcallback, false); |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 else |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 if (evobj.attachEvent) |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 evobj.attachEvent("on" + evtype, evcallback); |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 else |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 evobj["on"+evtype] = evcallback; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 }; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 function mgalNavigateTo(url) |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 { |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 if (url != "") |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 window.location = url; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 } |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 function mgalProcessKeyPress(ev) |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 { |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 ev = ev || window.event; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 var key = ev.keyCode ? ev.keyCode : ev.which; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 switch (key) |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 { |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 case 37: |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 case 65: |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 case 52: |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 // left |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 mgalNavigateTo(mgalPrevURL); |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 break; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 case 39: |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 case 68: |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 case 54: |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 // right |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 mgalNavigateTo(mgalNextURL); |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 break; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 case 38: |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 case 56: |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 // up |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 mgalNavigateTo(mgalUpURL); |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 break; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 default: |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 return true; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 } |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 ev.preventDefault(); |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 return false; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 } |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 function mgalGetWindowSize() |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 { |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 var winW = 0, winH = 0; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 if (typeof(window.innerWidth) == 'number') |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 { |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 // Non-MSIE |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 winW = window.innerWidth; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 winH = window.innerHeight; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 } |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 else |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
76 if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 { |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 // MSIE 6+ in 'standards compliant mode' |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 winW = document.documentElement.clientWidth; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 winH = document.documentElement.clientHeight; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 } |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 else |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 if (document.body && (document.body.clientWidth || document.body.clientHeight)) |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 { |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 // MSIE 4 compatible |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 winW = document.body.clientWidth; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
87 winH = document.body.clientHeight; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
88 } |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 return [winW, winH]; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 } |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 function mgalAdjustImageDo() |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 { |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 var eimg = document.getElementById("imageImage"); |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 var win = mgalGetWindowSize(); |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 var madj = 0.92; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 if (eimg) |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 { |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 if (eimg.width > eimg.height) |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 { |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 eimg.style.width = "100%"; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 eimg.style.height = "auto"; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 if (eimg.height > win[1] * madj) |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 { |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 eimg.style.width = "auto"; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 eimg.style.height = (win[1] * madj)+"px"; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 } |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 } |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 else |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 { |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 eimg.style.width = "auto"; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 if (eimg.height > win[1] * madj) |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 eimg.style.height = (win[1] * madj)+"px"; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 else |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 eimg.style.height = "100%"; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 } |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 } |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 adjustPID = -1; |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 } |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 function mgalAdjustImage() |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 { |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 if (adjustPID == -1) |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 adjustPID = setTimeout(mgalAdjustImageDo, 50); |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 } |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 |
b4751909c48f
Move some Javascript code to a separate file and make the location configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 |