/* SkyJS Rama Version Copyright (c) 2010 Seo, Jaehan Referred to ui javascript framework - gony Prototype javascript framework - Sam Stephenson Swaf javascript framework - reizes jQuery javascript framework - John Resig (jquery.com) */ // Class ////////////////////////////////////////////////////////////////////// var Class = function() { var obj = function() { if (this.init) this.init.apply(this, arguments); } if (arguments[0]) Class.extend(obj.prototype, arguments[0]); return obj; } Class.extend = function(obj) { for(var i=1; i]+>/gi, ''); }, validHTML : function() { var div = document.createElement('div'); div.innerHTML = this; return div.innerHTML; }, escapeHTML: function() { var div = document.createElement('div'); var text = document.createTextNode(this); div.appendChild(text); return div.innerHTML; }, unescapeHTML: function() { var div = document.createElement('div'); div.innerHTML = this.stripTags(); return div.childNodes[0] ? div.childNodes[0].nodeValue : ''; }, decodeQuery : function(isUrl) { if (isUrl) { var tmp = this.substring(this.indexOf('?')+1).match(/^\??(.*)$/)[1].split('&'); } else { var tmp = this.match(/^\??(.*)$/)[1].split('&'); } var ret = {}; for (var i=0; i | 3 clause BSD license // https://github.com/alexei/sprintf.js sprintf : function() { this.format = function(parse_tree, argv) { var cursor = 0, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; for (i = 0; i < tree_length; i++) { node_type = this.get_type(parse_tree[i]); if (node_type === 'string') { output.push(parse_tree[i]); } else if (node_type === 'array') { match = parse_tree[i]; // convenience purposes only if (match[2]) { // keyword argument arg = argv[cursor]; for (k = 0; k < match[2].length; k++) { if (!arg.hasOwnProperty(match[2][k])) { throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); } arg = arg[match[2][k]]; } } else if (match[1]) { // positional argument (explicit) arg = argv[match[1]]; } else { // positional argument (implicit) arg = argv[cursor++]; } if (/[^s]/.test(match[8]) && (this.get_type(arg) != 'number')) { throw(sprintf('[sprintf] expecting number but found %s', this.get_type(arg))); } switch (match[8]) { case 'b': arg = arg.toString(2); break; case 'c': arg = String.fromCharCode(arg); break; case 'd': arg = parseInt(arg, 10); break; case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; case 'o': arg = arg.toString(8); break; case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; case 'u': arg = arg >>> 0; break; case 'x': arg = arg.toString(16); break; case 'X': arg = arg.toString(16).toUpperCase(); break; } arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; pad_length = match[6] - String(arg).length; pad = match[6] ? this.str_repeat(pad_character, pad_length) : ''; output.push(match[5] ? arg + pad : pad + arg); } } return output.join(''); }; this.cache = null; this.parse = function(fmt) { var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; while (_fmt) { if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { parse_tree.push(match[0]); } else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { parse_tree.push('%'); } else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { if (match[2]) { arg_names |= 1; var field_list = [], replacement_field = match[2], field_match = []; if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { field_list.push(field_match[1]); while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { field_list.push(field_match[1]); } else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { field_list.push(field_match[1]); } else { throw('[sprintf] huh?'); } } } else { throw('[sprintf] huh?'); } match[2] = field_list; } else { arg_names |= 2; } if (arg_names === 3) { throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); } parse_tree.push(match); } else { throw('[sprintf] huh?'); } _fmt = _fmt.substring(match[0].length); } return parse_tree; }; this.get_type = function(variable) { return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); } this.str_repeat = function(input, multiplier) { for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} return output.join(''); } if (!this.cache) { this.cache = this.parse(this.valueOf()); } return this.format(this.cache, arguments); } }); String.prototype.parseQuery = String.prototype.decodeQuery; // Event ////////////////////////////////////////////////////////////////////// var Event = { __funcId : 0, bind : function(func, obj) { if (typeof obj.__evtFunc == 'undefined') { obj.__evtFunc = {}; } if (!func.__funcId) { func.__funcId = this.__funcId++; } if (typeof obj.__evtFunc[func.__funcId] != 'function') { obj.__evtFunc[func.__funcId] = function(evt) { func(evt, obj); } } return obj.__evtFunc[func.__funcId]; }, addListener : function(obj, handler, func) { if (!(obj instanceof Array)) obj = [obj]; for (var i=0; i t.right || o.right < t.left || o.top > t.bottom || o.bottom < t.top); }, inTest : function(obj, target) { var o = this.getRect(obj); var t = this.getRect(target); return (o.left >= t.left && o.right <= t.right && o.top >= t.top && o.bottom <= t.bottom); }, addBefore : function(obj, src) { obj.parentNode.insertBefore(src, obj); if (obj.blocker) this.updateBlocker(obj); }, addAfter : function(obj, src) { if (obj.nextSibling) { obj.parentNode.insertBefore(src, obj.nextSibling); } else { obj.parentNode.appendChild(src); } if (obj.blocker) this.updateBlocker(obj); }, clone : function(obj, deep) { return obj.cloneNode(deep); }, remove : function(obj) { if (obj.blocker) this.hide(obj.blocker); obj.parentNode.removeChild(obj); }, attachBlocker : function(obj, group) { if (!Util.isIE) return; // IE only if (!obj.blocker) { var iframeId = '__blocker_' + (group || 'default'); var iframe = $id(iframeId); if (!iframe) { iframe = $c('iframe'); iframe.setAttribute('src', 'about:blank'); iframe.setAttribute('id', iframeId); iframe.setAttribute('frameBorder', '0'); this.setStyle(iframe, { position : 'absolute', width : '0px', height : '0px', filter : 'alpha(opacity=0)' }); document.body.appendChild(iframe); } obj.blocker = iframe; } }, updateBlocker : function(obj) { var iframe = obj.blocker; if (!iframe) return; var display = this.getStyle(obj, 'display'); if (display == 'none') { this.hide(iframe); } else { this.show(iframe); this.setPosition(iframe, this.getPosition(obj)); this.setSize(iframe, this.getSize(obj)); var zIndex = parseInt(this.getStyle(obj, 'zIndex'), 10); if (!zIndex) { zIndex = 1000; this.setStyle(obj, 'zIndex', zIndex) } this.setStyle(iframe, 'zIndex', zIndex-1); } }, extend : function(obj) { obj = $id(obj); if (typeof obj.extended != 'undefined') return obj; for (var func in this) { if (func == 'extend') continue; if (!this[func].bind) continue; obj[func] = this[func].bind(this, obj); } obj.extended = true; return obj; } } ramaElement.pos = ramaElement.getPosition; ramaElement.moveTo = ramaElement.setPosition; if (typeof Element != 'undefined') { Element = Class.extend(Element, ramaElement); } else { Element = ramaElement; } // Selector /////////////////////////////////////////////////////////////////// /* [ selector syntax ] - basic #id tag .class * - hierarchy E F - F descendant of E E > F - F child of E E + F - F next sibling of E E ~ F - F previouse sibling of E E @ F - F ancestor of E - filter : E:filter first last even odd only nth(index) eq(index), indexe(index), lt(index), gt(index), le(index), ge(index) =index, !index, !=index, index, <=index, >=index - attribute filter : E[filter] attr - have attr! - not have attr=value - same attr!=value - not same attr*=value - match part attr^=value - start with attr$=value - end with */ var Selector = { patternA : /((?:^|[\s]+)(?:[>+~@][\s]+)?)([^ ]+)/g, patternB : /([\.\[:])([^\.:\[\]]+)/g, query : function(selector, context) { // none if (!selector) { return []; } // dom object if (selector.nodeType) { return [selector]; } // query if (typeof selector == 'string') { var result = []; var sList = selector.split(/[\s]*,[\s]*/); for (var i=0; i') { result = Selector.findChildNodes(m[0], m[1], result); } else if (d == '+') { result = Selector.findNextSibling(m[0], m[1], result); } else if (d == '~') { result = Selector.findPrevSibling(m[0], m[1], result); } else if (d == '@') { result = Selector.findParent(m[0], m[1], result); } if (!result.length) { break; } } return result; }, findDescendant : function(type, filter, list) { var result = []; if (type.charAt(0) == '#') { var obj = document.getElementById(type.slice(1)); if (obj) { for (var i=0; i -1) { obj = Selector.filterNode(obj, v); } else if (v.indexOf('child') > -1) { obj = Selector.filterChild(obj, v); } else { obj = Selector.filterList(obj, v); } } else if (k == '[') { obj = Selector.filterAttr(obj, v); } } return obj; }, filterClass : function(obj, className) { if (!obj) { return []; } if (obj.nodeType) { obj = [obj]; } var result = []; for (var i=0; i 0) { result.push(obj[0]); } } else if (filter == 'last') { if (obj.length > 0) { result.push(obj[obj.length-1]); } } else if (filter == 'even') { for (var i=0; i<=]+|(?:nth|eq|lt|gt|ne|le|ge))?[\(]?([^\(\)]+)[\}]?/); if (match) { if (!match[1] || match[1] == '=' || match[1] == 'eq') { var index = parseInt(match[2], 10); if (typeof obj[index] != 'undefined') { result.push(obj[index]); } } else if (match[1] == 'nth') { try { do { var index = eval(match[2]); if (typeof obj[index] != 'undefined') { result.push(obj[index]); } } while (index < obj.length); } catch (e) {} } else { if (!(obj instanceof Array)) { obj = $a(obj); } var index = parseInt(match[2], 10); switch (match[1]) { // not equal case '!' : case '!=' : case 'ne' : result = obj.splice(index, 1); break; // greater than case '>' : case 'gt' : result = obj.slice(index+1); break; // greater than or equal case '>=' : case 'ge' : result = obj.slice(index); break; // less than case '<' : case 'lt' : result = obj.slice(0, index); break; // less than or equal case '<=' : case 'le' : result = obj.slice(0, index+1); break; } } } } return result; }, filterAttr : function(obj, attr, value) { if (!obj) { return []; } if (obj.nodeType) { obj = [obj]; } if (arguments.length == 2) { var tmp = attr.split('='); var attr = tmp[0]; var value = tmp[1]; } var result = []; if (!value) { if (attr.slice(-1) == '!') { attr = attr.slice(0, -1); for (var i=0; i -1) { result.push(obj[i]); } } break; // start with case '^' : attr = attr.slice(0, -1); reg = new RegExp('^' + value); for (var i=0; i -1) { var o = str.slice(0, pos) || '*'; var x = Selector.regExecAll(Selector.patternB, str.slice(pos)); } else { var o = str; var x = []; } return [o, x]; }, regExecAll : function(reg, str) { reg.lastIndex = 0; var match = []; var tmp = null; while (tmp = reg.exec(str)) { match.push(tmp); } return (match.length) ? match : null; } } // Ajax /////////////////////////////////////////////////////////////////////// var Ajax = Class({ init : function(options) { Class.extend(this, { url : '', method : 'GET', // GET, POST type : 'TEXT', // TEXT, HTML, JSON, XML userid : null, password : null, header : {}, param : {}, callback : null, target : null, repeat : 1, delay : 5 }); this.http = null; this.postData = null; this.timer = null; this.count = 0; this.initHTTP(); if (options) { this.request(options); } }, initHTTP : function() { if (!this.http) { if (window.XMLHttpRequest) { this.http = new XMLHttpRequest(); this.httpType = 'XMLHttpRequest'; } else if (window.ActiveXObject) { var pid = ['MSXML2.XMLHTTP', 'Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'MSXML3.XMLHTTP']; for (var i=0; i this.area.right - size.width) newX = this.area.right - size.width; if (newY > this.area.bottom - size.height) newY = this.area.bottom - size.height; if (newX < this.area.left) newX = this.area.left; if (newY < this.area.top) newY = this.area.top; } this.newX = newX; this.newY = newY; // callback var ret; if (typeof this.options.onMove == 'function') { ret = this.options.onMove.call(this, evt); } if (ret !== false) { this.object.setPosition(this.newX, this.newY); } }, onMouseUp : function(evt) { Event.stop(evt); $lx(document, 'mousemove', this.onmousemove); $lx(document, 'mouseup', this.onmouseup); this.object.setStyle('zIndex', this.zIndex); // callback if (typeof this.options.onEnd == 'function') { this.options.onEnd.call(this, evt); } } }); // Debug ////////////////////////////////////////////////////////////////////// /* Only works when console is available! You can get information about firebug at http://getfirebug.com/ */ var Debug = { use : false, log : function(obj) { if (this.use && typeof console != 'undefined') { console.log(obj); } }, error : function(obj) { if (this.use && typeof console != 'undefined') { console.error(obj); } } } // Util /////////////////////////////////////////////////////////////////////// var Util = { // brower isIE : (window.navigator.userAgent.search(/(Trident|msie)/i) != -1), isFF : (window.navigator.userAgent.search(/firefox/i) != -1), isOpera : (window.navigator.userAgent.search(/opera/i) != -1), isSafari : (window.navigator.userAgent.search(/safari/i) != -1), userAgent : window.navigator.userAgent, appName : ( (new RegExp('(rv:|msie |firefox/|opera/|safari/|kakaotalk )([0-9.]+)', 'i')).exec(window.navigator.userAgent) ? (new RegExp('(rv:|msie |firefox/|opera/|safari/|kakaotalk )([0-9.]+)', 'i')).exec(window.navigator.userAgent)[1].slice(0, -1) : '' ), appVersion : ( (new RegExp('(rv:|msie |firefox/|opera/|safari/|kakaotalk )([0-9.]+)', 'i')).exec(window.navigator.userAgent) ? (new RegExp('(rv:|msie |firefox/|opera/|safari/|kakaotalk )([0-9.]+)', 'i')).exec(window.navigator.userAgent)[2] : '' ), // window, document getClientSize : function(win) { if (!win) win = self; var w = win.innerWidth || win.document.documentElement.clientWidth || win.document.body.clientWidth; var h = win.innerHeight || win.document.documentElement.clientHeight || win.document.body.clientHeight; return { width:w, height:h }; }, getDocSize : function(win) { if (!win) win = self; var docSize = Element.getSize(win.document.body); var w = Math.max(win.document.body.scrollWidth, docSize.width); var h = Math.max(win.document.body.scrollHeight, docSize.height); return { width:w, height:h }; }, getScrollOffset : function(win) { if (!win) win = self; var x = win.pageXOffset || win.document.body.scrollLeft || document.documentElement.scrollLeft || 0; var y = win.pageYOffset || win.document.body.scrollTop || document.documentElement.scrollTop || 0; return { x:x, y:y }; }, getDocumentWindow : function(doc) { return doc.defaultView || doc.parentWindow; }, // iframe getIframeDoc : function(iframe) { if (iframe.contentWindow) { return iframe.contentWindow.document; } else if (iframe.contentDocument) { return iframe.contentDocument.documentElement; } else { return null; } }, getIframeDocSize : function(iframe) { iframe = $id(iframe); var doc = this.getIframeDoc(iframe); var win = this.getDocumentWindow(doc); return this.getDocSize(win); }, autoResizeIframe : function(iframe, noWidth, noHeight) { this.resizeIframe(iframe, !noWidth, !noHeight); }, resizeIframe : function(iframe, width, height) { iframe = $id(iframe); if (width === true || height === true) { var docSize = this.getIframeDocSize(iframe); } if (width) { width = (width === true) ? docSize.width : width; Element.setStyle(iframe, 'width', (typeof width == 'number') ? (width || 400) + 'px' : width); } if (height) { height = (height === true) ? docSize.height : height; Element.setStyle(iframe, 'height', (typeof height == 'number') ? (height || 300) + 'px' : height); } }, // math random : function(min, max) { if (typeof min == 'number' && typeof max == 'number') { return Math.floor(Math.random() * (max-min) + min); } else { return Math.floor(Math.random() * 10); } }, randomId : function(cipher, prefix) { if (typeof cipher != 'number') { cipher = 7; } else if (cipher > 15) { cipher = 15; } var min = parseInt('100000000000000'.substr(0, cipher), 10); var max = parseInt('999999999999999'.substr(0, cipher), 10); return (prefix) ? prefix+'_'+Util.random(min, max) : Util.random(min, max); }, // cookie getCookie : function(name) { var re = new RegExp(name + '=([^;]+)'); var value = re.exec(document.cookie); return (value != null) ? unescape(value[1]) : null; }, setCookie : function(name, value, expire, path, domain) { expire = parseInt(expire, 10); if (!path) path = '/'; if (expire) { var today = new Date(); var expiry = new Date(today.getTime() + expire * 1000); var cookie = name + '=' + escape(value) + '; expires=' + expiry.toGMTString() + '; path=' + path; } else { var cookie = name + '=' + escape(value) + '; path=' + path; } if (domain) cookie += '; domain=' + domain; document.cookie = cookie; }, // link style sheet linkStyle : function(href, id) { var link = id ? ($id(id) || $c('link')) : $c('link'); if (link.id) { link.setAttribute('href', href); } else { if (id) link.setAttribute('id', id); link.setAttribute('type', 'text/css'); link.setAttribute('rel', 'stylesheet'); link.setAttribute('href', href); var head = document.getElementsByTagName('head')[0]; head.appendChild(link); } return link; }, linkCSS : function(href, id) { return this.linkStyle(href, id); }, // js path getJSPath : function(jsFile) { if (!jsFile) jsFile = 'sky.rama.js'; var scripts = document.getElementsByTagName('script'); for (var i=0; i0) { break; } } return ret; } // extend function $e(obj) { if (typeof obj == 'string' || (typeof obj.nodeType == 'number' && obj.nodeType == 1)) { obj = Element.extend(obj); } else if (typeof obj.initEvent == 'function' || typeof obj.keyCode == 'number') { obj = Event.extend(obj); } else { obj = Class.extend.apply(Class, arguments); } return obj; } // create element function $c(tag) { return document.createElement(tag); } // array function $a = Array.prototype.copy; function $array(obj) { return (obj instanceof Array) ? obj : [obj]; } // event function function $l(obj, handler, func) { Event.addListener(obj, handler, func); } function $lx(obj, handler, func) { Event.delListener(obj, handler, func); } function $load(func) { if (!(this.__window_load_func instanceof Array)) { this.__window_load_func = []; } if (typeof func == 'function') { this.__window_load_func.push(func); if (this.__window_load_func.length == 1) { $l(window, 'load', __window_load_init); } } } function __window_load_init(evt, obj) { for (var i=0; i<__window_load_func.length; i++) { __window_load_func[i](evt, obj); } } // get form function $form(name) { if (typeof name == 'string') { return document.forms[name] || document.getElementById(name); } else { return name; } } // get form element value function $v(obj) { obj = $id(obj); if (obj.type) { var type = obj.type; } else if (obj.length) { var type = obj[0] ? obj[0].type : false; } else { var type = false; } if (!type) return false; switch (type.toLowerCase()) { case 'radio' : var value = $a(obj).filter(function(e) { return e.checked ? e.value : false; }, true); value = (value.length) ? value[0] : ''; break; case 'checkbox' : var value = $a(obj).filter(function(e) { return e.checked ? e.value : false; }, true); break; case 'select-one' : var value = $a(obj.options).filter(function(e) { return e.selected ? e.value : false; }, true); value = (value.length) ? value[0] : ''; break; case 'select-multiple' : var value = $a(obj.options).filter(function(e) { return e.selected ? e.value : false; }, true); break; default : var value = $a(obj).each(function(e) { return e.value; }); if (value.length == 1) value = value[0]; break; } return value; } // set form element value function $vset(obj, value) { obj = $id(obj); if (obj.type) { var type = obj.type; } else if (obj.length) { var type = obj[0] ? obj[0].type : false; } else { var type = false; } if (!type) return false; switch (type.toLowerCase()) { case 'radio' : $a(obj).each(function(e) { if (e.value == value) e.checked = true; }); break; case 'checkbox' : $a(value).each(function(v) { var tmp = $a(obj); if (tmp[0].getAttribute('bitwise') != null) { v = parseInt(v, 10); tmp.each(function(e) { if (parseInt(e.value, 10) & v) { e.checked = true; } else { e.checked = false; } }); } else if (tmp[0].getAttribute('withall') != null) { tmp.each(function(e) { if (e.value == v || v == 'ALL') { e.checked = true; } else { e.checked = false; } }); } else { tmp.each(function(e) { if (e.value == v) { e.checked = true; } else { e.checked = false; } }); } }); break; case 'select-one' : $a(obj.options).each(function(e) { if (e.value == value) e.selected = true; }); break; case 'select-multiple' : $a(value).each(function(v) { $a(obj.options).each(function(e) { if (e.value == v) e.selected = true; }); }); break; default : var e = $a(obj); $a(value).each(function(v, i) { if (typeof e[i] != 'undefined') e[i].value = v; }); break; } } // get selected option object function $select(obj) { obj = $id(obj); if (typeof obj.options == 'undefined') return false; var option = $a(obj.options).filter(function(e) { return e.selected ? e : false; }, true); if (obj.type.toLowerCase() == 'select-one') option = (option.length) ? option[0] : false; return option; } function $resolve() { if (typeof jQuery != 'undefined') { jQuery.noConflict(); } window.$ = $id; } $resolve();