/** * User: inui@TCI * Date: 11/07/05 * Time: 11:13 * To change this template use File | Settings | File Templates. * * eventドリブンにjavascriptを書いてしまうためのutility */ /* * 名前空間の帳尻合わせ(※標準prototype拡張) */ Function.prototype.bindFunc = function (bind) { var self = this; return function () { return self.apply(bind, arguments); } } /* * curry化(※標準prototype拡張) */ Function.prototype.curry = function(t0, t1, t2, t3) { var self = this; var args = [t0]; if (typeof t1 != 'undefined') args.push(t1); if (typeof t2 != 'undefined') args.push(t2); if (typeof t3 != 'undefined') args.push(t3); return function () { return self.apply(this, args.concat(Array.prototype.slice.call(arguments))); } } Array.prototype.exists = function (factor) { var self = this; var exists = false; for (var i = 0; i < self.length; i++) { exists = (self[i] == factor) ? true : false; } return exists; } function dynamicScriptLoader (uri) { var ele = document.createElement('script'); ele.type = 'text/javascript'; ele.src = uri; ele.charset = 'UTF-8'; var target = null; var i = 0; while (target === null) { if (document.getElementsByTagName('script')[i].src.match(new RegExp("util\\.js"))) { target = document.getElementsByTagName('script')[i]; } i++; } //var target = document.getElementsByTagName('script')[0]; target.parentElement.insertBefore(ele, target.nextSibling); //target.parentElement.insertBefore(ele, target); } /* * Registers function +fn+ will be executed when the dom * tree is loaded without waiting for images. * * Example: * * Event.domReady.add(function() { * ... * }); * */ if (typeof Event == 'undefined') Event = new Object(); Event.domReady = { add: function(fn) { //----------------------------------------------------------- // Already loaded? //----------------------------------------------------------- if (Event.domReady.loaded) return fn(); //----------------------------------------------------------- // Observers //----------------------------------------------------------- var observers = Event.domReady.observers; if (!observers) observers = Event.domReady.observers = []; // Array#push is not supported by Mac IE 5 observers[observers.length] = fn; //----------------------------------------------------------- // domReady function //----------------------------------------------------------- if (Event.domReady.callback) return; Event.domReady.callback = function() { if (Event.domReady.loaded) return; Event.domReady.loaded = true; if (Event.domReady.timer) { clearInterval(Event.domReady.timer); Event.domReady.timer = null; } var observers = Event.domReady.observers; for (var i = 0, length = observers.length; i < length; i++) { var fn = observers[i]; observers[i] = null; fn(); // make 'this' as window } Event.domReady.callback = Event.domReady.observers = null; }; //----------------------------------------------------------- // Emulates 'onDOMContentLoaded' //----------------------------------------------------------- var ie = !!(window.attachEvent && !window.opera); var webkit = navigator.userAgent.indexOf('AppleWebKit/') > -1; if (document.readyState && webkit) { // Apple WebKit (Safari, OmniWeb, ...) Event.domReady.timer = setInterval(function() { var state = document.readyState; if (state == 'loaded' || state == 'complete') { Event.domReady.callback(); } }, 50); } else if (document.readyState && ie) { // Windows IE var src = (window.location.protocol == 'https:') ? '://0' : 'javascript:void(0)'; document.write( ' * の?以下を取得して、「=」の前がlabel 後ろがvalueのobjectを生成 * var srcParam = new ScriptSrcParam(); * srcParam.execute('main.js'); * srcParam.get('load'); -> effects */ var ScriptSrcParam = function () { this.initialize.apply(this, arguments); } ScriptSrcParam.prototype = { initialize: function () { this._param = {}; }, execute: function (jsName) { var scripts = document.getElementsByTagName('script'); var script; for (var i = 0; i < scripts.length; i++) { var s = scripts.item(i); if(s.src.indexOf(jsName) != -1 ) { script = s; break; } } if (script) { script.src.match(/.*?\?(.*)/); if(RegExp.$1) { var a = RegExp.$1.split('&'); if (a) { for (var i = 0; i < a.length; i++) { var p = a[i].split('='); if (p[0]) { if (p.length > 2) { var tmp = ''; for (var j = 1; j < p.length; j++) { tmp += (j % 2 == 0) ? p[j] : p[j]+'='; } p[1] = tmp; } this._param[p[0]] = p[1]; } } } } } }, get: function (name) { return this._param[name]; } } /** * 自らのURIから URI引数を取得する。 * http://local.host/dev/null.html?load=effects * の?以下を取得して、「=」の前がlabel 後ろがvalueのobjectを生成 */ var UriParam = function () { this.initialize.apply(this, arguments); } UriParam.prototype = { initialize: function () { this._param = {}; }, execute: function () { if (document.location.toString().match(new RegExp('^.+?\\?(.+)$'))) { var paramList = RegExp.$1.split('&'); for (var i = 0; i < paramList.length; i++) { var tmp = paramList[i].split('='); this._param[tmp[0]] = tmp[1]; } } }, get: function (name) { return this._param[name]; } } /* * debag */ var ObjectInspector = function () { this.initialize.apply(this, arguments); } ObjectInspector.prototype = { initialize: function () { this.str = ''; }, inspect: function (elm, type) { this.str = '「' + typeof elm + "」の中身"; var cnt = 0; for (i in elm) { if(type == 'html'){ this.str += '
\n' + "[" + cnt + "] " + i.bold() + ' = ' + elm[i]; } else { this.str += '\n' + "[" + cnt + "] " + i + ' = ' + elm[i]; } cnt++; status = cnt; } if (type == 'html') { var swElm = document.getElementById('subwindow'); var scElm = document.getElementById('sub_contents'); scElm.innerHTML = this.str; swElm.style.display = 'block'; } else { return this.str; } } } /* * ブラウザのdefault eventをインターセプト */ var DefaultEventInterceptor = function () { this.initialize.apply(this, arguments); } DefaultEventInterceptor.prototype = { initialize: function () { }, execute: function (e) { if(e.preventDefault) { e.preventDefault(); e.stopPropagation(); } else if(e) { e.returnValue = false; } else if(window.event.cancelBubble) { window.event.returnValue = false; window.event.cancelBubble = true; } } } /* * カスタムイベント関連 * http://www.fladdict.net/blog-jp/archives/2005/06/javascript.php * //hogeオブジェクト * function hoge(){ * //hogeインスタンスに、イベント通知機能を実装 * new EventDispatcher(this); * } * * hoge.prototype.doSomething = function(){ * //doSomethingを実行したらイベントを通知 * this.dispatchEvent({type:"onSomething", target:this}); * } * * var h = new hoge(); // イベント機能つきhogeインスタンス作成。 * var listener = new Object(); * //イベントハンドラ * listener.onSomething = function(e){ * alert("event受信 " + e.type); * } * * h.addEventListener("onSomething", listener); * * h.doSomething(); //doSomething実行のラストでイベントが発行される。 */ var EventDispatcher = function () { this.initialize.apply(this, arguments); } EventDispatcher.prototype = { initialize: function (obj) { obj.__ed_eventContainer = new Object(); obj.addEventListener = this._addEventListener; obj.removeEventListener = this._removeEventListener; obj.dispatchEvent = this._dispatchEvent; }, _addEventListener: function (eventName, object) { if(this.__ed_eventContainer[eventName] == null) { this.__ed_eventContainer[eventName] = new Array(); } this.removeEventListener(eventName, object); this.__ed_eventContainer[eventName].push(object); //register object }, _removeEventListener: function (eventName, object) { var listener_ar = this.__ed_eventContainer[eventName]; if(listener_ar == undefined) return; var imax = listener_ar.length; for(var i = 0; i < imax; i++) { var listener = listener_ar[i]; if(listener == object) { listener_ar.splice(i, 1); return; } } }, _dispatchEvent: function(eventObj) { if(eventObj.target == null) eventObj.target = this; var eventName = eventObj.type; if(this.__ed_eventContainer[eventName] == null) return; var imax = this.__ed_eventContainer[eventName].length; for(var i=0; i < imax; i++) { var listener = this.__ed_eventContainer[eventName][i]; if(typeof(listener) == "object"){ listener[eventName].apply(listener, new Array(eventObj)); return; }else{ listener(eventObj); return; } } } } var UsrEventHandler = function () { this.initialize.apply(this, arguments); } UsrEventHandler.prototype = { initialize: function () { this._evtName = ''; this._obj = null; }, set: function (obj) { this._obj = obj; var msecNow = (new Date()).getTime(); var num = msecNow - Math.random(); this._evtName = 'dom:UsrEvent'+String(num); return this._evtName; }, fire: function() { this._obj.dispatchEvent({type: this._evtName, target: this._obj}); } } /* * EventListenerの登録 */ var EventListenerAttacher = function () { this.initialize.apply(this, arguments); } EventListenerAttacher.prototype = { initialize: function () { }, attachClickListenerByName: function (name, listener, obj) { var elements = document.getElementsByName(name); for (var i = 0; i < elements.length; i++) { if (document.addEventListener) { //elements[i].addEventListener("click", listener.bindFunc(obj), false); elements[i].onclick = listener.bindFunc(obj); } else { //elements[i].attachEvent("onclick", listener.bindFunc(obj)); elements[i].onclick = listener.curry(event).bindFunc(obj); } } }, attachClickListenerByClassName: function (name, listener, obj) { var elements = document.getElementsByClassName(name); for (var i = 0; i < elements.length; i++) { if (document.addEventListener) { //elements[i].addEventListener("click", listener.bindFunc(obj), false); elements[i].onclick = listener.bindFunc(obj); } else { //elements[i].attachEvent("onclick", listener.bindFunc(obj)); elements[i].onclick = listener.curry(event).bindFunc(obj); } } }, attachClickListenerById: function (id, listener, obj) { var element = document.getElementById(id); if (element == null) alert('attachClickListenerById'+"\n"+'['+id+']::指定したidは存在しません!'); if (document.addEventListener) { //element.addEventListener("click", listener.bindFunc(obj), false); element.onclick = listener.bindFunc(obj); } else { //element.attachEvent("onclick", listener.bindFunc(obj)); element.onclick = listener.curry(event).bindFunc(obj); } }, attachChangeListenerById: function (id, listener, obj) { var element = document.getElementById(id); if (document.addEventListener) { element.addEventListener("change", listener.bindFunc(obj), false); } else { element.attachEvent("onchange", listener.bindFunc(obj)); } //element.onchange = listener.bindFunc(obj); } } var EventListenerRemover = function () { this.initialize.apply(this, arguments); } EventListenerRemover.prototype = { initialize: function () { }, removeClickListenerByName: function (name, listener, obj) { var elements = document.getElementsByName(name); for (var i = 0; i < elements.length; i++) { elements[i].onclick = null; } }, removeClickListenerByClassName: function (name, listener, obj) { var elements = document.getElementsByClassName(name); for (var i = 0; i < elements.length; i++) { elements[i].onclick = listener.bindFunc(obj); } }, removeClickListenerById: function (id, listerner, obj) { var element = document.getElementById(id); /*if (document.removeEventListener) { element.removeEventListener("click", listerner.bindFunc(obj), false); } else { element.detachEvent("onclick", listerner.bindFunc(obj)); }*/ element.onclick = null; } } /* * 非同期通信 */ var RequestObj = function () { this.initialize.apply(this, arguments); } RequestObj.prototype = { initialize: function (uri, method) { method = (method) ? method : 'GET'; this._attrs = { uri: uri , charaCode: 'UTF-8' , method: method , param: null , exists: false , receive: '' , time: '' }; }, get: function (label) { return this._attrs[label]; }, set: function (label, value) { if (label == 'param') value = this._convertParam(value); this._attrs[label] = value; }, _convertParam: function (value) { if (value instanceof Object) { var tmp = ''; var i = 0; for (label in value) { if (i == 0) { tmp = label+'='+value[label]; } else { tmp += '&'+label+'='+value[label]; } i++; } value = tmp; } return value; } } var HttpRequest = function () { this.initialize.apply(this, arguments); } HttpRequest.prototype = { initialize: function () { new EventDispatcher(this); this._httpObj = null; this._reqObj = null; this._usrEvt = null; try { this._httpObj = new XMLHttpRequest(); } catch(e) { try { this._httpObj = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { this._httpObj = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { return null; } } } }, execute: function(reqObj, usrEvt) { this._reqObj = reqObj; if (typeof usrEvt != 'undefined') this._usrEvt = usrEvt; this._httpObj.abort(); // 再利用する際は最初にabort呼ばないと、うまく動かない。 this._request(); }, _request: function() { this._httpObj.onreadystatechange = this._processResponse.bindFunc(this); this._httpObj.open(this._reqObj.get('method'), this._reqObj.get('uri'), false); if (this._reqObj.get('method').toUpperCase() == 'POST') { var msec = (new Date()).getTime(); var param = (this._reqObj.get('param')) ? this._reqObj.get('param')+"&cache="+msec+"&ajaxreq=yes" : "cache="+msec+"&ajaxreq=yes"; this._httpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8"); //this._reqObj.get('charaCode') try { this._httpObj.send(param); } catch(e) { this._httpObj.status = 404; this._httpObj.readyState = 4; this._processResponse(); } } else { try { this._httpObj.send(param); } catch(e) { this._httpObj.status = 404; this._httpObj.readyState = 4; this._processResponse(); } } }, _processResponse: function () { if (this._httpObj.readyState == 4) { if (this._httpObj.status == 200 || this._httpObj.status == 201) { this._reqObj.set('reqStatus', 'ok'); this._reqObj.set('receive', this._httpObj.responseText); this._reqObj.set('time', this._httpObj.getResponseHeader('Date')); if (this._usrEvt != null) this._usrEvt.fire(); } else { this._reqObj.set('reqStatus', 'ng'); this._reqObj.set('receive', "エラーで読み込めませんでした"); this._reqObj.set('time', this._httpObj.getResponseHeader('Date')); if (this._usrEvt != null) this._usrEvt.fire(); } } } } /* * cookie読み書き * expireは分単位で */ var CookieManager = function () { this.initialize.apply(this, arguments); } CookieManager.prototype = { initialize: function (ckname, expire, domain) { document.location.toString().match(/^https*:\/\/(.+?)\/.*$/); this._attrs = { name: (typeof ckname == 'undefined') ? 'defaultCookieName' : ckname , expire: (typeof expire == 'undefined') ? 0 : expire , domain: (typeof domain != 'undefined') ? domain : RegExp.$1 , values: [] } }, setCookie: function (values) { if (typeof values != 'undefined') this.set('values', values); var expire = new Date(); expire.setTime(expire.getTime()+1000*60*this.get('expire')); // JavaScriptの時間単位は1/1000秒 var ckstr = ''; for (var i = 0; i < values.length; i++) { // デリミタ %00(null)にてuri_escapeしながらimplode //ckstr += escape(values[i]); ckstr += (i == 0) ? escape(values[i]) : "%00"+escape(values[i]) ; } document.cookie = this.get('name') + "=" + ckstr + "; expires=" + expire.toGMTString(); }, getCookie: function () { var cklng = document.cookie.length; var ckary = document.cookie.split("; "); var ckstr = ''; var cknamelng = Number(this.get('name').length) + 1; for (var i = 0; i < ckary.length; i++) { //alert(ckary[i]); if (ckary[i].substr(0, cknamelng) == this.get('name')+'=') { ckstr = ckary[i].substr(cknamelng, ckary[i].length); break; } } this.set('values', ckstr.split("%00")); return this.get('values'); }, get: function (label) { return this._attrs[label]; }, set: function (label, value) { this._attrs[label] = value; } } /* * object配列関連 */ var ArrayObject = function () { this.initialize.apply(this, arguments); } ArrayObject.prototype = { initialize: function () { this._objects = new Array(); }, getIterator: function () { return new ArrayIterator(this._objects); }, append: function(obj) { this._objects.push(obj); }, count: function () { return this._objects.length; }, offsetExists: function (index) { if (index in this._objects) return true; return false; }, offsetGet: function (index) { if (index in this._objects) return this._objects[index]; }, offsetSet: function (index, obj) { this._objects[index] = obj; }, offsetUnset: function (index) { if (index in this._objects) delete this._objects[index]; }, sort: function (label, order) { if (order == null) order = 'ASC'; if (order.toUpperCase() == 'ASC') { this._objects = this._objects.sortBy(function(s){ return s.get(label); }); } if (order.toUpperCase() == 'DESC') { this._objects = this._objects.sortBy(function(s){ return s.get(label) * -1; }); } }, search: function (label, value) { var hitObj = null; for (var i = 0; i < this._objects.length; i++) { var objValue = (this._objects[i].get) ? this._objects[i].get(label) : this._objects[i][label]; if (objValue == value) hitObj = this._objects[i]; } return hitObj; } } var ArrayIterator = function () { this.initialize.apply(this, arguments); } ArrayIterator.prototype = { initialize: function (array) { this._array = array; this._index = 0; }, count: function() { return this._array.length; }, current: function () { return this._array[this._index]; }, next: function () { this._index++; }, prev: function() { this._index--; if (this._index < 0) this._index = 0; }, rewind: function() { this._index = 0; }, valid: function () { if (this._index in this._array) return true; return false; }, seek: function (position) { this._index = position; }, index: function () { return this._index; } } /** * ブラウザ判別 */ var BrowserJudgement = function () { this.initialize.apply(this, arguments); } BrowserJudgement.prototype = { initialize: function () { this._ua = navigator.userAgent; this._browser = { name: '' , ver: '' , genre: '' , windows: false , mac: false , linux: false , bsd: false , sunos: false , iphone: false , ipad: false , android: false , blackberry: false , windowsce: false , palm: false }; }, judge: function () { if (this._ua.match(/Opera[\/\s](\d\.\d+)/)) { this._browser.name = "Opera"; this._browser.ver = RegExp.$1; } else if (this._ua.match(/MSIE (\d\.\d+)/)) { if (this._ua.match(/Trident\/4\.0/)) { this._browser.name = "Internet Explorer"; this._browser.ver = '8.0'; } else { this._browser.name = "Internet Explorer"; this._browser.ver = RegExp.$1; } } else if (this._ua.match(/Mozilla\/(4\.[5678]\d?)/)) { this._browser.name = "Netscape Communicator"; this._browser.ver = RegExp.$1; } else if (this._ua.match(/Netscape6?\/([\.\d]+)/)) { this._browser.name = "Netscape"; this._browser.ver = RegExp.$1; } else if (this._ua.match(/Shiira\/([\.\d]+)/)) { this._browser.name = "Shiira"; this._browser.ver = RegExp.$1; } else if (this._ua.match(/Chrome\/([\.\d]+)/)) { this._browser.name = "Google Chrome"; this._browser.ver = RegExp.$1; } else if (this._ua.match(/Safari\/([\.\d]+)/)) { this._browser.name = "Safari"; this._browser.ver = RegExp.$1; } else if (this._ua.match(/Gecko/)) { if (this._ua.match(/(Firebird|Firefox)\/([\.\d]+)/)) { this._browser.name = "Mozilla " + RegExp.$1; this._browser.ver = RegExp.$2; } else if (this._ua.match(/Thunderbird\/([\.\d]+)/)) { this._browser.name = "Mozilla Thunderbird"; this._browser.ver = RegExp.$1; } else if (this._ua.match(/Camino\/([\.\d]+)/)) { this._browser.name = "Camino"; this._browser.ver = RegExp.$1; } else if (this._ua.match(/rv:([\.\d]+)/)) { this._browser.name = "Mozilla"; this._browser.ver = RegExp.$1; } else { this._browser.name = "Mozilla"; } } else if (this._ua.match(/MSIEMobile (\d\.\d+)/)) { this._browser.name = "MSIEMobile"; this._browser.ver = RegExp.$1; } else if (this._ua.match(/BlackBerry (\d+)/)) { this._browser.name = "BlackBerry"; } else { this._browser.name = "N/A"; } if (this._ua.indexOf("iPhone") >= 0) { this._browser.iphone = true; this._browser.genre = 'sp'; } else if (this._ua.indexOf("iPad") >= 0) { this._browser.ipad = true; this._browser.genre = 'pc'; } else if (this._ua.indexOf("Android") >= 0) { // Android 1.5+ this._browser.android = true; this._browser.genre = 'sp'; } else if (this._ua.indexOf("CUPCAKE") >= 0) { // Android 1.5 this._browser.android = true; this._browser.genre = 'sp'; } else if (this._ua.indexOf("dream") >= 0) { // Android 1.5Pre this._browser.android = true; this._browser.genre = 'sp'; } else if (this._ua.indexOf("BlackBerry") >= 0) { this._browser.blackberry = true; this._browser.genre = 'sp'; } else if (this._ua.indexOf("Windows CE") >= 0) { this._browser.windowsce = true; this._browser.genre = 'sp'; } else if (this._ua.indexOf("webOS") >= 0) { this._browser.palm = true; this._browser.genre = 'sp'; } else if (this._ua.indexOf("Win") >= 0) { this._browser.windows = true; this._browser.genre = 'pc'; } else if (this._ua.indexOf("Mac") >= 0) { this._browser.mac = true; this._browser.genre = 'pc'; } else if (this._ua.indexOf("Linux") >= 0) { this._browser.linux = true; this._browser.genre = 'pc'; } else if (this._ua.indexOf("BSD") >= 0) { this._browser.bsd = true; this._browser.genre = 'pc'; } else if (this._ua.indexOf("SunOS") >= 0) { this._browser.sunos = true; this._browser.genre = 'pc'; } }, getResult: function () { return this._browser; } } /* * subwindow制御 */ var SubwindowCtrl = function () { this.initialize.apply(this, arguments); } SubwindowCtrl.prototype = { initialize: function (areaName, dAndD) { this._id = 0; this._zindex = 500; this._existsCnt = 0; this._defaultWidth = 400; this._defaultHeight = ''; this._defaultTop = 0; this._defaultLeft = 0; this._uniqFlgs = {}; this._areaName = areaName; this._dAndD = (typeof dAndD == 'undefined' || dAndD == '') ? false : dAndD; this._subwindowAreaElm = document.getElementById(areaName); this._attacher = new EventListenerAttacher(); if (this._dAndD === true) this._dAndDAttacher = new DragAndDropAttacher(areaName); this._defaultEventInterceptor = new DefaultEventInterceptor(); this._debugger = new ObjectInspector(); // 閉じるボタンのイベントハンドラ this._attacher.attachClickListenerById(areaName, this._closeBtn, this); }, create: function (width, height, top, left, closeBtn, uniqFlgName) { if (uniqFlgName) { if (this._uniqFlgs[uniqFlgName]) { if (this._uniqFlgs[uniqFlgName] == true) return null; } else { this._uniqFlgs[uniqFlgName] = false; } } this._id++; this._existsCnt++; closeBtn = (!closeBtn) ? false : true; var settings = { id: this._id , width: width , height: height , top: top , left: left , closeBtn: closeBtn , uniqFlgName: uniqFlgName }; this._subwindowAreaElm.innerHTML += this._createSubwindowHtml(settings); //this._setting(settings); return settings; }, rendering: function (settings, contents, title) { settings.contents = contents; settings.title = title; this._setting(settings); if (this._dAndD === true) this._dAndDAttacher.attach(this._areaName+'_'+settings.id, this._areaName+'_title_bar_'+settings.id); document.getElementById(this._areaName+'_'+settings.id).style.display = 'block'; if (settings.uniqFlgName) this._uniqFlgs[settings.uniqFlgName] = true; }, /* * windowの大きさや位置などを設定 */ _setting: function (settings) { var subwindowElm = document.getElementById(this._areaName+'_'+String(this._id)); document.getElementById(this._areaName+'_title_'+this._id).innerHTML = settings.title; document.getElementById('sub_contents_'+this._areaName+'_'+this._id).innerHTML = settings.contents; subwindowElm.style.width = (settings.width) ? settings.width+'px' : this._defaultWidth+'px'; subwindowElm.style.zindex = this._zindex + this._id; document.getElementById('sub_contents_'+this._areaName+'_'+this._id).style.height = (!settings.height) ? '' : settings.height+'px'; // 透明にしてから表示してsubwindowの高さと幅を計算(renderingしてからでないと、位置情報が取得できない!) this._setOpacity(subwindowElm, 0); subwindowElm.style.display = 'block'; // 描画領域サイズを取得 var viewportSize = this._getViewportSize(); // 中央を算出 this._defaultTop = parseInt((viewportSize.height - subwindowElm.offsetHeight) / 2); this._defaultLeft = parseInt((viewportSize.width - subwindowElm.offsetWidth) / 2); // スクロールを考慮 //var scrollOffset = popupElement.cumulativeScrollOffset(document); //top += scrollOffset.top; //left += scrollOffset.left; // 高さと幅を取得後、隠して不透明に戻す。 subwindowElm.style.display = 'none'; this._setOpacity(subwindowElm, 100); // window位置を設定 subwindowElm.style.top = (settings.top) ? String(settings.top)+'px' : String(this._defaultTop)+'px'; subwindowElm.style.left = (settings.left) ? settings.left+'px' : this._defaultLeft+'px'; }, close: function (id, eventObj) { if (eventObj) this._defaultEventInterceptor.execute(eventObj); if (this._dAndD === true) this._dAndDAttacher.detach(this._areaName+'_'+id, this._areaName+'_title_bar_'+id); this._subwindowAreaElm.removeChild(document.getElementById(this._areaName+'_'+id)); if (eval('document.uniqFlgNameArea_'+this._areaName+'_'+id)) { delete this._uniqFlgs[eval('document.uniqFlgNameArea_'+this._areaName+'_'+id+'.uniqFlgName.value')]; this._subwindowAreaElm.removeChild(document.getElementById('uniqFlgNameArea_'+this._areaName+'_'+id)); } this._existsCnt--; if (this._existsCnt == 0) this._id = 0; }, _closeBtn: function (eventObj) { var targetElement = eventObj.target || eventObj.srcElement; if (targetElement.id.match(new RegExp("^sub_close_(\\d+)$"))) { this._defaultEventInterceptor.execute(eventObj); if (this._dAndD === true) this._dAndDAttacher.detach(this._areaName+'_'+RegExp.$1, this._areaName+'_title_bar_'+RegExp.$1); this._subwindowAreaElm.removeChild(document.getElementById(this._areaName+'_'+RegExp.$1)); if (eval('document.uniqFlgNameArea_'+this._areaName+'_'+RegExp.$1)) { delete this._uniqFlgs[eval('document.uniqFlgNameArea_'+this._areaName+'_'+RegExp.$1+'.uniqFlgName.value')]; this._subwindowAreaElm.removeChild(document.getElementById('uniqFlgNameArea_'+this._areaName+'_'+RegExp.$1)); } this._existsCnt--; if (this._existsCnt == 0) this._id = 0; } }, _createSubwindowHtml: function (settings) { var subwindowHtml = ''; subwindowHtml = ''; subwindowHtml += (settings.uniqFlgName) ? '
' : ''; return subwindowHtml; }, /* * 不透明度を設定する */ _setOpacity: function (obj, num) { if (obj.style.filter) { obj.style.filter = 'alpha(opacity=' + num + ')'; } else if (obj.style.opacity) { obj.style.opacity = num / 100; } else { obj.style.MozOpacity = num / 100; } }, /* * browser描画領域の取得 */ _getViewportSize: function () { var viewportSize = { width: 0 , height: 0 }; if (document.documentMode) { //5:Quirksモードと呼ばれるIE5、6の互換モード //7:IE7標準準拠モード //8:IE8標準準拠モード if (document.documentMode == 5) { viewportSize.width = document.body.clientWidth; viewportSize.height = document.body.clientHeight; } else { viewportSize.width = document.documentElement.clientWidth; viewportSize.height = document.documentElement.clientHeight; } } else { if (document.body.clientWidth) { viewportSize.width = document.body.clientWidth; viewportSize.height = document.body.clientHeight; } else { viewportSize.width = window.innerWidth; viewportSize.height = window.innerHeight; } } return viewportSize; } } /** * Drag&Drop * areaIdに指定した範囲内のdivをD&D可能にする */ var DragAndDropAttacher = function () { this.initialize.apply(this, arguments); } DragAndDropAttacher.prototype = { initialize: function (areaId) { this._offsetX = 0; this._offsetY = 0; this._winidList = []; this._handleList = []; var areaElm = document.getElementById(areaId); if (document.addEventListener) { areaElm.onmousedown = this._onMouseDown.curry(areaId).bindFunc(this); } else { areaElm.onmousedown = this._onMouseDown.curry(areaId, event).bindFunc(this); } }, destroy: function (areaId) { var areaElm = document.getElementById(areaId); if (document.addEventListener) { areaElm.onmousedown = null; } else { areaElm.onmousedown = null; } }, attach: function (winId, handleId) { var handleExists = (typeof handleId == 'undefined') ? false : true; if (!this._winidList.exists(winId)) { this._winidList.push(winId); if (!handleExists) document.getElementById(winId).style.cursor = 'move'; } if (handleExists) { if (!this._handleList.exists(handleId)) { this._handleList.push(handleId); document.getElementById(handleId).style.cursor = 'move'; } } }, detach: function (winId, handleId) { var pointer = 0; for (var i = 0; i < this._winidList.length; i++) { if (this._winidList[i] == winId) { pointer = i; break; } } delete this._winidList[pointer]; if (typeof handleId != 'undefined') { pointer = 0; for (var i = 0; i < this._handleList.length; i++) { if (this._handleList[i] == winId) { pointer = i; break; } } delete this._handleList[pointer]; } }, _onMouseDown: function (areaId, eventObj) { this._disableTextSelect(); var target = eventObj.srcElement || eventObj.target; //document.body.innerHTML += (new ObjectInspector()).inspect(target); var search = true; var handle = null; var main = null; while (search) { if (target == null) break; if (typeof target.form != 'undefined') break; for (var i = 0; i < this._winidList.length; i++) { if (target.id == this._winidList[i]) { main = target; search = false; break; } } if (search) target = target.parentNode; } if (main == null) return true; if (typeof this._handleList[i] != 'undefined') { target = eventObj.srcElement || eventObj.target; search = true; while (search) { if (target == null) break; if (target.id == this._handleList[i]) { handle = target; search = false; break; } if (search) target = target.parentNode; } if (handle == null) return true; } else { handle = main; } if (document.addEventListener) { this._offsetX = eventObj.clientX - parseInt(main.style.left); this._offsetY = eventObj.clientY - parseInt(main.style.top); handle.onmousemove = this._onMouseMove.curry(areaId).bindFunc(this); handle.onmouseup = this._onMouseUp.curry(areaId).bindFunc(this); } else { this._offsetX = event.offsetX + 5; this._offsetY = event.offsetY + 5; handle.onmousemove = this._onMouseMove.curry(areaId, event).bindFunc(this); handle.onmouseup = this._onMouseUp.curry(areaId, event).bindFunc(this); } this._setOpacity(main, 70); main.style.zIndex = Number(main.style.zIndex) + 10000; return false; }, _onMouseMove: function (areaId, eventObj) { var target = eventObj.srcElement || eventObj.target; var search = true; var hit = false; while (search) { for (var i = 0; i < this._winidList.length; i++) { if (target.id == this._winidList[i]) { hit = true; search = false; } } if (search) target = target.parentNode; } if (!hit) return true; var dx; var dy; if (document.all) { /*dx = event.clientX - this._offsetX + document.body.scrollLeft; dy = event.clientY - this._offsetY + document.body.scrollTop;*/ dx = event.clientX - this._offsetX; dy = event.clientY - this._offsetY; } else if (target.getElementsByTagName) { dx = eventObj.clientX - this._offsetX; dy = eventObj.clientY - this._offsetY; } target.style.left = dx + 'px'; target.style.top = dy + 'px'; return false; }, _onMouseUp: function (areaId, eventObj) { var target = eventObj.srcElement || eventObj.target; var search = true; var main = null; var handle = null; while (search) { if (target == null) break; if (typeof target.form != 'undefined') break; for (var i = 0; i < this._winidList.length; i++) { if (target.id == this._winidList[i]) { main = target; search = false; break; } } if (search) target = target.parentNode; } if (main == null) return true; if (typeof this._handleList[i] != 'undefined') { target = eventObj.srcElement || eventObj.target; search = true; while (search) { if (target == null) break; if (target.id == this._handleList[i]) { handle = target; search = false; break; } if (search) target = target.parentNode; } if (handle == null) return true; } else { handle = main; } handle.onmousemove = null; handle.onmouseup = null; this._setOpacity(main, 100); main.style.zIndex = Number(main.style.zIndex) - 10000; this._enableTextSelect(); }, _disableTextSelect: function () { var nodes = document.body.childNodes; for (var i = 0; i < nodes.length; i++) { if (typeof nodes[i].firstChild != 'undefined' && nodes[i].firstChild != null) { if (nodes[i].firstChild.data != '') this._disableSelection(nodes[i]); } else if (typeof nodes[i].textContent != 'undefined') { if (nodes[i].textContent != '') this._disableSelection(nodes[i]); } else if (typeof nodes[i].innerText != 'undefined') { if (nodes[i].innerText != '') this._disableSelection(nodes[i]); } } }, _disableSelection: function (target) { if (typeof target.onselectstart != 'undefined') { target.onselectstart = function () { return false; } } else if (target.style && typeof target.style.MozUserSelect != "undefined") { target.style.MozUserSelect = 'none' } else { target.onmousedown = function(){ return false; } if (target.style) target.style.cursor = "default"; } }, _enableTextSelect: function () { var nodes = document.body.childNodes; for (var i = 0; i < nodes.length; i++) { if (typeof nodes[i].firstChild != 'undefined' && nodes[i].firstChild != null) { if (nodes[i].firstChild.data != '') this._enableSelection(nodes[i]); } else if (typeof nodes[i].textContent != 'undefined') { if (nodes[i].textContent != '') this._enableSelection(nodes[i]); } else if (typeof nodes[i].innerText != 'undefined') { if (nodes[i].innerText != '') this._enableSelection(nodes[i]); } } }, _enableSelection: function (target) { if (typeof target.onselectstart != 'undefined') { target.onselectstart = null; } else if (target.style && typeof target.style.MozUserSelect != "undefined") { target.style.MozUserSelect = 'inherit' } else { target.onmousedown = null; if (target.style) target.style.cursor = "auto"; } }, /* * 不透明度を設定する */ _setOpacity: function (target, num) { //if (target.style.filter) { target.style.filter = 'alpha(opacity=' + num + ')'; if (target.style.opacity) { target.style.opacity = num / 100; } else { target.style.MozOpacity = num / 100; } } }