qwrap의 Jss 호출
/**
*@name getOwnJssData data-jss
*@param el
*@param needInit
*@return {Object} data
/
function getOwnJssData(el,needInit){
var data = el.__jssData;
if(!data){
// key data-jss data-jss=""
var s = el.getAttribute('data-jss');
if(s){
// {}
if (!/^\s*{/.test(s)) {
s = '{' + s + '}';
}
//evalExp
// data el.__jssData
data = el.__jssData = evalExp(s);
}else if(needInit){
data = el.__jssData = {};
}
}
//
return data;
}
/**
*@name getOwnJss
*@param el
*@param attributeName key attributeName
*@see getOwnJssData
*/
getOwnJss:function(el,attributeName){
var data = getOwnJssData(el);
if(data && (attributeName in data)){
return data[attributeName];
}
return undefined;
}
결론:
/**
*@name setJss
*@param el
*@param attributeName
*@param attributeValue
*@see getOwnJssData
*/
setJss:function(el,attributeName,attributeValue){
var data = getOwnJssData(el,true);
data[attributeName] = attributeValue;
}
/**
*@name removeJss
*@param el
*@param attributeName
*@see getOwnJssData
*/
removeJss:function(el,attributeName){
var data = getOwnJssData(el);
if(data && (attributeName in data)){
// delete
delete data[attributeName];
// ,true
return true;
}
// , false
return false;
}
/**
*@name getJss
*@param el
*@param attributeName
*@see getOwnJssData
*@see getRuleData
*/
getJss:function(el,attributeName){
var data = getOwnJssData(el);
if(data && (attributeName in data)){
return data[attributeName];
}
//id
var getRuleData = Jss.getRuleDate,
id = el.id;
//id "#"+id
if(id && (data = getRuleData("#" + id)) && (attributeName in data)){
return data[attributeName];
}
//name
var name = el.name;
//name "@"+name
if(name && (data = getRuleData("@" + name)) && (attributeName in data)) {
return data[attributeName];
}
//className
var className = el.className;
//className "."+className
if(className){
// "classNameA classNameB classNameC"
var classNames = className.split(" ");
for(var i = 0;i<classNames.length;i++){
if((data = getRuleData('.'+classNames[i])) && (attributeName in data)){
return data[attributeName];
}
}
}
//tagName
var tagName = el.tagName;
if(tagName && (data = getRuleData(tagName)) && (attributeName in data)){
return data[attributeName];
}
return undefined;
}
getJss의 디자인에서 몇 가지 결론을 얻었다.