source: temp/trunk/html/drecomcms/common.js @ 1328

Revision 1328, 11.2 KB checked in by naka, 20 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2 * ‹¤’Ê JavaScript
3 *
4 *
5 * Copyright (c) 2003 DRECOM CO.,LTD. All rights reserved.
6 *
7 * [email protected]
8 * http://www.drecom.co.jp/
9 */
10
11/**
12 * ƒuƒ‰ƒEƒU‰æ–ʗ̈æ‚Ì•‚ðŽæ“¾
13 */
14function getWidth(win)
15{
16    var tmp_width;
17   
18    if (win.document.documentElement) {
19        tmp_width = win.document.documentElement.clientWidth;
20        if (tmp_width > 0) {
21            return tmp_width;
22        }
23    }
24    if (win.document.all) {
25        tmp_width = win.document.body.clientWidth;
26        return tmp_width;
27    }
28    return win.innerWidth;
29}
30       
31/**
32 * ƒuƒ‰ƒEƒU‰æ–ʗ̈æ‚̍‚‚³‚ðŽæ“¾
33 */
34function getHeight(win)
35{
36    var tmp_height;
37   
38    if (win.document.documentElement) {
39        tmp_height = win.document.documentElement.clientHeight;
40        if (tmp_height > 0) {
41            return(tmp_height);
42        }
43    }
44    if (win.document.all) {
45        return(win.document.body.clientHeight);
46    }
47    return(win.innerHeight);
48}
49
50/**
51 * Window‚𒆐S‚Ɉړ®
52 */
53function moveWindowToCenter(win) {
54    x = (screen.width  - getWidth(win)) / 2;
55    y = (screen.height - getHeight(win)) / 2;
56    win.moveTo(x,y);
57}
58
59/**
60 * í‚ÉŽè‘O‚É•\ަ‚·‚éƒEƒBƒ“ƒhƒE‚ðŠJ‚­
61 */
62function openModalWindow(url, name, height, width, scrollbars, resizable, status)
63{
64    ModalWindow = openWindow(url, name, height, width, scrollbars, resizable, status);
65    onfocus = function onFocus(){
66        if (null !=ModalWindow && !ModalWindow.closed) {
67            try {
68                ModalWindow.focus();
69            } catch(e) {
70                document.onmousemove = null;
71            }
72        } else {
73            document.onmousemove = null;
74        }
75    }
76   
77    document.onmousemove = onfocus;
78   
79    return ModalWindow;
80}
81
82/**
83 * ƒEƒBƒ“ƒhƒE‚ðŠJ‚­
84 */
85function openWindow(url, name, height, width, scrollbars, resizable, status, left, top)
86{
87    var window_condition = "height=" + height + ",width=" + width +
88                    ((left) ? ",left=" + left : "") + ((top) ? ",top=" + top : "") +
89                    ",scrollbars=" + scrollbars + ",resizable=" + resizable + ",toolbar=no,status=" + status;
90
91    subWindow = window.open(url, name, window_condition);
92    // ƒ|ƒbƒvƒAƒbƒvƒuƒƒbƒJ[‚ȂǂŃuƒƒbƒN‚³‚ꂽê‡‚ÉJavaScriptƒGƒ‰[‚ɂȂç‚È‚¢‚悤‚É
93    if (subWindow) {
94        subWindow.focus();
95    }
96
97    return subWindow;
98}
99
100/**
101 * ƒEƒBƒ“ƒhƒE‚ðŒã‚ë‚ÉŠJ‚­
102 */
103function openWindowBack(url, name, height, width, scrollbars, resizable, status)
104{
105    var window_condition = "height=" + height + ",width=" + width +
106                    ",scrollbars=" + scrollbars + ",resizable=" + resizable + ",toolbar=no,status=" + status +
107                    ",left=" + window.screen.width;
108    subWindow = window.open(url, name, window_condition);
109    subWindow.blur();
110    window.focus();
111    subWindow.moveTo(0,0);
112    return subWindow;
113}
114
115/**
116 * EscƒL[‚ŃEƒBƒ“ƒhƒE‚ð•‚¶‚éƒCƒxƒ“ƒg
117 *
118 * ¦ƒTƒuƒEƒBƒ“ƒhƒE‚Ìonload‚Å
119 *   document.body.onkeypress = subwinCloseOnEsc;
120 * ‚̂悤‚ÉŽg‚Á‚Ä‚­‚¾‚³‚¢B
121 */
122function subwinCloseOnEsc(ev)
123{
124    ev || (ev = window.event);
125    if (ev.keyCode == 27) {
126        window.close();
127        return false;
128    }
129    return true;
130}
131
132
133
134// 2004-06-09 Takanori Ishikawa
135// -----------------------------------------------------------
136// htmlAlert(), htmlConfirm() ‚Í html ‚ð‚»‚Ì‚Ü‚Ü
137// o—Í‚¹‚¸AƒTƒjƒ^ƒCƒY‚·‚邿‚¤‚É‚µ‚½B
138
139// sanitize html message
140function sanitize_msg(msg)
141{
142    msg = msg.replace(/</g, '&lt;');
143    msg = msg.replace(/>/g, '&gt;');
144    msg = msg.replace(/&lt;br\s*&gt;/g, '<br>');
145
146    return msg;
147}
148// alert
149function htmlAlert(msg, height, width)
150{
151    height = (null == height) ? 150: height;
152    width  = (null == width) ? 300: width;
153    msg = sanitize_msg(msg);
154   
155    if (defined(window.showModalDialog)) {
156        showModalDialog("/drecomcms/html/message_box.html", sanitize_msg(msg), "dialogHeight: " + height + "px; dialogWidth: " + width + "px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");
157    } else {
158        dialogArguments = msg;
159        ModalWindow = open("/drecomcms/html/message_box.html", "sub_alert","height=" + height + ",width=" + width +
160                    ",scrollbars=no,resizable=no,toolbar=no,status=no,alwaysRaised=yes");
161        onfocus = function onFocus(){
162            if (null !=ModalWindow && !ModalWindow.closed) {
163                ModalWindow.focus();
164            }
165        }
166        document.onmousemove = onfocus;
167        return ModalWindow;
168    }
169}
170// confirm
171function htmlConfirm(msg, height, width)
172{
173    height = (null == height) ? 150: height;
174    width  = (null == width) ? 300: width;
175    if (defined(window.showModalDialog)) {
176        var value = showModalDialog("/drecomcms/html/confirm.html", sanitize_msg(msg), "dialogHeight: " + height + "px; dialogWidth: " + width + "px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");
177        if (typeof value == "undefined") {
178            value = false;
179        }
180        return value;
181    } else {
182        return window.confirm(msg.replace(/<br[^>]*\/?>/, '\n'));
183    }
184}
185
186/**
187  * —j“ú‚ðŽæ“¾‚·‚éŠÖ”
188  * year:  ”N
189  * month: ŒŽ
190  * day:   “ú
191  */
192function getDayOfWeek(year, month, day) {
193
194    DateOfWeek  = new Date();
195    DateOfWeek.setYear(year);
196    DateOfWeek.setMonth(month - 1);
197    DateOfWeek.setDate(day);
198    day_of_week_number  = DateOfWeek.getDay();
199
200    days = new Array('“ú','ŒŽ','‰Î','…','–Ø','‹à','“y');
201    return days[day_of_week_number];
202}
203
204
205// -----------------------------------------------------------
206// ƒ|[ƒ^ƒ‹Aƒwƒbƒ_
207// -----------------------------------------------------------
208/**
209 * INPUT FORM ‚Ì”wŒiF•ύX
210 */
211function focusForm(obj,flag){
212    if (obj == null || obj.style == null) {
213        return;
214    }
215    obj.style.backgroundColor = flag ? '#FFFFCC' : '#FFFFFF'
216}
217function Skinup(fnr){
218    win = window.open('/contents/skinpop_'+fnr,'skin','width=455,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes');
219    win.focus();
220}
221function imgSwap(name,gifPath) {
222    document.images[name].src = gifPath ;
223}
224
225
226// -----------------------------------------------------------
227// ‰æ‘œ
228// -----------------------------------------------------------
229/**
230 * ‰æ‘œ‚Ì•\ަƒTƒCƒY’²®
231 */
232function adjustImageSize(imgElementName, widthMax, heightMax) {
233    var imgs = document.getElementsByName(imgElementName);
234    if (imgs) {
235        if (!imgs.length) {
236            if (widthMax && imgs.width > widthMax) {
237                imgs.height = imgs.height * widthMax / imgs.width;
238                imgs.width = widthMax;
239            }
240            if (heightMax && imgs.height > heightMax) {
241                imgs.width = imgs.width * heightMax / imgs.height;
242                imgs.height = heightMax;
243            }
244        } else {
245            for (i=0; i<imgs.length; i++) {
246                if (widthMax && imgs[i].width > widthMax) {
247                    imgs[i].height = imgs[i].height * widthMax / imgs[i].width;
248                    imgs[i].width = widthMax;
249                }
250                if (heightMax && imgs[i].height > heightMax) {
251                    imgs[i].width = imgs[i].width * heightMax / imgs[i].height;
252                    imgs[i].height = heightMax;
253                }
254            }
255        }
256    }
257}
258
259/**
260 * –{•¶‚ÌHTMLƒ\[ƒX‚æ‚èŠO•”‰æ‘œURL("http://`")‚ðPickUp
261 */
262function getExternalImageList(orgHtml) {
263
264    var extImageList = new Array();
265    var list = new Array();
266    var n = 0; 
267    var exp;
268   
269    exp = new RegExp("<img [^>]*src=[\"']?http://[^\"']*[\"']?[^>]*>", 'ig');
270    list = orgHtml.match(exp);
271    if (list) {
272        for (var i = 0; i < list.length; i++) {
273            var str = "";
274            exp = new RegExp("src=[\"']?");
275            list[i].match(exp);
276            str = RegExp.rightContext;
277            exp = new RegExp("[\"'\\s>]|/>");
278            if (str) {
279                str.match(exp);
280                str = RegExp.leftContext;
281               
282                var isExist = false;
283                for (var j = 0; j < extImageList.length; j++) {
284                    if (extImageList[j] == str) { isExist = true; break; }
285                }
286                if (!isExist) { extImageList[n++] = str; }
287            }
288        }
289    }
290    return extImageList;
291}
292
293/**
294 * –{•¶‚ÌHTMLƒ\[ƒX‚æ‚èŠO•”FlashURL("http://`")‚ðPickUp
295 */
296function getExternalFlashList(orgHtml) {
297
298    var extFlashList = new Array();
299    var list = new Array();
300    var n = 0; 
301    var exp;
302
303    var flashTag = "\\{\\\$CMSInclude [^\\\$\\}]*name=\"flash\"\\s*param=\"[^\"]*Movie=http://[^\"]*\"\\s*\\\$\\}";
304    exp = new RegExp(flashTag, 'ig');   
305    list = orgHtml.match(exp);
306    if (list) {
307        for (var i = 0; i < list.length; i++) {
308            var str = "";
309            exp = new RegExp("Movie=");
310            list[i].match(exp);
311            str = RegExp.rightContext;
312            exp = new RegExp(";");
313            if (str) {
314                str.match(exp);
315                str = RegExp.leftContext;
316
317                var isExist = false;               
318                for (var j = 0; j < extFlashList.length; j++) {
319                    if (extFlashList[j] == str) { isExist = true; break; }
320                }
321                if (!isExist) { extFlashList[n++] = str; }
322            }
323        }
324    }
325    return extFlashList;
326}
327 
328/**
329 * ƒŠƒ“ƒN‚Ì‘JˆÚæ‚𖳌ø‚É‚·‚éB
330 * i<a>ƒ^ƒO‚Ìhref‘®«‚ð"javascript:void(0)"‚É’uŠ·j
331 */
332function replaceLinkInvalid(html) {
333    html = html.replace(/<a [^>]*>/ig, '<a href="javascript:void(0);">');
334    html = html.replace(/openPermLink\([^)]*\)/ig, 'void(0)');
335    return html;
336}
337
338/**
339 * URL—p‚̃GƒXƒP[ƒv‚ðs‚¢‚Ü‚·B
340 * '&' -> '&amp;'
341 * '>' -> '&gt;'
342 * '<' -> '&lt;'
343 * '"' -> '&quot;'
344 * —¼’[‚Ì‹ó”’‚Í Trim
345 * ' ' -> '%20'
346 * @param src ‘Ώە¶Žš—ñ
347 */
348function /*: String :*/ escapeUrl(/*: String :*/ src) {
349    var s = replaceAll(src, '&', '&amp;');
350    s = replaceAll(s, '>', '&gt;');
351    s = replaceAll(s, '<', '&lt;');
352    s = replaceAll(s, '"', '&quot;');
353    s = trim(s);
354    s = replaceAll(s, ' ', '%20');
355    return s;
356}
357function /*: String :*/ escapeScript(/*: String :*/ src) {
358    var s = replaceAll(src, "\\", "\\\\");
359    s = replaceAll(s, "'", "\\'");
360    s = replaceAll(s, "\"", "\\\"");
361    return s;
362}
363/**
364 * •¶Žš—ñ‚Ì‘S’uŠ·‚ðs‚¢‚Ü‚·B
365 * @param src ‘Ώە¶Žš—ñ
366 * @param oldc ‹Œ•¶Žš—ñ
367 * @param newc V•¶Žš—ñ
368 */
369function /*: String :*/ replaceAll(/*: String :*/src, /*: String :*/oldc, /*: String :*/newc) {
370 var h = "";
371 var b = src;
372 var index = 0;
373 while (true) {
374  index = b.indexOf(oldc, 0);
375  if (index == -1) {
376   break;
377  }
378  src = b.replace(oldc, newc);
379  h += src.substring(0, index + newc.length);
380  b = src.substring(index + newc.length, src.length);
381 }
382 return h + b;
383}
384/**
385 * —¼’[‚Ì”¼Šp/‘SŠpƒXƒy[ƒX‚ðŽæ‚èœ‚«‚Ü‚·B
386 * @param src ‘Ώە¶Žš—ñ
387 */
388function /*: String :*/ trim(/*: String :*/src ) {
389    var s = trimR(src);
390    return trimL(s);
391}
392/**
393 * ‰E’[‚Ì”¼Šp/‘SŠpƒXƒy[ƒX‚ðŽæ‚èœ‚«‚Ü‚·B
394 * @param src ‘Ώە¶Žš—ñ
395 */
396function /*: String :*/ trimR(/*: String :*/src) {
397    var nLoop = 0;
398    var strFinal = src;
399    var strTemp = src;
400    while (nLoop < strTemp.length) {
401        if ((strFinal.substring(strFinal.length - 1, strFinal.length) == " ") || (strFinal.substring(strFinal.length - 1, strFinal.length) == "@")) {
402            strFinal = strTemp.substring(0, strTemp.length - (nLoop + 1));
403        }
404        else {
405            break;
406        }
407        nLoop++;
408    }
409    return strFinal;
410}
411/**
412 * ¶’[‚Ì”¼Šp/‘SŠpƒXƒy[ƒX‚ðŽæ‚èœ‚«‚Ü‚·B
413 * @param src ‘Ώە¶Žš—ñ
414 */
415function /*: String :*/ trimL(/*: String :*/src) {
416    var nLoop = 0;
417    var strFinal = src;
418    var strTemp = src;
419    while (nLoop < strTemp.length) {
420        if ((strFinal.substring(0, 1) == " ") || (strFinal.substring(0, 1) == "@")) {
421            strFinal = strTemp.substring(nLoop + 1, strTemp.length );
422        }
423        else {
424            break;
425        }
426        nLoop++;
427    }
428    return strFinal;
429}
430
431/**
432 * Œp³
433 */
434function extend(subClass, superClass) {
435    for (var prop in superClass.prototype) {
436        subClass.prototype[prop] = superClass.prototype[prop];
437    }
438}
439
440
441/**
442 * ƒ|ƒbƒvƒAƒbƒvƒuƒƒbƒJ[‘΍ô
443 * window.onPopupBlocked,window.onPopupNonBlocked‚ðƒI[ƒo[ƒ‰ƒCƒh‚µ‚Ä‚­‚¾‚³‚¢B
444 */
445window.onPopupBlocked = function(){
446    alert('ƒEƒBƒ“ƒhƒE‚ðŠJ‚¯‚Ü‚¹‚ñ‚Å‚µ‚½Bƒ|ƒbƒvƒAƒbƒvƒuƒƒbƒJ[‚ð—LŒø‚É‚µ‚Ä‚¢‚éê‡‚́A–³Œø‚É‚µ‚Ä‚­‚¾‚³‚¢B');
447};
448
449window.onPopupNonBlocked = function(){}
450
451if (typeof window.org_open == 'undefined'){
452    window.org_open = window.open;
453    window.open = function() {
454        var win = (2 == window.open.arguments.length)
455                    ? window.org_open(window.open.arguments[0], window.open.arguments[1])
456                    : window.org_open(window.open.arguments[0], window.open.arguments[1], window.open.arguments[2]);
457        if (null == win) {
458            window.onPopupBlocked(window.open.arguments);
459        } else {
460            window.onPopupNonBlocked(window.open.arguments);
461        }
462        return win;
463    }
464}
465
466
Note: See TracBrowser for help on using the repository browser.