mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-26 06:39:56 +09:00
Author name update.
NHN developers@xpressengine.com http://xpressengine.com/ git-svn-id: http://xe-core.googlecode.com/svn/sandbox@7676 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
7d1fa86e5c
commit
8f385a592b
603 changed files with 67379 additions and 67522 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,279 +1,279 @@
|
|||
/**
|
||||
* @file js_app.js
|
||||
* @author taggon (gonom9@gmail.com)
|
||||
* @brief XE JavaScript Application Framework (JAF)
|
||||
* @namespace xe
|
||||
* @update 20100701
|
||||
*/
|
||||
(function($){
|
||||
|
||||
var _xe_base, _app_base, _plugin_base;
|
||||
var _apps = [];
|
||||
|
||||
_xe_base = {
|
||||
/**
|
||||
* @brief return the name of Core module
|
||||
*/
|
||||
getName : function() {
|
||||
return 'Core';
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief Create an application class
|
||||
*/
|
||||
createApp : function(sName, oDef) {
|
||||
var _base = getTypeBase();
|
||||
|
||||
$.extend(_base.prototype, _app_base, oDef);
|
||||
|
||||
_base.prototype.getName = function() {
|
||||
return sName;
|
||||
};
|
||||
|
||||
return _base;
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief Create a plugin class
|
||||
*/
|
||||
createPlugin : function(sName, oDef) {
|
||||
var _base = getTypeBase();
|
||||
|
||||
$.extend(_base.prototype, _plugin_base, oDef);
|
||||
|
||||
_base.prototype.getName = function() {
|
||||
return sName;
|
||||
};
|
||||
|
||||
return _base;
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief Get the array of applications
|
||||
*/
|
||||
getApps : function() {
|
||||
return $.makeArray(_apps);
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief Get one application
|
||||
*/
|
||||
getApp : function(indexOrName) {
|
||||
indexOrName = (indexOrName||'').toLowerCase();
|
||||
if(typeof _apps[indexOrName] != 'undefined') {
|
||||
return _apps[indexOrName];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief Register an application instance
|
||||
*/
|
||||
registerApp : function(oApp) {
|
||||
var sName = oApp.getName().toLowerCase();
|
||||
|
||||
_apps.push(oApp);
|
||||
if (!$.isArray(_apps[sName])) {
|
||||
_apps[sName] = [];
|
||||
}
|
||||
_apps[sName].push(oApp);
|
||||
|
||||
oApp.parent = this;
|
||||
|
||||
// register event
|
||||
if ($.isFunction(oApp.activate)) oApp.activate();
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief Unregister an application instance
|
||||
*/
|
||||
unregisterApp : function(oApp) {
|
||||
var sName = oPlugin.getName().toLowerCase();
|
||||
var nIndex = $.inArray(oApp, _apps);
|
||||
|
||||
if (nIndex >= 0) _apps.splice(nIndex, 1);
|
||||
|
||||
if ($.isArray(_apps[sName])) {
|
||||
nIndex = $.inArray(oApp, _apps[sName]);
|
||||
if (nIndex >= 0) _apps[sName].splice(nIndex, 1);
|
||||
}
|
||||
|
||||
// unregister event
|
||||
if ($.isFunction(oApp.deactivate)) oApp.deactivate();
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief overrides broadcast method
|
||||
*/
|
||||
broadcast : function(msg, params) {
|
||||
this._broadcast(this, msg, params);
|
||||
},
|
||||
|
||||
_broadcast : function(sender, msg, params) {
|
||||
for(var i=0; i < _apps.length; i++) {
|
||||
_apps[i]._cast(sender, msg, params);
|
||||
}
|
||||
|
||||
|
||||
// cast to child plugins
|
||||
this._cast(sender, msg, params);
|
||||
}
|
||||
}
|
||||
|
||||
_app_base = {
|
||||
_plugins : [],
|
||||
_messages : {},
|
||||
|
||||
/**
|
||||
* @brief get plugin
|
||||
*/
|
||||
getPlugin : function(sPluginName) {
|
||||
sPluginName = sPluginName.toLowerCase();
|
||||
if ($.isArray(this._plugins[sPluginName])) {
|
||||
return this._plugins[sPluginName];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief register a plugin instance
|
||||
*/
|
||||
registerPlugin : function(oPlugin) {
|
||||
var self = this;
|
||||
var sName = oPlugin.getName().toLowerCase();
|
||||
|
||||
// check if the plugin is already registered
|
||||
if ($.inArray(oPlugin, this._plugins) >= 0) return false;
|
||||
|
||||
// push the plugin into the _plugins array
|
||||
this._plugins.push(oPlugin);
|
||||
|
||||
if (!$.isArray(this._plugins[sName])) this._plugins[sName] = [];
|
||||
this._plugins[sName].push(oPlugin);
|
||||
|
||||
// register method pool
|
||||
$.each(oPlugin._binded_fn, function(api, fn){ self.registerHandler(api, fn); });
|
||||
|
||||
// binding
|
||||
oPlugin.oApp = this;
|
||||
|
||||
// registered event
|
||||
if ($.isFunction(oPlugin.activate)) oPlugin.activate();
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief register api message handler
|
||||
*/
|
||||
registerHandler : function(api, func) {
|
||||
var msgs = this._messages; api = api.toUpperCase();
|
||||
if (!$.isArray(msgs[api])) msgs[api] = [];
|
||||
msgs[api].push(func);
|
||||
},
|
||||
|
||||
cast : function(msg, params) {
|
||||
return this._cast(this, msg, params || []);
|
||||
},
|
||||
|
||||
broadcast : function(sender, msg, params) {
|
||||
if (this.parent && this.parent._broadcast) {
|
||||
this.parent._broadcast(sender, msg, params);
|
||||
}
|
||||
},
|
||||
|
||||
_cast : function(sender, msg, params) {
|
||||
var i, len;
|
||||
var aMsg = this._messages;
|
||||
|
||||
msg = msg.toUpperCase();
|
||||
|
||||
// BEFORE hooker
|
||||
if (aMsg['BEFORE_'+msg] || this['API_BEFORE_'+msg]) {
|
||||
var bContinue = this._cast(sender, 'BEFORE_'+msg, params);
|
||||
if (!bContinue) return;
|
||||
}
|
||||
|
||||
// main api function
|
||||
var vRet = [], sFn = 'API_'+msg;
|
||||
if ($.isArray(aMsg[msg])) {
|
||||
for(i=0; i < aMsg[msg].length; i++) {
|
||||
vRet.push( aMsg[msg][i](sender, params) );
|
||||
}
|
||||
}
|
||||
if (vRet.length < 2) vRet = vRet[0];
|
||||
|
||||
// AFTER hooker
|
||||
if (aMsg['AFTER_'+msg] || this['API_AFTER_'+msg]) {
|
||||
this._cast(sender, 'AFTER_'+msg, params);
|
||||
}
|
||||
|
||||
if (!/^(?:AFTER|BEFORE)_/.test(msg)) { // top level function
|
||||
return vRet;
|
||||
} else {
|
||||
return $.isArray(vRet)?($.inArray(false, vRet)<0):((typeof vRet=='undefined')?true:!!vRet);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_plugin_base = {
|
||||
oApp : null,
|
||||
|
||||
cast : function(msg, params) {
|
||||
if (this.oApp && this.oApp._cast) {
|
||||
return this.oApp._cast(this, msg, params || []);
|
||||
}
|
||||
},
|
||||
|
||||
broadcast : function(msg, params) {
|
||||
if (this.oApp && this.oApp.broadcast) {
|
||||
this.oApp.broadcast(this, mag, params || []);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler prototype
|
||||
*
|
||||
* function (oSender, params)
|
||||
*/
|
||||
};
|
||||
|
||||
function getTypeBase() {
|
||||
var _base = function() {
|
||||
var self = this;
|
||||
var pool = null;
|
||||
|
||||
if ($.isArray(this._plugins)) this._plugins = [];
|
||||
if (this._messages) this._messages = {};
|
||||
else this._binded_fn = {};
|
||||
|
||||
// bind functions
|
||||
$.each(this, function(key, val){
|
||||
if (!$.isFunction(val)) return true;
|
||||
if (!/^API_([A-Z0-9_]+)$/.test(key)) return true;
|
||||
|
||||
var api = RegExp.$1;
|
||||
var fn = function(sender, params){ return self[key](sender, params) };
|
||||
|
||||
if (self._messages) self._messages[api] = [fn];
|
||||
else self._binded_fn[api] = fn;
|
||||
});
|
||||
|
||||
if ($.isFunction(this.init)) this.init.apply(this, arguments);
|
||||
};
|
||||
|
||||
return _base;
|
||||
}
|
||||
|
||||
window.xe = $.extend(_app_base, _xe_base);
|
||||
window.xe.lang = {}; // language repository
|
||||
|
||||
// domready event
|
||||
$(function(){ xe.broadcast('ONREADY'); });
|
||||
|
||||
// load event
|
||||
$(window).load(function(){ xe.broadcast('ONLOAD'); });
|
||||
|
||||
})(jQuery);
|
||||
/**
|
||||
* @file js_app.js
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @brief XE JavaScript Application Framework (JAF)
|
||||
* @namespace xe
|
||||
* @update 20100701
|
||||
*/
|
||||
(function($){
|
||||
|
||||
var _xe_base, _app_base, _plugin_base;
|
||||
var _apps = [];
|
||||
|
||||
_xe_base = {
|
||||
/**
|
||||
* @brief return the name of Core module
|
||||
*/
|
||||
getName : function() {
|
||||
return 'Core';
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief Create an application class
|
||||
*/
|
||||
createApp : function(sName, oDef) {
|
||||
var _base = getTypeBase();
|
||||
|
||||
$.extend(_base.prototype, _app_base, oDef);
|
||||
|
||||
_base.prototype.getName = function() {
|
||||
return sName;
|
||||
};
|
||||
|
||||
return _base;
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief Create a plugin class
|
||||
*/
|
||||
createPlugin : function(sName, oDef) {
|
||||
var _base = getTypeBase();
|
||||
|
||||
$.extend(_base.prototype, _plugin_base, oDef);
|
||||
|
||||
_base.prototype.getName = function() {
|
||||
return sName;
|
||||
};
|
||||
|
||||
return _base;
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief Get the array of applications
|
||||
*/
|
||||
getApps : function() {
|
||||
return $.makeArray(_apps);
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief Get one application
|
||||
*/
|
||||
getApp : function(indexOrName) {
|
||||
indexOrName = (indexOrName||'').toLowerCase();
|
||||
if(typeof _apps[indexOrName] != 'undefined') {
|
||||
return _apps[indexOrName];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief Register an application instance
|
||||
*/
|
||||
registerApp : function(oApp) {
|
||||
var sName = oApp.getName().toLowerCase();
|
||||
|
||||
_apps.push(oApp);
|
||||
if (!$.isArray(_apps[sName])) {
|
||||
_apps[sName] = [];
|
||||
}
|
||||
_apps[sName].push(oApp);
|
||||
|
||||
oApp.parent = this;
|
||||
|
||||
// register event
|
||||
if ($.isFunction(oApp.activate)) oApp.activate();
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief Unregister an application instance
|
||||
*/
|
||||
unregisterApp : function(oApp) {
|
||||
var sName = oPlugin.getName().toLowerCase();
|
||||
var nIndex = $.inArray(oApp, _apps);
|
||||
|
||||
if (nIndex >= 0) _apps.splice(nIndex, 1);
|
||||
|
||||
if ($.isArray(_apps[sName])) {
|
||||
nIndex = $.inArray(oApp, _apps[sName]);
|
||||
if (nIndex >= 0) _apps[sName].splice(nIndex, 1);
|
||||
}
|
||||
|
||||
// unregister event
|
||||
if ($.isFunction(oApp.deactivate)) oApp.deactivate();
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief overrides broadcast method
|
||||
*/
|
||||
broadcast : function(msg, params) {
|
||||
this._broadcast(this, msg, params);
|
||||
},
|
||||
|
||||
_broadcast : function(sender, msg, params) {
|
||||
for(var i=0; i < _apps.length; i++) {
|
||||
_apps[i]._cast(sender, msg, params);
|
||||
}
|
||||
|
||||
|
||||
// cast to child plugins
|
||||
this._cast(sender, msg, params);
|
||||
}
|
||||
}
|
||||
|
||||
_app_base = {
|
||||
_plugins : [],
|
||||
_messages : {},
|
||||
|
||||
/**
|
||||
* @brief get plugin
|
||||
*/
|
||||
getPlugin : function(sPluginName) {
|
||||
sPluginName = sPluginName.toLowerCase();
|
||||
if ($.isArray(this._plugins[sPluginName])) {
|
||||
return this._plugins[sPluginName];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief register a plugin instance
|
||||
*/
|
||||
registerPlugin : function(oPlugin) {
|
||||
var self = this;
|
||||
var sName = oPlugin.getName().toLowerCase();
|
||||
|
||||
// check if the plugin is already registered
|
||||
if ($.inArray(oPlugin, this._plugins) >= 0) return false;
|
||||
|
||||
// push the plugin into the _plugins array
|
||||
this._plugins.push(oPlugin);
|
||||
|
||||
if (!$.isArray(this._plugins[sName])) this._plugins[sName] = [];
|
||||
this._plugins[sName].push(oPlugin);
|
||||
|
||||
// register method pool
|
||||
$.each(oPlugin._binded_fn, function(api, fn){ self.registerHandler(api, fn); });
|
||||
|
||||
// binding
|
||||
oPlugin.oApp = this;
|
||||
|
||||
// registered event
|
||||
if ($.isFunction(oPlugin.activate)) oPlugin.activate();
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* @brief register api message handler
|
||||
*/
|
||||
registerHandler : function(api, func) {
|
||||
var msgs = this._messages; api = api.toUpperCase();
|
||||
if (!$.isArray(msgs[api])) msgs[api] = [];
|
||||
msgs[api].push(func);
|
||||
},
|
||||
|
||||
cast : function(msg, params) {
|
||||
return this._cast(this, msg, params || []);
|
||||
},
|
||||
|
||||
broadcast : function(sender, msg, params) {
|
||||
if (this.parent && this.parent._broadcast) {
|
||||
this.parent._broadcast(sender, msg, params);
|
||||
}
|
||||
},
|
||||
|
||||
_cast : function(sender, msg, params) {
|
||||
var i, len;
|
||||
var aMsg = this._messages;
|
||||
|
||||
msg = msg.toUpperCase();
|
||||
|
||||
// BEFORE hooker
|
||||
if (aMsg['BEFORE_'+msg] || this['API_BEFORE_'+msg]) {
|
||||
var bContinue = this._cast(sender, 'BEFORE_'+msg, params);
|
||||
if (!bContinue) return;
|
||||
}
|
||||
|
||||
// main api function
|
||||
var vRet = [], sFn = 'API_'+msg;
|
||||
if ($.isArray(aMsg[msg])) {
|
||||
for(i=0; i < aMsg[msg].length; i++) {
|
||||
vRet.push( aMsg[msg][i](sender, params) );
|
||||
}
|
||||
}
|
||||
if (vRet.length < 2) vRet = vRet[0];
|
||||
|
||||
// AFTER hooker
|
||||
if (aMsg['AFTER_'+msg] || this['API_AFTER_'+msg]) {
|
||||
this._cast(sender, 'AFTER_'+msg, params);
|
||||
}
|
||||
|
||||
if (!/^(?:AFTER|BEFORE)_/.test(msg)) { // top level function
|
||||
return vRet;
|
||||
} else {
|
||||
return $.isArray(vRet)?($.inArray(false, vRet)<0):((typeof vRet=='undefined')?true:!!vRet);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_plugin_base = {
|
||||
oApp : null,
|
||||
|
||||
cast : function(msg, params) {
|
||||
if (this.oApp && this.oApp._cast) {
|
||||
return this.oApp._cast(this, msg, params || []);
|
||||
}
|
||||
},
|
||||
|
||||
broadcast : function(msg, params) {
|
||||
if (this.oApp && this.oApp.broadcast) {
|
||||
this.oApp.broadcast(this, mag, params || []);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler prototype
|
||||
*
|
||||
* function (oSender, params)
|
||||
*/
|
||||
};
|
||||
|
||||
function getTypeBase() {
|
||||
var _base = function() {
|
||||
var self = this;
|
||||
var pool = null;
|
||||
|
||||
if ($.isArray(this._plugins)) this._plugins = [];
|
||||
if (this._messages) this._messages = {};
|
||||
else this._binded_fn = {};
|
||||
|
||||
// bind functions
|
||||
$.each(this, function(key, val){
|
||||
if (!$.isFunction(val)) return true;
|
||||
if (!/^API_([A-Z0-9_]+)$/.test(key)) return true;
|
||||
|
||||
var api = RegExp.$1;
|
||||
var fn = function(sender, params){ return self[key](sender, params) };
|
||||
|
||||
if (self._messages) self._messages[api] = [fn];
|
||||
else self._binded_fn[api] = fn;
|
||||
});
|
||||
|
||||
if ($.isFunction(this.init)) this.init.apply(this, arguments);
|
||||
};
|
||||
|
||||
return _base;
|
||||
}
|
||||
|
||||
window.xe = $.extend(_app_base, _xe_base);
|
||||
window.xe.lang = {}; // language repository
|
||||
|
||||
// domready event
|
||||
$(function(){ xe.broadcast('ONREADY'); });
|
||||
|
||||
// load event
|
||||
$(window).load(function(){ xe.broadcast('ONLOAD'); });
|
||||
|
||||
})(jQuery);
|
||||
|
|
|
|||
|
|
@ -1,409 +1,409 @@
|
|||
/**
|
||||
* @file common/js/xml_handler.js
|
||||
* @brief XE에서 ajax기능을 이용함에 있어 module, act를 잘 사용하기 위한 자바스크립트
|
||||
**/
|
||||
|
||||
// xml handler을 이용하는 user function
|
||||
var show_waiting_message = true;
|
||||
|
||||
/* This work is licensed under Creative Commons GNU LGPL License.
|
||||
|
||||
License: http://creativecommons.org/licenses/LGPL/2.1/
|
||||
Version: 0.9
|
||||
Author: Stefan Goessner/2006
|
||||
Web: http://goessner.net/
|
||||
*/
|
||||
function xml2json(xml, tab, ignoreAttrib) {
|
||||
var X = {
|
||||
toObj: function(xml) {
|
||||
var o = {};
|
||||
if (xml.nodeType==1) { // element node ..
|
||||
if (ignoreAttrib && xml.attributes.length) // element with attributes ..
|
||||
for (var i=0; i<xml.attributes.length; i++)
|
||||
o["@"+xml.attributes[i].nodeName] = (xml.attributes[i].nodeValue||"").toString();
|
||||
if (xml.firstChild) { // element has child nodes ..
|
||||
var textChild=0, cdataChild=0, hasElementChild=false;
|
||||
for (var n=xml.firstChild; n; n=n.nextSibling) {
|
||||
if (n.nodeType==1) hasElementChild = true;
|
||||
else if (n.nodeType==3 && n.nodeValue.match(/[^ \f\n\r\t\v]/)) textChild++; // non-whitespace text
|
||||
else if (n.nodeType==4) cdataChild++; // cdata section node
|
||||
}
|
||||
if (hasElementChild) {
|
||||
if (textChild < 2 && cdataChild < 2) { // structured element with evtl. a single text or/and cdata node ..
|
||||
X.removeWhite(xml);
|
||||
for (var n=xml.firstChild; n; n=n.nextSibling) {
|
||||
if (n.nodeType == 3) // text node
|
||||
o = X.escape(n.nodeValue);
|
||||
else if (n.nodeType == 4) // cdata node
|
||||
// o["#cdata"] = X.escape(n.nodeValue);
|
||||
o = X.escape(n.nodeValue);
|
||||
else if (o[n.nodeName]) { // multiple occurence of element ..
|
||||
if (o[n.nodeName] instanceof Array)
|
||||
o[n.nodeName][o[n.nodeName].length] = X.toObj(n);
|
||||
else
|
||||
o[n.nodeName] = [o[n.nodeName], X.toObj(n)];
|
||||
}
|
||||
else // first occurence of element..
|
||||
o[n.nodeName] = X.toObj(n);
|
||||
}
|
||||
}
|
||||
else { // mixed content
|
||||
if (!xml.attributes.length)
|
||||
o = X.escape(X.innerXml(xml));
|
||||
else
|
||||
o["#text"] = X.escape(X.innerXml(xml));
|
||||
}
|
||||
}
|
||||
else if (textChild) { // pure text
|
||||
if (!xml.attributes.length)
|
||||
o = X.escape(X.innerXml(xml));
|
||||
else
|
||||
o["#text"] = X.escape(X.innerXml(xml));
|
||||
}
|
||||
else if (cdataChild) { // cdata
|
||||
if (cdataChild > 1)
|
||||
o = X.escape(X.innerXml(xml));
|
||||
else
|
||||
for (var n=xml.firstChild; n; n=n.nextSibling){
|
||||
//o["#cdata"] = X.escape(n.nodeValue);
|
||||
o = X.escape(n.nodeValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!xml.attributes.length && !xml.firstChild) o = null;
|
||||
}
|
||||
else if (xml.nodeType==9) { // document.node
|
||||
o = X.toObj(xml.documentElement);
|
||||
}
|
||||
else
|
||||
alert("unhandled node type: " + xml.nodeType);
|
||||
return o;
|
||||
},
|
||||
toJson: function(o, name, ind) {
|
||||
var json = name ? ("\""+name+"\"") : "";
|
||||
if (o instanceof Array) {
|
||||
for (var i=0,n=o.length; i<n; i++)
|
||||
o[i] = X.toJson(o[i], "", ind+"\t");
|
||||
json += (name?":[":"[") + (o.length > 1 ? ("\n"+ind+"\t"+o.join(",\n"+ind+"\t")+"\n"+ind) : o.join("")) + "]";
|
||||
}
|
||||
else if (o == null)
|
||||
json += (name&&":") + "null";
|
||||
else if (typeof(o) == "object") {
|
||||
var arr = [];
|
||||
for (var m in o)
|
||||
arr[arr.length] = X.toJson(o[m], m, ind+"\t");
|
||||
json += (name?":{":"{") + (arr.length > 1 ? ("\n"+ind+"\t"+arr.join(",\n"+ind+"\t")+"\n"+ind) : arr.join("")) + "}";
|
||||
}
|
||||
else if (typeof(o) == "string")
|
||||
json += (name&&":") + "\"" + o.toString() + "\"";
|
||||
else
|
||||
json += (name&&":") + o.toString();
|
||||
return json;
|
||||
},
|
||||
innerXml: function(node) {
|
||||
var s = ""
|
||||
if ("innerHTML" in node)
|
||||
s = node.innerHTML;
|
||||
else {
|
||||
var asXml = function(n) {
|
||||
var s = "";
|
||||
if (n.nodeType == 1) {
|
||||
s += "<" + n.nodeName;
|
||||
for (var i=0; i<n.attributes.length;i++)
|
||||
s += " " + n.attributes[i].nodeName + "=\"" + (n.attributes[i].nodeValue||"").toString() + "\"";
|
||||
if (n.firstChild) {
|
||||
s += ">";
|
||||
for (var c=n.firstChild; c; c=c.nextSibling)
|
||||
s += asXml(c);
|
||||
s += "</"+n.nodeName+">";
|
||||
}
|
||||
else
|
||||
s += "/>";
|
||||
}
|
||||
else if (n.nodeType == 3)
|
||||
s += n.nodeValue;
|
||||
else if (n.nodeType == 4)
|
||||
s += "<![CDATA[" + n.nodeValue + "]]>";
|
||||
return s;
|
||||
};
|
||||
for (var c=node.firstChild; c; c=c.nextSibling)
|
||||
s += asXml(c);
|
||||
}
|
||||
return s;
|
||||
},
|
||||
escape: function(txt) {
|
||||
return txt.replace(/[\\]/g, "\\\\")
|
||||
.replace(/[\"]/g, '\\"')
|
||||
.replace(/[\n]/g, '\\n')
|
||||
.replace(/[\r]/g, '\\r');
|
||||
},
|
||||
removeWhite: function(e) {
|
||||
e.normalize();
|
||||
for (var n = e.firstChild; n; ) {
|
||||
if (n.nodeType == 3) { // text node
|
||||
if (!n.nodeValue.match(/[^ \f\n\r\t\v]/)) { // pure whitespace text node
|
||||
var nxt = n.nextSibling;
|
||||
e.removeChild(n);
|
||||
n = nxt;
|
||||
}
|
||||
else
|
||||
n = n.nextSibling;
|
||||
}
|
||||
else if (n.nodeType == 1) { // element node
|
||||
X.removeWhite(n);
|
||||
n = n.nextSibling;
|
||||
}
|
||||
else // any other node
|
||||
n = n.nextSibling;
|
||||
}
|
||||
return e;
|
||||
}
|
||||
};
|
||||
if (xml.nodeType == 9) // document node
|
||||
xml = xml.documentElement;
|
||||
|
||||
var json_obj = X.toObj(X.removeWhite(xml)), json_str;
|
||||
|
||||
if (typeof(JSON)=='object' && jQuery.isFunction(JSON.stringify) && false) {
|
||||
var obj = {}; obj[xml.nodeName] = json_obj;
|
||||
json_str = JSON.stringify(obj);
|
||||
return json_str;
|
||||
} else {
|
||||
json_str = X.toJson(json_obj, xml.nodeName, "");
|
||||
return "{" + (tab ? json_str.replace(/\t/g, tab) : json_str.replace(/\t|\n/g, "")) + "}";
|
||||
}
|
||||
}
|
||||
|
||||
(function($){
|
||||
/**
|
||||
* @brief exec_xml
|
||||
* @author taggon <gonom9@gmail.com>
|
||||
**/
|
||||
$.exec_xml = window.exec_xml = function(module, act, params, callback_func, response_tags, callback_func_arg, fo_obj) {
|
||||
var xml_path = request_uri+"index.php"
|
||||
if(!params) params = {};
|
||||
|
||||
// {{{ set parameters
|
||||
if($.isArray(params)) params = arr2obj(params);
|
||||
params['module'] = module;
|
||||
params['act'] = act;
|
||||
|
||||
if(typeof(xeVid)!='undefined') params['vid'] = xeVid;
|
||||
if(typeof(response_tags)=="undefined" || response_tags.length<1) response_tags = ['error','message'];
|
||||
else {
|
||||
response_tags.push('error', 'message');
|
||||
}
|
||||
// }}} set parameters
|
||||
|
||||
// use ssl?
|
||||
if ($.isArray(ssl_actions) && params['act'] && $.inArray(params['act'], ssl_actions) >= 0)
|
||||
{
|
||||
var url = default_url || request_uri;
|
||||
var port = window.https_port || 443;
|
||||
var _ul = $('<a>').attr('href', url)[0];
|
||||
var target = 'https://' + _ul.hostname.replace(/:\d+$/, '');
|
||||
|
||||
if(port != 443) target += ':'+port;
|
||||
if(_ul.pathname[0] != '/') target += '/';
|
||||
|
||||
target += _ul.pathname;
|
||||
xml_path = target.replace(/\/$/, '')+'/index.php';
|
||||
}
|
||||
|
||||
var _u1 = $('<a>').attr('href', location.href)[0];
|
||||
var _u2 = $('<a>').attr('href', xml_path)[0];
|
||||
|
||||
// 현 url과 ajax call 대상 url의 schema 또는 port가 다르면 직접 form 전송
|
||||
if(_u1.protocol != _u2.protocol || _u1.port != _u2.port) return send_by_form(xml_path, params);
|
||||
|
||||
var xml = [], i = 0;
|
||||
xml[i++] = '<?xml version="1.0" encoding="utf-8" ?>';
|
||||
xml[i++] = '<methodCall>';
|
||||
xml[i++] = '<params>';
|
||||
|
||||
$.each(params, function(key, val) {
|
||||
xml[i++] = '<'+key+'><![CDATA['+val+']]></'+key+'>';
|
||||
});
|
||||
|
||||
xml[i++] = '</params>';
|
||||
xml[i++] = '</methodCall>';
|
||||
|
||||
var _xhr = null;
|
||||
if (_xhr && _xhr.readyState != 0) _xhr.abort();
|
||||
|
||||
// 전송 성공시
|
||||
function onsuccess(data, textStatus, xhr) {
|
||||
var resp_xml = $(data).find('response')[0], resp_obj, txt='', ret=[], tags={}, json_str='';
|
||||
|
||||
waiting_obj.css('visibility', 'hidden');
|
||||
|
||||
if(!resp_xml) {
|
||||
alert(_xhr.responseText);
|
||||
return null;
|
||||
}
|
||||
|
||||
json_str = xml2json(resp_xml, false, false);
|
||||
resp_obj = (typeof(JSON)=='object' && $.isFunction(JSON.parse))?JSON.parse(json_str):eval('('+json_str+')');
|
||||
resp_obj = resp_obj.response;
|
||||
|
||||
if (typeof(resp_obj)=='undefined') {
|
||||
ret['error'] = -1;
|
||||
ret['message'] = 'Unexpected error occured.';
|
||||
try {
|
||||
if(typeof(txt=resp_xml.childNodes[0].firstChild.data)!='undefined') ret['message'] += '\r\n'+txt;
|
||||
} catch(e){};
|
||||
return ret;
|
||||
}
|
||||
|
||||
$.each(response_tags, function(key, val){ tags[val] = true; });
|
||||
tags["redirect_url"] = true;
|
||||
tags["act"] = true;
|
||||
$.each(resp_obj, function(key, val){ if(tags[key]) ret[key] = val; });
|
||||
|
||||
if(ret['error'] != 0) {
|
||||
if ($.isFunction($.exec_xml.onerror)) {
|
||||
return $.exec_xml.onerror(module, act, ret, callback_func, response_tags, callback_func_arg, fo_obj);
|
||||
}
|
||||
|
||||
alert(ret['message'] || 'error!');
|
||||
return null;
|
||||
}
|
||||
|
||||
if(ret['redirect_url']) {
|
||||
location.href = ret['redirect_url'].replace(/&/g, '&');
|
||||
return null;
|
||||
}
|
||||
|
||||
if($.isFunction(callback_func)) callback_func(ret, response_tags, callback_func_arg, fo_obj);
|
||||
}
|
||||
|
||||
// 모든 xml데이터는 POST방식으로 전송. try-catch문으로 오류 발생시 대처
|
||||
try {
|
||||
$.ajax({
|
||||
url : xml_path,
|
||||
type : 'POST',
|
||||
dataType : 'xml',
|
||||
data : xml.join('\n'),
|
||||
contentType : 'text/plain',
|
||||
beforeSend : function(xhr){ _xhr = xhr; },
|
||||
success : onsuccess,
|
||||
error : function(xhr, textStatus) {
|
||||
waiting_obj.css('visibility', 'hidden');
|
||||
|
||||
var msg = '';
|
||||
if (textStatus == 'parsererror') {
|
||||
msg = 'The result is not valid XML :\n-------------------------------------\n';
|
||||
if(xhr.responseText == "") return;
|
||||
msg += xhr.responseText.replace(/<[^>]+>/g, '');
|
||||
} else {
|
||||
msg = textStatus;
|
||||
}
|
||||
|
||||
alert(msg);
|
||||
}
|
||||
});
|
||||
} catch(e) {
|
||||
alert(e);
|
||||
return;
|
||||
}
|
||||
|
||||
// ajax 통신중 대기 메세지 출력 (show_waiting_message값을 false로 세팅시 보이지 않음)
|
||||
var waiting_obj = $('#waitingforserverresponse');
|
||||
if(show_waiting_message && waiting_obj.length) {
|
||||
var d = $(document);
|
||||
waiting_obj.html(waiting_message).css({
|
||||
'top' : (d.scrollTop()+20)+'px',
|
||||
'left' : (d.scrollLeft()+20)+'px',
|
||||
'visibility' : 'visible'
|
||||
});
|
||||
}
|
||||
}
|
||||
function send_by_form(url, params) {
|
||||
var frame_id = 'xeTmpIframe';
|
||||
var form_id = 'xeVirtualForm';
|
||||
|
||||
if (!$('#'+frame_id).length) {
|
||||
$('<iframe name="%id%" id="%id%" style="position:absolute;left:-1px;top:1px;width:1px;height:1px"></iframe>'.replace(/%id%/g, frame_id)).appendTo(document.body);
|
||||
}
|
||||
|
||||
$('#'+form_id).remove();
|
||||
var form = $('<form id="%id%"></form>'.replace(/%id%/g, form_id)).attr({
|
||||
'id' : form_id,
|
||||
'method' : 'post',
|
||||
'action' : url,
|
||||
'target' : frame_id
|
||||
});
|
||||
|
||||
params['xeVirtualRequestMethod'] = 'xml';
|
||||
params['xeRequestURI'] = location.href.replace(/#(.*)$/i,'');
|
||||
params['xeVirtualRequestUrl'] = request_uri;
|
||||
|
||||
$.each(params, function(key, value){
|
||||
$('<input type="hidden">').attr('name', key).attr('value', value).appendTo(form);
|
||||
});
|
||||
|
||||
form.appendTo(document.body).submit();
|
||||
}
|
||||
function arr2obj(arr) {
|
||||
var ret = {};
|
||||
for(var key in arr) {
|
||||
if(arr.hasOwnProperty(key)) ret[key] = arr[key];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief exec_json (exec_xml와 같은 용도)
|
||||
**/
|
||||
$.exec_json = function(action,data,func){
|
||||
if(typeof(data) == 'undefined') data = {};
|
||||
action = action.split(".");
|
||||
if(action.length == 2){
|
||||
|
||||
if(show_waiting_message) {
|
||||
$("#waitingforserverresponse").html(waiting_message).css('top',$(document).scrollTop()+20).css('left',$(document).scrollLeft()+20).css('visibility','visible');
|
||||
}
|
||||
|
||||
$.extend(data,{module:action[0],act:action[1]});
|
||||
if(typeof(xeVid)!='undefined') $.extend(data,{vid:xeVid});
|
||||
$.ajax({
|
||||
type:"POST"
|
||||
,dataType:"json"
|
||||
,url:request_uri
|
||||
,contentType:"application/json"
|
||||
,data:$.param(data)
|
||||
,success : function(data){
|
||||
$("#waitingforserverresponse").css('visibility','hidden');
|
||||
if(data.error > 0) alert(data.message);
|
||||
if($.isFunction(func)) func(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$.fn.exec_html = function(action,data,type,func,args){
|
||||
if(typeof(data) == 'undefined') data = {};
|
||||
if(!$.inArray(type, ['html','append','prepend'])) type = 'html';
|
||||
|
||||
var self = $(this);
|
||||
action = action.split(".");
|
||||
if(action.length == 2){
|
||||
if(show_waiting_message) {
|
||||
$("#waitingforserverresponse").html(waiting_message).css('top',$(document).scrollTop()+20).css('left',$(document).scrollLeft()+20).css('visibility','visible');
|
||||
}
|
||||
|
||||
$.extend(data,{module:action[0],act:action[1]});
|
||||
$.ajax({
|
||||
type:"POST"
|
||||
,dataType:"html"
|
||||
,url:request_uri
|
||||
,data:$.param(data)
|
||||
,success : function(html){
|
||||
$("#waitingforserverresponse").css('visibility','hidden');
|
||||
self[type](html);
|
||||
if($.isFunction(func)) func(args);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
})(jQuery);
|
||||
/**
|
||||
* @file common/js/xml_handler.js
|
||||
* @brief XE에서 ajax기능을 이용함에 있어 module, act를 잘 사용하기 위한 자바스크립트
|
||||
**/
|
||||
|
||||
// xml handler을 이용하는 user function
|
||||
var show_waiting_message = true;
|
||||
|
||||
/* This work is licensed under Creative Commons GNU LGPL License.
|
||||
|
||||
License: http://creativecommons.org/licenses/LGPL/2.1/
|
||||
Version: 0.9
|
||||
Author: Stefan Goessner/2006
|
||||
Web: http://goessner.net/
|
||||
*/
|
||||
function xml2json(xml, tab, ignoreAttrib) {
|
||||
var X = {
|
||||
toObj: function(xml) {
|
||||
var o = {};
|
||||
if (xml.nodeType==1) { // element node ..
|
||||
if (ignoreAttrib && xml.attributes.length) // element with attributes ..
|
||||
for (var i=0; i<xml.attributes.length; i++)
|
||||
o["@"+xml.attributes[i].nodeName] = (xml.attributes[i].nodeValue||"").toString();
|
||||
if (xml.firstChild) { // element has child nodes ..
|
||||
var textChild=0, cdataChild=0, hasElementChild=false;
|
||||
for (var n=xml.firstChild; n; n=n.nextSibling) {
|
||||
if (n.nodeType==1) hasElementChild = true;
|
||||
else if (n.nodeType==3 && n.nodeValue.match(/[^ \f\n\r\t\v]/)) textChild++; // non-whitespace text
|
||||
else if (n.nodeType==4) cdataChild++; // cdata section node
|
||||
}
|
||||
if (hasElementChild) {
|
||||
if (textChild < 2 && cdataChild < 2) { // structured element with evtl. a single text or/and cdata node ..
|
||||
X.removeWhite(xml);
|
||||
for (var n=xml.firstChild; n; n=n.nextSibling) {
|
||||
if (n.nodeType == 3) // text node
|
||||
o = X.escape(n.nodeValue);
|
||||
else if (n.nodeType == 4) // cdata node
|
||||
// o["#cdata"] = X.escape(n.nodeValue);
|
||||
o = X.escape(n.nodeValue);
|
||||
else if (o[n.nodeName]) { // multiple occurence of element ..
|
||||
if (o[n.nodeName] instanceof Array)
|
||||
o[n.nodeName][o[n.nodeName].length] = X.toObj(n);
|
||||
else
|
||||
o[n.nodeName] = [o[n.nodeName], X.toObj(n)];
|
||||
}
|
||||
else // first occurence of element..
|
||||
o[n.nodeName] = X.toObj(n);
|
||||
}
|
||||
}
|
||||
else { // mixed content
|
||||
if (!xml.attributes.length)
|
||||
o = X.escape(X.innerXml(xml));
|
||||
else
|
||||
o["#text"] = X.escape(X.innerXml(xml));
|
||||
}
|
||||
}
|
||||
else if (textChild) { // pure text
|
||||
if (!xml.attributes.length)
|
||||
o = X.escape(X.innerXml(xml));
|
||||
else
|
||||
o["#text"] = X.escape(X.innerXml(xml));
|
||||
}
|
||||
else if (cdataChild) { // cdata
|
||||
if (cdataChild > 1)
|
||||
o = X.escape(X.innerXml(xml));
|
||||
else
|
||||
for (var n=xml.firstChild; n; n=n.nextSibling){
|
||||
//o["#cdata"] = X.escape(n.nodeValue);
|
||||
o = X.escape(n.nodeValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!xml.attributes.length && !xml.firstChild) o = null;
|
||||
}
|
||||
else if (xml.nodeType==9) { // document.node
|
||||
o = X.toObj(xml.documentElement);
|
||||
}
|
||||
else
|
||||
alert("unhandled node type: " + xml.nodeType);
|
||||
return o;
|
||||
},
|
||||
toJson: function(o, name, ind) {
|
||||
var json = name ? ("\""+name+"\"") : "";
|
||||
if (o instanceof Array) {
|
||||
for (var i=0,n=o.length; i<n; i++)
|
||||
o[i] = X.toJson(o[i], "", ind+"\t");
|
||||
json += (name?":[":"[") + (o.length > 1 ? ("\n"+ind+"\t"+o.join(",\n"+ind+"\t")+"\n"+ind) : o.join("")) + "]";
|
||||
}
|
||||
else if (o == null)
|
||||
json += (name&&":") + "null";
|
||||
else if (typeof(o) == "object") {
|
||||
var arr = [];
|
||||
for (var m in o)
|
||||
arr[arr.length] = X.toJson(o[m], m, ind+"\t");
|
||||
json += (name?":{":"{") + (arr.length > 1 ? ("\n"+ind+"\t"+arr.join(",\n"+ind+"\t")+"\n"+ind) : arr.join("")) + "}";
|
||||
}
|
||||
else if (typeof(o) == "string")
|
||||
json += (name&&":") + "\"" + o.toString() + "\"";
|
||||
else
|
||||
json += (name&&":") + o.toString();
|
||||
return json;
|
||||
},
|
||||
innerXml: function(node) {
|
||||
var s = ""
|
||||
if ("innerHTML" in node)
|
||||
s = node.innerHTML;
|
||||
else {
|
||||
var asXml = function(n) {
|
||||
var s = "";
|
||||
if (n.nodeType == 1) {
|
||||
s += "<" + n.nodeName;
|
||||
for (var i=0; i<n.attributes.length;i++)
|
||||
s += " " + n.attributes[i].nodeName + "=\"" + (n.attributes[i].nodeValue||"").toString() + "\"";
|
||||
if (n.firstChild) {
|
||||
s += ">";
|
||||
for (var c=n.firstChild; c; c=c.nextSibling)
|
||||
s += asXml(c);
|
||||
s += "</"+n.nodeName+">";
|
||||
}
|
||||
else
|
||||
s += "/>";
|
||||
}
|
||||
else if (n.nodeType == 3)
|
||||
s += n.nodeValue;
|
||||
else if (n.nodeType == 4)
|
||||
s += "<![CDATA[" + n.nodeValue + "]]>";
|
||||
return s;
|
||||
};
|
||||
for (var c=node.firstChild; c; c=c.nextSibling)
|
||||
s += asXml(c);
|
||||
}
|
||||
return s;
|
||||
},
|
||||
escape: function(txt) {
|
||||
return txt.replace(/[\\]/g, "\\\\")
|
||||
.replace(/[\"]/g, '\\"')
|
||||
.replace(/[\n]/g, '\\n')
|
||||
.replace(/[\r]/g, '\\r');
|
||||
},
|
||||
removeWhite: function(e) {
|
||||
e.normalize();
|
||||
for (var n = e.firstChild; n; ) {
|
||||
if (n.nodeType == 3) { // text node
|
||||
if (!n.nodeValue.match(/[^ \f\n\r\t\v]/)) { // pure whitespace text node
|
||||
var nxt = n.nextSibling;
|
||||
e.removeChild(n);
|
||||
n = nxt;
|
||||
}
|
||||
else
|
||||
n = n.nextSibling;
|
||||
}
|
||||
else if (n.nodeType == 1) { // element node
|
||||
X.removeWhite(n);
|
||||
n = n.nextSibling;
|
||||
}
|
||||
else // any other node
|
||||
n = n.nextSibling;
|
||||
}
|
||||
return e;
|
||||
}
|
||||
};
|
||||
if (xml.nodeType == 9) // document node
|
||||
xml = xml.documentElement;
|
||||
|
||||
var json_obj = X.toObj(X.removeWhite(xml)), json_str;
|
||||
|
||||
if (typeof(JSON)=='object' && jQuery.isFunction(JSON.stringify) && false) {
|
||||
var obj = {}; obj[xml.nodeName] = json_obj;
|
||||
json_str = JSON.stringify(obj);
|
||||
return json_str;
|
||||
} else {
|
||||
json_str = X.toJson(json_obj, xml.nodeName, "");
|
||||
return "{" + (tab ? json_str.replace(/\t/g, tab) : json_str.replace(/\t|\n/g, "")) + "}";
|
||||
}
|
||||
}
|
||||
|
||||
(function($){
|
||||
/**
|
||||
* @brief exec_xml
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
**/
|
||||
$.exec_xml = window.exec_xml = function(module, act, params, callback_func, response_tags, callback_func_arg, fo_obj) {
|
||||
var xml_path = request_uri+"index.php"
|
||||
if(!params) params = {};
|
||||
|
||||
// {{{ set parameters
|
||||
if($.isArray(params)) params = arr2obj(params);
|
||||
params['module'] = module;
|
||||
params['act'] = act;
|
||||
|
||||
if(typeof(xeVid)!='undefined') params['vid'] = xeVid;
|
||||
if(typeof(response_tags)=="undefined" || response_tags.length<1) response_tags = ['error','message'];
|
||||
else {
|
||||
response_tags.push('error', 'message');
|
||||
}
|
||||
// }}} set parameters
|
||||
|
||||
// use ssl?
|
||||
if ($.isArray(ssl_actions) && params['act'] && $.inArray(params['act'], ssl_actions) >= 0)
|
||||
{
|
||||
var url = default_url || request_uri;
|
||||
var port = window.https_port || 443;
|
||||
var _ul = $('<a>').attr('href', url)[0];
|
||||
var target = 'https://' + _ul.hostname.replace(/:\d+$/, '');
|
||||
|
||||
if(port != 443) target += ':'+port;
|
||||
if(_ul.pathname[0] != '/') target += '/';
|
||||
|
||||
target += _ul.pathname;
|
||||
xml_path = target.replace(/\/$/, '')+'/index.php';
|
||||
}
|
||||
|
||||
var _u1 = $('<a>').attr('href', location.href)[0];
|
||||
var _u2 = $('<a>').attr('href', xml_path)[0];
|
||||
|
||||
// 현 url과 ajax call 대상 url의 schema 또는 port가 다르면 직접 form 전송
|
||||
if(_u1.protocol != _u2.protocol || _u1.port != _u2.port) return send_by_form(xml_path, params);
|
||||
|
||||
var xml = [], i = 0;
|
||||
xml[i++] = '<?xml version="1.0" encoding="utf-8" ?>';
|
||||
xml[i++] = '<methodCall>';
|
||||
xml[i++] = '<params>';
|
||||
|
||||
$.each(params, function(key, val) {
|
||||
xml[i++] = '<'+key+'><![CDATA['+val+']]></'+key+'>';
|
||||
});
|
||||
|
||||
xml[i++] = '</params>';
|
||||
xml[i++] = '</methodCall>';
|
||||
|
||||
var _xhr = null;
|
||||
if (_xhr && _xhr.readyState != 0) _xhr.abort();
|
||||
|
||||
// 전송 성공시
|
||||
function onsuccess(data, textStatus, xhr) {
|
||||
var resp_xml = $(data).find('response')[0], resp_obj, txt='', ret=[], tags={}, json_str='';
|
||||
|
||||
waiting_obj.css('visibility', 'hidden');
|
||||
|
||||
if(!resp_xml) {
|
||||
alert(_xhr.responseText);
|
||||
return null;
|
||||
}
|
||||
|
||||
json_str = xml2json(resp_xml, false, false);
|
||||
resp_obj = (typeof(JSON)=='object' && $.isFunction(JSON.parse))?JSON.parse(json_str):eval('('+json_str+')');
|
||||
resp_obj = resp_obj.response;
|
||||
|
||||
if (typeof(resp_obj)=='undefined') {
|
||||
ret['error'] = -1;
|
||||
ret['message'] = 'Unexpected error occured.';
|
||||
try {
|
||||
if(typeof(txt=resp_xml.childNodes[0].firstChild.data)!='undefined') ret['message'] += '\r\n'+txt;
|
||||
} catch(e){};
|
||||
return ret;
|
||||
}
|
||||
|
||||
$.each(response_tags, function(key, val){ tags[val] = true; });
|
||||
tags["redirect_url"] = true;
|
||||
tags["act"] = true;
|
||||
$.each(resp_obj, function(key, val){ if(tags[key]) ret[key] = val; });
|
||||
|
||||
if(ret['error'] != 0) {
|
||||
if ($.isFunction($.exec_xml.onerror)) {
|
||||
return $.exec_xml.onerror(module, act, ret, callback_func, response_tags, callback_func_arg, fo_obj);
|
||||
}
|
||||
|
||||
alert(ret['message'] || 'error!');
|
||||
return null;
|
||||
}
|
||||
|
||||
if(ret['redirect_url']) {
|
||||
location.href = ret['redirect_url'].replace(/&/g, '&');
|
||||
return null;
|
||||
}
|
||||
|
||||
if($.isFunction(callback_func)) callback_func(ret, response_tags, callback_func_arg, fo_obj);
|
||||
}
|
||||
|
||||
// 모든 xml데이터는 POST방식으로 전송. try-catch문으로 오류 발생시 대처
|
||||
try {
|
||||
$.ajax({
|
||||
url : xml_path,
|
||||
type : 'POST',
|
||||
dataType : 'xml',
|
||||
data : xml.join('\n'),
|
||||
contentType : 'text/plain',
|
||||
beforeSend : function(xhr){ _xhr = xhr; },
|
||||
success : onsuccess,
|
||||
error : function(xhr, textStatus) {
|
||||
waiting_obj.css('visibility', 'hidden');
|
||||
|
||||
var msg = '';
|
||||
if (textStatus == 'parsererror') {
|
||||
msg = 'The result is not valid XML :\n-------------------------------------\n';
|
||||
if(xhr.responseText == "") return;
|
||||
msg += xhr.responseText.replace(/<[^>]+>/g, '');
|
||||
} else {
|
||||
msg = textStatus;
|
||||
}
|
||||
|
||||
alert(msg);
|
||||
}
|
||||
});
|
||||
} catch(e) {
|
||||
alert(e);
|
||||
return;
|
||||
}
|
||||
|
||||
// ajax 통신중 대기 메세지 출력 (show_waiting_message값을 false로 세팅시 보이지 않음)
|
||||
var waiting_obj = $('#waitingforserverresponse');
|
||||
if(show_waiting_message && waiting_obj.length) {
|
||||
var d = $(document);
|
||||
waiting_obj.html(waiting_message).css({
|
||||
'top' : (d.scrollTop()+20)+'px',
|
||||
'left' : (d.scrollLeft()+20)+'px',
|
||||
'visibility' : 'visible'
|
||||
});
|
||||
}
|
||||
}
|
||||
function send_by_form(url, params) {
|
||||
var frame_id = 'xeTmpIframe';
|
||||
var form_id = 'xeVirtualForm';
|
||||
|
||||
if (!$('#'+frame_id).length) {
|
||||
$('<iframe name="%id%" id="%id%" style="position:absolute;left:-1px;top:1px;width:1px;height:1px"></iframe>'.replace(/%id%/g, frame_id)).appendTo(document.body);
|
||||
}
|
||||
|
||||
$('#'+form_id).remove();
|
||||
var form = $('<form id="%id%"></form>'.replace(/%id%/g, form_id)).attr({
|
||||
'id' : form_id,
|
||||
'method' : 'post',
|
||||
'action' : url,
|
||||
'target' : frame_id
|
||||
});
|
||||
|
||||
params['xeVirtualRequestMethod'] = 'xml';
|
||||
params['xeRequestURI'] = location.href.replace(/#(.*)$/i,'');
|
||||
params['xeVirtualRequestUrl'] = request_uri;
|
||||
|
||||
$.each(params, function(key, value){
|
||||
$('<input type="hidden">').attr('name', key).attr('value', value).appendTo(form);
|
||||
});
|
||||
|
||||
form.appendTo(document.body).submit();
|
||||
}
|
||||
function arr2obj(arr) {
|
||||
var ret = {};
|
||||
for(var key in arr) {
|
||||
if(arr.hasOwnProperty(key)) ret[key] = arr[key];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief exec_json (exec_xml와 같은 용도)
|
||||
**/
|
||||
$.exec_json = function(action,data,func){
|
||||
if(typeof(data) == 'undefined') data = {};
|
||||
action = action.split(".");
|
||||
if(action.length == 2){
|
||||
|
||||
if(show_waiting_message) {
|
||||
$("#waitingforserverresponse").html(waiting_message).css('top',$(document).scrollTop()+20).css('left',$(document).scrollLeft()+20).css('visibility','visible');
|
||||
}
|
||||
|
||||
$.extend(data,{module:action[0],act:action[1]});
|
||||
if(typeof(xeVid)!='undefined') $.extend(data,{vid:xeVid});
|
||||
$.ajax({
|
||||
type:"POST"
|
||||
,dataType:"json"
|
||||
,url:request_uri
|
||||
,contentType:"application/json"
|
||||
,data:$.param(data)
|
||||
,success : function(data){
|
||||
$("#waitingforserverresponse").css('visibility','hidden');
|
||||
if(data.error > 0) alert(data.message);
|
||||
if($.isFunction(func)) func(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$.fn.exec_html = function(action,data,type,func,args){
|
||||
if(typeof(data) == 'undefined') data = {};
|
||||
if(!$.inArray(type, ['html','append','prepend'])) type = 'html';
|
||||
|
||||
var self = $(this);
|
||||
action = action.split(".");
|
||||
if(action.length == 2){
|
||||
if(show_waiting_message) {
|
||||
$("#waitingforserverresponse").html(waiting_message).css('top',$(document).scrollTop()+20).css('left',$(document).scrollLeft()+20).css('visibility','visible');
|
||||
}
|
||||
|
||||
$.extend(data,{module:action[0],act:action[1]});
|
||||
$.ajax({
|
||||
type:"POST"
|
||||
,dataType:"html"
|
||||
,url:request_uri
|
||||
,data:$.param(data)
|
||||
,success : function(html){
|
||||
$("#waitingforserverresponse").css('visibility','hidden');
|
||||
self[type](html);
|
||||
if($.isFunction(func)) func(args);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
})(jQuery);
|
||||
|
|
|
|||
|
|
@ -1,301 +1,301 @@
|
|||
/**
|
||||
* @file common/js/xml_js_filter.js
|
||||
* @author taggon (taggon@gmail.com)
|
||||
* @brief xml filter (validator) plugin
|
||||
*
|
||||
* A rule is a method validate one field.
|
||||
* A filter is made up of one or more rules.
|
||||
**/
|
||||
(function($){
|
||||
|
||||
var messages = [];
|
||||
var rules = [];
|
||||
var filters = [];
|
||||
var callbacks = [];
|
||||
var extras = {};
|
||||
|
||||
var Validator = xe.createApp('Validator', {
|
||||
init : function() {
|
||||
// {{{ add filters
|
||||
// email
|
||||
var regEmail = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)*$/;
|
||||
this.cast('ADD_RULE', ['email', regEmail]);
|
||||
this.cast('ADD_RULE', ['email_address', regEmail]);
|
||||
|
||||
// userid
|
||||
var regUserid = /^[a-z]+[\w-]*[a-z0-9_]+$/i;
|
||||
this.cast('ADD_RULE', ['userid', regUserid]);
|
||||
this.cast('ADD_RULE', ['user_id', regUserid]);
|
||||
|
||||
// url
|
||||
var regUrl = /^(https?|ftp|mms):\/\/[0-9a-z-]+(\.[_0-9a-z-\/\~]+)+(:[0-9]{2,4})*$/;
|
||||
this.cast('ADD_RULE', ['url', regUrl]);
|
||||
this.cast('ADD_RULE', ['homepage', regUrl]);
|
||||
|
||||
// korean
|
||||
var regKor = /^[가-힣]*$/;
|
||||
this.cast('ADD_RULE', ['korean', regKor]);
|
||||
|
||||
// korean_number
|
||||
var regKorNum = /^[가-힣0-9]*$/;
|
||||
this.cast('ADD_RULE', ['korean_number', regKorNum]);
|
||||
|
||||
// alpha
|
||||
var regAlpha = /^[a-z]*$/i;
|
||||
this.cast('ADD_RULE', ['alpha', regAlpha]);
|
||||
|
||||
// alpha_number
|
||||
var regAlphaNum = /^[a-z][a-z0-9_]*$/i;
|
||||
this.cast('ADD_RULE', ['alpha_number', regAlphaNum]);
|
||||
|
||||
// number
|
||||
var regNum = /^[0-9]*$/;
|
||||
this.cast('ADD_RULE', ['number', regNum]);
|
||||
// }}} add filters
|
||||
},
|
||||
// run validator
|
||||
run : function(oForm) {
|
||||
var filter = '';
|
||||
|
||||
if (oForm._filter) filter = oForm._filter.value;
|
||||
|
||||
var params = [oForm, filter];
|
||||
var result = this.cast('VALIDATE', params);
|
||||
if (typeof result == 'undefined') result = false;
|
||||
|
||||
return result;
|
||||
},
|
||||
API_ONREADY : function() {
|
||||
var self = this;
|
||||
|
||||
// hook form submit event
|
||||
$('form')
|
||||
.each(function(){
|
||||
if (this.onsubmit) {
|
||||
this['xe:onsubmit'] = this.onsubmit;
|
||||
this.onsubmit = null;
|
||||
}
|
||||
})
|
||||
.submit(function(){
|
||||
var legacyFn = this['xe:onsubmit'];
|
||||
var hasLegacyFn = $.isFunction(legacyFn);
|
||||
var bResult = hasLegacyFn?legacyFn.apply(this):self.run(this);
|
||||
|
||||
return bResult;
|
||||
});
|
||||
},
|
||||
API_VALIDATE : function(sender, params) {
|
||||
var self = this, result = true, form = params[0], filter=null, callback=null;
|
||||
|
||||
if (form.elements['_filter']) filter = form.elements['_filter'].value;
|
||||
if (!filter) return true;
|
||||
if ($.isFunction(callbacks[filter])) callback = callbacks[filter];
|
||||
filter = $.extend({}, filters[filter.toLowerCase()] || {}, extras);
|
||||
|
||||
$.each(filter, function(name) {
|
||||
var _el = form.elements[name];
|
||||
|
||||
if (!_el) return true;
|
||||
|
||||
var el = $(_el), val = $.trim(get_value(el));
|
||||
var minlen = parseInt(this.minlength) || 0;
|
||||
var maxlen = parseInt(this.maxlength) || 0;
|
||||
var rule = (this.rule || '').split(',');
|
||||
|
||||
if (this.required && !val) return (result = (!!self.cast('ALERT', [form, name, 'isnull']) && false));
|
||||
if (!this.required && !val) return (result = true);
|
||||
if ((minlen && val.length < minlen) || (maxlen && val.length > maxlen)) return (result = (!!self.cast('ALERT', [form, name, 'outofrange', minlen, maxlen]) && false));
|
||||
|
||||
if (this.equalto) {
|
||||
var eq_val = get_value($(form.elements[this.equalto]));
|
||||
if (eq_val != val) return (result = (!!self.cast('ALERT', [form, name, 'equalto']) && false));
|
||||
}
|
||||
|
||||
$.each(rule, function() {
|
||||
var ret = self.cast('APPLY_RULE', [this, val]);
|
||||
if (!ret) {
|
||||
self.cast('ALERT', [form, name, 'invalid_'+this]);
|
||||
return (result = false);
|
||||
}
|
||||
});
|
||||
|
||||
if (!result) return false;
|
||||
});
|
||||
|
||||
if (!result) return false;
|
||||
if ($.isFunction(callback)) return callback(form);
|
||||
|
||||
return true;
|
||||
},
|
||||
API_ADD_RULE : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
rules[name] = params[1];
|
||||
},
|
||||
API_DEL_RULE : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
delete rules[name];
|
||||
},
|
||||
API_GET_RULE : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
|
||||
if (rules[name]) {
|
||||
return rules[name];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
API_ADD_FILTER : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
var filter = params[1];
|
||||
|
||||
filters[name] = filter;
|
||||
},
|
||||
API_DEL_FILTER : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
delete filters[name];
|
||||
},
|
||||
API_GET_FILTER : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
|
||||
if (filters[name]) {
|
||||
return filters[name];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
API_ADD_EXTRA_FIELD : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
var prop = params[1];
|
||||
|
||||
extras[name] = prop;
|
||||
},
|
||||
API_GET_EXTRA_FIELD : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
return extras[name];
|
||||
},
|
||||
API_DEL_EXTRA_FIELD : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
delete extras[name];
|
||||
},
|
||||
API_APPLY_RULE : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
var value = params[1];
|
||||
|
||||
if (typeof(rules[name]) == 'undefined') return true; // no filter
|
||||
if ($.isFunction(rules[name])) return rules[name](value);
|
||||
if (rules[name] instanceof RegExp) return rules[name].test(value);
|
||||
|
||||
return true;
|
||||
},
|
||||
API_ALERT : function(sender, params) {
|
||||
var form = params[0];
|
||||
var field_name = params[1];
|
||||
var msg_code = params[2];
|
||||
var minlen = params[3];
|
||||
var maxlen = params[4];
|
||||
|
||||
var field_msg = this.cast('GET_MESSAGE', [field_name]);
|
||||
var msg = this.cast('GET_MESSAGE', [msg_code]);
|
||||
|
||||
if (msg != msg_code) msg = (msg.indexOf('%s')<0)?(field_msg+msg):(msg.replace('%s',field_msg));
|
||||
if (minlen||maxlen) msg += '('+(minlen||'')+'~'+(maxlen||'')+')';
|
||||
|
||||
this.cast('SHOW_ALERT', [msg]);
|
||||
|
||||
// set focus
|
||||
$(form.elements[field_name]).focus();
|
||||
},
|
||||
API_SHOW_ALERT : function(sender, params) {
|
||||
alert(params[0]);
|
||||
},
|
||||
API_ADD_MESSAGE : function(sender, params) {
|
||||
var msg_code = params[0];
|
||||
var msg_str = params[1];
|
||||
|
||||
messages[msg_code] = msg_str;
|
||||
},
|
||||
API_GET_MESSAGE : function(sender, params) {
|
||||
var msg_code = params[0];
|
||||
|
||||
return messages[msg_code] || msg_code;
|
||||
},
|
||||
API_ADD_CALLBACK : function(sender, params) {
|
||||
var name = params[0];
|
||||
var func = params[1];
|
||||
|
||||
callbacks[name] = func;
|
||||
},
|
||||
API_REMOVE_CALLBACK : function(sender, params) {
|
||||
var name = params[0];
|
||||
|
||||
delete callbacks[name];
|
||||
}
|
||||
});
|
||||
|
||||
var oValidator = new Validator;
|
||||
|
||||
// register validator
|
||||
xe.registerApp(oValidator);
|
||||
|
||||
// 호환성을 위해 추가한 플러그인 - 에디터에서 컨텐트를 가져와서 설정한다.
|
||||
var EditorStub = xe.createPlugin('editor_stub', {
|
||||
API_BEFORE_VALIDATE : function(sender, params) {
|
||||
var form = params[0];
|
||||
var seq = form.getAttribute('editor_sequence');
|
||||
|
||||
if (seq) {
|
||||
try {
|
||||
editorRelKeys[seq].content.value = editorRelKeys[seq].func(seq) || '';
|
||||
} catch(e) { }
|
||||
}
|
||||
}
|
||||
});
|
||||
oValidator.registerPlugin(new EditorStub);
|
||||
|
||||
// functions
|
||||
function get_value(elem) {
|
||||
var vals = [];
|
||||
if (elem.is(':radio')){
|
||||
return elem.filter(':checked').val();
|
||||
} else if (elem.is(':checkbox')) {
|
||||
elem.filter(':checked').each(function(){
|
||||
vals.push(this.value);
|
||||
});
|
||||
return vals.join('|@|');
|
||||
} else {
|
||||
return elem.val();
|
||||
}
|
||||
}
|
||||
|
||||
})(jQuery);
|
||||
|
||||
/**
|
||||
* @function filterAlertMessage
|
||||
* @brief ajax로 서버에 요청후 결과를 처리할 callback_function을 지정하지 않았을 시 호출되는 기본 함수
|
||||
**/
|
||||
function filterAlertMessage(ret_obj) {
|
||||
var error = ret_obj["error"];
|
||||
var message = ret_obj["message"];
|
||||
var act = ret_obj["act"];
|
||||
var redirect_url = ret_obj["redirect_url"];
|
||||
var url = location.href;
|
||||
|
||||
if(typeof(message)!="undefined"&&message&&message!="success") alert(message);
|
||||
|
||||
if(typeof(act)!="undefined" && act) url = current_url.setQuery("act", act);
|
||||
else if(typeof(redirect_url)!="undefined" && redirect_url) url = redirect_url;
|
||||
|
||||
if(url == location.href) url = url.replace(/#(.*)$/,'');
|
||||
|
||||
location.href = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function to process filters
|
||||
* @deprecated
|
||||
*/
|
||||
function procFilter(fo_obj, filter_func)
|
||||
{
|
||||
filter_func(fo_obj);
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* @file common/js/xml_js_filter.js
|
||||
* @author NHN (developers@xpressengine.com)
|
||||
* @brief xml filter (validator) plugin
|
||||
*
|
||||
* A rule is a method validate one field.
|
||||
* A filter is made up of one or more rules.
|
||||
**/
|
||||
(function($){
|
||||
|
||||
var messages = [];
|
||||
var rules = [];
|
||||
var filters = [];
|
||||
var callbacks = [];
|
||||
var extras = {};
|
||||
|
||||
var Validator = xe.createApp('Validator', {
|
||||
init : function() {
|
||||
// {{{ add filters
|
||||
// email
|
||||
var regEmail = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)*$/;
|
||||
this.cast('ADD_RULE', ['email', regEmail]);
|
||||
this.cast('ADD_RULE', ['email_address', regEmail]);
|
||||
|
||||
// userid
|
||||
var regUserid = /^[a-z]+[\w-]*[a-z0-9_]+$/i;
|
||||
this.cast('ADD_RULE', ['userid', regUserid]);
|
||||
this.cast('ADD_RULE', ['user_id', regUserid]);
|
||||
|
||||
// url
|
||||
var regUrl = /^(https?|ftp|mms):\/\/[0-9a-z-]+(\.[_0-9a-z-\/\~]+)+(:[0-9]{2,4})*$/;
|
||||
this.cast('ADD_RULE', ['url', regUrl]);
|
||||
this.cast('ADD_RULE', ['homepage', regUrl]);
|
||||
|
||||
// korean
|
||||
var regKor = /^[가-힣]*$/;
|
||||
this.cast('ADD_RULE', ['korean', regKor]);
|
||||
|
||||
// korean_number
|
||||
var regKorNum = /^[가-힣0-9]*$/;
|
||||
this.cast('ADD_RULE', ['korean_number', regKorNum]);
|
||||
|
||||
// alpha
|
||||
var regAlpha = /^[a-z]*$/i;
|
||||
this.cast('ADD_RULE', ['alpha', regAlpha]);
|
||||
|
||||
// alpha_number
|
||||
var regAlphaNum = /^[a-z][a-z0-9_]*$/i;
|
||||
this.cast('ADD_RULE', ['alpha_number', regAlphaNum]);
|
||||
|
||||
// number
|
||||
var regNum = /^[0-9]*$/;
|
||||
this.cast('ADD_RULE', ['number', regNum]);
|
||||
// }}} add filters
|
||||
},
|
||||
// run validator
|
||||
run : function(oForm) {
|
||||
var filter = '';
|
||||
|
||||
if (oForm._filter) filter = oForm._filter.value;
|
||||
|
||||
var params = [oForm, filter];
|
||||
var result = this.cast('VALIDATE', params);
|
||||
if (typeof result == 'undefined') result = false;
|
||||
|
||||
return result;
|
||||
},
|
||||
API_ONREADY : function() {
|
||||
var self = this;
|
||||
|
||||
// hook form submit event
|
||||
$('form')
|
||||
.each(function(){
|
||||
if (this.onsubmit) {
|
||||
this['xe:onsubmit'] = this.onsubmit;
|
||||
this.onsubmit = null;
|
||||
}
|
||||
})
|
||||
.submit(function(){
|
||||
var legacyFn = this['xe:onsubmit'];
|
||||
var hasLegacyFn = $.isFunction(legacyFn);
|
||||
var bResult = hasLegacyFn?legacyFn.apply(this):self.run(this);
|
||||
|
||||
return bResult;
|
||||
});
|
||||
},
|
||||
API_VALIDATE : function(sender, params) {
|
||||
var self = this, result = true, form = params[0], filter=null, callback=null;
|
||||
|
||||
if (form.elements['_filter']) filter = form.elements['_filter'].value;
|
||||
if (!filter) return true;
|
||||
if ($.isFunction(callbacks[filter])) callback = callbacks[filter];
|
||||
filter = $.extend({}, filters[filter.toLowerCase()] || {}, extras);
|
||||
|
||||
$.each(filter, function(name) {
|
||||
var _el = form.elements[name];
|
||||
|
||||
if (!_el) return true;
|
||||
|
||||
var el = $(_el), val = $.trim(get_value(el));
|
||||
var minlen = parseInt(this.minlength) || 0;
|
||||
var maxlen = parseInt(this.maxlength) || 0;
|
||||
var rule = (this.rule || '').split(',');
|
||||
|
||||
if (this.required && !val) return (result = (!!self.cast('ALERT', [form, name, 'isnull']) && false));
|
||||
if (!this.required && !val) return (result = true);
|
||||
if ((minlen && val.length < minlen) || (maxlen && val.length > maxlen)) return (result = (!!self.cast('ALERT', [form, name, 'outofrange', minlen, maxlen]) && false));
|
||||
|
||||
if (this.equalto) {
|
||||
var eq_val = get_value($(form.elements[this.equalto]));
|
||||
if (eq_val != val) return (result = (!!self.cast('ALERT', [form, name, 'equalto']) && false));
|
||||
}
|
||||
|
||||
$.each(rule, function() {
|
||||
var ret = self.cast('APPLY_RULE', [this, val]);
|
||||
if (!ret) {
|
||||
self.cast('ALERT', [form, name, 'invalid_'+this]);
|
||||
return (result = false);
|
||||
}
|
||||
});
|
||||
|
||||
if (!result) return false;
|
||||
});
|
||||
|
||||
if (!result) return false;
|
||||
if ($.isFunction(callback)) return callback(form);
|
||||
|
||||
return true;
|
||||
},
|
||||
API_ADD_RULE : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
rules[name] = params[1];
|
||||
},
|
||||
API_DEL_RULE : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
delete rules[name];
|
||||
},
|
||||
API_GET_RULE : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
|
||||
if (rules[name]) {
|
||||
return rules[name];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
API_ADD_FILTER : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
var filter = params[1];
|
||||
|
||||
filters[name] = filter;
|
||||
},
|
||||
API_DEL_FILTER : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
delete filters[name];
|
||||
},
|
||||
API_GET_FILTER : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
|
||||
if (filters[name]) {
|
||||
return filters[name];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
API_ADD_EXTRA_FIELD : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
var prop = params[1];
|
||||
|
||||
extras[name] = prop;
|
||||
},
|
||||
API_GET_EXTRA_FIELD : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
return extras[name];
|
||||
},
|
||||
API_DEL_EXTRA_FIELD : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
delete extras[name];
|
||||
},
|
||||
API_APPLY_RULE : function(sender, params) {
|
||||
var name = params[0].toLowerCase();
|
||||
var value = params[1];
|
||||
|
||||
if (typeof(rules[name]) == 'undefined') return true; // no filter
|
||||
if ($.isFunction(rules[name])) return rules[name](value);
|
||||
if (rules[name] instanceof RegExp) return rules[name].test(value);
|
||||
|
||||
return true;
|
||||
},
|
||||
API_ALERT : function(sender, params) {
|
||||
var form = params[0];
|
||||
var field_name = params[1];
|
||||
var msg_code = params[2];
|
||||
var minlen = params[3];
|
||||
var maxlen = params[4];
|
||||
|
||||
var field_msg = this.cast('GET_MESSAGE', [field_name]);
|
||||
var msg = this.cast('GET_MESSAGE', [msg_code]);
|
||||
|
||||
if (msg != msg_code) msg = (msg.indexOf('%s')<0)?(field_msg+msg):(msg.replace('%s',field_msg));
|
||||
if (minlen||maxlen) msg += '('+(minlen||'')+'~'+(maxlen||'')+')';
|
||||
|
||||
this.cast('SHOW_ALERT', [msg]);
|
||||
|
||||
// set focus
|
||||
$(form.elements[field_name]).focus();
|
||||
},
|
||||
API_SHOW_ALERT : function(sender, params) {
|
||||
alert(params[0]);
|
||||
},
|
||||
API_ADD_MESSAGE : function(sender, params) {
|
||||
var msg_code = params[0];
|
||||
var msg_str = params[1];
|
||||
|
||||
messages[msg_code] = msg_str;
|
||||
},
|
||||
API_GET_MESSAGE : function(sender, params) {
|
||||
var msg_code = params[0];
|
||||
|
||||
return messages[msg_code] || msg_code;
|
||||
},
|
||||
API_ADD_CALLBACK : function(sender, params) {
|
||||
var name = params[0];
|
||||
var func = params[1];
|
||||
|
||||
callbacks[name] = func;
|
||||
},
|
||||
API_REMOVE_CALLBACK : function(sender, params) {
|
||||
var name = params[0];
|
||||
|
||||
delete callbacks[name];
|
||||
}
|
||||
});
|
||||
|
||||
var oValidator = new Validator;
|
||||
|
||||
// register validator
|
||||
xe.registerApp(oValidator);
|
||||
|
||||
// 호환성을 위해 추가한 플러그인 - 에디터에서 컨텐트를 가져와서 설정한다.
|
||||
var EditorStub = xe.createPlugin('editor_stub', {
|
||||
API_BEFORE_VALIDATE : function(sender, params) {
|
||||
var form = params[0];
|
||||
var seq = form.getAttribute('editor_sequence');
|
||||
|
||||
if (seq) {
|
||||
try {
|
||||
editorRelKeys[seq].content.value = editorRelKeys[seq].func(seq) || '';
|
||||
} catch(e) { }
|
||||
}
|
||||
}
|
||||
});
|
||||
oValidator.registerPlugin(new EditorStub);
|
||||
|
||||
// functions
|
||||
function get_value(elem) {
|
||||
var vals = [];
|
||||
if (elem.is(':radio')){
|
||||
return elem.filter(':checked').val();
|
||||
} else if (elem.is(':checkbox')) {
|
||||
elem.filter(':checked').each(function(){
|
||||
vals.push(this.value);
|
||||
});
|
||||
return vals.join('|@|');
|
||||
} else {
|
||||
return elem.val();
|
||||
}
|
||||
}
|
||||
|
||||
})(jQuery);
|
||||
|
||||
/**
|
||||
* @function filterAlertMessage
|
||||
* @brief ajax로 서버에 요청후 결과를 처리할 callback_function을 지정하지 않았을 시 호출되는 기본 함수
|
||||
**/
|
||||
function filterAlertMessage(ret_obj) {
|
||||
var error = ret_obj["error"];
|
||||
var message = ret_obj["message"];
|
||||
var act = ret_obj["act"];
|
||||
var redirect_url = ret_obj["redirect_url"];
|
||||
var url = location.href;
|
||||
|
||||
if(typeof(message)!="undefined"&&message&&message!="success") alert(message);
|
||||
|
||||
if(typeof(act)!="undefined" && act) url = current_url.setQuery("act", act);
|
||||
else if(typeof(redirect_url)!="undefined" && redirect_url) url = redirect_url;
|
||||
|
||||
if(url == location.href) url = url.replace(/#(.*)$/,'');
|
||||
|
||||
location.href = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function to process filters
|
||||
* @deprecated
|
||||
*/
|
||||
function procFilter(fo_obj, filter_func)
|
||||
{
|
||||
filter_func(fo_obj);
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue