MINI MINI MANI MO
/**
* Jindo2 Framework
* @version 1.5.2
* NHN_Library:Jindo-1.5.2;JavaScript Framework;
*/
/**
* @fileOverview $¿Í $Class¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
*/
if (typeof window != "undefined" && typeof window.nhn == "undefined") {
window.nhn = {};
}
if (typeof window != "undefined") {
if (typeof window.jindo == "undefined") {
window.jindo = {};
}
} else {
if (!jindo) {
jindo = {};
}
}
/**
* $Jindo °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù. $Jindo °´Ã¼´Â ÇÁ·¹ÀÓ¿÷¿¡ ´ëÇÑ Á¤º¸¿Í À¯Æ¿¸®Æ¼ ÇÔ¼ö¸¦ Á¦°øÇÑ´Ù.
* @constructor
* @class $Jindo °´Ã¼´Â ÇÁ·¹ÀÓ¿÷¿¡ ´ëÇÑ Á¤º¸¿Í À¯Æ¿¸®Æ¼ ÇÔ¼ö¸¦ Á¦°øÇÑ´Ù.
* @description [Lite]
*/
jindo.$Jindo = function() {
var cl=arguments.callee;
var cc=cl._cached;
if (cc) return cc;
if (!(this instanceof cl)) return new cl();
if (!cc) cl._cached = this;
this.version = "1.5.2";
}
/**
* @function
* $ ÇÔ¼ö´Â ´ÙÀ½ÀÇ µÎ °¡Áö ¿ªÇÒÀ» ÇÑ´Ù.
* <ul><li/>ID¸¦ »ç¿ëÇÏ¿© HTML ¿¤¸®¸ÕÆ®¸¦ °¡Á®¿Â´Ù. ¸Å°³º¯¼ö¸¦ µÎ °³ ÀÌ»ó ÁöÁ¤Çϸé HTML ¿¤¸®¸ÕÆ®¸¦ ¿ø¼Ò·ÎÇÏ´Â ¹è¿À» ¸®ÅÏÇÑ´Ù.
* <li>¶ÇÇÑ "<tagName>" °ú °°Àº Çü½ÄÀÇ ¹®ÀÚ¿À» ÀÔ·ÂÇϸé tagNameÀ» °¡Áö´Â °´Ã¼¸¦ »ý¼ºÇÑ´Ù.</li></ul>
* @param {String...} sID HTML ¿¤¸®¸ÕÆ®ÀÇ ID. ID´Â Çϳª ÀÌ»ó ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù. (1.4.6ºÎÅÍ´Â ¸¶Áö¸· ¸Å°³º¯¼ö¿¡ documentÀ» ÁöÁ¤ÇÒ¼ö ÀÖ´Ù.)
* @return {Element|Array} HTML ¿¤¸®¸ÕÆ® ȤÀº HTML ¿¤¸®¸ÕÆ®¸¦ ¿ø¼Ò·Î °¡Áö´Â ¹è¿À» ¸®ÅÏÇÑ´Ù. ¸¸¾à ID¿¡ ÇØ´çÇÏ´Â HTML ¿¤¸®¸ÕÆ®°¡ ¾øÀ¸¸é nullÀ» ¸®ÅÏÇÑ´Ù.
* @description [Lite]
* @example
// ID¸¦ ÀÌ¿ëÇÏ¿© °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
<div id="div1"></div>
var el = $("div1");
// ID¸¦ ÀÌ¿ëÇÏ¿© ¿©·¯°³ÀÇ °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
<div id="div1"></div>
<div id="div2"></div>
var els = $("div1","div2"); // [$("div1"),$("div2")]¿Í °°Àº °á°ú¸¦ ¸®ÅÏÇÑ´Ù.
// tagName°ú °°Àº Çü½ÄÀÇ ¹®ÀÚ¿À» ÀÌ¿ëÇÏ¿© °´Ã¼¸¦ »ý¼ºÇÑ´Ù.
var el = $("<DIV>");
var els = $("<DIV id='div1'><SPAN>hello</SPAN></DIV>");
//IE´Â iframe¿¡ Ãß°¡ÇÒ ¿¤¸®¸ÕÆ®¸¦ »ý¼ºÇÏ·Á°í ÇÒ ¶§´Â document¸¦ ¹Ýµå½Ã ÁöÁ¤ÇØ¾ß ÇÑ´Ù.(1.4.6 ºÎÅÍ Áö¿ø)
var els = $("<div>" , iframe.contentWindow.document);
//À§¿Í °°À» °æ¿ì divűװ¡ iframe.contentWindow.document±âÁØÀ¸·Î »ý±è.
*/
jindo.$ = function(sID/*, id1, id2*/) {
var ret = [], arg = arguments, nArgLeng = arg.length, lastArgument = arg[nArgLeng-1],doc = document,el = null;
var reg = /^<([a-z]+|h[1-5])>$/i;
var reg2 = /^<([a-z]+|h[1-5])(\s+[^>]+)?>/i;
if (nArgLeng > 1 && typeof lastArgument != "string" && lastArgument.body) {
/*
¸¶Áö¸· ÀÎÀÚ°¡ documentÀ϶§.
*/
arg = Array.prototype.slice.apply(arg,[0,nArgLeng-1]);
doc = lastArgument;
}
for(var i=0; i < nArgLeng; i++) {
el = arg[i];
if (typeof el == "string") {
el = el.replace(/^\s+|\s+$/g, "");
if (el.indexOf("<")>-1) {
if (reg.test(el)) {
el = doc.createElement(RegExp.$1);
}else if (reg2.test(el)) {
var p = { thead:'table', tbody:'table', tr:'tbody', td:'tr', dt:'dl', dd:'dl', li:'ul', legend:'fieldset',option:"select" };
var tag = RegExp.$1.toLowerCase();
var ele = jindo._createEle(p[tag],el,doc);
for (var i=0,leng = ele.length; i < leng ; i++) {
ret.push(ele[i]);
};
el = null;
}
}else {
el = doc.getElementById(el);
}
}
if (el) ret[ret.length] = el;
}
return ret.length>1?ret:(ret[0] || null);
}
jindo._createEle = function(sParentTag,sHTML,oDoc,bWantParent){
var sId = 'R' + new Date().getTime() + parseInt(Math.random() * 100000,10);
var oDummy = oDoc.createElement("div");
switch (sParentTag) {
case 'select':
case 'table':
case 'dl':
case 'ul':
case 'fieldset':
oDummy.innerHTML = '<' + sParentTag + ' class="' + sId + '">' + sHTML + '</' + sParentTag + '>';
break;
case 'thead':
case 'tbody':
case 'col':
oDummy.innerHTML = '<table><' + sParentTag + ' class="' + sId + '">' + sHTML + '</' + sParentTag + '></table>';
break;
case 'tr':
oDummy.innerHTML = '<table><tbody><tr class="' + sId + '">' + sHTML + '</tr></tbody></table>';
break;
default:
oDummy.innerHTML = '<div class="' + sId + '">' + sHTML + '</div>';
break;
}
var oFound;
for (oFound = oDummy.firstChild; oFound; oFound = oFound.firstChild){
if (oFound.className==sId) break;
}
return bWantParent? oFound : oFound.childNodes;
}
/**
* Ŭ·¡½º °´Ã¼¸¦ »ý¼ºÇÑ´Ù.
* @extends core
* @class $Class´Â Jindo¿¡¼ °´Ã¼ ÁöÇâ ÇÁ·Î±×·¡¹Ö(OOP)¸¦ ±¸ÇöÇÏ´Â °´Ã¼ÀÌ´Ù. $Class.$init ¸Þ¼Òµå´Â Ŭ·¡½º¸¦ »ý¼ºÇÒ ¶§ Ŭ·¡½º ÀνºÅϽº¿¡ ´ëÇÑ »ý¼ºÀÚ ÇÔ¼ö¸¦ Á¤ÀÇÇÑ´Ù.
* @param {Object} oDef Ŭ·¡½º¸¦ Á¤ÀÇÇÏ´Â °´Ã¼. ¸Þ¼µå, ÇÁ·ÎÆÛƼ¿Í »ý¼ºÀÚ¸¦ Á¤ÀÇÇÑ´Ù. $staic Ű¿öµå´Â ÀνºÅϽº¸¦ »ý¼ºÇÏÁö ¾Ê¾Æµµ »ç¿ëÇÒ ¼ö ÀÖ´Â ¸Þ¼µåÀÇ ÁýÇÕÀÌ´Ù.
* @return {$Class} Ŭ·¡½º °´Ã¼
* @description [Lite]
* @example
var CClass = $Class({
prop : null,
$init : function() {
this.prop = $Ajax();
...
},
$static : {
static_method : function(){ return 1;}
}
});
var c1 = new CClass();
var c2 = new CClass();
// c1°ú c2´Â ¼·Î ´Ù¸¥ $Ajax °´Ã¼¸¦ °¢°¢ °¡Áø´Ù.
CClass.static_method(); -> 1
*/
jindo.$Class = function(oDef) {
function typeClass() {
var t = this;
var a = [];
var superFunc = function(m, superClass, func) {
if(m!='constructor' && func.toString().indexOf("$super")>-1 ){
var funcArg = func.toString().replace(/function\s*\(([^\)]*)[\w\W]*/g,"$1").split(",");
// var funcStr = func.toString().replace(/function\s*\(.*\)\s*\{/,"").replace(/this\.\$super/g,"this.$super.$super");
var funcStr = func.toString().replace(/function[^{]*{/,"").replace(/(\w|\.?)(this\.\$super|this)/g,function(m,m2,m3){
if(!m2){
return m3+".$super"
}
return m;
});
funcStr = funcStr.substr(0,funcStr.length-1);
func = superClass[m] = eval("false||function("+funcArg.join(",")+"){"+funcStr+"}");
}
return function() {
var f = this.$this[m];
var t = this.$this;
var r = (t[m] = func).apply(t, arguments);
t[m] = f;
return r;
};
}
while(typeof t._$superClass != "undefined") {
t.$super = new Object;
t.$super.$this = this;
for(var x in t._$superClass.prototype) {
if (t._$superClass.prototype.hasOwnProperty(x)){
if (typeof this[x] == "undefined" && x !="$init") this[x] = t._$superClass.prototype[x];
if (x!='constructor' && x!='_$superClass' && typeof t._$superClass.prototype[x] == "function") {
t.$super[x] = superFunc(x, t._$superClass, t._$superClass.prototype[x]);
} else {
t.$super[x] = t._$superClass.prototype[x];
}
}
}
if (typeof t.$super.$init == "function") a[a.length] = t;
t = t.$super;
}
for(var i=a.length-1; i > -1; i--) a[i].$super.$init.apply(a[i].$super, arguments);
if (typeof this.$init == "function") this.$init.apply(this,arguments);
}
if (typeof oDef.$static != "undefined") {
var i=0, x;
for(x in oDef){
if (oDef.hasOwnProperty(x)) {
x=="$static"||i++;
}
}
for(x in oDef.$static){
if (oDef.$static.hasOwnProperty(x)) {
typeClass[x] = oDef.$static[x];
}
}
if (!i) return oDef.$static;
delete oDef.$static;
}
// if (typeof oDef.$destroy == "undefined") {
// oDef.$destroy = function(){
// if(this.$super&&(arguments.callee==this.$super.$destroy)){this.$super.$destroy();}
// }
// } else {
// oDef.$destroy = eval("false||"+oDef.$destroy.toString().replace(/\}$/,"console.log(this.$super);console.log(arguments.callee!=this.$super.$destroy);if(this.$super&&(arguments.callee==this.$destroy)){this.$super.$destroy();}}"));
// }
//
typeClass.prototype = oDef;
typeClass.prototype.constructor = typeClass;
typeClass.extend = jindo.$Class.extend;
return typeClass;
}
/**
* Ŭ·¡½º¸¦ »ó¼ÓÇÑ´Ù.
* ÇÏÀ§ Ŭ·¡½º´Â this.$super.method ·Î »óÀ§ Ŭ·¡½ºÀÇ ¸Þ¼µå¿¡ Á¢±ÙÇÒ ¼ö ÀÖÀ¸³ª, this.$super.$super.method ¿Í °°ÀÌ ÇÑ ´Ü°è ÀÌ»óÀÇ »óÀ§ Ŭ·¡½º´Â Á¢±ÙÇÒ ¼ö ¾ø´Ù.
* @name $Class#extend
* @type $Class
* @function
* @param {$Class} superClass ¼öÆÛ Ŭ·¡½º °´Ã¼
* @return {$Class} »ó¼ÓµÈ Ŭ·¡½º
* @description [Lite]
* @example
var ClassExt = $Class(classDefinition);
ClassExt.extend(superClass);
// ClassExt´Â SuperClass¸¦ »ó¼Ó¹Þ´Â´Ù.
*/
jindo.$Class.extend = function(superClass) {
// superClass._$has_super = true;
if (typeof superClass == "undefined" || superClass === null || !superClass.extend) {
throw new Error("extend½Ã ½´ÆÛ Ŭ·¡½º´Â Class¿©¾ß ÇÕ´Ï´Ù.");
}
this.prototype._$superClass = superClass;
// inherit static methods of parent
for(var x in superClass) {
if (superClass.hasOwnProperty(x)) {
if (x == "prototype") continue;
this[x] = superClass[x];
}
}
return this;
};
/**
ºÎ¸ð Ŭ·¡½ºÀÇ ¸Þ¼µå¿¡ Á¢±ÙÇÒ ¶§ »ç¿ëÇÑ´Ù. ºÎ¸ð Ŭ·¡½º¿Í ÀÚ½Ä Å¬·¡½º°¡ °°Àº À̸§ÀÇ ¸Þ¼µå¸¦ °¡Áö°í ÀÖ°í $super·Î ±× ¸Þ¼µå¸¦ È£ÃâÇϸé, ÀÚ½Ä Å¬·¡½ºÀÇ ¸Þ¼µå¸¦ »ç¿ëÇÑ´Ù.
@name $Class#$super
@type $Class
@example
var Parent = $Class ({
a: 100,
b: 200,
c: 300,
sum2: function () {
var init = this.sum();
return init;
},
sum: function () {
return this.a + this.b
}
});
var Child = $Class ({
a: 10,
b: 20,
sum2 : function () {
var init = this.sum();
return init;
},
sum: function () {
return this.b;
}
}).extend (Parent);
var oChild = new Child();
var oParent = new Parent();
oChild.sum(); // 20
oChild.sum2(); // 20
oChild.$super.sum(); // 30 -> ºÎ¸ð Ŭ·¡½ºÀÇ 100(a)°ú 200(b)´ë½Å ÀÚ½Ä Å¬·¡½ºÀÇ 10(a)°ú 20(b)À» ´õÇÑ´Ù.
oChild.$super.sum2(); // 20 -> ºÎ¸ð Ŭ·¡½ºÀÇ sum2 ¸Þ¼µå¿¡¼ ºÎ¸ð Ŭ·¡½ºÀÇ sum()ÀÌ ¾Æ´Ñ ÀÚ½Ä Å¬·¡½ºÀÇ sum()À» È£ÃâÇÑ´Ù.
*/
/**
* @fileOverview CSS ¼¿·ºÅ͸¦ »ç¿ëÇÑ ¿¤¸®¸ÕÆ® ¼±Åà ¿£Áø
* @name cssquery.js
* @author Hooriza
*/
/**
* CSS ¼¿·ºÅ͸¦ »ç¿ëÇÏ¿© °´Ã¼¸¦ Ž»öÇÑ´Ù.
*
* @function CSS ¼¿·ºÅ͸¦ »ç¿ëÇÏ¿© °´Ã¼¸¦ Ž»öÇÑ´Ù.
* @param {String} CSS¼¿·ºÅÍ
* @param {Element} Ž»ö ´ë»óÀÌ µÇ´Â ¿ä¼Ò, ¿ä¼ÒÀÇ ÇÏÀ§ ³ëµå¿¡¼¸¸ Ž»öÇÑ´Ù.
* @return {Array} Á¶°Ç¿¡ ÇØ´çÇÏ´Â ¿ä¼ÒÀÇ ¹è¿À» ¹ÝȯÇÑ´Ù.
* @description [Lite]
* @example
// ¹®¼¿¡¼ IMG ű׸¦ ã´Â´Ù.
var imgs = $$('IMG');
// div ¿ä¼Ò ÇÏÀ§¿¡¼ IMG ű׸¦ ã´Â´Ù.
var imgsInDiv = $$('IMG', $('div'));
// ¹®¼¿¡¼ IMG ÅÂ±× Áß °¡Àå ù ¿ä¼Ò¸¦ ã´Â´Ù.
var firstImg = $$.getSingle('IMG');
*/
jindo.$$ = jindo.cssquery = (function() {
/*
querySelector ¼³Á¤.
*/
var sVersion = '3.0';
var debugOption = { repeat : 1 };
/*
ºü¸¥ 󸮸¦ À§ÇØ ³ëµå¸¶´Ù À¯ÀÏŰ °ª ¼ÂÆÃ
*/
var UID = 1;
var cost = 0;
var validUID = {};
var bSupportByClassName = document.getElementsByClassName ? true : false;
var safeHTML = false;
var getUID4HTML = function(oEl) {
var nUID = safeHTML ? (oEl._cssquery_UID && oEl._cssquery_UID[0]) : oEl._cssquery_UID;
if (nUID && validUID[nUID] == oEl) return nUID;
nUID = UID++;
oEl._cssquery_UID = safeHTML ? [ nUID ] : nUID;
validUID[nUID] = oEl;
return nUID;
};
var getUID4XML = function(oEl) {
var oAttr = oEl.getAttribute('_cssquery_UID');
var nUID = safeHTML ? (oAttr && oAttr[0]) : oAttr;
if (!nUID) {
nUID = UID++;
oEl.setAttribute('_cssquery_UID', safeHTML ? [ nUID ] : nUID);
}
return nUID;
};
var getUID = getUID4HTML;
var uniqid = function(sPrefix) {
return (sPrefix || '') + new Date().getTime() + parseInt(Math.random() * 100000000,10);
};
function getElementsByClass(searchClass,node,tag) {
var classElements = new Array();
if ( node == null )
node = document;
if ( tag == null )
tag = '*';
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
for (i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
classElements[j] = els[i];
j++;
}
}
return classElements;
}
var getChilds_dontShrink = function(oEl, sTagName, sClassName) {
if (bSupportByClassName && sClassName) {
if(oEl.getElementsByClassName)
return oEl.getElementsByClassName(sClassName);
if(oEl.querySelectorAll)
return oEl.querySelectorAll(sClassName);
return getElementsByClass(sClassName, oEl, sTagName);
}else if (sTagName == '*') {
return oEl.all || oEl.getElementsByTagName(sTagName);
}
return oEl.getElementsByTagName(sTagName);
};
var clearKeys = function() {
backupKeys._keys = {};
};
var oDocument_dontShrink = document;
var bXMLDocument = false;
/*
µû¿ÈÇ¥, [] µî ÆÄ½Ì¿¡ ¹®Á¦°¡ µÉ ¼ö ÀÖ´Â ºÎºÐ replace ½ÃÄѳõ±â
*/
var backupKeys = function(sQuery) {
var oKeys = backupKeys._keys;
/*
ÀÛÀº µû¿ÈÇ¥ °È¾î³»±â
*/
sQuery = sQuery.replace(/'(\\'|[^'])*'/g, function(sAll) {
var uid = uniqid('QUOT');
oKeys[uid] = sAll;
return uid;
});
/*
Å« µû¿ÈÇ¥ °È¾î³»±â
*/
sQuery = sQuery.replace(/"(\\"|[^"])*"/g, function(sAll) {
var uid = uniqid('QUOT');
oKeys[uid] = sAll;
return uid;
});
/*
[ ] ÇüÅ °È¾î³»±â
*/
sQuery = sQuery.replace(/\[(.*?)\]/g, function(sAll, sBody) {
if (sBody.indexOf('ATTR') == 0) return sAll;
var uid = '[' + uniqid('ATTR') + ']';
oKeys[uid] = sAll;
return uid;
});
/*
( ) ÇüÅ °È¾î³»±â
*/
var bChanged;
do {
bChanged = false;
sQuery = sQuery.replace(/\(((\\\)|[^)|^(])*)\)/g, function(sAll, sBody) {
if (sBody.indexOf('BRCE') == 0) return sAll;
var uid = '_' + uniqid('BRCE');
oKeys[uid] = sAll;
bChanged = true;
return uid;
});
} while(bChanged);
return sQuery;
};
/*
replace ½ÃÄѳõÀº ºÎºÐ º¹±¸Çϱâ
*/
var restoreKeys = function(sQuery, bOnlyAttrBrace) {
var oKeys = backupKeys._keys;
var bChanged;
var rRegex = bOnlyAttrBrace ? /(\[ATTR[0-9]+\])/g : /(QUOT[0-9]+|\[ATTR[0-9]+\])/g;
do {
bChanged = false;
sQuery = sQuery.replace(rRegex, function(sKey) {
if (oKeys[sKey]) {
bChanged = true;
return oKeys[sKey];
}
return sKey;
});
} while(bChanged);
/*
( ) ´Â ÇѲ¨Ç®¸¸ ¹þ°Ü³»±â
*/
sQuery = sQuery.replace(/_BRCE[0-9]+/g, function(sKey) {
return oKeys[sKey] ? oKeys[sKey] : sKey;
});
return sQuery;
};
/*
replace ½ÃÄѳõÀº ¹®ÀÚ¿¿¡¼ Quot À» Á¦¿ÜÇÏ°í ¸®ÅÏ
*/
var restoreString = function(sKey) {
var oKeys = backupKeys._keys;
var sOrg = oKeys[sKey];
if (!sOrg) return sKey;
return eval(sOrg);
};
var wrapQuot = function(sStr) {
return '"' + sStr.replace(/"/g, '\\"') + '"';
};
var getStyleKey = function(sKey) {
if (/^@/.test(sKey)) return sKey.substr(1);
return null;
};
var getCSS = function(oEl, sKey) {
if (oEl.currentStyle) {
if (sKey == "float") sKey = "styleFloat";
return oEl.currentStyle[sKey] || oEl.style[sKey];
} else if (window.getComputedStyle) {
return oDocument_dontShrink.defaultView.getComputedStyle(oEl, null).getPropertyValue(sKey.replace(/([A-Z])/g,"-$1").toLowerCase()) || oEl.style[sKey];
}
if (sKey == "float" && /MSIE/.test(window.navigator.userAgent)) sKey = "styleFloat";
return oEl.style[sKey];
};
var oCamels = {
'accesskey' : 'accessKey',
'cellspacing' : 'cellSpacing',
'cellpadding' : 'cellPadding',
'class' : 'className',
'colspan' : 'colSpan',
'for' : 'htmlFor',
'maxlength' : 'maxLength',
'readonly' : 'readOnly',
'rowspan' : 'rowSpan',
'tabindex' : 'tabIndex',
'valign' : 'vAlign'
};
var getDefineCode = function(sKey) {
var sVal;
var sStyleKey;
if (bXMLDocument) {
sVal = 'oEl.getAttribute("' + sKey + '",2)';
} else {
if (sStyleKey = getStyleKey(sKey)) {
sKey = '$$' + sStyleKey;
sVal = 'getCSS(oEl, "' + sStyleKey + '")';
} else {
switch (sKey) {
case 'checked':
sVal = 'oEl.checked + ""';
break;
case 'disabled':
sVal = 'oEl.disabled + ""';
break;
case 'enabled':
sVal = '!oEl.disabled + ""';
break;
case 'readonly':
sVal = 'oEl.readOnly + ""';
break;
case 'selected':
sVal = 'oEl.selected + ""';
break;
default:
if (oCamels[sKey]) {
sVal = 'oEl.' + oCamels[sKey];
} else {
sVal = 'oEl.getAttribute("' + sKey + '",2)';
}
}
}
}
return '_' + sKey + ' = ' + sVal;
};
var getReturnCode = function(oExpr) {
var sStyleKey = getStyleKey(oExpr.key);
var sVar = '_' + (sStyleKey ? '$$' + sStyleKey : oExpr.key);
var sVal = oExpr.val ? wrapQuot(oExpr.val) : '';
switch (oExpr.op) {
case '~=':
return '(' + sVar + ' && (" " + ' + sVar + ' + " ").indexOf(" " + ' + sVal + ' + " ") > -1)';
case '^=':
return '(' + sVar + ' && ' + sVar + '.indexOf(' + sVal + ') == 0)';
case '$=':
return '(' + sVar + ' && ' + sVar + '.substr(' + sVar + '.length - ' + oExpr.val.length + ') == ' + sVal + ')';
case '*=':
return '(' + sVar + ' && ' + sVar + '.indexOf(' + sVal + ') > -1)';
case '!=':
return '(' + sVar + ' != ' + sVal + ')';
case '=':
return '(' + sVar + ' == ' + sVal + ')';
}
return '(' + sVar + ')';
};
var getNodeIndex = function(oEl) {
var nUID = getUID(oEl);
var nIndex = oNodeIndexes[nUID] || 0;
/*
³ëµå À妽º¸¦ ±¸ÇÒ ¼ö ¾øÀ¸¸é
*/
if (nIndex == 0) {
for (var oSib = (oEl.parentNode || oEl._IE5_parentNode).firstChild; oSib; oSib = oSib.nextSibling) {
if (oSib.nodeType != 1){
continue;
}
nIndex++;
setNodeIndex(oSib, nIndex);
}
nIndex = oNodeIndexes[nUID];
}
return nIndex;
};
/*
¸î¹øÂ° ÀÚ½ÄÀÎÁö ¼³Á¤ÇÏ´Â ºÎºÐ
*/
var oNodeIndexes = {};
var setNodeIndex = function(oEl, nIndex) {
var nUID = getUID(oEl);
oNodeIndexes[nUID] = nIndex;
};
var unsetNodeIndexes = function() {
setTimeout(function() { oNodeIndexes = {}; }, 0);
};
/*
°¡»ó Ŭ·¡½º
*/
var oPseudoes_dontShrink = {
'contains' : function(oEl, sOption) {
return (oEl.innerText || oEl.textContent || '').indexOf(sOption) > -1;
},
'last-child' : function(oEl, sOption) {
for (oEl = oEl.nextSibling; oEl; oEl = oEl.nextSibling){
if (oEl.nodeType == 1)
return false;
}
return true;
},
'first-child' : function(oEl, sOption) {
for (oEl = oEl.previousSibling; oEl; oEl = oEl.previousSibling){
if (oEl.nodeType == 1)
return false;
}
return true;
},
'only-child' : function(oEl, sOption) {
var nChild = 0;
for (var oChild = (oEl.parentNode || oEl._IE5_parentNode).firstChild; oChild; oChild = oChild.nextSibling) {
if (oChild.nodeType == 1) nChild++;
if (nChild > 1) return false;
}
return nChild ? true : false;
},
'empty' : function(oEl, _) {
return oEl.firstChild ? false : true;
},
'nth-child' : function(oEl, nMul, nAdd) {
var nIndex = getNodeIndex(oEl);
return nIndex % nMul == nAdd;
},
'nth-last-child' : function(oEl, nMul, nAdd) {
var oLast = (oEl.parentNode || oEl._IE5_parentNode).lastChild;
for (; oLast; oLast = oLast.previousSibling){
if (oLast.nodeType == 1) break;
}
var nTotal = getNodeIndex(oLast);
var nIndex = getNodeIndex(oEl);
var nLastIndex = nTotal - nIndex + 1;
return nLastIndex % nMul == nAdd;
},
'checked' : function(oEl){
return !!oEl.checked;
},
'selected' : function(oEl){
return !!oEl.selected;
},
'enabled' : function(oEl){
return !oEl.disabled;
},
'disabled' : function(oEl){
return !!oEl.disabled;
}
};
/*
´ÜÀÏ part ÀÇ body ¿¡¼ expression »Ì¾Æ³¿
*/
var getExpression = function(sBody) {
var oRet = { defines : '', returns : 'true' };
var sBody = restoreKeys(sBody, true);
var aExprs = [];
var aDefineCode = [], aReturnCode = [];
var sId, sTagName;
/*
À¯»çŬ·¡½º Á¶°Ç ¾ò¾î³»±â
*/
var sBody = sBody.replace(/:([\w-]+)(\(([^)]*)\))?/g, function(_1, sType, _2, sOption) {
switch (sType) {
case 'not':
/*
°ýÈ£ ¾È¿¡ Àִ°ŠÀç±ÍÆÄ½ÌÇϱâ
*/
var oInner = getExpression(sOption);
var sFuncDefines = oInner.defines;
var sFuncReturns = oInner.returnsID + oInner.returnsTAG + oInner.returns;
aReturnCode.push('!(function() { ' + sFuncDefines + ' return ' + sFuncReturns + ' })()');
break;
case 'nth-child':
case 'nth-last-child':
sOption = restoreString(sOption);
if (sOption == 'even'){
sOption = '2n';
}else if (sOption == 'odd') {
sOption = '2n+1';
}
var nMul, nAdd;
var matchstr = sOption.match(/([0-9]*)n([+-][0-9]+)*/);
if (matchstr) {
nMul = matchstr[1] || 1;
nAdd = matchstr[2] || 0;
} else {
nMul = Infinity;
nAdd = parseInt(sOption,10);
}
aReturnCode.push('oPseudoes_dontShrink[' + wrapQuot(sType) + '](oEl, ' + nMul + ', ' + nAdd + ')');
break;
case 'first-of-type':
case 'last-of-type':
sType = (sType == 'first-of-type' ? 'nth-of-type' : 'nth-last-of-type');
sOption = 1;
case 'nth-of-type':
case 'nth-last-of-type':
sOption = restoreString(sOption);
if (sOption == 'even') {
sOption = '2n';
}else if (sOption == 'odd'){
sOption = '2n+1';
}
var nMul, nAdd;
if (/([0-9]*)n([+-][0-9]+)*/.test(sOption)) {
nMul = parseInt(RegExp.$1,10) || 1;
nAdd = parseInt(RegExp.$2,20) || 0;
} else {
nMul = Infinity;
nAdd = parseInt(sOption,10);
}
oRet.nth = [ nMul, nAdd, sType ];
break;
default:
sOption = sOption ? restoreString(sOption) : '';
aReturnCode.push('oPseudoes_dontShrink[' + wrapQuot(sType) + '](oEl, ' + wrapQuot(sOption) + ')');
break;
}
return '';
});
/*
[key=value] ÇüÅ Á¶°Ç ¾ò¾î³»±â
*/
var sBody = sBody.replace(/\[(@?[\w-]+)(([!^~$*]?=)([^\]]*))?\]/g, function(_1, sKey, _2, sOp, sVal) {
sKey = restoreString(sKey);
sVal = restoreString(sVal);
if (sKey == 'checked' || sKey == 'disabled' || sKey == 'enabled' || sKey == 'readonly' || sKey == 'selected') {
if (!sVal) {
sOp = '=';
sVal = 'true';
}
}
aExprs.push({ key : sKey, op : sOp, val : sVal });
return '';
});
var sClassName = null;
/*
Ŭ·¡½º Á¶°Ç ¾ò¾î³»±â
*/
var sBody = sBody.replace(/\.([\w-]+)/g, function(_, sClass) {
aExprs.push({ key : 'class', op : '~=', val : sClass });
if (!sClassName) sClassName = sClass;
return '';
});
/*
id Á¶°Ç ¾ò¾î³»±â
*/
var sBody = sBody.replace(/#([\w-]+)/g, function(_, sIdValue) {
if (bXMLDocument) {
aExprs.push({ key : 'id', op : '=', val : sIdValue });
}else{
sId = sIdValue;
}
return '';
});
sTagName = sBody == '*' ? '' : sBody;
/*
match ÇÔ¼ö ÄÚµå ¸¸µé¾î ³»±â
*/
var oVars = {};
for (var i = 0, oExpr; oExpr = aExprs[i]; i++) {
var sKey = oExpr.key;
if (!oVars[sKey]) aDefineCode.push(getDefineCode(sKey));
/*
À¯»çŬ·¡½º Á¶°Ç °Ë»ç°¡ ¸Ç µÚ·Î °¡µµ·Ï unshift »ç¿ë
*/
aReturnCode.unshift(getReturnCode(oExpr));
oVars[sKey] = true;
}
if (aDefineCode.length) oRet.defines = 'var ' + aDefineCode.join(',') + ';';
if (aReturnCode.length) oRet.returns = aReturnCode.join('&&');
oRet.quotID = sId ? wrapQuot(sId) : '';
oRet.quotTAG = sTagName ? wrapQuot(bXMLDocument ? sTagName : sTagName.toUpperCase()) : '';
if (bSupportByClassName) oRet.quotCLASS = sClassName ? wrapQuot(sClassName) : '';
oRet.returnsID = sId ? 'oEl.id == ' + oRet.quotID + ' && ' : '';
oRet.returnsTAG = sTagName && sTagName != '*' ? 'oEl.tagName == ' + oRet.quotTAG + ' && ' : '';
return oRet;
};
/*
Äõ¸®¸¦ ¿¬»êÀÚ ±âÁØÀ¸·Î Àß¶ó³¿
*/
var splitToParts = function(sQuery) {
var aParts = [];
var sRel = ' ';
var sBody = sQuery.replace(/(.*?)\s*(!?[+>~ ]|!)\s*/g, function(_, sBody, sRelative) {
if (sBody) aParts.push({ rel : sRel, body : sBody });
sRel = sRelative.replace(/\s+$/g, '') || ' ';
return '';
});
if (sBody) aParts.push({ rel : sRel, body : sBody });
return aParts;
};
var isNth_dontShrink = function(oEl, sTagName, nMul, nAdd, sDirection) {
var nIndex = 0;
for (var oSib = oEl; oSib; oSib = oSib[sDirection]){
if (oSib.nodeType == 1 && (!sTagName || sTagName == oSib.tagName))
nIndex++;
}
return nIndex % nMul == nAdd;
};
/*
Àß¶ó³½ part ¸¦ ÇÔ¼ö·Î ÄÄÆÄÀÏ Çϱâ
*/
var compileParts = function(aParts) {
var aPartExprs = [];
/*
Àß¶ó³½ ºÎºÐµé Á¶°Ç ¸¸µé±â
*/
for (var i = 0, oPart; oPart = aParts[i]; i++)
aPartExprs.push(getExpression(oPart.body));
//////////////////// BEGIN
var sFunc = '';
var sPushCode = 'aRet.push(oEl); if (oOptions.single) { bStop = true; }';
for (var i = aParts.length - 1, oPart; oPart = aParts[i]; i--) {
var oExpr = aPartExprs[i];
var sPush = (debugOption.callback ? 'cost++;' : '') + oExpr.defines;
var sReturn = 'if (bStop) {' + (i == 0 ? 'return aRet;' : 'return;') + '}';
if (oExpr.returns == 'true') {
sPush += (sFunc ? sFunc + '(oEl);' : sPushCode) + sReturn;
}else{
sPush += 'if (' + oExpr.returns + ') {' + (sFunc ? sFunc + '(oEl);' : sPushCode ) + sReturn + '}';
}
var sCheckTag = 'oEl.nodeType != 1';
if (oExpr.quotTAG) sCheckTag = 'oEl.tagName != ' + oExpr.quotTAG;
var sTmpFunc =
'(function(oBase' +
(i == 0 ? ', oOptions) { var bStop = false; var aRet = [];' : ') {');
if (oExpr.nth) {
sPush =
'if (isNth_dontShrink(oEl, ' +
(oExpr.quotTAG ? oExpr.quotTAG : 'false') + ',' +
oExpr.nth[0] + ',' +
oExpr.nth[1] + ',' +
'"' + (oExpr.nth[2] == 'nth-of-type' ? 'previousSibling' : 'nextSibling') + '")) {' + sPush + '}';
}
switch (oPart.rel) {
case ' ':
if (oExpr.quotID) {
sTmpFunc +=
'var oEl = oDocument_dontShrink.getElementById(' + oExpr.quotID + ');' +
'var oCandi = oEl;' +
'for (; oCandi; oCandi = (oCandi.parentNode || oCandi._IE5_parentNode)) {' +
'if (oCandi == oBase) break;' +
'}' +
'if (!oCandi || ' + sCheckTag + ') return aRet;' +
sPush;
} else {
sTmpFunc +=
'var aCandi = getChilds_dontShrink(oBase, ' + (oExpr.quotTAG || '"*"') + ', ' + (oExpr.quotCLASS || 'null') + ');' +
'for (var i = 0, oEl; oEl = aCandi[i]; i++) {' +
(oExpr.quotCLASS ? 'if (' + sCheckTag + ') continue;' : '') +
sPush +
'}';
}
break;
case '>':
if (oExpr.quotID) {
sTmpFunc +=
'var oEl = oDocument_dontShrink.getElementById(' + oExpr.quotID + ');' +
'if ((oEl.parentNode || oEl._IE5_parentNode) != oBase || ' + sCheckTag + ') return aRet;' +
sPush;
} else {
sTmpFunc +=
'for (var oEl = oBase.firstChild; oEl; oEl = oEl.nextSibling) {' +
'if (' + sCheckTag + ') { continue; }' +
sPush +
'}';
}
break;
case '+':
if (oExpr.quotID) {
sTmpFunc +=
'var oEl = oDocument_dontShrink.getElementById(' + oExpr.quotID + ');' +
'var oPrev;' +
'for (oPrev = oEl.previousSibling; oPrev; oPrev = oPrev.previousSibling) { if (oPrev.nodeType == 1) break; }' +
'if (!oPrev || oPrev != oBase || ' + sCheckTag + ') return aRet;' +
sPush;
} else {
sTmpFunc +=
'for (var oEl = oBase.nextSibling; oEl; oEl = oEl.nextSibling) { if (oEl.nodeType == 1) break; }' +
'if (!oEl || ' + sCheckTag + ') { return aRet; }' +
sPush;
}
break;
case '~':
if (oExpr.quotID) {
sTmpFunc +=
'var oEl = oDocument_dontShrink.getElementById(' + oExpr.quotID + ');' +
'var oCandi = oEl;' +
'for (; oCandi; oCandi = oCandi.previousSibling) { if (oCandi == oBase) break; }' +
'if (!oCandi || ' + sCheckTag + ') return aRet;' +
sPush;
} else {
sTmpFunc +=
'for (var oEl = oBase.nextSibling; oEl; oEl = oEl.nextSibling) {' +
'if (' + sCheckTag + ') { continue; }' +
'if (!markElement_dontShrink(oEl, ' + i + ')) { break; }' +
sPush +
'}';
}
break;
case '!' :
if (oExpr.quotID) {
sTmpFunc +=
'var oEl = oDocument_dontShrink.getElementById(' + oExpr.quotID + ');' +
'for (; oBase; oBase = (oBase.parentNode || oBase._IE5_parentNode)) { if (oBase == oEl) break; }' +
'if (!oBase || ' + sCheckTag + ') return aRet;' +
sPush;
} else {
sTmpFunc +=
'for (var oEl = (oBase.parentNode || oBase._IE5_parentNode); oEl; oEl = (oEl.parentNode || oEl._IE5_parentNode)) {'+
'if (' + sCheckTag + ') { continue; }' +
sPush +
'}';
}
break;
case '!>' :
if (oExpr.quotID) {
sTmpFunc +=
'var oEl = oDocument_dontShrink.getElementById(' + oExpr.quotID + ');' +
'var oRel = (oBase.parentNode || oBase._IE5_parentNode);' +
'if (!oRel || oEl != oRel || (' + sCheckTag + ')) return aRet;' +
sPush;
} else {
sTmpFunc +=
'var oEl = (oBase.parentNode || oBase._IE5_parentNode);' +
'if (!oEl || ' + sCheckTag + ') { return aRet; }' +
sPush;
}
break;
case '!+' :
if (oExpr.quotID) {
sTmpFunc +=
'var oEl = oDocument_dontShrink.getElementById(' + oExpr.quotID + ');' +
'var oRel;' +
'for (oRel = oBase.previousSibling; oRel; oRel = oRel.previousSibling) { if (oRel.nodeType == 1) break; }' +
'if (!oRel || oEl != oRel || (' + sCheckTag + ')) return aRet;' +
sPush;
} else {
sTmpFunc +=
'for (oEl = oBase.previousSibling; oEl; oEl = oEl.previousSibling) { if (oEl.nodeType == 1) break; }' +
'if (!oEl || ' + sCheckTag + ') { return aRet; }' +
sPush;
}
break;
case '!~' :
if (oExpr.quotID) {
sTmpFunc +=
'var oEl = oDocument_dontShrink.getElementById(' + oExpr.quotID + ');' +
'var oRel;' +
'for (oRel = oBase.previousSibling; oRel; oRel = oRel.previousSibling) { ' +
'if (oRel.nodeType != 1) { continue; }' +
'if (oRel == oEl) { break; }' +
'}' +
'if (!oRel || (' + sCheckTag + ')) return aRet;' +
sPush;
} else {
sTmpFunc +=
'for (oEl = oBase.previousSibling; oEl; oEl = oEl.previousSibling) {' +
'if (' + sCheckTag + ') { continue; }' +
'if (!markElement_dontShrink(oEl, ' + i + ')) { break; }' +
sPush +
'}';
}
break;
}
sTmpFunc +=
(i == 0 ? 'return aRet;' : '') +
'})';
sFunc = sTmpFunc;
}
eval('var fpCompiled = ' + sFunc + ';');
return fpCompiled;
};
/*
Äõ¸®¸¦ match ÇÔ¼ö·Î º¯È¯
*/
var parseQuery = function(sQuery) {
var sCacheKey = sQuery;
var fpSelf = arguments.callee;
var fpFunction = fpSelf._cache[sCacheKey];
if (!fpFunction) {
sQuery = backupKeys(sQuery);
var aParts = splitToParts(sQuery);
fpFunction = fpSelf._cache[sCacheKey] = compileParts(aParts);
fpFunction.depth = aParts.length;
}
return fpFunction;
};
parseQuery._cache = {};
/*
test Äõ¸®¸¦ match ÇÔ¼ö·Î º¯È¯
*/
var parseTestQuery = function(sQuery) {
var fpSelf = arguments.callee;
var aSplitQuery = backupKeys(sQuery).split(/\s*,\s*/);
var aResult = [];
var nLen = aSplitQuery.length;
var aFunc = [];
for (var i = 0; i < nLen; i++) {
aFunc.push((function(sQuery) {
var sCacheKey = sQuery;
var fpFunction = fpSelf._cache[sCacheKey];
if (!fpFunction) {
sQuery = backupKeys(sQuery);
var oExpr = getExpression(sQuery);
eval('fpFunction = function(oEl) { ' + oExpr.defines + 'return (' + oExpr.returnsID + oExpr.returnsTAG + oExpr.returns + '); };');
}
return fpFunction;
})(restoreKeys(aSplitQuery[i])));
}
return aFunc;
};
parseTestQuery._cache = {};
var distinct = function(aList) {
var aDistinct = [];
var oDummy = {};
for (var i = 0, oEl; oEl = aList[i]; i++) {
var nUID = getUID(oEl);
if (oDummy[nUID]) continue;
aDistinct.push(oEl);
oDummy[nUID] = true;
}
return aDistinct;
};
var markElement_dontShrink = function(oEl, nDepth) {
var nUID = getUID(oEl);
if (cssquery._marked[nDepth][nUID]) return false;
cssquery._marked[nDepth][nUID] = true;
return true;
};
var oResultCache = null;
var bUseResultCache = false;
var bExtremeMode = false;
var old_cssquery = function(sQuery, oParent, oOptions) {
if (typeof sQuery == 'object') {
var oResult = {};
for (var k in sQuery){
if(sQuery.hasOwnProperty(k))
oResult[k] = arguments.callee(sQuery[k], oParent, oOptions);
}
return oResult;
}
cost = 0;
var executeTime = new Date().getTime();
var aRet;
for (var r = 0, rp = debugOption.repeat; r < rp; r++) {
aRet = (function(sQuery, oParent, oOptions) {
if(oOptions){
if(!oOptions.oneTimeOffCache){
oOptions.oneTimeOffCache = false;
}
}else{
oOptions = {oneTimeOffCache:false};
}
cssquery.safeHTML(oOptions.oneTimeOffCache);
if (!oParent) oParent = document;
/*
ownerDocument Àâ¾ÆÁÖ±â
*/
oDocument_dontShrink = oParent.ownerDocument || oParent.document || oParent;
/*
ºê¶ó¿ìÀú ¹öÁ¯ÀÌ IE5.5 ÀÌÇÏ
*/
if (/\bMSIE\s([0-9]+(\.[0-9]+)*);/.test(navigator.userAgent) && parseFloat(RegExp.$1) < 6) {
try { oDocument_dontShrink.location; } catch(e) { oDocument_dontShrink = document; }
oDocument_dontShrink.firstChild = oDocument_dontShrink.getElementsByTagName('html')[0];
oDocument_dontShrink.firstChild._IE5_parentNode = oDocument_dontShrink;
}
/*
XMLDocument ÀÎÁö üũ
*/
bXMLDocument = (typeof XMLDocument != 'undefined') ? (oDocument_dontShrink.constructor === XMLDocument) : (!oDocument_dontShrink.location);
getUID = bXMLDocument ? getUID4XML : getUID4HTML;
clearKeys();
/*
Äõ¸®¸¦ ½°Ç¥·Î ³ª´©±â
*/
var aSplitQuery = backupKeys(sQuery).split(/\s*,\s*/);
var aResult = [];
var nLen = aSplitQuery.length;
for (var i = 0; i < nLen; i++)
aSplitQuery[i] = restoreKeys(aSplitQuery[i]);
/*
½°Ç¥·Î ³ª´²Áø Äõ¸® ·çÇÁ
*/
for (var i = 0; i < nLen; i++) {
var sSingleQuery = aSplitQuery[i];
var aSingleQueryResult = null;
var sResultCacheKey = sSingleQuery + (oOptions.single ? '_single' : '');
/*
°á°ú ij½¬ µÚÁü
*/
var aCache = bUseResultCache ? oResultCache[sResultCacheKey] : null;
if (aCache) {
/*
ij½ÌµÇ¾î ÀÖ´Â°Ô ÀÖÀ¸¸é parent °¡ °°Àº°ÇÁö °Ë»çÇÑÈÄ aSingleQueryResult ¿¡ ´ëÀÔ
*/
for (var j = 0, oCache; oCache = aCache[j]; j++) {
if (oCache.parent == oParent) {
aSingleQueryResult = oCache.result;
break;
}
}
}
if (!aSingleQueryResult) {
var fpFunction = parseQuery(sSingleQuery);
// alert(fpFunction);
cssquery._marked = [];
for (var j = 0, nDepth = fpFunction.depth; j < nDepth; j++)
cssquery._marked.push({});
// console.log(fpFunction.toSource());
aSingleQueryResult = distinct(fpFunction(oParent, oOptions));
/*
°á°ú ij½¬¸¦ »ç¿ëÁßÀ̸é ij½¬¿¡ ÀúÀå
*/
if (bUseResultCache&&!oOptions.oneTimeOffCache) {
if (!(oResultCache[sResultCacheKey] instanceof Array)) oResultCache[sResultCacheKey] = [];
oResultCache[sResultCacheKey].push({ parent : oParent, result : aSingleQueryResult });
}
}
aResult = aResult.concat(aSingleQueryResult);
}
unsetNodeIndexes();
return aResult;
})(sQuery, oParent, oOptions);
}
executeTime = new Date().getTime() - executeTime;
if (debugOption.callback) debugOption.callback(sQuery, cost, executeTime);
return aRet;
};
var cssquery;
if (document.querySelectorAll) {
function _isNonStandardQueryButNotException(sQuery){
return /\[\s*(?:checked|selected|disabled)/.test(sQuery)
}
function _commaRevise (sQuery,sChange) {
return sQuery.replace(/\,/gi,sChange);
}
var protoSlice = Array.prototype.slice;
var _toArray = function(aArray){
return protoSlice.apply(aArray);
}
try{
protoSlice.apply(document.documentElement.childNodes);
}catch(e){
_toArray = function(aArray){
var returnArray = [];
var leng = aArray.length;
for ( var i = 0; i < leng; i++ ) {
returnArray.push( aArray[i] );
}
return returnArray;
}
}
/**
*/
cssquery = function(sQuery, oParent, oOptions){
oParent = oParent || document ;
try{
if (_isNonStandardQueryButNotException(sQuery)) {
throw Error("None Standard Query");
}else{
var sReviseQuery = sQuery;
var oReviseParent = oParent;
if (oParent.nodeType != 9) {
if(bExtremeMode){
if(!oParent.id) oParent.id = "p"+ new Date().getTime() + parseInt(Math.random() * 100000000,10);
}else{
throw Error("Parent Element has not ID.or It is not document.or None Extreme Mode.");
}
sReviseQuery = _commaRevise("#"+oParent.id+" "+sQuery,", #"+oParent.id);
oReviseParent = oParent.ownerDocument||oParent.document||document;
}
if (oOptions&&oOptions.single) {
return [oReviseParent.querySelector(sReviseQuery)];
}else{
return _toArray(oReviseParent.querySelectorAll(sReviseQuery));
}
}
}catch(e){
return old_cssquery(sQuery, oParent, oOptions);
}
}
}else{
cssquery = old_cssquery;
}
/**
* ƯÁ¤ ¿¤¸®¸ÕÆ®°¡ ÇØ´ç CSS ¼¿·ºÅÍ¿¡ ºÎÇÕÇÏ´Â ¿¤¸®¸ÕÆ®ÀÎÁö ÆÇ´ÜÇÑ´Ù
* @remark CSS ¼¿·ºÅÍ¿¡ ¿¬°áÀÚ´Â »ç¿ëÇÒ ¼ö ¾øÀ½¿¡ À¯ÀÇÇÑ´Ù.
* @param {Element} element °Ë»çÇϰíÀÚ ÇÏ´Â ¿¤¸®¸ÕÆ®
* @param {String} selector CSS ¼¿·ºÅÍ
* @return {Boolean} ¼¿·ºÅÍ Á¶°Ç¿¡ ºÎÇÕÇϸé true, ºÎÇÕÇÏÁö ¾ÊÀ¸¸é false
* @example
// oEl ÀÌ div ÅÂ±× ¶Ç´Â p ű×, ¶Ç´Â align=center ÀÎ ¿¤¸®¸ÕÆ®ÀÎÁö
if (cssquery.test(oEl, 'div, p, [align=center]')) alert('ÇØ´ç Á¶°Ç ¸¸Á·');// oEl ÀÌ div ÅÂ±× ¶Ç´Â p ű×, ¶Ç´Â align=center ÀÎ ¿¤¸®¸ÕÆ®ÀÎÁö
if (cssquery.test(oEl, 'div, p, [align=center]')) alert('ÇØ´ç Á¶°Ç ¸¸Á·');
*/
cssquery.test = function(oEl, sQuery) {
clearKeys();
var aFunc = parseTestQuery(sQuery);
for (var i = 0, nLen = aFunc.length; i < nLen; i++){
if (aFunc[i](oEl)) return true;
}
return false;
};
/**
* cssquery ¿¡ °á°ú ij½¬¸¦ »ç¿ëÇÒ °ÍÀÎÁö ÁöÁ¤Çϰųª È®ÀÎÇÑ´Ù.
* @remark °á°ú ij½¬¸¦ »ç¿ëÇÏ¸é µ¿ÀÏÇÑ ¼¿·ºÅ͸¦ »ç¿ëÇßÀ» °æ¿ì »õ·Î Ž»öÀ» ÇÏÁö ¾Ê°í ±âÁ¸ Ž»ö °á°ú¸¦ ±×´ë·Î ¹ÝȯÇϱ⠶§¹®¿¡ »ç¿ëÀÚ°¡ º¯¼ö ij½¬¿¡ ½Å°æ¾²Áö ¾Ê°í ÆíÇÏ°í ºü¸£°Ô ¾µ ¼ö ÀÖ´Â ÀåÁ¡ÀÌ ÀÖÁö¸¸ °á°úÀÇ ½Å·Ú¼ºÀ» À§ÇØ DOM ¿¡ º¯È°¡ ¾ø´Ù´Â °ÍÀÌ È®½ÇÇÒ¶§¸¸ »ç¿ëÇØ¾ß ÇÑ´Ù.
* @param {Boolean} flag »ç¿ëÇÒ °Í ÀÎÁö ¿©ºÎ (»ý·«½Ã »ç¿ë ¿©ºÎ¸¸ ¹Ýȯ)
* @return {Boolean} °á°ú ij½¬¸¦ »ç¿ëÇÏ´ÂÁö ¿©ºÎ
*/
cssquery.useCache = function(bFlag) {
if (typeof bFlag != 'undefined') {
bUseResultCache = bFlag;
cssquery.clearCache();
}
return bUseResultCache;
};
/**
* °á°ú ij½¬¸¦ »ç¿ë Áß¿¡ DOM ÀÇ º¯È°¡ »ý±â´Â µîÀÇ ÀÌÀ¯·Î ij½¬¸¦ ¸ðµÎ ºñ¿öÁÖ°í ½ÍÀ»¶§ »ç¿ëÇÑ´Ù.
* @return {Void} ¹Ýȯ°ª ¾øÀ½
*/
cssquery.clearCache = function() {
oResultCache = {};
};
/**
* CSS ¼¿·ºÅ͸¦ »ç¿ëÇÏ¿© DOM ¿¡¼ ¿øÇÏ´Â ¿¤¸®¸ÕÆ®¸¦ Çϳª¸¸ ¾ò¾î³½´Ù. ¹ÝȯÇÏ´Â °ªÀº ¹è¿ÀÌ ¾Æ´Ñ °´Ã¼ ¶Ç´Â null ÀÌ´Ù.
* @remark °á°ú¸¦ Çϳª¸¸ ¾ò¾î³»¸é ÀÌÈÄÀÇ ¸ðµç Ž»ö ÀÛ¾÷À» Áß´ÜÇϱ⠶§¹®¿¡ °á°ú°¡ Çϳª¶ó´Â º¸ÀåÀÌ ÀÖÀ»¶§ ºü¸¥ ¼Óµµ·Î °á°ú¸¦ ¾ò¾î¿Ã ¼ö ÀÖ´Ù.
* @param {String} selector CSS ¼¿·ºÅÍ
* @param {Document | Element} el Ž»öÀ» ÁøÇàÇÏ´Â ±âÁØÀÌ µÇ´Â ¿¤¸®¸ÕÆ® ¶Ç´Â ¹®¼ (»ý·«½Ã ÇöÀç ¹®¼ÀÇ document °´Ã¼)
* @param {Object} ¿ÀºêÁ§Æ®¿¡ onTimeOffCache¸¦ true·Î Çϸé ÇØ´ç Äõ¸®´Â cache¸¦ »ç¿ëÇÏÁö ¾Ê´Â´Ù.
* @return {Element} ¼±ÅÃµÈ ¿¤¸®¸ÕÆ®
*/
cssquery.getSingle = function(sQuery, oParent, oOptions) {
return cssquery(sQuery, oParent, { single : true ,oneTimeOffCache:oOptions?(!!oOptions.oneTimeOffCache):false})[0] || null;
};
/**
* XPath ¹®¹ýÀ» »ç¿ëÇÏ¿© ¿¤¸®¸ÕÆ®¸¦ ¾ò¾î¿Â´Ù.
* @remark Áö¿øÇÏ´Â ¹®¹ýÀÌ ¹«Ã´ Á¦ÇÑÀûÀ¸·Î Ư¼öÇÑ °æ¿ì¿¡¼¸¸ »ç¿ëÇÏ´Â °ÍÀ» ±ÇÀåÇÑ´Ù.
* @param {String} xpath XPath
* @param {Document | Element} el Ž»öÀ» ÁøÇàÇÏ´Â ±âÁØÀÌ µÇ´Â ¿¤¸®¸ÕÆ® ¶Ç´Â ¹®¼ (»ý·«½Ã ÇöÀç ¹®¼ÀÇ document °´Ã¼)
* @return {Array} ¼±ÅÃµÈ ¿¤¸®¸ÕÆ® ¸ñ·ÏÀÇ ¹è¿
*/
cssquery.xpath = function(sXPath, oParent) {
var sXPath = sXPath.replace(/\/(\w+)(\[([0-9]+)\])?/g, function(_1, sTag, _2, sTh) {
sTh = sTh || '1';
return '>' + sTag + ':nth-of-type(' + sTh + ')';
});
return old_cssquery(sXPath, oParent);
};
/**
* cssquery ¸¦ »ç¿ëÇÒ ¶§ÀÇ ¼º´ÉÀ» ÃøÁ¤Çϱâ À§ÇÑ ¹æ¹ýÀ» Á¦°øÇÏ´Â ÇÔ¼öÀÌ´Ù.
* @param {Function} callback ¼¿·ºÅÍ ½ÇÇà¿¡ ¼Ò¿äµÈ ºñ¿ë°ú ½Ã°£À» ¹Þ¾ÆµéÀÌ´Â ÇÔ¼ö (false ÀÎ °æ¿ì debug ¿É¼ÇÀ» ²û)
* @param {Number} repeat ÇϳªÀÇ ¼¿·ºÅ͸¦ ¹Ýº¹ÇÏ¿© ¼öÇàÇϵµ·Ï ÇØ¼ ÀÎÀ§ÀûÀ¸·Î ½ÇÇà ¼Óµµ¸¦ ´ÊÃã
* @remark callback ÇÔ¼öÀÇ ÇüÅ´ ¾Æ·¡¿Í °°½À´Ï´Ù.
* callback : function({String}query, {Number}cost, {Number}executeTime)
* <dl>
* <dt>query</dt>
* <dd>½ÇÇà¿¡ »ç¿ëµÈ ¼¿·ºÅÍ</dd>
* <dt>cost</dt>
* <dd>Ž»ö¿¡ »ç¿ëµÈ ºñ¿ë (·çÇÁ Ƚ¼ö)</dd>
* <dt>executeTime</dt>
* <dd>Ž»ö¿¡ ¼Ò¿äµÈ ½Ã°£</dd>
* </dl>
* @return {Void} ¹Ýȯ°ª ¾øÀ½
* @example
cssquery.debug(function(sQuery, nCost, nExecuteTime) {
if (nCost > 5000)
console.warn('5000 ÀÌ ³Ñ´Â ºñ¿ëÀÌ?! Ã¼Å©ÇØº¸ÀÚ -> ' + sQuery + '/' + nCost);
else if (nExecuteTime > 200)
console.warn('0.2Ãʰ¡ ³Ñ°Ô ½ÇÇàÀ»?! Ã¼Å©ÇØº¸ÀÚ -> ' + sQuery + '/' + nExecuteTime);
}, 20);
....
cssquery.debug(false);
*/
cssquery.debug = function(fpCallback, nRepeat) {
debugOption.callback = fpCallback;
debugOption.repeat = nRepeat || 1;
};
/**
* IE ¿¡¼ innerHTML À» ¾µ¶§ _cssquery_UID ³ª¿ÀÁö ¾Êµµ·Ï ÇÏ´Â ÇÔ¼öÀÌ´Ù.
* true ·Î ¼³Á¤ÇÏ¸é ±×¶§ºÎÅÍ Å½»öÇÏ´Â ³ëµå¿¡ ´ëÇØ¼´Â innerHTML ¿¡ _cssquery_UID °¡ ³ª¿ÀÁö ¾Êµµ·Ï ÇÏÁö¸¸ Ž»ö¼Óµµ´Â ´Ù¼Ò ´À·ÁÁú ¼ö ÀÖ´Ù.
* @param {Boolean} flag true ·Î ¼ÂÆÃÇϸé _cssquery_UID °¡ ³ª¿ÀÁö ¾ÊÀ½
* @return {Boolean} _cssquery_UID °¡ ³ª¿ÀÁö ¾Ê´Â »óÅÂÀ̸é true ¹Ýȯ
*/
cssquery.safeHTML = function(bFlag) {
var bIE = /MSIE/.test(window.navigator.userAgent);
if (arguments.length > 0)
safeHTML = bFlag && bIE;
return safeHTML || !bIE;
};
/**
* cssquery ÀÇ ¹öÁ¯Á¤º¸¸¦ ´ã°í ÀÖ´Â ¹®ÀÚ¿ÀÌ´Ù.
*/
cssquery.version = sVersion;
/**
* IE¿¡¼ validUID,cache¸¦ »ç¿ëÇßÀ»¶§ ¸Þ¸ð¸® ´ÐÀÌ ¹ß»ýÇÏ¿© »èÁ¦ÇÏ´Â ¸ðµâ Ãß°¡.
*/
cssquery.release = function() {
if(/MSIE/.test(window.navigator.userAgent)){
delete validUID;
validUID = {};
if(bUseResultCache){
cssquery.clearCache();
}
}
};
/**
* cache°¡ »èÁ¦°¡ µÇ´ÂÁö È®ÀÎÇϱâ À§ÇØ ÇÊ¿äÇÑ ÇÔ¼ö
* @ignore
*/
cssquery._getCacheInfo = function(){
return {
uidCache : validUID,
eleCache : oResultCache
}
}
/**
* Å×½ºÆ®¸¦ À§ÇØ ÇÊ¿äÇÑ ÇÔ¼ö
* @ignore
*/
cssquery._resetUID = function(){
UID = 0
}
/**
* querySelector°¡ ÀÖ´Â ºê¶ó¿ìÁ®¿¡¼ extremeÀ» ½ÇÇà½Ã۸é querySelectorÀ» »ç¿ëÇÒ¼ö ÀÖ´Â Ä¿¹ö¸®Áö°¡ ³ô¾ÆÁ® ÀüüÀûÀ¸·Î ¼Óµµ°¡ »¡¸®Áø´Ù.
* ÇÏÁö¸¸ ID°¡ ¾ø´Â ¿¤¸®¸ÕÆ®¸¦ ±âÁØ ¿¤¸®¸ÕÆ®·Î ³Ö¾úÀ» ¶§ ±âÁØ ¿¤¸®¸ÕÆ®¿¡ ÀÓÀÇÀÇ ¾ÆÀ̵𰡠µé¾î°£´Ù.
* @param {Boolean} bExtreme true
*/
cssquery.extreme = function(bExtreme){
if(arguments.length == 0){
bExtreme = true;
}
bExtremeMode = bExtreme;
}
return cssquery;
})();
/**
* @fileOverview $AgentÀÇ »ý¼ºÀÚ ¹× ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
*/
/**
* Agent °´Ã¼¸¦ ¹ÝȯÇÑ´Ù. Agent °´Ã¼´Â ºê¶ó¿ìÀú¿Í OS¿¡ ´ëÇÑ Á¤º¸¸¦ °¡Áø´Ù.
* @class Agent °´Ã¼´Â ¿î¿µÃ¼Á¦, ºê¶ó¿ìÀú¸¦ ºñ·ÔÇÑ »ç¿ëÀÚ ½Ã½ºÅÛÀÇ Á¤º¸¸¦ °¡Áø´Ù.
* @constructor
* @author Kim, Taegon
*/
jindo.$Agent = function() {
var cl = arguments.callee;
var cc = cl._cached;
if (cc) return cc;
if (!(this instanceof cl)) return new cl;
if (!cc) cl._cached = this;
this._navigator = navigator;
}
/**
* navigator ¸Þ¼µå´Â À¥ ºê¶ó¿ìÀúÀÇ Á¤º¸ °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @return {Object} À¥ ºê¶ó¿ìÀú Á¤º¸¸¦ ÀúÀåÇÏ´Â °´Ã¼. <br>
* object´Â ºê¶ó¿ìÀú À̸§°ú ¹öÀüÀ» ¼Ó¼ºÀ¸·Î °¡Áø´Ù. ºê¶ó¿ìÀú À̸§Àº ¿µ¾î ¼Ò¹®ÀڷΠǥ½ÃÇϸç, »ç¿ëÀÚÀÇ ºê¶ó¿ìÀú¿Í ÀÏÄ¡ÇÏ´Â ºê¶ó¿ìÀú À̸§Àº true¸¦ °¡Áø´Ù.
* @since 1.4.3 ºÎÅÍ mobile,msafari,mopera,mie »ç¿ë °¡´É.
* @since 1.4.5 ºÎÅÍ ipad¿¡¼ mobileÀº false¸¦ ¹Ýȯ ÇÑ´Ù.
* @example
oAgent = $Agent().navigator(); // »ç¿ëÀÚ°¡ ÆÄÀÌ¾îÆø½º 3¸¦ »ç¿ëÇÑ´Ù°í °¡Á¤ÇÑ´Ù.
oAgent.camino // false
oAgent.firefox // true
oAgent.konqueror // false
oAgent.mozilla //true
oAgent.netscape // false
oAgent.omniweb //false
oAgent.opera //false
oAgent.webkit /false
oAgent.safari //false
oAgent.ie //false
oAgent.chrome //false
oAgent.icab //false
oAgent.version //3
oAgent.nativeVersion //-1 (1.4.2ºÎÅÍ »ç¿ë °¡´É, IE8¿¡¼ ȣȯ ¸ðµå »ç¿ë½Ã nativeVersionÀº 8·Î ³ª¿È.)
oAgent.getName() // firefox
*/
jindo.$Agent.prototype.navigator = function() {
var info = new Object;
var ver = -1;
var nativeVersion = -1;
var u = this._navigator.userAgent;
var v = this._navigator.vendor || "";
function f(s,h){ return ((h||"").indexOf(s) > -1) };
info.getName = function(){
var name = "";
for(x in info){
if(typeof info[x] == "boolean" && info[x]&&info.hasOwnProperty(x))
name = x;
}
return name;
}
info.webkit = f("WebKit",u);
info.opera = (typeof window.opera != "undefined") || f("Opera",u);
info.ie = !info.opera && f("MSIE",u);
info.chrome = info.webkit && f("Chrome",u);
info.safari = info.webkit && !info.chrome && f("Apple",v);
info.firefox = f("Firefox",u);
info.mozilla = f("Gecko",u) && !info.safari && !info.chrome && !info.firefox;
info.camino = f("Camino",v);
info.netscape = f("Netscape",u);
info.omniweb = f("OmniWeb",u);
info.icab = f("iCab",v);
info.konqueror = f("KDE",v);
info.mobile = (f("Mobile",u)||f("Android",u)||f("Nokia",u)||f("webOS",u)||f("Opera Mini",u)||f("BlackBerry",u)||(f("Windows",u)&&f("PPC",u))||f("Smartphone",u)||f("IEMobile",u))&&!f("iPad",u);
info.msafari = (!f("IEMobile",u) && f("Mobile",u))||(f("iPad",u)&&f("Safari",u));
info.mopera = f("Opera Mini",u);
info.mie = f("PPC",u)||f("Smartphone",u)||f("IEMobile",u);
try {
if (info.ie) {
ver = u.match(/(?:MSIE) ([0-9.]+)/)[1];
if (u.match(/(?:Trident)\/([0-9.]+)/)){
var nTridentNum = parseInt(RegExp.$1,10);
if(nTridentNum > 3){
nativeVersion = nTridentNum + 4;
}
}
} else if (info.safari||info.msafari) {
ver = parseFloat(u.match(/Safari\/([0-9.]+)/)[1]);
if (ver == 100) {
ver = 1.1;
} else {
if(u.match(/Version\/([0-9.]+)/)){
ver = RegExp.$1;
}else{
ver = [1.0,1.2,-1,1.3,2.0,3.0][Math.floor(ver/100)];
}
}
} else if(info.mopera){
ver = u.match(/(?:Opera\sMini)\/([0-9.]+)/)[1];
} else if (info.firefox||info.opera||info.omniweb) {
ver = u.match(/(?:Firefox|Opera|OmniWeb)\/([0-9.]+)/)[1];
} else if (info.mozilla) {
ver = u.match(/rv:([0-9.]+)/)[1];
} else if (info.icab) {
ver = u.match(/iCab[ \/]([0-9.]+)/)[1];
} else if (info.chrome) {
ver = u.match(/Chrome[ \/]([0-9.]+)/)[1];
}
info.version = parseFloat(ver);
info.nativeVersion = parseFloat(nativeVersion);
if (isNaN(info.version)) info.version = -1;
} catch(e) {
info.version = -1;
}
this.navigator = function() {
return info;
};
return info;
};
/**
* os ¸Þ¼µå´Â ¿î¿µÃ¼Á¦¿¡ ´ëÇÑ Á¤º¸ °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @return {Object} ¿î¿µÃ¼Á¦ Á¤º¸ °´Ã¼. ¿î¿µÃ¼Á¦ÀÇ ¿µ¹® À̸§À» ¼Ó¼ºÀ¸·Î °¡Áö¸ç, »ç¿ëÀÚ°¡ »ç¿ëÇÏ´Â ¿î¿µÃ¼Á¦¿Í µ¿ÀÏÇÑ À̸§ÀÇ ¼Ó¼ºÀº true¸¦ °¡Áø´Ù.
* @since 1.4.3 ºÎÅÍ iphone,android,nokia,webos,blackberry,mwin »ç¿ë °¡´É.
* @since 1.4.5 ºÎÅÍ ipad »ç¿ë°¡´É.
* @example
oOS = $Agent().os(); // »ç¿ëÀÚÀÇ ¿î¿µÃ¼Á¦°¡ Windows XP¶ó°í °¡Á¤ÇÑ´Ù.
oOS.linux // false
oOS.mac // false
oOS.vista // false
oOS.win // true
oOS.win2000 // false
oOS.winxp // true
oOS.xpsp2 // false
oOS.win7 // false
oOS.getName() // winxp
*/
jindo.$Agent.prototype.os = function() {
var info = new Object;
var u = this._navigator.userAgent;
var p = this._navigator.platform;
var f = function(s,h){ return (h.indexOf(s) > -1) };
info.getName = function(){
var name = "";
for(x in info){
if(typeof info[x] == "boolean" && info[x]&&info.hasOwnProperty(x))
name = x;
}
return name;
}
info.win = f("Win",p)
info.mac = f("Mac",p);
info.linux = f("Linux",p);
info.win2000 = info.win && (f("NT 5.0",u) || f("2000",u));
info.winxp = info.win && f("NT 5.1",u);
info.xpsp2 = info.winxp && f("SV1",u);
info.vista = info.win && f("NT 6.0",u);
info.win7 = info.win && f("NT 6.1",u);
info.ipad = f("iPad",u);
info.iphone = f("iPhone",u) && !info.ipad;
info.android = f("Android",u);
info.nokia = f("Nokia",u);
info.webos = f("webOS",u);
info.blackberry = f("BlackBerry",u);
info.mwin = f("PPC",u)||f("Smartphone",u)||f("IEMobile",u);
this.os = function() {
return info;
};
return info;
};
/**
* flash ¸Þ¼µå´Â Ç÷¡½Ã¿¡ ´ëÇÑ Á¤º¸ °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @return {Object} Flash Á¤º¸ °´Ã¼. <br>
* object.installed´Â Ç÷¡½Ã Ç÷¹ÀÌ¾î ¼³Ä¡ ¿©ºÎ¸¦ boolean °ªÀ¸·Î °¡Áö°í object.versionÀº Ç÷¡½Ã Ç÷¹À̾îÀÇ ¹öÀüÀ» °¡Áø´Ù. Ç÷¡½Ã ¹öÀüÀ» ŽÁöÇÏÁö ¸øÇϸé flash.versionÀº -1ÀÇ °ªÀ» °¡Áø´Ù.
* @example
var oFlash = $Agent.flash();
oFlash.installed // Ç÷¡½Ã Ç÷¹À̾ ¼³Ä¡Çß´Ù¸é true
oFlash.version // Ç÷¡½Ã Ç÷¹À̾îÀÇ ¹öÀü.
*/
jindo.$Agent.prototype.flash = function() {
var info = new Object;
var p = this._navigator.plugins;
var m = this._navigator.mimeTypes;
var f = null;
info.installed = false;
info.version = -1;
if (typeof p != "undefined" && p.length) {
f = p["Shockwave Flash"];
if (f) {
info.installed = true;
if (f.description) {
info.version = parseFloat(f.description.match(/[0-9.]+/)[0]);
}
}
if (p["Shockwave Flash 2.0"]) {
info.installed = true;
info.version = 2;
}
} else if (typeof m != "undefined" && m.length) {
f = m["application/x-shockwave-flash"];
info.installed = (f && f.enabledPlugin);
} else {
for(var i=10; i > 1; i--) {
try {
f = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
info.installed = true;
info.version = i;
break;
} catch(e) {}
}
}
this.flash = function() {
return info;
};
/*
ÇÏÀ§È£È¯À» À§ÇØ ÀÏ´Ü ³²°ÜµÐ´Ù.
*/
this.info = this.flash;
return info;
};
/**
* silverlight ¸Þ¼µå´Â ½Ç¹ö¶óÀÌÆ®(Silverlight)¿¡ ´ëÇÑ Á¤º¸ °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @returns {Object} Silverlight Á¤º¸ °´Ã¼. <br>
* object.installedÀº ½Ç¹ö¶óÀÌÆ® Ç÷¹ÀÌ¾î ¼³Ä¡ ¿©ºÎ¸¦ boolean °ªÀ¸·Î °¡Áö°í object.versionÀº ½Ç¹ö¶óÀÌÆ® Ç÷¹À̾îÀÇ ¹öÀüÀ» °¡Áø´Ù. Ç÷¹À̾îÀÇ ¹öÀüÀ» ŽÁöÇÏÁö ¸øÇϸé object.versionÀÇ °ªÀº -1ÀÌ µÈ´Ù.
* @example
var oSilver = $Agent.silverlight();
oSilver.installed // Silverlight Ç÷¹À̾ ¼³Ä¡Çß´Ù¸é true
oSilver.version // Silverlight Ç÷¹À̾îÀÇ ¹öÀü.
*/
jindo.$Agent.prototype.silverlight = function() {
var info = new Object;
var p = this._navigator.plugins;
var s = null;
info.installed = false;
info.version = -1;
if (typeof p != "undefined" && p.length) {
s = p["Silverlight Plug-In"];
if (s) {
info.installed = true;
info.version = parseInt(s.description.split(".")[0],10);
if (s.description == "1.0.30226.2") info.version = 2;
}
} else {
try {
s = new ActiveXObject("AgControl.AgControl");
info.installed = true;
if(s.isVersionSupported("3.0")){
info.version = 3;
}else if (s.isVersionSupported("2.0")) {
info.version = 2;
} else if (s.isVersionSupported("1.0")) {
info.version = 1;
}
} catch(e) {}
}
this.silverlight = function() {
return info;
};
return info;
};
/**
* @fileOverview $AÀÇ »ý¼ºÀÚ ¹× ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name array.js
*/
/**
* $A °´Ã¼¸¦ »ý¼ºÇÏ¿© ¹ÝȯÇÑ´Ù.
* @extends core
* @class $A Ŭ·¡½º´Â ¹è¿(Array)À» ·¡ÇÎ(wrapping)ÇÏ¿© ¹è¿À» ´Ù·ç±â À§ÇÑ ¿©·¯°¡Áö ¸Þ¼µå¸¦ Á¦°øÇÑ´Ù.<br>
* ¿©±â¼ ·¡ÇÎÀ̶õ ÀÚ¹Ù½ºÅ©¸³Æ®ÀÇ ÇÔ¼ö¸¦ °¨½Î º»·¡ ÇÔ¼öÀÇ ±â´É¿¡ »õ·Î¿î È®Àå ¼Ó¼ºÀ» Ãß°¡ÇÏ´Â °ÍÀ» ¸»ÇÑ´Ù.
* @param {Array|$A} array ¹è¿. ¸¸¾à ¸Å°³ º¯¼ö¸¦ »ý·«ÇÏ¸é ºó ¹è¿À» °¡Áø »õ·Î¿î $A °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @constructor
* @description [Lite]
* @author Kim, Taegon
*
* @example
var zoo = ["zebra", "giraffe", "bear", "monkey"];
var waZoo = $A(zoo); // ["zebra", "giraffe", "bear", "monkey"]¸¦ ·¡ÇÎÇÑ $A °´Ã¼¸¦ »ý¼ºÇÏ¿© ¹Ýȯ
*/
jindo.$A = function(array) {
var cl = arguments.callee;
if (typeof array == "undefined" || array == null) array = [];
if (array instanceof cl) return array;
if (!(this instanceof cl)) return new cl(array);
this._array = []
if (array.constructor != String) {
this._array = [];
for(var i=0; i < array.length; i++) {
this._array[this._array.length] = array[i];
}
}
};
/**
* toString ¸Þ¼µå´Â ³»ºÎ ¹è¿À» ¹®ÀÚ¿·Î º¯È¯ÇÑ´Ù. ÀÚ¹Ù½ºÅ©¸³Æ®ÀÇ Array.toString À» »ç¿ëÇÑ´Ù.
* @return {String} ³»ºÎ ¹è¿À» º¯È¯ÇÑ ¹®ÀÚ¿.
* @description [Lite]
*
* @example
var zoo = ["zebra", "giraffe", "bear", "monkey"];
$A(zoo).toString();
// °á°ú : zebra,giraffe,bear,monkey
*/
jindo.$A.prototype.toString = function() {
return this._array.toString();
};
/**
* À妽º·Î ¹è¿ÀÇ ¿ø¼Ò °ªÀ» Á¶È¸ÇÑ´Ù.
* @param {Number} nIndex Á¶È¸ÇÒ ¹è¿ÀÇ À妽º. À妽º´Â 0ºÎÅÍ ½ÃÀÛÇÑ´Ù.
* @return {Value} ¹è¿¿¡¼ÀÇ ÇØ´ç À妽ºÀÇ ¿ø¼Ò °ª.
* @description [Lite]
* @since 1.4.2 ºÎÅÍ Áö¿ø
*
* @example
var zoo = ["zebra", "giraffe", "bear", "monkey"];
var waZoo = $A(zoo);
// ¿ø¼Ò °ª Á¶È¸
waZoo.get(1); // °á°ú : giraffe
waZoo.get(3); // °á°ú : monkey
*/
jindo.$A.prototype.get = function(nIndex){
return this._array[nIndex];
};
/**
* ³»ºÎ ¹è¿ÀÇ Å©±â¸¦ ÁöÁ¤Çϰųª ¸®ÅÏÇÑ´Ù.
* @param {Number} [nLen] ÁöÁ¤ÇÒ ¹è¿ÀÇ Å©±â.<br>
* nLen ÀÌ ±âÁ¸ ¹è¿ÀÇ Å©±âº¸´Ù Å©¸é oValue ¸Å°³ º¯¼öÀÇ °ªÀ» ¹è¿ÀÇ ¸¶Áö¸·¿¡ µ¡ºÙÀδÙ.<br>
* nLen ÀÌ ±âÁ¸ ¹è¿ÀÇ Å©±âº¸´Ù ÀÛÀ¸¸é nLen ¹øÂ° ÀÌÈÄÀÇ ¿ø¼Ò´Â Á¦°ÅÇÑ´Ù.
* @param {Value} [oValue] »õ·Î¿î ¿ø¼Ò¸¦ Ãß°¡ÇÒ ¶§ »ç¿ëÇÒ ÃʱⰪ
* @return {Number|$A} ¸Å°³ º¯¼ö¸¦ ¸ðµÎ »ý·«Çϸé ÇöÀç ³»ºÎ ¹è¿ÀÇ Å©±â¸¦ ¸®ÅÏÇϰí,<br>
* ¸Å°³ º¯¼ö¸¦ ÁöÁ¤ÇÑ °æ¿ì¿¡´Â ³»ºÎ ¹è¿À» º¯°æÇÑ $A °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
*
* @example
var zoo = ["zebra", "giraffe", "bear", "monkey"];
var birds = ["parrot", "sparrow", "dove"];
// ¹è¿ÀÇ Å©±â Á¶È¸
$A(zoo).length(); // °á°ú : 4
// ¹è¿ÀÇ Å©±â ÁöÁ¤ (¿ø¼Ò°¡ »èÁ¦µÇ´Â °æ¿ì)
$A(zoo).length(2);
// °á°ú : ["zebra", "giraffe"]
// ¹è¿ÀÇ Å©±â ÁöÁ¤ (¿ø¼Ò°¡ Ãß°¡µÇ´Â °æ¿ì)
$A(zoo).length(6, "(Empty)");
// °á°ú : ["zebra", "giraffe", "bear", "monkey", "(Empty)", "(Empty)"]
$A(zoo).length(5, birds);
// °á°ú : ["zebra", "giraffe", "bear", "monkey", ["parrot", "sparrow", "dove"]]
*/
jindo.$A.prototype.length = function(nLen, oValue) {
if (typeof nLen == "number") {
var l = this._array.length;
this._array.length = nLen;
if (typeof oValue != "undefined") {
for(var i=l; i < nLen; i++) {
this._array[i] = oValue;
}
}
return this;
} else {
return this._array.length;
}
};
/**
* ¹è¿¿¡¼ ƯÁ¤ °ªÀ» °Ë»öÇÑ´Ù.
* @param {Value} oValue °Ë»öÇÒ °ª
* @return {Boolean} ¹è¿¿¡¼ ¸Å°³ º¯¼öÀÇ °ª°ú µ¿ÀÏÇÑ ¿ø¼Ò¸¦ ãÀ¸¸é true¸¦, ãÁö ¸øÇϸé false¸¦ ¸®ÅÏÇÑ´Ù.
* @see $A#indexOf
* @description [Lite]
*
* @example
var arr = $A([1,2,3]);
// °ª °Ë»ö
arr.has(3); // °á°ú : true
arr.has(4); // °á°ú : false
*/
jindo.$A.prototype.has = function(oValue) {
return (this.indexOf(oValue) > -1);
};
/**
* ¹è¿¿¡¼ ƯÁ¤ °ªÀ» °Ë»öÇÏ°í °Ë»öÇÑ ¿ø¼ÒÀÇ À妽º¸¦ ¸®ÅÏÇÑ´Ù.
* @param {Value} oValue °Ë»öÇÒ °ª
* @return {Number} ãÀº ¿ø¼ÒÀÇ À妽º. À妽º´Â 0 ºÎÅÍ ½ÃÀÛÇÑ´Ù. ¸Å°³ º¯¼ö¿Í µ¿ÀÏÇÑ ¿ø¼Ò¸¦ ãÁö ¸øÇϸé -1 À» ¸®ÅÏÇÑ´Ù.
* @see $A#has
* @description [Lite]
*
* @example
var zoo = ["zebra", "giraffe", "bear"];
va r waZoo = $A(zoo);
// °ª °Ë»ö ÈÄ À妽º ¸®ÅÏ
waZoo.indexOf("giraffe"); // 1
waZoo.indexOf("monkey"); // -1
*/
jindo.$A.prototype.indexOf = function(oValue) {
if (typeof this._array.indexOf != 'undefined') {
jindo.$A.prototype.indexOf = function(oValue) {
return this._array.indexOf(oValue);
}
}else{
jindo.$A.prototype.indexOf = function(oValue) {
for(var i=0; i < this._array.length; i++) {
if (this._array[i] == oValue) return i;
}
return -1;
}
}
return this.indexOf(oValue);
};
/**
* ³»ºÎÀÇ ¿øº» ¹è¿À» ¸®ÅÏÇÑ´Ù.
* @return {Array} ¹è¿
* @description [Lite]
*
* @example
var waNum = $A([1, 2, 3]);
waNum.$value(); // ¿ø·¡ÀÇ ¹è¿ÀÎ [1, 2, 3]ÀÌ ¹ÝȯµÈ´Ù
*/
jindo.$A.prototype.$value = function() {
return this._array;
};
/**
* ³»ºÎ ¹è¿¿¡ Çϳª ÀÌ»óÀÇ ¿ø¼Ò¸¦ Ãß°¡ÇÑ´Ù.
* @param {oValue1, ..., oValueN} oValueN Ãß°¡ÇÒ N °³ÀÇ °ª
* @return {Number} Çϳª ÀÌ»óÀÇ ¿ø¼Ò¸¦ Ãß°¡ÇÑ ³»ºÎ ¹è¿ÀÇ Å©±â
* @description [Lite]
*
* @example
var arr = $A([1,2,3]);
// ¿ø¼Ò Ãß°¡
arr.push(4); // °á°ú : 4 ¹Ýȯ, ³»ºÎ ¹è¿Àº [1,2,3,4]·Î º¯°æ µÊ
arr.push(5,6); // °á°ú : 6 ¹Ýȯ, ³»ºÎ ¹è¿Àº [1,2,3,4,5,6]·Î º¯°æ µÊ
*/
jindo.$A.prototype.push = function(oValue1/*, ...*/) {
return this._array.push.apply(this._array, Array.prototype.slice.apply(arguments));
};
/**
* ³»ºÎ ¹è¿ÀÇ ¸¶Áö¸· ¿ø¼Ò¸¦ »èÁ¦ÇÑ´Ù.
* @return {Value} »èÁ¦ÇÑ ¿ø¼Ò
* @description [Lite]
*
* @example
var arr = $A([1,2,3,4,5]);
arr.pop(); // °á°ú : 5 ¹Ýȯ, ³»ºÎ ¹è¿Àº [1,2,3,4]·Î º¯°æ µÊ
*/
jindo.$A.prototype.pop = function() {
return this._array.pop();
};
/**
* ³»ºÎ ¹è¿ÀÇ ¸ðµç ¿ø¼Ò¸¦ ¾ÕÀ¸·Î ÇÑ Ä¾¿ À̵¿ÇÑ´Ù. ³»ºÎ ¹è¿ÀÇ Ã¹ ¹øÂ° ¿ø¼Ò´Â »èÁ¦µÈ´Ù.
* @return {Value} »èÁ¦ÇÑ Ã¹ ¹øÂ° ¿ø¼Ò.
* @see $A#pop
* @see $A#unshift
* @description [Lite]
* @example
var arr = $A(['Melon','Grape','Apple','Kiwi']);
arr.shift(); // °á°ú : 'Melon' ¹Ýȯ, ³»ºÎ ¹è¿Àº ["Grape", "Apple", "Kiwi"]·Î º¯°æ µÊ.
*/
jindo.$A.prototype.shift = function() {
return this._array.shift();
};
/**
* ³»ºÎ ¹è¿ÀÇ ¸Ç ¾Õ¿¡ Çϳª ÀÌ»óÀÇ ¿ø¼Ò¸¦ »ðÀÔÇÑ´Ù.
* @param {oValue1, ..., oValueN} oValueN »ðÀÔÇÒ Çϳª ÀÌ»óÀÇ °ª
* @return {Number} ¿ø¼Ò¸¦ Ãß°¡ÇÑ ÈÄÀÇ ¹è¿ÀÇ Å©±â
* @description [Lite]
* @example
var arr = $A([4,5]);
arr.unshift('c'); // °á°ú : 3 ¹Ýȯ, ³»ºÎ ¹è¿Àº ["c", 4, 5]·Î º¯°æ µÊ.
arr.unshift('a', 'b'); // °á°ú : 5 ¹Ýȯ, ³»ºÎ ¹è¿Àº ["a", "b", "c", 4, 5]·Î º¯°æ µÊ.
*/
jindo.$A.prototype.unshift = function(oValue1/*, ...*/) {
this._array.unshift.apply(this._array, Array.prototype.slice.apply(arguments));
return this._array.length;
};
/**
* ³»ºÎ ¹è¿ÀÇ ¸ðµç ¿ø¼Ò¸¦ ¼øÈ¸ÇÏ¸é¼ Äݹé ÇÔ¼ö¸¦ ½ÇÇàÇÑ´Ù.
*
* @param {Function} fCallback ¼øÈ¸ÇÏ¸é¼ ½ÇÇàÇÒ Äݹé ÇÔ¼ö.<br>
* <br>
* Äݹé ÇÔ¼ö´Â fCallback(value, index, array) ÀÇ Çü½ÄÀ» °¡Áø´Ù. <br>
* value ´Â ¹è¿ÀÌ °¡Áø ¿ø¼ÒÀÇ °ªÀ» °¡Áö°í,<br>
* index ´Â ÇØ´ç ¿ø¼ÒÀÇ À妽º¸¦ °¡Áö°í,<br>
* array ´Â ¹è¿ ±× ÀÚü¸¦ °¡¸®Å²´Ù.
* @param {Object} [oThis] Äݹé ÇÔ¼ö°¡ °´Ã¼ÀÇ ¸Þ¼µåÀÏ ¶§ Äݹé ÇÔ¼ö ³»ºÎ¿¡¼ »ç¿ëÇÒ this
* @return {$A} $A °´Ã¼
* @import core.$A[Break, Continue]
* @see $A#map
* @see $A#filter
* @description [Lite]
*
* @example
var waZoo = $A(["zebra", "giraffe", "bear", "monkey"]);
waZoo.forEach(function(value, index, array) {
document.writeln((index+1) + ". " + value);
});
// °á°ú :
// 1. zebra
// 2. giraffe
// 3. bear
// 4. monkey
* @example
var waArray = $A([1, 2, 3]);
waArray.forEach(function(value, index, array) {
array[index] += 10;
});
document.write(waArray.$value());
// °á°ú : 11, 12, 13 (³»ºÎ ¹è¿¿¡ 10¾¿ ´õÇØÁü)
*/
jindo.$A.prototype.forEach = function(fCallback, oThis) {
if (typeof this._array.forEach == "function") {
jindo.$A.prototype.forEach = function(fCallback, oThis) {
var arr = this._array;
var errBreak = this.constructor.Break;
var errContinue = this.constructor.Continue;
function f(v,i,a) {
try {
fCallback.call(oThis, v, i, a);
} catch(e) {
if (!(e instanceof errContinue)) throw e;
}
};
try {
this._array.forEach(f);
} catch(e) {
if (!(e instanceof errBreak)) throw e;
}
return this;
}
}else{
jindo.$A.prototype.forEach = function(fCallback, oThis) {
var arr = this._array;
var errBreak = this.constructor.Break;
var errContinue = this.constructor.Continue;
function f(v,i,a) {
try {
fCallback.call(oThis, v, i, a);
} catch(e) {
if (!(e instanceof errContinue)) throw e;
}
};
for(var i=0; i < arr.length; i++) {
try {
f(arr[i], i, arr);
} catch(e) {
if (e instanceof errBreak) break;
throw e;
}
}
return this;
}
}
return this.forEach(fCallback, oThis);
};
/**
* ¹è¿ÀÇ ÀϺθ¦ ÃßÃâÇÑ´Ù.
* @param {Number} nStart Àß¶ó³¾ ºÎºÐÀÇ ½ÃÀÛ À妽º. À妽º´Â 0ºÎÅÍ ½ÃÀÛÇÑ´Ù.
* @param {Number} nEnd Àß¶ó³¾ ºÎºÐÀÇ ¹Ù·Î µÚ À妽º
* @return {$A} ³»ºÎ ¹è¿ÀÇ ÀϺθ¦ ÃßÃâÇÑ »õ·Î¿î $A °´Ã¼.<br>
* nStart °ªÀÌ 0 º¸´Ù À۰ųª ȤÀº nStart °ªÀÌ nEnd °ª º¸´Ù Å©°Å³ª °°À¸¸é ºó ¹è¿À» °¡Áö´Â $A °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @description [Lite]
*
* @example
var arr = $A([12, 5, 8, 130, 44]);
var newArr = arr.slice(1,3);
// Àß¶ó³½ ¹è¿ÀÎ [5, 8]¸¦ ·¡ÇÎÇÑ $A °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù. (¿ø·¡ÀÇ ¹è¿Àº º¯È ¾øÀ½)
* @example
var arr = $A([12, 5, 8, 130, 44]);
var newArr = arr.slice(3,3);
// []¸¦ ·¡ÇÎÇÑ $A °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
*/
jindo.$A.prototype.slice = function(nStart, nEnd) {
var a = this._array.slice.call(this._array, nStart, nEnd);
return jindo.$A(a);
};
/**
* ¹è¿ÀÇ ÀϺθ¦ »èÁ¦ÇÑ´Ù.
* @param {Number} nIndex »èÁ¦ÇÒ ºÎºÐÀÇ ½ÃÀÛ À妽º. À妽º´Â 0ºÎÅÍ ½ÃÀÛÇÑ´Ù.
* @param {Number} [nHowMany] »èÁ¦ÇÒ ¿ø¼ÒÀÇ °³¼ö.<br>
* ÀÌ °ª°ú oValueN ¸¦ »ý·«Çϸé nIndex ¹øÂ° ¿ø¼ÒºÎÅÍ ¹è¿ÀÇ ¸¶Áö¸· ¿ø¼Ò±îÁö »èÁ¦ÇÑ´Ù.<br>
* ÀÌ °ªÀ» 0 ȤÀº ÁöÁ¤ÇÏÁö ¾Ê°í oValueN ¿¡ °ªÀ» ÁöÁ¤Çϸé nIndex ¹øÂ° À§Ä¡¿¡ oValueN °ªÀÌ Ãß°¡µÈ´Ù.
* @param {Value1, ...,ValueN} [oValueN] »èÁ¦ÇÑ ¹è¿¿¡ Ãß°¡ÇÒ Çϳª ÀÌ»óÀÇ °ª. nIndex °ªÀÇ À妽ººÎÅÍ Ãß°¡µÈ´Ù.
* @returns {$A} »èÁ¦ÇÑ ¿ø¼Ò¸¦ ·¡ÇÎÇÏ´Â »õ·Î¿î $A °´Ã¼
* @description [Lite]
*
* @example
var arr = $A(["angel", "clown", "mandarin", "surgeon"]);
var removed = arr.splice(2, 0, "drum");
// arrÀÇ ³»ºÎ ¹è¿Àº ["angel", "clown", "drum", "mandarin", "surgeon"]·Î À妽º 2¿¡ drumÀÌ Ãß°¡ µÊ
// removedÀÇ ³»ºÎ ¹è¿Àº []·Î »èÁ¦µÈ ¿ø¼Ò°¡ ¾øÀ½
removed = arr.splice(3, 1);
// arrÀÇ ³»ºÎ ¹è¿Àº ["angel", "clown", "drum", "surgeon"]·Î mandarinÀÌ »èÁ¦ µÊ
// removedÀÇ ³»ºÎ ¹è¿Àº »èÁ¦µÈ ¿ø¼Ò ["mandarin"]¸¦ °¡Áü
removed = arr.splice(2, 1, "trumpet", "parrot");
// arrÀÇ ³»ºÎ ¹è¿Àº ["angel", "clown", "trumpet", "parrot", "surgeon"]·Î drumÀÌ »èÁ¦µÇ°í »õ·Î¿î ¿ø¼Ò°¡ Ãß°¡ µÊ
// removedÀÇ ³»ºÎ ¹è¿Àº »èÁ¦µÈ ¿ø¼Ò ["drum"]À» °¡Áü
removed = arr.splice(3);
// arrÀÇ ³»ºÎ ¹è¿Àº ["angel", "clown", "trumpet"]·Î À妽º 3ºÎÅÍ ¸¶Áö¸· ¿ø¼Ò°¡ »èÁ¦µÇ¾úÀ½
// removedÀÇ ³»ºÎ ¹è¿Àº »èÁ¦µÈ ¿ø¼Ò ["parrot", "surgeon"]À» °¡Áü
*/
jindo.$A.prototype.splice = function(nIndex, nHowMany/*, oValue1,...*/) {
var a = this._array.splice.apply(this._array, Array.prototype.slice.apply(arguments));
return jindo.$A(a);
};
/**
* ¹è¿ÀÇ ¿ø¼Ò¸¦ ¹«ÀÛÀ§·Î ¼¯´Â´Ù.
* @return {$A} ¹è¿ÀÌ ¼¯¿©Áø $A °´Ã¼
* @description [Lite]
*
* @example
var dice = $A([1,2,3,4,5,6]);
dice.shuffle();
document.write("You get the number " + dice.get(0));
// °á°ú : 1ºÎÅÍ 6±îÁöÀÇ ¼ýÀÚ Áß ·£´ýÇÑ ¼ýÀÚ
*/
jindo.$A.prototype.shuffle = function() {
this._array.sort(function(a,b){ return Math.random()>Math.random()?1:-1 });
return this;
};
/**
* ¹è¿ ¿ø¼ÒÀÇ ¼ø¼¸¦ °Å²Ù·Î µÚÁý´Â´Ù.
* @return {$A} ¿ø¼Ò ¼ø¼¸¦ µÚÁýÀº $A °´Ã¼
* @description [Lite]
*
* @example
var arr = $A([1, 2, 3, 4, 5]);
arr.reverse(); // °á°ú : [5, 4, 3, 2, 1]
*/
jindo.$A.prototype.reverse = function() {
this._array.reverse();
return this;
};
/**
* ¹è¿ÀÇ ¸ðµç ¿ø¼Ò¸¦ Á¦°ÅÇϰí, ºó ¹è¿·Î ¸¸µç´Ù.
* @return {$A} ¹è¿ÀÇ ¿ø¼Ò°¡ Á¦°ÅµÈ $A °´Ã¼
* @description [Lite]
*
* @example
var arr = $A([1, 2, 3]);
arr.empty(); // °á°ú : []
*/
jindo.$A.prototype.empty = function() {
return this.length(0);
};
/**
* Break ¸Þ¼µå´Â forEach, filter, map ¸Þ¼µåÀÇ ¼øÈ¸ ·çÇÁ¸¦ Áß´ÜÇÑ´Ù.
* @remark ³»ºÎÀûÀ¸·Î´Â °Á¦·Î ¿¹¿Ü¸¦ ¹ß»ý½ÃŰ´Â ±¸Á¶À̹ǷÎ, try ~ catch ¿µ¿ª¿¡¼ ÀÌ ¸Þ¼Òµå¸¦ ½ÇÇàÇϸé Á¤»óÀûÀ¸·Î µ¿ÀÛÇÏÁö ¾ÊÀ» ¼ö ÀÖ´Ù.
*
* @description [Lite]
* @see $A#Continue
* @see $A#forEach
* @see $A#filter
* @see $A#map
* @example
$A([1,2,3,4,5]).forEach(function(value,index,array) {
// °ªÀÌ 4º¸´Ù Å©¸é Á¾·á
if (value > 4) $A.Break();
...
});
*/
jindo.$A.Break = function() {
if (!(this instanceof arguments.callee)) throw new arguments.callee;
};
/**
* Continue ¸Þ¼µå´Â forEach, filter, map ¸Þ¼µåÀÇ ¼øÈ¸ ·çÇÁ¿¡¼ ³ª¸ÓÁö ¸í·ÉÀ» ½ÇÇàÇÏÁö ¾Ê°í ´ÙÀ½ ·çÇÁ·Î °Ç³Ê¶Ú´Ù.
* @remark ³»ºÎÀûÀ¸·Î´Â °Á¦·Î ¿¹¿Ü¸¦ ¹ß»ý½ÃŰ´Â ±¸Á¶À̹ǷÎ, try ~ catch ¿µ¿ª¿¡¼ ÀÌ ¸Þ¼Òµå¸¦ ½ÇÇàÇϸé Á¤»óÀûÀ¸·Î µ¿ÀÛÇÏÁö ¾ÊÀ» ¼ö ÀÖ´Ù.
*
* @description [Lite]
* @see $A#Break
* @see $A#forEach
* @see $A#filter
* @see $A#map
* @example
$A([1,2,3,4,5]).forEach(function(value,index,array) {
// °ªÀÌ Â¦¼ö¸é 󸮸¦ ÇÏÁö ¾ÊÀ½
if (value%2 == 0) $A.Continue();
...
});
*/
jindo.$A.Continue = function() {
if (!(this instanceof arguments.callee)) throw new arguments.callee;
};
/**
* @fileOverview $AÀÇ È®Àå ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name array.extend.js
*/
/**
* ¹è¿ÀÇ ¸ðµç ¿ø¼Ò¸¦ ¼øÈ¸ÇÏ¸é¼ Äݹé ÇÔ¼ö¸¦ ½ÇÇàÇÑ´Ù.<br>
* Äݹé ÇÔ¼öÀÇ ½ÇÇà °á°ú¸¦ ¹è¿ÀÇ ¿ø¼Ò¿¡ ¼³Á¤ÇÑ´Ù.
*
* @param {Function} fCallback ¼øÈ¸ÇÏ¸é¼ ½ÇÇàÇÒ Äݹé ÇÔ¼ö.<br>
* <br>
* Äݹé ÇÔ¼ö´Â fCallback(value, index, array) ÀÇ Çü½ÄÀ» °¡Áø´Ù. <br>
* value ´Â ¹è¿ÀÌ °¡Áø ¿ø¼ÒÀÇ °ªÀ» °¡Áö°í,<br>
* index ´Â ÇØ´ç ¿ø¼ÒÀÇ À妽º¸¦ °¡Áö°í,<br>
* array ´Â ¹è¿ ±× ÀÚü¸¦ °¡¸®Å²´Ù.<br>
* <br>
* Äݹé ÇÔ¼ö¿¡¼ ¸®ÅÏÇÏ´Â °ªÀ» ¿ø¼ÒÀÇ °ªÀ¸·Î ¼³Á¤ÇÑ´Ù.
*
* @param {Object} [oThis] Äݹé ÇÔ¼ö°¡ °´Ã¼ÀÇ ¸Þ¼µåÀÏ ¶§ Äݹé ÇÔ¼ö ³»ºÎ¿¡¼ »ç¿ëÇÒ this
* @return {$A} Äݹé ÇÔ¼öÀÇ ¼öÇà °á°ú¸¦ ¹Ý¿µÇÑ $A °´Ã¼
* @see $A#forEach
* @see $A#filter
*
* @example
var waZoo = $A(["zebra", "giraffe", "bear", "monkey"]);
waZoo.map(function(value, index, array) {
return (index+1) + ". " + value;
});
// °á°ú : [1. zebra, 2. giraffe, 3. bear, 4. monkey]
* @example
var waArray = $A([1, 2, 3]);
waArray.map(function(value, index, array) {
return value + 10;
});
document.write(waArray.$value());
// °á°ú : 11, 12, 13 (³»ºÎ ¹è¿¿¡ 10¾¿ ´õÇØÁü)
*/
jindo.$A.prototype.map = function(fCallback, oThis) {
if (typeof this._array.map == "function") {
jindo.$A.prototype.map = function(fCallback, oThis) {
var arr = this._array;
var errBreak = this.constructor.Break;
var errContinue = this.constructor.Continue;
function f(v,i,a) {
try {
return fCallback.call(oThis, v, i, a);
} catch(e) {
if (e instanceof errContinue){
return v;
} else{
throw e;
}
}
};
try {
this._array = this._array.map(f);
} catch(e) {
if(!(e instanceof errBreak)) throw e;
}
return this;
}
}else{
jindo.$A.prototype.map = function(fCallback, oThis) {
var arr = this._array;
var returnArr = [];
var errBreak = this.constructor.Break;
var errContinue = this.constructor.Continue;
function f(v,i,a) {
try {
return fCallback.call(oThis, v, i, a);
} catch(e) {
if (e instanceof errContinue){
return v;
} else{
throw e;
}
}
};
for(var i=0; i < this._array.length; i++) {
try {
returnArr[i] = f(arr[i], i, arr);
} catch(e) {
if (e instanceof errBreak){
return this;
}else{
throw e;
}
}
}
this._array = returnArr;
return this;
}
}
return this.map(fCallback, oThis);
};
/**
* ¹è¿ÀÇ ¸ðµç ¿ø¼Ò¸¦ ¼øÈ¸ÇÏ¸é¼ Äݹé ÇÔ¼ö¸¦ ½ÇÇàÇÑ´Ù. ½ÇÇàÀÌ ³¡³ª¸é filter ¸Þ¼µå´Â ÄÝ¹Ú ÇÔ¼ö¸¦ ¸¸Á·ÇÏ´Â ¿ø¼Ò·Î ÀÌ·ç¾îÁø »õ·Î¿î $A °´Ã¼¸¦ ¹ÝȯÇÑ´Ù.
* @param {Function} fCallback ¼øÈ¸ÇÏ¸é¼ ½ÇÇàÇÒ Äݹé ÇÔ¼ö.<br>
* <br>
* Äݹé ÇÔ¼ö´Â fCallback(value, index, array)ÀÇ Çü½ÄÀ¸·Î ÀÛ¼ºÇØ¾ß ÇÑ´Ù. ¿©±â¼
* value ´Â ¹è¿ÀÌ °¡Áø ¿ø¼ÒÀÇ °ª, index ´Â ÇØ´ç ¿ø¼ÒÀÇ À妽º, array ´Â ¿øº» ¹è¿ÀÌ´Ù.<br>
* <br>
* Äݹé ÇÔ¼ö´Â Boolean À» ¸®ÅÏÇØ¾ßÇÑ´Ù. ¸¸¾à ¸®ÅÏ °ªÀÌ true ÀÎ ¿ø¼Ò´Â »õ·Î¿î ¹è¿ÀÇ ¿ø¼Ò°¡ µÈ´Ù.
*
* @param {Object} oThis Äݹé ÇÔ¼ö°¡ °´Ã¼ÀÇ ¸Þ¼µåÀÏ ¶§ Äݹé ÇÔ¼ö ³»ºÎ¿¡¼ »ç¿ëÇÒ this
* @return {$A} Äݹé ÇÔ¼öÀÇ ¸®ÅÏ °ªÀÌ true ÀÎ ¿ø¼Ò·Î ÀÌ·ç¾îÁø »õ·Î¿î $A °´Ã¼
* @see $A#forEach
* @see $A#map
*
* @example
var arr = $A([1,2,3,4,5]);
// ÇÊÅ͸µ ÇÔ¼ö
function filterFunc(value, index, array) {
if (value > 2) {
return true;
} else {
return false;
}
}
var newArr = arr.filter(filterFunc);
document.write(arr.$value()); // °á°ú : [1,2,3,4,5]
document.write(newArr.$value()); // °á°ú : [3,4,5]
*/
jindo.$A.prototype.filter = function(fCallback, oThis) {
if (typeof this._array.filter != "undefined") {
jindo.$A.prototype.filter = function(fCallback, oThis) {
return jindo.$A(this._array.filter(fCallback, oThis));
}
}else{
jindo.$A.prototype.filter = function(fCallback, oThis) {
var ar = [];
this.forEach(function(v,i,a) {
if (fCallback.call(oThis, v, i, a) === true) {
ar[ar.length] = v;
}
});
return jindo.$A(ar);
}
}
return this.filter(fCallback, oThis);
};
/**
* ¹è¿ÀÇ ¸ðµç ¿ø¼Ò¸¦ ¼øÈ¸ÇÏ¸é¼ Äݹé ÇÔ¼ö¸¦ ½ÇÇàÇÑ´Ù. µ¿½Ã¿¡ ¹è¿ÀÇ ¸ðµç ¿ø¼Ò°¡ Äݹé ÇÔ¼ö¸¦ ¸¸Á·ÇÏ´ÂÁö(Äݹé ÇÔ¼ö°¡ true¸¦ ¸®ÅÏÇÏ´ÂÁö) °Ë»çÇÑ´Ù. <br>
* ¸¸¾à ¸ðµç ¿ø¼Ò°¡ Äݹé ÇÔ¼ö¸¦ ¸¸Á·Çϸé every ¸Þ¼µå´Â true¸¦ ¸®ÅÏÇÑ´Ù.
*
* @param {Function} fCallback ¼øÈ¸ÇÏ¸é¼ ½ÇÇàÇÒ Äݹé ÇÔ¼ö.<br>
* <br>
* Äݹé ÇÔ¼ö´Â fCallback(value, index, array) ÀÇ Çü½ÄÀ¸·Î ÀÛ¼ºÇØ¾ß ÇÑ´Ù. ¿©±â¼
* value ´Â ¹è¿ÀÌ °¡Áø ¿ø¼ÒÀÇ °ª, index ´Â ÇØ´ç ¿ø¼ÒÀÇ À妽º, array ´Â ¿øº» ¹è¿ÀÌ´Ù.<br>
* <br>
* Äݹé ÇÔ¼ö´Â Boolean À» ¸®ÅÏÇØ¾ßÇÑ´Ù.<br>
*
* @param {Object} oThis Äݹé ÇÔ¼ö°¡ °´Ã¼ÀÇ ¸Þ¼µåÀÏ ¶§ Äݹé ÇÔ¼ö ³»ºÎ¿¡¼ »ç¿ëÇÒ this
* @return {Boolean} Äݹé ÇÔ¼öÀÇ ¸®ÅÏ °ªÀÌ ¸ðµÎ true À̸é true ¸¦, ±×·¸Áö ¾ÊÀ¸¸é false ¸¦ ¸®ÅÏÇÑ´Ù.
* @see $A#some
*
* @example
function isBigEnough(value, index, array) {
return (value >= 10);
}
var try1 = $A([12, 5, 8, 130, 44]).every(isBigEnough); // °á°ú : false
var try2 = $A([12, 54, 18, 130, 44]).every(isBigEnough); // °á°ú : true
*/
jindo.$A.prototype.every = function(fCallback, oThis) {
if (typeof this._array.every != "undefined"){
jindo.$A.prototype.every = function(fCallback, oThis) {
return this._array.every(fCallback, oThis);
}
}else{
jindo.$A.prototype.every = function(fCallback, oThis) {
var result = true;
this.forEach(function(v, i, a) {
if (fCallback.call(oThis, v, i, a) === false) {
result = false;
jindo.$A.Break();
}
});
return result;
}
}
return this.every(fCallback, oThis);
};
/**
* ¹è¿ÀÇ ¸ðµç ¿ø¼Ò¸¦ ¼øÈ¸ÇÏ¸é¼ Äݹé ÇÔ¼ö¸¦ ½ÇÇàÇÑ´Ù.<br>
* Äݹé ÇÔ¼ö¸¦ ¸¸Á·ÇÏ´Â ¿ø¼Ò°¡ ÀÖ´ÂÁö °Ë»çÇÑ´Ù.
*
* @param {Function} fCallback ¼øÈ¸ÇÏ¸é¼ ½ÇÇàÇÒ Äݹé ÇÔ¼ö.<br>
* <br>
* Äݹé ÇÔ¼ö´Â fCallback(value, index, array) ÀÇ Çü½ÄÀ¸·Î ÀÛ¼ºÇØ¾ß ÇÑ´Ù. ¿©±â¼
* value ´Â ¹è¿ÀÌ °¡Áø ¿ø¼Ò, index ´Â ÇØ´ç ¿ø¼ÒÀÇ À妽º, array ´Â ¿øº» ¹è¿ÀÌ´Ù.<br>
* <br>
* Äݹé ÇÔ¼ö´Â Boolean À» ¸®ÅÏÇØ¾ßÇÑ´Ù.<br>
*
* @param {Object} oThis Äݹé ÇÔ¼ö°¡ °´Ã¼ÀÇ ¸Þ¼µåÀÏ ¶§ Äݹé ÇÔ¼ö ³»ºÎ¿¡¼ »ç¿ëÇÒ this
* @return {Boolean} Äݹé ÇÔ¼öÀÇ ¸®ÅÏ °ªÀÌ true ÀÎ ¿ø¼Ò°¡ ÀÖÀ¸¸é true ¸¦, Çϳªµµ ¾øÀ¸¸é false ¸¦ ¸®ÅÏÇÑ´Ù.
* @see $A#every
*
* @example
function twoDigitNumber(value, index, array) {
return (value >= 10 && value < 100);
}
var try1 = $A([12, 5, 8, 130, 44]).some(twoDigitNumber); // °á°ú : true
var try2 = $A([1, 5, 8, 130, 4]).some(twoDigitNumber); // °á°ú : false
*/
jindo.$A.prototype.some = function(fCallback, oThis) {
if (typeof this._array.some != "undefined"){
jindo.$A.prototype.some = function(fCallback, oThis) {
return this._array.some(fCallback, oThis);
}
}else{
jindo.$A.prototype.some = function(fCallback, oThis) {
var result = false;
this.forEach(function(v, i, a) {
if (fCallback.call(oThis, v, i, a) === true) {
result = true;
jindo.$A.Break();
}
});
return result;
}
}
return this.some(fCallback, oThis);
};
/**
* ¹è¿¿¡¼ ¸Å°³ º¯¼ö¿Í °°Àº °ªÀ» Á¦¿ÜÇÏ¿© »õ·Î¿î $A °´Ã¼¸¦ ¸¸µç´Ù.
*
* @param {Value, ..., ValueN} oValueN ¹è¿¿¡¼ Á¦¿ÜÇÒ °ª
* @return {$A} ¹è¿¿¡¼ ƯÁ¤ °ªÀ» Á¦¿ÜÇÑ »õ·Î¿î $A °´Ã¼
*
* @example
var arr = $A([12, 5, 8, 130, 44]);
var newArr1 = arr.refuse(12);
document.write(arr); // °á°ú : [12, 5, 8, 130, 44]
document.write(newArr1); // °á°ú : [5, 8, 130, 44]
var newArr2 = newArr1.refuse(8, 44, 130);
document.write(newArr1); // °á°ú : [5, 8, 130, 44]
document.write(newArr2); // °á°ú : [5]
*/
jindo.$A.prototype.refuse = function(oValue1/*, ...*/) {
var a = jindo.$A(Array.prototype.slice.apply(arguments));
return this.filter(function(v,i) { return !a.has(v) });
};
/**
* ¹è¿¿¡¼ Áߺ¹µÇ´Â ¿ø¼Ò¸¦ »èÁ¦ÇÑ´Ù.
*
* @return {$A} Áߺ¹µÇ´Â ¿ø¼Ò¸¦ Á¦°ÅÇÑ $A °´Ã¼
*
* @example
var arr = $A([10, 3, 76, 5, 4, 3]);
arr.unique(); // °á°ú : [10, 3, 76, 5, 4]
*/
jindo.$A.prototype.unique = function() {
var a = this._array, b = [], l = a.length;
var i, j;
/*
Áߺ¹µÇ´Â ¿ø¼Ò Á¦°Å
*/
for(i = 0; i < l; i++) {
for(j = 0; j < b.length; j++) {
if (a[i] == b[j]) break;
}
if (j >= b.length) b[j] = a[i];
}
this._array = b;
return this;
};
/**
* @fileOverview $AjaxÀÇ »ý¼ºÀÚ ¹× ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name Ajax.js
*/
/**
* $Ajax´Â ¼¹ö¿Í ºê¶ó¿ìÀú »çÀÌÀÇ ºñµ¿±â Åë½Å, Áï Ajax Åë½ÅÀ» Áö¿øÇÑ´Ù. $Ajax´Â XHR(XMLHTTPRequest)À» »ç¿ëÇÑ ±âº»ÀûÀÎ ¹æ½Ä°ú ÇÔ²² ´Ù¸¥ È£½ºÆ®(Host) »çÀÌÀÇ Åë½ÅÀ» À§ÇÑ ¿©·¯ ¹æ½ÄÀ» Á¦°øÇÑ´Ù.
* $Ajax °´Ã¼ÀÇ ±âº»ÀûÀÎ ÃʱâÈ ¹æ½ÄÀº ´ÙÀ½°ú °°´Ù.
* <textarea name="code" class="js:nocontrols">
* var oAjax = new $Ajax('server.php', {
type : 'xhr',
method : 'get', // GET ¹æ½ÄÀ¸·Î Åë½Å
onload : function(res){ // ¿äûÀÌ ¿Ï·áµÇ¸é ½ÇÇàµÉ Äݹé ÇÔ¼ö
$('list').innerHTML = res.text();
},
timeout : 3, // 3ÃÊ À̳»¿¡ ¿äûÀÌ ¿Ï·áµÇÁö ¾ÊÀ¸¸é ontimeout ½ÇÇà (»ý·« ½Ã 0)
ontimeout : function(){ // ŸÀÓ ¾Æ¿ôÀÌ ¹ß»ýÇÏ¸é ½ÇÇàµÉ Äݹé ÇÔ¼ö, »ý·« ½Ã ŸÀÓ ¾Æ¿ôÀÌ µÇ¸é ¾Æ¹« 󸮵µ ÇÏÁö ¾ÊÀ½
alert("Timeout!");
},
async : true // ºñµ¿±â·Î È£ÃâÇÏ´Â °æ¿ì, »ý·«Çϸé true
});
oAjax.request();
}
* </textarea>
*
* @extends core
* @class $Ajax Ŭ·¡½º´Â ´Ù¾çÇÑ °³¹ß ȯ°æ¿¡¼ Ajax ¿äû°ú ÀÀ´äÀ» ½±°Ô ±¸ÇöÇϱâ À§ÇÑ ¸Þ¼µå¸¦ Á¦°øÇÑ´Ù.<br>
*
* $Ajax¸¦ ÃʱâÈÇÒ ¶§ »ç¿ëÇÏ´Â ¸Å°³ º¯¼ö´Â ´ÙÀ½°ú °°´Ù.
*
* @param {String} url Ajax ¿äûÀ» º¸³¾ ¼¹ö Ãø URL.<br>
* @param {Object} option $Ajax ¿¡¼ »ç¿ëÇÏ´Â Äݹé ÇÔ¼ö, Åë½Å ¹æ½Ä µî°ú °°Àº ´Ù¾çÇÑ Á¤º¸¸¦ Á¤ÀÇÇÑ´Ù.<br>
* <br>
* option °´Ã¼ÀÇ ÇÁ·ÎÆÛƼ¿Í »ç¿ë¹ýÀº ¾Æ·¡¿¡¼ ¼³¸íÇÑ´Ù.<br>
<table>
<thead style="background-color:#D2E0E6;">
<th>ÇÁ·ÎÆÛƼ ¸í</th>
<th>ŸÀÔ</th>
<th>¼³¸í</th>
</thead>
<tbody>
<tr>
<td style="font-weight:bold;">type</td>
<td>String</td>
<td>
Ajax ±¸Çö ¹æ½Ä. »ý·« ½Ã ±âº» °ªÀº "xhr"
<ul>
<li><strong>xhr</strong>
ºê¶ó¿ìÀú¿¡ ³»ÀåµÈ XMLHttpRequest °´Ã¼¸¦ ÀÌ¿ëÇÏ¿© Ajax ¿äûÀ» ó¸®ÇÑ´Ù.<br>
ÀÀ´äÀ¸·Î´Â text, xml, json ¹æ½Ä ¸ðµÎ »ç¿ëÀÌ °¡´ÉÇϸç, ¿äû ½ÇÆÐ ½Ã HTTP ÀÀ´äÄڵ带 ÅëÇØ ¿øÀÎ ÆÄ¾ÇÀÌ °¡´ÉÇÏ´Ù.<br>
´Ü, Cross-Domain ¿¡¼´Â »ç¿ëÇÒ ¼ö ¾ø´Ù.
</li>
<li><strong>iframe</strong>
iframe À» ÇÁ·Ï½Ã·Î »ç¿ëÇÏ¿© Ajax ¿äûÀ» ó¸®ÇÑ´Ù. Cross-Domain ¿¡¼ »ç¿ëÇÑ´Ù.<br>
·ÎÄÃ(¿äû ÇÏ´Â ÂÊ)°ú ¿ø°Ý(¿äû ¹Þ´Â ÂÊ)¿¡ ¸ðµÎ ÇÁ·Ï½Ã¿ë HTML ÆÄÀÏÀ» ¸¸µé¾î<br>
iframe ¿¡¼ ¿ø°Ý ÇÁ·Ï½Ã¿¡ ¿äûÇϸé, ¿ø°Ý ÇÁ·Ï½Ã¿¡¼ ¿ø°Ý µµ¸ÞÀÎÀÇ ÆäÀÌÁö¿¡ XHR ·Î Ajax ¿äûÀ» ÇÑ´Ù.<br>
ÀÀ´äÀ» ¹ÞÀº ¿ø°Ý ÇÁ·Ï½Ã¿¡¼ ·ÎÄà ÇÁ·Ï½Ã·Î ÀÀ´äÀ» Àü´ÞÇÏ¸é ·ÎÄà ÇÁ·Ï½Ã¿¡¼ ÃÖÁ¾ÀûÀ¸·Î Äݹé ÇÔ¼ö(onload)¸¦ È£ÃâÇÏ¿© 󸮵ȴÙ.<br>
<ul type="disc">
<li>¿ø°Ý ÇÁ·Ï½Ã ÆÄÀÏ : ajax_remote_callback.html</li>
<li>·ÎÄà ÇÁ·Ï½Ã ÆÄÀÏ : ajax_local_callback.html</li>
</ul>
¡Ø IE ¿¡¼´Â "µü.µü." ÇÏ´Â ÆäÀÌÁö À̵¿À½ÀÌ µé¸± ¼öµµ ÀÖ´Ù (¿äû´ç 2ȸ).
</li>
<li><strong>jsonp</strong>
JSON °ú <script> ű׸¦ »ç¿ëÇÏ¿© »ç¿ëÇÏ¿© Ajax ¿äûÀ» ó¸®ÇÑ´Ù. Cross-Domain ¿¡¼ »ç¿ëÇÑ´Ù.<br>
<script> ű׸¦ µ¿ÀûÀ¸·Î »ý¼ºÇÏ¿©, ¿äûÇÒ ¿ø°Ý ÆäÀÌÁö¸¦ ½ºÅ©¸³Æ®¿¡ »ðÀÔÇÏ¿© GET ¹æ½ÄÀ¸·Î ¿äûÀ» Àü¼ÛÇÑ´Ù.<br>
¿äû ½Ã¿¡ Äݹé ÇÔ¼ö¸¦ ¸Å°³ º¯¼ö·Î ³Ñ±â¸é, ¿ø°Ý ÆäÀÌÁö¿¡¼ Àü´Þ¹ÞÀº Äݹé ÇÔ¼ö¸íÀ¸·Î ¾Æ·¡¿Í °°ÀÌ ÀÀ´äÀ» º¸³½´Ù.<br>
<ul type="disc"><li>function_name(...°á°ú °ª...)</li></ul>
ÀÀ´äÀº Äݹé ÇÔ¼ö(onload)¿¡¼ 󸮵ȴÙ.<br>
¡Ø GET ¹æ½Ä¸¸ °¡´ÉÇϹǷÎ, Àü¼Û µ¥ÀÌÅÍ ±æÀÌ´Â URL ¿¡ Çã¿ëÇÏ´Â ±æÀÌ·Î Á¦ÇѵȴÙ.
</li>
<li><strong>flash</strong>
Ç÷¡½Ã °´Ã¼¸¦ »ç¿ëÇÏ¿© Ajax ¿äûÀ» ó¸®ÇÑ´Ù. Cross-Domain ¿¡¼ »ç¿ëÇÑ´Ù.<br>
¼¹öÀÇ ·çÆ®¿¡ crossdomain.xml ÀÌ Á¸ÀçÇØ¾ß Çϸç Á¢±Ù ±ÇÇÑÀ» ¼³Á¤ÇØ¾ß »ç¿ëÇÒ ¼ö ÀÖ´Ù.<br>
¸ðµç Åë½ÅÀº Ç÷¡½Ã °´Ã¼¸¦ ÅëÇÏ¿© ÁÖ°í ¹ÞÀ¸¸ç Ajax È£ÃâÀ» Çϱâ Àü¿¡ ¹Ýµå½Ã Ç÷¡½Ã °´Ã¼¸¦ ÃʱâÈÇØ¾ß ÇÑ´Ù.<br>
$Ajax.SWFRequest.write ¸Þ¼µå »ç¿ëÇÏ¿© ÃʱâÈÇϸç ÇØ´ç ¸Þ¼µå´Â <body> ÅÂ±× ³»¿¡ ÀÛ¼ºÇÑ´Ù.
</li>
<li><strong>get/post/put/delete</strong> : ³»ºÎÀûÀ¸·Î xhr ·Î ó¸®ÇÑ´Ù.</li>
</ul>
</td>
</tr>
<tr>
<td style="font-weight:bold;">method</td>
<td>String</td>
<td>
HTTP Åë½Å ¹æ¹ý
<ul>
<li><strong>post</strong> : »ý·« ½Ã ±âº» °ª.</li>
<li><strong>get</strong> : type ÀÌ "jsonp" À̸é "get" À¸·Î ¼³Á¤µÈ´Ù.</li>
<li><strong>put</strong> : 1.4.2 ºÎÅÍ »ç¿ë °¡´É</li>
<li><strong>delete</strong> : 1.4.2 ºÎÅÍ »ç¿ë °¡´É</li>
</ul>
</td>
</tr>
<tr>
<td style="font-weight:bold;">timeout</td>
<td>Number</td>
<td>
¿äû ŸÀӾƿô ½Ã°£. »ý·« ½Ã 0 (´ÜÀ§´Â ÃÊ).<br>
ŸÀӾƿô ½Ã°£ ³»¿¡ ¿äûÀÌ ¿Ï·áµÇÁö ¾ÊÀ¸¸é ÁßÁö½ÃŲ´Ù.<br>
ºñµ¿±â È£ÃâÀÎ °æ¿ì¿¡¸¸ »ç¿ë °¡´ÉÇÏ´Ù.
</td>
</tr>
<tr>
<td style="font-weight:bold;">onload</td>
<td>Function</td>
<td>
¿äûÀÌ ¿Ï·áµÇ¸é ½ÇÇàÇÒ Äݹé ÇÔ¼ö. ¹Ýµå½Ã ÁöÁ¤ÇØ¾ß ÇÑ´Ù.<br>
¸Å°³ º¯¼ö·Î ÀÀ´ä °´Ã¼ÀÎ $Ajax.Response °´Ã¼°¡ Àü´Þ µÈ´Ù.
</td>
</tr>
<tr>
<td style="font-weight:bold;">onerror</td>
<td>Function</td>
<td>
¿äûÀÌ ½ÇÆÐÇÏ¸é ½ÇÇàÇÒ Äݹé ÇÔ¼ö.<br>
»ý·«ÇÏ¸é ¿¡·¯°¡ ¹ß»ýÇØµµ onload ¸¦ ½ÇÇàÇÑ´Ù.
</td>
</tr>
<tr>
<td style="font-weight:bold;">ontimeout</td>
<td>Function</td>
<td>
ŸÀӾƿôÀÌ µÇ¾úÀ» ¶§ ½ÇÇàÇÒ Äݹé ÇÔ¼ö.<br>
»ý·«Çϸé ŸÀӾƿô ¹ß»ý ÈÄ¿¡ ¾Æ¹«·± 󸮸¦ ÇÏÁö ¾Ê´Â´Ù.
</td>
</tr>
<tr>
<td style="font-weight:bold;">proxy</td>
<td>String</td>
<td>
·ÎÄà ÇÁ·Ï½Ã ÆÄÀÏ(ajax_local_callback.html)ÀÇ °æ·Î.<br>
type ÀÌ "iframe" ÀÏ ¶§ »ç¿ëÇÏ¸ç ¹Ýµå½Ã ÁöÁ¤ÇØ¾ß ÇÑ´Ù.
</td>
</tr>
<tr>
<td style="font-weight:bold;">jsonp_charset</td>
<td>String</td>
<td>
¿äû ½Ã »ç¿ëÇÒ <script> ÀÎÄÚµù ¹æ½Ä.<br>
type ÀÌ "jsonp" ÀÏ ¶§ »ç¿ëÇÑ´Ù. »ý·«Çϸé "euc-kr" ÀÌ ±âº»°ªÀÌ´Ù. (0.4.2 ºÎÅÍ Áö¿ø)
</td>
</tr>
<tr>
<td style="font-weight:bold;">callbackid</td>
<td>String</td>
<td>
Äݹé ÇÔ¼ö À̸§¿¡ »ç¿ëÇÒ ¾ÆÀ̵𠰪.<br>
type ÀÌ "jsonp" ÀÏ ¶§ »ç¿ëÇÑ´Ù. (1.3.0 ºÎÅÍ Áö¿ø)<br>
»ý·«Çϸé ÀÚµ¿À¸·Î ·£´ýÇÑ ¾ÆÀ̵𠰪À» »ý¼ºÇÏ¿© »ç¿ëÇÑ´Ù.
<br>
jsonp ¹æ½Ä¿¡¼ Ajax ¿äû ½Ã, Äݹé ÇÔ¼ö À̸§¿¡ ·£´ýÇÑ ¾ÆÀ̵𠰪À» µ¡ºÙ¿© ¸¸µç Äݹé ÇÔ¼ö À̸§À» ¼¹ö·Î Àü´ÞÇÑ´Ù.<br>
ÀÌ ¶§ ·£´ýÇÑ °ªÀ» ¾ÆÀ̵ð·Î »ç¿ëÇÏ¿© ³Ñ±â¹Ç·Î ¿äû URLÀÌ ¸Å¹ø »õ·Ó°Ô »ý¼ºµÇ¾î ij½¬ ¼¹ö°¡ ¾Æ´Ñ ¼¹ö·Î Á÷Á¢ µ¥ÀÌÅ͸¦ ¿äûÇÏ°Ô µÈ´Ù.<br>
¾ÆÀ̵𠰪À» ÁöÁ¤ÇÏ¸é ·£´ýÇÑ ¾ÆÀ̵𠰪À¸·Î Äݹé ÇÔ¼ö À̸§À» »ý¼ºÇÏÁö ¾ÊÀ¸¹Ç·Î<br>
ij½¬ ¼¹ö¸¦ »ç¿ëÇÏ¿© ±×¿¡ ´ëÇÑ È÷Æ®À²À» ³ôÀ̰íÀÚ ÇÒ ¶§ ¾ÆÀ̵𸦠ÁöÁ¤ÇÏ¿© »ç¿ëÇÒ ¼ö ÀÖ´Ù.
</td>
</tr>
<tr>
<td style="font-weight:bold;">callbackname</td>
<td>String</td>
<td>
Äݹé ÇÔ¼ö À̸§À» °¡Áö´Â ¸Å°³º¯¼ö À̸§.<br>
type ÀÌ "jsonp" ÀÏ ¶§ »ç¿ëÇÑ´Ù. ±âº» °ªÀº "_callback" ÀÌ´Ù. (1.3.8 ºÎÅÍ Áö¿ø)
</td>
</tr>
<tr>
<td style="font-weight:bold;">sendheader</td>
<td>Boolean</td>
<td>
¿äû Çì´õ¸¦ Àü¼ÛÇÒÁö ¿©ºÎ.<br>
type ÀÌ "flash" ÀÏ ¶§ »ç¿ëÇϸç, ¼¹ö¿¡¼ Á¢±Ù ±ÇÇÑÀ» ¼³Á¤ÇÏ´Â crossdomain.xml ¿¡<br>
allow-header °¡ ¾ø´Â °æ¿ì¿¡ false ·Î ¼³Á¤ÇØ¾ß ÇÑ´Ù.<br>
Ç÷¡½Ã 9¿¡¼´Â allow-header°¡ falseÀÎ °æ¿ì get¸¸ ajax°¡ µÇ¸é post´Â ajax°¡ ¾ÈµÈ´Ù.<br>
Ç÷¡½Ã 10¿¡¼´Â allow-header°¡ falseÀÎ °æ¿ì get,post µÑ´Ù ajax°¡ ¾ÈµÈ´Ù.<br>
±×·¡¼ allow-header°¡ ¼³Á¤µÇ¾î ÀÖÁö ¾Ê´Ù¸é ¹Ýµå½Ã false·Î ¼ÂÆÃÇØ¾ß ÇÑ´Ù.<br>
±âº» °ªÀº true ÀÌ´Ù. (1.3.4ºÎÅÍ Áö¿ø)
</td>
</tr>
<tr>
<td style="font-weight:bold;">async</td>
<td>Boolean</td>
<td>
ºñµ¿±â È£Ãâ ¿©ºÎ.<br>
type ÀÌ "xhr" ÀÏ ¶§¸¸ À¯È¿ÇÏ´Ù. ±âº» °ªÀº true ÀÌ´Ù. (1.3.7ºÎÅÍ Áö¿ø)
</td>
</tr>
<tr>
<td style="font-weight:bold;">decode</td>
<td>Boolean</td>
<td>
type ÀÌ "flash" ÀÏ ¶§ »ç¿ëÇϸç, ¿äûÇÑ µ¥ÀÌÅÍ ¾È¿¡ euc-kr ÀÌ ¾Æ´Ñ ´Ù¸¥ ÀÎÄÚµùÀÌ µÇ¾î ÀÖÀ»¶§ false ·Î ÁöÁ¤ÇÑ´Ù.<br>
±âº» °ªÀº true ÀÌ´Ù. (1.4.0ºÎÅÍ Áö¿ø)
</td>
</tr>
<tr>
<td style="font-weight:bold;">postBody</td>
<td>Boolean</td>
<td>
¿äû ½Ã ¼¹ö·Î Àü´ÞÇÒ µ¥ÀÌÅ͸¦ Body ¿µ¿ª¿¡ Àü´ÞÇÒ ÁöÀÇ ¿©ºÎ.<br>
type ÀÌ "xhr" À̰í method °¡ "get"ÀÌ ¾Æ´Ï¾î¾ß À¯È¿Çϸç REST ȯ°æ¿¡¼ »ç¿ëµÈ´Ù.<br>
±âº»°ªÀº false ÀÌ´Ù. (1.4.2ºÎÅÍ Áö¿ø)
</td>
</tr>
</tbody>
</table>
* @constructor
* @description [Lite]
* @see <a href="http://dev.naver.com/projects/jindo/wiki/cross%20domain%20ajax">Cross Domain Ajax ÀÌÇØ</a>
* @author Kim, Taegon
*
* @example
// 'Get List' ¹öư Ŭ¸¯ ½Ã, ¼¹ö¿¡¼ µ¥ÀÌÅ͸¦ ¹Þ¾Æ¿Í ¸®½ºÆ®¸¦ ±¸¼ºÇÏ´Â ¿¹Á¦
// (1) ¼¹ö ÆäÀÌÁö¿Í ¼ºñ½º ÆäÀÌÁö°¡ °°Àº µµ¸ÞÀο¡ ÀÖ´Â °æ¿ì - xhr
// [client.html]
<!DOCTYPE html>
<html>
<head>
<title>Ajax Sample</title>
<meta http-equiv="content-type" content="text/html; charset=euc-kr"/>
<script type="text/javascript" language="javascript" src="lib/jindo.all.js"></script>
<script type="text/javascript" language="javascript">
function getList() {
var oAjax = new $Ajax('server.php', {
type : 'xhr',
method : 'get', // GET ¹æ½ÄÀ¸·Î Åë½Å
onload : function(res){ // ¿äûÀÌ ¿Ï·áµÇ¸é ½ÇÇàµÉ Äݹé ÇÔ¼ö
$('list').innerHTML = res.text();
},
timeout : 3, // 3ÃÊ À̳»¿¡ ¿äûÀÌ ¿Ï·áµÇÁö ¾ÊÀ¸¸é ontimeout ½ÇÇà (»ý·« ½Ã 0)
ontimeout : function(){ // ŸÀÓ ¾Æ¿ôÀÌ ¹ß»ýÇÏ¸é ½ÇÇàµÉ Äݹé ÇÔ¼ö, »ý·« ½Ã ŸÀÓ ¾Æ¿ôÀÌ µÇ¸é ¾Æ¹« 󸮵µ ÇÏÁö ¾ÊÀ½
alert("Timeout!");
},
async : true // ºñµ¿±â·Î È£ÃâÇÏ´Â °æ¿ì, »ý·«Çϸé true
});
oAjax.request();
}
</script>
</head>
<body>
<button onclick="getList(); return false;">Get List</button>
<ul id="list">
</ul>
</body>
</html>
// [server.php]
<?php
echo "<li>ù¹øÂ°</li><li>µÎ¹øÂ°</li><li>¼¼¹øÂ°</li>";
?>
* @example
// 'Get List' ¹öư Ŭ¸¯ ½Ã, ¼¹ö¿¡¼ µ¥ÀÌÅ͸¦ ¹Þ¾Æ¿Í ¸®½ºÆ®¸¦ ±¸¼ºÇÏ´Â ¿¹Á¦
// (2) ¼¹ö ÆäÀÌÁö¿Í ¼ºñ½º ÆäÀÌÁö°¡ °°Àº µµ¸ÞÀο¡ ÀÖ´Â °æ¿ì - iframe
// [http://local.com/some/client.html]
<!DOCTYPE html>
<html>
<head>
<title>Ajax Sample</title>
<meta http-equiv="content-type" content="text/html; charset=euc-kr"/>
<script type="text/javascript" language="javascript" src="lib/jindo.all.js"></script>
<script type="text/javascript" language="javascript">
function getList() {
var oAjax = new $Ajax('http://server.com/some/some.php', {
type : 'iframe',
method : 'get', // GET ¹æ½ÄÀ¸·Î Åë½Å
// POST·Î ÁöÁ¤ÇÏ¸é ¿ø°Ý ÇÁ·Ï½Ã ÆÄÀÏ¿¡¼ some.php ·Î ¿äû ½Ã¿¡ POST ¹æ½ÄÀ¸·Î ó¸®
onload : function(res){ // ¿äûÀÌ ¿Ï·áµÇ¸é ½ÇÇàµÉ Äݹé ÇÔ¼ö
$('list').innerHTML = res.text();
},
// ·ÎÄà ÇÁ·Ï½Ã ÆÄÀÏÀÇ °æ·Î.
// ¹Ýµå½Ã Á¤È®ÇÑ °æ·Î¸¦ ÁöÁ¤ÇØ¾ß Çϸç, ·ÎÄà µµ¸ÞÀÎÀÇ °æ·Î¶ó¸é ¾îµð¿¡ µÎ¾îµµ »ó°ü ¾øÀ½
// (¡Ø ¿ø°Ý ÇÁ·Ï½Ã ÆÄÀÏÀº ¹Ýµå½Ã ¿ø°Ý µµ¸ÞÀÎ ¼¹öÀÇ µµ¸ÞÀÎ ·çÆ® »ó¿¡ µÎ¾î¾ß ÇÔ)
proxy : 'http://local.naver.com/some/ajax_local_callback.html'
});
oAjax.request();
}
</script>
</head>
<body>
<button onclick="getList(); return false;">Get List</button>
<ul id="list">
</ul>
</body>
</html>
// [http://server.com/some/some.php]
<?php
echo "<li>ù¹øÂ°</li><li>µÎ¹øÂ°</li><li>¼¼¹øÂ°</li>";
?>
* @example
// 'Get List' ¹öư Ŭ¸¯ ½Ã, ¼¹ö¿¡¼ µ¥ÀÌÅ͸¦ ¹Þ¾Æ¿Í ¸®½ºÆ®¸¦ ±¸¼ºÇÏ´Â ¿¹Á¦
// (3) ¼¹ö ÆäÀÌÁö¿Í ¼ºñ½º ÆäÀÌÁö°¡ °°Àº µµ¸ÞÀο¡ ÀÖ´Â °æ¿ì - jsonp
// [http://local.com/some/client.html]
<!DOCTYPE html>
<html>
<head>
<title>Ajax Sample</title>
<meta http-equiv="content-type" content="text/html; charset=euc-kr"/>
<script type="text/javascript" language="javascript" src="lib/jindo.all.js"></script>
<script type="text/javascript" language="javascript">
function getList(){
var oAjax = new $Ajax('http://server.com/some/some.php', {
type: 'jsonp',
method: 'get', // type ÀÌ jsonp À̸é get À¸·Î ÁöÁ¤ÇÏÁö ¾Ê¾Æµµ ÀÚµ¿À¸·Î get À¸·Î ó¸®ÇÔ (»ý·«°¡´É)
jsonp_charset: 'euc-kr', // ¿äû ½Ã »ç¿ëÇÒ <script> ÀÎÄÚµù ¹æ½Ä (»ý·« ½Ã euc-kr)
onload: function(res){ // ¿äûÀÌ ¿Ï·áµÇ¸é ½ÇÇàµÉ Äݹé ÇÔ¼ö
var response = res.json();
var welList = $Element('list').empty();
for (var i = 0, nLen = response.length; i < nLen; i++) {
welList.append($("<li>" + response[i] + "</li>"));
}
},
callbackid: '12345', // Äݹé ÇÔ¼ö À̸§¿¡ »ç¿ëÇÒ ¾ÆÀ̵𠰪 (»ý·«°¡´É)
callbackname: 'ajax_callback_fn' // ¼¹ö¿¡¼ »ç¿ëÇÒ Äݹé ÇÔ¼öÀ̸§À» °¡Áö´Â ¸Å°³ º¯¼ö À̸§ (»ý·« ½Ã '_callback')
});
oAjax.request();
}
</script>
</head>
<body>
<button onclick="getList(); return false;">Get List</button>
<ul id="list">
</ul>
</body>
</html>
// [http://server.com/some/some.php]
<?php
$callbackName = $_GET['ajax_callback_fn'];
echo $callbackName."(['ù¹øÂ°','µÎ¹øÂ°','¼¼¹øÂ°'])";
?>
* @example
// 'Get List' ¹öư Ŭ¸¯ ½Ã, ¼¹ö¿¡¼ µ¥ÀÌÅ͸¦ ¹Þ¾Æ¿Í ¸®½ºÆ®¸¦ ±¸¼ºÇÏ´Â ¿¹Á¦
// (4) ¼¹ö ÆäÀÌÁö¿Í ¼ºñ½º ÆäÀÌÁö°¡ °°Àº µµ¸ÞÀο¡ ÀÖ´Â °æ¿ì - flash
// [http://local.com/some/client.html]
<!DOCTYPE html>
<html>
<head>
<title>Ajax Sample</title>
<meta http-equiv="content-type" content="text/html; charset=euc-kr"/>
<script type="text/javascript" language="javascript" src="lib/jindo.all.js"></script>
<script type="text/javascript" language="javascript">
function getList(){
var oAjax = new $Ajax('http://server.com/some/some.php', {
type : 'flash',
method : 'get', // GET ¹æ½ÄÀ¸·Î Åë½Å
sendheader : false, // ¿äû Çì´õ¸¦ Àü¼ÛÇÒÁö ¿©ºÎ. (»ý·« ½Ã true)
decode : true, // ¿äûÇÑ µ¥ÀÌÅÍ ¾È¿¡ euc-kr ÀÌ ¾Æ´Ñ ´Ù¸¥ ÀÎÄÚµùÀÌ µÇ¾î ÀÖÀ»¶§ false. (»ý·« ½Ã true)
onload : function(res){ // ¿äûÀÌ ¿Ï·áµÇ¸é ½ÇÇàµÉ Äݹé ÇÔ¼ö
$('list').innerHTML = res.text();
},
});
oAjax.request();
}
</script>
</head>
<body>
<script type="text/javascript">
$Ajax.SWFRequest.write("swf/ajax.swf"); // Ajax È£ÃâÀ» Çϱâ Àü¿¡ ¹Ýµå½Ã Ç÷¡½Ã °´Ã¼¸¦ ÃʱâÈ
</script>
<button onclick="getList(); return false;">Get List</button>
<ul id="list">
</ul>
</body>
</html>
// [http://server.com/some/some.php]
<?php
echo "<li>ù¹øÂ°</li><li>µÎ¹øÂ°</li><li>¼¼¹øÂ°</li>";
?>
*/
jindo.$Ajax = function (url, option) {
var cl = arguments.callee;
if (!(this instanceof cl)) return new cl(url, option);
function _getXHR() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (ActiveXObject) {
try {
return new ActiveXObject('MSXML2.XMLHTTP');
}catch(e) {
return new ActiveXObject('Microsoft.XMLHTTP');
}
return null;
}
}
var loc = location.toString();
var domain = '';
try { domain = loc.match(/^https?:\/\/([a-z0-9_\-\.]+)/i)[1]; } catch(e) {}
this._status = 0;
this._url = url;
this._options = new Object;
this._headers = new Object;
this._options = {
type :"xhr",
method :"post",
proxy :"",
timeout:0,
onload :function(req){},
onerror :null,
ontimeout:function(req){},
jsonp_charset : "euc-kr",
callbackid : "",
callbackname : "",
sendheader : true,
async : true,
decode :true,
postBody :false
};
this.option(option);
/*
Å×½ºÆ®¸¦ À§ÇØ ¿ì¼± Àû¿ë°¡´ÉÇÑ ¼³Á¤ °´Ã¼°¡ Á¸ÀçÇϸé Àû¿ë
*/
if(jindo.$Ajax.CONFIG){
this.option(jindo.$Ajax.CONFIG);
}
var _opt = this._options;
_opt.type = _opt.type.toLowerCase();
_opt.method = _opt.method.toLowerCase();
if (typeof window.__jindo2_callback == "undefined") {
window.__jindo2_callback = new Array();
}
switch (_opt.type) {
case "put":
case "delete":
case "get":
case "post":
_opt.method = _opt.type;
_opt.type = "xhr";
case "xhr":
this._request = _getXHR();
break;
case "flash":
if(!jindo.$Ajax.SWFRequest) throw Error('Require jindo.$Ajax.SWFRequest');
this._request = new jindo.$Ajax.SWFRequest(jindo.$Fn(this.option,this).bind());
break;
case "jsonp":
if(!jindo.$Ajax.JSONPRequest) throw Error('Require jindo.$Ajax.JSONPRequest');
_opt.method = "get";
this._request = new jindo.$Ajax.JSONPRequest(jindo.$Fn(this.option,this).bind());
break;
case "iframe":
if(!jindo.$Ajax.FrameRequest) throw Error('Require jindo.$Ajax.FrameRequest');
this._request = new jindo.$Ajax.FrameRequest(jindo.$Fn(this.option,this).bind());
break;
}
};
/**
* @ignore
*/
jindo.$Ajax.prototype._onload = (function(isIE) {
if(isIE){
return function(){
var bSuccess = this._request.readyState == 4 && this._request.status == 200;
var oResult;
if (this._request.readyState == 4) {
try {
if (this._request.status != 200 && typeof this._options.onerror == 'function'){
if(!this._request.status == 0){
this._options.onerror(jindo.$Ajax.Response(this._request));
}
}else{
if(!this._is_abort){
oResult = this._options.onload(jindo.$Ajax.Response(this._request));
}
}
}finally{
if(typeof this._oncompleted == 'function'){
this._oncompleted(bSuccess, oResult);
}
if (this._options.type == "xhr" ){
this.abort();
try { delete this._request.onload; } catch(e) { this._request.onload =undefined;}
}
delete this._request.onreadystatechange;
}
}
}
}else{
return function(){
var bSuccess = this._request.readyState == 4 && this._request.status == 200;
var oResult;
if (this._request.readyState == 4) {
try {
if (this._request.status != 200 && typeof this._options.onerror == 'function'){
this._options.onerror(jindo.$Ajax.Response(this._request));
}else{
oResult = this._options.onload(jindo.$Ajax.Response(this._request));
}
}finally{
this._status--;
if(typeof this._oncompleted == 'function'){
this._oncompleted(bSuccess, oResult);
}
}
}
}
}
})(/MSIE/.test(window.navigator.userAgent));
/**
* request ¸Þ¼µå´Â Ajax ¿äûÀ» ¼¹ö¿¡ Àü¼ÛÇÑ´Ù.<br>
* ¿äû¿¡ »ç¿ëÇÒ ¸Å°³ º¯¼ö´Â $Ajax »ý¼ºÀÚ¿¡¼ ¼³Á¤Çϰųª option ¸Þ¼µå¿¡¼ º¯°æÇÒ ¼ö ÀÖ´Ù.<br>
*
* @remark ¿äû ŸÀÔ(type)ÀÌ "flash" À̸é ÀÌ ¸Þ¼Òµå¸¦ ½ÇÇàÇϱâ Àü¿¡ body ÅÂ±× ³»ºÎ¿¡¼ $Ajax.SWFRequest.write() ¸í·É¾î¸¦ ¹Ýµå½Ã ½ÇÇàÇØ¾ß ÇÑ´Ù.
*
* @param {Object} oData ¼¹ö·Î Àü¼ÛÇÒ µ¥ÀÌÅÍ.
* @return {$Ajax} $Ajax °´Ã¼
* @description [Lite]
* @example
*
*
var ajax = $Ajax("http://www.remote.com", {
onload : function(res) {
// onload Çڵ鷯
}
});
ajax.request( {key1:"value1", key2:"value2"} ); // ¼¹ö¿¡ Àü¼ÛÇÒ µ¥ÀÌÅ͸¦ ¸Å°³º¯¼ö·Î ³Ñ±ä´Ù.
*/
jindo.$Ajax.prototype.request = function(oData) {
this._status++;
var t = this;
var req = this._request;
var opt = this._options;
var data, v,a = [], data = "";
var _timer = null;
var url = this._url;
this._is_abort = false;
if( opt.postBody && opt.type.toUpperCase()=="XHR" && opt.method.toUpperCase()!="GET"){
if(typeof oData == 'string'){
data = oData;
}else{
data = jindo.$Json(oData).toString();
}
}else if (typeof oData == "undefined" || !oData) {
data = null;
} else {
for(var k in oData) {
if(oData.hasOwnProperty(k)){
v = oData[k];
if (typeof v == "function") v = v();
if (v instanceof Array || v instanceof jindo.$A) {
jindo.$A(v).forEach(function(value,index,array) {
a[a.length] = k+"="+encodeURIComponent(value);
});
} else {
a[a.length] = k+"="+encodeURIComponent(v);
}
}
}
data = a.join("&");
}
/*
XHR GET ¹æ½Ä ¿äûÀÎ °æ¿ì URL¿¡ ÆÄ¶ó¹ÌÅÍ Ãß°¡
*/
if(data && opt.type.toUpperCase()=="XHR" && opt.method.toUpperCase()=="GET"){
if(url.indexOf('?')==-1){
url += "?";
} else {
url += "&";
}
url += data;
data = null;
}
req.open(opt.method.toUpperCase(), url, opt.async);
if(opt.type.toUpperCase()=="XHR"&&opt.method.toUpperCase()=="GET"&&/MSIE/.test(window.navigator.userAgent)){
/*
xhrÀÎ °æ¿ì IE¿¡¼´Â GETÀ¸·Î º¸³¾ ¶§ ºê¶ó¿ìÁ®¿¡¼ ÀÚü cacheÇÏ¿© cacheÀ» ¾ÈµÇ°Ô ¼öÁ¤.
*/
req.setRequestHeader("If-Modified-Since", "Thu, 1 Jan 1970 00:00:00 GMT");
}
if (opt.sendheader) {
if(!this._headers["Content-Type"]){
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=euc-kr");
}
req.setRequestHeader("charset", "euc-kr");
for (var x in this._headers) {
if(this._headers.hasOwnProperty(x)){
if (typeof this._headers[x] == "function")
continue;
req.setRequestHeader(x, String(this._headers[x]));
}
}
}
var navi = navigator.userAgent;
if(req.addEventListener&&!(navi.indexOf("Opera") > -1)&&!(navi.indexOf("MSIE") > -1)){
/*
* opera 10.60¿¡¼ XMLHttpRequest¿¡ addEventListener±â Ãß°¡µÇ¾úÁö¸¸ Á¤»óÀûÀ¸·Î µ¿ÀÛÇÏÁö ¾Ê¾Æ opera´Â ¹«Á¶°Ç dom1¹æ½ÄÀ¸·Î Áö¿øÇÔ.
* IE9¿¡¼µµ opera¿Í °°Àº ¹®Á¦°¡ ÀÖÀ½.
*/
if(this._loadFunc){ req.removeEventListener("load", this._loadFunc, false); }
this._loadFunc = function(rq){
clearTimeout(_timer);
_timer = undefined;
t._onload(rq);
}
req.addEventListener("load", this._loadFunc, false);
}else{
if (typeof req.onload != "undefined") {
req.onload = function(rq){
if(req.readyState == 4 && !t._is_abort){
clearTimeout(_timer);
_timer = undefined;
t._onload(rq);
}
};
} else {
/*
* IE6¿¡¼´Â onreadystatechange°¡ µ¿±âÀûÀ¸·Î ½ÇÇàµÇ¾î timeoutÀ̺¥Æ®°¡ ¹ß»ý¾ÈµÊ.
* ±×·¡¼ interval·Î üũÇÏ¿© timeoutÀ̺¥Æ®°¡ Á¤»óÀûÀ¸·Î ¹ß»ýµÇµµ·Ï ¼öÁ¤. ºñµ¿±â ¹æ½ÄÀ϶§¸¸
*/
if(window.navigator.userAgent.match(/(?:MSIE) ([0-9.]+)/)[1]==6&&opt.async){
var onreadystatechange = function(rq){
if(req.readyState == 4 && !t._is_abort){
if(_timer){
clearTimeout(_timer);
_timer = undefined;
}
t._onload(rq);
clearInterval(t._interval);
t._interval = undefined;
}
};
this._interval = setInterval(onreadystatechange,300);
}else{
req.onreadystatechange = function(rq){
if(req.readyState == 4){
clearTimeout(_timer);
_timer = undefined;
t._onload(rq);
}
};
}
}
}
if (opt.timeout > 0) {
// if(this._interval)clearInterval(this._interval);
if(this._timer) clearTimeout(this._timer);
_timer = setTimeout(function(){
t._is_abort = true;
if(t._interval){
clearInterval(t._interval);
t._interval = undefined;
}
try{ req.abort(); }catch(e){};
opt.ontimeout(req);
if(typeof t._oncompleted == 'function') t._oncompleted(false);
}, opt.timeout * 1000 );
this._timer = _timer;
}
/*
* testÀ» Çϱâ À§ÇÑ url
*/
this._test_url = url;
req.send(data);
return this;
};
/**
* isIdle ¸Þ¼µå´Â Ajax °´Ã¼°¡ ÇöÀç ¿äû ´ë±â »óÅÂÀÎÁö È®ÀÎÇÑ´Ù.
* @return {Boolean} ÇöÀç ´ë±â ÁßÀ̸é true ¸¦, ±×·¸Áö ¾ÊÀ¸¸é false¸¦ ¸®ÅÏÇÑ´Ù.
* @since 1.3.5 ºÎÅÍ »ç¿ë °¡´É
* @description [Lite]
* @example
var ajax = $Ajax("http://www.remote.com",{
onload : function(res){
// onload Çڵ鷯
}
});
if(ajax.isIdle()) ajax.request();
*/
jindo.$Ajax.prototype.isIdle = function(){
return this._status==0;
}
/**
* abort ¸Þ¼µå´Â ¼¹ö·Î Àü¼ÛÇÑ Ajax ¿äûÀ» Ãë¼ÒÇÑ´Ù. Ajax ¿äûÀÇ ÀÀ´ä ½Ã°£ÀÌ ±æ°Å³ª °Á¦·Î Ajax ¿äûÀ» Ãë¼ÒÇÒ °æ¿ì »ç¿ëÇÑ´Ù.
* @return {$Ajax} Àü¼ÛÀ» Ãë¼ÒÇÑ $Ajax °´Ã¼
* @description [Lite]
* @example
var ajax = $Ajax("http://www.remote.com", {
timeout : 3,
ontimeout : function() {
stopRequest();
}
onload : function(res) {
// onload Çڵ鷯
}
}).request( {key1:"value1", key2:"value2"} );
function stopRequest() {
ajax.abort();
}
*/
jindo.$Ajax.prototype.abort = function() {
try {
if(this._interval) clearInterval(this._interval);
if(this._timer) clearTimeout(this._timer);
this._interval = undefined;
this._timer = undefined;
this._is_abort = true;
this._request.abort();
}finally{
this._status--;
}
return this;
};
/**
* option ¸Þ¼µå´Â Ajax ¿äû¿¡¼ »ç¿ëÇÑ Á¤º¸¸¦ °¡Á®¿À°Å³ª ȤÀº ¼³Á¤ÇÑ´Ù.<br>
* ¼³Á¤ÇÏ·Á¸é À̸§°ú °ªÀ», ȤÀº À̸§°ú °ªÀ» ¿ø¼Ò·Î °¡Áö´Â ÇϳªÀÇ °´Ã¼¸¦ ¸Å°³ º¯¼ö·Î »ç¿ëÇÑ´Ù.<br>
* À̸§°ú °ªÀ» ¿ø¼Ò·Î °¡Áö´Â °´Ã¼¸¦ »ç¿ëÇÏ¸é µÎ °³ ÀÌ»óÀÇ Á¤º¸¸¦ ÇÑ ¹ø¿¡ ¼³Á¤ÇÒ ¼ö ÀÖ´Ù.
*
* @param {String | Object} name <br>
* ¸Å°³ º¯¼öÀÇ Å¸ÀÔÀº ¹®ÀÚ¿ ȤÀº °´Ã¼¸¦ »ç¿ëÇÑ´Ù.<br>
* <br>
* ¹®ÀÚ¿À» ¸Å°³ º¯¼ö·Î »ç¿ëÇÏ¸é ´ÙÀ½°ú °°ÀÌ µ¿ÀÛÇÑ´Ù..<br>
* 1. value ¸Å°³ º¯¼ö¸¦ »ý·«Çϸé À̸§¿¡ ÇØ´çÇÏ´Â $AjaxÀÇ ¼Ó¼º °ªÀ» ¸®ÅÏÇÑ´Ù.<br>
* 2. value ¸Å°³ º¯¼ö¸¦ ¼³Á¤Çϸé À̸§¿¡ ÇØ´çÇÏ´Â $AjaxÀÇ ¼Ó¼º¿¡ value¸¦ °ªÀ¸·Î ¼³Á¤ÇÑ´Ù.<br>
* <br>
* °´Ã¼ÀÎ °æ¿ì¿¡´Â ¼Ó¼º À̸§À¸·Î Á¤º¸¸¦ ã¾Æ ¼Ó¼ºÀÇ °ªÀ¸·Î ¼³Á¤ÇÑ´Ù. °´Ã¼¿¡ µÎ °³ ÀÌ»óÀÇ ¼Ó¼ºÀ» ÁöÁ¤ÇÏ¸é ¿©·¯ ¼Ó¼º °ªÀ» ÇÑ ¹ø¿¡ ¼³Á¤ÇÒ ¼ö ÀÖ´Ù.
* @param {String} [value] »õ·Î ¼³Á¤ÇÒ Á¤º¸ÀÇ °ª. name ¸Å°³ º¯¼ö°¡ ¹®ÀÚ¿ÀÎ °æ¿ì¿¡¸¸ »ç¿ëµÈ´Ù.
* @return {String|$Ajax} Á¤º¸ÀÇ °ªÀ» °¡Á®¿Ã ¶§´Â ¹®ÀÚ¿À», °ªÀ» ¼³Á¤ÇÒ ¶§´Â $Ajax °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @description [Lite]
* @example
var ajax = $Ajax("http://www.remote.com", {
type : "xhr",
method : "get",
onload : function(res) {
// onload Çڵ鷯
}
});
var request_type = ajax.option("type"); // type ÀÎ xhr À» ¸®ÅÏÇÑ´Ù.
ajax.option("method", "post"); // method ¸¦ post ·Î ¼³Á¤ÇÑ´Ù.
ajax.option( { timeout : 0, onload : handler_func } ); // timeout À» À¸·Î, onload ¸¦ handler_func ·Î ¼³Á¤ÇÑ´Ù.
*/
jindo.$Ajax.prototype.option = function(name, value) {
if (typeof name == "undefined") return "";
if (typeof name == "string") {
if (typeof value == "undefined") return this._options[name];
this._options[name] = value;
return this;
}
try {
for(var x in name){
if(name.hasOwnProperty(x))
this._options[x] = name[x]
}
} catch(e) {};
return this;
};
/**
* header ¸Þ¼µå´Â Ajax ¿äû¿¡¼ »ç¿ëÇÒ HTTP ¿äû Çì´õ¸¦ °¡Á®¿À°Å³ª ¼³Á¤ÇÑ´Ù.<br>
* Çì´õ¸¦ ¼³Á¤ÇÏ·Á¸é Çì´õÀÇ À̸§°ú °ªÀ» °¢°¢ ¸Å°³ º¯¼ö·Î »ç¿ëÇϰųª, Çì´õÀÇ À̸§°ú °ªÀ» ¿ø¼Ò·Î °¡Áö´Â °´Ã¼¸¦ ¸Å°³ º¯¼ö·Î »ç¿ëÇÑ´Ù. ¸¸¾à ¿©·¯ °³ÀÇ ¼Ó¼ºÀ» °¡Áø °´Ã¼¸¦ »ç¿ëÇÏ¸é µÎ °³ ÀÌ»óÀÇ Çì´õ¸¦ ÇÑ ¹ø¿¡ ¼³Á¤ÇÒ ¼ö ÀÖ´Ù.<br>
* Çì´õ¿¡¼ ƯÁ¤ ¼Ó¼ºÀÇ °ªÀ» °¡Á®¿À·Á¸é ¼Ó¼ºÀÇ À̸§À» ¸Å°³ º¯¼ö·Î »ç¿ëÇÑ´Ù.
*
* @param {String|Object} name <br>
* ¸Å°³ º¯¼öÀÇ Å¸ÀÔÀº ¹®ÀÚ¿ ȤÀº °´Ã¼¸¦ »ç¿ëÇÑ´Ù.<br>
* <br>
* ¹®ÀÚ¿À» ¸Å°³ º¯¼ö·Î »ç¿ëÇÏ¸é ´ÙÀ½°ú °°ÀÌ µ¿ÀÛÇÑ´Ù. <br>
* 1. value ¸Å°³ º¯¼ö¸¦ »ý·«Çϸé HTTP ¿äû Çì´õ¿¡¼ ¹®ÀÚ¿°ú ÀÏÄ¡ÇÏ´Â ¼Ó¼º°ªÀ» ã´Â´Ù.<br>
* 2. value ¸Å°³ º¯¼ö¸¦ ¼³Á¤Çϸé HTTP ¿äû Çì´õ¿¡¼ ¹®ÀÚ¿°ú ÀÏÄ¡ÇÏ´Â ¼Ó¼º¿¡ value¸¦ °ªÀ¸·Î ¼³Á¤ÇÑ´Ù.<br>
* <br>
* °´Ã¼ÀÎ °æ¿ì¿¡´Â ¼Ó¼º À̸§À¸·Î Á¤º¸¸¦ ã¾Æ ¼Ó¼ºÀÇ °ªÀ¸·Î ¼³Á¤ÇÑ´Ù. °´Ã¼¿¡ µÎ °³ ÀÌ»óÀÇ ¼Ó¼ºÀ» ÁöÁ¤Çϸé HTTP ¿äû Çì´õ¿¡¼ ¿©·¯ ¼Ó¼º °ªÀ» ÇÑ ¹ø¿¡ ¼³Á¤ÇÒ ¼ö ÀÖ´Ù.
* @param {Value} [value] ¼³Á¤ÇÒ Çì´õ °ª. name ¸Å°³ º¯¼ö°¡ ¹®ÀÚ¿ÀÎ °æ¿ì¿¡¸¸ »ç¿ëµÈ´Ù.
* @return {String|$Ajax} Á¤º¸ÀÇ °ªÀ» °¡Á®¿Ã ¶§´Â ¹®ÀÚ¿À», °ªÀ» ¼³Á¤ÇÒ ¶§´Â $Ajax °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @description [Lite]
* @example
var customheader = ajax.header("myHeader"); // HTTP ¿äû Çì´õ¿¡¼ myHeader ÀÇ °ª
ajax.header( "myHeader", "someValue" ); // HTTP ¿äû Çì´õÀÇ myHeader ¸¦ someValue ·Î ¼³Á¤ÇÑ´Ù.
ajax.header( { anotherHeader : "someValue2" } ); // HTTP ¿äû Çì´õÀÇ anotherHeader ¸¦ someValue2 ·Î ¼³Á¤ÇÑ´Ù.
*/
jindo.$Ajax.prototype.header = function(name, value) {
if (typeof name == "undefined") return "";
if (typeof name == "string") {
if (typeof value == "undefined") return this._headers[name];
this._headers[name] = value;
return this;
}
try {
for (var x in name) {
if (name.hasOwnProperty(x))
this._headers[x] = name[x]
}
} catch(e) {};
return this;
};
/**
* Ajax ÀÀ´ä °´Ã¼¸¦ ·¡ÇÎÇÏ¿© ÀÀ´äÀ» °¡Á®¿À´Âµ¥ À¯¿ëÇÑ ¸Þ¼µå¸¦ Á¦°øÇÑ´Ù.
* @class $Ajax.Response °´Ã¼¸¦ »ý¼ºÇÏ¿© ¸®ÅÏÇÑ´Ù.<br>
* $Ajax °´Ã¼¿¡¼ request ¿äû ó¸® ¿Ï·á ÈÄ, »ý¼ºµÇ¸ç $Ajax »ý¼º ½Ã¿¡ ¼³Á¤ÇÑ onload Äݹé ÇÔ¼öÀÇ ¸Å°³ º¯¼ö·Î Àü´ÞµÈ´Ù.
* @constructor
* @param {Object} req ¿äû °´Ã¼
* @description [Lite]
*/
jindo.$Ajax.Response = function(req) {
if (this === jindo.$Ajax) return new jindo.$Ajax.Response(req);
this._response = req;
};
/**
* ÀÀ´äÀ» XML °´Ã¼·Î ¸®ÅÏÇÑ´Ù.
* @return {Object} ÀÀ´ä XML °´Ã¼. XHRÀÇ responseXML °ú À¯»çÇÏ´Ù.
* @description [Lite]
*
* @example
// some.xml
?<?xml version="1.0" encoding="euc-kr"?>
<data>
<li>ù¹øÂ°</li>
<li>µÎ¹øÂ°</li>
<li>¼¼¹øÂ°</li>
</data>
// client.html
var oAjax = new $Ajax('some.xml', {
type : 'xhr',
method : 'get',
onload : function(res){
var elData = cssquery.getSingle('data', res.xml()); // ÀÀ´äÀ» XML °´Ã¼·Î ¸®ÅÏÇÑ´Ù
$('list').innerHTML = elData.firstChild.nodeValue;
},
}).request();
*/
jindo.$Ajax.Response.prototype.xml = function() {
return this._response.responseXML;
};
/**
* ÀÀ´äÀ» ¹®ÀÚ¿·Î ¸®ÅÏÇÑ´Ù.
* @return {String} ÀÀ´ä ¹®ÀÚ¿. XHRÀÇ responseText ¿Í À¯»çÇÏ´Ù.
* @description [Lite]
*
* @example
// some.php
<?php
echo "<li>ù¹øÂ°</li><li>µÎ¹øÂ°</li><li>¼¼¹øÂ°</li>";
?>
// client.html
var oAjax = new $Ajax('some.xml', {
type : 'xhr',
method : 'get',
onload : function(res){
$('list').innerHTML = res.text(); // ÀÀ´äÀ» ¹®ÀÚ¿·Î ¸®ÅÏÇÑ´Ù
},
}).request();
*/
jindo.$Ajax.Response.prototype.text = function() {
return this._response.responseText;
};
/**
* HTTP ÀÀ´ä Äڵ带 ¸®ÅÏÇÑ´Ù.
* @return {Number} ÀÀ´ä ÄÚµå. http ÀÀ´ä ÄÚµåÇ¥¸¦ Âü°íÇÑ´Ù.
* @description [Lite]
*
* @example
var oAjax = new $Ajax('some.php', {
type : 'xhr',
method : 'get',
onload : function(res){
if(res.status() == 200){ // HTTP ÀÀ´ä Äڵ带 È®ÀÎÇÑ´Ù.
$('list').innerHTML = res.text();
}
},
}).request();
*/
jindo.$Ajax.Response.prototype.status = function() {
return this._response.status;
};
/**
* ÀÀ´äÀÇ readyState ¸¦ ¸®ÅÏÇÑ´Ù.
* @return {Number} readyState.
* @description [Lite]
*
* @example
var oAjax = new $Ajax('some.php', {
type : 'xhr',
method : 'get',
onload : function(res){
if(res.readyState() == 4){ // ÀÀ´äÀÇ readyState ¸¦ È®ÀÎÇÑ´Ù.
$('list').innerHTML = res.text();
}
},
}).request();
*/
jindo.$Ajax.Response.prototype.readyState = function() {
return this._response.readyState;
};
/**
* ÀÀ´äÀ» JSON °´Ã¼·Î ¸®ÅÏÇÑ´Ù.
* @return {Object} ÀÀ´ä JSON °´Ã¼. <br>
* ÀÀ´ä ¹®ÀÚ¿À» ÀÚµ¿À¸·Î JSON °´Ã¼·Î º¯È¯ÇÏ¿© ¸®ÅÏÇÑ´Ù. º¯È¯ °úÁ¤¿¡¼ ¿À·ù°¡ ¹ß»ýÇÏ¸é ºó °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @description [Lite]
*
* @example
// some.php
<?php
echo "['ù¹øÂ°', 'µÎ¹øÂ°', '¼¼¹øÂ°']";
?>
// client.html
var oAjax = new $Ajax('some.php', {
type : 'xhr',
method : 'get',
onload : function(res){
var welList = $Element('list').empty();
var jsonData = res.json(); // ÀÀ´äÀ» JSON °´Ã¼·Î ¸®ÅÏÇÑ´Ù
for(var i = 0, nLen = jsonData.length; i < nLen; i++){
welList.append($("<li>" + jsonData[i] + "</li>"));
}
},
}).request();
*/
jindo.$Ajax.Response.prototype.json = function() {
if (this._response.responseJSON) {
return this._response.responseJSON;
} else if (this._response.responseText) {
try {
return eval("("+this._response.responseText+")");
} catch(e) {
return {};
}
}
return {};
};
/**
* ÀÀ´ä Çì´õ¸¦ °¡Á®¿Â´Ù. ¸Å°³ º¯¼ö¸¦ Àü´ÞÇÏÁö ¾ÊÀ¸¸é Çì´õ Àüü¸¦ ¸®ÅÏÇÑ´Ù.
* @param {String} name °¡Á®¿Ã ÀÀ´ä Çì´õÀÇ À̸§
* @return {String|Object} ¸Å°³ º¯¼ö°¡ ÀÖÀ» ¶§´Â ÇØ´çÇÏ´Â Çì´õ °ªÀ», ±×·¸Áö ¾ÊÀ¸¸é Çì´õ Àüü¸¦ ¸®ÅÏÇÑ´Ù.
* @description [Lite]
*
* @example
var oAjax = new $Ajax('some.php', {
type : 'xhr',
method : 'get',
onload : function(res){
res.header(); // ÀÀ´ä Çì´õ Àüü¸¦ ¸®ÅÏÇÑ´Ù.
res.header("Content-Length") // ÀÀ´ä Çì´õ¿¡¼ "Content-Length" ÀÇ °ªÀ» ¸®ÅÏÇÑ´Ù.
},
}).request();
*/
jindo.$Ajax.Response.prototype.header = function(name) {
if (typeof name == "string") return this._response.getResponseHeader(name);
return this._response.getAllResponseHeaders();
};
/**
* @fileOverview $AjaxÀÇ È®Àå ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name Ajax.extend.js
*/
/**
* Ajax ¿äû ŸÀÔ º°·Î ¿äû °´Ã¼¸¦ »ý¼ºÇϱâ À§ÇÑ »óÀ§ °´Ã¼·Î »ç¿ëÇÑ´Ù.
* @class Ajax ¿äû °´Ã¼ÀÇ ±âº» °´Ã¼ÀÌ´Ù.
*/
jindo.$Ajax.RequestBase = jindo.$Class({
_respHeaderString : "",
callbackid:"",
callbackname:"",
responseXML : null,
responseJSON : null,
responseText : "",
status : 404,
readyState : 0,
$init : function(fpOption){},
onload : function(){},
abort : function(){},
open : function(){},
send : function(){},
setRequestHeader : function(sName, sValue) {
this._headers[sName] = sValue;
},
getResponseHeader : function(sName) {
return this._respHeaders[sName] || "";
},
getAllResponseHeaders : function() {
return this._respHeaderString;
},
_getCallbackInfo : function() {
var id = "";
if(this.option("callbackid")!="") {
var idx = 0;
do {
id = "_" + this.option("callbackid") + "_"+idx;
idx++;
} while (window.__jindo2_callback[id]);
}else{
do {
id = "_" + Math.floor(Math.random() * 10000);
} while (window.__jindo2_callback[id]);
}
if(this.option("callbackname") == ""){
this.option("callbackname","_callback");
}
return {callbackname:this.option("callbackname"),id:id,name:"window.__jindo2_callback."+id};
}
});
/**
* $Ajax.JSONPRequest °´Ã¼¸¦ »ý¼ºÇÏ¿© ¸®ÅÏÇÑ´Ù.
* @extends $Ajax.RequestBase
* @class Ajax ¿äû ŸÀÔ(type)ÀÌ jsonp ÀÎ ¿äû °´Ã¼¸¦ »ý¼ºÇϸç, jindo.$Ajax »ý¼ºÀÚ¿¡¼ ¿äû °´Ã¼ »ý¼º ½Ã »ç¿ëÇÑ´Ù.
*/
jindo.$Ajax.JSONPRequest = jindo.$Class({
_headers : {},
_respHeaders : {},
_script : null,
_onerror : null,
$init : function(fpOption){
this.option = fpOption;
},
_callback : function(data) {
if (this._onerror) {
clearTimeout(this._onerror);
this._onerror = null;
}
var self = this;
this.responseJSON = data;
this.onload(this);
setTimeout(function(){ self.abort() }, 10);
},
abort : function() {
if (this._script) {
try {
this._script.parentNode.removeChild(this._script);
}catch(e){
};
}
},
open : function(method, url) {
this.responseJSON = null;
this._url = url;
},
send : function(data) {
var t = this;
var info = this._getCallbackInfo();
var head = document.getElementsByTagName("head")[0];
this._script = jindo.$("<script>");
this._script.type = "text/javascript";
this._script.charset = this.option("jsonp_charset");
if (head) {
head.appendChild(this._script);
} else if (document.body) {
document.body.appendChild(this._script);
}
window.__jindo2_callback[info.id] = function(data){
try {
t.readyState = 4;
t.status = 200;
t._callback(data);
} finally {
delete window.__jindo2_callback[info.id];
}
};
var agent = jindo.$Agent(navigator);
if (agent.navigator().ie || agent.navigator().opera) {
this._script.onreadystatechange = function(){
if (this.readyState == 'loaded'){
if (!t.responseJSON) {
t.readyState = 4;
t.status = 500;
t._onerror = setTimeout(function(){t._callback(null);}, 200);
}
this.onreadystatechange = null;
}
};
} else {
this._script.onload = function(){
if (!t.responseJSON) {
t.readyState = 4;
t.status = 500;
t._onerror = setTimeout(function(){t._callback(null);}, 200);
}
this.onload = null;
this.onerror = null;
};
this._script.onerror = function(){
if (!t.responseJSON) {
t.readyState = 4;
t.status = 404;
t._onerror = setTimeout(function(){t._callback(null);}, 200);
}
this.onerror = null;
this.onload = null;
};
}
var delimiter = "&";
if(this._url.indexOf('?')==-1){
delimiter = "?";
}
if (data) {
data = "&" + data;
}else{
data = "";
}
//test url for spec.
this._test_url = this._url+delimiter+info.callbackname+"="+info.name+data;
this._script.src = this._url+delimiter+info.callbackname+"="+info.name+data;
}
}).extend(jindo.$Ajax.RequestBase);
/**
* $Ajax.SWFRequest °´Ã¼¸¦ »ý¼ºÇÏ¿© ¸®ÅÏÇÑ´Ù.
* @extends $Ajax.RequestBase
* @class Ajax ¿äû ŸÀÔ(type)ÀÌ flash ÀÎ ¿äû °´Ã¼¸¦ »ý¼ºÇϸç, jindo.$Ajax »ý¼ºÀÚ¿¡¼ ¿äû °´Ã¼ »ý¼º ½Ã »ç¿ëÇÑ´Ù.
*/
jindo.$Ajax.SWFRequest = jindo.$Class({
$init : function(fpOption){
this.option = fpOption;
},
_headers : {},
_respHeaders : {},
_getFlashObj : function(){
var navi = jindo.$Agent(window.navigator).navigator();
var obj;
if (navi.ie&&navi.version==9) {
obj = document.getElementById(jindo.$Ajax.SWFRequest._tmpId);
}else{
obj = window.document[jindo.$Ajax.SWFRequest._tmpId];
}
return(this._getFlashObj = function(){
return obj;
})();
},
_callback : function(status, data, headers){
this.readyState = 4;
/*
ÇÏÀ§ ȣȯÀ» À§ÇØ status°¡ boolean °ªÀÎ °æ¿ìµµ ó¸®
*/
if( (typeof status).toLowerCase() == 'number'){
this.status = status;
}else{
if(status==true) this.status=200;
}
if (this.status==200) {
if (typeof data == "string") {
try {
this.responseText = this.option("decode")?decodeURIComponent(data):data;
if(!this.responseText || this.responseText=="") {
this.responseText = data;
}
} catch(e) {
/*
µ¥ÀÌÅÍ ¾È¿¡ euc-krÀÌ ¾Æ´Ñ ´Ù¸¥ ÀÎÄÚµùÀ϶§ µðÄÚµùÀ» ¾ÈÇÏ°í ¹Ù·Î text¿¡ ÀúÀå.
*/
if(e.name == "URIError"){
this.responseText = data;
if(!this.responseText || this.responseText=="") {
this.responseText = data;
}
}
}
}
/*
ÄݹéÄÚµå´Â ³Ö¾úÁö¸¸, ¾ÆÁ÷ SWF¿¡¼ ÀÀ´äÇì´õ Áö¿ø ¾ÈÇÔ
*/
if(typeof headers == "object"){
this._respHeaders = headers;
}
}
this.onload(this);
},
open : function(method, url) {
var re = /https?:\/\/([a-z0-9_\-\.]+)/i;
this._url = url;
this._method = method;
},
send : function(data) {
this.responseXML = false;
this.responseText = "";
var t = this;
var dat = {};
var info = this._getCallbackInfo();
var swf = this._getFlashObj()
function f(arg) {
switch(typeof arg){
case "string":
return '"'+arg.replace(/\"/g, '\\"')+'"';
break;
case "number":
return arg;
break;
case "object":
var ret = "", arr = [];
if (arg instanceof Array) {
for(var i=0; i < arg.length; i++) {
arr[i] = f(arg[i]);
}
ret = "["+arr.join(",")+"]";
} else {
for(var x in arg) {
if(arg.hasOwnProperty(x)){
arr[arr.length] = f(x)+":"+f(arg[x]);
}
}
ret = "{"+arr.join(",")+"}";
}
return ret;
default:
return '""';
}
}
data = (data || "").split("&");
for(var i=0; i < data.length; i++) {
pos = data[i].indexOf("=");
key = data[i].substring(0,pos);
val = data[i].substring(pos+1);
dat[key] = decodeURIComponent(val);
}
this._current_callback_id = info.id
window.__jindo2_callback[info.id] = function(success, data){
try {
t._callback(success, data);
} finally {
delete window.__jindo2_callback[info.id];
}
};
var oData = {
url : this._url,
type : this._method,
data : dat,
charset : "euc-kr",
callback : info.name,
header_json : this._headers
};
swf.requestViaFlash(f(oData));
},
abort : function(){
if(this._current_callback_id){
window.__jindo2_callback[this._current_callback_id] = function(){
delete window.__jindo2_callback[info.id];
}
}
}
}).extend(jindo.$Ajax.RequestBase);
/**
* Ajax ¿äû ŸÀÔ(type)ÀÌ flash ÀÏ ¶§, request ¸Þ¼Òµå°¡ È£ÃâµÇ±â Àü¿¡ ¹Ýµå½Ã ÇÑ ¹ø ½ÇÇàÇØ¾ß ÇÑ´Ù.<br>
* <br>
* ¿äû ŸÀÔÀÌ flash ÀÌ¸é ¸ðµç Åë½ÅÀº Ç÷¡½Ã °´Ã¼¸¦ ÅëÇÏ¿© ÁÖ°í ¹ÞÀ¸¸ç Ajax È£ÃâÀ» Çϱâ Àü¿¡ ¹Ýµå½Ã Ç÷¡½Ã °´Ã¼¸¦ ÃʱâÈÇØ¾ßÇÑ´Ù.<br>
* $Ajax.SWFRequest.write ¸Þ¼µå¸¦ È£ÃâÇϸé Åë½ÅÀ» À§ÇÑ Ç÷¡½Ã °´Ã¼¸¦ ¹®¼ ³»¿¡ Ãß°¡ÇÑ´Ù.
*
* @param {String} [swf_path] Åë½ÅÀ» ´ã´çÇÒ Ç÷¡½Ã ÆÄÀÏÀÇ °æ·Î. »ý·«ÇÏ¸é ±âº» °ªÀº "./ajax.swf" ÀÌ´Ù.
*
* @remark ÇØ´ç ¸Þ¼µå´Â <body> ÅÂ±× ³»¿¡ ÀÛ¼ºµÇ¾î¾ß ÇÑ´Ù.
* @remark ¹Ýµå½Ã ÇÑ ¹ø ½ÇÇàÇØ¾ß ÇÑ´Ù. µÎ ¹ø ÀÌ»ó ½ÇÇàÇØµµ ¹®Á¦°¡ ¹ß»ýÇÑ´Ù.
*
* @see $Ajax#request
*/
jindo.$Ajax.SWFRequest.write = function(swf_path) {
if(typeof swf_path == "undefined") swf_path = "./ajax.swf";
jindo.$Ajax.SWFRequest._tmpId = 'tmpSwf'+(new Date()).getMilliseconds()+Math.floor(Math.random()*100000);
var activeCallback = "jindo.$Ajax.SWFRequest.loaded";
jindo.$Ajax._checkFlashLoad();
document.write('<div style="position:absolute;top:-1000px;left:-1000px"><object id="'+jindo.$Ajax.SWFRequest._tmpId+'" width="1" height="1" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"><param name="movie" value="'+swf_path+'"><param name = "FlashVars" value = "activeCallback='+activeCallback+'" /><param name = "allowScriptAccess" value = "always" /><embed name="'+jindo.$Ajax.SWFRequest._tmpId+'" src="'+swf_path+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" width="1" height="1" allowScriptAccess="always" swLiveConnect="true" FlashVars="activeCallback='+activeCallback+'"></embed></object></div>');
};
/**
* @ignore
*/
jindo.$Ajax._checkFlashLoad = function(){
jindo.$Ajax._checkFlashKey = setTimeout(function(){
// throw new Error("Check your flash file!. Unload flash on a page.");
// [SMARTEDITORSUS-334] Flash ¸¦ Áö¿øÇÏÁö ¾Ê´Â ȯ°æ(ex. iOS)¿¡¼ °æ°íâÀ» ¶ç¿ìÁö ¾Êµµ·Ï ÀÓ½ÃÀûÀ¸·Î ÁÖ¼® ó¸®ÇÔ
// alert("Check your flash file!. Unload flash on a page.");
},5000);
jindo.$Ajax._checkFlashLoad = function(){}
}
/**
* flash°¡ ·Îµù µÇ¾ú´ÂÁö È®ÀÎ ÇÏ´Â º¯¼ö.
*/
jindo.$Ajax.SWFRequest.activeFlash = false;
/**
* flash¿¡¼ ·Îµù ÈÄ ½ÇÇà ½ÃŰ´Â ÇÔ¼ö.
* @ignore
*/
jindo.$Ajax.SWFRequest.loaded = function(){
clearTimeout(jindo.$Ajax._checkFlashKey);
jindo.$Ajax.SWFRequest.activeFlash = true;
}
/**
* $Ajax.FrameRequest °´Ã¼¸¦ »ý¼ºÇÏ¿© ¸®ÅÏÇÑ´Ù.
* @extends $Ajax.RequestBase
* @class Ajax ¿äû ŸÀÔ(type)ÀÌ iframe ÀÎ ¿äû °´Ã¼¸¦ »ý¼ºÇϸç, jindo.$Ajax »ý¼ºÀÚ¿¡¼ ¿äû °´Ã¼ »ý¼º ½Ã »ç¿ëÇÑ´Ù.
*/
jindo.$Ajax.FrameRequest = jindo.$Class({
_headers : {},
_respHeaders : {},
_frame : null,
_domain : "",
$init : function(fpOption){
this.option = fpOption;
},
_callback : function(id, data, header) {
var self = this;
this.readyState = 4;
this.status = 200;
this.responseText = data;
this._respHeaderString = header;
header.replace(/^([\w\-]+)\s*:\s*(.+)$/m, function($0,$1,$2) {
self._respHeaders[$1] = $2;
});
this.onload(this);
setTimeout(function(){ self.abort() }, 10);
},
abort : function() {
if (this._frame) {
try {
this._frame.parentNode.removeChild(this._frame);
} catch(e) {
}
}
},
open : function(method, url) {
var re = /https?:\/\/([a-z0-9_\-\.]+)/i;
var dom = document.location.toString().match(re);
this._method = method;
this._url = url;
this._remote = String(url).match(/(https?:\/\/[a-z0-9_\-\.]+)(:[0-9]+)?/i)[0];
this._frame = null;
this._domain = (dom[1] != document.domain)?document.domain:"";
},
send : function(data) {
this.responseXML = "";
this.responseText = "";
var t = this;
var re = /https?:\/\/([a-z0-9_\-\.]+)/i;
var info = this._getCallbackInfo();
var url;
var _aStr = [];
_aStr.push(this._remote+"/ajax_remote_callback.html?method="+this._method);
var header = new Array;
window.__jindo2_callback[info.id] = function(id, data, header){
try {
t._callback(id, data, header);
} finally {
delete window.__jindo2_callback[info.id];
}
};
for(var x in this._headers) {
if(this._headers.hasOwnProperty(x)){
header[header.length] = "'"+x+"':'"+this._headers[x]+"'";
}
}
header = "{"+header.join(",")+"}";
_aStr.push("&id="+info.id);
_aStr.push("&header="+encodeURIComponent(header));
_aStr.push("&proxy="+encodeURIComponent(this.option("proxy")));
_aStr.push("&domain="+this._domain);
_aStr.push("&url="+encodeURIComponent(this._url.replace(re, "")));
_aStr.push("#"+encodeURIComponent(data));
var fr = this._frame = jindo.$("<iframe>");
fr.style.position = "absolute";
fr.style.visibility = "hidden";
fr.style.width = "1px";
fr.style.height = "1px";
var body = document.body || document.documentElement;
if (body.firstChild){
body.insertBefore(fr, body.firstChild);
}else{
body.appendChild(fr);
}
fr.src = _aStr.join("");
}
}).extend(jindo.$Ajax.RequestBase);
/**
* $Ajax °´Ã¼¸¦ ¼ø¼´ë·Î È£ÃâÇÒ ¼ö ÀÖ´Â ±â´ÉÀ» Á¦°øÇÑ´Ù.
* @class $Ajax.Queue´Â Ajax ¿äûÀ» Å¥¿¡ ´ã¾Æ Å¥¿¡ µé¾î¿Â ¼ø¼´ë·Î ó¸®ÇÑ´Ù.
* @param {Object} option $Ajax.Queue ¿¡¼ ¼¹ö¿¡ ¿äûÇÒ ¶§ »ç¿ëÇÏ´Â ´Ù¾çÇÑ Á¤º¸¸¦ Á¤ÀÇÇÑ´Ù.
<ul>
<li>
async : ºñµ¿±â/µ¿±â ¿äû ¿©ºÎ¸¦ ¼³Á¤ÇÑ´Ù. ºñµ¿±âÀÎ °æ¿ì true À̸ç, ±âº» °ªÀº false ÀÌ´Ù.
</li>
<li>
useResultAsParam : ÀÌÀü¿¡ ó¸®µÈ ¿äûÀÇ °á°ú¸¦ ´ÙÀ½ ¿äû¿¡ ¸Å°³ º¯¼ö·Î ³Ñ±æÁö ¿©ºÎ¸¦ ¼³Á¤ÇÑ´Ù. ¿äû °á°ú¸¦ ³Ñ±â¸é true À̸ç, ±âº» °ªÀº false ÀÌ´Ù.
</li>
<li>
stopOnFailure : ÀÌÀü ¿äûÀÌ ½ÇÆÐÇÏ´Â °æ¿ì ´ÙÀ½ ¿äûÀ» ¸ØÃâÁö ¿©ºÎ¸¦ ¼³Á¤ÇÑ´Ù. ¸ØÃá´Ù¸é true À̸ç, ±âº» °ªÀº false ÀÌ´Ù.
</li>
</ul>
* @constructor
* @since 1.3.7
*
* @example
// $Ajax ¿äû Å¥¸¦ »ý¼ºÇÑ´Ù.
var oAjaxQueue = new $Ajax.Queue({
useResultAsParam : true
});
*/
jindo.$Ajax.Queue = function (option) {
var cl = arguments.callee;
if (!(this instanceof cl)){ return new cl(option);}
this._options = {
async : false,
useResultAsParam : false,
stopOnFailure : false
};
this.option(option);
this._queue = [];
}
/**
* $Ajax.Queue ÀÇ ¿É¼ÇÀ» °¡Á®¿À°Å³ª ¼³Á¤ÇÑ´Ù.
* @param {Object} name ¿É¼ÇÀÇ À̸§
* @param {Object} [value] ¿É¼ÇÀÇ °ª. ¿É¼ÇÀ» ¼³Á¤ÇÏ´Â °æ¿ì¿¡´Â °ªÀ» ÁöÁ¤ÇÑ´Ù.
* @return {Value | $Ajax.Queue} °ªÀ» °¡Á®¿À´Â °æ¿ì ÇØ´ç °ªÀ», ¼³Á¤ÇÏ´Â °æ¿ì $Ajax.Queue °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @example
var oAjaxQueue = new $Ajax.Queue({
useResultAsParam : true
});
oAjaxQueue.option("useResultAsParam"); // useResultAsParam ¿É¼Ç °ªÀÎ true ¸¦ ¸®ÅÏÇÑ´Ù.
oAjaxQueue.option("async", true); // async ¿É¼ÇÀ» true ·Î ¼³Á¤ÇÑ´Ù.
*/
jindo.$Ajax.Queue.prototype.option = function(name, value) {
if (typeof name == "undefined"){ return "";}
if (typeof name == "string") {
if (typeof value == "undefined"){ return this._options[name];}
this._options[name] = value;
return this;
}
try {
for(var x in name) {
if(name.hasOwnProperty(x))
this._options[x] = name[x]
}
} catch(e) {
};
return this;
};
/**
* Ajax ¿äû Å¥¿¡ ¿äûÀ» Ãß°¡ÇÑ´Ù.
* @param {$Ajax} Ãß°¡ÇÒ $Ajax °´Ã¼
* @param {Object} ¿äû ½Ã Àü¼ÛÇÒ ¸Å°³ º¯¼ö °´Ã¼
*
* @example
var oAjax1 = new $Ajax('ajax_test.php',{
onload : function(res){
// onload Çڵ鷯
}
});
var oAjax2 = new $Ajax('ajax_test.php',{
onload : function(res){
// onload Çڵ鷯
}
});
var oAjax3 = new $Ajax('ajax_test.php',{
onload : function(res){
// onload Çڵ鷯
}
});
var oAjaxQueue = new $Ajax.Queue({
async : true,
useResultAsParam : true,
stopOnFailure : false
});
// Ajax ¿äû Å¥¿¡ Ãß°¡ÇÑ´Ù.
oAjaxQueue.add(oAjax1,{seq:1});
oAjaxQueue.add(oAjax2,{seq:2,foo:99});
oAjaxQueue.add(oAjax3,{seq:3});
oAjaxQueue.request();
*/
jindo.$Ajax.Queue.prototype.add = function (oAjax, oParam) {
this._queue.push({obj:oAjax, param:oParam});
}
/**
* Ajax Queue¸¦ ¿äûÇÑ´Ù.
*
* @example
var oAjaxQueue = new $Ajax.Queue({
useResultAsParam : true
});
oAjaxQueue.add(oAjax1,{seq:1});
oAjaxQueue.add(oAjax2,{seq:2,foo:99});
oAjaxQueue.add(oAjax3,{seq:3});
// ¼¹ö¿¡ Ajax ¿äûÀ» º¸³½´Ù.
oAjaxQueue.request();
*/
jindo.$Ajax.Queue.prototype.request = function () {
if(this.option('async')){
this._requestAsync();
} else {
this._requestSync(0);
}
}
jindo.$Ajax.Queue.prototype._requestSync = function (nIdx, oParam) {
var t = this;
if (this._queue.length > nIdx+1) {
this._queue[nIdx].obj._oncompleted = function(bSuccess, oResult){
if(!t.option('stopOnFailure') || bSuccess) t._requestSync(nIdx + 1, oResult);
};
}
var _oParam = this._queue[nIdx].param||{};
if(this.option('useResultAsParam') && oParam){
try { for(var x in oParam) if(typeof _oParam[x] == 'undefined' && oParam.hasOwnProperty(x)) _oParam[x] = oParam[x] } catch(e) {};
}
this._queue[nIdx].obj.request(_oParam);
}
jindo.$Ajax.Queue.prototype._requestAsync = function () {
for( var i=0; i<this._queue.length; i++)
this._queue[i].obj.request(this._queue[i].param);
}
/**
* @fileOverview $HÀÇ »ý¼ºÀÚ ¹× ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name hash.js
*/
/**
* $H ÇØ½Ã °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù
* @class $H Ŭ·¡½º´Â Ű¿Í °ªÀ» ¿ø¼Ò·Î °¡Áö´Â ¿°ÅÇü ¹è¿ÀÎ ÇØ½Ã¸¦ ±¸ÇöÇϰí, ÇØ½Ã¸¦ ´Ù·ç±â À§ÇÑ ¿©·¯ °¡Áö À§ÇÑ ¸Þ¼µå¸¦ Á¦°øÇÑ´Ù.
* @param {Object} hashObject ÇØ½Ã·Î ¸¸µé °´Ã¼.
* @return {$H} ÇØ½Ã °´Ã¼
* @constructor
* @example
var h = $H({one:"first", two:"second", three:"third"})
* @author Kim, Taegon
*/
jindo.$H = function(hashObject) {
var cl = arguments.callee;
if (typeof hashObject == "undefined") hashObject = new Object;
if (hashObject instanceof cl) return hashObject;
if (!(this instanceof cl)) return new cl(hashObject);
this._table = {};
for(var k in hashObject) {
if(hashObject.hasOwnProperty(k)){
this._table[k] = hashObject[k];
}
}
};
/**
* $value ¸Þ¼µå´Â ÇØ½Ì ´ë»óÀÎ °´Ã¼¸¦ ¹ÝȯÇÑ´Ù.
* @return {Object} ÇØ½Ì ´ë»ó °´Ã¼
*/
jindo.$H.prototype.$value = function() {
return this._table;
};
/**
* $ ¸Þ¼µå´Â Ű¿Í °ªÀ» ¼³Á¤Çϰųª Ű¿¡ ÇØ´çÇÏ´Â °ªÀ» ¹ÝȯÇÑ´Ù.
* @param {String} key Ű
* @param {void} [value] °ª
* @return {void|$H} Ű¿¡ ÇØ´çÇÏ´Â °ª ȤÀº $H °´Ã¼
* @example
* var hash = $H({one:"first", two:"second"});
*
* // °ªÀ» ¼³Á¤ÇÒ ¶§
* hash.$("three", "third");
*
* // hash => {one:"first", two:"second", three:"third"}
*
* // °ªÀ» ¹ÝȯÇÒ ¶§
* var three = hash.$("three");
*
* // three => "third"
*/
jindo.$H.prototype.$ = function(key, value) {
if (typeof value == "undefined") {
return this._table[key];
}
this._table[key] = value;
return this;
};
/**
* length ¸Þ¼µå´Â ÇØ½Ã °´Ã¼ÀÇ Å©±â¸¦ ¹ÝȯÇÑ´Ù.
* @return {Number} ÇØ½ÃÀÇ Å©±â
*/
jindo.$H.prototype.length = function() {
var i = 0;
for(var k in this._table) {
if(this._table.hasOwnProperty(k)){
if (typeof Object.prototype[k] != "undeifned" && Object.prototype[k] === this._table[k]) continue;
i++;
}
}
return i;
};
/**
* forEach ¸Þ¼µå´Â ÇØ½Ã °´Ã¼ÀÇ Å°¿Í °ªÀ» Àμö·Î ÁöÁ¤ÇÑ Äݹé ÇÔ¼ö¸¦ ½ÇÇàÇÑ´Ù.
* @param {Function} callback ½ÇÇàÇÒ Äݹé ÇÔ¼ö
* @param {Object} thisObject Äݹé ÇÔ¼öÀÇ this
* @example
function printIt(value, key) {
document.write(key+" => "+value+" <br>");
}
$H({one:"first", two:"second", three:"third"}).forEach(printIt);
*/
jindo.$H.prototype.forEach = function(callback, thisObject) {
var t = this._table;
var h = this.constructor;
for(var k in t) {
if (t.hasOwnProperty(k)) {
if (!t.propertyIsEnumerable(k)) continue;
try {
callback.call(thisObject, t[k], k, t);
} catch(e) {
if (e instanceof h.Break) break;
if (e instanceof h.Continue) continue;
throw e;
}
}
}
return this;
};
/**
* filter ¸Þ¼µå´Â ÇØ½Ã °´Ã¼¿¡¼ ÇÊÅÍ Äݹé ÇÔ¼ö¸¦ ¸¸Á·ÇÏ´Â ¿ø¼Ò¸¦ ¼öÁýÇÑ´Ù. ¼öÁýÇÑ ¿ø¼Ò´Â »õ·Î¿î $H °´Ã¼ÀÇ ¿ø¼Ò°¡ µÈ´Ù.
* ÄݹéÇÔ¼ö´Â Boolean °ªÀ» ¹ÝÈ¯ÇØ¾ß ÇÑ´Ù.
* @param {Function} callback ÇÊÅÍ Äݹé ÇÔ¼ö
* @param {Object} thisObject Äݹé ÇÔ¼öÀÇ this
* @return {$H} ¼öÁýÇÑ ¿ø¼Ò·Î »õ·Î ¸¸µç ÇØ½Ã °´Ã¼
* @remark ÇÊÅÍ Äݹé ÇÔ¼öÀÇ °á°ú°¡ trueÀÎ ¿ø¼Ò¸¸ ¼öÁýÇÑ´Ù. Äݹé ÇÔ¼ö´Â Çü½ÄÀº ¿¹Á¦¸¦ Âü°íÇÑ´Ù.
* @example
function callback(value, key, object) {
// value ÇØ½ÃÀÇ °ª
// key ÇØ½ÃÀÇ °íÀ¯ÇÑ Å° ȤÀº À̸§
// object JavaScript Core Object °´Ã¼
}
*/
jindo.$H.prototype.filter = function(callback, thisObject) {
var h = jindo.$H();
this.forEach(function(v,k,o) {
if(callback.call(thisObject, v, k, o) === true) {
h.add(k,v);
}
});
return h;
};
/**
* map ¸Þ¼µå´Â ÇØ½Ã °´Ã¼ÀÇ ¿ø¼Ò¸¦ Àμö·Î Äݹé ÇÔ¼ö¸¦ ½ÇÇàÇϰí, ÇÔ¼öÀÇ ¸®ÅÏ °ªÀ» ÇØ´ç ¿ø¼ÒÀÇ °ªÀ¸·Î ÁöÁ¤ÇÑ´Ù.
* @param {Function} callback Äݹé ÇÔ¼ö
* @param {Object} thisObject Äݹé ÇÔ¼öÀÇ this
* @return {$H} °ªÀ» º¯°æÇÑ ÇØ½Ã °´Ã¼
* @remark Äݹé ÇÔ¼ö´Â Çü½ÄÀº ¿¹Á¦¸¦ Âü°íÇÑ´Ù.
* @example
function callback(value, key, object ) {
// value ÇØ½ÃÀÇ °ª
// key ÇØ½ÃÀÇ °íÀ¯ÇÑ Å° ȤÀº À̸§
// object JavaScript Core Object °´Ã¼
var r = key+"_"+value;
document.writeln (r + "<br />");
return r;
}
$H({one:"first", two:"second", three:"third"}).map(callback);
*/
jindo.$H.prototype.map = function(callback, thisObject) {
var t = this._table;
this.forEach(function(v,k,o) {
t[k] = callback.call(thisObject, v, k, o);
});
return this;
};
/**
* ÇØ½Ã Å×ÀÌºí¿¡ °ªÀ» Ãß°¡ÇÑ´Ù.
* @param {String} key Ãß°¡ÇÑ °ªÀ» À§ÇÑ Å°
* @param {String} value ÇØ½Ã Å×ÀÌºí¿¡ Ãß°¡ÇÒ °ª
* @return {$H} °ªÀ» Ãß°¡ÇÑ ÇØ½Ã °´Ã¼
*/
jindo.$H.prototype.add = function(key, value) {
//if (this.hasKey(key)) return null;
this._table[key] = value;
return this;
};
/**
* remove ¸Þ¼µå´Â ÇØ½Ã Å×À̺íÀÇ ¿ø¼Ò¸¦ Á¦°ÅÇÑ´Ù.
* @param {String} key Á¦°ÅÇÒ ¿ø¼ÒÀÇ Å°
* @return {void} Á¦°ÅÇÑ Å° °ª
* @example
var h = $H({one:"first", two:"second", three:"third"});
h.remove ("two");
// hÀÇ ÇØ½Ã Å×À̺íÀº {one:"first", three:"third"}
*/
jindo.$H.prototype.remove = function(key) {
if (typeof this._table[key] == "undefined") return null;
var val = this._table[key];
delete this._table[key];
return val;
};
/**
* search ¸Þ¼µå´Â ÇØ½Ã Å×ÀÌºí¿¡¼ Àμö·Î ÁöÁ¤ÇÑ °ªÀ» ã´Â´Ù.
* @param {String} value °Ë»öÇÒ °ª
* @returns {String | Boolean} °ªÀ» ã¾Ò´Ù¸é °ª¿¡ ´ëÇÑ Å°. °ªÀ» ãÁö ¸øÇß´Ù¸é false.
* @example
var h = $H({one:"first", two:"second", three:"third"});
h.search ("second");
// two
h.search ("fist");
// false
*/
jindo.$H.prototype.search = function(value) {
var result = false;
this.forEach(function(v,k,o) {
if (v === value) {
result = k;
jindo.$H.Break();
}
});
return result;
};
/**
* hasKey ¸Þ¼µå´Â ÇØ½Ã Å×ÀÌºí¿¡ Àμö·Î ÁöÁ¤ÇÑ Å°°¡ ÀÖ´ÂÁö ã´Â´Ù.
* @param {String} key ÇØ½Ã Å×ÀÌºí¿¡¼ °Ë»öÇÒ Å°
* @return {Boolean} ŰÀÇ Á¸Àç ¿©ºÎ
* @example
var h = $H({one:"first", two:"second", three:"third"});
h.hasKey("four"); // false
h.hasKey("one"); // true
*/
jindo.$H.prototype.hasKey = function(key) {
var result = false;
return (typeof this._table[key] != "undefined");
};
/**
* hasValue ¸Þ¼µå´Â ÇØ½Ã Å×ÀÌºí¿¡ Àμö·Î ÁöÁ¤ÇÑ °ªÀÌ ÀÖ´ÂÁö È®ÀÎÇÑ´Ù.
* @param {String} value ÇØ½Ã Å×ÀÌºí¿¡¼ °Ë»öÇÒ °ª
* @return {Boolean} °ªÀÇ Á¸Àç ¿©ºÎ
*/
jindo.$H.prototype.hasValue = function(value) {
return (this.search(value) !== false);
};
/**
* sort ¸Þ¼µå´Â °ªÀ» ±âÁØÀ¸·Î ¿ø¼Ò¸¦ ¿À¸§Â÷¼ø Á¤·ÄÇÑ´Ù.
* @return {$H} ¿ø¼Ò¸¦ Á¤·ÄÇÑ ÇØ½Ã °´Ã¼.
* @see $H#ksort
* @example
var h = $H({one:"Çϳª", two:"µÑ", three:"¼Â"});
h.sort ();
// {two:"µÑ", three:"¼Â", one:"Çϳª"}
*/
jindo.$H.prototype.sort = function() {
var o = new Object;
var a = this.values();
var k = false;
a.sort();
for(var i=0; i < a.length; i++) {
k = this.search(a[i]);
o[k] = a[i];
delete this._table[k];
}
this._table = o;
return this;
};
/**
* ksort ¸Þ¼µå´Â ۸¦ ±âÁØÀ¸·Î ¿ø¼Ò¸¦ ¿À¸§Â÷¼ø Á¤·ÄÇÑ´Ù.
* @return {$H} ¿ø¼Ò¸¦ Á¤·ÄÇÑ ÇØ½Ã °´Ã¼
* @see $H#sort
* @example
var h = $H({one:"Çϳª", two:"µÑ", three:"¼Â"});
h.sort ();
// h => {one:"Çϳª", three:"¼Â", two:"µÑ"}
*/
jindo.$H.prototype.ksort = function() {
var o = new Object;
var a = this.keys();
a.sort();
for(var i=0; i < a.length; i++) {
o[a[i]] = this._table[a[i]];
}
this._table = o;
return this;
};
/**
* keys ¸Þ¼µå´Â ÇØ½Ã ŰÀÇ ¹è¿À» ¹ÝȯÇÑ´Ù.
* @return {Array} ÇØ½Ã ŰÀÇ ¹è¿
* @example
var h = $H({one:"first", two:"second", three:"third"});
h.keys ();
// ["one", "two", "three"]
* @see $H#values
*/
jindo.$H.prototype.keys = function() {
var keys = new Array;
for(var k in this._table) {
if(this._table.hasOwnProperty(k))
keys.push(k);
}
return keys;
};
/**
* values ¸Þ¼µå´Â ÇØ½Ã °ªÀÇ ¹è¿À» ¹ÝȯÇÑ´Ù.
* @return {Array} ÇØ½Ã °ªÀÇ ¹è¿
* @example
var h = $H({one:"first", two:"second", three:"third"});
h.values();
// ["first", "second", "third"]
* @see $H#keys
*/
jindo.$H.prototype.values = function() {
var values = [];
for(var k in this._table) {
if(this._table.hasOwnProperty(k))
values[values.length] = this._table[k];
}
return values;
};
/**
* toQueryStringÀº ÇØ½Ã °´Ã¼¸¦ Äõ¸® ½ºÆ®¸µ ÇüÅ·Π¸¸µç´Ù.
* @return {String}
* @example
var h = $H({one:"first", two:"second", three:"third"});
h.toQueryString();
// "one=first&two=second&three=third"
*/
jindo.$H.prototype.toQueryString = function() {
var buf = [], val = null, idx = 0;
for(var k in this._table) {
if (this._table.hasOwnProperty(k)) {
if (typeof(val = this._table[k]) == "object" && val.constructor == Array) {
for(i=0; i < val.length; i++) {
buf[buf.length] = encodeURIComponent(k)+"[]="+encodeURIComponent(val[i]+"");
}
} else {
buf[buf.length] = encodeURIComponent(k)+"="+encodeURIComponent(this._table[k]+"");
}
}
}
return buf.join("&");
};
/**
* empty´Â ÇØ½Ã °´Ã¼¸¦ ºó °´Ã¼·Î ¸¸µç´Ù.
* @return {$H} ºñ¿öÁø ÇØ½Ã °´Ã¼
* @example
var hash = $H({a:1, b:2, c:3});
// hash => {a:1, b:2, c:3}
hash.empty();
// hash => {}
*/
jindo.$H.prototype.empty = function() {
var keys = this.keys();
for(var i=0; i < keys.length; i++) {
delete this._table[keys[i]];
}
return this;
};
/**
* Break ¸Þ¼µå´Â ¹Ýº¹¹®ÀÇ ½ÇÇàÀ» Áß´ÜÇÒ ¶§ »ç¿ëÇÑ´Ù.
* @remark forEach, filter, map¿Í °°Àº ·çÇÁ¸¦ Áß´ÜÇÑ´Ù. °Á¦·Î exceptionÀ» ¹ß»ý½ÃŰ¹Ç·Î try ~ catch ¿µ¿ª¿¡¼ ÀÌ ¸Þ¼Òµå¸¦ ½ÇÇàÇϸé Á¤»óÀûÀ¸·Î µ¿ÀÛÇÏÁö ¾ÊÀ» ¼ö ÀÖ´Ù.
* @example
$H({a:1, b:2, c:3}).forEach(function(v,k,o) {
...
if (k == "b") $H.Break();
...
});
* @see $H.Continue
*/
jindo.$H.Break = function() {
if (!(this instanceof arguments.callee)) throw new arguments.callee;
};
/**
* Continue ¸Þ¼µå´Â ·çÇÁ¸¦ ½ÇÇàÇÏ´Ù ´ÙÀ½ ´Ü°è·Î ³Ñ¾î°¥ ¶§ »ç¿ëÇÑ´Ù.
* @remark forEach, filter, map¿Í °°Àº ·çÇÁ ½ÇÇà µµÁß¿¡ ÇöÀç ·çÇÁ¸¦ Áß´ÜÇÏ°í ´ÙÀ½À¸·Î ³Ñ¾î°£´Ù. °Á¦·Î exceptionÀ» ¹ß»ý½ÃŰ¹Ç·Î try ~ catch ¿µ¿ª¿¡¼ ÀÌ ¸Þ¼Òµå¸¦ ½ÇÇàÇϸé Á¤»óÀûÀ¸·Î µ¿ÀÛÇÏÁö ¾ÊÀ» ¼ö ÀÖ´Ù.
* @example
$H({a:1, b:2, c:3}).forEach(function(v,k,o) {
...
if (v % 2 == 0) $H.Continue();
...
});
* @see $H.Break
*/
jindo.$H.Continue = function() {
if (!(this instanceof arguments.callee)) throw new arguments.callee;
};
/**
* @fileOverview $JsonÀÇ »ý¼ºÀÚ ¹× ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name json.js
*/
/**
* $Json °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @class $Json °´Ã¼´Â ÀÚ¹Ù½ºÅ©¸³Æ®¿¡¼ JSON(JavaScript Object Notation)À» ´Ù·ç±â À§ÇÑ ´Ù¾çÇÑ ¸Þ¼µå¸¦ Á¦°øÇÑ´Ù.
* @param {Object | String} sObject °´Ã¼, ȤÀº JSONÀ¸·Î ÀÎÄÚµù °¡´ÉÇÑ ¹®ÀÚ¿.
* @return {$Json} Àμö¸¦ ÀÎÄÚµùÇÑ $Json °´Ã¼.
* @remark XML ÇüÅÂÀÇ ¹®ÀÚ¿À» »ç¿ëÇÏ¿© $Json °´Ã¼¸¦ »ý¼ºÇÏ·Á¸é $Json#fromXML ¸Þ¼µå¸¦ »ç¿ëÇÑ´Ù.
* @example
var oStr = $Json ('{ zoo: "myFirstZoo", tiger: 3, zebra: 2}');
var d = {name : 'nhn', location: 'Bundang-gu'}
var oObj = $Json (d);
* @constructor
* @author Kim, Taegon
*/
jindo.$Json = function (sObject) {
var cl = arguments.callee;
if (typeof sObject == "undefined") sObject = {};
if (sObject instanceof cl) return sObject;
if (!(this instanceof cl)) return new cl(sObject);
if (typeof sObject == "string") {
this._object = jindo.$Json._oldMakeJSON(sObject);
}else{
this._object = sObject;
}
}
/*
native jsonÀÇ parseÀÇ ¼º´ÉÀÌ º¸´Ù ÁÁÁö ¸øÇØ native jsonÀº »ç¿ëÇÏÁö ¾ÊÀ½.
jindo.$Json._makeJson = function(sObject){
if (window.JSON&&window.JSON.parse) {
jindo.$Json._makeJson = function(sObject){
if (typeof sObject == "string") {
try{
return JSON.parse(sObject);
}catch(e){
return jindo.$Json._oldMakeJSON(sObject);
}
}
return sObject;
}
}else{
jindo.$Json._makeJson = function(sObject){
if (typeof sObject == "string") {
return jindo.$Json._oldMakeJSON(sObject);
}
return sObject;
}
}
return jindo.$Json._makeJson(sObject);
}
*/
jindo.$Json._oldMakeJSON = function(sObject){
try {
if(/^(?:\s*)[\{\[]/.test(sObject)){
sObject = eval("("+sObject+")");
}else{
sObject = sObject;
}
} catch(e) {
sObject = {};
}
return sObject;
}
/**
* fromXML ¸Þ¼µå´Â XML ÇüÅÂÀÇ ¹®ÀÚ¿À» $Json °´Ã¼·Î ÀÎÄÚµùÇÑ´Ù.
* @param {String} sXML $Json °´Ã¼·Î ÀÎÄÚµùÇÒ XML ÇüÅÂÀÇ ¹®ÀÚ¿
* @returns {$Json} $Json °´Ã¼
* @remark ¼Ó¼º°ú CDATA¸¦ °¡Áö´Â ű״ CDATA¸¦ '$cdata' ¼Ó¼º°ú °ªÀ¸·Î ÀÎÄÚµùÇÑ´Ù.
* @example
var j1 = $Json.fromXML('<data>only string</data>');
// °á°ú :
// {"data":"only string"}
var j2 = $Json.fromXML('<data><id>Faqh%$</id><str attr="123">string value</str></data>');
// °á°ú:
// {"data":{"id":"Faqh%$","str":{"attr":"123","$cdata":"string value"}}}
*/
jindo.$Json.fromXML = function(sXML) {
var o = {};
var re = /\s*<(\/?[\w:\-]+)((?:\s+[\w:\-]+\s*=\s*(?:"(?:\\"|[^"])*"|'(?:\\'|[^'])*'))*)\s*((?:\/>)|(?:><\/\1>|\s*))|\s*<!\[CDATA\[([\w\W]*?)\]\]>\s*|\s*>?([^<]*)/ig;
var re2= /^[0-9]+(?:\.[0-9]+)?$/;
var ec = {"&":"&"," ":" ",""":"\"","<":"<",">":">"};
var fg = {tags:["/"],stack:[o]};
var es = function(s){
if (typeof s == "undefined") return "";
return s.replace(/&[a-z]+;/g, function(m){ return (typeof ec[m] == "string")?ec[m]:m; })
};
var at = function(s,c){s.replace(/([\w\:\-]+)\s*=\s*(?:"((?:\\"|[^"])*)"|'((?:\\'|[^'])*)')/g, function($0,$1,$2,$3){c[$1] = es(($2?$2.replace(/\\"/g,'"'):undefined)||($3?$3.replace(/\\'/g,"'"):undefined));}) };
var em = function(o){
for(var x in o){
if (o.hasOwnProperty(x)) {
if(Object.prototype[x])
continue;
return false;
}
};
return true
};
/*
$0 : Àüü
$1 : ű׸í
$2 : ¼Ó¼º¹®ÀÚ¿
$3 : ´Ý´Âű×
$4 : CDATA¹Ùµð°ª
$5 : ±×³É ¹Ùµð°ª
*/
var cb = function($0,$1,$2,$3,$4,$5) {
var cur, cdata = "";
var idx = fg.stack.length - 1;
if (typeof $1 == "string" && $1) {
if ($1.substr(0,1) != "/") {
var has_attr = (typeof $2 == "string" && $2);
var closed = (typeof $3 == "string" && $3);
var newobj = (!has_attr && closed)?"":{};
cur = fg.stack[idx];
if (typeof cur[$1] == "undefined") {
cur[$1] = newobj;
cur = fg.stack[idx+1] = cur[$1];
} else if (cur[$1] instanceof Array) {
var len = cur[$1].length;
cur[$1][len] = newobj;
cur = fg.stack[idx+1] = cur[$1][len];
} else {
cur[$1] = [cur[$1], newobj];
cur = fg.stack[idx+1] = cur[$1][1];
}
if (has_attr) at($2,cur);
fg.tags[idx+1] = $1;
if (closed) {
fg.tags.length--;
fg.stack.length--;
}
} else {
fg.tags.length--;
fg.stack.length--;
}
} else if (typeof $4 == "string" && $4) {
cdata = $4;
} else if (typeof $5 == "string" && $5) {
cdata = es($5);
}
if (cdata.replace(/^\s+/g, "").length > 0) {
var par = fg.stack[idx-1];
var tag = fg.tags[idx];
if (re2.test(cdata)) {
cdata = parseFloat(cdata);
}else if (cdata == "true"){
cdata = true;
}else if(cdata == "false"){
cdata = false;
}
if(typeof par =='undefined') return;
if (par[tag] instanceof Array) {
var o = par[tag];
if (typeof o[o.length-1] == "object" && !em(o[o.length-1])) {
o[o.length-1].$cdata = cdata;
o[o.length-1].toString = function(){ return cdata; }
} else {
o[o.length-1] = cdata;
}
} else {
if (typeof par[tag] == "object" && !em(par[tag])) {
par[tag].$cdata = cdata;
par[tag].toString = function(){ return cdata; }
} else {
par[tag] = cdata;
}
}
}
};
sXML = sXML.replace(/<(\?|\!-)[^>]*>/g, "");
sXML.replace(re, cb);
return jindo.$Json(o);
};
/**
* get ¸Þ¼µå´Â path¿¡ ÇØ´çÇÏ´Â $Json °´Ã¼ÀÇ °ªÀ» ¸®ÅÏÇÑ´Ù.
* @param {String} sPath path ¹®ÀÚ¿
* @return {Array} ÁöÁ¤µÈ path¿¡ ÇØ´çÇÏ´Â value¸¦ ¿ø¼Ò·Î °¡Áö´Â ¹è¿
* @example
var j = $Json.fromXML('<data><id>Faqh%$</id><str attr="123">string value</str></data>');
var r = j.get ("/data/id");
// °á°ú :
// [Faqh%$]
*/
jindo.$Json.prototype.get = function(sPath) {
var o = this._object;
var p = sPath.split("/");
var re = /^([\w:\-]+)\[([0-9]+)\]$/;
var stack = [[o]], cur = stack[0];
var len = p.length, c_len, idx, buf, j, e;
for(var i=0; i < len; i++) {
if (p[i] == "." || p[i] == "") continue;
if (p[i] == "..") {
stack.length--;
} else {
buf = [];
idx = -1;
c_len = cur.length;
if (c_len == 0) return [];
if (re.test(p[i])) idx = +RegExp.$2;
for(j=0; j < c_len; j++) {
e = cur[j][p[i]];
if (typeof e == "undefined") continue;
if (e instanceof Array) {
if (idx > -1) {
if (idx < e.length) buf[buf.length] = e[idx];
} else {
buf = buf.concat(e);
}
} else if (idx == -1) {
buf[buf.length] = e;
}
}
stack[stack.length] = buf;
}
cur = stack[stack.length-1];
}
return cur;
};
/**
* toString ¸Þ¼µå´Â $Json °´Ã¼¸¦ JSON ¹®ÀÚ¿·Î ¸®ÅÏÇÑ´Ù.
* @return {String} JSON ¹®ÀÚ¿
* @example
var j = $Json({foo:1, bar: 31});
document.write (j.toString());
document.write (j);
// °á°ú :
// {"bar":31,"foo":1}{"bar":31,"foo":1}
*/
jindo.$Json.prototype.toString = function() {
if (window.JSON&&window.JSON.stringify) {
jindo.$Json.prototype.toString = function() {
try{
return window.JSON.stringify(this._object);
}catch(e){
return jindo.$Json._oldToString(this._object);
}
}
}else{
jindo.$Json.prototype.toString = function() {
return jindo.$Json._oldToString(this._object);
}
}
return this.toString();
};
jindo.$Json._oldToString = function(oObj){
var func = {
$ : function($) {
if (typeof $ == "object" && $ == null) return 'null';
if (typeof $ == "undefined") return '""';
if (typeof $ == "boolean") return $?"true":"false";
if (typeof $ == "string") return this.s($);
if (typeof $ == "number") return $;
if ($ instanceof Array) return this.a($);
if ($ instanceof Object) return this.o($);
},
s : function(s) {
var e = {'"':'\\"',"\\":"\\\\","\n":"\\n","\r":"\\r","\t":"\\t"};
var c = function(m){ return (typeof e[m] != "undefined")?e[m]:m };
return '"'+s.replace(/[\\"'\n\r\t]/g, c)+'"';
},
a : function(a) {
// a = a.sort();
var s = "[",c = "",n=a.length;
for(var i=0; i < n; i++) {
if (typeof a[i] == "function") continue;
s += c+this.$(a[i]);
if (!c) c = ",";
}
return s+"]";
},
o : function(o) {
o = jindo.$H(o).ksort().$value();
var s = "{",c = "";
for(var x in o) {
if (o.hasOwnProperty(x)) {
if (typeof o[x] == "function") continue;
s += c+this.s(x)+":"+this.$(o[x]);
if (!c) c = ",";
}
}
return s+"}";
}
}
return func.$(oObj);
}
/**
* toXML ¸Þ¼µå´Â $Json °´Ã¼¸¦ XML ÇüÅÂÀÇ ¹®ÀÚ¿·Î ¸®ÅÏÇÑ´Ù.
* @return {String} XML ÇüÅÂÀÇ ¹®ÀÚ¿
* @example
var json = $Json({foo:1, bar: 31});
json.toXML();
// °á°ú :
// <foo>1</foo><bar>31</bar>
*/
jindo.$Json.prototype.toXML = function() {
var f = function($,tag) {
var t = function(s,at) { return "<"+tag+(at||"")+">"+s+"</"+tag+">" };
switch (typeof $) {
case "undefined":
case "null":
return t("");
case "number":
return t($);
case "string":
if ($.indexOf("<") < 0){
return t($.replace(/&/g,"&"));
}else{
return t("<![CDATA["+$+"]]>");
}
case "boolean":
return t(String($));
case "object":
var ret = "";
if ($ instanceof Array) {
var len = $.length;
for(var i=0; i < len; i++) { ret += f($[i],tag); };
} else {
var at = "";
for(var x in $) {
if ($.hasOwnProperty(x)) {
if (x == "$cdata" || typeof $[x] == "function") continue;
ret += f($[x], x);
}
}
if (tag) ret = t(ret, at);
}
return ret;
}
};
return f(this._object, "");
};
/**
* toObject ¸Þ¼µå´Â $Json °´Ã¼ ¿ø·¡ÀÇ JSON µ¥ÀÌÅÍ °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @return {Object} ¿ø·¡ÀÇ µ¥ÀÌÅÍ °´Ã¼
* @example
var json = $Json({foo:1, bar: 31});
json.toObject();
// °á°ú :
// {foo: 1, bar: 31}
*/
jindo.$Json.prototype.toObject = function() {
return this._object;
};
/**
* compare ¸Þ¼µå´Â json°´Ã¼ ³¢¸® °ªÀÌ °°ÀºÁö ºñ±³¸¦ ÇÑ´Ù. (1.4.4ºÎÅÍ »ç¿ë°¡´É.)
* @return {Boolean} ºÒ¸°°ª.
* @example
$Json({foo:1, bar: 31}).compare({foo:1, bar: 31});
// °á°ú :
// true
$Json({foo:1, bar: 31}).compare({foo:1, bar: 1});
// °á°ú :
// false
*/
jindo.$Json.prototype.compare = function(oData){
return jindo.$Json._oldToString(this._object).toString() == jindo.$Json._oldToString(jindo.$Json(oData).$value()).toString();
}
/**
* $value ¸Þ¼µå´Â $Json.toObjectÀÇ º°Äª(Alias)ÀÌ´Ù.
* @return {Object} ¿ø·¡ÀÇ µ¥ÀÌÅÍ °´Ã¼
*/
jindo.$Json.prototype.$value = jindo.$Json.prototype.toObject;
/**
* @fileOverview $CookieÀÇ »ý¼ºÀÚ ¹× ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name cookie.js
*/
/**
* $Cookie °´Ã¼¸¦ »ý¼ºÇÑ´Ù.
* @class $Cookie Ŭ·¡½º´Â ÄíŰ(Cookie)¸¦ Ãß°¡, ¼öÁ¤, ȤÀº »èÁ¦Çϰųª ÄíŰÀÇ °ªÀ» °¡Á®¿Â´Ù.
* @constructor
* @return {$Cookie} »ý¼ºµÈ $Cookie °´Ã¼
* @author Kim, Taegon
* @example
var cookie = $Cookie();
*/
jindo.$Cookie = function() {
var cl = arguments.callee;
var cached = cl._cached;
if (cl._cached) return cl._cached;
if (!(this instanceof cl)) return new cl;
if (typeof cl._cached == "undefined") cl._cached = this;
};
/**
* keys ¸Þ¼µå´Â ÄíŰ À̸§À» ¿ø¼Ò·Î °¡Áö´Â ¹è¿À» ¸®ÅÏÇÑ´Ù.
* @return {Array} ÄíŰ À̸§À» ¿ø¼Ò·Î °¡Áö´Â ¹è¿
* @example
var cookie = $Cookie();
cookie.set("session_id1", "value1", 1);
cookie.set("session_id2", "value2", 1);
cookie.set("session_id3", "value3", 1);
document.write (cookie.keys ());
*
* // °á°ú :
* // session_id1, session_id2, session_id3
*/
jindo.$Cookie.prototype.keys = function() {
var ca = document.cookie.split(";");
var re = /^\s+|\s+$/g;
var a = new Array;
for(var i=0; i < ca.length; i++) {
a[a.length] = ca[i].substr(0,ca[i].indexOf("=")).replace(re, "");
}
return a;
};
/**
* get ¸Þ¼µå´Â ÄíŰ À̸§¿¡ ÇØ´çÇÏ´Â ÄíŰ °ªÀ» °¡Á®¿Â´Ù. °ªÀÌ Á¸ÀçÇÏÁö ¾Ê´Â´Ù¸é nullÀ» ¸®ÅÏÇÑ´Ù.
* @param {String} sName ÄíŰ À̸§
* @return {String} ÄíŰ °ª
* @example
var cookie = $Cookie();
cookie.set("session_id1", "value1", 1);
document.write (cookie.get ("session_id1"));
*
* // °á°ú :
* // value1
*
document.write (cookie.get ("session_id0"));
*
* // °á°ú :
* // null
*/
jindo.$Cookie.prototype.get = function(sName) {
var ca = document.cookie.split(/\s*;\s*/);
var re = new RegExp("^(\\s*"+sName+"\\s*=)");
for(var i=0; i < ca.length; i++) {
if (re.test(ca[i])) return unescape(ca[i].substr(RegExp.$1.length));
}
return null;
};
/**
* set ¸Þ¼µå´Â ÄíŰ °ªÀ» ¼³Á¤ÇÑ´Ù.
* @param {String} sName ÄíŰ À̸§
* @param {String} sValue ÄíŰ °ª
* @param {Number} [nDays] ÄíŰ À¯È¿ ½Ã°£. À¯È¿ ½Ã°£Àº ÀÏ´ÜÀ§·Î ¼³Á¤ÇÑ´Ù. À¯È¿½Ã°£À» »ý·«Çß´Ù¸é ÄíŰ´Â À¥ ºê¶ó¿ìÀú°¡ Á¾·áµÇ¸é ¾ø¾îÁø´Ù.
* @param {String} [sDomain] ÄíŰ µµ¸ÞÀÎ
* @param {String} [sPath] ÄíŰ °æ·Î
* @return {$Cookie} $Cookie °´Ã¼
* @example
var cookie = $Cookie();
cookie.set("session_id1", "value1", 1);
cookie.set("session_id2", "value2", 1);
cookie.set("session_id3", "value3", 1);
*/
jindo.$Cookie.prototype.set = function(sName, sValue, nDays, sDomain, sPath) {
var sExpire = "";
if (typeof nDays == "number") {
sExpire = ";expires="+(new Date((new Date()).getTime()+nDays*1000*60*60*24)).toGMTString();
}
if (typeof sDomain == "undefined") sDomain = "";
if (typeof sPath == "undefined") sPath = "/";
document.cookie = sName+"="+escape(sValue)+sExpire+"; path="+sPath+(sDomain?"; domain="+sDomain:"");
return this;
};
/**
* remove ¸Þ¼µå´Â ÄíŰ À̸§¿¡ ¼³Á¤µÈ ÄíŰ °ªÀ» Á¦°ÅÇÑ´Ù.
* @param {String} sName ÄíŰ À̸§
* @param {String} sDomain ÄíŰ µµ¸ÞÀÎ
* @param {String} sPath ÄíŰ °æ·Î
* @return {$Cookie} $Cookie °´Ã¼
* @example
var cookie = $Cookie();
cookie.set("session_id1", "value1", 1);
document.write (cookie.get ("session_id1"));
*
* // °á°ú :
* // value1
*
cookie.remove("session_id1");
document.write (cookie.get ("session_id1"));
*
* // °á°ú :
* // null
*/
jindo.$Cookie.prototype.remove = function(sName, sDomain, sPath) {
if (this.get(sName) != null) this.set(sName, "", -1, sDomain, sPath);
return this;
};
/**
* @fileOverview $ElementÀÇ »ý¼ºÀÚ ¹× ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name element.js
*/
/**
* $Element °´Ã¼¸¦ »ý¼ºÇÏ¿© ¹ÝȯÇÑ´Ù.
* @class $Element Ŭ·¡½º´Â HTML ¿¤¸®¸ÕÆ®¸¦ ·¡ÇÎ(wrapping)Çϸç, ¿¤¸®¸ÕÆ®¸¦ ´Ù·ç±â À§ÇÑ ¸Þ¼µå¸¦ Á¦°øÇÑ´Ù.<br>
* ·¡ÇÎÀ̶õ ÀÚ¹Ù½ºÅ©¸³Æ®ÀÇ ÇÔ¼ö¸¦ Çѹø ´õ °¨½Î º»·¡ ÇÔ¼öÀÇ ±â´ÉÀº ±×´ë·Î À¯ÁöÇÏ¸é¼ È®ÀåµÈ ±â´ÉÀ» ¼Ó¼º ÇüÅ·ΠÁ¦°øÇÏ´Â °ÍÀ» ¸»ÇÑ´Ù.
* @constructor
* @description [Lite]
* @author Kim, Taegon
*
* @param {String | HTML Element | $Element} el
* <br>
* $Element ´Â ¹®ÀÚ¿, HTML ¿¤¸®¸ÕÆ®, ȤÀº $Element ¸¦ ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.<br>
* <br>
* ¸Å°³ º¯¼ö°¡ ¹®ÀÚ¿ÀÌ¸é µÎ °¡Áö ¹æ½ÄÀ¸·Î µ¿ÀÛÇÑ´Ù.<br>
* ¸¸ÀÏ "<tagName>" °ú °°Àº Çü½ÄÀÇ ¹®ÀÚ¿À̸é tagNameÀ» °¡Áö´Â °´Ã¼¸¦ »ý¼ºÇÑ´Ù.<br>
* ±× ÀÌ¿ÜÀÇ °æ¿ì ¹®ÀÚ¿À» id ·Î ÇÏ´Â HTML ¿¤¸®¸ÕÆ®¸¦ »ç¿ëÇÏ¿© $Element ¸¦ »ý¼ºÇÑ´Ù.<br>
* <br>
* ¸Å°³ º¯¼ö°¡ HTML ¿¤¸®¸ÕÆ®À̸é HTML ¿¤¸®¸ÕÆ®¸¦ ·¡ÇÎÇÏ¿© $Element ¸¦ »ý¼ºÇÑ´Ù.<br>
* <br>
* ¸Å°³ º¯¼ö°¡ $Element À̸é Àü´ÞµÈ ¸Å°³ º¯¼ö¸¦ ±×´ë·Î ¹ÝȯÇϸç undefined ȤÀº null ÀÎ °æ¿ì¿¡´Â null À» ¹ÝȯÇÑ´Ù.
* @return {$Element} »ý¼ºµÈ $Element °´Ã¼
*
* @example
var element = $Element($("box")); // HTML ¿¤¸®¸ÕÆ®¸¦ ¸Å°³ º¯¼ö·Î ÁöÁ¤
var element = $Element("box"); // HTML ¿¤¸®¸ÕÆ®ÀÇ id¸¦ ¸Å°³ º¯¼ö·Î ÁöÁ¤
var element = $Element("<DIV>"); // ű׸¦ ¸Å°³ º¯¼ö·Î ÁöÁ¤, DIV ¿¤¸®¸ÕÆ®¸¦ »ý¼ºÇÏ¿© ·¡ÇÎÇÔ
*/
jindo.$Element = function(el) {
var cl = arguments.callee;
if (el && el instanceof cl) return el;
if (el===null || typeof el == "undefined"){
return null;
}else{
el = jindo.$(el);
if (el === null) {
return null;
};
}
if (!(this instanceof cl)) return new cl(el);
this._element = (typeof el == "string") ? jindo.$(el) : el;
var tag = this._element.tagName;
// tagname
this.tag = (typeof tag!='undefined')?tag.toLowerCase():'';
}
/**
* agentÀÇ dependency¸¦ ¾ø¾Ö±â À§ÇØ º°·Îµµ ¼³Á¤.
* @ignore
**/
var _j_ag = navigator.userAgent;
var IS_IE = _j_ag.indexOf("MSIE") > -1;
var IS_FF = _j_ag.indexOf("Firefox") > -1;
var IS_OP = _j_ag.indexOf("Opera") > -1;
var IS_SF = _j_ag.indexOf("Apple") > -1;
var IS_CH = _j_ag.indexOf("Chrome") > -1;
/**
* $value ¸Þ¼µå´Â ¿ø·¡ÀÇ HTML ¿¤¸®¸ÕÆ®¸¦ ¹ÝȯÇÑ´Ù.
* @return {HTML Element} ·¡ÇÎµÈ ¿ø·¡ÀÇ ¿¤¸®¸ÕÆ®
* @description [Lite]
*
* @example
var element = $Element("sample_div");
element.$value(); // ¿ø·¡ÀÇ ¿¤¸®¸ÕÆ®°¡ ¹ÝȯµÈ´Ù
*/
jindo.$Element.prototype.$value = function() {
return this._element;
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ display ¼Ó¼ºÀ» È®ÀÎÇϰųª display ¼Ó¼ºÀ» ¼³Á¤Çϱâ À§ÇØ »ç¿ëÇÑ´Ù.
*
* @param {Boolean} [bVisible] ȸ鿡 º¸¿©ÁÙÁöÀÇ ¿©ºÎ<br>
* ¸Å°³ º¯¼ö¸¦ »ý·«Çϸé HTML ¿¤¸®¸ÕÆ®ÀÇ ÇöÀç display ¼Ó¼ºÀ» È®ÀÎÇÏ¿© true/false·Î ¹ÝȯÇÑ´Ù.(none À̸é false)<br>
* ¸Å°³ º¯¼ö°¡ trueÀÎ °æ¿ì¿¡´Â display ¼Ó¼ºÀ» ¼³Á¤Çϰí falseÀÎ °æ¿ì¿¡´Â display ¼Ó¼ºÀ» none À¸·Î º¯°æÇÑ´Ù.
* @param {String} [sDisplay] display ¼Ó¼º °ª<br>
* bVisible ¸Å°³ º¯¼ö°¡ true À̸é display ¼Ó¼ºÀ» Àü´ÞµÈ ¸Å°³ º¯¼ö·Î ¼³Á¤ÇÑ´Ù.
* @return {$Element} display ¼Ó¼ºÀ» º¯°æÇÑ $Element °´Ã¼
*
* @description [Lite]
* @since 1.1.2ºÎÅÍ ¼³Á¤ ±â´ÉÀ» »ç¿ëÇÒ ¼ö ÀÖ´Ù.
* @since 1.4.5ºÎÅÍ bVisible ¸Å°³ º¯¼öÀÇ °ªÀÌ true ÀÎ °æ¿ì sDisplay ¸Å°³ º¯¼öÀÇ °ªÀ¸·Î display ¼Ó¼ºÀ» ¼³Á¤ÇÒ ¼ö ÀÖ´Ù.
* @see $Element#show
* @see $Element#hide
* @see $Element#toggle
*
* @example
<div id="sample_div" style="display:none">Hello world</div>
// Á¶È¸
$Element("sample_div").visible(); // false
* @example
// ȸ鿡 º¸À̵µ·Ï ¼³Á¤
$Element("sample_div").visible(true, 'block');
//Before
<div id="sample_div" style="display:none">Hello world</div>
//After
<div id="sample_div" style="display:block">Hello world</div>
*/
jindo.$Element.prototype.visible = function(bVisible, sDisplay) {
if (typeof bVisible != "undefined") {
this[bVisible?"show":"hide"](sDisplay);
return this;
}
return (this.css("display") != "none");
};
/**
* HTML ¿¤¸®¸ÕÆ®°¡ ȸ鿡 º¸À̵µ·Ï display ¼Ó¼ºÀ» º¯°æÇÑ´Ù.
* @param {String} [sDisplay] º¯°æÇÒ display ¼Ó¼º °ª<br>
* ¸Å°³ º¯¼ö¸¦ »ý·«Çϸé ű׺°·Î ¹Ì¸® ÁöÁ¤µÈ µðÆúÆ® ¼Ó¼º °ªÀ¸·Î ¼³Á¤ÇÑ´Ù.<br>
* ¹Ì¸® ÁöÁ¤µÈ µðÆúÆ® ¼Ó¼º °ªÀÌ ¾øÀ¸¸é "inline" À¸·Î ¼³Á¤ÇÑ´Ù.
* @return {$Element} display ¼Ó¼ºÀ» º¯°æÇÑ $Element °´Ã¼
* @description [Lite]
* @see $Element#hide
* @see $Element#toggle
* @see $Element#visible
* @since 1.4.5ºÎÅÍ sDisplay °ªÀ¸·Î display ¼Ó¼º °ª ÁöÁ¤ÀÌ °¡´ÉÇÏ´Ù.
*
* @example
// ȸ鿡 º¸À̵µ·Ï ¼³Á¤
$Element("sample_div").show();
//Before
<div id="sample_div" style="display:none">Hello world</div>
//After
<div id="sample_div" style="display:block">Hello world</div>
*/
jindo.$Element.prototype.show = function(sDisplay) {
var s = this._element.style;
var b = "block";
var c = { p:b,div:b,form:b,h1:b,h2:b,h3:b,h4:b,ol:b,ul:b,fieldset:b,td:"table-cell",th:"table-cell",
li:"list-item",table:"table",thead:"table-header-group",tbody:"table-row-group",tfoot:"table-footer-group",
tr:"table-row",col:"table-column",colgroup:"table-column-group",caption:"table-caption",dl:b,dt:b,dd:b};
try {
if (sDisplay) {
s.display = sDisplay;
}else{
var type = c[this.tag];
s.display = type || "inline";
}
} catch(e) {
/*
IE¿¡¼ sDisplay°ªÀÌ ºñÁ¤»óÀûÀ϶§ block·Î ¼ÂÆÃÇÑ´Ù.
*/
s.display = "block";
}
return this;
};
/**
* HTML ¿¤¸®¸ÕÆ®°¡ ȸ鿡 º¸ÀÌÁö ¾Êµµ·Ï display ¼Ó¼ºÀ» none À¸·Î º¯°æÇÑ´Ù.
* @returns {$Element} display ¼Ó¼ºÀ» º¯°æÇÑ $Element °´Ã¼
* @description [Lite]
* @see $Element#show
* @see $Element#toggle
* @see $Element#visible
*
* @example
// ȸ鿡 º¸ÀÌÁö ¾Êµµ·Ï ¼³Á¤
$Element("sample_div").hide();
//Before
<div id="sample_div" style="display:block">Hello world</div>
//After
<div id="sample_div" style="display:none">Hello world</div>
*/
jindo.$Element.prototype.hide = function() {
this._element.style.display = "none";
return this;
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ display ¼Ó¼ºÀ» º¯°æÇÏ¿© ¿¤¸®¸ÕÆ®¸¦ ȸ鿡 º¸À̰ųª, º¸ÀÌÁö ¾Ê°Ô ÇÑ´Ù.
* @param {String} [sDisplay] º¸À̵µ·Ï º¯°æÇÒ ¶§ »ç¿ëµÇ´Â display ¼Ó¼º °ª
* @returns {$Element} display ¼Ó¼ºÀ» º¯°æÇÑ $Element °´Ã¼
* @description [Lite]
* @see $Element#show
* @see $Element#hide
* @see $Element#visible
* @since 1.4.5ºÎÅÍ º¸À̵µ·Ï ¼³Á¤ÇÒ ¶§ sDisplay °ªÀ¸·Î display ¼Ó¼º °ª ÁöÁ¤ÀÌ °¡´ÉÇÏ´Ù.
* @example
// ȸ鿡 º¸À̰ųª, º¸ÀÌÁö ¾Êµµ·Ï ó¸®
$Element("sample_div1").toggle();
$Element("sample_div2").toggle();
//Before
<div id="sample_div1" style="display:block">Hello</div>
<div id="sample_div2" style="display:none">Good Bye</div>
//After
<div id="sample_div1" style="display:none">Hello</div>
<div id="sample_div2" style="display:block">Good Bye</div>
*/
jindo.$Element.prototype.toggle = function(sDisplay) {
this[this.visible()?"hide":"show"](sDisplay);
return this;
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ Åõ¸íµµ °ªÀ» °¡Á®¿À°Å³ª ¼³Á¤ÇÑ´Ù.
* @param {Number} [value] ¼³Á¤ÇÒ Åõ¸íµµ °ª<br>
* Åõ¸íµµ °ªÀº 0 ~ 1 »çÀÌÀÇ ½Ç¼ö °ªÀ¸·Î ÁöÁ¤ÇÑ´Ù.<br>
* ¸Å°³ º¯¼öÀÇ °ªÀÌ 0º¸´Ù ÀÛÀ¸¸é 0À», 1º¸´Ù Å©¸é 1À» ¼³Á¤ÇÑ´Ù.
* @return {Number} HTML ¿¤¸®¸ÕÆ®ÀÇ Åõ¸íµµ °ª
* @description [Lite]
*
* @example
<div id="sample" style="background-color:#2B81AF; width:20px; height:20px;"></div>
// Á¶È¸
$Element("sample").opacity(); // 1
* @example
// Åõ¸íµµ °ª ¼³Á¤
$Element("sample").opacity(0.4);
//Before
<div style="background-color: rgb(43, 129, 175); width: 20px; height: 20px;" id="sample"></div>
//After
<div style="background-color: rgb(43, 129, 175); width: 20px; height: 20px; opacity: 0.4;" id="sample"></div>
*/
jindo.$Element.prototype.opacity = function(value) {
var v,e = this._element,b = (this._getCss(e,"display") != "none");
value = parseFloat(value);
/*
IE¿¡¼ layoutÀ» °¡Áö°í ÀÖÁö ¾ÊÀ¸¸é opacity°¡ Àû¿ëµÇÁö ¾ÊÀ½.
*/
e.style.zoom = 1;
if (!isNaN(value)) {
value = Math.max(Math.min(value,1),0);
if (typeof e.filters != "undefined") {
value = Math.ceil(value*100);
if (typeof e.filters != 'unknown' && typeof e.filters.alpha != "undefined") {
e.filters.alpha.opacity = value;
} else {
e.style.filter = (e.style.filter + " alpha(opacity=" + value + ")");
}
} else {
e.style.opacity = value;
}
return value;
}
if (typeof e.filters != "undefined") {
v = (typeof e.filters.alpha == "undefined")?(b?100:0):e.filters.alpha.opacity;
v = v / 100;
} else {
v = parseFloat(e.style.opacity);
if (isNaN(v)) v = b?1:0;
}
return v;
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ CSS ¼Ó¼º °ªÀ» °¡Á®¿À°Å³ª ¼³Á¤ÇÑ´Ù.
* @remark CSS ¼Ó¼ºÀº Camel Ç¥±â¹ýÀ» »ç¿ëÇÑ´Ù. µû¶ó¼ border-width-bottomÀº borderWidthBottomÀ¸·Î Á¤ÀÇÇÑ´Ù.
* @remark float ¼Ó¼ºÀº JavascriptÀÇ ¿¹¾à¾î·Î »ç¿ëÇϹǷΠcss ¸Þ¼µå¿¡¼´Â float ´ë½Å cssFloat¸¦ »ç¿ëÇÑ´Ù. (Internet Explorer¿¡¼´Â styleFloat¸¦, ±× ¿ÜÀÇ ºê¶ó¿ìÀú¿¡¼´Â cssFloat¸¦ »ç¿ëÇÑ´Ù.)
* @param {String | Object | $H} sName CSS ¼Ó¼º¸í ȤÀº Çϳª ÀÌ»óÀÇ CSS ¼Ó¼º°ú °ªÀ» °¡Áö´Â °´Ã¼.<br>
* css ¸Þ¼µå´Â ¹®ÀÚ¿, Object, ȤÀº $H ¸¦ ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.<br>
* <br>
* ¸Å°³ º¯¼ö°¡ ¹®ÀÚ¿À̸é Á¶È¸ ȤÀº ¼öÁ¤ÇÒ ¼Ó¼º ¸íÀ¸·Î ¾Æ·¡ µÎ °¡Áö ¹æ½ÄÀ¸·Î µ¿ÀÛÇÑ´Ù.<br>
* µÎ ¹øÂ° ¸Å°³ º¯¼öÀÎ sValue ¸Å°³ º¯¼ö¸¦ »ý·«Çϸé CSS ¼Ó¼ºÀÇ °ªÀ» °¡Á®¿Â´Ù.<br>
* µÎ ¹øÂ° ¸Å°³ º¯¼öÀÎ sValue ¸Å°³ º¯¼ö¿¡ °ªÀÌ ÀÖÀ¸¸é CSS ¼Ó¼ºÀÇ °ªÀ» sValue °ªÀ¸·Î ¼³Á¤ÇÑ´Ù.<br>
* <br>
* Object ȤÀº $H °´Ã¼¸¦ »ç¿ëÇÏ¸é µÎ °³ ÀÌ»óÀÇ CSS ¼Ó¼ºÀ» ÇѲ¨¹ø¿¡ ¼³Á¤ÇÒ ¼ö ÀÖ´Ù.<br>
* °´Ã¼ÀÇ ÇÁ·ÎÆÛƼ À̸§À¸·Î CSS ¼Ó¼ºÀ» ã¾Æ ÇÁ·ÎÆÛƼ °ªÀ¸·Î ¼³Á¤ÇÑ´Ù.
* @param {String | Number} [sValue] CSS ¼Ó¼º¿¡ ¼³Á¤ÇÒ °ª.<br>
* ´ÜÀ§°¡ ÇÊ¿äÇÑ °ªÀº ¼ýÀÚ È¤Àº ´ÜÀ§¸¦ Æ÷ÇÔÇÑ ¹®ÀÚ¿À» »ç¿ëÇÑ´Ù.
* @return {String | $Element} °ªÀ» °¡Á®¿Ã ¶§´Â °ªÀ» ¹®ÀÚ¿·Î ¹ÝȯÇϰí, °ªÀ» ¼³Á¤ÇÒ ¶§´Â °ªÀ» ¼³Á¤ÇÑ ÇöÀçÀÇ $Element ¸¦ ¹ÝȯÇÑ´Ù.
* @description [Lite]
* @example
<style type="text/css">
#btn {
width: 120px;
height: 30px;
background-color: blue;
}
</style>
<span id="btn"></span>
...
// CSS ¼Ó¼º °ª Á¶È¸
$Element('btn').css('backgroundColor'); // rgb (0, 0, 255)
* @example
// CSS ¼Ó¼º °ª ¼³Á¤
$Element('btn').css('backgroundColor', 'red');
//Before
<span id="btn"></span>
//After
<span id="btn" style="background-color: red;"></span>
* @example
// ¿©·¯°³ÀÇ CSS ¼Ó¼º °ªÀ» ¼³Á¤
$Element('btn').css({
width: "200px", // 200
height: "80px" // 80 À¸·Î ¼³Á¤ÇÏ¿©µµ °á°ú´Â °°À½
});
//Before
<span id="btn" style="background-color: red;"></span>
//After
<span id="btn" style="background-color: red; width: 200px; height: 80px;"></span>
*/
jindo.$Element.prototype.css = function(sName, sValue) {
var e = this._element;
var type_v = (typeof sValue);
if (sName == 'opacity') return type_v == 'undefined' ? this.opacity() : this.opacity(sValue);
var type_n = (typeof sName);
if (type_n == "string") {
var view;
if (type_v == "string" || type_v == "number") {
var obj = {};
obj[sName] = sValue;
sName = obj;
} else {
var _getCss = this._getCss;
if((IS_FF||IS_OP)&&(sName=="backgroundPositionX"||sName=="backgroundPositionY")){
var bp = _getCss(e, "backgroundPosition").split(/\s+/);
return (sName == "backgroundPositionX") ? bp[0] : bp[1];
}
if (IS_IE && sName == "backgroundPosition") {
return _getCss(e, "backgroundPositionX") + " " + _getCss(e, "backgroundPositionY")
}
if ((IS_FF||IS_SF||IS_CH) && (sName=="padding"||sName=="margin")) {
var top = _getCss(e, sName+"Top");
var right = _getCss(e, sName+"Right");
var bottom = _getCss(e, sName+"Bottom");
var left = _getCss(e, sName+"Left");
if ((top == right) && (bottom == left)) {
return top;
}else if (top == bottom) {
if (right == left) {
return top+" "+right;
}else{
return top+" "+right+" "+bottom+" "+left;
}
}else{
return top+" "+right+" "+bottom+" "+left;
}
}
return _getCss(e, sName);
}
}
var h = jindo.$H;
if (typeof h != "undefined" && sName instanceof h) {
sName = sName._table;
}
if (typeof sName == "object") {
var v, type;
for(var k in sName) {
if(sName.hasOwnProperty(k)){
v = sName[k];
type = (typeof v);
if (type != "string" && type != "number") continue;
if (k == 'opacity') {
type == 'undefined' ? this.opacity() : this.opacity(v);
continue;
}
if (k == "cssFloat" && IS_IE) k = "styleFloat";
if((IS_FF||IS_OP)&&( k =="backgroundPositionX" || k == "backgroundPositionY")){
var bp = this.css("backgroundPosition").split(/\s+/);
v = k == "backgroundPositionX" ? v+" "+bp[1] : bp[0]+" "+v;
this._setCss(e, "backgroundPosition", v);
}else{
this._setCss(e, k, v);
}
}
}
}
return this;
};
/**
* css¿¡¼ »ç¿ëµÇ´Â ÇÔ¼ö
* @ignore
* @param {Element} e
* @param {String} sName
*/
jindo.$Element.prototype._getCss = function(e, sName){
var fpGetCss;
if (e.currentStyle) {
fpGetCss = function(e, sName){
try{
if (sName == "cssFloat") sName = "styleFloat";
var sStyle = e.style[sName];
if(sStyle){
return sStyle;
}else{
var oCurrentStyle = e.currentStyle;
if (oCurrentStyle) {
return oCurrentStyle[sName];
}
}
return sStyle;
}catch(ex){
throw new Error((e.tagName||"document") + "´Â css¸¦ »ç¿ë ÇÒ¼ö ¾ø½À´Ï´Ù.");
}
}
} else if (window.getComputedStyle) {
fpGetCss = function(e, sName){
try{
if (sName == "cssFloat") sName = "float";
var d = e.ownerDocument || e.document || document;
var sVal = (e.style[sName]||d.defaultView.getComputedStyle(e,null).getPropertyValue(sName.replace(/([A-Z])/g,"-$1").toLowerCase()));
if (sName == "textDecoration") sVal = sVal.replace(",","");
return sVal;
}catch(ex){
throw new Error((e.tagName||"document") + "´Â css¸¦ »ç¿ë ÇÒ¼ö ¾ø½À´Ï´Ù.");
}
}
} else {
fpGetCss = function(e, sName){
try{
if (sName == "cssFloat" && IS_IE) sName = "styleFloat";
return e.style[sName];
}catch(ex){
throw new Error((e.tagName||"document") + "´Â css¸¦ »ç¿ë ÇÒ¼ö ¾ø½À´Ï´Ù.");
}
}
}
jindo.$Element.prototype._getCss = fpGetCss;
return fpGetCss(e, sName);
}
/**
* css¿¡¼ css¸¦ ¼¼ÆÃÇϱâ À§ÇÑ ÇÔ¼ö
* @ignore
* @param {Element} e
* @param {String} k
*/
jindo.$Element.prototype._setCss = function(e, k, v){
if (("#top#left#right#bottom#").indexOf(k+"#") > 0 && (typeof v == "number" ||(/\d$/.test(v)))) {
e.style[k] = parseInt(v,10)+"px";
}else{
e.style[k] = v;
}
}
/**
* DOM ¿¤¸®¸ÕÆ®ÀÇ HTML ¼Ó¼ºÀ» °¡Á®¿À°Å³ª ¼³Á¤ÇÑ´Ù.
* ÇϳªÀÇ ÀÎÀÚ¸¸ »ç¿ëÇϸé ÇØ´ç HTML ¼Ó¼ºÀÇ ¼Ó¼º °ªÀ» °¡Á®¿Â´Ù. ÇØ´ç ¼Ó¼ºÀÌ ¾ø´Ù¸é nullÀ» ¹ÝȯÇÑ´Ù.
* µÎ °³ÀÇ ÀÎÀÚ¸¦ »ç¿ëÇϸé ù ¹øÂ° ÀÎÀÚ¿¡ ÇØ´çÇÏ´Â HTML ¼Ó¼ºÀÇ ¼Ó¼º °ªÀ» µÎ ¹øÂ° ÀÎÀÚÀÇ °ªÀ¸·Î ¼³Á¤ÇÑ´Ù.
* ù ¹øÂ° ÀÎÀÚ·Î Object ȤÀº $H °´Ã¼¸¦ »ç¿ëÇÏ¸é µÎ °³ ÀÌ»óÀÇ HTML ¼Ó¼ºÀ» ÇѲ¨¹ø¿¡ Á¤ÀÇÇÒ ¼ö ÀÖ´Ù.
* @param {String|Object|$H} sName HTML ¼Ó¼º À̸§ ȤÀº ¼³Á¤°ª °´Ã¼
* @param {String|Number} [sValue] ¼³Á¤ °ª. ¼³Á¤ °ªÀ» null·Î ÁöÁ¤Çϸé ÇØ´ç HTML ¼Ó¼ºÀ» »èÁ¦ÇÑ´Ù.
* @return {String|$Element} °ªÀ» °¡Á®¿Ã ¶§´Â String ¼³Á¤ °ªÀ», °ªÀ» ¼³Á¤ÇÒ ¶§´Â °ªÀ» ¼³Á¤ÇÑ ÇöÀçÀÇ $Element¸¦ ¸®ÅÏÇÑ´Ù.
* @description [Lite]
*
* @example
<a href="http://www.naver.com" id="sample_a" target="_blank">Naver</a>
$Element("sample_a").attr("href"); // http://www.naver.com
* @example
$Element("sample_a").attr("href", "http://www.hangame.com/");
//Before
<a href="http://www.naver.com" id="sample_a" target="_blank">Naver</a>
//After
<a href="http://www.hangame.com" id="sample_a" target="_blank">Naver</a>
* @example
$Element("sample_a").attr({
"href" : "http://www.hangame.com",
"target" : "_self"
})
//Before
<a href="http://www.naver.com" id="sample_a" target="_blank">Naver</a>
//After
<a href="http://www.hangame.com" id="sample_a" target="_self">Naver</a>
*/
jindo.$Element.prototype.attr = function(sName, sValue) {
var e = this._element;
if (typeof sName == "string") {
if (typeof sValue != "undefined") {
var obj = {};
obj[sName] = sValue;
sName = obj;
} else {
if (sName == "class" || sName == "className"){
return e.className;
}else if(sName == "style"){
return e.style.cssText;
}else if(sName == "checked"||sName == "disabled"){
return !!e[sName];
}else if(sName == "value"){
return e.value;
}else if(sName == "href"){
return e.getAttribute(sName,2);
}
return e.getAttribute(sName);
}
}
if (typeof jindo.$H != "undefined" && sName instanceof jindo.$H) {
sName = sName.$value();
}
if (typeof sName == "object") {
for(var k in sName) {
if(sName.hasOwnProperty(k)){
if (typeof(sValue) != "undefined" && sValue === null) {
e.removeAttribute(k);
}else{
if (k == "class"|| k == "className") {
e.className = sName[k];
}else if(k == "style"){
e.style.cssText = sName[k];
}else if(k == "checked"||k == "disabled"){
e[k] = sName[k];
}else if(k == "value"){
e.value = sName[k];
}else{
e.setAttribute(k, sName[k]);
}
}
}
}
}
return this;
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ ³Êºñ¸¦ °¡Á®¿À°Å³ª ¼³Á¤ÇÑ´Ù.
* @remark width ¸Þ¼µå´Â HTML ¿¤¸®¸ÕÆ®ÀÇ ½ÇÁ¦ ³Êºñ¸¦ °¡Á®¿Â´Ù. ºê¶ó¿ìÀú¸¶´Ù Box ¸ðµ¨ÀÇ Å©±â °è»ê ¹æ¹ýÀÌ ´Ù¸£¹Ç·Î CSSÀÇ width ¼Ó¼º °ª°ú width ¸Þ¼µåÀÇ ¹Ýȯ °ªÀº ¼·Î ´Ù¸¦ ¼ö ÀÖ´Ù.
* @param {Number} [width] ¼³Á¤ÇÒ ³Êºñ °ª. ´ÜÀ§´Â px ÀÌ¸ç ¸Å°³ º¯¼öÀÇ °ªÀº ¼ýÀÚ·Î ÁöÁ¤ÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö¸¦ »ý·«ÇÏ¸é ³Êºñ °ªÀ» °¡Á®¿Â´Ù.
* @return {Number | $Element} °ªÀ» °¡Á®¿À´Â °æ¿ì¿¡´Â HTML ¿¤¸®¸ÕÆ®ÀÇ ½ÇÁ¦ ³Êºñ¸¦, °ªÀ» ¼³Á¤ÇÏ´Â °æ¿ì¿¡´Â ³Êºñ °ªÀÌ º¯°æµÈ ÇöÀçÀÇ $Element °´Ã¼¸¦ ¹ÝȯÇÑ´Ù.
* @description [Lite]
* @see $Element#height
*
* @example
<style type="text/css">
div { width:70px; height:50px; padding:5px; margin:5px; background:red; }
</style>
<div id="sample_div"></div>
...
// Á¶È¸
$Element("sample_div").width(); // 80
* @example
// À§ÀÇ ¿¹Á¦ HTML ¿¤¸®¸ÕÆ®¿¡ ³Êºñ °ªÀ» ¼³Á¤
$Element("sample_div").width(200);
//Before
<div id="sample_div"></div>
//After
<div id="sample_div" style="width: 190px"></div>
*/
jindo.$Element.prototype.width = function(width) {
if (typeof width == "number") {
var e = this._element;
e.style.width = width+"px";
var off = e.offsetWidth;
if (off != width && off!==0) {
var w = (width*2 - off);
if (w>0)
e.style.width = w + "px";
}
return this;
}
return this._element.offsetWidth;
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ ³ôÀ̸¦ °¡Á®¿À°Å³ª ¼³Á¤ÇÑ´Ù.
* @remark height ¸Þ¼µå´Â HTML ¿¤¸®¸ÕÆ®ÀÇ ½ÇÁ¦ ³ôÀ̸¦ °¡Á®¿Â´Ù. ºê¶ó¿ìÀú¸¶´Ù Box ¸ðµ¨ÀÇ Å©±â °è»ê ¹æ¹ýÀÌ ´Ù¸£¹Ç·Î CSSÀÇ height ¼Ó¼º °ª°ú height ¸Þ¼µåÀÇ ¹Ýȯ °ªÀº ¼·Î ´Ù¸¦ ¼ö ÀÖ´Ù.
* @param {Number} [height] ¼³Á¤ÇÒ ³ôÀÌ °ª. ´ÜÀ§´Â px ÀÌ¸ç ¸Å°³ º¯¼öÀÇ °ªÀº ¼ýÀÚ·Î ÁöÁ¤ÇÑ´Ù.
* @return {Number | $Element} °ªÀ» °¡Á®¿À´Â °æ¿ì¿¡´Â HTML ¿¤¸®¸ÕÆ®ÀÇ ½ÇÁ¦ ³ôÀ̸¦, °ªÀ» ¼³Á¤ÇÏ´Â °æ¿ì¿¡´Â ³ôÀÌ °ªÀÌ º¯°æµÈ ÇöÀçÀÇ $Element °´Ã¼¸¦ ¹ÝȯÇÑ´Ù.
* @description [Lite]
* @see $Element#width
*
* @example
<style type="text/css">
div { width:70px; height:50px; padding:5px; margin:5px; background:red; }
</style>
<div id="sample_div"></div>
...
// Á¶È¸
$Element("sample_div").height(); // 60
* @example
// À§ÀÇ ¿¹Á¦ HTML ¿¤¸®¸ÕÆ®¿¡ ³ôÀÌ °ªÀ» ¼³Á¤
$Element("sample_div").height(100);
//Before
<div id="sample_div"></div>
//After
<div id="sample_div" style="height: 90px"></div>
*/
jindo.$Element.prototype.height = function(height) {
if (typeof height == "number") {
var e = this._element;
e.style.height = height+"px";
var off = e.offsetHeight;
if (off != height && off!==0) {
var height = (height*2 - off);
if(height>0)
e.style.height = height + "px";
}
return this;
}
return this._element.offsetHeight;
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ Å¬·¡½º¸íÀ» ¼³Á¤Çϰųª ¹ÝȯÇÑ´Ù.
* @param {String} [sClass] ¼³Á¤ÇÒ Å¬·¡½º¸í<br>
* ¸Å°³ º¯¼ö¸¦ »ý·«Çϸé HTML ¿¤¸®¸ÕÆ®ÀÇ ÇöÀçÀÇ Å¬·¡½º¸íÀ» ¹ÝȯÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö¸¦ ÁöÁ¤Çϸé Ŭ·¡½º¸íÀ» ¼³Á¤ÇÑ´Ù. ¿©·¯°³ÀÇ Å¬·¡½º¸íÀ» ¼³Á¤ÇÏ·Á¸é °ø¹éÀ¸·Î ±¸ºÐÇÑ´Ù.
* @return {String | $Element} Ŭ·¡½º¸íÀ» Á¶È¸ÇÏ´Â °æ¿ì¿¡´Â Ŭ·¡½º¸íÀ» ¹ÝȯÇÑ´Ù.<br>
* Ŭ·¡½º°¡ µÎ °³ ÀÌ»óÀ̸é Ŭ·¡½º¸íÀ» °ø¹éÀ¸·Î ±¸ºÐÇÏ¿© °ø¹éÀ» Æ÷ÇÔÇÑ ¹®ÀÚ¿·Î ¹ÝȯÇÑ´Ù.<br>
* Ŭ·¡½º¸íÀ» ¼³Á¤ÇÑ °æ¿ì¿¡´Â º¯°æµÈ ÇöÀçÀÇ $Element °´Ã¼¸¦ ¹ÝȯÇÑ´Ù.
* @description [Lite]
* @see $Element#hasClass
* @see $Element#addClass
* @see $Element#removeClass
* @see $Element#toggleClass
*
* @example
<style type="text/css">
p { margin: 8px; font-size:16px; }
.selected { color:#0077FF; }
.highlight { background:#C6E746; }
</style>
<p>Hello and <span id="sample_span" class="selected">Goodbye</span></p>
...
// Ŭ·¡½º¸í Á¶È¸
$Element("sample_span").className(); // selected
* @example
// À§ÀÇ ¿¹Á¦ HTML ¿¤¸®¸ÕÆ®¿¡ Ŭ·¡½º¸í ¼³Á¤
welSample.className("highlight");
//Before
<p>Hello and <span id="sample_span" class="selected">Goodbye</span></p>
//After
<p>Hello and <span id="sample_span" class="highlight">Goodbye</span></p>
*/
jindo.$Element.prototype.className = function(sClass) {
var e = this._element;
if (typeof sClass == "undefined") return e.className;
e.className = sClass;
return this;
};
/**
* HTML ¿¤¸®¸ÕÆ®¿¡¼ ƯÁ¤ Ŭ·¡½º¸¦ »ç¿ëÇϰí ÀÖ´ÂÁö È®ÀÎÇÑ´Ù.
* @param {String} sClass È®ÀÎÇÒ Å¬·¡½º¸í
* @return {Boolean} Ŭ·¡½º »ç¿ë ¿©ºÎ
* @description [Lite]
* @see $Element#className
* @see $Element#addClass
* @see $Element#removeClass
* @see $Element#toggleClass
*
* @example
<style type="text/css">
p { margin: 8px; font-size:16px; }
.selected { color:#0077FF; }
.highlight { background:#C6E746; }
</style>
<p>Hello and <span id="sample_span" class="selected highlight">Goodbye</span></p>
...
// Ŭ·¡½ºÀÇ »ç¿ë¿©ºÎ¸¦ È®ÀÎ
var welSample = $Element("sample_span");
welSample.hasClass("selected"); // true
welSample.hasClass("highlight"); // true
*/
jindo.$Element.prototype.hasClass = function(sClass) {
if(this._element.classList){
jindo.$Element.prototype.hasClass = function(sClass){
return this._element.classList.contains(sClass);
}
} else {
jindo.$Element.prototype.hasClass = function(sClass){
return (" "+this._element.className+" ").indexOf(" "+sClass+" ") > -1;
}
}
return this.hasClass(sClass);
};
/**
* HTML ¿¤¸®¸ÕÆ®¿¡ Ŭ·¡½º¸¦ Ãß°¡ÇÑ´Ù.
* @param {String} sClass Ãß°¡ÇÒ Å¬·¡½º¸í. ¿©·¯°³ÀÇ Å¬·¡½º¸íÀ» Ãß°¡ÇÏ·Á¸é °ø¹éÀ¸·Î ±¸ºÐÇÑ´Ù.
* @return {$Element} Ŭ·¡½º°¡ Ãß°¡µÈ ÇöÀçÀÇ $Element °´Ã¼
* @description [Lite]
* @see $Element#className
* @see $Element#hasClass
* @see $Element#removeClass
* @see $Element#toggleClass
*
* @example
// Ŭ·¡½º Ãß°¡
$Element("sample_span1").addClass("selected");
$Element("sample_span2").addClass("selected highlight");
//Before
<p>Hello and <span id="sample_span1">Goodbye</span></p>
<p>Hello and <span id="sample_span2">Goodbye</span></p>
//After
<p>Hello and <span id="sample_span1" class="selected">Goodbye</span></p>
<p>Hello and <span id="sample_span2" class="selected highlight">Goodbye</span></p>
*/
jindo.$Element.prototype.addClass = function(sClass) {
if(this._element.classList){
jindo.$Element.prototype.addClass = function(sClass){
var aClass = sClass.split(/\s+/);
var flistApi = this._element.classList;
for(var i = aClass.length ; i-- ;){
flistApi.add(aClass[i]);
}
return this;
}
} else {
jindo.$Element.prototype.addClass = function(sClass){
var e = this._element;
var aClass = sClass.split(/\s+/);
var eachClass;
for (var i = aClass.length - 1; i >= 0 ; i--){
eachClass = aClass[i];
if (!this.hasClass(eachClass)) {
e.className = (e.className+" "+eachClass).replace(/^\s+/, "");
};
};
return this;
}
}
return this.addClass(sClass);
};
/**
* HTML ¿¤¸®¸ÕÆ®¿¡¼ ƯÁ¤ Ŭ·¡½º¸¦ Á¦°ÅÇÑ´Ù.
* @param {String} sClass Á¦°ÅÇÒ Å¬·¡½º¸í. ¿©·¯°³ÀÇ Å¬·¡½º¸íÀ» Á¦°ÅÇÏ·Á¸é °ø¹éÀ¸·Î ±¸ºÐÇÑ´Ù.
* @return {$Element} Ŭ·¡½º°¡ Á¦°ÅµÈ ÇöÀçÀÇ $Element °´Ã¼
* @description [Lite]
* @see $Element#className
* @see $Element#hasClass
* @see $Element#addClass
* @see $Element#toggleClass
*
* @example
// Ŭ·¡½º Á¦°Å
$Element("sample_span").removeClass("selected");
//Before
<p>Hello and <span id="sample_span" class="selected highlight">Goodbye</span></p>
//After
<p>Hello and <span id="sample_span" class="highlight">Goodbye</span></p>
* @example
// ¿©·¯°³ÀÇ Å¬·¡½º¸¦ Á¦°Å
$Element("sample_span").removeClass("selected highlight");
$Element("sample_span").removeClass("highlight selected");
//Before
<p>Hello and <span id="sample_span" class="selected highlight">Goodbye</span></p>
//After
<p>Hello and <span id="sample_span" class="">Goodbye</span></p>
*/
jindo.$Element.prototype.removeClass = function(sClass) {
if(this._element.classList){
jindo.$Element.prototype.removeClass = function(sClass){
var flistApi = this._element.classList;
var aClass = sClass.split(" ");
for(var i = aClass.length ; i-- ;){
flistApi.remove(aClass[i]);
}
return this;
}
} else {
jindo.$Element.prototype.removeClass = function(sClass){
var e = this._element;
var aClass = sClass.split(/\s+/);
var eachClass;
for (var i = aClass.length - 1; i >= 0 ; i--){
eachClass = aClass[i];
if (this.hasClass(eachClass)) {
e.className = (" "+e.className.replace(/\s+$/, "").replace(/^\s+/, "")+" ").replace(" "+eachClass+" ", " ").replace(/\s+$/, "").replace(/^\s+/, "");
};
};
return this;
}
}
return this.removeClass(sClass);
};
/**
* HTML ¿¤¸®¸ÕÆ®¿¡ Ŭ·¡½º°¡ ÀÌ¹Ì Àû¿ëµÇ¾î ÀÖÀ¸¸é Á¦°ÅÇÏ°í ¸¸¾à ¾øÀ¸¸é Ãß°¡ÇÑ´Ù.
* @param {String} sClass Ãß°¡ ȤÀº Á¦°ÅÇÒ Å¬·¡½º¸í
* @param {String} [sClass2] Ãß°¡ ȤÀº Á¦°ÅÇÒ Å¬·¡½º¸í<br>
* sClass2 ¸Å°³ º¯¼ö¸¦ »ý·«Çϸé HTML ¿¤¸®¸ÕÆ®¿¡¼ sClass ¸Å°³ º¯¼ö °ªÀÇ Å¬·¡½º¸¦ »ç¿ë ÁßÀÎÁö È®ÀÎÇÑ´Ù.<br>
* ¸¸¾à »ç¿ëÇϰí ÀÖ´Ù¸é ÇØ´ç Ŭ·¡½º¸¦ Á¦°ÅÇϰí, »ç¿ëÇϰí ÀÖÁö ¾Ê´Ù¸é Ãß°¡ÇÑ´Ù.<br>
* µÎ °³ÀÇ ¸Å°³ º¯¼ö¸¦ ¸ðµÎ »ç¿ëÇϸé, µÎ Ŭ·¡½º Áß¿¡¼ »ç¿ëÇϰí ÀÖ´Â °ÍÀ» Á¦°ÅÇÏ°í ³ª¸ÓÁö¸¦ Ãß°¡ÇÑ´Ù.
* @return {$Element} Ŭ·¡½º°¡ Ãß°¡ ȤÀº Á¦°ÅµÈ ÇöÀçÀÇ $Element °´Ã¼
* @import core.$Element[hasClass,addClass,removeClass]
* @description [Lite]
* @see $Element#className
* @see $Element#hasClass
* @see $Element#addClass
* @see $Element#removeClass
*
* @example
// ¸Å°³ º¯¼ö°¡ ÇϳªÀÎ °æ¿ì
$Element("sample_span1").toggleClass("highlight");
$Element("sample_span2").toggleClass("highlight");
//Before
<p>Hello and <span id="sample_span1" class="selected highlight">Goodbye</span></p>
<p>Hello and <span id="sample_span2" class="selected">Goodbye</span></p>
//After
<p>Hello and <span id="sample_span1" class="selected">Goodbye</span></p>
<p>Hello and <span id="sample_span2" class="selected highlight">Goodbye</span></p>
* @example
// ¸Å°³ º¯¼ö°¡ µÎ °³ÀÎ °æ¿ì
$Element("sample_span1").toggleClass("selected", "highlight");
$Element("sample_span2").toggleClass("selected", "highlight");
//Before
<p>Hello and <span id="sample_span1" class="highlight">Goodbye</span></p>
<p>Hello and <span id="sample_span2" class="selected">Goodbye</span></p>
//After
<p>Hello and <span id="sample_span1" class="selected">Goodbye</span></p>
<p>Hello and <span id="sample_span2" class="highlight">Goodbye</span></p>
*/
jindo.$Element.prototype.toggleClass = function(sClass, sClass2) {
if(this._element.classList){
jindo.$Element.prototype.toggleClass = function(sClass, sClass2){
if (typeof sClass2 == "undefined") {
this._element.classList.toggle(sClass);
} else {
if(this.hasClass(sClass)){
this.removeClass(sClass);
this.addClass(sClass2);
}else{
this.addClass(sClass);
this.removeClass(sClass2);
}
}
return this;
}
} else {
jindo.$Element.prototype.toggleClass = function(sClass, sClass2){
sClass2 = sClass2 || "";
if (this.hasClass(sClass)) {
this.removeClass(sClass);
if (sClass2) this.addClass(sClass2);
} else {
this.addClass(sClass);
if (sClass2) this.removeClass(sClass2);
}
return this;
}
}
return this.toggleClass(sClass, sClass2);
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ ÅØ½ºÆ® ³ëµå °ªÀ» °¡Á®¿À°Å³ª ¼³Á¤ÇÑ´Ù.
* @param {String} [sText] ¼³Á¤ÇÒ ÅØ½ºÆ®<br>
* ¸Å°³ º¯¼ö¸¦ »ý·«Çϸé ÅØ½ºÆ® ³ëµå¸¦ Á¶È¸Çϰí, ¸Å°³ º¯¼ö¸¦ ÁöÁ¤ÇÏ¸é ¸Å°³ º¯¼öÀÇ °ªÀ¸·Î ÅØ½ºÆ® ³ëµå¸¦ ¼³Á¤ÇÑ´Ù.
* @returns {String} °ªÀ» Á¶È¸ÇÏ´Â °æ¿ì¿¡´Â HTML ¿¤¸®¸ÕÆ®ÀÇ ÅØ½ºÆ® ³ëµå¸¦ ¹ÝȯÇϰí,<br>
* °ªÀ» ¼³Á¤ÇÏ´Â °æ¿ì¿¡´Â ÅØ½ºÆ® ³ëµå¸¦ ¼³Á¤ÇÑ ÇöÀçÀÇ $Element °´Ã¼¸¦ ¹Ýȯ
* @description [Lite]
*
* @example
<ul id="sample_ul">
<li>Çϳª</li>
<li>µÑ</li>
<li>¼Â</li>
<li>³Ý</li>
</ul>
...
// ÅØ½ºÆ® ³ëµå °ª Á¶È¸
$Element("sample_ul").text();
// °á°ú
// Çϳª
// µÑ
// ¼Â
// ³Ý
@example
// ÅØ½ºÆ® ³ëµå °ª ¼³Á¤
$Element("sample_ul").text('´Ù¼¸');
//Before
<ul id="sample_ul">
<li>Çϳª</li>
<li>µÑ</li>
<li>¼Â</li>
<li>³Ý</li>
</ul>
//After
<ul id="sample_ul">´Ù¼¸</ul>
@example
// ÅØ½ºÆ® ³ëµå °ª ¼³Á¤
$Element("sample_p").text("New Content");
//Before
<p id="sample_p">
Old Content
</p>
//After
<p id="sample_p">
New Content
</p>
*/
jindo.$Element.prototype.text = function(sText) {
var ele = this._element;
var tag = this.tag;
var prop = (typeof ele.innerText != "undefined")?"innerText":"textContent";
if (tag == "textarea" || tag == "input") prop = "value";
var type = (typeof sText);
if (type != "undefined"&&(type == "string" || type == "number" || type == "boolean")) {
sText += "";
try {
/*
* Opera 11.01¿¡¼ textContext°¡ GetÀ϶§ Á¤»óÀûÀ¸·Î µ¿ÀÛÇÏÁö ¾ÊÀ½. ±×·¡¼ getÀÏ ¶§´Â innerTextÀ» »ç¿ëÇϰí setÇÏ´Â °æ¿ì´Â textContentÀ» »ç¿ëÇÑ´Ù.(http://devcafe.nhncorp.com/ajaxui/295768)
*/
if (prop!="value") prop = (typeof ele.textContent != "undefined")?"textContent":"innerText";
ele[prop] = sText;
} catch(e) {
return this.html(sText.replace(/&/g, '&').replace(/</g, '<'));
}
return this;
}
return ele[prop];
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ ³»ºÎ HTML(innerHTML) À» °¡Á®¿À°Å³ª ¼³Á¤ÇÑ´Ù.
* @param {String} [sHTML] ¼³Á¤ÇÒ HTML ¹®ÀÚ¿<br>
* ¸Å°³ º¯¼ö¸¦ »ý·«ÇÏ¸é ³»ºÎ HTML À» Á¶È¸Çϰí, ¸Å°³ º¯¼ö¸¦ ÁöÁ¤ÇÏ¸é ¸Å°³ º¯¼öÀÇ °ªÀ¸·Î ³»ºÎ HTMLÀ» º¯°æÇÑ´Ù.
* @return {String | $Element} °ªÀ» Á¶È¸ÇÏ´Â °æ¿ì¿¡´Â HTML ¿¤¸®¸ÕÆ®ÀÇ ³»ºÎ HTMLÀ» ¹ÝȯÇϰí,<br>
* °ªÀ» ¼³Á¤ÇÏ´Â °æ¿ì¿¡´Â ³»ºÎ HTML À» º¯°æÇÑ ÇöÀçÀÇ $Element °´Ã¼¸¦ ¹Ýȯ
* @see $Element#outerHTML
* @description [Lite]
*
* @example
<div id="sample_container">
<p><em>Old</em> content</p>
</div>
...
// ³»ºÎ HTML Á¶È¸
$Element("sample_container").html(); // <p><em>Old</em> content</p>
* @example
// ³»ºÎ HTML ¼³Á¤
$Element("sample_container").html("<p>New <em>content</em></p>");
//Before
<div id="sample_container">
<p><em>Old</em> content</p>
</div>
//After
<div id="sample_container">
<p>New <em>content</em></p>
</div>
*/
jindo.$Element.prototype.html = function(sHTML) {
var isIe = IS_IE;
var isFF = IS_FF;
if (isIe) {
jindo.$Element.prototype.html = function(sHTML){
if (typeof sHTML != "undefined" && arguments.length) {
sHTML += "";
jindo.$$.release();
var oEl = this._element;
while(oEl.firstChild){
oEl.removeChild(oEl.firstChild);
}
/*
IE ³ª FireFox ÀÇ ÀϺΠ»óȲ¿¡¼ SELECT ű׳ª TABLE, TR, THEAD, TBODY ű׿¡ innerHTML À» ¼ÂÆÃÇØµµ
¹®Á¦°¡ »ý±âÁö ¾Êµµ·Ï º¸¿Ï - hooriza
*/
var sId = 'R' + new Date().getTime() + parseInt(Math.random() * 100000,10);
var oDoc = oEl.ownerDocument || oEl.document || document;
var oDummy;
var sTag = oEl.tagName.toLowerCase();
switch (sTag) {
case 'select':
case 'table':
oDummy = oDoc.createElement("div");
oDummy.innerHTML = '<' + sTag + ' class="' + sId + '">' + sHTML + '</' + sTag + '>';
break;
case 'tr':
case 'thead':
case 'tbody':
case 'colgroup':
oDummy = oDoc.createElement("div");
oDummy.innerHTML = '<table><' + sTag + ' class="' + sId + '">' + sHTML + '</' + sTag + '></table>';
break;
default:
oEl.innerHTML = sHTML;
break;
}
if (oDummy) {
var oFound;
for (oFound = oDummy.firstChild; oFound; oFound = oFound.firstChild)
if (oFound.className == sId) break;
if (oFound) {
var notYetSelected = true;
for (var oChild; oChild = oEl.firstChild;) oChild.removeNode(true); // innerHTML = '';
for (var oChild = oFound.firstChild; oChild; oChild = oFound.firstChild){
if(sTag=='select'){
/*
* ie¿¡¼ selectÅ×±×ÀÏ °æ¿ì optionÁß selected°¡ µÇ¾î ÀÖ´Â optionÀÌ ÀÖ´Â °æ¿ì Áß°£¿¡
* selected°¡ µÇ¾î ÀÖÀ¸¸é ±× ´ÙÀ½ ºÎÅÍ´Â °è¼Ó selected°¡ true·Î µÇ¾î ÀÖ¾î
* ÇØ°áÇϱâ À§ÇØ cloneNode¸¦ ÀÌ¿ëÇÏ¿© optionÀ» Ä«ÇÇÇÑ ÈÄ selected¸¦ º¯°æÇÔ. - mixed
*/
var cloneNode = oChild.cloneNode(true);
if (oChild.selected && notYetSelected) {
notYetSelected = false;
cloneNode.selected = true;
}
oEl.appendChild(cloneNode);
oChild.removeNode(true);
}else{
oEl.appendChild(oChild);
}
}
oDummy.removeNode && oDummy.removeNode(true);
}
oDummy = null;
}
return this;
}
return this._element.innerHTML;
}
}else if(isFF){
jindo.$Element.prototype.html = function(sHTML){
if (typeof sHTML != "undefined" && arguments.length) {
sHTML += "";
var oEl = this._element;
if(!oEl.parentNode){
/*
IE ³ª FireFox ÀÇ ÀϺΠ»óȲ¿¡¼ SELECT ű׳ª TABLE, TR, THEAD, TBODY ű׿¡ innerHTML À» ¼ÂÆÃÇØµµ
¹®Á¦°¡ »ý±âÁö ¾Êµµ·Ï º¸¿Ï - hooriza
*/
var sId = 'R' + new Date().getTime() + parseInt(Math.random() * 100000,10);
var oDoc = oEl.ownerDocument || oEl.document || document;
var oDummy;
var sTag = oEl.tagName.toLowerCase();
switch (sTag) {
case 'select':
case 'table':
oDummy = oDoc.createElement("div");
oDummy.innerHTML = '<' + sTag + ' class="' + sId + '">' + sHTML + '</' + sTag + '>';
break;
case 'tr':
case 'thead':
case 'tbody':
case 'colgroup':
oDummy = oDoc.createElement("div");
oDummy.innerHTML = '<table><' + sTag + ' class="' + sId + '">' + sHTML + '</' + sTag + '></table>';
break;
default:
oEl.innerHTML = sHTML;
break;
}
if (oDummy) {
var oFound;
for (oFound = oDummy.firstChild; oFound; oFound = oFound.firstChild)
if (oFound.className == sId) break;
if (oFound) {
for (var oChild; oChild = oEl.firstChild;) oChild.removeNode(true); // innerHTML = '';
for (var oChild = oFound.firstChild; oChild; oChild = oFound.firstChild){
oEl.appendChild(oChild);
}
oDummy.removeNode && oDummy.removeNode(true);
}
oDummy = null;
}
}else{
oEl.innerHTML = sHTML;
}
return this;
}
return this._element.innerHTML;
}
}else{
jindo.$Element.prototype.html = function(sHTML){
if (typeof sHTML != "undefined" && arguments.length) {
sHTML += "";
var oEl = this._element;
oEl.innerHTML = sHTML;
return this;
}
return this._element.innerHTML;
}
}
return this.html(sHTML);
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ ¿ÜºÎ HTML(outerHTML) À» ¹ÝȯÇÑ´Ù.
* @return {String} ¿ÜºÎ HTML
* @see $Element#html
* @description [Lite]
*
* @example
<h2 id="sample0">Today is...</h2>
<div id="sample1">
<p><span id="sample2">Sample</span> content</p>
</div>
...
// ¿ÜºÎ HTML °ªÀ» Á¶È¸
$Element("sample0").outerHTML(); // <h2 id="sample0">Today is...</h2>
$Element("sample1").outerHTML(); // <div id="sample1"> <p><span id="sample2">Sample</span> content</p> </div>
$Element("sample2").outerHTML(); // <span id="sample2">Sample</span>
*/
jindo.$Element.prototype.outerHTML = function() {
var e = this._element;
if (typeof e.outerHTML != "undefined") return e.outerHTML;
var oDoc = e.ownerDocument || e.document || document;
var div = oDoc.createElement("div");
var par = e.parentNode;
/**
»óÀ§³ëµå°¡ ¾øÀ¸¸é innerHTML¹Ýȯ
*/
if(!par) return e.innerHTML;
par.insertBefore(div, e);
div.style.display = "none";
div.appendChild(e);
var s = div.innerHTML;
par.insertBefore(e, div);
par.removeChild(div);
return s;
};
/**
* HTML ¿¤¸®¸ÕÆ®¸¦ HTML ¹®ÀÚ¿·Î º¯È¯ÇÏ¿© ¹ÝȯÇÑ´Ù. (outerHTML ¸Þ¼µå¿Í µ¿ÀÏ)
* @return {String} ¿ÜºÎ HTML
* @see $Element#outerHTML
*/
jindo.$Element.prototype.toString = jindo.$Element.prototype.outerHTML;
/**
* @fileOverview $ElementÀÇ È®Àå ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name element.extend.js
*/
/**
* appear ,disappear¿¡¼ »ç¿ëµÇ´Â ÇÔ¼ö·Î ÇöÀç transitionÀ» »ç¿ë ÇÒ¼ö ÀÖ´ÂÁö¸¦ ÇÐÀÎÇÑ´Ù.
* @ignore
*/
jindo.$Element._getTransition = function(){
var hasTransition = false , sTransitionName = "";
if (typeof document.body.style.trasition != "undefined") {
hasTransition = true;
sTransitionName = "trasition";
}
/*
¾ÆÁ÷ firefox´Â transitionEnd API¸¦ Áö¿ø ÇÏÁö ¾ÊÀ½.
*/
// else if(typeof document.body.style.MozTransition !== "undefined"){
// hasTransition = true;
// sTransitionName = "MozTransition";
// }
else if(typeof document.body.style.webkitTransition !== "undefined"){
hasTransition = true;
sTransitionName = "webkitTransition";
}else if(typeof document.body.style.OTransition !== "undefined"){
hasTransition = true;
sTransitionName = "OTransition";
}
return (jindo.$Element._getTransition = function(){
return {
"hasTransition" : hasTransition,
"name" : sTransitionName
};
})();
}
/**
* HTML ¿¤¸®¸ÕÆ®¸¦ ¼¼È÷ ³ªÅ¸³ª°Ô ÇÑ´Ù. (Fade-in È¿°ú)
*
* @param {Number} duration HTML ¿¤¸®¸ÕÆ®°¡ ¿ÏÀüÈ÷ ³ªÅ¸³¯ ¶§±îÁö °É¸®´Â ½Ã°£. ´ÜÀ§´Â Ãʸ¦ »ç¿ëÇÑ´Ù.
* @param {Function} [callback] HTML ¿¤¸®¸ÕÆ®°¡ ¿ÏÀüÈ÷ ³ªÅ¸³ ÈÄ¿¡ ½ÇÇàÇÒ Äݹé ÇÔ¼ö.
* @return {$Element} ÇöÀçÀÇ $Element °´Ã¼
*
* @remark IE6 ¿¡¼ filter »ç¿ë ½Ã ÇØ´ç ¿¤¸®¸ÕÆ®°¡ position ¼Ó¼ºÀ» °¡Áö°í ÀÖÀ¸¸é »ç¶óÁö´Â ¹®Á¦°¡ Àֱ⠶§¹®¿¡ HTML ¿¤¸®¸ÕÆ®¿¡ position ¼Ó¼ºÀÌ ¾ø¾î¾ß ÇÑ´Ù.
* @remark webkit±â¹ÝÀÇ ºê¶ó¿ìÀú(safari5+, mobile safari, chrome, mobile webkit), opera10.60+ ¿¡¼´Â CSS3 transitionÀ» »ç¿ëÇÑ´Ù. ±× ÀÌ¿ÜÀÇ ºê¶ó¿ìÀú¿¡¼´Â ÀÚ¹Ù½ºÅ©¸³Æ®¸¦ »ç¿ëÇÑ´Ù.
*
* @see $Element#show
* @see $Element#disappear
*
* @example
$Element("sample1").appear(5, function(){
$Element("sample2").appear(3);
});
//Before
<div style="display: none; background-color: rgb(51, 51, 153); width: 100px; height: 50px;" id="sample1">
<div style="display: none; background-color: rgb(165, 10, 81); width: 50px; height: 20px;" id="sample2">
</div>
</div>
//After(1) : sample1 ¿¤¸®¸ÕÆ®°¡ ³ªÅ¸³²
<div style="display: block; background-color: rgb(51, 51, 153); width: 100px; height: 50px; opacity: 1;" id="sample1">
<div style="display: none; background-color: rgb(165, 10, 81); width: 50px; height: 20px;" id="sample2">
</div>
</div>
//After(2) : sample2 ¿¤¸®¸ÕÆ®°¡ ³ªÅ¸³²
<div style="display: block; background-color: rgb(51, 51, 153); width: 100px; height: 50px; opacity: 1;" id="sample1">
<div style="display: block; background-color: rgb(165, 10, 81); width: 50px; height: 20px; opacity: 1;" id="sample2">
</div>
</div>
*/
jindo.$Element.prototype.appear = function(duration, callback) {
var oTransition = jindo.$Element._getTransition();
if (oTransition.hasTransition) {
jindo.$Element.prototype.appear = function(duration, callback) {
duration = duration||0.3;
callback = callback || function(){};
var bindFunc = function(){
callback();
this.show();
this.removeEventListener(oTransition.name+"End", arguments.callee , false );
};
var ele = this._element;
var self = this;
if(!this.visible()){
ele.style.opacity = ele.style.opacity||0;
self.show();
}
ele.addEventListener( oTransition.name+"End", bindFunc , false );
ele.style[oTransition.name + 'Property'] = 'opacity';
ele.style[oTransition.name + 'Duration'] = duration+'s';
ele.style[oTransition.name + 'TimingFunction'] = 'linear';
setTimeout(function(){
ele.style.opacity = '1';
},1);
return this;
}
}else{
jindo.$Element.prototype.appear = function(duration, callback) {
var self = this;
var op = this.opacity();
if(!this.visible()) op = 0;
if (op == 1) return this;
try { clearTimeout(this._fade_timer); } catch(e){};
callback = callback || function(){};
var step = (1-op) / ((duration||0.3)*100);
var func = function(){
op += step;
self.opacity(op);
if (op >= 1) {
callback(self);
} else {
self._fade_timer = setTimeout(func, 10);
}
};
this.show();
func();
return this;
}
}
return this.appear(duration, callback);
};
/**
* HTML ¿¤¸®¸ÕÆ®¸¦ ¼¼È÷ »ç¶óÁö°Ô ÇÑ´Ù. (Fade-out È¿°ú)<br>
* HTML ¿¤¸®¸ÕÆ®°¡ ¿ÏÀüÈ÷ »ç¶óÁö¸é ¿¤¸®¸ÕÆ®ÀÇ display ¼Ó¼ºÀº none À¸·Î º¯ÇÑ´Ù.
*
* @param {Number} duration HTML ¿¤¸®¸ÕÆ® ¿ÏÀüÈ÷ »ç¶óÁú ¶§±îÁö °É¸®´Â ½Ã°£. ´ÜÀ§´Â Ãʸ¦ »ç¿ëÇÑ´Ù.
* @param {Function} [callback] HTML ¿¤¸®¸ÕÆ®°¡ ¿ÏÀüÈ÷ »ç¶óÁø ÈÄ¿¡ ½ÇÇàÇÒ Äݹé ÇÔ¼ö.
* @return {$Element} ÇöÀçÀÇ $Element °´Ã¼
*
* @remark webkit±â¹ÝÀÇ ºê¶ó¿ìÀú(safari5+, mobile safari, chrome, mobile webkit), opera10.60+ ¿¡¼´Â CSS3 transitionÀ» »ç¿ëÇÑ´Ù. ±× ÀÌ¿ÜÀÇ ºê¶ó¿ìÀú¿¡¼´Â ÀÚ¹Ù½ºÅ©¸³Æ®¸¦ »ç¿ëÇÑ´Ù.
*
* @see $Element#hide
* @see $Element#appear
*
* @example
$Element("sample1").disappear(5, function(){
$Element("sample2").disappear(3);
});
//Before
<div id="sample1" style="background-color: rgb(51, 51, 153); width: 100px; height: 50px;">
</div>
<div id="sample2" style="background-color: rgb(165, 10, 81); width: 100px; height: 50px;">
</div>
//After(1) : sample1 ¿¤¸®¸ÕÆ®°¡ »ç¶óÁü
<div id="sample1" style="background-color: rgb(51, 51, 153); width: 100px; height: 50px; opacity: 1; display: none;">
</div>
<div id="sample2" style="background-color: rgb(165, 10, 81); width: 100px; height: 50px;">
</div>
//After(2) : sample2 ¿¤¸®¸ÕÆ®°¡ »ç¶óÁü
<div id="sample1" style="background-color: rgb(51, 51, 153); width: 100px; height: 50px; opacity: 1; display: none;">
</div>
<div id="sample2" style="background-color: rgb(165, 10, 81); width: 100px; height: 50px; opacity: 1; display: none;">
</div>
*/
jindo.$Element.prototype.disappear = function(duration, callback) {
var oTransition = jindo.$Element._getTransition();
if (oTransition.hasTransition) {
jindo.$Element.prototype.disappear = function(duration, callback) {
duration = duration||0.3
var self = this;
callback = callback || function(){};
var bindFunc = function(){
callback();
this.removeEventListener(oTransition.name+"End", arguments.callee , false );
self.hide();
};
var ele = this._element;
ele.addEventListener( oTransition.name+"End", bindFunc , false );
ele.style[oTransition.name + 'Property'] = 'opacity';
ele.style[oTransition.name + 'Duration'] = duration+'s';
ele.style[oTransition.name + 'TimingFunction'] = 'linear';
/*
opera ¹ö±×·Î ÀÎÇÏ¿© ¾Æ·¡¿Í °°ÀÌ Ã³¸®ÇÔ.
*/
setTimeout(function(){
ele.style.opacity = '0';
},1);
return this;
}
}else{
jindo.$Element.prototype.disappear = function(duration, callback) {
var self = this;
var op = this.opacity();
if (op == 0) return this;
try { clearTimeout(this._fade_timer); } catch(e){};
callback = callback || function(){};
var step = op / ((duration||0.3)*100);
var func = function(){
op -= step;
self.opacity(op);
if (op <= 0) {
self.hide();
self.opacity(1);
callback(self);
} else {
self._fade_timer = setTimeout(func, 10);
}
};
func();
return this;
}
}
return this.disappear(duration, callback);
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ À§Ä¡¸¦ °¡Á®¿À°Å³ª ¼³Á¤ÇÑ´Ù.<br>
* <br>
* ¸Å°³ º¯¼ö¸¦ »ý·«Çϸé À§Ä¡ °ªÀ» °¡Á®¿Â´Ù.<br>
* ¸Å°³ º¯¼ö¸¦ ÁöÁ¤Çϸé HTML ¿¤¸®¸ÕÆ®ÀÇ À§Ä¡¸¦ ¼³Á¤ÇÑ´Ù.<br>
* ±âÁØÁ¡Àº ºê¶ó¿ìÀú ¹®¼ÀÇ ¿ÞÂÊ »ó´ÜÀÌ´Ù.
*
* @param {Number} [nTop] ¹®¼ÀÇ ¸Ç À§¿¡¼ HTML ¿¤¸®¸ÕÆ® ¸Ç À§±îÁöÀÇ °Å¸®. ´ÜÀ§´Â px
* @param {Number} [nLeft] ¹®¼ÀÇ ¿ÞÂÊ °¡ÀåÀÚ¸®¿¡¼ HTML ¿¤¸®¸ÕÆ® ¿ÞÂÊ °¡ÀåÀÚ¸®±îÁöÀÇ °Å¸®. ´ÜÀ§´Â px
* @return {$Element | Object} À§Ä¡¸¦ ¼³Á¤Çϸé À§Ä¡ °ªÀÌ º¯°æµÈ $Element °´Ã¼¸¦ ¹ÝȯÇϰí,<br>
* À§Ä¡¸¦ °¡Á®¿À¸é HTML ¿¤¸®¸ÕÆ®ÀÇ top, left À§Ä¡ °ªÀ» °´Ã¼·Î ¹ÝȯÇÑ´Ù.
*
* @remark HTML ¿¤¸®¸ÕÆ®°¡ º¸ÀÌ´Â »óÅ¿¡¼ Àû¿ëÇØ¾ß ÇÑ´Ù. ¿¤¸®¸ÕÆ®°¡ ȸ鿡 º¸ÀÌÁö ¾ÊÀ¸¸é offset ÀÇ »ç¿ëÀÌ Á¤È®ÇÏÁö ¾Ê´Ù.
* @remark ÀϺΠºê¶ó¿ìÀú¿Í ÀϺΠ»óȲ¿¡¼ inline ¿¤¸®¸ÕÆ®¿¡ ´ëÇÑ À§Ä¡°¡ ¿Ã¹Ù¸£°Ô ¾ò¾îÁöÁö ¾Ê´Â ¹®Á¦°¡ ÀÖÀ¸¸ç ÀÌ °æ¿ì ÇØ´ç ¿¤¸®¸ÕÆ®¸¦ position:relative; ·Î ¹Ù²ãÁÖ´Â ½ÄÀ¸·Î ÇØ°áÇÒ ¼ö ÀÖ´Ù.
* @author Hooriza
*
* @example
<style type="text/css">
div { background-color:#2B81AF; width:20px; height:20px; float:left; left:100px; top:50px; position:absolute;}
</style>
<div id="sample"></div>
...
// À§Ä¡ °ª Á¶È¸
$Element("sample").offset(); // { left=100, top=50 }
* @example
// À§Ä¡ °ª ¼³Á¤
$Element("sample").offset(40, 30);
//Before
<div id="sample"></div>
//After
<div id="sample" style="top: 40px; left: 30px;"></div>
*/
jindo.$Element.prototype.offset = function(nTop, nLeft) {
var oEl = this._element;
var oPhantom = null;
// setter
if (typeof nTop == 'number' && typeof nLeft == 'number') {
if (isNaN(parseInt(this.css('top'),10))) this.css('top', 0);
if (isNaN(parseInt(this.css('left'),10))) this.css('left', 0);
var oPos = this.offset();
var oGap = { top : nTop - oPos.top, left : nLeft - oPos.left };
oEl.style.top = parseInt(this.css('top'),10) + oGap.top + 'px';
oEl.style.left = parseInt(this.css('left'),10) + oGap.left + 'px';
return this;
}
// getter
var bSafari = /Safari/.test(navigator.userAgent);
var bIE = /MSIE/.test(navigator.userAgent);
var nVer = bIE?navigator.userAgent.match(/(?:MSIE) ([0-9.]+)/)[1]:0;
var fpSafari = function(oEl) {
var oPos = { left : 0, top : 0 };
for (var oParent = oEl, oOffsetParent = oParent.offsetParent; oParent = oParent.parentNode; ) {
if (oParent.offsetParent) {
oPos.left -= oParent.scrollLeft;
oPos.top -= oParent.scrollTop;
}
if (oParent == oOffsetParent) {
oPos.left += oEl.offsetLeft + oParent.clientLeft;
oPos.top += oEl.offsetTop + oParent.clientTop ;
if (!oParent.offsetParent) {
oPos.left += oParent.offsetLeft;
oPos.top += oParent.offsetTop;
}
oOffsetParent = oParent.offsetParent;
oEl = oParent;
}
}
return oPos;
};
var fpOthers = function(oEl) {
var oPos = { left : 0, top : 0 };
var oDoc = oEl.ownerDocument || oEl.document || document;
var oHtml = oDoc.documentElement;
var oBody = oDoc.body;
if (oEl.getBoundingClientRect) { // has getBoundingClientRect
if (!oPhantom) {
var bHasFrameBorder = (window == top);
if(!bHasFrameBorder){
try{
bHasFrameBorder = (window.frameElement && window.frameElement.frameBorder == 1);
}catch(e){}
}
if ((bIE && nVer < 8 && window.external) && bHasFrameBorder) {
oPhantom = { left : 2, top : 2 };
oBase = null;
} else {
oPhantom = { left : 0, top : 0 };
}
}
var box = oEl.getBoundingClientRect();
if (oEl !== oHtml && oEl !== oBody) {
oPos.left = box.left - oPhantom.left;
oPos.top = box.top - oPhantom.top;
oPos.left += oHtml.scrollLeft || oBody.scrollLeft;
oPos.top += oHtml.scrollTop || oBody.scrollTop;
}
} else if (oDoc.getBoxObjectFor) { // has getBoxObjectFor
var box = oDoc.getBoxObjectFor(oEl);
var vpBox = oDoc.getBoxObjectFor(oHtml || oBody);
oPos.left = box.screenX - vpBox.screenX;
oPos.top = box.screenY - vpBox.screenY;
} else {
for (var o = oEl; o; o = o.offsetParent) {
oPos.left += o.offsetLeft;
oPos.top += o.offsetTop;
}
for (var o = oEl.parentNode; o; o = o.parentNode) {
if (o.tagName == 'BODY') break;
if (o.tagName == 'TR') oPos.top += 2;
oPos.left -= o.scrollLeft;
oPos.top -= o.scrollTop;
}
}
return oPos;
};
return (bSafari ? fpSafari : fpOthers)(oEl);
};
/**
* ¹®ÀÚ¿ ³»ÀÇ JavaScript¸¦ ½ÇÇàÇÑ´Ù.<br>
* <script> űװ¡ Æ÷ÇÔµÈ ¹®ÀÚ¿À» ¸Å°³ º¯¼ö·Î ÁöÁ¤Çϸé, <script> ¾È¿¡ ÀÖ´Â ³»¿ëÀ» ÆÄ½ÌÇÏ¿© eval ¸¦ ¼öÇàÇÑ´Ù.
*
* @param {String} sHTML <script> űװ¡ Æ÷ÇÔµÈ HTML ¹®ÀÚ¿
* @return {$Element} ÇöÀçÀÇ $Element °´Ã¼¸¦ ¹Ýȯ
*
* @example
// script űװ¡ Æ÷ÇÔµÈ ¹®ÀÚ¿À» ÁöÁ¤
var response = "<script type='text/javascript'>$Element('sample').appendHTML('<li>4</li>')</script>";
$Element("sample").evalScripts(response);
//Before
<ul id="sample">
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
//After
<ul id="sample">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li></ul>
*/
jindo.$Element.prototype.evalScripts = function(sHTML) {
var aJS = [];
sHTML = sHTML.replace(new RegExp('<script(\\s[^>]+)*>(.*?)</'+'script>', 'gi'), function(_1, _2, sPart) { aJS.push(sPart); return ''; });
eval(aJS.join('\n'));
return this;
};
/**
* element¸¦ µÚ¿¡ ºÙÀ϶§ »ç¿ëµÇ´Â ÇÔ¼ö.
* @ignore
* @param {Element} ±âÁØ ¿¤¸®¸ÕÆ®
* @param {Element} ºÙÀÏ ¿¤¸®¸ÕÆ®
* @return {$Element} µÎ¹øÂ° ÆÄ¶ó¸ÞÅÍÀÇ ¿¤¸®¸ÕÆ®
*/
jindo.$Element._append = function(oParent, oChild){
if (typeof oChild == "string") {
oChild = jindo.$(oChild);
}else if(oChild instanceof jindo.$Element){
oChild = oChild.$value();
}
oParent._element.appendChild(oChild);
return oParent;
}
/**
* element¸¦ ¾Õ¿¡ ºÙÀ϶§ »ç¿ëµÇ´Â ÇÔ¼ö.
* @ignore
* @param {Element} ±âÁØ ¿¤¸®¸ÕÆ®
* @param {Element} ºÙÀÏ ¿¤¸®¸ÕÆ®
* @return {$Element} µÎ¹øÂ° ÆÄ¶ó¸ÞÅÍÀÇ ¿¤¸®¸ÕÆ®
*/
jindo.$Element._prepend = function(oParent, oChild){
if (typeof oParent == "string") {
oParent = jindo.$(oParent);
}else if(oParent instanceof jindo.$Element){
oParent = oParent.$value();
}
var nodes = oParent.childNodes;
if (nodes.length > 0) {
oParent.insertBefore(oChild._element, nodes[0]);
} else {
oParent.appendChild(oChild._element);
}
return oChild;
}
/**
* HTML ¿¤¸®¸ÕÆ®¿¡ ¸¶Áö¸· ÀÚ½Ä ³ëµå¸¦ Ãß°¡ÇÑ´Ù.
*
* @param {$Element | HTML Element | String} oElement Ãß°¡ÇÒ HTML ¿¤¸®¸ÕÆ®. ¹®ÀÚ¿, HTML ¿¤¸®¸ÕÆ®, ȤÀº $Element À» ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.<br>
* <br>
* ¸Å°³ º¯¼ö°¡ ¹®ÀÚ¿À̸é ÇØ´ç ¹®ÀÚ¿À» id ·Î ÇÏ´Â HTML ¿¤¸®¸ÕÆ®¸¦ ¸¶Áö¸· Àڽijëµå·Î Ãß°¡ÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ HTML ¿¤¸®¸ÕÆ®À̸é ÇØ´ç ¿¤¸®¸ÕÆ®¸¦ ¸¶Áö¸· Àڽijëµå·Î Ãß°¡ÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ $Element À̸é $Element °´Ã¼ ³»ºÎÀÇ HTML ¿¤¸®¸ÕÆ®¸¦ ¸¶Áö¸· Àڽijëµå·Î Ãß°¡ÇÑ´Ù.
* @return {$Element} $Element °´Ã¼ ÀÚ½Å
*
* @see $Element#prepend
* @see $Element#before
* @see $Element#after
* @see $Element#appendTo
* @see $Element#prependTo
*
* @example
// id °¡ sample1 ÀÎ HTML ¿¤¸®¸ÕÆ®¿¡
// id °¡ sample2 ÀÎ HTML ¿¤¸®¸ÕÆ®¸¦ Ãß°¡
$Element("sample1").append("sample2");
//Before
<div id="sample2">
<div>Hello 2</div>
</div>
<div id="sample1">
<div>Hello 1</div>
</div>
//After
<div id="sample1">
<div>Hello 1</div>
<div id="sample2">
<div>Hello 2</div>
</div>
</div>
* @example
// id °¡ sample ÀÎ HTML ¿¤¸®¸ÕÆ®¿¡
// »õ·Î¿î DIV ¿¤¸®¸ÕÆ®¸¦ Ãß°¡
var elChild = $("<div>Hello New</div>");
$Element("sample").append(elChild);
//Before
<div id="sample">
<div>Hello</div>
</div>
//After
<div id="sample">
<div>Hello </div>
<div>Hello New</div>
</div>
*/
jindo.$Element.prototype.append = function(oElement) {
return jindo.$Element._append(this,oElement);
};
/**
* HTML ¿¤¸®¸ÕÆ®¿¡ ù ¹øÂ° ÀÚ½Ä ³ëµå¸¦ Ãß°¡ÇÑ´Ù.
*
* @param {$Element | HTMLElement | String} oElement Ãß°¡ÇÒ HTML ¿¤¸®¸ÕÆ®. ¹®ÀÚ¿, HTML ¿¤¸®¸ÕÆ®, ȤÀº $Element À» ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.<br>
* <br>
* ¸Å°³ º¯¼ö°¡ ¹®ÀÚ¿À̸é ÇØ´ç ¹®ÀÚ¿À» id ·Î ÇÏ´Â HTML ¿¤¸®¸ÕÆ®¸¦ ù ¹øÂ° Àڽijëµå·Î Ãß°¡ÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ HTML ¿¤¸®¸ÕÆ®À̸é ÇØ´ç ¿¤¸®¸ÕÆ®¸¦ ù ¹øÂ° Àڽijëµå·Î Ãß°¡ÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ $Element À̸é $Element °´Ã¼ ³»ºÎÀÇ HTML ¿¤¸®¸ÕÆ®¸¦ ù ¹øÂ° Àڽijëµå·Î Ãß°¡ÇÑ´Ù.
* @return {$Element} $Element °´Ã¼ ÀÚ½Å
*
* @see $Element#append
* @see $Element#before
* @see $Element#after
* @see $Element#appendTo
* @see $Element#prependTo
*
* @example
// id °¡ sample1 ÀÎ HTML ¿¤¸®¸ÕÆ®¿¡¼
// id °¡ sample2 ÀÎ HTML ¿¤¸®¸ÕÆ®¸¦ ù ¹øÂ° Àڽijëµå·Î À̵¿
$Element("sample1").prepend("sample2");
//Before
<div id="sample1">
<div>Hello 1</div>
<div id="sample2">
<div>Hello 2</div>
</div>
</div>
//After
<div id="sample1">
<div id="sample2">
<div>Hello 2</div>
</div>
<div>Hello 1</div>
</div>
* @example
// id °¡ sample ÀÎ HTML ¿¤¸®¸ÕÆ®¿¡
// »õ·Î¿î DIV ¿¤¸®¸ÕÆ®¸¦ Ãß°¡
var elChild = $("<div>Hello New</div>");
$Element("sample").prepend(elChild);
//Before
<div id="sample">
<div>Hello</div>
</div>
//After
<div id="sample">
<div>Hello New</div>
<div>Hello</div>
</div>
*/
jindo.$Element.prototype.prepend = function(oElement) {
return jindo.$Element._prepend(this._element, jindo.$Element(oElement));
};
/**
* $Element °´Ã¼ ³»ºÎÀÇ HTML ¿¤¸®¸ÕÆ®¸¦ ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÑ ¿¤¸®¸ÕÆ®·Î ´ëüÇÑ´Ù.
*
* @param {$Element | HTML Element | String} oElement ´ëüÇÒ HTML ¿¤¸®¸ÕÆ®. ¹®ÀÚ¿, HTML ¿¤¸®¸ÕÆ®, ȤÀº $Element À» ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.<br>
* <br>
* ¸Å°³ º¯¼ö°¡ ¹®ÀÚ¿À̸é ÇØ´ç ¹®ÀÚ¿À» id ·Î ÇÏ´Â HTML ¿¤¸®¸ÕÆ®·Î ´ëüÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ HTML ¿¤¸®¸ÕÆ®À̸é ÇØ´ç ¿¤¸®¸ÕÆ®·Î ´ëüÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ $Element À̸é $Element °´Ã¼ ³»ºÎÀÇ HTML ¿¤¸®¸ÕÆ®·Î ´ëüÇÑ´Ù.
* @return {$Element} HTML ¿¤¸®¸ÕÆ®°¡ ´ëü µÈ $Element °´Ã¼¸¦ ¹Ýȯ
*
* @example
// id °¡ sample1 ÀÎ HTML ¿¤¸®¸ÕÆ®¿¡¼
// id °¡ sample2 ÀÎ HTML ¿¤¸®¸ÕÆ®·Î ´ëü
$Element('sample1').replace('sample2');
//Before
<div>
<div id="sample1">Sample1</div>
</div>
<div id="sample2">Sample2</div>
//After
<div>
<div id="sample2">Sample2</div>
</div>
* @example
// »õ·Î¿î DIV ¿¤¸®¸ÕÆ®·Î ´ëü
$Element("btn").replace($("<div>Sample</div>"));
//Before
<button id="btn">Sample</button>
//After
<div>Sample</div>
*/
jindo.$Element.prototype.replace = function(oElement) {
jindo.$$.release();
var e = this._element;
var oParentNode = e.parentNode;
var o = jindo.$Element(oElement);
if(oParentNode&&oParentNode.replaceChild){
oParentNode.replaceChild(o.$value(),e);
return o;
}
var o = o.$value();
oParentNode.insertBefore(o, e);
oParentNode.removeChild(e);
return o;
};
/**
* HTML ¿¤¸®¸ÕÆ®¸¦ ´Ù¸¥ HTML ¿¤¸®¸ÕÆ®ÀÇ ¸¶Áö¸· Àڽijëµå·Î Ãß°¡ÇÑ´Ù.
*
* @param {$Element | HTML Element | String} oElement ºÎ¸ð°¡ µÉ HTML ¿¤¸®¸ÕÆ®. <br>
* <br>
* ¹®ÀÚ¿, HTML ¿¤¸®¸ÕÆ®, ȤÀº $Element À» ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.<br>
* <br>
* ¸Å°³ º¯¼ö°¡ ¹®ÀÚ¿À̸é ÇØ´ç ¹®ÀÚ¿À» id ·Î ÇÏ´Â HTML ¿¤¸®¸ÕÆ®¸¦ ºÎ¸ð·Î ÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ HTML ¿¤¸®¸ÕÆ®À̸é ÇØ´ç ¿¤¸®¸ÕÆ®¸¦ ºÎ¸ð·Î ÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ $Element À̸é $Element °´Ã¼ ³»ºÎÀÇ HTML ¿¤¸®¸ÕÆ®¸¦ ºÎ¸ð·Î ÇÑ´Ù.
* @return {$Element} ÀÎÀÚ·Î ¹ÞÀº ¿¤¸®¸ÕÆ®
*
* @see $Element#append
* @see $Element#prepend
* @see $Element#after
* @see $Element#appendTo
* @see $Element#prependTo
*
* @example
// id °¡ sample2 ÀÎ HTML ¿¤¸®¸ÕÆ®¿¡
// id °¡ sample1 ÀÎ HTML ¿¤¸®¸ÕÆ®¸¦ Ãß°¡
$Element("sample1").appendTo("sample2");
//Before
<div id="sample1">
<div>Hello 1</div>
</div>
<div id="sample2">
<div>Hello 2</div>
</div>
//After
<div id="sample2">
<div>Hello 2</div>
<div id="sample1">
<div>Hello 1</div>
</div>
</div>
*/
jindo.$Element.prototype.appendTo = function(oElement) {
var ele = jindo.$Element(oElement);
jindo.$Element._append(ele, this._element);
return ele;
};
/**
* HTML ¿¤¸®¸ÕÆ®¸¦ ´Ù¸¥ HTML ¿¤¸®¸ÕÆ®ÀÇ Ã¹ ¹øÂ° Àڽijëµå·Î Ãß°¡ÇÑ´Ù.
*
* @param {$Element | HTML Element | String} oElement ºÎ¸ð°¡ µÉ HTML ¿¤¸®¸ÕÆ®. ¹®ÀÚ¿, HTML ¿¤¸®¸ÕÆ®, ȤÀº $Element À» ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.<br>
* <br>
* ¸Å°³ º¯¼ö°¡ ¹®ÀÚ¿À̸é ÇØ´ç ¹®ÀÚ¿À» id ·Î ÇÏ´Â HTML ¿¤¸®¸ÕÆ®¸¦ ºÎ¸ð·Î ÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ HTML ¿¤¸®¸ÕÆ®À̸é ÇØ´ç ¿¤¸®¸ÕÆ®¸¦ ºÎ¸ð·Î ÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ $Element À̸é $Element °´Ã¼ ³»ºÎÀÇ HTML ¿¤¸®¸ÕÆ®¸¦ ºÎ¸ð·Î ÇÑ´Ù.
* @return {$Element} ÀÎÀÚ·Î ¹ÞÀº ¿¤¸®¸ÕÆ®
*
* @see $Element#append
* @see $Element#prepend
* @see $Element#after
* @see $Element#appendTo
* @see $Element#prependTo
*
* @example
// id °¡ sample2 ÀÎ HTML ¿¤¸®¸ÕÆ®¿¡
// id °¡ sample1 ÀÎ HTML ¿¤¸®¸ÕÆ®¸¦ Ãß°¡
$Element("sample1").prependTo("sample2");
//Before
<div id="sample1">
<div>Hello 1</div>
</div>
<div id="sample2">
<div>Hello 2</div>
</div>
//After
<div id="sample2">
<div id="sample1">
<div>Hello 1</div>
</div>
<div>Hello 2</div>
</div>
*/
jindo.$Element.prototype.prependTo = function(oElement) {
jindo.$Element._prepend(oElement, this);
return jindo.$Element(oElement);
};
/**
* HTML ¿¤¸®¸ÕÆ® ¹Ù·Î ¾Õ¿¡ HTML ¿¤¸®¸ÕÆ®¸¦ Ãß°¡ÇÑ´Ù.
*
* @param {$Element | HTML Element | String} oElement Ãß°¡ÇÒ HTML ¿¤¸®¸ÕÆ®.<br>
* <br>
* ¹®ÀÚ¿, HTML ¿¤¸®¸ÕÆ®, ȤÀº $Element À» ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.<br>
* <br>
* ¸Å°³ º¯¼ö°¡ ¹®ÀÚ¿À̸é ÇØ´ç ¹®ÀÚ¿À» id ·Î ÇÏ´Â HTML ¿¤¸®¸ÕÆ®¸¦ Ãß°¡ÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ HTML ¿¤¸®¸ÕÆ®À̸é ÇØ´ç ¿¤¸®¸ÕÆ®¸¦ Ãß°¡ÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ $Element À̸é $Element °´Ã¼ ³»ºÎÀÇ HTML ¿¤¸®¸ÕÆ®¸¦ Ãß°¡ÇÑ´Ù.
* @return {$Element} Ãß°¡ µÈ $Element °´Ã¼
*
* @see $Element#append
* @see $Element#prepend
* @see $Element#after
* @see $Element#appendTo
* @see $Element#prependTo
*
* @example
// id °¡ sample1 ÀÎ HTML ¿¤¸®¸ÕÆ® ¾Õ¿¡
// id °¡ sample2 ÀÎ HTML ¿¤¸®¸ÕÆ®¸¦ Ãß°¡ ÇÔ
$Element("sample1").before("sample2"); // sample2¸¦ ·¡ÇÎÇÑ $Element ¸¦ ¹Ýȯ
//Before
<div id="sample1">
<div>Hello 1</div>
<div id="sample2">
<div>Hello 2</div>
</div>
</div>
//After
<div id="sample2">
<div>Hello 2</div>
</div>
<div id="sample1">
<div>Hello 1</div>
</div>
* @example
// »õ·Î¿î DIV ¿¤¸®¸ÕÆ®¸¦ Ãß°¡
var elNew = $("<div>Hello New</div>");
$Element("sample").before(elNew); // elNew ¿¤¸®¸ÕÆ®¸¦ ·¡ÇÎÇÑ $Element ¸¦ ¹Ýȯ
//Before
<div id="sample">
<div>Hello</div>
</div>
//After
<div>Hello New</div>
<div id="sample">
<div>Hello</div>
</div>
*/
jindo.$Element.prototype.before = function(oElement) {
var oRich = jindo.$Element(oElement);
var o = oRich.$value();
this._element.parentNode.insertBefore(o, this._element);
return oRich;
};
/**
* HTML ¿¤¸®¸ÕÆ® ¹Ù·Î µÚ¿¡ HTML ¿¤¸®¸ÕÆ®¸¦ Ãß°¡ÇÑ´Ù.
*
* @param {$Element | HTML Element | String} oElement Ãß°¡ÇÒ HTML ¿¤¸®¸ÕÆ®. ¹®ÀÚ¿, HTML ¿¤¸®¸ÕÆ®, ȤÀº $Element À» ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.<br>
* <br>
* ¸Å°³ º¯¼ö°¡ ¹®ÀÚ¿À̸é ÇØ´ç ¹®ÀÚ¿À» id ·Î ÇÏ´Â HTML ¿¤¸®¸ÕÆ®¸¦ Ãß°¡ÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ HTML ¿¤¸®¸ÕÆ®À̸é ÇØ´ç ¿¤¸®¸ÕÆ®¸¦ Ãß°¡ÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ $Element À̸é $Element °´Ã¼ ³»ºÎÀÇ HTML ¿¤¸®¸ÕÆ®¸¦ Ãß°¡ÇÑ´Ù.
* @return {$Element} Ãß°¡ µÈ $Element °´Ã¼
*
* @see $Element#append
* @see $Element#prepend
* @see $Element#before
* @see $Element#appendTo
* @see $Element#prependTo
*
* @example
// id °¡ sample1 ÀÎ HTML ¿¤¸®¸ÕÆ® µÚ¿¡
// id °¡ sample2 ÀÎ HTML ¿¤¸®¸ÕÆ®¸¦ Ãß°¡ ÇÔ
$Element("sample1").after("sample2"); // sample2¸¦ ·¡ÇÎÇÑ $Element ¸¦ ¹Ýȯ
//Before
<div id="sample1">
<div>Hello 1</div>
<div id="sample2">
<div>Hello 2</div>
</div>
</div>
//After
<div id="sample1">
<div>Hello 1</div>
</div>
<div id="sample2">
<div>Hello 2</div>
</div>
* @example
// »õ·Î¿î DIV ¿¤¸®¸ÕÆ®¸¦ Ãß°¡
var elNew = $("<div>Hello New</div>");
$Element("sample").after(elNew); // elNew ¿¤¸®¸ÕÆ®¸¦ ·¡ÇÎÇÑ $Element ¸¦ ¹Ýȯ
//Before
<div id="sample">
<div>Hello</div>
</div>
//After
<div id="sample">
<div>Hello</div>
</div>
<div>Hello New</div>
*/
jindo.$Element.prototype.after = function(oElement) {
var o = this.before(oElement);
o.before(this);
return o;
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ »óÀ§ ¿¤¸®¸ÕÆ® ³ëµå¸¦ °Ë»öÇÑ´Ù.
*
* @param {Function} [pFunc] »óÀ§ ¿¤¸®¸ÕÆ® ³ëµåÀÇ °Ë»ö Á¶°ÇÀ» ÁöÁ¤ÇÑ Äݹé ÇÔ¼ö.<br>
* ¸Å°³ º¯¼ö¸¦ »ý·«ÇÏ¸é ºÎ¸ð ¿¤¸®¸ÕÆ® ³ëµå¸¦ ¹ÝȯÇϰí,<br>
* ¸Å°³ º¯¼ö·Î Äݹé ÇÔ¼ö¸¦ ÁöÁ¤Çϸé Äݹé ÇÔ¼öÀÇ ½ÇÇà °á°ú°¡ true ÀÎ »óÀ§ ¿¤¸®¸ÕÆ® ³ëµåÀÇ ¹è¿À» ¹ÝȯÇÑ´Ù.<br>
* Äݹé ÇÔ¼ö¿¡ ¸Å°³ º¯¼ö·Î Ž»ö ÁßÀÎ »óÀ§ ¿¤¸®¸ÕÆ® ³ëµåÀÇ $Element °´Ã¼¸¦ ³Ñ±ä´Ù.
* @param {Number} [limit] Ž»öÇÒ »óÀ§ ¿¤¸®¸ÕÆ® ³ëµåÀÇ µª½º.<br>
* ¸Å°³ º¯¼ö¸¦ »ý·«ÇÏ¸é ¸ðµç »óÀ§ ¿¤¸®¸ÕÆ® ³ëµå¸¦ Ž»öÇÑ´Ù.<br>
* pFunc ¸Å°³ º¯¼ö¸¦ null·Î ¼³Á¤Çϰí limit ¸Å°³ º¯¼ö¸¦ ¼³Á¤Çϸé Á¦ÇÑµÈ µª½ºÀÇ »óÀ§ ¿¤¸®¸ÕÆ® ³ëµå¸¦ Á¶°Ç ¾øÀÌ °Ë»öÇÑ´Ù.
* @return {$Element | Array} ºÎ¸ð ¿¤¸®¸ÕÆ® ³ëµå ȤÀº »óÀ§ ¿¤¸®¸ÕÆ® ³ëµåÀÇ ¹è¿.<br>
* ¸Å°³ º¯¼ö¸¦ »ý·«ÇÏ¿© ºÎ¸ð ¿¤¸®¸ÕÆ® ³ëµå¸¦ ¹ÝȯÇÏ´Â °æ¿ì, $Element ŸÀÔÀ¸·Î ¹ÝȯÇÑ´Ù.<br>
* ±× À̿ܿ¡´Â °Ë»öµÈ ¿¤¸®¸ÕÆ® ³ëµå¸¦ $ElementÀÇ ¹è¿·Î ¹ÝȯÇÑ´Ù.
*
* @see $Element#child
* @see $Element#prev
* @see $Element#next
* @see $Element#first
* @see $Element#last
* @see $Element#indexOf
*
* @example
<div class="sample" id="div1">
<div id="div2">
<div class="sample" id="div3">
<div id="target">
Sample
<div id="div4">
Sample
</div>
<div class="sample" id="div5">
Sample
</div>
</div>
<div class="sample" id="div6">
Sample
</div>
</div>
</div>
</div>
<script type="text/javascript">
var welTarget = $Element("target");
var parent = welTarget.parent();
// id°¡ div3ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¸¦ ¹Ýȯ
parent = welTarget.parent(function(v){
return v.hasClass("sample");
});
// id°¡ div3ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¿Í
// id°¡ div1ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¸¦ ¿ø¼Ò·Î ÇÏ´Â ¹è¿À» ¹Ýȯ
parent = welTarget.parent(function(v){
return v.hasClass("sample");
}, 1);
// id°¡ div3ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¸¦ ¿ø¼Ò·Î ÇÏ´Â ¹è¿À» ¹Ýȯ
</script>
*/
jindo.$Element.prototype.parent = function(pFunc, limit) {
var e = this._element;
var a = [], p = null;
if (typeof pFunc == "undefined") return jindo.$Element(e.parentNode);
if (typeof limit == "undefined" || limit == 0) limit = -1;
while (e.parentNode && limit-- != 0) {
p = jindo.$Element(e.parentNode);
if (e.parentNode == document.documentElement) break;
if (!pFunc || (pFunc && pFunc(p))) a[a.length] = p;
e = e.parentNode;
}
return a;
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ ÇÏÀ§ ¿¤¸®¸ÕÆ® ³ëµå¸¦ °Ë»öÇÑ´Ù.
*
* @param {Function} [pFunc] ÇÏÀ§ ¿¤¸®¸ÕÆ® ³ëµåÀÇ °Ë»ö Á¶°ÇÀ» ÁöÁ¤ÇÑ Äݹé ÇÔ¼ö.<br>
* ¸Å°³ º¯¼ö¸¦ »ý·«Çϸé ÀÚ½Ä ¿¤¸®¸ÕÆ® ³ëµåÀÇ ¹è¿À» ¹ÝȯÇϰí,<br>
* ¸Å°³ º¯¼ö·Î Äݹé ÇÔ¼ö¸¦ ÁöÁ¤Çϸé Äݹé ÇÔ¼öÀÇ ½ÇÇà °á°ú°¡ true ÀÎ ÇÏÀ§ ¿¤¸®¸ÕÆ® ³ëµåÀÇ ¹è¿À» ¹ÝȯÇÑ´Ù.<br>
* Äݹé ÇÔ¼ö¿¡ ¸Å°³ º¯¼ö·Î Ž»ö ÁßÀÎ ÇÏÀ§ ¿¤¸®¸ÕÆ® ³ëµåÀÇ $Element °´Ã¼¸¦ ³Ñ±ä´Ù.
* @param {Number} [limit] Ž»öÇÒ ÇÏÀ§ ¿¤¸®¸ÕÆ® ³ëµåÀÇ µª½º.<br>
* ¸Å°³ º¯¼ö¸¦ »ý·«ÇÏ¸é ¸ðµç ÇÏÀ§ ¿¤¸®¸ÕÆ® ³ëµå¸¦ Ž»öÇÑ´Ù.<br>
* pFunc ¸Å°³ º¯¼ö¸¦ null·Î ¼³Á¤Çϰí limit ¸Å°³ º¯¼ö¸¦ ¼³Á¤Çϸé Á¦ÇÑµÈ µª½ºÀÇ ÇÏÀ§ ¿¤¸®¸ÕÆ® ³ëµå¸¦ Á¶°Ç ¾øÀÌ °Ë»öÇÑ´Ù.
* @return {$Element | Array} ÀÚ½Ä ¿¤¸®¸ÕÆ® ³ëµå ȤÀº Á¶°Ç¿¡ ¸Â´Â ÇÏÀ§ ³ëµåÀÇ $ElementÀÇ ¹è¿À» ¹ÝȯÇÑ´Ù.
*
* @see $Element#parent
* @see $Element#prev
* @see $Element#next
* @see $Element#first
* @see $Element#last
* @see $Element#indexOf
*
* @example
<div class="sample" id="target">
<div id="div1">
<div class="sample" id="div2">
<div id="div3">
Sample
<div id="div4">
Sample
</div>
<div class="sample" id="div5">
Sample
<div class="sample" id="div6">
Sample
</div>
</div>
</div>
</div>
</div>
<div class="sample" id="div7">
Sample
</div>
</div>
<script type="text/javascript">
var welTarget = $Element("target");
var child = welTarget.child();
// id°¡ div1ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¿Í
// id°¡ div7ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¸¦ ¿ø¼Ò·Î ÇÏ´Â ¹è¿À» ¹Ýȯ
child = welTarget.child(function(v){
return v.hasClass("sample");
});
// id°¡ div2ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¿Í
// id°¡ div5ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¿Í
// id°¡ div6ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¿Í
// id°¡ div7ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¸¦ ¿ø¼Ò·Î ÇÏ´Â ¹è¿À» ¹Ýȯ
child = welTarget.child(function(v){
return v.hasClass("sample");
}, 1);
// id°¡ div7ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¸¦ ¿ø¼Ò·Î ÇÏ´Â ¹è¿À» ¹Ýȯ
child = welTarget.child(function(v){
return v.hasClass("sample");
}, 2);
// id°¡ div2ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¿Í
// id°¡ div7ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¸¦ ¿ø¼Ò·Î ÇÏ´Â ¹è¿À» ¹Ýȯ
</script>
*/
jindo.$Element.prototype.child = function(pFunc, limit) {
var e = this._element;
var a = [], c = null, f = null;
if (typeof pFunc == "undefined") return jindo.$A(e.childNodes).filter(function(v){ return v.nodeType == 1}).map(function(v){ return jindo.$Element(v) }).$value();
if (typeof limit == "undefined" || limit == 0) limit = -1;
(f = function(el, lim){
var ch = null, o = null;
for(var i=0; i < el.childNodes.length; i++) {
ch = el.childNodes[i];
if (ch.nodeType != 1) continue;
o = jindo.$Element(el.childNodes[i]);
if (!pFunc || (pFunc && pFunc(o))) a[a.length] = o;
if (lim != 0) f(el.childNodes[i], lim-1);
}
})(e, limit-1);
return a;
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ ÀÌÀü¿¡ ³ª¿À´Â ÇüÁ¦ ¿¤¸®¸ÕÆ® ³ëµå¸¦ °Ë»öÇÑ´Ù.
*
* @param {Function} [pFunc] ÀÌÀü ÇüÁ¦ ¿¤¸®¸ÕÆ® ³ëµåÀÇ °Ë»ö Á¶°ÇÀ» ÁöÁ¤ÇÑ Äݹé ÇÔ¼ö.<br>
* ¸Å°³ º¯¼ö¸¦ »ý·«ÇÏ¸é ¹Ù·Î ÀÌÀüÀÇ ÇüÁ¦ ¿¤¸®¸ÕÆ® ³ëµå¸¦ ¹ÝȯÇϰí,<br>
* ¸Å°³ º¯¼ö·Î Äݹé ÇÔ¼ö¸¦ ÁöÁ¤Çϸé Äݹé ÇÔ¼öÀÇ ½ÇÇà °á°ú°¡ true ÀÎ ÇüÁ¦ ¿¤¸®¸ÕÆ® ³ëµåÀÇ ¹è¿À» ¹ÝȯÇÑ´Ù.<br>
* Äݹé ÇÔ¼ö¿¡ ¸Å°³ º¯¼ö·Î Ž»ö ÁßÀÎ ÇüÁ¦ ¿¤¸®¸ÕÆ® ³ëµå¸¦ ³Ñ±ä´Ù. ($Element °´Ã¼°¡ ¾Æ´Ô)
* @return {$Element | Array} ¹Ù·Î ÀüÀÇ ÇüÁ¦ ¿¤¸®¸ÕÆ® ³ëµå¸¦ °¡¸®Å°´Â $Element ȤÀº Á¶°Ç¿¡ ¸Â´Â ÇüÁ¦ ³ëµåÀÇ $ElementÀÇ ¹è¿À» ¹ÝȯÇÑ´Ù.
*
* @see $Element#parent
* @see $Element#child
* @see $Element#next
* @see $Element#first
* @see $Element#last
* @see $Element#indexOf
*
* @example
<div class="sample" id="sample_div1">
<div id="sample_div2">
<div class="sample" id="sample_div3">
Sample1
</div>
<div id="sample_div4">
Sample2
</div>
<div class="sample" id="sample_div5">
Sample3
</div>
<div id="sample_div">
Sample4
<div id="sample_div6">
Sample5
</div>
</div>
<div id="sample_div7">
Sample6
</div>
<div class="sample" id="sample_div8">
Sample7
</div>
</div>
</div>
<script type="text/javascript">
var sibling = $Element("sample_div").prev();
// id°¡ sample_div5ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¸¦ ¹Ýȯ
sibling = $Element("sample_div").prev(function(v){
return $Element(v).hasClass("sample");
});
// id°¡ sample_div5ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¿Í
// id°¡ sample_div3ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¸¦ ¿ø¼Ò·Î ÇÏ´Â ¹è¿À» ¹Ýȯ
</script>
*/
jindo.$Element.prototype.prev = function(pFunc) {
var e = this._element;
var a = [];
var b = (typeof pFunc == "undefined");
if (!e) return b?jindo.$Element(null):a;
do {
e = e.previousSibling;
if (!e || e.nodeType != 1) continue;
if (b) return jindo.$Element(e);
if (!pFunc || pFunc(e)) a[a.length] = jindo.$Element(e);
} while(e);
return b?jindo.$Element(e):a;
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ ´ÙÀ½¿¡ ³ª¿À´Â ÇüÁ¦ ¿¤¸®¸ÕÆ® ³ëµå¸¦ °Ë»öÇÑ´Ù.
*
* @param {Function} [pFunc] ´ÙÀ½ ÇüÁ¦ ¿¤¸®¸ÕÆ® ³ëµåÀÇ °Ë»ö Á¶°ÇÀ» ÁöÁ¤ÇÑ Äݹé ÇÔ¼ö.<br>
* ¸Å°³ º¯¼ö¸¦ »ý·«ÇÏ¸é ¹Ù·Î ´ÙÀ½ÀÇ ÇüÁ¦ ¿¤¸®¸ÕÆ® ³ëµå¸¦ ¹ÝȯÇϰí,<br>
* ¸Å°³ º¯¼ö·Î Äݹé ÇÔ¼ö¸¦ ÁöÁ¤Çϸé Äݹé ÇÔ¼öÀÇ ½ÇÇà °á°ú°¡ true ÀÎ ÇüÁ¦ ¿¤¸®¸ÕÆ® ³ëµåÀÇ ¹è¿À» ¹ÝȯÇÑ´Ù.<br>
* Äݹé ÇÔ¼ö¿¡ ¸Å°³ º¯¼ö·Î Ž»ö ÁßÀÎ ÇüÁ¦ ¿¤¸®¸ÕÆ® ³ëµå¸¦ ³Ñ±ä´Ù. ($Element °´Ã¼°¡ ¾Æ´Ô)
* @return {$Element | Array} ¹Ù·Î ´ÙÀ½ÀÇ ÇüÁ¦ ¿¤¸®¸ÕÆ® ³ëµå¸¦ °¡¸®Å°´Â $Element ȤÀº Á¶°Ç¿¡ ¸Â´Â ÇüÁ¦ ³ëµåÀÇ $ElementÀÇ ¹è¿À» ¹ÝȯÇÑ´Ù.
*
* @see $Element#parent
* @see $Element#child
* @see $Element#prev
* @see $Element#first
* @see $Element#last
* @see $Element#indexOf
*
* @example
<div class="sample" id="sample_div1">
<div id="sample_div2">
<div class="sample" id="sample_div3">
Sample1
</div>
<div id="sample_div4">
Sample2
</div>
<div class="sample" id="sample_div5">
Sample3
</div>
<div id="sample_div">
Sample4
<div id="sample_div6">
Sample5
</div>
</div>
<div id="sample_div7">
Sample6
</div>
<div class="sample" id="sample_div8">
Sample7
</div>
</div>
</div>
<script type="text/javascript">
var sibling = $Element("sample_div").next();
// id°¡ sample_div7ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¸¦ ¹Ýȯ
sibling = $Element("sample_div").next(function(v){
return $Element(v).hasClass("sample");
});
// id°¡ sample_div8ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¸¦ ¿ø¼Ò·Î ÇÏ´Â ¹è¿À» ¹Ýȯ
</script>
*/
jindo.$Element.prototype.next = function(pFunc) {
var e = this._element;
var a = [];
var b = (typeof pFunc == "undefined");
if (!e) return b?jindo.$Element(null):a;
do {
e = e.nextSibling;
if (!e || e.nodeType != 1) continue;
if (b) return jindo.$Element(e);
if (!pFunc || pFunc(e)) a[a.length] = jindo.$Element(e);
} while(e);
return b?jindo.$Element(e):a;
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ Ã¹ ¹øÂ° ÀÚ½Ä ¿¤¸®¸ÕÆ® ³ëµå¸¦ ¹ÝȯÇÑ´Ù.
*
* @return {$Element} ù ¹øÂ° ÀÚ½Ä ¿¤¸®¸ÕÆ® ³ëµå
* @since 1.2.0
*
* @see $Element#parent
* @see $Element#child
* @see $Element#prev
* @see $Element#next
* @see $Element#last
* @see $Element#indexOf
*
* @example
<div id="sample_div1">
<div id="sample_div2">
<div id="sample_div">
Sample1
<div id="sample_div3">
<div id="sample_div4">
Sample2
</div>
Sample3
</div>
<div id="sample_div5">
Sample4
<div id="sample_div6">
Sample5
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var firstChild = $Element("sample_div").first();
// id°¡ sample_div3ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¸¦ ¹Ýȯ
</script>
*/
jindo.$Element.prototype.first = function() {
var el = this._element.firstElementChild||this._element.firstChild;
if (!el) return null;
while(el && el.nodeType != 1) el = el.nextSibling;
return el?jindo.$Element(el):null;
}
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ ¸¶Áö¸· ÀÚ½Ä ¿¤¸®¸ÕÆ® ³ëµå¸¦ ¹ÝȯÇÑ´Ù.
*
* @return {$Element} ¸¶Áö¸· ÀÚ½Ä ¿¤¸®¸ÕÆ® ³ëµå
* @since 1.2.0
*
* @see $Element#parent
* @see $Element#child
* @see $Element#prev
* @see $Element#next
* @see $Element#first
* @see $Element#indexOf
*
* @example
<div id="sample_div1">
<div id="sample_div2">
<div id="sample_div">
Sample1
<div id="sample_div3">
<div id="sample_div4">
Sample2
</div>
Sample3
</div>
<div id="sample_div5">
Sample4
<div id="sample_div6">
Sample5
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var lastChild = $Element("sample_div").last();
// id°¡ sample_div5ÀÎ DIV¸¦ ·¡ÇÎÇÑ $Element¸¦ ¹Ýȯ
</script>
*/
jindo.$Element.prototype.last = function() {
var el = this._element.lastElementChild||this._element.lastChild;
if (!el) return null;
while(el && el.nodeType != 1) el = el.previousSibling;
return el?jindo.$Element(el):null;
}
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ ºÎ¸ð ¿¤¸®¸ÕÆ® ³ëµå¸¦ È®ÀÎÇÑ´Ù.
*
* @param {HTML Element | String | $Element} element ºÎ¸ð ³ëµåÀÎÁö È®ÀÎÇÒ HTML ¿¤¸®¸ÕÆ®.<br>
* <br>
* ¹®ÀÚ¿, HTML ¿¤¸®¸ÕÆ®, ȤÀº $Element À» ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.<br>
* <br>
* ¸Å°³ º¯¼ö°¡ ¹®ÀÚ¿À̸é ÇØ´ç ¹®ÀÚ¿À» id ·Î ÇÏ´Â HTML ¿¤¸®¸ÕÆ®¸¦ È®ÀÎÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ HTML ¿¤¸®¸ÕÆ®À̸é ÇØ´ç ¿¤¸®¸ÕÆ®¸¦ È®ÀÎÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ $Element À̸é $Element °´Ã¼ ³»ºÎÀÇ HTML ¿¤¸®¸ÕÆ®¸¦ È®ÀÎÇÑ´Ù.
* @return {Boolean} ¸Å°³ º¯¼ö°¡ ºÎ¸ð ¿¤¸®¸ÕÆ® ³ëµåÀ̸é true ¸¦, ±×·¸Áö ¾ÊÀ¸¸é false ¸¦ ¹ÝȯÇÑ´Ù.
*
* @see $Element#isParentOf
*
* @example
<div id="parent">
<div id="child">
<div id="grandchild"></div>
</div>
</div>
<div id="others"></div>
...
// ºÎ¸ð/ÀÚ½Ä È®ÀÎÇϱâ
$Element("child").isChildOf("parent"); // °á°ú : true
$Element("others").isChildOf("parent"); // °á°ú : false
$Element("grandchild").isChildOf("parent"); // °á°ú : true
*/
jindo.$Element.prototype.isChildOf = function(element) {
return jindo.$Element._contain(jindo.$Element(element).$value(),this._element);
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ ÀÚ½Ä ¿¤¸®¸ÕÆ® ³ëµå¸¦ È®ÀÎÇÑ´Ù.
*
* @param {HTML Element | String | $Element} element ÀÚ½Ä ³ëµåÀÎÁö È®ÀÎÇÒ HTML ¿¤¸®¸ÕÆ®. ¹®ÀÚ¿, HTML ¿¤¸®¸ÕÆ®, ȤÀº $Element À» ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù°¡¸Å°³ º¯¼ö°¡ ¹®ÀÚ¿À̸é ÇØ´ç ¹®ÀÚ¿À» id ·Î ÇÏ´Â HTML ¿¤¸®¸ÕÆ®¸¦ È®ÀÎÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ HTML ¿¤¸®¸ÕÆ®À̸é ÇØ´ç ¿¤¸®¸ÕÆ®¸¦ È®ÀÎÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ $Element À̸é $Element °´Ã¼ ³»ºÎÀÇ HTML ¿¤¸®¸ÕÆ®¸¦ È®ÀÎÇÑ´Ù.
* @return {Boolean} ¸Å°³ º¯¼ö°¡ ÀÚ½Ä ¿¤¸®¸ÕÆ® ³ëµåÀ̸é true ¸¦, ±×·¸Áö ¾ÊÀ¸¸é false ¸¦ ¹ÝȯÇÑ´Ù.
*
* @see $Element#isChildOf
*
* @example
<div id="parent">
<div id="child"></div>
</div>
<div id="others"></div>
...
// ºÎ¸ð/ÀÚ½Ä È®ÀÎÇϱâ
$Element("parent").isParentOf("child"); // °á°ú : true
$Element("others").isParentOf("child"); // °á°ú : false
$Element("parent").isParentOf("grandchild");// °á°ú : true
*/
jindo.$Element.prototype.isParentOf = function(element) {
return jindo.$Element._contain(this._element, jindo.$Element(element).$value());
};
/**
* isChildOf , isParentOfÀÇ ±âº»ÀÌ µÇ´Â API(IE¿¡¼´Â contains,±âŸ ºê¶ó¿ìÁ®¿¡´Â compareDocumentPositionÀ» »ç¿ëÇÏ°í µÑ´Ù ¾ø´Â °æ¿ì´Â ±âÁ¸ ·¹°Å½Ã API»ç¿ë.)
* @param {HTMLElement} eParent ºÎ¸ð³ëµå
* @param {HTMLElement} eChild Àڽijëµå
* @ignore
*/
jindo.$Element._contain = function(eParent,eChild){
if (document.compareDocumentPosition) {
jindo.$Element._contain = function(eParent,eChild){
return !!(eParent.compareDocumentPosition(eChild)&16);
}
}else if(document.body.contains){
jindo.$Element._contain = function(eParent,eChild){
return (eParent !== eChild)&&(eParent.contains ? eParent.contains(eChild) : true);
}
}else{
jindo.$Element._contain = function(eParent,eChild){
var e = eParent;
var el = eChild;
while(e && e.parentNode) {
e = e.parentNode;
if (e == el) return true;
}
return false;
}
}
return jindo.$Element._contain(eParent,eChild);
}
/**
* ÇöÀçÀÇ HTML ¿¤¸®¸ÕÆ®¿Í µ¿ÀÏÇÑ ¿¤¸®¸ÕÆ®ÀÎÁö È®ÀÎÇÑ´Ù.
*
* @remark DOM3ÀÇ APIÁß isSameNode¿Í °°Àº ÇÔ¼ö·Î ·¹ÆÛ·±½º±îÁö È®ÀÎ ÇÔ¼öÀÌ´Ù.
* @remark isEqualNode¿Í´Â ´Ù¸¥ ÇÔ¼öÀ̱⠶§¹®¿¡ Çò°¥¸®Áö ¾Êµµ·Ï ÇÑ´Ù.
*
* @param {HTML Element | String | $Element} element °°Àº HTML ¿¤¸®¸ÕÆ®ÀÎÁö È®ÀÎÇÒ HTML ¿¤¸®¸ÕÆ®. ¹®ÀÚ¿, HTML ¿¤¸®¸ÕÆ®, ȤÀº $Element À» ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.<br>
* <br>
* ¸Å°³ º¯¼ö°¡ ¹®ÀÚ¿À̸é ÇØ´ç ¹®ÀÚ¿À» id ·Î ÇÏ´Â HTML ¿¤¸®¸ÕÆ®¸¦ È®ÀÎÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ HTML ¿¤¸®¸ÕÆ®À̸é ÇØ´ç ¿¤¸®¸ÕÆ®¸¦ È®ÀÎÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ $Element À̸é $Element °´Ã¼ ³»ºÎÀÇ HTML ¿¤¸®¸ÕÆ®¸¦ È®ÀÎÇÑ´Ù.
* @return {Boolean} ¸Å°³ º¯¼ö°¡ °°Àº HTML ¿¤¸®¸ÕÆ®À̸é true ¸¦, ±×·¸Áö ¾ÊÀ¸¸é false ¸¦ ¹ÝȯÇÑ´Ù.
*
* @example
<div id="sample1"><span>Sample</span></div>
<div id="sample2"><span>Sample</span></div>
...
// °°Àº HTML ¿¤¸®¸ÕÆ®ÀÎÁö È®ÀÎ
var welSpan1 = $Element("sample1").first(); // <span>Sample</span>
var welSpan2 = $Element("sample2").first(); // <span>Sample</span>
welSpan1.isEqual(welSpan2); // °á°ú : false
welSpan1.isEqual(welSpan1); // °á°ú : true
*/
jindo.$Element.prototype.isEqual = function(element) {
try {
return (this._element === jindo.$Element(element).$value());
} catch(e) {
return false;
}
};
/**
* HTML ¿¤¸®¸ÕÆ®¿¡ À̺¥Æ®¸¦ ¹ß»ý½ÃŲ´Ù.
*
* @param {String} sEvent ½ÇÇàÇÒ À̺¥Æ® À̸§. on Á¢µÎ»ç´Â »ý·«ÇÑ´Ù.
* @param {Object} [oProps] À̺¥Æ® ½ÇÇà ½Ã »ç¿ëÇÒ À̺¥Æ® °´Ã¼ÀÇ ¼Ó¼ºÀ» ÁöÁ¤ÇÑ´Ù.
* @return {$Element} À̺¥Æ®°¡ ¹ß»ýÇÑ HTML ¿¤¸®¸ÕÆ®
*
* @since WebKit °è¿¿¡¼´Â À̺¥Æ® °´Ã¼ÀÇ keyCode °¡ read-only ÀÎ °ü°è·Î key À̺¥Æ®¸¦ ¹ß»ý½Ãų °æ¿ì keyCode °ªÀÌ ¼³Á¤µÇÁö ¾Ê´Â´Ù. 1.4.1 ºÎÅÍ keyCode °ªÀ» ¼³Á¤ÇÒ ¼ö ÀÖ´Ù.
*
* @example
$Element("div").fireEvent("click", {left : true, middle : false, right : false}); // click À̺¥Æ® ¹ß»ý
$Element("div").fireEvent("mouseover", {screenX : 50, screenY : 50, clientX : 50, clientY : 50}); // mouseover À̺¥Æ® ¹ß»ý
$Element("div").fireEvent("keydown", {keyCode : 13, alt : true, shift : false ,meta : false, ctrl : true}); // keydown À̺¥Æ® ¹ß»ý
*/
jindo.$Element.prototype.fireEvent = function(sEvent, oProps) {
function IE(sEvent, oProps) {
sEvent = (sEvent+"").toLowerCase();
var oEvent = document.createEventObject();
if(oProps){
for (k in oProps){
if(oProps.hasOwnProperty(k))
oEvent[k] = oProps[k];
}
oEvent.button = (oProps.left?1:0)+(oProps.middle?4:0)+(oProps.right?2:0);
oEvent.relatedTarget = oProps.relatedElement||null;
}
this._element.fireEvent("on"+sEvent, oEvent);
return this;
};
function DOM2(sEvent, oProps) {
var sType = "HTMLEvents";
sEvent = (sEvent+"").toLowerCase();
if (sEvent == "click" || sEvent.indexOf("mouse") == 0) {
sType = "MouseEvent";
if (sEvent == "mousewheel") sEvent = "dommousescroll";
} else if (sEvent.indexOf("key") == 0) {
sType = "KeyboardEvent";
}
var evt;
if (oProps) {
oProps.button = 0 + (oProps.middle?1:0) + (oProps.right?2:0);
oProps.ctrl = oProps.ctrl||false;
oProps.alt = oProps.alt||false;
oProps.shift = oProps.shift||false;
oProps.meta = oProps.meta||false;
switch (sType) {
case 'MouseEvent':
evt = document.createEvent(sType);
evt.initMouseEvent( sEvent, true, true, null, oProps.detail||0, oProps.screenX||0, oProps.screenY||0, oProps.clientX||0, oProps.clientY||0,
oProps.ctrl, oProps.alt, oProps.shift, oProps.meta, oProps.button, oProps.relatedElement||null);
break;
case 'KeyboardEvent':
if (window.KeyEvent) {
evt = document.createEvent('KeyEvents');
evt.initKeyEvent(sEvent, true, true, window, oProps.ctrl, oProps.alt, oProps.shift, oProps.meta, oProps.keyCode, oProps.keyCode);
} else {
try {
evt = document.createEvent("Events");
} catch (e){
evt = document.createEvent("UIEvents");
} finally {
evt.initEvent(sEvent, true, true);
evt.ctrlKey = oProps.ctrl;
evt.altKey = oProps.alt;
evt.shiftKey = oProps.shift;
evt.metaKey = oProps.meta;
evt.keyCode = oProps.keyCode;
evt.which = oProps.keyCode;
}
}
break;
default:
evt = document.createEvent(sType);
evt.initEvent(sEvent, true, true);
}
}else{
evt = document.createEvent(sType);
evt.initEvent(sEvent, true, true);
}
this._element.dispatchEvent(evt);
return this;
};
jindo.$Element.prototype.fireEvent = (typeof this._element.dispatchEvent != "undefined")?DOM2:IE;
return this.fireEvent(sEvent, oProps);
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ ÀÚ½Ä ³ëµå¸¦ ¸ðµÎ Á¦°ÅÇÑ´Ù.
*
* @return {$Element} ÀÚ½Ä ³ëµå¸¦ ¸ðµÎ Á¦°ÅÇÑ ÇöÀçÀÇ $Element °´Ã¼
*
* @see $Element#leave
* @see $Element#remove
*
* @example
// ÀÚ½Ä ³ëµå¸¦ ¸ðµÎ Á¦°Å
$Element("sample").empty();
//Before
<div id="sample"><span>³ëµå</span> <span>¸ðµÎ</span> »èÁ¦Çϱâ </div>
//After
<div id="sample"></div>
*/
jindo.$Element.prototype.empty = function() {
jindo.$$.release();
this.html("");
return this;
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ Æ¯Á¤ ÀÚ½Ä ³ëµå¸¦ Á¦°ÅÇÑ´Ù. Á¦°ÅµÇ´Â ÀÚ½Ä ¿¤¸®¸ÕÆ® ³ëµåÀÇ À̺¥Æ® Çڵ鷯µµ Á¦°ÅÇÑ´Ù.
*
* @param {HTML Element | String | $Element} oChild Á¦°ÅÇÒ ÀÚ½Ä ¿¤¸®¸ÕÆ® ³ëµå.<br>
* <br>
* ¹®ÀÚ¿, HTML ¿¤¸®¸ÕÆ®, ȤÀº $Element À» ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.<br>
* <br>
* ¸Å°³ º¯¼ö°¡ ¹®ÀÚ¿À̸é ÇØ´ç ¹®ÀÚ¿À» id ·Î ÇÏ´Â HTML ¿¤¸®¸ÕÆ®¸¦ Á¦°ÅÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ HTML ¿¤¸®¸ÕÆ®À̸é ÇØ´ç ¿¤¸®¸ÕÆ®¸¦ Á¦°ÅÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ $Element À̸é $Element °´Ã¼ ³»ºÎÀÇ HTML ¿¤¸®¸ÕÆ®¸¦ Á¦°ÅÇÑ´Ù.
* @return {$Element} ÀÚ½Ä ³ëµå¸¦ ¸ðµÎ Á¦°ÅÇÑ ÇöÀçÀÇ $Element °´Ã¼
*
* @see $Element#empty
* @see $Element#leave
*
* @example
// ƯÁ¤ ÀÚ½Ä ³ëµå¸¦ Á¦°Å
$Element("sample").remove("child2");
//Before
<div id="sample"><span id="child1">³ëµå</span> <span id="child2">»èÁ¦Çϱâ</span></div>
//After
<div id="sample"><span id="child1">³ëµå</span> </div>
*/
jindo.$Element.prototype.remove = function(oChild) {
jindo.$$.release();
jindo.$Element(oChild).leave();
return this;
}
/**
* HTML ¿¤¸®¸ÕÆ®¸¦ ºÎ¸ð ¿¤¸®¸ÕÆ® ³ëµå¿¡¼ Á¦°ÅÇÑ´Ù.<br>
* HTML ¿¤·¯¸ÕÆ®¿¡ µî·ÏµÈ À̺¥Æ® Çڵ鷯µµ Á¦°ÅÇÑ´Ù.
*
* @return {$Element} ºÎ¸ð ¿¤¸®¸ÕÆ® ³ëµå¿¡¼ Á¦°Å µÈ ÇöÀçÀÇ $Element °´Ã¼
*
* @see $Element#empty
* @see $Element#remove
*
* @example
// ºÎ¸ð ¿¤¸®¸ÕÆ® ³ëµå¿¡¼ Á¦°Å
$Element("sample").leave();
//Before
<div>
<div id="sample"><span>³ëµå</span> <span>¸ðµÎ</span> »èÁ¦Çϱâ </div>
</div>
//After
// <div id="sample"><span>³ëµå</span> <span>¸ðµÎ</span> »èÁ¦Çϱâ </div>¸¦ ·¡ÇÎÇÑ $Element°¡ ¹ÝȯµÈ´Ù
<div>
</div>
*/
jindo.$Element.prototype.leave = function() {
var e = this._element;
if (e.parentNode) {
jindo.$$.release();
e.parentNode.removeChild(e);
}
jindo.$Fn.freeElement(this._element);
return this;
};
/**
* HTML ¿¤¸®¸ÕÆ®¸¦ ´Ù¸¥ HTML ¿¤¸®¸ÕÆ®·Î °¨½Ñ´Ù.
*
* @param {String | HTML Element | $Element} wrapper °¨½Ò HTML ¿¤¸®¸ÕÆ®. ¹®ÀÚ¿, HTML ¿¤¸®¸ÕÆ®, ȤÀº $Element À» ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.<br>
* <br>
* ¸Å°³ º¯¼ö°¡ ¹®ÀÚ¿À̸é ÇØ´ç ¹®ÀÚ¿À» id ·Î ÇÏ´Â HTML ¿¤¸®¸ÕÆ®¸¦ »ç¿ëÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ HTML ¿¤¸®¸ÕÆ®À̸é ÇØ´ç ¿¤¸®¸ÕÆ®¸¦ »ç¿ëÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ $Element À̸é $Element °´Ã¼ ³»ºÎÀÇ HTML ¿¤¸®¸ÕÆ®¸¦ »ç¿ëÇÑ´Ù.
* @return {$Element} »õ·Î¿î HTML ¿¤¸®¸ÕÆ®·Î °¨½Ñ $Element °³Ã¼
*
* @example
$Element("sample1").wrap("sample2");
//Before
<div id="sample1"><span>Sample</span></div>
<div id="sample2"><span>Sample</span></div>
//After
<div id="sample2"><span>Sample</span><div id="sample1"><span>Sample</span></div></div>
* @example
$Element("box").wrap($('<DIV>'));
//Before
<span id="box"></span>
//After
<div><span id="box"></span></div>
*/
jindo.$Element.prototype.wrap = function(wrapper) {
var e = this._element;
wrapper = jindo.$Element(wrapper).$value();
if (e.parentNode) {
e.parentNode.insertBefore(wrapper, e);
}
wrapper.appendChild(e);
return this;
};
/**
* HTML ¿¤¸®¸ÕÆ®ÀÇ ÅØ½ºÆ® ³ëµå°¡ ºê¶ó¿ìÀú¿¡¼ ÇÑ ÁÙ·Î º¸À̵µ·Ï ±æÀ̸¦ Á¶ÀýÇÑ´Ù.
*
* @remark ÀÌ ¸Þ¼µå´Â HTML ¿¤¸®¸ÕÆ®°¡ ÅØ½ºÆ® ³ëµå¸¸À» Æ÷ÇÔÇÑ´Ù°í °¡Á¤ÇÑ´Ù. µû¶ó¼, ÀÌ ¿ÜÀÇ »óȲ¿¡¼ÀÇ µ¿ÀÛÀº º¸ÀåÇÏÁö ¾Ê´Â´Ù.
* @remark ºê¶ó¿ìÀú¿¡¼ÀÇ HTML ¿¤¸®¸ÕÆ®ÀÇ ³Êºñ¸¦ ±âÁØÀ¸·Î ÅØ½ºÆ® ³ëµåÀÇ ±æÀ̸¦ Á¤ÇϹǷΠHTML ¿¤¸®¸ÕÆ®´Â ¹Ýµå½Ã º¸ÀÌ´Â »óÅ¿©¾ß ÇÑ´Ù.
* @remark ȸ鿡 Àüü ÅØ½ºÆ® ³ëµå°¡ º¸¿´´Ù°¡ ÁÙ¾îµå´Â °æ¿ì°¡ ÀÖ´Ù. ÀÌ·± °æ¿ì, HTML ¿¤¸®¸ÕÆ®¿¡¼ overflow:hidden ¼Ó¼ºÀ» Ȱ¿ëÇÑ´Ù.
*
* @param {String} [stringTail] ¸»ÁÙÀÓ Ç¥½ÃÀÚ. <br>
* ¸Å°³ º¯¼ö¿¡ ÁöÁ¤ÇÑ ¹®ÀÚ¿À» ÅØ½ºÆ® ³ëµå ¸Ç ³¡¿¡ ºÙÀ̰í ÅØ½ºÆ® ³ëµåÀÇ ±æÀ̸¦ Á¶ÀýÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö¸¦ »ý¶ôÇÏ¸é ¸»ÁÙÀÓÇ¥('...')¸¦ »ç¿ëÇÑ´Ù.
*
* @example
$Element("sample_span").ellipsis();
//Before
<div style="width:300px; border:1px solid #CCCCCC; padding:10px">
<span id="sample_span">NHNÀº °Ë»ö°ú °ÔÀÓÀ» ¾çÃàÀ¸·Î Çõ½ÅÀûÀÌ°í Æí¸®ÇÑ ¿Â¶óÀÎ ¼ºñ½º¸¦ ²ÙÁØÈ÷ ¼±º¸ÀÌ¸ç µðÁöÅÐ ¶óÀÌÇÁ¸¦ ¼±µµÇϰí ÀÖ½À´Ï´Ù.</span>
</div>
//After
<div style="width:300px; border:1px solid #CCCCCC; padding:10px">
<span id="sample_span">NHNÀº °Ë»ö°ú °ÔÀÓÀ» ¾çÃàÀ¸·Î Çõ½ÅÀû...</span>
</div>
*/
jindo.$Element.prototype.ellipsis = function(stringTail) {
stringTail = stringTail || "...";
var txt = this.text();
var len = txt.length;
var padding = parseInt(this.css("paddingTop"),10) + parseInt(this.css("paddingBottom"),10);
var cur_h = this.height() - padding;
var i = 0;
var h = this.text('A').height() - padding;
if (cur_h < h * 1.5) return this.text(txt);
cur_h = h;
while(cur_h < h * 1.5) {
i += Math.max(Math.ceil((len - i)/2), 1);
cur_h = this.text(txt.substring(0,i)+stringTail).height() - padding;
}
while(cur_h > h * 1.5) {
i--;
cur_h = this.text(txt.substring(0,i)+stringTail).height() - padding;
}
};
/**
* HTML ¿¤¸®¸ÕÆ®¿¡¼ ¸Å°³ º¯¼ö°¡ ¸î ¹øÂ° ÀÚ½Ä ¿¤¸®¸ÕÆ® ³ëµåÀÎÁö È®ÀÎÇÏ¿© À妽º¸¦ ¹ÝȯÇÑ´Ù.
*
* @param {String | HTML Element | $Element} element È®ÀÎÇÒ HTML ¿¤¸®¸ÕÆ®. ¹®ÀÚ¿, HTML ¿¤¸®¸ÕÆ®, ȤÀº $Element À» ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.<br>
* <br>
* ¸Å°³ º¯¼ö°¡ ¹®ÀÚ¿À̸é ÇØ´ç ¹®ÀÚ¿À» id ·Î ÇÏ´Â HTML ¿¤¸®¸ÕÆ®¸¦ »ç¿ëÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ HTML ¿¤¸®¸ÕÆ®À̸é ÇØ´ç ¿¤¸®¸ÕÆ®¸¦ »ç¿ëÇÑ´Ù.<br>
* ¸Å°³ º¯¼ö°¡ $Element À̸é $Element °´Ã¼ ³»ºÎÀÇ HTML ¿¤¸®¸ÕÆ®¸¦ »ç¿ëÇÑ´Ù.
* @return {Number} °Ë»ö °á°ú À妽º.<br>
* À妽º´Â 0 ºÎÅÍ ½ÃÀÛÇϸç, ãÁö ¸øÇÑ °æ¿ì¿¡´Â -1 À» ¹ÝȯÇÑ´Ù.
*
* @since 1.2.0
*
* @see $Element#parent
* @see $Element#child
* @see $Element#prev
* @see $Element#next
* @see $Element#first
* @see $Element#last
*
* @example
<div id="sample_div1">
<div id="sample_div">
<div id="sample_div2">
Sample1
</div>
<div id="sample_div3">
<div id="sample_div4">
Sample2
</div>
Sample3
</div>
<div id="sample_div5">
Sample4
<div id="sample_div6">
Sample5
</div>
</div>
</div>
</div>
<script type="text/javascript">
var welSample = $Element("sample_div");
welSample.indexOf($Element("sample_div1")); // °á°ú : -1
welSample.indexOf($Element("sample_div2")); // °á°ú : 0
welSample.indexOf($Element("sample_div3")); // °á°ú : 1
welSample.indexOf($Element("sample_div4")); // °á°ú : -1
welSample.indexOf($Element("sample_div5")); // °á°ú : 2
welSample.indexOf($Element("sample_div6")); // °á°ú : -1
</script>
*/
jindo.$Element.prototype.indexOf = function(element) {
try {
var e = jindo.$Element(element).$value();
var n = this._element.childNodes;
var c = 0;
var l = n.length;
for (var i=0; i < l; i++) {
if (n[i].nodeType != 1) continue;
if (n[i] === e) return c;
c++;
}
}catch(e){}
return -1;
};
/**
* HTML ¿¤¸®¸ÕÆ®¿¡¼ ƯÁ¤ CSS ¼¿·ºÅÍ(selector)¸¦ ¸¸Á·ÇÏ´Â ÇÏÀ§ ¿¤¸®¸ÕÆ® ³ëµå¸¦ ã´Â´Ù.
*
* @param {String} sSelector CSS ¼¿·ºÅÍ
* @return {Array} CSS ¼¿·ºÅÍ Á¶°ÇÀ» ¸¸Á·ÇÏ´Â HTML ¿¤¸®¸ÕÆ®ÀÇ ¹è¿À» ¹ÝȯÇÑ´Ù.<br>
* ¸¸Á·ÇÏ´Â HTML ¿¤¸®¸ÕÆ®°¡ Á¸ÀçÇÏÁö ¾ÊÀ¸¸é ºó ¹è¿À» ¹ÝȯÇÑ´Ù.
*
* @see $Element#query
* @see $Element#queryAll
*
* @example
<div id="sample">
<div></div>
<div class="pink"></div>
<div></div>
<div class="pink"></div>
<div></div>
<div class="blue"></div>
<div class="blue"></div>
</div>
<script type="text/javascript">
$Element("sample").queryAll(".pink");
// <div class="pink"></div>¿Í <div class="pink"></div>¸¦ ¿ø¼Ò·Î ÇÏ´Â ¹è¿À» ¹Ýȯ
$Element("sample").queryAll(".green");
// [] ºó ¹è¿À» ¹Ýȯ
</script>
*/
jindo.$Element.prototype.queryAll = function(sSelector) {
return jindo.$$(sSelector, this._element);
};
/**
* HTML ¿¤¸®¸ÕÆ®¿¡¼ ƯÁ¤ CSS ¼¿·ºÅÍ(selector)¸¦ ¸¸Á·Çϴ ù ¹øÂ° ÇÏÀ§ ¿¤¸®¸ÕÆ® ³ëµå¸¦ ¹ÝȯÇÑ´Ù.
*
* @param {String} sSelector CSS ¼¿·ºÅÍ
* @return {HTML Element} CSS ¼¿·ºÅÍ Á¶°ÇÀ» ¸¸Á·Çϴ ù ¹øÂ° HTML ¿¤¸®¸ÕÆ®.<br>
* ¸¸Á·ÇÏ´Â HTML ¿¤¸®¸ÕÆ®°¡ Á¸ÀçÇÏÁö ¾ÊÀ¸¸é null À» ¹ÝȯÇÑ´Ù.
*
* @see $Element#test
* @see $Element#queryAll
*
* @example
<div id="sample">
<div></div>
<div class="pink"></div>
<div></div>
<div class="pink"></div>
<div></div>
<div class="blue"></div>
<div class="blue"></div>
</div>
<script type="text/javascript">
$Element("sample").query(".pink");
// ù ¹øÂ° <div class="pink"></div> DIV ¿¤¸®¸ÕÆ®¸¦ ¹Ýȯ
$Element("sample").query(".green");
// null À» ¹Ýȯ
</script>
*/
jindo.$Element.prototype.query = function(sSelector) {
return jindo.$$.getSingle(sSelector, this._element);
};
/**
* HTML ¿¤¸®¸ÕÆ®¿¡¼ ƯÁ¤ CSS ¼¿·ºÅÍ(selector)¸¦ ¸¸Á·ÇÏ´ÂÁö È®ÀÎÇÑ´Ù.
*
* @param {String} sSelector CSS ¼¿·ºÅÍ
* @return {Boolean} CSS ¼¿·ºÅÍ Á¶°ÇÀ» ¸¸Á·ÇÏ´ÂÁö È®ÀÎÇÏ¿© true/false ·Î ¹ÝȯÇÑ´Ù.
*
* @see $Element#query
* @see $Element#queryAll
*
* @example
<div id="sample" class="blue"></div>
<script type="text/javascript">
$Element("sample").test(".blue"); // °á°ú : true
$Element("sample").test(".red"); // °á°ú : false
</script>
*/
jindo.$Element.prototype.test = function(sSelector) {
return jindo.$$.test(this._element, sSelector);
};
/**
* HTML ¿¤¸®¸ÕÆ®¸¦ ±âÁØÀ¸·Î XPath ¹®¹ýÀ» »ç¿ëÇÏ¿© ÇØ´çÇÏ´Â HTML ¿¤¸®¸ÕÆ®¸¦ °¡Á®¿Â´Ù.
*
* @remark Áö¿øÇÏ´Â ¹®¹ýÀÌ ¹«Ã´ Á¦ÇÑÀûÀ¸·Î Ư¼öÇÑ °æ¿ì¿¡¼¸¸ »ç¿ëÇÏ´Â °ÍÀ» ±ÇÀåÇÑ´Ù.
*
* @param {String} sXPath XPath ¹®¹ý
* @return {Array} XPath ¿¡ ÇØ´çÇÏ´Â HTML ¿¤¸®¸ÕÆ®¸¦ ¿ø¼Ò·Î ÇÏ´Â ¹è¿À» ¹ÝȯÇÑ´Ù.
*
* @example
<div id="sample">
<div>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
</div>
<script type="text/javascript">
$Element("sample").xpathAll("div/div[5]");
// <div>5</div> ¿¤¸®¸ÕÆ®¸¦ ¿ø¼Ò·Î ÇÏ´Â ¹è¿ÀÌ ¹Ýȯ µÊ
</script>
*/
jindo.$Element.prototype.xpathAll = function(sXPath) {
return jindo.$$.xpath(sXPath, this._element);
};
/**
* insertAdjacentHTML ÇÔ¼ö. Á÷Á¢»ç¿ëÇÏÁö ¸øÇÔ.
* @ignore
*/
jindo.$Element.insertAdjacentHTML = function(ins,html,insertType,type,fn){
var _ele = ins._element;
if( _ele.insertAdjacentHTML && !(/^<(option|tr|td|th|col)(?:.*?)>/.test(html.replace(/^(\s|¡¡)+|(\s|¡¡)+$/g, "").toLowerCase()))){
_ele.insertAdjacentHTML(insertType, html);
}else{
var oDoc = _ele.ownerDocument || _ele.document || document;
var fragment = oDoc.createDocumentFragment();
var defaultElement;
var sTag = html.replace(/^(\s|¡¡)+|(\s|¡¡)+$/g, "");
var oParentTag = {
"option" : "select",
"tr" : "tbody",
"thead" : "table",
"tbody" : "table",
"col" : "table",
"td" : "tr",
"th" : "tr",
"div" : "div"
}
var aMatch = /^\<(option|tr|thead|tbody|td|th|col)(?:.*?)\>/i.exec(sTag);
var sChild = aMatch === null ? "div" : aMatch[1].toLowerCase();
var sParent = oParentTag[sChild] ;
defaultElement = jindo._createEle(sParent,sTag,oDoc,true);
var scripts = defaultElement.getElementsByTagName("script");
for ( var i = 0, l = scripts.length; i < l; i++ ){
scripts[i].parentNode.removeChild( scripts[i] );
}
while ( defaultElement[ type ]){
fragment.appendChild( defaultElement[ type ] );
}
fn(fragment.cloneNode(true));
}
return ins;
}
/**
* HTML ¿¤¸®¸ÕÆ® ³»ºÎ HTML ÀÇ °¡Àå µÚ¿¡ HTML À» µ¡ºÙÀδÙ.
*
* @param {String} sHTML µ¡ºÙÀÏ HTML ¹®ÀÚ¿
* @return {$Element} 1.4.8ºÎÅÍ ³»ºÎ HTML À» º¯°æÇÑ ÇöÀçÀÇ $Element °´Ã¼¸¦ ¹ÝȯÇÑ´Ù.
* @since 1.4.6 ºÎÅÍ »ç¿ë °¡´É.
* @since 1.4.8 ºÎÅÍ $Element °´Ã¼¸¦ ¹ÝȯÇÑ´Ù.
* @see $Element#prependHTML
* @see $Element#beforeHTML
* @see $Element#afterHTML
*
* @example
// ³»ºÎ HTML °¡Àå µÚ¿¡ µ¡ºÙÀ̱â
$Element("sample_ul").appendHTML("<li>3</li><li>4</li>");
//Before
<ul id="sample_ul">
<li>1</li>
<li>2</li>
</ul>
//After
<ul id="sample_ul">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
*/
jindo.$Element.prototype.appendHTML = function(sHTML) {
return jindo.$Element.insertAdjacentHTML(this,sHTML,"beforeEnd","firstChild",jindo.$Fn(function(oEle){
this.append(oEle);
},this).bind());
};
/**
* HTML ¿¤¸®¸ÕÆ® ³»ºÎ HTML ÀÇ °¡Àå ¾Õ¿¡ HTML À» »ðÀÔÇÑ´Ù.
*
* @param {String} sHTML »ðÀÔÇÒ HTML ¹®ÀÚ¿
* @return {$Element} 1.4.8ºÎÅÍ ³»ºÎ HTML À» º¯°æÇÑ ÇöÀçÀÇ $Element °´Ã¼¸¦ ¹ÝȯÇÑ´Ù.
* @since 1.4.6ºÎÅÍ »ç¿ë °¡´É.
* @see $Element#appendHTML
* @see $Element#beforeHTML
* @see $Element#afterHTML
*
* @example
// ³»ºÎ HTML °¡Àå ¾Õ¿¡ »ðÀÔ
$Element("sample_ul").prependHTML("<li>3</li><li>4</li>");
//Before
<ul id="sample_ul">
<li>1</li>
<li>2</li>
</ul>
//After
<ul id="sample_ul">
<li>4</li>
<li>3</li>
<li>1</li>
<li>2</li>
</ul>
*/
jindo.$Element.prototype.prependHTML = function(sHTML) {
return jindo.$Element.insertAdjacentHTML(this,sHTML,"afterBegin","lastChild",jindo.$Fn(function(oEle){
this.prepend(oEle);
},this).bind());
};
/**
* HTML ¿¤¸®¸ÕÆ® ¾Õ¿¡ HTML À» »ðÀÔÇÑ´Ù.
*
* @param {String} sHTML »ðÀÔÇÒ HTML ¹®ÀÚ¿
* @return {$Element} 1.4.8ºÎÅÍ ÇöÀçÀÇ $Element °´Ã¼¸¦ ¹ÝȯÇÑ´Ù.
* @since 1.4.6ºÎÅÍ »ç¿ë °¡´É.
* @see $Element#appendHTML
* @see $Element#prependHTML
* @see $Element#afterHTML
*
* @example
var welSample = $Element("sample_ul");
welSample.beforeHTML("<ul><li>3</li><li>4</li></ul>");
welSample.beforeHTML("<ul><li>5</li><li>6</li></ul>");
//Before
<ul id="sample_ul">
<li>1</li>
<li>2</li>
</ul>
//After
<ul>
<li>3</li>
<li>4</li>
</ul>
<ul>
<li>5</li>
<li>6</li>
</ul>
<ul id="sample_ul">
<li>1</li>
<li>2</li>
</ul>
*/
jindo.$Element.prototype.beforeHTML = function(sHTML) {
return jindo.$Element.insertAdjacentHTML(this,sHTML,"beforeBegin","firstChild",jindo.$Fn(function(oEle){
this.before(oEle);
},this).bind());
};
/**
* HTML ¿¤¸®¸ÕÆ® µÚ¿¡ HTML À» µ¡ºÙÀδÙ.
* @param {String} sHTML µ¡ºÙÀÏ HTML ¹®ÀÚ¿
* @returns {$Element} 1.4.8ºÎÅÍ ÇöÀçÀÇ $Element °´Ã¼¸¦ ¹ÝȯÇÑ´Ù.
* @since 1.4.6ºÎÅÍ »ç¿ë °¡´É.
* @see $Element#appendHTML
* @see $Element#prependHTML
* @see $Element#beforeHTML
* @example
var welSample = $Element("sample_ul");
welSample.beforeHTML("<ul><li>3</li><li>4</li></ul>");
welSample.beforeHTML("<ul><li>5</li><li>6</li></ul>");
//Before
<ul id="sample_ul">
<li>1</li>
<li>2</li>
</ul>
//After
<ul id="sample_ul">
<li>1</li>
<li>2</li>
</ul>
<ul>
<li>5</li>
<li>6</li>
</ul>
<ul>
<li>3</li>
<li>4</li>
</ul>
*/
jindo.$Element.prototype.afterHTML = function(sHTML) {
return jindo.$Element.insertAdjacentHTML(this,sHTML,"afterEnd","lastChild",jindo.$Fn(function(oEle){
this._element.parentNode.insertBefore( oEle, this._element.nextSibling );
},this).bind());
};
/**
* À̺¥Æ® µ¨¸®°ÔÀ̼ÇÀ¸·Î À̺¥Æ®¸¦ ó¸®ÇÑ´Ù.<br>
* À̺¥Æ® µ¨¸®°ÔÀ̼ÇÀ̶õ À̺¥Æ® ¹öºí¸µÀ» ÀÌ¿ëÇÏ¿© È¿À²ÀûÀ¸·Î À̺¥Æ®¸¦ °ü¸®ÇÏ´Â ¹æ¹ýÀÌ´Ù.<br>
* ÀÚ¼¼ÇÑ ³»¿ëÀº ¾Æ·¡ÀÇ URLÀ» Âü°íÇÑ´Ù.<br>
* <br>
*
* <ul>
* <li><a href="http://devcode.nhncorp.com/projects/jindo/wiki/EventDelegate" target="_blank">Event Delegate ¶õ?</a></li>
* <ul>
*
* @param {String} sEvent À̺¥Æ® À̸§. on Á¢µÎ»ç´Â »ý·«ÇÑ´Ù.<br>
* domready, mousewheel, mouseenter, mouseleave Àº Áö¿øÇÏÁö ¾Ê´Â´Ù.<br>
*
* @param {String | Function} vFilter ¿øÇÏ´Â HTML ¿¤¸®¸ÕÆ®¿¡ ´ëÇØ¼¸¸ À̺¥Æ®¸¦ ½ÇÇàÇϵµ·Ï Çϱâ À§ÇÑ ÇÊÅÍÀÌ´Ù.<br>
* <br>
* ÇÊÅÍ¿¡´Â CSS ¼¿·ºÅÍ¿Í ÇÔ¼öÀÇ µÎ °¡Áö ŸÀÔÀÌ ÀÖ´Ù.<br>
* <br>
* ÇÊÅ͸¦ CSS ¼¿·ºÅ͸¦ »ç¿ëÇÏ·Á¸é ¹®ÀÚ¿À» ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÑ´Ù.<br>
* <br>
* ÇÊÅ͸¦ ÇÔ¼ö·Î »ç¿ëÇÏ·Á¸é Boolean À» ¹ÝȯÇÏ´Â ÇÔ¼ö¸¦ ¸Å°³ º¯¼ö·Î ÁöÁ¤ÇÑ´Ù.<br>
* ÇÊÅÍ ÇÔ¼öÀÇ Ã¹ ¹øÂ° ¸Å°³ º¯¼ö´Â HTML ¿¤¸®¸ÕÆ® ÀÚ½ÅÀ̰í, µÎ ¹øÂ° ¸Å°³ º¯¼ö´Â À̺¥Æ®°¡ ¹ß»ýÇÑ HTML ¿¤¸®¸ÕÆ®ÀÌ´Ù.
*
* @param {Function} fpCallback ÇÊÅÍ¿¡¼ true °¡ ¹ÝȯµÈ °æ¿ì ½ÇÇàµÇ´Â Äݹé ÇÔ¼öÀÌ´Ù.<br>
* ¸Å°³ º¯¼ö·Î À̺¥Æ® °´Ã¼°¡ ÁöÁ¤µÈ´Ù.
*
* @return {$Element} $Element °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @since 1.4.6ºÎÅÍ »ç¿ë °¡´É.
* @see $Element#undelegate
*
* @example
<ul id="parent">
<li class="odd">1</li>
<li>2</li>
<li class="odd">3</li>
<li>4</li>
</ul>
// CSS ¼¿·ºÅ͸¦ ÇÊÅÍ·Î »ç¿ëÇÏ´Â °æ¿ì
$Element("parent").delegate("click",
".odd", // ÇÊÅÍ
function(eEvent){ // Äݹé ÇÔ¼ö
alert("odd Ŭ·¡½º¸¦ °¡Áø li°¡ Ŭ¸¯ µÉ ¶§ ½ÇÇà");
});
* @example
<ul id="parent">
<li class="odd">1</li>
<li>2</li>
<li class="odd">3</li>
<li>4</li>
</ul>
// ÇÔ¼ö¸¦ ÇÊÅÍ·Î »ç¿ëÇÏ´Â °æ¿ì
$Element("parent").delegate("click",
function(oEle,oClickEle){ // ÇÊÅÍ
return oClickEle.innerHTML == "2"
},
function(eEvent){ // Äݹé ÇÔ¼ö
alert("Ŭ¸¯ÇÑ ¿¤¸®¸ÕÆ®ÀÇ innerHTMLÀÌ 2ÀÎ °æ¿ì¿¡ ½ÇÇà");
});
*/
jindo.$Element.prototype.delegate = function(sEvent , vFilter , fpCallback){
if(!this._element["_delegate_"+sEvent]){
this._element["_delegate_"+sEvent] = {};
var fAroundFunc = jindo.$Fn(function(sEvent,wEvent){
wEvent = wEvent || window.event;
if (typeof wEvent.currentTarget == "undefined") {
wEvent.currentTarget = this._element;
}
var oEle = wEvent.target || wEvent.srcElement;
var aData = this._element["_delegate_"+sEvent];
var data,func,event,resultFilter;
for(var i in aData){
data = aData[i];
resultFilter = data.checker(oEle);
if(resultFilter[0]){
func = data.func;
event = jindo.$Event(wEvent);
event.element = resultFilter[1];
for(var j = 0, l = func.length ; j < l ;j++){
func[j](event);
}
}
}
},this).bind(sEvent);
jindo.$Element._eventBind(this._element,sEvent,fAroundFunc);
var oEle = this._element;
oEle["_delegate_"+sEvent+"_func"] = fAroundFunc;
if (this._element["_delegate_events"]) {
this._element["_delegate_events"].push(sEvent);
}else{
this._element["_delegate_events"] = [sEvent];
}
oEle = null;
}
this._bind(sEvent,vFilter,fpCallback);
return this;
}
/**
* À̺¥Æ®¸¦ ¹ÙÀεù ÇÏ´Â ÇÔ¼ö.
* @param {Element} oEle ¿¤¸®¸ÕÆ®
* @param {Boolean} sEvent À̺¥Æ® ŸÀÔ.
* @param {Function} fAroundFunc ¹ÙÀεùÇÒ ÇÔ¼ö
* @ignore.
*/
jindo.$Element._eventBind = function(oEle,sEvent,fAroundFunc){
if(oEle.addEventListener){
jindo.$Element._eventBind = function(oEle,sEvent,fAroundFunc){
oEle.addEventListener(sEvent,fAroundFunc,false);
}
}else{
jindo.$Element._eventBind = function(oEle,sEvent,fAroundFunc){
oEle.attachEvent("on"+sEvent,fAroundFunc);
}
}
jindo.$Element._eventBind(oEle,sEvent,fAroundFunc);
}
/**
* HTML ¿¤¸®¸ÕÆ®¿¡ µî·ÏµÈ À̺¥Æ® µ¨¸®°ÔÀ̼ÇÀ» ÇØÁ¦ÇÑ´Ù.
*
* @param {String} sEvent À̺¥µå µ¨¸®°ÔÀÌ¼Ç µî·Ï ½Ã »ç¿ëÇÑ À̺¥Æ® À̸§. on Á¢µÎ»ç´Â »ý·«ÇÑ´Ù.
* @param {String|Function} vFilter À̺¥Æ® µ¨¸®°ÔÀÌ¼Ç µî·Ï ½Ã »ç¿ëÇÑ ÇÊÅÍ.
* @param {Function} fpCallback À̺¥Æ® µ¨¸®°ÔÀÌ¼Ç µî·Ï ½Ã »ç¿ëÇÑ Äݹé ÇÔ¼ö.
* @return {$Element} $Element °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @since 1.4.6ºÎÅÍ »ç¿ë °¡´É.
* @see $Element#delegate
*
* @example
<ul id="parent">
<li class="odd">1</li>
<li>2</li>
<li class="odd">3</li>
<li>4</li>
</ul>
// Äݹé ÇÔ¼ö
var fnOddClass = function(eEvent){
alert("odd Ŭ·¡½º¸¦ °¡Áø li°¡ Ŭ¸¯ µÉ ¶§ ½ÇÇà");
};
$Element("parent").delegate("click", ".odd", fnOddClass); // À̺¥Æ® µ¨¸®°ÔÀÌ¼Ç »ç¿ë
$Element("parent").undelegate("click", ".odd", fnOddClass); // À̺¥Æ® ÇØÁ¦
*/
jindo.$Element.prototype.undelegate = function(sEvent, vFilter, fpCallback){
this._unbind(sEvent,vFilter,fpCallback);
return this;
}
/**
* µô¸®°ÔÀ̼ÇÀ¸·Î ½ÇÇàµÇ¾î¾ß ÇÒ ÇÔ¼ö¸¦ Ãß°¡ ÇÏ´Â ÇÔ¼ö.
* @param {String} sEvent À̺¥Æ® ŸÀÔ.
* @param {String|Function} vFilter cssquery,function ÀÌ·¸°Ô 2°¡Áö ŸÀÔÀÌ µé¾î¿È.
* @param {Function} fpCallback ÇØ´ç cChecker¿¡ µé¾î¿À´Â ÇÔ¼ö°¡ ¸ÂÀ»¶§ ½ÇÇàµÇ´Â ÇÔ¼ö.
* @returns {$Element} $Element °´Ã¼.
* @since 1.4.6ºÎÅÍ »ç¿ë°¡´É.
* @ignore
*/
jindo.$Element.prototype._bind = function(sEvent,vFilter,fpCallback){
var _aDataOfEvent = this._element["_delegate_"+sEvent];
if(_aDataOfEvent){
var fpCheck;
if(typeof vFilter == "string"){
fpCheck = jindo.$Fn(function(sCssquery,oEle){
var eIncludeEle = oEle;
var isIncludeEle = jindo.$$.test(oEle, sCssquery);
if(!isIncludeEle){
var aPropagationElements = this._getParent(oEle);
for(var i = 0, leng = aPropagationElements.length ; i < leng ; i++){
eIncludeEle = aPropagationElements[i];
if(jindo.$$.test(eIncludeEle, sCssquery)){
isIncludeEle = true;
break;
}
}
}
return [isIncludeEle,eIncludeEle];
},this).bind(vFilter);
}else if(typeof vFilter == "function"){
fpCheck = jindo.$Fn(function(fpFilter,oEle){
var eIncludeEle = oEle;
var isIncludeEle = fpFilter(this._element,oEle);
if(!isIncludeEle){
var aPropagationElements = this._getParent(oEle);
for(var i = 0, leng = aPropagationElements.length ; i < leng ; i++){
eIncludeEle = aPropagationElements[i];
if(fpFilter(this._element,eIncludeEle)){
isIncludeEle = true;
break;
}
}
}
return [isIncludeEle,eIncludeEle];
},this).bind(vFilter);
}
this._element["_delegate_"+sEvent] = jindo.$Element._addBind(_aDataOfEvent,vFilter,fpCallback,fpCheck);
}else{
alert("check your delegate event.");
}
}
/**
* ÆÄ¶ó¸ÞÅÍ·Î µé¾î¿À´Â ¿¤¸®¸ÕÆ® ºÎÅÍ ÀÚ½ÅÀÇ ¿¤¸®¸ÕÆ® ±îÁöÀÇ ¿¤¸®¸ÕÆ®¸¦ ±¸ÇÏ´Â ÇÔ¼ö.
* @param {Element} ¿¤¸®¸ÕÆ®.
* @returns {Array} ¹è¿ °´Ã¼.
* @ignore
*/
jindo.$Element.prototype._getParent = function(oEle) {
var e = this._element;
var a = [], p = null;
while (oEle.parentNode && p != e) {
p = oEle.parentNode;
if (p == document.documentElement) break;
a[a.length] = p;
oEle = p;
}
return a;
};
/**
* ¿¤¸®¸ÕÆ®¿¡ À̺¥Æ®¸¦ Ãß°¡ÇÏ´Â ÇÔ¼ö.
* @param {Object} aDataOfEvent À̺¥Æ®¿Í ÇÔ¼ö¸¦ °¡Áö°í ÀÖ´Â ¿ÀºêÁ§Æ®.
* @param {String|Function} vFilter cssquery,checkÇÏ´Â ÇÔ¼ö.
* @param {Function} fpCallback ½ÇÇàµÉ ÇÔ¼ö.
* @param {Function} fpCheck üũÇÏ´Â ÇÔ¼ö.
* @retruns {Object} aDataOfEvent¸¦ ¹Ýȯ.
* @ignore
*/
jindo.$Element._addBind = function(aDataOfEvent,vFilter,fpCallback,fpCheck){
var aEvent = aDataOfEvent[vFilter];
if(aEvent){
var fpFuncs = aEvent.func;
fpFuncs.push(fpCallback);
aEvent.func = fpFuncs;
}else{
aEvent = {
checker : fpCheck,
func : [fpCallback]
};
}
aDataOfEvent[vFilter] = aEvent
return aDataOfEvent;
}
/**
* µô¸®°ÔÀ̼ǿ¡¼ ÇØÁ¦µÇ¾î¾ß ÇÒ ÇÔ¼ö¸¦ »èÁ¦ÇÏ´Â ÇÔ¼ö.
* @param {String} sEvent À̺¥Æ® ŸÀÔ.
* @param {String|Function} vFilter cssquery,function ÀÌ·¸°Ô 2°¡Áö ŸÀÔÀÌ µé¾î¿È.
* @param {Function} fpCallback ÇØ´ç cChecker¿¡ µé¾î¿À´Â ÇÔ¼ö°¡ ¸ÂÀ»¶§ ½ÇÇàµÇ´Â ÇÔ¼ö.
* @returns {$Element} $Element °´Ã¼.
* @since 1.4.6ºÎÅÍ »ç¿ë°¡´É.
* @ignore
*/
jindo.$Element.prototype._unbind = function(sEvent, vFilter,fpCallback){
var oEle = this._element;
if (sEvent&&vFilter&&fpCallback) {
var oEventInfo = oEle["_delegate_"+sEvent];
if(oEventInfo&&oEventInfo[vFilter]){
var fpFuncs = oEventInfo[vFilter].func;
fpFuncs = oEventInfo[vFilter].func = jindo.$A(fpFuncs).refuse(fpCallback).$value();
if (!fpFuncs.length) {
jindo.$Element._deleteFilter(oEle,sEvent,vFilter);
}
}
}else if (sEvent&&vFilter) {
jindo.$Element._deleteFilter(oEle,sEvent,vFilter);
}else if (sEvent) {
jindo.$Element._deleteEvent(oEle,sEvent,vFilter);
}else{
var aEvents = oEle['_delegate_events'];
var sEachEvent;
for(var i = 0 , l = aEvents.length ; i < l ; i++){
sEachEvent = aEvents[i];
jindo.$Element._unEventBind(oEle,sEachEvent,oEle["_delegate_"+sEachEvent+"_func"]);
jindo.$Element._delDelegateInfo(oEle,"_delegate_"+sEachEvent);
jindo.$Element._delDelegateInfo(oEle,"_delegate_"+sEachEvent+"_func");
}
jindo.$Element._delDelegateInfo(oEle,"_delegate_events");
}
return this;
}
/**
* ¿ÀºêÁ§Æ®¿¡ ۰ªÀ¸·Î Á¤º¸»èÁ¦ÇÏ´Â ÇÔ¼ö
* @param {Object} »èÁ¦ÇÒ ¿ÀºêÁ§Æ®.
* @param {String|Function} sType ۰ªÀÌ µé¾î¿È.
* @returns {Object} »èÁ¦µÈ ¿ÀºêÁ§Æ®.
* @since 1.4.6ºÎÅÍ »ç¿ë°¡´É.
* @ignore
*/
jindo.$Element._delDelegateInfo = function(oObj , sType){
try{
oObj[sType] = null;
delete oObj[sType];
}catch(e){}
return oObj
}
/**
* ÇÃÅÍ ±âÁØÀ¸·Î »èÁ¦ÇÏ´Â ÇÔ¼ö.
* @param {Element} »èÁ¦ÇÒ ¿¤¸®¸ÕÆ®.
* @param {String} À̺¥Æ®¸í.
* @param {String|Function} cssquery, ÇÊÅÍÇÏ´Â ÇÔ¼ö.
* @since 1.4.6ºÎÅÍ »ç¿ë°¡´É.
* @ignore
*/
jindo.$Element._deleteFilter = function(oEle,sEvent,vFilter){
var oEventInfo = oEle["_delegate_"+sEvent];
if(oEventInfo&&oEventInfo[vFilter]){
if (jindo.$H(oEventInfo).keys().length == 1) {
jindo.$Element._deleteEvent(oEle,sEvent,vFilter);
}else{
jindo.$Element._delDelegateInfo(oEventInfo,vFilter);
}
}
}
/**
* event ±âÁØÀ¸·Î »èÁ¦ÇÏ´Â ÇÔ¼ö.
* @param {Element} »èÁ¦ÇÒ ¿¤¸®¸ÕÆ®.
* @param {String} À̺¥Æ®¸í.
* @param {String|Function} cssquery, ÇÊÅÍÇÏ´Â ÇÔ¼ö.
* @since 1.4.6ºÎÅÍ »ç¿ë°¡´É.
* @ignore
*/
jindo.$Element._deleteEvent = function(oEle,sEvent,vFilter){
var aEvents = oEle['_delegate_events'];
jindo.$Element._unEventBind(oEle,sEvent,oEle["_delegate_"+sEvent+"_func"]);
jindo.$Element._delDelegateInfo(oEle,"_delegate_"+sEvent);
jindo.$Element._delDelegateInfo(oEle,"_delegate_"+sEvent+"_func");
aEvents = jindo.$A(aEvents).refuse(sEvent).$value();
if (!aEvents.length) {
jindo.$Element._delDelegateInfo(oEle,"_delegate_events");
}else{
oEle['_delegate_events'] = jindo.$A(aEvents).refuse(sEvent).$value();
}
}
/**
* À̺¥Æ®¸¦ ÇØÁ¦ ÇÏ´Â ÇÔ¼ö.
* @param {Element} oEle ¿¤¸®¸ÕÆ®
* @param {Boolean} sType À̺¥Æ® ŸÀÔ.
* @param {Function} fAroundFunc ¹ÙÀεùÀ» ÇØÁ¦ÇÒ ÇÔ¼ö.
* @ignore
*/
jindo.$Element._unEventBind = function(oEle,sType,fAroundFunc){
if(oEle.removeEventListener){
jindo.$Element._unEventBind = function(oEle,sType,fAroundFunc){
oEle.removeEventListener(sType,fAroundFunc,false);
}
}else{
jindo.$Element._unEventBind = function(oEle,sType,fAroundFunc){
oEle.detachEvent("on"+sType,fAroundFunc);
}
}
jindo.$Element._unEventBind(oEle,sType,fAroundFunc);
}
/**
* @fileOverview $FnÀÇ »ý¼ºÀÚ ¹× ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name function.js
*/
/**
* $Fn °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @extends core
* @class $Fn Ŭ·¡½º´Â ÀÚ¹Ù½ºÅ©¸³Æ® Function °´Ã¼ÀÇ ·¡ÆÛ(Wrapper) Ŭ·¡½ºÀÌ´Ù.
* @constructor
* @param {Function | String} func
* <br>
* Function °´Ã¼ ȤÀº ÇÔ¼öÀÇ ¸Å°³º¯¼ö¸¦ ³ªÅ¸³»´Â ¹®ÀÚ¿
* @param {Object | String} thisObject
* <br>
* ÇÔ¼ö°¡ ƯÁ¤ °´Ã¼ÀÇ ¸Þ¼µåÀÏ ¶§, ÇØ´ç °´Ã¼µµ °°ÀÌ Àü´ÞÇÑ´Ù. ȤÀº ÇÔ¼öÀÇ ¸öü¸¦ ³ªÅ¸³»´Â ¹®ÀÚ¿.
* @return {$Fn} $Fn °´Ã¼
* @see $Fn#toFunction
* @description [Lite]
* @example
func : function() {
// code here
}
var fn = $Fn(func, this);
* @example
var someObject = {
func : function() {
// code here
}
}
var fn = $Fn(someObject.func, someObject);
* @example
var fn = $Fn("a, b", "return a + b;");
var result = fn.$value()(1, 2) // result = 3;
// fnÀº ÇÔ¼ö ¸®ÅÍ·²ÀÎ function(a, b){ return a + b;}¿Í µ¿ÀÏÇÑ ÇÔ¼ö¸¦ ·¡ÇÎÇÑ´Ù.
* @author Kim, Taegon
*/
jindo.$Fn = function(func, thisObject) {
var cl = arguments.callee;
if (func instanceof cl) return func;
if (!(this instanceof cl)) return new cl(func, thisObject);
this._events = [];
this._tmpElm = null;
this._key = null;
if (typeof func == "function") {
this._func = func;
this._this = thisObject;
} else if (typeof func == "string" && typeof thisObject == "string") {
//this._func = new Function(func, thisObject);
this._func = eval("false||function("+func+"){"+thisObject+"}")
}
}
/**
* userAgent cache
* @ignore
*/
var _ua = navigator.userAgent;
/**
* $value ¸Þ¼µå´Â ¿ø·¡ÀÇ Function °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @return {Function} ÇÔ¼ö °´Ã¼
* @description [Lite]
* @example
func : function() {
// code here
}
var fn = $Fn(func, this);
fn.$value(); // ¿ø·¡ÀÇ ÇÔ¼ö°¡ ¸®ÅϵȴÙ.
*/
jindo.$Fn.prototype.$value = function() {
return this._func;
};
/**
* bind ¸Þ¼µå´Â ÇÔ¼ö°¡ °´Ã¼ÀÇ ¸Þ¼Òµå·Î µ¿ÀÛÇϵµ·Ï ¹ÀÎ Function °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @return {Function} thisObjectÀÇ ¸Þ¼Òµå·Î ¹ÀÎ Function °´Ã¼
* @description [Lite]
* @example
var sName = "OUT";
var oThis = {
sName : "IN"
};
function getName() {
return this.sName;
}
oThis.getName = $Fn(getName, oThis).bind();
alert( getName() ); // OUT
alert( oThis.getName() ); // IN
* @example
// ÇÔ¼ö¸¦ ¹Ì¸® ¼±¾ðÇÏ°í ³ªÁß¿¡ »ç¿ëÇÒ ¶§,
// ÇÔ¼ö¿¡¼ ÂüÁ¶ ÇÏ´Â °ªµéÀº ÇØ´ç ÇÔ¼ö¸¦ »ý¼º ÇÒ¶§ÀÇ °ªÀÌ ¾Æ´Ï¶ó ÇÔ¼ö ½ÇÇà ½ÃÁ¡ÀÇ °ªÀÌ »ç¿ë µÇ¹Ç·Î À̶§ bind¸¦ ÀÌ¿ëÇÑ´Ù.
for(var i=0; i<2;i++){
aTmp[i] = function(){alert(i);}
}
for(var n=0; n<2;n++){
aTmp[n](); // ¼ýÀÚ 2¸¸ µÎ¹ø alertµÈ´Ù.
}
for(var i=0; i<2;i++){
aTmp[i] = $Fn(function(nTest){alert(nTest);}, this).bind(i);
}
for(var n=0; n<2;n++){
aTmp[n](); // ¼ýÀÚ 0, 1ÀÌ alertµÈ´Ù.
}
* @example
//Ŭ·¡½º »ý¼º ½Ã ÇÔ¼ö¸¦ ¸Å°³º¯¼ö·Î ÇÒ ¶§, scope¸¦ ¸ÂÃçÁÖ±â À§ÇØ bind¸¦ »ç¿ëÇÑ´Ù.
var MyClass = $Class({
fFunc : null,
$init : function(func){
this.fFunc = func;
this.testFunc();
},
testFunc : function(){
this.fFunc();
}
})
var MainClass = $Class({
$init : function(){
var oMyClass1 = new MyClass(this.func1);
var oMyClass2 = new MyClass($Fn(this.func2, this).bind());
},
func1 : function(){
alert(this);// this´Â MyClass ¸¦ ÀǹÌÇÑ´Ù.
},
func2 : function(){
alert(this);// this´Â MainClass ¸¦ ÀǹÌÇÑ´Ù.
}
})
function init(){
var a = new MainClass();
}
*/
jindo.$Fn.prototype.bind = function() {
var a = jindo.$A(arguments).$value();
var f = this._func;
var t = this._this;
var b = function() {
var args = jindo.$A(arguments).$value();
// fix opera concat bug
if (a.length) args = a.concat(args);
return f.apply(t, args);
};
return b;
};
/**
* bingForEvent´Â °´Ã¼¿Í ¸Þ¼µå¸¦ ¹¾î ÇϳªÀÇ À̺¥Æ® Çڵ鷯 FunctionÀ¸·Î ¹ÝȯÇÑ´Ù.
* @param {Element, ...} [elementN] À̺¥Æ® °´Ã¼¿Í ÇÔ²² Àü´ÞÇÒ °ª
* @see $Fn#bind
* @see $Event
* @description [Lite]
* @ignore
*/
jindo.$Fn.prototype.bindForEvent = function() {
var a = arguments;
var f = this._func;
var t = this._this;
var m = this._tmpElm || null;
var b = function(e) {
var args = Array.prototype.slice.apply(a);
if (typeof e == "undefined") e = window.event;
if (typeof e.currentTarget == "undefined") {
e.currentTarget = m;
}
var oEvent = jindo.$Event(e);
args.unshift(oEvent);
var returnValue = f.apply(t, args);
if(typeof returnValue != "undefined" && oEvent.type=="beforeunload"){
e.returnValue = returnValue;
}
return returnValue;
};
return b;
};
/**
* attach ¸Þ¼µå´Â ÇÔ¼ö¸¦ ƯÁ¤ ¿¤¸®¸ÕÆ®ÀÇ À̺¥Æ® Çڵ鷯·Î ÇÒ´çÇÑ´Ù.<br>
* ÇÔ¼öÀÇ ¹Ýȯ °ªÀÌ falseÀÎ °æ¿ì, $Fn¿¡ ¹ÙÀεùÇÏ¿© »ç¿ëÇßÀ» ½Ã IE¿¡¼ ±âº» ±â´ÉÀ» ¸·±â ¶§¹®¿¡ »ç¿ëÇÏÁö ¾Êµµ·Ï ÁÖÀÇÇÑ´Ù.
<ul>
<li>À̺¥Æ® À̸§¿¡´Â on Á¢µÎ¾î¸¦ »ç¿ëÇÏÁö ¾Ê´Â´Ù.</li>
<li>¸¶¿ì½º ÈÙ ½ºÅ©·Ñ À̺¥Æ®´Â mousewheel ·Î »ç¿ëÇÑ´Ù.</li>
<li>±âº» À̺¥Æ® ¿Ü¿¡ Ãß°¡·Î »ç¿ëÀÌ °¡´ÉÇÑ À̺¥Æ®¿¡´Â domready, mouseenter, mouseleave, mousewheelÀÌ ÀÖ´Ù.</li>
</ul>
* @param {Element | Array} oElement À̺¥Æ® Çڵ鷯¸¦ ÇÒ´çÇÒ ¿¤¸®¸ÕÆ®(¿¤¸®¸ÕÆ®°¡ ¿ø¼ÒÀÎ ¹è¿µµ °¡´É)
* @param {String} sEvent À̺¥Æ® Á¾·ù
* @param {Boolean} bUseCapture capturingÀ» »ç¿ëÇÒ ¶§(1.4.2 ºÎÅÍ Áö¿ø)
* @see $Fn#detach
* @description [Lite]
* @return {$Fn} »ý¼ºµÈ $Fn °´Ã¼
* @example
var someObject = {
func : function() {
// code here
}
}
$Fn(someObject.func, someObject).attach($("test"),"click"); // ´ÜÀÏ ¿¤¸®¸ÕÆ®¿¡ Ŭ¸¯À» ÇÒ´çÇÑ °æ¿ì
$Fn(someObject.func, someObject).attach($$(".test"),"click"); // ¿©·¯ ¿¤¸®¸ÕÆ®¿¡ Ŭ¸¯À» ÇÒ´çÇÑ °æ¿ì
//attach¿¡ ù¹øÂ° ÀÎÀÚ·Î ¿¤¸®¸ÕÆ® ¹è¿ÀÌ µé¾î¿À¸é ÇØ´ç ¸ðµç ¿¤¸®¸ÕÆ®¿¡ À̺¥Æ®°¡ ¹ÙÀεù µÊ.
*/
jindo.$Fn.prototype.attach = function(oElement, sEvent, bUseCapture) {
var fn = null, l, ev = sEvent, el = oElement, ua = _ua;
if (typeof bUseCapture == "undefined") {
bUseCapture = false;
};
this._bUseCapture = bUseCapture;
if ((el instanceof Array) || (jindo.$A && (el instanceof jindo.$A) && (el=el.$value()))) {
for(var i=0; i < el.length; i++) this.attach(el[i], ev, bUseCapture);
return this;
}
if (!el || !ev) return this;
if (typeof el.$value == "function") el = el.$value();
el = jindo.$(el);
ev = ev.toLowerCase();
this._tmpElm = el;
fn = this.bindForEvent();
this._tmpElm = null;
var bIsIE = ua.indexOf("MSIE") > -1;
if (typeof el.addEventListener != "undefined") {
if (ev == "domready") {
ev = "DOMContentLoaded";
}else if (ev == "mousewheel" && ua.indexOf("WebKit") < 0 && !/Opera/.test(ua) && !bIsIE) {
/*
IE9ÀÎ °æ¿ìµµ DOMMouseScrollÀÌ µ¿ÀÛÇÏÁö ¾ÊÀ½.
*/
ev = "DOMMouseScroll";
}else if (ev == "mouseenter" && !bIsIE){
ev = "mouseover";
fn = jindo.$Fn._fireWhenElementBoundary(el, fn);
}else if (ev == "mouseleave" && !bIsIE){
ev = "mouseout";
fn = jindo.$Fn._fireWhenElementBoundary(el, fn);
}else if(ev == "transitionend"||ev == "transitionstart"){
var sPrefix, sPostfix = ev.replace("transition","");
sPostfix = sPostfix.substr(0,1).toUpperCase() + sPostfix.substr(1);
if(typeof document.body.style.WebkitTransition !== "undefined"){
sPrefix = "webkit";
}else if(typeof document.body.style.OTransition !== "undefined"){
sPrefix = "o";
}else if(typeof document.body.style.MsTransition !== "undefined"){
sPrefix = "ms";
}
ev = (sPrefix?sPrefix+"Transition":"transition")+sPostfix;
this._for_test_attach = ev;
this._for_test_detach = "";
}else if(ev == "animationstart"||ev == "animationend"||ev == "animationiteration"){
var sPrefix, sPostfix = ev.replace("animation","");
sPostfix = sPostfix.substr(0,1).toUpperCase() + sPostfix.substr(1);
if(typeof document.body.style.WebkitAnimationName !== "undefined"){
sPrefix = "webkit";
}else if(typeof document.body.style.OAnimationName !== "undefined"){
sPrefix = "o";
}else if(typeof document.body.style.MsTransitionName !== "undefined"){
sPrefix = "ms";
}
ev = (sPrefix?sPrefix+"Animation":"animation")+sPostfix;
this._for_test_attach = ev;
this._for_test_detach = "";
}
el.addEventListener(ev, fn, bUseCapture);
} else if (typeof el.attachEvent != "undefined") {
if (ev == "domready") {
/*
iframe¾È¿¡¼ domreadyÀ̺¥Æ®°¡ ½ÇÇàµÇÁö ¾Ê±â ¶§¹®¿¡ error¸¦ ´øÁü.
*/
if(window.top != window) throw new Error("Domready Event doesn't work in the iframe.");
jindo.$Fn._domready(el, fn);
return this;
} else {
el.attachEvent("on"+ev, fn);
}
}
if (!this._key) {
this._key = "$"+jindo.$Fn.gc.count++;
jindo.$Fn.gc.pool[this._key] = this;
}
this._events[this._events.length] = {element:el, event:sEvent.toLowerCase(), func:fn};
return this;
};
/**
* detach ¸Þ¼µå´Â ¿¤¸®¸ÕÆ®ÀÇ À̺¥Æ® Çڵ鷯·Î ÇÒ´çµÈ ÇÔ¼ö¸¦ ÇØÁ¦ÇÑ´Ù.
* @remark À̺¥Æ® À̸§¿¡´Â on Á¢µÎ¾î¸¦ »ç¿ëÇÏÁö ¾Ê´Â´Ù.
* @remark ¸¶¿ì½º ÈÙ ½ºÅ©·Ñ À̺¥Æ®´Â mousewheel ·Î »ç¿ëÇÑ´Ù.
* @param {Element} oElement À̺¥Æ® Çڵ鷯¸¦ ÇØÁ¦ÇÒ ¿¤¸®¸ÕÆ®
* @param {String} sEvent À̺¥Æ® Á¾·ù
* @see $Fn#attach
* @description [Lite]
* @return {$Fn} »ý¼ºµÈ $Fn °´Ã¼
* @example
var someObject = {
func : function() {
// code here
}
}
$Fn(someObject.func, someObject).detach($("test"),"click"); // ´ÜÀÏ ¿¤¸®¸ÕÆ®¿¡ Ŭ¸¯À» ÇÒ´çÇÑ °æ¿ì
$Fn(someObject.func, someObject).detach($$(".test"),"click"); // ¿©·¯ ¿¤¸®¸ÕÆ®¿¡ Ŭ¸¯À» ÇÒ´çÇÑ °æ¿ì
*/
jindo.$Fn.prototype.detach = function(oElement, sEvent) {
var fn = null, l, el = oElement, ev = sEvent, ua = _ua;
if ((el instanceof Array) || (jindo.$A && (el instanceof jindo.$A) && (el=el.$value()))) {
for(var i=0; i < el.length; i++) this.detach(el[i], ev);
return this;
}
if (!el || !ev) return this;
if (jindo.$Element && el instanceof jindo.$Element) el = el.$value();
el = jindo.$(el);
ev = ev.toLowerCase();
var e = this._events;
for(var i=0; i < e.length; i++) {
if (e[i].element !== el || e[i].event !== ev) continue;
fn = e[i].func;
this._events = jindo.$A(this._events).refuse(e[i]).$value();
break;
}
if (typeof el.removeEventListener != "undefined") {
if (ev == "domready") {
ev = "DOMContentLoaded";
}else if (ev == "mousewheel" && ua.indexOf("WebKit") < 0) {
ev = "DOMMouseScroll";
}else if (ev == "mouseenter"){
ev = "mouseover";
}else if (ev == "mouseleave"){
ev = "mouseout";
}else if(ev == "transitionend"||ev == "transitionstart"){
var sPrefix, sPostfix = ev.replace("transition","");
sPostfix = sPostfix.substr(0,1).toUpperCase() + sPostfix.substr(1);
if(typeof document.body.style.WebkitTransition !== "undefined"){
sPrefix = "webkit";
}else if(typeof document.body.style.OTransition !== "undefined"){
sPrefix = "o";
}else if(typeof document.body.style.MsTransition !== "undefined"){
sPrefix = "ms";
}
ev = (sPrefix?sPrefix+"Transition":"transition")+sPostfix;
this._for_test_detach = ev;
this._for_test_attach = "";
}else if(ev == "animationstart"||ev == "animationend"||ev == "animationiteration"){
var sPrefix, sPostfix = ev.replace("animation","");
sPostfix = sPostfix.substr(0,1).toUpperCase() + sPostfix.substr(1);
if(typeof document.body.style.WebkitAnimationName !== "undefined"){
sPrefix = "webkit";
}else if(typeof document.body.style.OAnimationName !== "undefined"){
sPrefix = "o";
}else if(typeof document.body.style.MsTransitionName !== "undefined"){
sPrefix = "ms";
}
ev = (sPrefix?sPrefix+"Animation":"animation")+sPostfix;
this._for_test_detach = ev;
this._for_test_attach = "";
}
if (fn) el.removeEventListener(ev, fn, false);
} else if (typeof el.detachEvent != "undefined") {
if (ev == "domready") {
jindo.$Fn._domready.list = jindo.$Fn._domready.list.refuse(fn);
return this;
} else {
el.detachEvent("on"+ev, fn);
}
}
return this;
};
/**
* delay ¸Þ¼µå´Â ·¡ÇÎÇÑ ÇÔ¼ö¸¦ ÁöÁ¤ÇÑ ½Ã°£ ÀÌÈÄ¿¡ È£ÃâÇÑ´Ù.
* @param {Number} nSec ÇÔ¼ö¸¦ È£ÃâÇÒ ¶§±îÁö ´ë±âÇÒ ½Ã°£(ÃÊ ´ÜÀ§).
* @param {Array} args ÇÔ¼ö¸¦ È£ÃâÇÒ ¶§ »ç¿ëÇÒ ¸Å°³º¯¼ö. ¸Å°³º¯¼ö°¡ ¿©·¯ °³ÀÏ °æ¿ì ¹è¿À» »ç¿ëÇÑ´Ù.
* @see $Fn#bind
* @see $Fn#setInterval
* @description [Lite]
* @return {$Fn} »ý¼ºµÈ $Fn °´Ã¼
* @example
function func(a, b) {
alert(a + b);
}
$Fn(func).delay(5, [3, 5]);//5ÃÊ ÀÌÈÄ¿¡ 3, 5 °ªÀ» ¸Å°³º¯¼ö·Î ÇÏ´Â ÇÔ¼ö func¸¦ È£ÃâÇÑ´Ù.
*/
jindo.$Fn.prototype.delay = function(nSec, args) {
if (typeof args == "undefined") args = [];
this._delayKey = setTimeout(this.bind.apply(this, args), nSec*1000);
return this;
};
/**
* setInterval ¸Þ¼µå´Â ·¡ÇÎÇÑ ÇÔ¼ö¸¦ ÁöÁ¤ÇÑ ½Ã°£ °£°Ý¸¶´Ù È£ÃâÇÑ´Ù.
* @param {Number} nSec ÇÔ¼ö¸¦ È£ÃâÇÒ °£°Ý(ÃÊ ´ÜÀ§).
* @param {Array} args ÇÔ¼ö¸¦ È£ÃâÇÒ ¶§ »ç¿ëÇÒ ¸Å°³º¯¼ö. ¸Å°³º¯¼ö°¡ ¿©·¯ °³ÀÏ °æ¿ì ¹è¿À» »ç¿ëÇÑ´Ù.
* @return {Number} Interval ID, ÇÔ¼ö È£ÃâÀ» ÇØÁ¦ÇÒ ¶§ »ç¿ëÇÑ´Ù.
* @see $Fn#bind
* @see $Fn#delay
* @description [Lite]
* @example
function func(a, b) {
alert(a + b);
}
$Fn(func).setInterval(5, [3, 5]);//5ÃÊ °£°ÝÀ¸·Î 3, 5 °ªÀ» ¸Å°³º¯¼ö·Î ÇÏ´Â ÇÔ¼ö func¸¦ È£ÃâÇÑ´Ù.
*/
jindo.$Fn.prototype.setInterval = function(nSec, args) {
if (typeof args == "undefined") args = [];
this._repeatKey = setInterval(this.bind.apply(this, args), nSec*1000);
return this._repeatKey;
};
/**
* repeat ¸Þ¼µå´Â setInterval¿Í °°´Ù.
* @param {Number} nSec ÇÔ¼ö¸¦ È£Ãâ°£ °£°Ý.
* @param {Array} args ÇÔ¼ö¸¦ È£ÃâÇÒ ¶§ »ç¿ëÇÒ ¸Å°³º¯¼ö. ¸Å°³º¯¼ö°¡ ¿©·¯ °³ÀÏ °æ¿ì ¹è¿À» »ç¿ëÇÑ´Ù.
* @return {Number} Interval ID, ÇÔ¼ö È£ÃâÀ» ÇØÁ¦ÇÒ ¶§ »ç¿ëÇÑ´Ù.
* @see $Fn#bind
* @see $Fn#delay
* @description [Lite]
* @example
function func(a, b) {
alert(a + b);
}
$Fn(func).repeat(5, [3, 5]);//5ÃÊ °£°ÝÀ¸·Î 3, 5 °ªÀ» ¸Å°³º¯¼ö·Î ÇÏ´Â ÇÔ¼ö func¸¦ È£ÃâÇÑ´Ù.
*/
jindo.$Fn.prototype.repeat = jindo.$Fn.prototype.setInterval;
/**
* stopDelay´Â delay ¸Þ¼µå·Î ÁöÁ¤ÇÑ ÇÔ¼ö È£ÃâÀ» ¸ØÃâ ¶§ »ç¿ëÇÑ´Ù.
* @return {$Fn} $Fn °´Ã¼
* @see $Fn#delay
* @example
function func(a, b) {
alert(a + b);
}
var fpDelay = $Fn(func);
fpDelay.delay(5, [3, 5]);
fpDelay.stopDelay();
*/
jindo.$Fn.prototype.stopDelay = function(){
if(typeof this._delayKey != "undefined"){
window.clearTimeout(this._delayKey);
delete this._delayKey;
}
return this;
}
/**
* stopRepeat´Â repeat¸Þ¼µå·Î ÁöÁ¤ÇÑ ÇÔ¼ö È£ÃâÀ» ¸ØÃâ ¶§ »ç¿ëÇÑ´Ù.
* @return {$Fn} $Fn °´Ã¼
* @see $Fn#repeat
* @example
function func(a, b) {
alert(a + b);
}
var fpDelay = $Fn(func);
fpDelay.repeat(5, [3, 5]);
fpDelay.stopRepeat();
*/
jindo.$Fn.prototype.stopRepeat = function(){
if(typeof this._repeatKey != "undefined"){
window.clearInterval(this._repeatKey);
delete this._repeatKey;
}
return this;
}
/**
* ¸Þ¸ð¸®¿¡¼ ÀÌ °´Ã¼¸¦ »ç¿ëÇÑ ÂüÁ¶¸¦ ¸ðµÎ ÇØÁ¦ÇÑ´Ù(Á÷Á¢ È£Ãâ ±ÝÁö).
* @param {Element} ÇØ´ç ¿ä¼ÒÀÇ À̺¥Æ® Çڵ鷯¸¸ ÇØÁ¦.
* @ignore
*/
jindo.$Fn.prototype.free = function(oElement) {
var len = this._events.length;
while(len > 0) {
var el = this._events[--len].element;
var sEvent = this._events[len].event;
var fn = this._events[len].func;
if (oElement && el!==oElement){
continue;
}
this.detach(el, sEvent);
/*
unload½Ã¿¡ ¿¤¸®¸ÕÆ®¿¡ attachÇÑ ÇÔ¼ö¸¦ detachÇÏ´Â ·ÎÁ÷ÀÌ Àִµ¥ ÇØ´ç ·ÎÁ÷À¸·Î ÀÎÇÏ¿© unloadÀ̺¥Æ®°¡ ½ÇÇàµÇÁö ¾Ê¾Æ ½ÇÇà½ÃŰ´Â ·ÎÁ÷À» ¸¸µë. ±×¸®°í ÇØ´ç ·ÎÁ÷Àº gc¿¡¼ È£ÃâÇÒ¶§¸¸ È£Ãâ.
*/
var isGCCall = !oElement;
if (isGCCall && window === el && sEvent == "unload" && _ua.indexOf("MSIE")<1) {
this._func.call(this._this);
}
delete this._events[len];
}
if(this._events.length==0)
try { delete jindo.$Fn.gc.pool[this._key]; }catch(e){};
};
/**
* IE¿¡¼ domready(=DOMContentLoaded) À̺¥Æ®¸¦ ¿¡¹Ä·¹À̼ÇÇÑ´Ù.
* @ignore
*/
jindo.$Fn._domready = function(doc, func) {
if (typeof jindo.$Fn._domready.list == "undefined") {
var f = null, l = jindo.$Fn._domready.list = jindo.$A([func]);
// use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
var done = false, execFuncs = function(){
if(!done) {
done = true;
var evt = {
type : "domready",
target : doc,
currentTarget : doc
};
while(f = l.shift()) f(evt);
}
};
(function (){
try {
doc.documentElement.doScroll("left");
} catch(e) {
setTimeout(arguments.callee, 50);
return;
}
execFuncs();
})();
// trying to always fire before onload
doc.onreadystatechange = function() {
if (doc.readyState == 'complete') {
doc.onreadystatechange = null;
execFuncs();
}
};
} else {
jindo.$Fn._domready.list.push(func);
}
};
/**
* ºñ IE¿¡¼ mouseenter/mouseleave À̺¥Æ®¸¦ ¿¡¹Ä·¹À̼ÇÇϱâ À§ÇÑ ¿ä¼Ò ¿µ¿ªÀ» ¹þ¾î³ª´Â °æ¿ì¿¡¸¸ ½ÇÇàÇÏ´Â ÇÔ¼ö ÇÊÅÍ
* @ignore
*/
jindo.$Fn._fireWhenElementBoundary = function(doc, func) {
return function(evt){
var oEvent = jindo.$Event(evt);
var relatedElement = jindo.$Element(oEvent.relatedElement);
if(relatedElement && (relatedElement.isEqual(this) || relatedElement.isChildOf(this))) return;
func.call(this,evt);
}
};
/**
* gc ¸Þ¼µå´Â ¿¤¸®¸ÕÆ®¿¡ ÇÒ´çµÈ ¸ðµç À̺¥Æ® Çڵ鷯¸¦ ÇØÁ¦ÇÑ´Ù.
* @example
var someObject = {
func1 : function() {
// code here
},
func2 : function() {
// code here
}
}
$Fn(someObject.func1, someObject).attach($("test1"),"mouseup");
$Fn(someObject.func2, someObject).attach($("test1"),"mousedown");
$Fn(someObject.func1, someObject).attach($("test2"),"mouseup");
$Fn(someObject.func2, someObject).attach($("test2"),"mousedown");
..
..
$Fn.gc();
*/
jindo.$Fn.gc = function() {
var p = jindo.$Fn.gc.pool;
for(var key in p) {
if(p.hasOwnProperty(key))
try { p[key].free(); }catch(e){ };
}
/*
·¹ÆÛ·±½º¸¦ »èÁ¦ÇÑ´Ù.
*/
jindo.$Fn.gc.pool = p = {};
};
/**
* freeElement ¸Þ¼Òµå´Â ÁöÁ¤ÇÑ ¿¤¸®¸ÕÆ®¿¡ ÇÒ´çµÈ À̺¥Æ® Çڵ鷯¸¦ ¸ðµÎ ÇØÁ¦ÇÑ´Ù.
* @since 1.3.5
* @see $Fn#gc
* @example
var someObject = {
func : function() {
// code here
}
}
$Fn(someObject.func, someObject).attach($("test"),"mouseup");
$Fn(someObject.func, someObject).attach($("test"),"mousedown");
$Fn.freeElement($("test"));
*/
jindo.$Fn.freeElement = function(oElement){
var p = jindo.$Fn.gc.pool;
for(var key in p) {
if(p.hasOwnProperty(key)){
try {
p[key].free(oElement);
}catch(e){ };
}
}
}
jindo.$Fn.gc.count = 0;
jindo.$Fn.gc.pool = {};
function isUnCacheAgent(){
var isIPad = (_ua.indexOf("iPad") > -1);
var isAndroid = (_ua.indexOf("Android") > -1);
var isMSafari = (!(_ua.indexOf("IEMobile") > -1) && (_ua.indexOf("Mobile") > -1) )||(isIPad && (_ua.indexOf("Safari") > -1));
return isMSafari && !isIPad && !isAndroid;
}
if (typeof window != "undefined" && !isUnCacheAgent()) {
jindo.$Fn(jindo.$Fn.gc).attach(window, "unload");
}
/**
* @fileOverview $EventÀÇ »ý¼ºÀÚ ¹× ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name event.js
*/
/**
* JavaScript Core À̺¥Æ® °´Ã¼·ÎºÎÅÍ $Event °´Ã¼¸¦ »ý¼ºÇÑ´Ù.
* @class $Event Ŭ·¡½º´Â ÀÚ¹Ù½ºÅ©¸³Æ® Event °´Ã¼ÀÇ ·¡ÆÛ(Wrapper) Ŭ·¡½ºÀÌ´Ù. »ç¿ëÀÚ´Â $Event.element ¸Þ¼µå¸¦ »ç¿ëÇÏ¿© À̺¥Æ®°¡ ¹ß»ýÇÑ °´Ã¼¸¦ ¾Ë ¼ö ÀÖ´Ù.
* @param {Event} e Event °´Ã¼
* @constructor
* @description [Lite]
* @author Kim, Taegon
*/
jindo.$Event = function(e) {
var cl = arguments.callee;
if (e instanceof cl) return e;
if (!(this instanceof cl)) return new cl(e);
if (typeof e == "undefined") e = window.event;
if (e === window.event && document.createEventObject) e = document.createEventObject(e);
this._event = e;
this._globalEvent = window.event;
/**
À̺¥Æ®ÀÇ Á¾·ù
*/
this.type = e.type.toLowerCase();
if (this.type == "dommousescroll") {
this.type = "mousewheel";
} else if (this.type == "domcontentloaded") {
this.type = "domready";
}
this.canceled = false;
/**
À̺¥Æ®°¡ ¹ß»ýÇÑ ¿¤¸®¸ÕÆ®
*/
this.element = e.target || e.srcElement;
/**
À̺¥Æ®°¡ Á¤ÀÇµÈ ¿¤¸®¸ÕÆ®
*/
this.currentElement = e.currentTarget;
/**
À̺¥Æ®ÀÇ ¿¬°ü ¿¤¸®¸ÕÆ®
*/
this.relatedElement = null;
if (typeof e.relatedTarget != "undefined") {
this.relatedElement = e.relatedTarget;
} else if(e.fromElement && e.toElement) {
this.relatedElement = e[(this.type=="mouseout")?"toElement":"fromElement"];
}
}
/**
* mouse ¸Þ¼µå´Â ¸¶¿ì½º À̺¥Æ®ÀÇ ¹öư, ÈÙ Á¤º¸¸¦ ¸®ÅÏÇÑ´Ù.
* @description [Lite]
* @example
function eventHandler(evt) {
var mouse = evt.mouse();
mouse.delta; // Number. ÈÙÀÌ ¿òÁ÷ÀÎ Á¤µµ. ÈÙÀ» À§·Î ±¼¸®¸é ¾ç¼ö, ¾Æ·¡·Î ±¼¸®¸é À½¼ö.
mouse.left; // Boolean. ¸¶¿ì½º ¿ÞÂÊ ¹öưÀ» ´·ÈÀ¸¸é true, ¾Æ´Ï¸é false
mouse.middle; // Boolean. ¸¶¿ì½º Áß°£ ¹öưÀ» ´·ÈÀ¸¸é true, ¾Æ´Ï¸é false
mouse.right; // Boolean. ¸¶¿ì½º ¿À¸¥ÂÊ ¹öưÀ» ´·ÈÀ¸¸é true, ¾Æ´Ï¸é false
}
* @return {Object} ¸¶¿ì½º Á¤º¸¸¦ °¡Áö´Â °´Ã¼. ¸®ÅÏÇÑ °´Ã¼ÀÇ ¼Ó¼ºÀº ¿¹Á¦¸¦ ÂüÁ¶ÇÑ´Ù.
*/
jindo.$Event.prototype.mouse = function() {
var e = this._event;
var delta = 0;
var left = false,mid = false,right = false;
var left = e.which ? e.button==0 : !!(e.button&1);
var mid = e.which ? e.button==1 : !!(e.button&4);
var right = e.which ? e.button==2 : !!(e.button&2);
var ret = {};
if (e.wheelDelta) {
delta = e.wheelDelta / 120;
} else if (e.detail) {
delta = -e.detail / 3;
}
ret = {
delta : delta,
left : left,
middle : mid,
right : right
};
// replace method
this.mouse = function(){ return ret };
return ret;
};
/**
* key ¸Þ¼µå´Â Űº¸µå À̺¥Æ® Á¤º¸¸¦ ¸®ÅÏÇÑ´Ù.
* @description [Lite]
* @example
function eventHandler(evt) {
var key = evt.key();
key.keyCode; // Number. ´¸° Űº¸µåÀÇ Å°ÄÚµå
key.alt; // Boolean. Alt ۸¦ ´·ÈÀ¸¸é true.
key.ctrl; // Boolean. Ctrl ۸¦ ´·ÈÀ¸¸é true.
key.meta; // Boolean. Meta ۸¦ ´·ÈÀ¸¸é true. MetaŰ´Â ¸ÆÀÇ Ä¿¸Çµå۸¦ °ËÃâÇÒ ¶§ »ç¿ëÇÕ´Ï´Ù.
key.shift; // Boolean. Shift ۸¦ ´·ÈÀ¸¸é true.
key.up; // Boolean. À§ÂÊ È»ìÇ¥ ۸¦ ´·ÈÀ¸¸é true.
key.down; // Boolean. ¾Æ·¡ÂÊ È»ìÇ¥ ۸¦ ´·ÈÀ¸¸é true.
key.left; // Boolean. ¿ÞÂÊ È»ìÇ¥ ۸¦ ´·ÈÀ¸¸é true.
key.right; // Boolean. ¿À¸¥ÂÊ È»ìÇ¥ ۸¦ ´·ÈÀ¸¸é true.
key.enter; // Boolean. ¸®ÅÏ۸¦ ´·¶À¸¸é true
key.esc; // Boolean. ESC۸¦ ´·¶À¸¸é true
}
}
* @return {Object} Űº¸µå À̺¥Æ®ÀÇ ´¸° ۰ª. °´Ã¼ÀÇ ¼Ó¼ºÀº ¿¹Á¦¸¦ ÂüÁ¶ÇÑ´Ù.
*/
jindo.$Event.prototype.key = function() {
var e = this._event;
var k = e.keyCode || e.charCode;
var ret = {
keyCode : k,
alt : e.altKey,
ctrl : e.ctrlKey,
meta : e.metaKey,
shift : e.shiftKey,
up : (k == 38),
down : (k == 40),
left : (k == 37),
right : (k == 39),
enter : (k == 13),
esc : (k == 27)
};
this.key = function(){ return ret };
return ret;
};
/**
* pos ¸Þ¼µå´Â ¸¶¿ì½º Ä¿¼ÀÇ À§Ä¡ Á¤º¸¸¦ ¸®ÅÏÇÑ´Ù.
* @param {Boolean} bGetOffset ÇöÀç ¿¤¸®¸ÕÆ®¿¡ ´ëÇÑ ¸¶¿ì½º Ä¿¼ÀÇ »ó´ëÀ§Ä¡ÀÎ offsetX, offsetY¸¦ ±¸ÇÒ °ÍÀÎÁöÀÇ ¿©ºÎ. true¸é °ªÀ» ±¸ÇÑ´Ù(offsetX, offsetY´Â 1.2.0¹öÀüºÎÅÍ Ãß°¡). $Element °¡ Æ÷ÇԵǾî ÀÖ¾î¾ß ÇÑ´Ù.
* @description [Lite]
* @example
function eventHandler(evt) {
var pos = evt.pos();
pos.clientX; // Number. ÇöÀç ȸ鿡 ´ëÇÑ X ÁÂÇ¥
pos.clientY; // Number. ÇöÀç ȸ鿡 ´ëÇÑ Y ÁÂÇ¥
pos.pageX; // Number. ¹®¼ Àüü¿¡ ´ëÇÑ X ÁÂÇ¥
pos.pageY; // Number. ¹®¼ Àüü¿¡ ´ëÇÑ Y ÁÂÇ¥
pos.layerX; // Number. <b>deprecated.</b> À̺¥Æ®°¡ ¹ß»ýÇÑ ¿¤¸®¸ÕÆ®·ÎºÎÅÍÀÇ »ó´ëÀûÀÎ X ÁÂÇ¥
pos.layerY; // Number. <b>deprecated.</b> À̺¥Æ®°¡ ¹ß»ýÇÑ ¿¤¸®¸ÕÆ®·ÎºÎÅÍÀÇ »ó´ëÀûÀÎ Y ÁÂÇ¥
pos.offsetX; // Number. À̺¥Æ®°¡ ¹ß»ýÇÑ ¿¤¸®¸ÕÆ®¿¡ ´ëÇÑ ¸¶¿ì½º Ä¿¼ÀÇ »ó´ëÀûÀÎ XÁÂÇ¥ (1.2.0 ÀÌ»ó)
pos.offsetY; // Number. À̺¥Æ®°¡ ¹ß»ýÇÑ ¿¤¸®¸ÕÆ®¿¡ ´ëÇÑ ¸¶¿ì½º Ä¿¼ÀÇ »ó´ëÀûÀÎ YÁÂÇ¥ (1.2.0 ÀÌ»ó)
}
* @return {Object} ¸¶¿ì½º Ä¿¼ÀÇ À§Ä¡ Á¤º¸. °´Ã¼ÀÇ ¼Ó¼ºÀº ¿¹Á¦¸¦ ÂüÁ¶ÇÑ´Ù.
* @remark layerX, layerY´Â Â÷ÈÄ Áö¿øÇÏÁö ¾ÊÀ»(deprecated) ¿¹Á¤ÀÔ´Ï´Ù.
*/
jindo.$Event.prototype.pos = function(bGetOffset) {
var e = this._event;
var b = (this.element.ownerDocument||document).body;
var de = (this.element.ownerDocument||document).documentElement;
var pos = [b.scrollLeft || de.scrollLeft, b.scrollTop || de.scrollTop];
var ret = {
clientX : e.clientX,
clientY : e.clientY,
pageX : 'pageX' in e ? e.pageX : e.clientX+pos[0]-b.clientLeft,
pageY : 'pageY' in e ? e.pageY : e.clientY+pos[1]-b.clientTop,
layerX : 'offsetX' in e ? e.offsetX : e.layerX - 1,
layerY : 'offsetY' in e ? e.offsetY : e.layerY - 1
};
/*
¿ÀÇÁ¼ÂÀ» ±¸ÇÏ´Â ¸Þ¼ÒµåÀÇ ºñ¿ëÀÌ Å©¹Ç·Î, ¿äû½Ã¿¡¸¸ ±¸Çϵµ·Ï ÇÑ´Ù.
*/
if (bGetOffset && jindo.$Element) {
var offset = jindo.$Element(this.element).offset();
ret.offsetX = ret.pageX - offset.left;
ret.offsetY = ret.pageY - offset.top;
}
return ret;
};
/**
* stop ¸Þ¼µå´Â À̺¥Æ®ÀÇ ¹öºí¸µ°ú ±âº» µ¿ÀÛÀ» ÁßÁö½ÃŲ´Ù.
* @remark ¹öºí¸µÀº ƯÁ¤ HTML ¿¤¸®¸ÕÆ®¿¡¼ À̺¥Æ®°¡ ¹ß»ýÇßÀ» ¶§ À̺¥Æ®°¡ »óÀ§ ³ëµå·Î ÀüÆÄµÇ´Â Çö»óÀÌ´Ù. ¿¹¸¦ µé¾î, div °´Ã¼¸¦ Ŭ¸¯ÇÒ ¶§ div¿Í ÇÔ²² »óÀ§ ¿¤¸®¸ÕÆ®ÀÎ document¿¡µµ onclick À̺¥Æ®°¡ ¹ß»ýÇÑ´Ù. stop() ¸Þ¼Òµå´Â ÁöÁ¤ÇÑ °´Ã¼¿¡¼¸¸ À̺¥Æ®°¡ ¹ß»ýÇϵµ·Ï ¹öºí¸µÀ» Â÷´ÜÇÑ´Ù.
* @description [Lite]
* @example
// ±âº» µ¿ÀÛ¸¸ ÁßÁö½ÃŰ°í ½ÍÀ» ¶§ (1.1.3¹öÀü ÀÌ»ó)
function stopDefaultOnly(evt) {
// Here is some code to execute
// Stop default event only
evt.stop($Event.CANCEL_DEFAULT);
}
* @return {$Event} À̺¥Æ® °´Ã¼.
* @param {Number} nCancel À̺¥Æ®ÀÇ ¹öºí¸µ°ú ±âº» µ¿ÀÛÀ» ¼±ÅÃÇÏ¿© ÁßÁö½ÃŲ´Ù. ±âº»°ªÀº $Event.CANCEL_ALL ÀÌ´Ù(1.1.3 ¹öÀü ÀÌ»ó).
*/
jindo.$Event.prototype.stop = function(nCancel) {
nCancel = nCancel || jindo.$Event.CANCEL_ALL;
var e = (window.event && window.event == this._globalEvent)?this._globalEvent:this._event;
var b = !!(nCancel & jindo.$Event.CANCEL_BUBBLE); // stop bubbling
var d = !!(nCancel & jindo.$Event.CANCEL_DEFAULT); // stop default event
this.canceled = true;
if (typeof e.preventDefault != "undefined" && d) e.preventDefault();
if (typeof e.stopPropagation != "undefined" && b) e.stopPropagation();
if(d) e.returnValue = false;
if(b) e.cancelBubble = true;
return this;
};
/**
* stopDefault ¸Þ¼µå´Â À̺¥Æ®ÀÇ ±âº» µ¿ÀÛÀ» ÁßÁö½ÃŲ´Ù.
* @return {$Event} À̺¥Æ® °´Ã¼.
* @see $Event#stop
* @description [Lite]
*/
jindo.$Event.prototype.stopDefault = function(){
return this.stop(jindo.$Event.CANCEL_DEFAULT);
}
/**
* stopBubble ¸Þ¼µå´Â À̺¥Æ®ÀÇ ¹öºí¸µÀ» ÁßÁö½ÃŲ´Ù.
* @return {$Event} À̺¥Æ® °´Ã¼.
* @see $Event#stop
* @description [Lite]
*/
jindo.$Event.prototype.stopBubble = function(){
return this.stop(jindo.$Event.CANCEL_BUBBLE);
}
/**
* $value ¸Þ¼µå´Â ¿ø·¡ÀÇ À̺¥Æ® °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù
* @example
function eventHandler(evt){
evt.$value();
}
* @return {Event} Event
*/
jindo.$Event.prototype.$value = function() {
return this._event;
};
/**
* $Event#stop ¸Þ¼µå¿¡¼ ¹öºí¸µÀ» ÁßÁö½ÃŲ´Ù.
* @final
*/
jindo.$Event.CANCEL_BUBBLE = 1;
/**
* $Event#stop ¸Þ¼µå¿¡¼ ±âº» µ¿ÀÛÀ» ÁßÁö½ÃŲ´Ù.
* @final
*/
jindo.$Event.CANCEL_DEFAULT = 2;
/**
* $Event#stop ¸Þ¼µå¿¡¼ ¹öºí¸µ°ú ±âº» µ¿ÀÛ ¸ðµÎ ÁßÁö½ÃŲ´Ù.
* @final
*/
jindo.$Event.CANCEL_ALL = 3;
/**
* @fileOverview $ElementListÀÇ »ý¼ºÀÚ ¹× ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name elementlist.js
*/
/**
* $ElementList °´Ã¼¸¦ »ý¼º ¹× ¸®ÅÏÇÑ´Ù.
* @class $ElementList Ŭ·¡½º´Â id ¹è¿, ȤÀº CSS Äõ¸® µîÀ» »ç¿ëÇÏ¿© DOM ¿¤¸®¸ÕÆ®ÀÇ ¹è¿À» ¸¸µç´Ù.
* @param {String | Array} els ¹®¼¿¡¼ DOM ¿¤¸®¸ÕÆ®¸¦ ã±â À§ÇÑ CSS ¼±ÅÃÀÚ È¤Àº id, HTMLElement, $ElementÀÇ ¹è¿
* @constructor
* @borrows $Element#show as this.show
* @borrows $Element#hide as this.hide
* @borrows $Element#toggle as this.toggle
* @borrows $Element#addClass as this.addClass
* @borrows $Element#removeClass as this.removeClass
* @borrows $Element#toggleClass as this.toggleClass
* @borrows $Element#fireEvent as this.fireEvent
* @borrows $Element#leave as this.leave
* @borrows $Element#empty as this.empty
* @borrows $Element#appear as this.appear
* @borrows $Element#disappear as this.disappear
* @borrows $Element#className as this.className
* @borrows $Element#width as this.width
* @borrows $Element#height as this.height
* @borrows $Element#text as this.text
* @borrows $Element#html as this.html
* @borrows $Element#css as this.css
* @borrows $Element#attr as this.attr
* @author Kim, Taegon
*/
jindo.$ElementList = function (els) {
var cl = arguments.callee;
if (els instanceof cl) return els;
if (!(this instanceof cl)) return new cl(els);
if (els instanceof Array) {
els = jindo.$A(els);
} else if(jindo.$A && els instanceof jindo.$A){
els = jindo.$A(els.$value());
} else if (typeof els == "string" && jindo.cssquery) {
els = jindo.$A(jindo.cssquery(els));
} else {
els = jindo.$A();
}
this._elements = els.map(function(v,i,a){ return jindo.$Element(v) });
}
/**
* get ¸Þ¼µå´Â $ElementList¿¡¼ À妽º¿¡ ÇØ´çÇÏ´Â ¿¤¸®¸ÕÆ®¸¦ °¡Á®¿Â´Ù.
* @param {Number} idx °¡Á®¿Ã ¿¤¸®¸ÕÆ®ÀÇ À妽º. À妽º´Â 0¿¡¼ ºÎÅÍ ½ÃÀÛÇÑ´Ù.
* @return {$Element} À妽º¿¡ ÇØ´çÇÏ´Â ¿¤¸®¸ÕÆ®
*/
jindo.$ElementList.prototype.get = function(idx) {
return this._elements.$value()[idx];
};
/**
* getFirst ¸Þ¼µå´Â $ElementListÀÇ Ã¹¹øÂ° ¿¤¸®¸ÕÆ®¸¦ °¡Á®¿Â´Ù.
* @remark getFirst ¸Þ¼µåÀÇ ¸®ÅϰªÀº $ElementList.get(0)ÀÇ ¸®Åϰª°ú µ¿ÀÏÇÏ´Ù.
* @return {$Element} ù¹øÂ° ¿¤¸®¸ÕÆ®
*/
jindo.$ElementList.prototype.getFirst = function() {
return this.get(0);
};
/**
* length¸Þ¼Òµå´Â $AÀÇ length¸¦ ÀÌ¿ëÇÑ´Ù.(1.4.3 ºÎÅÍ »ç¿ë °¡´É.)
* @return Number ¹è¿ÀÇ Å©±â
* @param {Number} [nLen] »õ·Î ¸®ÅÏÇÒ ¹è¿ÀÇ Å©±â. nLenÀÌ ±âÁ¸ÀÇ ¹è¿º¸´Ù Å©¸é oValueÀ¸·Î ÃʱâÈÇÑ ¿ø¼Ò¸¦ ¸¶Áö¸·¿¡ µ¡ºÙÀδÙ. nLenÀÌ ±âÁ¸ ¹è¿º¸´Ù ÀÛÀ¸¸é nLen¹øÂ° ÀÌÈÄÀÇ ¿ø¼Ò´Â Á¦°ÅÇÑ´Ù.
* @param {Value} [oValue] »õ·Î¿î ¿ø¼Ò¸¦ Ãß°¡ÇÒ ¶§ »ç¿ëÇÒ ÃʱⰪ
* @see $A#length
*/
jindo.$ElementList.prototype.length = function(nLen, oValue) {
return this._elements.length(nLen, oValue);
}
/**
* getLast ¸Þ¼µå´Â $ElementListÀÇ ¸¶Áö¸· ¿¤¸®¸ÕÆ®¸¦ °¡Á®¿Â´Ù.
* @return {$Element} ¸¶Áö¸· ¿¤¸®¸ÕÆ®
*/
jindo.$ElementList.prototype.getLast = function() {
return this.get(Math.max(this._elements.length()-1,0));
};
/**
* $value ¸Þ¼Òµå´Â ÀÚ½ÅÀÇ ¹è¿ ¿¤¸®¸ÕÆ®À» ¹Ýȯ ÇÑ´Ù.
* @return {Array} $Element°¡ µé¾î ÀÖ´Â ¹è¿.
*/
jindo.$ElementList.prototype.$value = function() {
return this._elements.$value();
};
(function(proto){
var setters = ['show','hide','toggle','addClass','removeClass','toggleClass','fireEvent','leave',
'empty','appear','disappear','className','width','height','text','html','css','attr'];
jindo.$A(setters).forEach(function(name){
proto[name] = function() {
var args = jindo.$A(arguments).$value();
this._elements.forEach(function(el){
el[name].apply(el, args);
});
return this;
}
});
jindo.$A(['appear','disappear']).forEach(function(name){
proto[name] = function(duration, callback) {
var len = this._elements.length;
var self = this;
this._elements.forEach(function(el,idx){
if(idx == len-1) {
el[name](duration, function(){callback(self)});
} else {
el[name](duration);
}
});
return this;
}
});
})(jindo.$ElementList.prototype);
/**
* @fileOverview $JsonÀÇ »ý¼ºÀÚ ¹× ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name json.js
*/
/**
* $S °´Ã¼¸¦ »ý¼ºÇÑ´Ù.
* @class $S Ŭ·¡½º´Â ¹®ÀÚ¿À» ó¸®Çϱâ À§ÇÑ ·¡ÆÛ(Wrapper) Ŭ·¡½ºÀÌ´Ù.
* @constructor
* @param {String} str
* <br>
* ¹®ÀÚ¿À» ¸Å°³º¯¼ö·Î ÁöÁ¤ÇÑ´Ù.
* @author Kim, Taegon
*/
jindo.$S = function(str) {
var cl = arguments.callee;
if (typeof str == "undefined") str = "";
if (str instanceof cl) return str;
if (!(this instanceof cl)) return new cl(str);
this._str = str+"";
}
/**
* $value ¸Þ¼µå´Â ¿ø·¡ÀÇ ¹®ÀÚ¿À» ¸®ÅÏÇÑ´Ù.
* @return {String} ·¡ÇÎµÈ ¿ø·¡ÀÇ ¹®ÀÚ¿
* @see $S#toString
* @example
var str = $S("Hello world!!");
str.$value();
*
* // °á°ú :
* // Hello world!!
*/
jindo.$S.prototype.$value = function() {
return this._str;
};
/**
* toString ¸Þ¼µå´Â ¿ø·¡ÀÇ ¹®ÀÚ¿À» ¸®ÅÏÇÑ´Ù.
* @return {String} ·¡ÇÎµÈ ¿ø·¡ÀÇ ¹®ÀÚ¿
* @remark $value¿Í °°Àº ÀǹÌ
* @example
var str = $S("Hello world!!");
str.toString();
*
* // °á°ú :
* // Hello world!!
*/
jindo.$S.prototype.toString = jindo.$S.prototype.$value;
/**
* trim ¸Þ¼µå´Â ¹®ÀÚ¿ÀÇ ¾ç ³¡ °ø¹éÀ» Á¦°ÅÇÑ´Ù.(1.4.1 ºÎÅÍ Àü°¢°ø¹éµµ Á¦°Å)
* @return {$S} ¹®ÀÚ¿ÀÇ ¾ç ³¡À» Á¦°ÅÇÑ »õ·Î¿î $S °´Ã¼
* @example
var str = " I have many spaces. ";
document.write ( $S(str).trim() );
*
* // °á°ú :
* // I have many spaces.
*/
jindo.$S.prototype.trim = function() {
if ("".trim) {
jindo.$S.prototype.trim = function() {
return jindo.$S(this._str.trim());
}
}else{
jindo.$S.prototype.trim = function() {
return jindo.$S(this._str.replace(/^(\s|¡¡)+/g, "").replace(/(\s|¡¡)+$/g, ""));
}
}
return jindo.$S(this.trim());
};
/**
* escapeHTML ¸Þ¼µå´Â HTML Ư¼ö ¹®ÀÚ¸¦ HTML ¿£Æ¼Æ¼(Entities)Çü½ÄÀ¸·Î À̽ºÄÉÀÌÇÁ(escape)ÇÑ´Ù.
* @return {$S} HTML Ư¼ö ¹®ÀÚ¸¦ ¿£Æ¼Æ¼ Çü½ÄÀ¸·Î º¯È¯ÇÑ »õ·Î¿î $S °´Ã¼
* @see $S#unescapeHTML
* @remark ", &, <, > ,' ¸¦ °¢°¢ ", &, <, > '·Î º¯°æÇÑ´Ù.
* @example
var str = ">_<;;";
document.write( $S(str).escapeHTML() );
*
* // °á°ú :
* // &gt;_&lt;;;
*/
jindo.$S.prototype.escapeHTML = function() {
var entities = {'"':'quot','&':'amp','<':'lt','>':'gt','\'':'#39'};
var s = this._str.replace(/[<>&"']/g, function(m0){
return entities[m0]?'&'+entities[m0]+';':m0;
});
return jindo.$S(s);
};
/**
* stripTags ¸Þ¼µå´Â ¹®ÀÚ¿¿¡¼ XML ȤÀº HTML ű׸¦ Á¦°ÅÇÑ´Ù.
* @return {$S} XML ȤÀº HTML ű׸¦ Á¦°ÅÇÑ »õ·Î¿î $S °´Ã¼
* @example
var str = "Meeting <b>people</b> is easy.";
document.write( $S(str).stripTags() );
*
* // °á°ú :
* // Meeting people is easy.
*/
jindo.$S.prototype.stripTags = function() {
return jindo.$S(this._str.replace(/<\/?(?:h[1-5]|[a-z]+(?:\:[a-z]+)?)[^>]*>/ig, ''));
};
/**
* times ¸Þ¼µå´Â ¹®ÀÚ¿À» ¸Å°³º¯¼ö·Î ÁöÁ¤ÇÑ ¼ýÀÚ¸¸Å ¹Ýº¹ÇÑ´Ù.
* @param {Number} nTimes ¹Ýº¹ÇÒ È½¼ö
* @return {$S} ¹®ÀÚ¿À» ÁöÁ¤ÇÑ ¼ýÀÚ¸¸Å ¹Ýº¹ÇÑ »õ·Î¿î $S °´Ã¼
* @example
document.write ( $S("Abc").times(3) );
*
* // °á°ú : AbcAbcAbc
*/
jindo.$S.prototype.times = function(nTimes) {
var buf = [];
for(var i=0; i < nTimes; i++) {
buf[buf.length] = this._str;
}
return jindo.$S(buf.join(''));
};
/**
* unescapeHTML ¸Þ¼µå´Â À̽ºÄÉÀÌÇÁ(escape)µÈ HTMLÀ» ¿ø·¡ÀÇ HTML·Î ¸®ÅÏÇÑ´Ù.
* @return {$S} À̽ºÄÉÀÌÇÁµÈ HTMLÀ» ¿ø·¡ÀÇ HTML·Î º¯È¯ÇÑ »õ·Î¿î $S °´Ã¼
* @remark ", &, <, > '¸¦ °¢°¢ ", &, <, >, ' À¸·Î º¯°æÇÑ´Ù.
* @see $S#escapeHTML
* @example
* var str = "<a href="http://naver.com">Naver</a>";
* document.write( $S(str).unescapeHTML() );
*
* // °á°ú :
* // <a href="http://naver.com">Naver</a>
*/
jindo.$S.prototype.unescapeHTML = function() {
var entities = {'quot':'"','amp':'&','lt':'<','gt':'>','#39':'\''};
var s = this._str.replace(/&([a-z]+|#[0-9]+);/g, function(m0,m1){
return entities[m1]?entities[m1]:m0;
});
return jindo.$S(s);
};
/**
* escape ¸Þ¼µå´Â ¹®ÀÚ¿¿¡ Æ÷ÇÔµÈ ÇѱÛÀ» ASCII ¹®ÀÚ¿·Î ÀÎÄÚµùÇÑ´Ù.
* @remark \r, \n, \t, ', ", non-ASCII ¹®ÀÚ¸¦ À̽ºÄÉÀÌÇÁ ó¸®ÇÑ´Ù.
* @return {$S} ¹®ÀÚ¿À» À̽ºÄÉÀÌÇÁ ó¸®ÇÑ »õ·Î¿î $S °´Ã¼
* @see $S#escapeHTML
* @example
* var str = '°¡"\'³ª\\';
* document.write( $S(str).escape() );
*
* // °á°ú :
* \uAC00\"\'\uB098\\
*/
jindo.$S.prototype.escape = function() {
var s = this._str.replace(/([\u0080-\uFFFF]+)|[\n\r\t"'\\]/g, function(m0,m1,_){
if(m1) return escape(m1).replace(/%/g,'\\');
return (_={"\n":"\\n","\r":"\\r","\t":"\\t"})[m0]?_[m0]:"\\"+m0;
});
return jindo.$S(s);
};
/**
* bytes ¸Þ¼µå´Â ¹®ÀÚ¿ÀÇ ½ÇÁ¦ ¹ÙÀÌÆ®(byte) ¼ö¸¦ ¸®ÅÏÇϰí, Á¦ÇÑÇÏ·Á´Â ¹ÙÀÌÆ®(byte) ¼ö¸¦ ÁöÁ¤ÇÏ¸é ¹®ÀÚ¿À» ÇØ´ç Å©±â¿¡ ¸Â°Ô Àß¶ó³½´Ù.(1.4.3 ºÎÅÍ charset»ç¿ë °¡´É)
* @return ¹®ÀÚ¿ÀÇ ¹ÙÀÌÆ® ¼ö. ´Ü, ù¹øÂ° ¸Å°³º¯¼ö¸¦ ¼³Á¤Çϸé Àڱ⠰´Ã¼($S)¸¦ ¸®ÅÏÇÑ´Ù.
* @param {Number|Object} nBytes ¸ÂÃâ ¹®ÀÚ¿ÀÇ ¹ÙÀÌÆ®(byte) ¼ö | charsetÀ» ÁöÁ¤ÇÒ ¶§ »ç¿ë
* @remark ¹®¼ÀÇ charsetÀ» ÇØ¼®Çؼ ÀÎÄÚµù ¹æ½Ä¿¡ µû¶ó ÇѱÛÀ» ºñ·ÔÇÑ À¯´ÏÄÚµå ¹®ÀÚ¿ÀÇ ¹ÙÀÌÆ® ¼ö¸¦ °è»êÇÑ´Ù.
* @example
// ¹®¼°¡ euc-kr ȯ°æÀÓÀ» °¡Á¤ÇÕ´Ï´Ù.
*
var str = "Çѱ۰ú English°¡ ¼¯ÀÎ ¹®Àå...";
document.write( $S(str).bytes() );
*
* // °á°ú :
* // 37
*
document.write( $S(str).bytes(20) );
*
* // °á°ú :
* // Çѱ۰ú English°¡
*
document.write( $S(str).bytes({charset:'euc-kr',size:20}) );
*
* // °á°ú :
* // Çѱ۰ú English°¡ ¼¯
*
document.write( $S(str).bytes({charset:'euc-kr'}) );
*
* // °á°ú :
* // 29
*/
jindo.$S.prototype.bytes = function(vConfig) {
var code = 0, bytes = 0, i = 0, len = this._str.length;
var charset = ((document.charset || document.characterSet || document.defaultCharset)+"");
var cut,nBytes;
if (typeof vConfig == "undefined") {
cut = false;
}else if(vConfig.constructor == Number){
cut = true;
nBytes = vConfig;
}else if(vConfig.constructor == Object){
charset = vConfig.charset||charset;
nBytes = vConfig.size||false;
cut = !!nBytes;
}else{
cut = false;
}
if (charset.toLowerCase() == "euc-kr") {
/*
À¯´ÏÄÚµå ¹®ÀÚ¿ÀÇ ¹ÙÀÌÆ® ¼ö´Â À§Å°ÇÇµð¾Æ¸¦ Âü°íÇß´Ù(http://ko.wikipedia.org/wiki/euc-kr).
*/
for(i=0; i < len; i++) {
code = this._str.charCodeAt(i);
if (code < 128) {
bytes += 1;
}else if (code < 2048){
bytes += 2;
}else if (code < 65536){
bytes += 3;
}else{
bytes += 4;
}
if (cut && bytes > nBytes) {
this._str = this._str.substr(0,i);
break;
}
}
} else {
for(i=0; i < len; i++) {
bytes += (this._str.charCodeAt(i) > 128)?2:1;
if (cut && bytes > nBytes) {
this._str = this._str.substr(0,i);
break;
}
}
}
return cut?this:bytes;
};
/**
* parseString ¸Þ¼µå´Â URL Äõ¸® ½ºÆ®¸µÀ» °´Ã¼·Î ÆÄ½ÌÇÑ´Ù.
* @return {Object} ¹®ÀÚ¿À» ÆÄ½ÌÇÑ °´Ã¼
* @example
* var str = "aa=first&bb=second";
* var obj = $S(str).parseString();
*
* // °á°ú :
* // obj => { aa : "first", bb : "second" }
*/
jindo.$S.prototype.parseString = function() {
if(this._str=="") return {};
var str = this._str.split(/&/g), pos, key, val, buf = {},isescape = false;
for(var i=0; i < str.length; i++) {
key = str[i].substring(0, pos=str[i].indexOf("=")), isescape = false;
try{
val = decodeURIComponent(str[i].substring(pos+1));
}catch(e){
isescape = true;
val = decodeURIComponent(unescape(str[i].substring(pos+1)));
}
if (key.substr(key.length-2,2) == "[]") {
key = key.substring(0, key.length-2);
if (typeof buf[key] == "undefined") buf[key] = [];
buf[key][buf[key].length] = isescape? escape(val) : val;;
} else {
buf[key] = isescape? escape(val) : val;
}
}
return buf;
};
/**
* escapeRegex ¸Þ¼µå´Â Á¤±Ô½Ä¿¡ »ç¿ëÇÒ ¼ö ÀÖµµ·Ï ¹®ÀÚ¿À» À̽ºÄÉÀÌÇÁ(escape) ÇÑ´Ù.
* @since 1.2.0
* @return {String} À̽ºÄÉÀÌÇÁµÈ ¹®ÀÚ¿
* @example
var str = "Slash / is very important. Backslash \ is more important. +_+";
document.write( $S(str).escapeRegex() );
*
* // °á°ú : \/ is very important\. Backslash \\ is more important\. \+_\+
*/
jindo.$S.prototype.escapeRegex = function() {
var s = this._str;
var r = /([\?\.\*\+\-\/\(\)\{\}\[\]\:\!\^\$\\\|])/g;
return jindo.$S(s.replace(r, "\\$1"));
};
/**
* format ¸Þ¼µå´Â ¹®ÀÚ¿À» Çü½Ä ¹®ÀÚ¿¿¡ ´ëÀÔÇÏ¿© »õ·Î¿î ¹®ÀÚ¿À» ¸¸µç´Ù. Çü½Ä ¹®ÀÚ¿Àº %·Î ½ÃÀÛÇϸç, Çü½Ä ¹®ÀÚ¿ÀÇ Á¾·ù´Â <a href="http://www.php.net/manual/en/function.sprintf.php">PHP</a>¿Í µ¿ÀÏÇÏ´Ù.
* @param {String} formatString Çü½Ä ¹®ÀÚ¿
* @return {String} ¹®ÀÚ¿À» Çü½Ä ¹®ÀÚ¿¿¡ ´ëÀÔÇÏ¿© ¸¸µç »õ·Î¿î ¹®ÀÚ¿.
* @example
var str = $S("%4d³â %02d¿ù %02dÀÏ").format(2008, 2, 13);
*
* // °á°ú :
* // str = "2008³â 02¿ù 13ÀÏ"
var str = $S("ÆÐµù %5s ºó°ø¹é").format("°ª");
*
* // °á°ú :
* // str => "ÆÐµù °ª ºó°ø¹é"
var str = $S("%b").format(10);
*
* // °á°ú :
* // str => "1010"
var str = $S("%x").format(10);
*
* // °á°ú :
* // str => "a"
var str = $S("%X").format(10);
*
* // °á°ú :
* // str => "A"
* @see $S#times
*/
jindo.$S.prototype.format = function() {
var args = arguments;
var idx = 0;
var s = this._str.replace(/%([ 0])?(-)?([1-9][0-9]*)?([bcdsoxX])/g, function(m0,m1,m2,m3,m4){
var a = args[idx++];
var ret = "", pad = "";
m3 = m3?+m3:0;
if (m4 == "s") {
ret = a+"";
} else if (" bcdoxX".indexOf(m4) > 0) {
if (typeof a != "number") return "";
ret = (m4 == "c")?String.fromCharCode(a):a.toString(({b:2,d:10,o:8,x:16,X:16})[m4]);
if (" X".indexOf(m4) > 0) ret = ret.toUpperCase();
}
if (ret.length < m3) pad = jindo.$S(m1||" ").times(m3 - ret.length).toString();
(m2 == '-')?(ret+=pad):(ret=pad+ret);
return ret;
});
return jindo.$S(s);
};
/**
* @fileOverview $Document »ý¼ºÀÚ ¹× ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name document.js
*/
/**
* $Document °´Ã¼¸¦ »ý¼ºÇÏ°í ¸®ÅÏÇÑ´Ù.
* @class $Document Ŭ·¡½º´Â ¹®¼¿Í °ü·ÃµÈ ¿©·¯°¡Áö ±â´ÉÀÇ ¸Þ¼µå¸¦ Á¦°øÇÑ´Ù
* @param {Document} doc ±â´É¿¡ »ç¿ëµÈ document °´Ã¼. ±âº»°ªÀº ÇöÀç ¹®¼ÀÇ document.
* @constructor
* @author Hooriza
*/
jindo.$Document = function (el) {
var cl = arguments.callee;
if (el instanceof cl) return el;
if (!(this instanceof cl)) return new cl(el);
this._doc = el || document;
this._docKey = this.renderingMode() == 'Standards' ? 'documentElement' : 'body';
};
/**
* $value ¸Þ¼µå´Â ¿ø·¡ÀÇ document °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @return {HTMLDocument} document °´Ã¼
*/
jindo.$Document.prototype.$value = function() {
return this._doc;
};
/**
* scrollSize ¸Þ¼µå´Â ¹®¼ÀÇ ½ÇÁ¦ °¡·Î, ¼¼·Î Å©±â¸¦ ±¸ÇÑ´Ù
* @return {Object} °¡·ÎÅ©±â´Â width, ¼¼·ÎÅ©±â´Â height ¶ó´Â ۰ªÀ¸·Î ¸®ÅϵȴÙ.
* @example
var size = $Document().scrollSize();
alert('°¡·Î : ' + size.width + ' / ¼¼·Î : ' + size.height);
*/
jindo.$Document.prototype.scrollSize = function() {
/*
webkit °è¿¿¡¼´Â Standard ¸ðµå¶óµµ body¸¦ »ç¿ëÇØ¾ß Á¤»óÀûÀÎ scroll Size¸¦ ¾ò¾î¿Â´Ù.
*/
var isWebkit = navigator.userAgent.indexOf("WebKit")>-1;
var oDoc = this._doc[isWebkit?'body':this._docKey];
return {
width : Math.max(oDoc.scrollWidth, oDoc.clientWidth),
height : Math.max(oDoc.scrollHeight, oDoc.clientHeight)
};
};
/**
* scrollPosition ¸Þ¼µå´Â ¹®¼ÀÇ ½ºÅ©·Ñ¹Ù À§Ä¡¸¦ ±¸ÇÑ´Ù
* @return {Object} °¡·Î À§Ä¡´Â left, ¼¼·ÎÀ§Ä¡´Â top ¶ó´Â ۰ªÀ¸·Î ¸®ÅϵȴÙ.
* @example
var size = $Document().scrollPosition();
alert('°¡·Î : ' + size.left + ' / ¼¼·Î : ' + size.top);
* @since 1.3.5
*/
jindo.$Document.prototype.scrollPosition = function() {
/*
webkit °è¿¿¡¼´Â Standard ¸ðµå¶óµµ body¸¦ »ç¿ëÇØ¾ß Á¤»óÀûÀÎ scroll Size¸¦ ¾ò¾î¿Â´Ù.
*/
var isWebkit = navigator.userAgent.indexOf("WebKit")>-1;
var oDoc = this._doc[isWebkit?'body':this._docKey];
return {
left : oDoc.scrollLeft||window.pageXOffset||window.scrollX||0,
top : oDoc.scrollTop||window.pageYOffset||window.scrollY||0
};
};
/**
* clientSize ¸Þ¼µå´Â ½ºÅ©·Ñ¹Ù·Î ÀÎÇØ °¡·ÁÁø ºÎºÐÀ» Á¦¿ÜÇÑ ¹®¼ Áß º¸ÀÌ´Â ºÎºÐÀÇ °¡·Î, ¼¼·Î Å©±â¸¦ ±¸ÇÑ´Ù
* @return {Object} °¡·ÎÅ©±â´Â width, ¼¼·ÎÅ©±â´Â height ¶ó´Â ۰ªÀ¸·Î ¸®ÅϵȴÙ
* @example
var size = $Document(document).clientSize();
alert('°¡·Î : ' + size.width + ' / ¼¼·Î : ' + size.height);
*/
jindo.$Document.prototype.clientSize = function() {
var agent = navigator.userAgent;
var oDoc = this._doc[this._docKey];
var isSafari = agent.indexOf("WebKit")>-1 && agent.indexOf("Chrome")==-1;
/*
»çÆÄ¸®ÀÇ °æ¿ì À©µµ¿ì ¸®»çÀÌÁî½Ã¿¡ clientWidth,clientHeight°ªÀÌ Á¤»óÀûÀ¸·Î ³ª¿ÀÁö ¾Ê¾Æ¼ window.innerWidth,innerHeight·Î ´ëü
*/
return (isSafari)?{
width : window.innerWidth,
height : window.innerHeight
}:{
width : oDoc.clientWidth,
height : oDoc.clientHeight
};
};
/**
* renderingMode ¸Þ¼µå´Â ¹®¼ÀÇ ·»´õ¸µ ¹æ½ÄÀ» ¾ò´Â´Ù
* @return {String} ·»´õ¸µ ¸ðµå
* <dl>
* <dt>Standards</dt>
* <dd>Ç¥ÁØ ·»´õ¸µ ¸ðµå</dd>
* <dt>Almost</dt>
* <dd>À¯»ç Ç¥ÁØ ·»´õ¸µ ¸ðµå (IE ¿ÜÀÇ ºê¶ó¿ìÀú¿¡¼ DTD À» ¿Ã¹Ù¸£°Ô ÁöÁ¤ÇÏÁö ¾Ê¾ÒÀ»¶§ ¸®ÅÏ)</dd>
* <dt>Quirks</dt>
* <dd>ºñÇ¥ÁØ ·»´õ¸µ ¸ðµå</dd>
* </dl>
* @example
var mode = $Document().renderingMode();
alert('·»´õ¸µ ¹æ½Ä : ' + mode);
*/
jindo.$Document.prototype.renderingMode = function() {
var agent = navigator.userAgent;
var isIe = (typeof window.opera=="undefined" && agent.indexOf("MSIE")>-1);
var isSafari = (agent.indexOf("WebKit")>-1 && agent.indexOf("Chrome")<0 && navigator.vendor.indexOf("Apple")>-1);
var sRet;
if ('compatMode' in this._doc){
sRet = this._doc.compatMode == 'CSS1Compat' ? 'Standards' : (isIe ? 'Quirks' : 'Almost');
}else{
sRet = isSafari ? 'Standards' : 'Quirks';
}
return sRet;
};
/**
* ¹®¼¿¡¼ ÁÖ¾îÁø selector¸¦ ¸¸Á·½ÃŰ´Â ¿ä¼ÒÀÇ ¹è¿À» ¹ÝȯÇÑ´Ù. ¸¸Á·ÇÏ´Â ¿ä¼Ò°¡ Á¸ÀçÇÏÁö ¾ÊÀ¸¸é ºó ¹è¿À» ¹ÝȯÇÑ´Ù.
* @param {String} sSelector
* @return {Array} Á¶°ÇÀ» ¸¸Á·ÇÏ´Â ¿ä¼ÒÀÇ ¹è¿
*/
jindo.$Document.prototype.queryAll = function(sSelector) {
return jindo.$$(sSelector, this._doc);
};
/**
* ¹®¼¿¡¼ ÁÖ¾îÁø selector¸¦ ¸¸Á·½ÃŰ´Â ¿ä¼ÒÁß Ã¹ ¹øÂ° ¿ä¼Ò¸¦ ¹ÝȯÇÑ´Ù. ¸¸Á·ÇÏ´Â ¿ä¼Ò°¡ Á¸ÀçÇÏÁö ¾ÊÀ¸¸é nullÀ» ¹ÝȯÇÑ´Ù.
* @param {String} sSelector
* @return {Element} Á¶°ÇÀ» ¸¸Á·ÇÏ´Â ¿ä¼ÒÁß Ã¹¹øÂ° ¿ä¼Ò
*/
jindo.$Document.prototype.query = function(sSelector) {
return jindo.$$.getSingle(sSelector, this._doc);
};
/**
* ¹®¼¿¡¼ XPath ¹®¹ý¿¡ ÇØ´çÇÏ´Â ¸ðµç ¿¤¸®¸ÕÆ®¸¦ ¹è¿·Î ¸®ÅÏÇÑ´Ù.
* @remark Áö¿øÇÏ´Â ¹®¹ý¿¡ Á¦¾à »çÇ×ÀÌ ¸¹À¸¹Ç·Î Ư¼öÇÑ °æ¿ì¿¡¸¸ »ç¿ëÇÑ´Ù.
* @param {String} sXPath ¿¤¸®¸ÕÆ®ÀÇ À§Ä¡¸¦ ÁöÁ¤ÇÑ XPath °ª
* @return {Array} path¿¡ ÇØ´çÇÏ´Â ¿ä¼ÒÀÇ ¹è¿
* @example
var oDocument = $Document();
alert (oDocument.xpathAll("body/div/div").length);
*/
jindo.$Document.prototype.xpathAll = function(sXPath) {
return jindo.$$.xpath(sXPath, this._doc);
};
/**
* @fileOverview $Form »ý¼ºÀÚ ¹× ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name form.js
*/
/**
* $Form °´Ã¼¸¦ »ý¼º ¹× ¸®ÅÏÇÑ´Ù.
* @class $Form Ŭ·¡½º´Â form ¿¤¸®¸ÕÆ®¿Í ÀÚ½Ä ¿¤¸®¸ÕÆ®¸¦ Á¦¾îÇϴ Ŭ·¡½ºÀÌ´Ù.
* @param {Element | String} el Æû(form) ¿¤¸®¸ÕÆ®, ȤÀº Æû ¿¤¸®¸ÕÆ®ÀÇ id. ¸¸¾à µ¿ÀÏÇÑ id¸¦ µÎ °³ ÀÌ»óÀÇ ¿¤¸®¸ÕÆ®¿¡¼ »ç¿ëÇÏ¸é ¸ÕÀú ³ª¿À´Â ¿¤¸®¸ÕÆ®¸¦ ¸®ÅÏÇÑ´Ù.
* @constructor
* @author Hooriza
*/
jindo.$Form = function (el) {
var cl = arguments.callee;
if (el instanceof cl) return el;
if (!(this instanceof cl)) return new cl(el);
el = jindo.$(el);
if (!el.tagName || el.tagName.toUpperCase() != 'FORM') throw new Error('The element should be a FORM element');
this._form = el;
}
/**
* $value ¸Þ¼µå´Â ·¦ÇÎµÈ ¿ø·¡ Æû ¿¤¸®¸ÕÆ®¸¦ ¸®ÅÏÇÑ´Ù
* @return {HTMLElement} Æû ¿¤¸®¸ÕÆ®
* @example
var el = $('<form>');
var form = $Form(el);
alert(form.$value() === el); // true
*/
jindo.$Form.prototype.$value = function() {
return this._form;
};
/**
* serialize ¸Þ¼µå´Â ƯÁ¤ ¶Ç´Â Àüü ¿¤¸®¸àÆ® ÀԷ¿ä¼Ò¸¦ ¹®ÀÚ¿ ÇüÅ·Π¸®ÅÏÇÑ´Ù.
* @param {Mixed} Mixed Àμö¸¦ ÁöÁ¤ÇÏÁö ¾Ê°Å³ª Àμö¸¦ Çϳª ÀÌ»ó ¼³Á¤ÇÒ ¼ö ÀÖ´Ù.
* <ol>
* <li>¸Å°³ º¯¼ö¸¦ ÁöÁ¤ÇÏÁö ¾ÊÀ¸¸é Æû ¿¤¸®¸ÕÆ®¿Í ÀÚ½Ä ¿¤¸®¸ÕÆ®ÀÇ ¸ðµç °ªÀ» Äõ¸® ÇüÅÂÀÇ ¹®ÀÚ¿·Î ¸®ÅÏÇÑ´Ù.</li>
* <li>¸Å°³ º¯¼ö·Î ¹®ÀÚ¿À» ¼³Á¤ÇÏ¸é ¹®ÀÚ¿°ú ÀÏÄ¡ÇÏ´Â name ¼Ó¼ºÀ» °¡Áö´Â ¿¤¸®¸ÕÆ®¸¦ Ž»öÇÏ°í °ªÀ» ¸®ÅÏÇÑ´Ù.</li>
* <li>¸Å¹è º¯¼ö·Î µÎ °³ ÀÌ»óÀÇ ¹®ÀÚ¿À» ¼³Á¤Çϸé, ¹®ÀÚ¿°ú ÀÏÄ¡ÇÏ´Â name ¼Ó¼ºÀ» °¡Áö´Â ¿¤¸®¸ÕÆ®¸¦ ¸ðµÎ Ž»öÇÏ°í °ªÀ» Äõ¸® ½ºÆ®¸µ ÇüÅ·Π¸®ÅÏÇÑ´Ù. </li>
* </ol>
* @return {String} Äõ¸® ¹®ÀÚ¿ ÇüÅ·Πº¯È¯ÇÑ ¿¤¸®¸ÕÆ®¿Í ±× °ª.
* @example
<form id="TEST">
<input name="ONE" value="1" type="text" />
<input name="TWO" value="2" checked="checked" type="checkbox" />
<input name="THREE" value="3_1" type="radio" />
<input name="THREE" value="3_2" checked="checked" type="radio" />
<input name="THREE" value="3_3" type="radio" />
<select name="FOUR">
<option value="4_1">..</option>
<option value="4_2">..</option>
<option value="4_3" selected="selected">..</option>
</select>
</form>
<script type="text/javascript">
var form = $Form('TEST');
var allstr = form.serialize();
alert(allstr == 'ONE=1&TWO=2&THREE=3_2&FOUR=4_3'); // true
var str = form.serialize('ONE', 'THREE');
alert(str == 'ONE=1&THREE=3_2'); // true
</script>
*/
jindo.$Form.prototype.serialize = function() {
var self = this;
var oRet = {};
var nLen = arguments.length;
var fpInsert = function(sKey) {
var sVal = self.value(sKey);
if (typeof sVal != 'undefined') oRet[sKey] = sVal;
};
if (nLen == 0) {
jindo.$A(this.element()).forEach(function(o) { if (o.name) fpInsert(o.name); });
}else{
for (var i = 0; i < nLen; i++) {
fpInsert(arguments[i]);
}
}
return jindo.$H(oRet).toQueryString();
};
/**
* element ¸Þ¼µå´Â ƯÁ¤ ¶Ç´Â Àüü ÀԷ¿ä¼Ò¸¦ ¸®ÅÏÇÑ´Ù.
* @param {String} sKey ¾ò°íÀÚ ÇÏ´Â ÀԷ¿ä¼Ò ¿¤¸®¸ÕÆ®ÀÇ name ¹®ÀÚ¿, »ý·«½Ã¿¡´Â ¸ðµç ÀԷ¿ä¼ÒµéÀ» ¹è¿·Î ¸®ÅÏÇÑ´Ù.
* @return {HTMLElement | Array} ÀÔ·Â ¿ä¼Ò ¿¤¸®¸ÕÆ®
*/
jindo.$Form.prototype.element = function(sKey) {
if (arguments.length > 0)
return this._form[sKey];
return this._form.elements;
};
/**
* enable ¸Þ¼µå´Â ÀÔ·Â ¿ä¼ÒÀÇ È°¼ºÈ ¿©ºÎ¸¦ ¾ò°Å³ª ¼³Á¤ÇÑ´Ù.
* @param {Mixed} mixed enable ¸Þ¼µå´Â ¸Å°³ º¯¼öÀÇ °³¼ö³ª Á¾·ù¿¡ µû¶ó ´Ù¸£°Ô µ¿ÀÛÇÑ´Ù. ÀÚ¼¼ÇÑ »ç¿ë¹ýÀº ´ÙÀ½°ú °°´Ù.
* <ol>
* <li> ¸Å°³ º¯¼ö·Î ¹®ÀÚ¿À» »ç¿ëÇÏ¸é ¹®ÀÚ¿°ú ÀÏÄ¡ÇÏ´Â name ¼Ó¼ºÀ» °¡Áø ¿¤¸®¸ÕÆ®¸¦ Ž»öÇÑ´Ù. ¿¤¸®¸ÕÆ®¸¦ ¹ß°ßÇß´Ù¸é ¿¤¸®¸ÕÆ®ÀÇ È°¼ºÈ ¿©ºÎ¸¦ ¸®ÅÏÇÑ´Ù.</li>
* <li> ¸Å°³ º¯¼ö·Î ¹®ÀÚ¿°ú ºÒ¸°(Boolean)À» »ç¿ëÇÏ¸é ¹®ÀÚ¿°ú ÀÏÄ¡ÇÏ´Â name ¼Ó¼ºÀ» °¡Áø ¿¤¸®¸ÕÆ®¸¦ Ž»öÇÑ ÈÄ, Ȱ¼ºÈ ¿©ºÎ¸¦ ¼³Á¤ÇÑ´Ù. </li>
* <li> ¸Å°³ º¯¼ö·Î °´Ã¼¸¦ »ç¿ëÇÒ ¼ö ÀÖ´Ù. °´Ã¼´Â ¼Ó¼º °ª°ú nameÀÌ ÀÏÄ¡ÇÏ´Â ¿¤¸®¸ÕÆ®¸¦ Ž»öÇØ¼ °ª¿¡ µû¶ó Ȱ¼ºÈ ¿©ºÎ¸¦ ¼³Á¤ÇÑ´Ù. </li>
* </ol>
* @return {Boolean|$Form} ¿¤¸®¸ÕÆ®ÀÇ È°¼ºÈ ¿©ºÎ¸¦ °¡Á®¿À°Å³ª ¿¤¸®¸ÕÆ®ÀÇ È°¼ºÈ ¿©ºÎ¸¦ ¼³Á¤ÇÑ $Form °´Ã¼.
* @example
<form id="TEST">
<input name="ONE" disabled="disabled" type="text" />
<input name="TWO" type="checkbox" />
</form>
<script type="text/javascript">
var form = $Form('TEST');
var one_enabled = form.enable('ONE');
alert(one_enabled === false); // true
form.enable('TWO', false);
form.enable({
'ONE' : true,
'TWO' : false
});
</script>
*/
jindo.$Form.prototype.enable = function() {
var sKey = arguments[0];
if (typeof sKey == 'object') {
var self = this;
jindo.$H(sKey).forEach(function(bFlag, sKey) { self.enable(sKey, bFlag); });
return this;
}
var aEls = this.element(sKey);
if (!aEls) return this;
aEls = aEls.nodeType == 1 ? [ aEls ] : aEls;
if (arguments.length < 2) {
var bEnabled = true;
jindo.$A(aEls).forEach(function(o) { if (o.disabled) {
bEnabled = false;
jindo.$A.Break();
}});
return bEnabled;
} else { // setter
var sFlag = arguments[1];
jindo.$A(aEls).forEach(function(o) { o.disabled = !sFlag; });
return this;
}
};
/**
* value ¸Þ¼µå´Â Æû ¿¤¸®¸ÕÆ®ÀÇ °ªÀ» ¾ò°Å³ª ¼³Á¤ÇÑ´Ù.
* @param {Mixed} Mixed Á¤È®¾È Àμö Á¤º¸´Â ´ÙÀ½°ú °°´Ù.
* <ol>
* <li>¸Å°³ º¯¼ö·Î ¹®ÀÚ¿À» ¼³Á¤Çϸé name ¼Ó¼ºÀÌ ÀÏÄ¡ÇÏ´Â ¾Ù¸®¸ÕÆ®¸¦ Ž»öÇÏ°í °ªÀ» ¸®ÅÏÇÑ´Ù</li>
* <li>¸Å°³ º¯¼ö·Î µÎ °³ÀÇ ¹®ÀÚ¿°ú ºÒ¸° °ªÀ» name ¼Ó¼ºÀÌ ÀÏÄ¡ÇÏ´Â ¾Ù¸®¸ÕÆ®¸¦ Ž»öÇÏ°í °ªÀ» ¼³Á¤ÇÑ´Ù. </br> checkbox, radio, selectbox´Â ¿¤¸®¸ÕÆ®¸¦ ¼±ÅÃ/¼±ÅÃ ÇØÁ¦ ÇÑ´Ù.</li>
* <li>µÎ °³ ÀÌ»óÀÇ ¿¤¸®¸ÕÆ® °ªÀ» µ¿½Ã¿¡ ÁöÁ¤ÇÏ°í ½ÍÀ¸¸é '¿¤¸®¸ÕÆ® À̸§ : ¿¤¸®¸ÕÆ® °ª'À» ¿ø¼Ò·Î °¡Áö´Â °´Ã¼¸¦ ¸Å°³ º¯¼ö·Î ¼³Á¤ÇÑ´Ù.</li>
* </ol>
* @return {String|$Form} Àμö·Î ¿¤¸®¸ÕÆ®¸¸ ÁöÁ¤Çß´Ù¸é ÁöÁ¤ÇÑ ¿¤¸®¸ÕÆ®ÀÇ °ªÀ», Àμö·Î Æû ¿¤¸®¸Õ¿Í ¿¤¸®¸ÕÆ®ÀÇ °ªÀ» ÁöÁ¤Çß´Ù¸é $Form °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @example
<form id="TEST">
<input name="ONE" value="1" type="text" />
<input name="TWO" value="2" type="checkbox" />
</form>
<script type="text/javascript">
var form = $Form('TEST');
var one_value = form.value('ONE');
alert(one_value === '1'); // true
var two_value = form.value('TWO');
alert(two_value === undefined); // true
form.value('TWO', 2);
alert(two_value === '2'); // true
form.value({
'ONE' : '1111',
'TWO' : '2'
});
// form.value('ONE') -> 1111
// form.value('ONE') -> 2
</script>
*/
jindo.$Form.prototype.value = function(sKey) {
if (typeof sKey == 'object') {
var self = this;
jindo.$H(sKey).forEach(function(bFlag, sKey) { self.value(sKey, bFlag); });
return this;
}
var aEls = this.element(sKey);
if (!aEls) throw new Error('¿¤¸®¸ÕÆ®´Â Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù.');
aEls = aEls.nodeType == 1 ? [ aEls ] : aEls;
if (arguments.length > 1) { // setter
var sVal = arguments[1];
jindo.$A(aEls).forEach(function(o) {
switch (o.type) {
case 'radio':
o.checked = (o.value == sVal);
break;
case 'checkbox':
if(sVal.constructor == Array){
o.checked = jindo.$A(sVal).has(o.value);
}else{
o.checked = (o.value == sVal);
}
break;
case 'select-one':
var nIndex = -1;
for (var i = 0, len = o.options.length; i < len; i++){
if (o.options[i].value == sVal) nIndex = i;
}
o.selectedIndex = nIndex;
break;
case 'select-multiple':
var nIndex = -1;
if(sVal.constructor == Array){
var waVal = jindo.$A(sVal);
for (var i = 0, len = o.options.length; i < len; i++){
o.options[i].selected = waVal.has(o.options[i].value);
}
}else{
for (var i = 0, len = o.options.length; i < len; i++){
if (o.options[i].value == sVal) nIndex = i;
}
o.selectedIndex = nIndex;
}
break;
default:
o.value = sVal;
break;
}
});
return this;
}
// getter
var aRet = [];
jindo.$A(aEls).forEach(function(o) {
switch (o.type) {
case 'radio':
case 'checkbox':
if (o.checked) aRet.push(o.value);
break;
case 'select-one':
if (o.selectedIndex != -1) aRet.push(o.options[o.selectedIndex].value);
break;
case 'select-multiple':
if (o.selectedIndex != -1){
for (var i = 0, len = o.options.length; i < len; i++){
if (o.options[i].selected) aRet.push(o.options[i].value);
}
}
break;
default:
aRet.push(o.value);
break;
}
});
return aRet.length > 1 ? aRet : aRet[0];
};
/**
* submit ¸Þ¼µå´Â ÆûÀÇ µ¥ÀÌÅ͸¦ À¥À¸·Î Á¦Ãâ(submit) ÇÑ´Ù.
* @param {String} sTargetName Á¦ÃâÇÒ ÆûÀÌ ÀÖ´Â À©µµ¿ìÀÇ À̸§. sTargetNameÀ» »ý·«ÇÏ¸é ±âº» Ÿ°Ù
* @param {String} fValidation Á¦ÃâÇÒ ÆûÀÇ ¹ë¸®µ¥ÀÌ¼Ç ÇÔ¼ö. form ¿ä¼Ò¸¦ ÀÎÀÚ·Î ¹Þ´Â´Ù.
* @return {$Form} µ¥ÀÌÅ͸¦ Á¦ÃâÇÑ $Form °´Ã¼.
* @example
var form = $Form(el);
form.submit();
form.submit('foo');
*/
jindo.$Form.prototype.submit = function(sTargetName, fValidation) {
var sOrgTarget = null;
if (typeof sTargetName == 'string') {
sOrgTarget = this._form.target;
this._form.target = sTargetName;
}
if(typeof sTargetName == 'function') fValidation = sTargetName;
if(typeof fValidation != 'undefined'){
if(!fValidation(this._form)) return this;
}
this._form.submit();
if (sOrgTarget !== null)
this._form.target = sOrgTarget;
return this;
};
/**
* reset ¸Þ¼µå´Â ÆûÀ» ÃʱâÈ(reset)ÇÑ´Ù.
* @param {String} fValidation Á¦ÃâÇÒ ÆûÀÇ ¹ë¸®µ¥ÀÌ¼Ç ÇÔ¼ö. form ¿ä¼Ò¸¦ ÀÎÀÚ·Î ¹Þ´Â´Ù.
* @return {$Form} ÃʱâÈÇÑ $Form °´Ã¼.
* @example
var form = $Form(el);
form.reset();
*/
jindo.$Form.prototype.reset = function(fValidation) {
if(typeof fValidation != 'undefined'){
if(!fValidation(this._form)) return this;
}
this._form.reset();
return this;
};
/**
* @fileOverview $TemplateÀÇ »ý¼ºÀÚ ¹× ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name template.js
*/
/**
* $Template °´Ã¼¸¦ »ý¼ºÇÑ´Ù.
* @class $Template Ŭ·¡½º´Â ÅÛÇø´À» ÇØ¼®ÇÏ¿© ÅÛÇø´ ¹®ÀÚ¿¿¡ µ¿ÀûÀ¸·Î ¹®ÀÚ¸¦ »ðÀÔÇÑ´Ù.
* @constructor
* @author Kim, Taegon
*
* @param {String | HTML Element | $Template} str
* <br>
* $Template Àº ¹®ÀÚ¿, HTML ¿¤¸®¸ÕÆ®, ȤÀº $Template À» ÀÎÀÚ·Î ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.<br>
* <br>
* ÀÎÀÚ°¡ ¹®ÀÚ¿ÀÌ¸é µÎ °¡Áö ¹æ½ÄÀ¸·Î µ¿ÀÛÇÑ´Ù.<br>
* ¸¸ÀÏ ¹®ÀÚ¿ÀÌ HTML ¿¤¸®¸ÕÆ®ÀÇ id ¶ó¸é HTML ¿¤¸®¸ÕÆ®ÀÇ innerHTML À» ÅÛÇø´À¸·Î »ç¿ëÇÑ´Ù.<br>
* ¸¸¾à ÀÏ¹Ý ¹®ÀÚ¿À̶ó¸é ¹®ÀÚ¿ ÀÚü¸¦ ÅÛÇø´À¸·Î »ç¿ëÇÑ´Ù.<br>
* <br>
* ÀÎÀÚ°¡ HTML ¿¤¸®¸ÕÆ®À̸é TEXTAREA ¿Í SCRIPT ¸¸ÀÌ »ç¿ë °¡´ÉÇÏ´Ù.<br>
* HTML ¿¤¸®¸ÕÆ® value °ªÀÇ ¹®ÀÚ¿À» ÅÛ Çø´À¸·Î »ç¿ëÇϸç, value °ªÀÌ ¾ø´Â °æ¿ì HTML ¿¤¸®¸ÕÆ®ÀÇ innerHTMLÀ» ÅÛÇø´À¸·Î »ç¿ëÇÑ´Ù.<br>
* <br>
* ÀÎÀÚ°¡ $Template À̸é Àü´ÞµÈ ÀÎÀÚ¸¦ ±×´ë·Î ¹ÝȯÇϸç ÀÎÀÚ¸¦ »ý·«Çϸé "" ¸¦ ÅÛÇø´À¸·Î »ç¿ëÇÑ´Ù.
* @return {$Template} »ý¼ºµÈ $Template °´Ã¼
*
* @remark ÀÎÀÚ°¡ SCRIPTÀÎ °æ¿ìÀÇ typeÀº ¹Ýµå½Ã "text/template"À¸·Î ÁöÁ¤ÇØ¾ß ÇÑ´Ù.
*
* @example
// ÀÎÀÚ°¡ ÀÏ¹Ý ¹®ÀÚ¿ÀÎ °æ¿ì
var tpl = $Template("{=service} : {=url}");
*
* @example
<textarea id="tpl1">
{=service} : {=url}
</textarea>
// °°Àº TEXTAREA ¿¤¸®¸ÕÆ®¸¦ ÅÛÇø´À¸·Î »ç¿ëÇÑ´Ù
var template1 = $Template("tpl1"); // ÀÎÀÚ°¡ HTML ¿¤¸®¸ÕÆ®ÀÇ id ¾ÆÀ̵ð
var template2 = $Template($("tpl1")); // ÀÎÀÚ°¡ TEXTAREA ¿¤¸®¸ÕÆ®ÀÎ °æ¿ì
</script>
*
* @example
<script type="text/template" id="tpl2">
{=service} : {=url}
</script>
// °°Àº SCRIPT ¿¤¸®¸ÕÆ®¸¦ ÅÛÇø´À¸·Î »ç¿ëÇÑ´Ù
var template1 = $Template("tpl2"); // ÀÎÀÚ°¡ HTML ¿¤¸®¸ÕÆ®ÀÇ id ¾ÆÀ̵ð
var template2 = $Template($("tpl2")); // ÀÎÀÚ°¡ SCRIPT ¿¤¸®¸ÕÆ®ÀÎ °æ¿ì
*/
jindo.$Template = function(str) {
var obj = null, tag = "";
var cl = arguments.callee;
if (str instanceof cl) return str;
if (!(this instanceof cl)) return new cl(str);
if(typeof str == "undefined") {
str = "";
}else if( (obj=document.getElementById(str)||str) && obj.tagName && (tag=obj.tagName.toUpperCase()) && (tag == "TEXTAREA" || (tag == "SCRIPT" && obj.getAttribute("type") == "text/template")) ) {
str = (obj.value||obj.innerHTML).replace(/^\s+|\s+$/g,"");
}
this._str = str+"";
}
jindo.$Template.splitter = /(?!\\)[\{\}]/g;
jindo.$Template.pattern = /^(?:if (.+)|elseif (.+)|for (?:(.+)\:)?(.+) in (.+)|(else)|\/(if|for)|=(.+)|js (.+)|set (.+))$/;
/**
* ÅÛÇø´À» ÇØ¼®ÇÏ°í µ¥ÀÌÅ͸¦ Àû¿ëÇÏ¿© »õ·Î¿î ¹®ÀÚ¿À» »ý¼ºÇÑ´Ù.<br>
* <br>
* ÅÛÇø´À» ÇØ¼®ÇÒ ¶§¿¡<br>
* ÅÛÇø´ ³»¿¡ ÆÐÅÏÀÌ ÀÖÀ¸¸é ÆÐÅÏ¿¡ µû¶ó ÅÛÇø´À» ÇØ¼®ÇÏ´Â ¹æ¹ýÀÌ ´Ù¸£´Ù.(°¢ ÆÐÅÏÀÇ ÇØ¼®Àº ¿¹Á¦¸¦ Âü°íÇÑ´Ù)<br>
* ÅÛÇø´ ³»¿¡ ÆÐÅÏÀÌ ¾øÀ¸¸é ´Ü¼ø ¹®ÀÚ¿ ġȯÀ¸·Î ó¸®ÇÑ´Ù.
* @param {Object} data ÅÛÇø´¿¡ µé¾î°¥ µ¥ÀÌÅ͸¦ °¡Áö´Â °´Ã¼<br>
* ÅÛÇø´¿¡ µ¥ÀÌÅ͸¦ Àû¿ëÇÒ ºÎºÐÀº °´Ã¼ÀÇ ÇÁ·ÎÆÛƼ(property) À̸§À¸·Î ã´Â´Ù.
* @return {String} ÅÛÇø´À» ÇØ¼®ÇÏ°í µ¥ÀÌÅ͸¦ Àû¿ëÇÑ »õ·Î¿î ¹®ÀÚ¿
*
* @example
// ´Ü¼ø ¹®ÀÚ¿ ġȯ
// {=value} ºÎºÐÀÇ °ªÀ» ġȯÇÑ´Ù.
?var tpl = $Template("Value1 : {=val1}, Value2 : {=val2}")
var data = { val1: "first value", val2: "second value" };
document.write( tpl.process(data) );
// °á°ú
// ?Value1 : first value, Value2 : second value
* @example
// ?if/elseif/else : Á¶°Ç¹®
// ÅÛÇø´À» ÇØ¼®ÇÒ ¶§ Á¶°Ç¹®À» ÆÇ´ÜÇÏ¿© ó¸®ÇÑ´Ù.
?var tpl= $Template("{if num >= 7}7º¸´Ù Å©°Å³ª °°´Ù.{elseif num <= 5}5º¸´Ù À۰ųª °°´Ù.{else}¾Æ¸¶ 6?{/if}");
var data = { num: 5 };
document.write( tpl.process(data) );
// °á°ú
// 5º¸´Ù À۰ųª °°´Ù.
* @example
// set : Àӽà º¯¼ö »ç¿ë
// set val=1 ·Î ¼³Á¤ÇÏ´Â °æ¿ì {=val} ºÎºÐ¿¡ 1À» ´ëÀÔÇÑ´Ù.
?var tpl = $Template("{set val3=val1}Value1 : {=val1}, Value2 : {=val2}, Value3 : {=val3}")
var data = { val1: "first value", val2: "second value" };
document.write( tpl.process(data) );
// °á°ú
?// Value1 : first value, Value2 : second value, Value3 : first value
* @example
// ?js : JavaScript »ç¿ë
// ÅÛÇø´À» ÇØ¼®ÇÒ ¶§ ÇØ´ç JavaScript¸¦ ½ÇÇàÇÑ´Ù.
?var tpl = $Template("Value1 : {js $S(=val1).bytes()}, Value2 : {=val2}")
var data = { val1: "first value", val2: "second value" };
document.write( tpl.process(data) );
// °á°ú
// ?Value1 : 11, Value2 : second value
* @example
// ?for in : ¹Ýº¹¹®(À妽º¸¦ »ç¿ëÇÏÁö ¾Ê´Â °æ¿ì)
?var tpl = $Template("<h1>Æ÷Å» »çÀÌÆ®</h1>\n<ul>{for site in portals}\n<li><a href='{=site.url}'>{=site.name}</a></li>{/for}\n</ul>");
var data = { portals: [
{ name: "³×À̹ö", url : "http://www.naver.com" },
{ name: "´ÙÀ½", url : "http://www.daum.net" },
{ name: "¾ßÈÄ", url : "http://www.yahoo.co.kr" }
]};
document.write( tpl.process(data) );
// °á°ú
//<h1>?Æ÷Å» »çÀÌÆ®</h1>
//<ul>
//<li><a href='http://www.naver.com'>³×À̹ö</a></li>
//<li><a href='http://www.daum.net'>´ÙÀ½</a></li>
//<li><a href='http://www.yahoo.co.kr'>¾ßÈÄ</a></li>
//</ul>
* @example
// ?for: ¹Ýº¹¹®(À妽º¸¦ »ç¿ëÇÏ´Â °æ¿ì)
?var tpl = $Template("{for num:word in numbers}{=word}({=num}){/for}");
var data = { numbers: ["zero", "one", "two", "three"] };
document.write( tpl.process(data) );
// °á°ú
// ?zero(0) one(1) two(2) three(3)
*/
jindo.$Template.prototype.process = function(data) {
var key = "\x01";
var leftBrace = "\x02";
var rightBrace = "\x03";
var tpl = (" "+this._str+" ").replace(/\\{/g,leftBrace).replace(/\\}/g,rightBrace).replace(/(?!\\)\}\{/g, "}"+key+"{").split(jindo.$Template.splitter), i = tpl.length;
var map = {'"':'\\"','\\':'\\\\','\n':'\\n','\r':'\\r','\t':'\\t','\f':'\\f'};
var reg = [/(["'](?:(?:\\.)+|[^\\["']+)*["']|[a-zA-Z_][\w\.]*)/g, /[\n\r\t\f"\\]/g, /^\s+/, /\s+$/, /#/g];
var cb = [function(m){ return (m.substring(0,1)=='"' || m.substring(0,1)=='\''||m=='null')?m:"d."+m; }, function(m){return map[m]||m}, "", ""];
var stm = [];
var lev = 0;
// remove " "
tpl[0] = tpl[0].substr(1);
tpl[i-1] = tpl[i-1].substr(0, tpl[i-1].length-1);
// no pattern
if(i<2) return tpl[0];
tpl = jindo.$A(tpl).reverse().$value();
var delete_info;
while(i--) {
if(i%2) {
tpl[i] = tpl[i].replace(jindo.$Template.pattern, function(){
var m = arguments;
// set
if (m[10]) {
return m[10].replace(/(\w+)(?:\s*)=(?:\s*)(?:([a-zA-Z0-9_]+)|(.+))$/g, function(){
var mm = arguments;
var str = "d."+mm[1]+"=";
if(mm[2]){
str+="d."+mm[2];
}else {
str += mm[3].replace( /(=(?:[a-zA-Z_][\w\.]*)+)/g,
function(m){ return (m.substring(0,1)=='=')?"d."+m.replace('=','') : m; }
);
}
return str;
}) + ";";
}
// js
if(m[9]) {
return 's[i++]=' + m[9].replace( /(=(?:[a-zA-Z_][\w\.]*)+)/g,
function(m){ return (m.substring(0,1)=='=')?"d."+m.replace('=','') : m; }
)+';';
}
// variables
if(m[8]) return 's[i++]= d.'+m[8]+';';
// if
if(m[1]) {
return 'if('+m[1].replace(reg[0],cb[0]).replace(/d\.(typeof) /,'$1 ').replace(/ d\.(instanceof) d\./,' $1 ')+'){';
}
// else if
if(m[2]) return '}else if('+m[2].replace(reg[0],cb[0]).replace(/d\.(typeof) /,'$1 ').replace(/ d\.(instanceof) d\./,' $1 ')+'){';
// for loop
if(m[5]) {
delete_info = m[4];
var _aStr = [];
_aStr.push('var t#=d.'+m[5]+'||{},p#=isArray(t#),i#=0;');
_aStr.push('for(var x# in t#){');
_aStr.push('if(!t#.hasOwnProperty(x#)){continue;}');
_aStr.push(' if( (p# && isNaN(i#=parseInt(x#,10))) || (!p# && !t#.propertyIsEnumerable(x#)) ) continue;');
_aStr.push(' d.'+m[4]+'=t#[x#];');
_aStr.push(m[3]?'d.'+m[3]+'=p#?i#:x#;':'');
return _aStr.join("").replace(reg[4], lev++ );
}
// else
if(m[6]) return '}else{';
// end if, end for
if(m[7]) {
if(m[7]=="for"){
return "delete d."+delete_info+"; };";
}else{
return '};';
}
}
return m[0];
});
}else if(tpl[i] == key) {
tpl[i] = "";
}else if(tpl[i]){
tpl[i] = 's[i++]="'+tpl[i].replace(reg[1],cb[1])+'";';
}
}
tpl = jindo.$A(tpl).reverse().$value().join('').replace(new RegExp(leftBrace,'g'),"{").replace(new RegExp(rightBrace,'g'),"}");
var _aStr = [];
_aStr.push('var s=[],i=0;');
_aStr.push('function isArray(o){ return Object.prototype.toString.call(o) == "[object Array]" };');
_aStr.push(tpl);
_aStr.push('return s.join("");');
tpl = eval("false||function(d){"+_aStr.join("")+"}");
tpl = tpl(data);
//(new Function("d",_aStr.join("")))(data);
return tpl;
};
/**
* @fileOverview $DateÀÇ »ý¼ºÀÚ ¹× ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name date.js
*/
/**
* $Date °´Ã¼¸¦ »ý¼ºÇÏ°í ¸®ÅÏÇÑ´Ù.
* ISO¹®ÀÚ¸¦ ³ÖÀº °æ¿ì jindo.$Date.utcÀ» ±â¹ÝÇÏ¿© °è»êµÈ´Ù.
* @extends core
* @class $Date Ŭ·¡½º´Â ³¯Â¥¸¦ ó¸®Çϱâ À§ÇÑ Date ŸÀÔÀÇ ·¹ÆÛ(Wrapper) Ŭ·¡½ºÀÌ´Ù.
* @constructor
* @author Kim, Taegon
* @example
$Date();
$Date(milliseconds);
$Date(dateString);
//1.4.6 ÀÌÈÄ ºÎÅÍ ´Þ±îÁö¸¸ ³Ö¾îµµ $Date»ç¿ë °¡´ÉÇÏ¿© ºó °ªÀº 1·Î ¼ÂÆÃ.
$Date(year, month, [date, [hours, [minitues, [seconds, [milliseconds]]]]]);
$Date(2010,6);//ÀÌ·¯°í Çϸé $Date(2010,6,1,1,1,1,1); ¿Í °°À½.
*/
jindo.$Date = function(src) {
var a=arguments,t="";
var cl=arguments.callee;
if (src && src instanceof cl) return src;
if (!(this instanceof cl)) return new cl(a[0],a[1],a[2],a[3],a[4],a[5],a[6]);
if ((t=typeof src) == "string") {
/*
iso stringÀ϶§
*/
if (/(\d\d\d\d)(?:-?(\d\d)(?:-?(\d\d)))/.test(src)) {
try{
this._date = new Date(src);
if (!this._date.toISOString) {
this._date = jindo.$Date.makeISO(src);
}else if(this._date.toISOString() == "Invalid Date"){
this._date = jindo.$Date.makeISO(src);
}
}catch(e){
this._date = jindo.$Date.makeISO(src);
}
}else{
this._date = cl.parse(src);
}
} else if (t == "number") {
if (typeof a[1] == "undefined") {
/*
ÇϳªÀÇ ¼ýÁöÀÎ °æ¿ì´Â ¹Ð¸® ¼¼Ä˵å·Î °è»êÇÔ.
*/
this._date = new Date(src);
}else{
for(var i = 0 ; i < 7 ; i++){
if(typeof a[i] != "number"){
a[i] = 1;
}
}
this._date = new Date(a[0],a[1],a[2],a[3],a[4],a[5],a[6]);
}
} else if (t == "object" && src.constructor == Date) {
(this._date = new Date).setTime(src.getTime());
this._date.setMilliseconds(src.getMilliseconds());
} else {
this._date = new Date;
}
this._names = {};
for(var i in jindo.$Date.names){
if(jindo.$Date.names.hasOwnProperty(i))
this._names[i] = jindo.$Date.names[i];
}
}
jindo.$Date.makeISO = function(src){
var match = src.match(/(\d\d\d\d)(?:-?(\d\d)(?:-?(\d\d)(?:[T ](\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|(?:([-+])(\d\d)(?::?(\d\d))?)?)?)?)?)?/);
var hour = parseInt(match[4]||0,10);
var min = parseInt(match[5]||0,10);
if (match[8] == "Z") {
hour += jindo.$Date.utc;
}else if(match[9] == "+" || match[9] == "-"){
hour += (jindo.$Date.utc - parseInt(match[9]+match[10],10));
min += parseInt(match[9] + match[11],10);
}
return new Date(match[1]||0,parseInt(match[2]||0,10)-1,match[3]||0,hour ,min ,match[6]||0,match[7]||0);
}
/**
* names ¼Ó¼ºÀº $Date¿¡¼ »ç¿ëÇÒ ´Þ, ¿äÀÏ, ¿ÀÀü/¿ÀÈÄÀÇ À̸§À» ¹®ÀÚ¿·Î ÀúÀåÇÑ´Ù. s_ ¸¦ Á¢µÎ¾î·Î °¡Áö´Â À̸§µéÀº ¾à¾î(abbreviation)ÀÌ´Ù.
*/
jindo.$Date.names = {
month : ["January","Febrary","March","April","May","June","July","August","September","October","Novermber","December"],
s_month : ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],
day : ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],
s_day : ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],
ampm : ["AM", "PM"]
};
/**
* UTC´Â <a href="http://ko.wikipedia.org/wiki/UTC">ÇùÁ¤ ¼¼°è½Ã°£</a>À¸·Î Çѱ¹À» ±âÁØÀ¸·Î ±âº» °ªÀÌ +9½Ã°£ÀÌ´Ù.
* @example
jindo.$Date.utc = -10; À» Çϸé ÇÏ¿ÍÀ̸¦ ±âÁØÀ¸·Î °è»êµÈ´Ù.
*/
jindo.$Date.utc = 9;
/**
* now ¸Þ¼µå´Â ÇöÀç ½Ã°£À» ¹Ð¸®ÃÊ ´ÜÀ§ÀÇ Á¤¼ö·Î ¸®ÅÏÇÑ´Ù.
* @return {Number} ¹Ð¸®ÃÊ ´ÜÀ§ÀÇ Á¤¼öÀÎ ÇöÀç ½Ã°£
*/
jindo.$Date.now = function() {
return Date.now();
};
/**
* names¼Ó¼ºÀ» ¼ÂÆÃ ȤÀº °¡Á® ¿Â´Ù.(1.4.1 Ãß°¡)
* @param {Object} oNames
*/
jindo.$Date.prototype.name = function(oNames){
if(arguments.length){
for(var i in oNames){
if(oNames.hasOwnProperty(i))
this._names[i] = oNames[i];
}
}else{
return this._names;
}
}
/**
* parse ¸Þ¼µå´Â Àμö·Î ÁöÁ¤ÇÑ ¹®ÀÚ¿À» ÆÄ½ÌÇÏ¿© ¹®ÀÚ¿ÀÇ Çü½Ä¿¡ ¸Â´Â Date °´Ã¼¸¦ »ý¼ºÇÑ´Ù.
* @param {String} strDate ³¯Â¥, ȤÀº ½Ã°£ Çü½ÄÀ» ÁöÁ¤ÇÑ ÆÄ½Ì ´ë»ó ¹®ÀÚ¿
* @return {Object} Date °´Ã¼.
*/
jindo.$Date.parse = function(strDate) {
return new Date(Date.parse(strDate));
};
/**
* $value ¸Þ¼µå´Â $Date°¡ °¨½Î°í ÀÖ´ø ¿øº» Date °´Ã¼¸¦ ¹ÝȯÇÑ´Ù.
* @returns {Object} Date °´Ã¼
*/
jindo.$Date.prototype.$value = function(){
return this._date;
};
/**
* format ¸Þ¼µå´Â $Date °´Ã¼°¡ ÀúÀåÇϰí ÀÖ´Â ½Ã°£À» Àμö·Î ÁöÁ¤ÇÑ Çü½Ä ¹®ÀÚ¿¿¡ ¸ÂÃß¾î º¯È¯ÇÑ´Ù. Çü½Ä ¹®ÀÚ¿Àº PHPÀÇ date ÇÔ¼ö¿Í µ¿ÀÏÇÏ°Ô »ç¿ëÇÑ´Ù.
<table>
<caption>³¯Â¥</caption>
<thead>
<tr>
<th scope="col">¹®ÀÚ</th>
<th scope="col">¼³¸í</th>
<th scope="col">±âŸ</th>
</tr>
</thead>
<tbody>
<tr>
<td>d</td>
<td>µÎÀÚ¸® ³¯Â¥</td>
<td>01 ~ 31</td>
</tr>
<tr>
<td>j</td>
<td>0 ¾ø´Â ³¯Â¥</td>
<td>1 ~ 31</td>
</tr>
<tr>
<td>l (¼Ò¹®ÀÚL)</td>
<td>ÁÖÀÇ Àüü ³¯Â¥</td>
<td>$Date.names.day¿¡ ÁöÁ¤µÇ´Â ³¯Â¥</td>
</tr>
<tr>
<td>D</td>
<td>¿ä¾àµÈ ³¯Â¥</td>
<td>$Date.names.s_day¿¡ ÁöÁ¤µÈ ³¯Â¥</td>
</tr>
<tr>
<td>w</td>
<td>±× ÁÖÀÇ ¸î¹øÂ° ÀÏ</td>
<td>0(ÀÏ) ~ 6(Åä)</td>
</tr>
<tr>
<td>N</td>
<td>ISO-8601 ÁÖÀÇ ¸î¹øÂ° ÀÏ</td>
<td>1(¿ù) ~ 7(ÀÏ)</td>
</tr>
<tr>
<td>S</td>
<td>2±ÛÀÚ, ¼¼öÇü½ÄÀÇ Ç¥Çö(1st, 2nd)</td>
<td>st, nd, rd, th</td>
</tr>
<tr>
<td>z</td>
<td>ÇØ´ç ³âµµÀÇ ¸î¹øÂ° ÀÏ(0ºÎÅÍ)</td>
<td>0 ~ 365</td>
</tr>
</tbody>
</table>
<table>
<caption>¿ù</caption>
<thead>
<tr>
<th scope="col">¹®ÀÚ</th>
<th scope="col">¼³¸í</th>
<th scope="col">±âŸ</th>
</tr>
</thead>
<tbody>
<tr>
<td>m</td>
<td>µÎÀÚ¸® °íÁ¤À¸·Î ¿ù</td>
<td>01 ~ 12</td>
</tr>
<tr>
<td>n</td>
<td>¾Õ¿¡ 0Á¦¿Ü ¿ù</td>
<td>1 ~ 12</td>
</tr>
</tbody>
</table>
<table>
<caption>³â</caption>
<thead>
<tr>
<th scope="col">¹®ÀÚ</th>
<th scope="col">¼³¸í</th>
<th scope="col">±âŸ</th>
</tr>
</thead>
<tbody>
<tr>
<td>L</td>
<td>À±³â ¿©ºÎ</td>
<td>true, false</td>
</tr>
<tr>
<td>o</td>
<td>4ÀÚ¸® ¿¬µµ</td>
<td>2010</td>
</tr>
<tr>
<td>Y</td>
<td>o¿Í °°À½.</td>
<td>2010</td>
</tr>
<tr>
<td>y</td>
<td>2ÀÚ¸® ¿¬µµ</td>
<td>10</td>
</tr>
</tbody>
</table>
<table>
<caption>½Ã</caption>
<thead>
<tr>
<th scope="col">¹®ÀÚ</th>
<th scope="col">¼³¸í</th>
<th scope="col">±âŸ</th>
</tr>
</thead>
<tbody>
<tr>
<td>a</td>
<td>¼Ò¹®ÀÚ ¿ÀÀü, ¿ÀÈÄ</td>
<td>am,pm</td>
</tr>
<tr>
<td>A</td>
<td>´ë¹®ÀÚ ¿ÀÀü,¿ÀÈÄ</td>
<td>AM,PM</td>
</tr>
<tr>
<td>g</td>
<td>(12½Ã°£ ÁÖ±â)0¾ø´Â µÎÀÚ¸® ½Ã°£.</td>
<td>1~12</td>
</tr>
<tr>
<td>G</td>
<td>(24½Ã°£ ÁÖ±â)0¾ø´Â µÎÀÚ¸® ½Ã°£.</td>
<td>0~24</td>
</tr>
<tr>
<td>h</td>
<td>(12½Ã°£ ÁÖ±â)0ÀÖ´Â µÎÀÚ¸® ½Ã°£.</td>
<td>01~12</td>
</tr>
<tr>
<td>H</td>
<td>(24½Ã°£ ÁÖ±â)0ÀÖ´Â µÎÀÚ¸® ½Ã°£.</td>
<td>00~24</td>
</tr>
<tr>
<td>i</td>
<td>0Æ÷ÇÔ 2ÀÚ¸® ºÐ.</td>
<td>00~59</td>
</tr>
<tr>
<td>s</td>
<td>0Æ÷ÇÔ 2ÀÚ¸® ÃÊ</td>
<td>00~59</td>
</tr>
<tr>
<td>u</td>
<td>microseconds</td>
<td>654321</td>
</tr>
</tbody>
</table>
<table>
<caption>±âŸ</caption>
<thead>
<tr>
<th scope="col">¹®ÀÚ</th>
<th scope="col">¼³¸í</th>
<th scope="col">±âŸ</th>
</tr>
</thead>
<tbody>
<tr>
<td>U</td>
<td>Unix Time(1970 00:00:00 GMT) </td>
<td></td>
</tr>
</tbody>
</table>
* @param {Date} strFormat Çü½Ä ¹®ÀÚ¿
* @returns {String} ½Ã°£À» Çü½Ä ¹®ÀÚ¿¿¡ ¸ÂÃß¾î º¯È¯ÇÑ ¹®ÀÚ¿.
* @example
var oDate = $Date("Jun 17 2009 12:02:54");
oDate.format("Y.m.d(D) A H:i") => "2009.06.17(Wed) PM 12:02"
*/
jindo.$Date.prototype.format = function(strFormat){
var o = {};
var d = this._date;
var name = this.name();
var self = this;
return (strFormat||"").replace(/[a-z]/ig, function callback(m){
if (typeof o[m] != "undefined") return o[m];
switch(m) {
case"d":
case"j":
o.j = d.getDate();
o.d = (o.j>9?"":"0")+o.j;
return o[m];
case"l":
case"D":
case"w":
case"N":
o.w = d.getDay();
o.N = o.w?o.w:7;
o.D = name.s_day[o.w];
o.l = name.day[o.w];
return o[m];
case"S":
return (!!(o.S=["st","nd","rd"][d.getDate()]))?o.S:(o.S="th");
case"z":
o.z = Math.floor((d.getTime() - (new Date(d.getFullYear(),0,1)).getTime())/(3600*24*1000));
return o.z;
case"m":
case"n":
o.n = d.getMonth()+1;
o.m = (o.n>9?"":"0")+o.n;
return o[m];
case"L":
o.L = self.isLeapYear();
return o.L;
case"o":
case"Y":
case"y":
o.o = o.Y = d.getFullYear();
o.y = (o.o+"").substr(2);
return o[m];
case"a":
case"A":
case"g":
case"G":
case"h":
case"H":
o.G = d.getHours();
o.g = (o.g=o.G%12)?o.g:12;
o.A = o.G<12?name.ampm[0]:name.ampm[1];
o.a = o.A.toLowerCase();
o.H = (o.G>9?"":"0")+o.G;
o.h = (o.g>9?"":"0")+o.g;
return o[m];
case"i":
o.i = (((o.i=d.getMinutes())>9)?"":"0")+o.i;
return o.i;
case"s":
o.s = (((o.s=d.getSeconds())>9)?"":"0")+o.s;
return o.s;
case"u":
o.u = d.getMilliseconds();
return o.u;
case"U":
o.U = self.time();
return o.U;
default:
return m;
}
});
};
/**
* time ¸Þ¼µå´Â GMT 1970/01/01 00:00:00À» ±âÁØÀ¸·Î °æ°úÇÑ ½Ã°£À» ¼³Á¤Çϰųª °¡Á®¿Â´Ù.
* @param {Number} nTime ¹Ð¸® ÃÊ ´ÜÀ§ÀÇ ½Ã°£ °ª.
* @return {$Date | Number} Àμö¸¦ ÁöÁ¤Çß´Ù¸é GMT 1970/01/01 00:00:00 ¿¡¼ ºÎÅÍ Àμö¸¸Å Áö³ ½Ã°£À» ¼³Á¤ÇÑ $DAte °´Ã¼. Àμö¸¦ ÁöÁ¤ÇÏÁö ¾Ê¾Ò´Ù¸é GMT 1970/01/01 00:00:00¿¡¼ ºÎÅÍ $Date °´Ã¼¿¡ ÁöÁ¤µÈ ½Ã°¢±îÁö °æ°úÇÑ ½Ã°£(¹Ð¸® ÃÊ).
*/
jindo.$Date.prototype.time = function(nTime) {
if (typeof nTime == "number") {
this._date.setTime(nTime);
return this;
}
return this._date.getTime();
};
/**
* year ¸Þ¼µå´Â ³âµµ¸¦ ¼³Á¤Çϰųª °¡Á®¿Â´Ù.
* @param {Number} nYear ¼³Á¤ÇÒ ³âµµ°ª
* @return {$Date | Number} Àμö¸¦ ÁöÁ¤ÇÏ¿´´Ù¸é »õ·Î ³âµµ °ªÀ» ¼³Á¤ÇÑ $Date °´Ã¼. Àμö¸¦ ÁöÁ¤ÇÏÁö ¾Ê¾Ò´Ù¸é $Date °´Ã¼°¡ ÁöÁ¤Çϰí ÀÖ´Â ½Ã°¢ÀÇ ³âµµ¸¦ ¸®ÅÏÇÑ´Ù.
*/
jindo.$Date.prototype.year = function(nYear) {
if (typeof nYear == "number") {
this._date.setFullYear(nYear);
return this;
}
return this._date.getFullYear();
};
/**
* month ¸Þ¼µå´Â ´ÞÀ» ¼³Á¤Çϰųª °¡Á®¿Â´Ù.
* @param {Number} nMon ¼³Á¤ÇÒ ´ÞÀÇ °ª
* @return {$Date | Number} Àμö¸¦ ÁöÁ¤ÇÏ¿´´Ù¸é »õ·Î ´ÞÀ» ¼³Á¤ÇÑ $Date °´Ã¼. Àμö¸¦ ÁöÁ¤ÇÏÁö ¾Ê¾Ò´Ù¸é $Date °´Ã¼°¡ ÁöÁ¤Çϰí ÀÖ´Â ½Ã°¢ÀÇ ´ÞÀ» ¸®ÅÏÇÑ´Ù.
* @remark ¸®ÅÏ °ªÀÇ ¹üÀ§´Â 0(1¿ù)¿¡¼ 11(12¿ù)ÀÌ´Ù.
*/
jindo.$Date.prototype.month = function(nMon) {
if (typeof nMon == "number") {
this._date.setMonth(nMon);
return this;
}
return this._date.getMonth();
};
/**
* date ¸Þ¼µå´Â ³¯Â¥¸¦ ¼³Á¤Çϰųª °¡Á®¿Â´Ù.
* @param {nDate} nDate ¼³Á¤ÇÒ ³¯Â¥ °ª
* @return {$Date | Number} Àμö¸¦ ÁöÁ¤ÇÏ¿´´Ù¸é »õ·Î ³¯Â¥¸¦ ¼³Á¤ÇÑ $Date °´Ã¼. Àμö¸¦ ÁöÁ¤ÇÏÁö ¾Ê¾Ò´Ù¸é $Date °´Ã¼°¡ ÁöÁ¤Çϰí ÀÖ´Â ½Ã°¢ÀÇ ³¯Â¥¸¦ ¸®ÅÏÇÑ´Ù.
*/
jindo.$Date.prototype.date = function(nDate) {
if (typeof nDate == "number") {
this._date.setDate(nDate);
return this;
}
return this._date.getDate();
};
/**
* day ¸Þ¼µå´Â ¿äÀÏÀ» °¡Á®¿Â´Ù.
* @return {Number} ¿äÀÏ °ª. 0(ÀÏ¿äÀÏ)¿¡¼ 6(Åä¿äÀÏ)À» ¸®ÅÏÇÑ´Ù.
*/
jindo.$Date.prototype.day = function() {
return this._date.getDay();
};
/**
* hours ¸Þ¼µå´Â ½Ã(ãÁ)¸¦ ¼³Á¤Çϰųª °¡Á®¿Â´Ù.
* @param {Number} nHour ¼³Á¤ÇÒ ½Ã °ª
* @return {$Date | Number} Àμö¸¦ ÁöÁ¤ÇÏ¿´´Ù¸é »õ·Î ½Ã °ªÀ» ¼³Á¤ÇÑ $Date °´Ã¼. Àμö¸¦ ÁöÁ¤ÇÏÁö ¾Ê¾Ò´Ù¸é $Date °´Ã¼°¡ ÁöÁ¤Çϰí ÀÖ´Â ½Ã°¢ÀÇ ½Ã °ª.
*/
jindo.$Date.prototype.hours = function(nHour) {
if (typeof nHour == "number") {
this._date.setHours(nHour);
return this;
}
return this._date.getHours();
};
/**
* minutes ¸Þ¼µå´Â ºÐÀ» ¼³Á¤Çϰųª °¡Á®¿Â´Ù.
* @param {Number} nMin ¼³Á¤ÇÒ ºÐ °ª
* @return {Number} Àμö¸¦ ÁöÁ¤ÇÏ¿´´Ù¸é »õ·Î ºÐ °ªÀ» ¼³Á¤ÇÑ $Date °´Ã¼. Àμö¸¦ ÁöÁ¤ÇÏÁö ¾Ê¾Ò´Ù¸é $Date °´Ã¼°¡ ÁöÁ¤Çϰí ÀÖ´Â ½Ã°¢ÀÇ ºÐ °ª.
*/
jindo.$Date.prototype.minutes = function(nMin) {
if (typeof nMin == "number") {
this._date.setMinutes(nMin);
return this;
}
return this._date.getMinutes();
};
/**
* seconds ¸Þ¼µå´Â ÃÊÀ» ¼³Á¤Çϰųª °¡Á®¿Â´Ù.
* @param {Number} nSec ¼³Á¤ÇÒ ÃÊ °ª
* @return {Number} Àμö¸¦ ÁöÁ¤ÇÏ¿´´Ù¸é »õ·Î ÃÊ °ªÀ» ¼³Á¤ÇÑ $Date °´Ã¼. Àμö¸¦ ÁöÁ¤ÇÏÁö ¾Ê¾Ò´Ù¸é $Date °´Ã¼°¡ ÁöÁ¤Çϰí ÀÖ´Â ½Ã°¢ÀÇ ÃÊ °ª.
*/
jindo.$Date.prototype.seconds = function(nSec) {
if (typeof nSec == "number") {
this._date.setSeconds(nSec);
return this;
}
return this._date.getSeconds();
};
/**
* isLeapYear ¸Þ¼µå´Â ½Ã°¢ÀÇ À±³â ¿©ºÎ¸¦ È®ÀÎÇÑ´Ù.
* @returns {Boolean} $Date°¡ °¡¸®Å°°í ÀÖ´Â ½Ã°¢ÀÌ À±³âÀ̸é True, ±×·¸Áö ¾Ê´Ù¸é False
*/
jindo.$Date.prototype.isLeapYear = function() {
var y = this._date.getFullYear();
return !(y%4)&&!!(y%100)||!(y%400);
};
/**
* @fileOverView $WindowÀÇ »ý¼ºÀÚ ¹× ¸Þ¼µå¸¦ Á¤ÀÇÇÑ ÆÄÀÏ
* @name window.js
*/
/**
* $Window °´Ã¼¸¦ »ý¼ºÇÏ°í »ý¼ºÇÑ °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @class $Window °´Ã¼´Â ºê¶ó¿ìÀú°¡ Á¦°øÇÏ´Â window °´Ã¼¸¦ ·¡ÇÎÇϰí, À̸¦ ´Ù·ç±â À§ÇÑ ¿©·¯°¡Áö ¸Þ¼µå¸¦ Á¦°øÇÑ´Ù.
* @param {HTMLWidnow} el
* <br>
* $Window·Î ·¡ÇÎÇÒ window ¿¤¸®¸ÕÆ®.
* @author gony
*/
jindo.$Window = function(el) {
var cl = arguments.callee;
if (el instanceof cl) return el;
if (!(this instanceof cl)) return new cl(el);
this._win = el || window;
}
/**
* $value ¸Þ¼µå´Â ¿ø·¡ÀÇ window °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
* @return {HTMLWindow} window ¿¤¸®¸ÕÆ®
* @example
$Window().$value(); // ¿ø·¡ÀÇ window °´Ã¼¸¦ ¸®ÅÏÇÑ´Ù.
*/
jindo.$Window.prototype.$value = function() {
return this._win;
};
/**
* resizeTo ¸Þ¼µå´Â âÀÇ Å©±â¸¦ ÁöÁ¤ÇÑ Å©±â·Î º¯°æÇÑ´Ù.<br>
* ÀÌ Å©±â´Â ÇÁ·¹ÀÓÀ» Æ÷ÇÔÇÑ Ã¢ ÀüüÀÇ Å©±â¸¦ ³ªÅ¸³»¹Ç·Î ½ÇÁ¦·Î Ç¥ÇöÇÏ´Â ÄÁÅÙÆ® »çÀÌÁî´Â ºê¶ó¿ìÀú Á¾·ù¿Í ¼³Á¤¿¡ µû¶ó ´Þ¶óÁú ¼ö ÀÖ´Ù.<br>
* ºê¶ó¿ìÀú¿¡ µû¶ó º¸¾È ¹®Á¦ ¶§¹®¿¡, â Å©±â°¡ ȸéÀÇ °¡½Ã ¿µ¿ªÀ» ¹þ¾î³ª¼ Ä¿ÁöÁö ¸øÇϵµ·Ï ¸·´Â °æ¿ìµµ ÀÖ´Ù. ÀÌ °æ¿ì¿¡´Â ÁöÁ¤ÇÑ Å©±âº¸´Ù ÀÛ°Ô Ã¢ÀÌ Ä¿Áø´Ù.<br>
* @param {Number} nWidth âÀÇ ³Êºñ
* @param {Number} nHeight âÀÇ ³ôÀÌ
* @return {$Window} $Window °´Ã¼
* @see $Window#resizeBy
* @example
* // ÇöÀç âÀÇ ³Êºñ¸¦ 400, ³ôÀ̸¦ 300À¸·Î º¯°æÇÑ´Ù.
* $Window.resizeTo(400, 300);
*/
jindo.$Window.prototype.resizeTo = function(nWidth, nHeight) {
this._win.resizeTo(nWidth, nHeight);
return this;
};
/**
* resizeBy ¸Þ¼µå´Â âÀÇ Å©±â¸¦ ÁöÁ¤ÇÑ Å©±â¸¸Å º¯°æÇÑ´Ù.
* @param {Number} nWidth ´Ã¾î³¯ âÀÇ ³Êºñ
* @param {Number} nHeight ´Ã¾î³¯ âÀÇ ³ôÀÌ
* @see $Window#resizeTo
* @example
* // ÇöÀç âÀÇ ³Êºñ¸¦ 100, ³ôÀ̸¦ 50 ¸¸Å ´Ã¸°´Ù.
* $Window().resize(100, 50);
*/
jindo.$Window.prototype.resizeBy = function(nWidth, nHeight) {
this._win.resizeBy(nWidth, nHeight);
return this;
};
/**
* moveTo ¸Þ¼µå´Â âÀ» ÁöÁ¤ÇÑ À§Ä¡·Î À̵¿½ÃŲ´Ù. ÁÂÇ¥´Â ÇÁ·¹ÀÓÀ» Æ÷ÇÔÇÑ Ã¢ÀÇ ÁÂÃø »ó´ÜÀ» ±âÁØÀ¸·Î ÇÑ´Ù.
* @param {Number} nLeft À̵¿ÇÒ xÁÂÇ¥ (pixel ´ÜÀ§)
* @param {Number} nTop À̵¿ÇÒ yÁÂÇ¥ (pixel ´ÜÀ§)
* @see $Window#moveBy
* @example
* // ÇöÀç âÀ» (15, 10) À¸·Î À̵¿½ÃŲ´Ù.
* $Window().moveTo(15, 10);
*/
jindo.$Window.prototype.moveTo = function(nLeft, nTop) {
this._win.moveTo(nLeft, nTop);
return this;
};
/**
* moveBy ¸Þ¼µå´Â âÀ» ÁöÁ¤ÇÑ À§Ä¡¸¸Å À̵¿½ÃŲ´Ù.
* @param {Number} nLeft xÁÂÇ¥·Î À̵¿ÇÒ ¸¸ÅÀÇ ¾ç (pixel ´ÜÀ§)
* @param {Number} nTop yÁÂÇ¥·Î À̵¿ÇÒ ¸¸ÅÀÇ ¾ç (pixel ´ÜÀ§)
* @see $Window#moveTo
* @example
* // ÇöÀç âÀ» ÁÂÃøÀ¸·Î 15px¸¸Å, ¾Æ·¡·Î 10px¸¸Å À̵¿½ÃŲ´Ù.
* $Window().moveBy(15, 10);
*/
jindo.$Window.prototype.moveBy = function(nLeft, nTop) {
this._win.moveBy(nLeft, nTop);
return this;
};
/**
* sizeToContent ¸Þ¼µå´Â ³»ºÎ ¹®¼ÀÇ ÄÁÅÙÃ÷ Å©±â¿¡ ¸ÂÃß¾î âÀÇ Å©±â¸¦ º¯°æÇϸç, ¸î °¡Áö Á¦¾à »çÇ×À» °¡Áø´Ù. <br>
* Á¦¾à»çÇ׿¡ °É¸®´Â °æ¿ì ¸Å°³º¯¼ö·Î âÀÇ »çÀÌÁ ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.
<ul>
<li>¸Þ¼µåÀÇ ³»ºÎ ¹®¼°¡ ¿ÏÀüÈ÷ ·ÎµùµÈ ´ÙÀ½¿¡ ½ÇÇàµÇ¾î¾ß ÇÑ´Ù. </li>
<li>âÀÌ ³»ºÎ ¹®¼º¸´Ù Å« °æ¿ì¿¡´Â ³»ºÎ ¹®¼¸¦ ±¸ÇÒ ¼ö ¾øÀ¸¹Ç·Î, ¹Ýµå½Ã â Å©±â¸¦ ³»ºÎ ¹®¼º¸´Ù ÀÛ°Ô ¸¸µç´Ù.</li>
<li>¹Ýµå½Ã body¿¡ »çÀÌÁî°¡ ÀÖ¾î¾ß ÇÑ´Ù.</li>
<li>htmlÀÇ DOCTYPEÀÌ QuirksÀ϶§ ¸Æ¿¡¼´Â opera(10), À©µµ¿ì¿¡¼´Â IE6+, opera(10), safari(4)¿¡¼ Á¤»óÀûÀ¸·Î µ¿ÀÛÇÏÁö ¾Ê´Â´Ù.</li>
<li>°¡´É ÇÏ¸é ºÎ¸ðâ¿¡¼ ½ÇÇà ½ÃÄÑ¾ß ÇÑ´Ù. ÀÚ½ÄâÀÌ ¸ð´ÏÅÍ È¸éÀ» ¹þ¾î³ª °¡·ÁÁ® ÀÖÀ» °æ¿ì, IE´Â °¡·ÁÁø ¿µ¿ªÀº ÄÁÅÙÃ÷°¡ ¾ø´Â °ÍÀ¸·Î ÆÇ´ÜÇÏ¿© °¡·ÁÁø ¿µ¿ª ¸¸Å ÁÙÀδÙ.</li>
</ul>
* @param {Number} nWidth âÀÇ ³Êºñ
* @param {Number} nHeight âÀÇ ³ôÀÌ
* @example
* // »õ âÀ» ¶ç¿ì°í ÀÚµ¿À¸·Î â Å©±â¸¦ ÄÁÅÙÆ®¿¡ ¸Â°Ô º¯°æÇÏ´Â ÇÔ¼ö
* function winopen(url) {
* try {
* win = window.open(url, "", "toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=250,height=300");
* win.moveTo(200, 100);
* win.focus();
* } catch(e){}
*
* setTimeout(function() {
* $Window(win).sizeToContent();
* }, 1000);
* }
*
* winopen('/samples/popup.html');
*/
jindo.$Window.prototype.sizeToContent = function(nWidth, nHeight) {
if (typeof this._win.sizeToContent == "function") {
this._win.sizeToContent();
} else {
if(arguments.length != 2){
// use trick by Peter-Paul Koch
// http://www.quirksmode.org/
var innerX,innerY;
var self = this._win;
var doc = this._win.document;
if (self.innerHeight) {
// all except Explorer
innerX = self.innerWidth;
innerY = self.innerHeight;
} else if (doc.documentElement && doc.documentElement.clientHeight) {
// Explorer 6 Strict Mode
innerX = doc.documentElement.clientWidth;
innerY = doc.documentElement.clientHeight;
} else if (doc.body) {
// other Explorers
innerX = doc.body.clientWidth;
innerY = doc.body.clientHeight;
}
var pageX,pageY;
var test1 = doc.body.scrollHeight;
var test2 = doc.body.offsetHeight;
if (test1 > test2) {
// all but Explorer Mac
pageX = doc.body.scrollWidth;
pageY = doc.body.scrollHeight;
} else {
// Explorer Mac;
//would also work in Explorer 6 Strict, Mozilla and Safari
pageX = doc.body.offsetWidth;
pageY = doc.body.offsetHeight;
}
nWidth = pageX - innerX;
nHeight = pageY - innerY;
}
this.resizeBy(nWidth, nHeight);
}
return this;
};
/**
* @fileOverview ´Ù¸¥ ÇÁ·¹ÀÓ¿÷ ¾øÀÌ jindo¸¸ »ç¿ëÇÒ °æ¿ì ÆíÀǼºÀ» À§ÇØ jindo °´Ã¼¸¦ window¿¡ ºÙÀÓ
*/
// copy jindo objects to window
if (typeof window != "undefined") {
for (prop in jindo) {
if (jindo.hasOwnProperty(prop)) {
window[prop] = jindo[prop];
}
}
}
OHA YOOOO