|
精华帖 (0) :: 良好帖 (10) :: 新手帖 (0) :: 隐藏帖 (8)
|
|
|---|---|
| 作者 | 正文 |
|
时间:2007-12-26
我很早就用 JScript 编写ASP。学会ExtJS后发现, 服务器侧的功能被极端弱化,微软的ASP技术足以满足企业级应用,连ASP.NET 都是多余的了。
而且,ASP 的 JScript 是最适合 ExtJS 的服务器端语言了(但是JScript.NET就不行,因为微软让它偏离JavaScript太多)。 为什么? 因为都是 JavaScript 写的啊,客户端和服务端开发都用同一种语言,对企业来讲是最经济、最高效的生产方式了。 ExtJS 的很多代码都可以被服务器侧重用,比如 Ext/core/Ext.js, Ext/util/Date.js, Ext/util/Format.js, Ext/util/JSON.js 请看我是如何把 Ext/util/JSON.js 转变成服务器侧 ASP(JScript) 的 (文件名: ext/util/json.asp)
<%
if (!Ext) { // 如果Ext对象不存在,就创建 Ext.util 。
// 部分 Ext js 文件可能需要定义 document, window 等对象,虽然服务器侧用不到,但是为了正确运行,也需要在这里定义这些“哑”对象,例如 var document = {window: null};
var Ext = {};
Ext.util = {};
}
//接下来就是原版照抄 Ext/util/JSON.js 文件的内容了,不需做任何修改
/*
* Ext JS Library 2.0
* Copyright(c) 2006-2007, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
/**
* @class Ext.util.JSON
* Modified version of Douglas Crockford"s json.js that doesn"t
* mess with the Object prototype
* http://www.json.org/js.html
* @singleton
*/
Ext.util.JSON = new (function(){
var useHasOwn = {}.hasOwnProperty ? true : false;
// crashes Safari in some instances
//var validRE = /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/;
var pad = function(n) {
return n < 10 ? "0" + n : n;
};
var m = {
"\b": '\\b',
"\t": '\\t',
"\n": '\\n',
"\f": '\\f',
"\r": '\\r',
'"' : '\\"',
"\\": '\\\\'
};
var encodeString = function(s){
if (/["\\\x00-\x1f]/.test(s)) {
return '"' + s.replace(/([\x00-\x1f\\"])/g, function(a, b) {
var c = m[b];
if(c){
return c;
}
c = b.charCodeAt();
return "\\u00" +
Math.floor(c / 16).toString(16) +
(c % 16).toString(16);
}) + '"';
}
return '"' + s + '"';
};
var encodeArray = function(o){
var a = ["["], b, i, l = o.length, v;
for (i = 0; i < l; i += 1) {
v = o[i];
switch (typeof v) {
case "undefined":
case "function":
case "unknown":
break;
default:
if (b) {
a.push(',');
}
a.push(v === null ? "null" : Ext.util.JSON.encode(v));
b = true;
}
}
a.push("]");
return a.join("");
};
var encodeDate = function(o){
return '"' + o.getFullYear() + "-" +
pad(o.getMonth() + 1) + "-" +
pad(o.getDate()) + " " + // + "T" +
pad(o.getHours()) + ":" +
pad(o.getMinutes()) + ":" +
pad(o.getSeconds()) + '"';
};
/**
* Encodes an Object, Array or other value
* @param {Mixed} o The variable to encode
* @return {String} The JSON string
*/
this.encode = function(o){
if(typeof o == "undefined" || o === null){
return "null";
}else if(o instanceof Array){
return encodeArray(o);
}else if(o instanceof Date){
return encodeDate(o);
}else if(typeof o == "string"){
return encodeString(o);
}else if(typeof o == "number"){
return isFinite(o) ? String(o) : "null";
}else if(typeof o == "boolean"){
return String(o);
}else {
var a = ["{"], b, i, v;
for (i in o) {
if(!useHasOwn || o.hasOwnProperty(i)) {
v = o[i];
switch (typeof v) {
case "undefined":
case "function":
case "unknown":
break;
default:
if(b){
a.push(',');
}
a.push(this.encode(i), ":",
v === null ? "null" : this.encode(v));
b = true;
}
}
}
a.push("}");
return a.join("");
}
};
/**
* Decodes (parses) a JSON string to an object. If the JSON is invalid, this function throws a SyntaxError.
* @param {String} json The JSON string
* @return {Object} The resulting object
*/
this.decode = function(json){
return eval("(" + json + ')');
};
})();
/**
* Shorthand for {@link Ext.util.JSON#encode}
* @member Ext encode
* @method */
Ext.encode = Ext.util.JSON.encode;
/**
* Shorthand for {@link Ext.util.JSON#decode}
* @member Ext decode
* @method */
Ext.decode = Ext.util.JSON.decode;
%>
接下来,就可以在服务器侧使用了:
<%@LANGUAGE="JSCRIPT" CODEPAGE="65001"%>
<!--#include file="ext/util/json.asp" -->
<%
Response.Buffer = true;
Response.Expires = 0;
Session.CodePage = 65001;
Response.Charset = 'utf-8';
Session.Timeout = 20;
var person = {
name : 'Jimmy',
age: 30,
language: 'JavaScript',
isManager: true
};
Response.Write(Ext.util.JSON.encode(person));
%>
声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
| 返回顶楼 | |
|
时间:2007-12-26
再发一个转化为服务器侧ASP脚本的 Ext 核心文件: ext/core/Ext.js
文件名: ext.js.asp 这样我们就可以在服务器端ASP里使用 Ext.apply,Ext.applyIf, Ext.extend, Ext.urlEncode, Ext.override, Ext.namespace 等 Ext 的核心方法了,实际上也就是为服务器侧的 JScript 增加了面向对象的继承/封装/重载/命名空间等技术,这些技术与 客户端的 ExtJS 联合使用,使开发人员用一种语言和技术就通吃Browser/Server 编程,令企业级的开发最经济最高效,老板一定最喜欢这个解决方案了!
<%
//先把客户端对象定义成“哑”对象,使 Ext.asp 不会报错。
var window = {
location: {
href: ''
}
}, document = {}, navigator = {
userAgent: ''
};
//然后原封不动地照搬ext.js 的内容
/*
* Ext JS Library 2.0
* Copyright(c) 2006-2007, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
Ext = {version: '2.0'};
// for old browsers
window["undefined"] = window["undefined"];
/**
* @class Ext
* Ext core utilities and functions.
* @singleton
*/
/**
* Copies all the properties of config to obj.
* @param {Object} obj The receiver of the properties
* @param {Object} config The source of the properties
* @param {Object} defaults A different object that will also be applied for default values
* @return {Object} returns obj
* @member Ext apply
*/
Ext.apply = function(o, c, defaults){
if(defaults){
// no "this" reference for friendly out of scope calls
Ext.apply(o, defaults);
}
if(o && c && typeof c == 'object'){
for(var p in c){
o[p] = c[p];
}
}
return o;
};
(function(){
var idSeed = 0;
var ua = navigator.userAgent.toLowerCase();
var isStrict = document.compatMode == "CSS1Compat",
isOpera = ua.indexOf("opera") > -1,
isSafari = (/webkit|khtml/).test(ua),
isIE = !isOpera && ua.indexOf("msie") > -1,
isIE7 = !isOpera && ua.indexOf("msie 7") > -1,
isGecko = !isSafari && ua.indexOf("gecko") > -1,
isBorderBox = isIE && !isStrict,
isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1),
isMac = (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1),
isLinux = (ua.indexOf("linux") != -1),
isSecure = window.location.href.toLowerCase().indexOf("https") === 0;
// remove css image flicker
if(isIE && !isIE7){
try{
document.execCommand("BackgroundImageCache", false, true);
}catch(e){}
}
Ext.apply(Ext, {
/**
* True if the browser is in strict mode
* @type Boolean
*/
isStrict : isStrict,
/**
* True if the page is running over SSL
* @type Boolean
*/
isSecure : isSecure,
/**
* True when the document is fully initialized and ready for action
* @type Boolean
*/
isReady : false,
/**
* True to automatically uncache orphaned Ext.Elements periodically (defaults to true)
* @type Boolean
*/
enableGarbageCollector : true,
/**
* True to automatically purge event listeners after uncaching an element (defaults to false).
* Note: this only happens if enableGarbageCollector is true.
* @type Boolean
*/
enableListenerCollection:false,
/**
* URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent
* the IE insecure content warning (defaults to javascript:false).
* @type String
*/
SSL_SECURE_URL : "javascript:false",
/**
* URL to a 1x1 transparent gif image used by Ext to create inline icons with CSS background images. (Defaults to
* "http://extjs.com/s.gif" and you should change this to a URL on your server).
* @type String
*/
BLANK_IMAGE_URL : "http:/"+"/extjs.com/s.gif",
/**
* A reusable empty function
* @property
* @type Function
*/
emptyFn : function(){},
/**
* Copies all the properties of config to obj if they don't already exist.
* @param {Object} obj The receiver of the properties
* @param {Object} config The source of the properties
* @return {Object} returns obj
*/
applyIf : function(o, c){
if(o && c){
for(var p in c){
if(typeof o[p] == "undefined"){ o[p] = c[p]; }
}
}
return o;
},
/**
* Applies event listeners to elements by selectors when the document is ready.
* The event name is specified with an @ suffix.
<pre><code>
Ext.addBehaviors({
// add a listener for click on all anchors in element with id foo
'#foo a@click' : function(e, t){
// do something
},
// add the same listener to multiple selectors (separated by comma BEFORE the @)
'#foo a, #bar span.some-class@mouseover' : function(){
// do something
}
});
</code></pre>
* @param {Object} obj The list of behaviors to apply
*/
addBehaviors : function(o){
if(!Ext.isReady){
Ext.onReady(function(){
Ext.addBehaviors(o);
});
return;
}
var cache = {}; // simple cache for applying multiple behaviors to same selector does query multiple times
for(var b in o){
var parts = b.split('@');
if(parts[1]){ // for Object prototype breakers
var s = parts[0];
if(!cache[s]){
cache[s] = Ext.select(s);
}
cache[s].on(parts[1], o[b]);
}
}
cache = null;
},
/**
* Generates unique ids. If the element already has an id, it is unchanged
* @param {Mixed} el (optional) The element to generate an id for
* @param {String} prefix (optional) Id prefix (defaults "ext-gen")
* @return {String} The generated Id.
*/
id : function(el, prefix){
prefix = prefix || "ext-gen";
el = Ext.getDom(el);
var id = prefix + (++idSeed);
return el ? (el.id ? el.id : (el.id = id)) : id;
},
/**
* Extends one class with another class and optionally overrides members with the passed literal. This class
* also adds the function "override()" to the class that can be used to override
* members on an instance.
* @param {Object} subclass The class inheriting the functionality
* @param {Object} superclass The class being extended
* @param {Object} overrides (optional) A literal with members
* @method extend
*/
extend : function(){
// inline overrides
var io = function(o){
for(var m in o){
this[m] = o[m];
}
};
return function(sb, sp, overrides){
if(typeof sp == 'object'){
overrides = sp;
sp = sb;
sb = function(){sp.apply(this, arguments);};
}
var F = function(){}, sbp, spp = sp.prototype;
F.prototype = spp;
sbp = sb.prototype = new F();
sbp.constructor=sb;
sb.superclass=spp;
if(spp.constructor == Object.prototype.constructor){
spp.constructor=sp;
}
sb.override = function(o){
Ext.override(sb, o);
};
sbp.override = io;
Ext.override(sb, overrides);
return sb;
};
}(),
/**
* Adds a list of functions to the prototype of an existing class, overwriting any existing methods with the same name.
* Usage:<pre><code>
Ext.override(MyClass, {
newMethod1: function(){
// etc.
},
newMethod2: function(foo){
// etc.
}
});
</code></pre>
* @param {Object} origclass The class to override
* @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
* containing one or more methods.
* @method override
*/
override : function(origclass, overrides){
if(overrides){
var p = origclass.prototype;
for(var method in overrides){
p[method] = overrides[method];
}
}
},
/**
* Creates namespaces to be used for scoping variables and classes so that they are not global. Usage:
* <pre><code>
Ext.namespace('Company', 'Company.data');
Company.Widget = function() { ... }
Company.data.CustomStore = function(config) { ... }
</code></pre>
* @param {String} namespace1
* @param {String} namespace2
* @param {String} etc
* @method namespace
*/
namespace : function(){
var a=arguments, o=null, i, j, d, rt;
for (i=0; i<a.length; ++i) {
d=a[i].split(".");
rt = d[0];
eval('if (typeof ' + rt + ' == "undefined"){' + rt + ' = {};} o = ' + rt + ';');
for (j=1; j<d.length; ++j) {
o[d[j]]=o[d[j]] || {};
o=o[d[j]];
}
}
},
/**
* Takes an object and converts it to an encoded URL. e.g. Ext.urlEncode({foo: 1, bar: 2}); would return "foo=1&bar=2". Optionally, property values can be arrays, instead of keys and the resulting string that's returned will contain a name/value pair for each array value.
* @param {Object} o
* @return {String}
*/
urlEncode : function(o){
if(!o){
return "";
}
var buf = [];
for(var key in o){
var ov = o[key], k = encodeURIComponent(key);
var type = typeof ov;
if(type == 'undefined'){
buf.push(k, "=&");
}else if(type != "function" && type != "object"){
buf.push(k, "=", encodeURIComponent(ov), "&");
}else if(ov instanceof Array){
if (ov.length) {
for(var i = 0, len = ov.length; i < len; i++) {
buf.push(k, "=", encodeURIComponent(ov[i] === undefined ? '' : ov[i]), "&");
}
} else {
buf.push(k, "=&");
}
}
}
buf.pop();
return buf.join("");
},
/**
* Takes an encoded URL and and converts it to an object. e.g. Ext.urlDecode("foo=1&bar=2"); would return {foo: 1, bar: 2} or Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", true); would return {foo: 1, bar: [2, 3, 4]}.
* @param {String} string
* @param {Boolean} overwrite (optional) Items of the same name will overwrite previous values instead of creating an an array (Defaults to false).
* @return {Object} A literal with members
*/
urlDecode : function(string, overwrite){
if(!string || !string.length){
return {};
}
var obj = {};
var pairs = string.split('&');
var pair, name, value;
for(var i = 0, len = pairs.length; i < len; i++){
pair = pairs[i].split('=');
name = decodeURIComponent(pair[0]);
value = decodeURIComponent(pair[1]);
if(overwrite !== true){
if(typeof obj[name] == "undefined"){
obj[name] = value;
}else if(typeof obj[name] == "string"){
obj[name] = [obj[name]];
obj[name].push(value);
}else{
obj[name].push(value);
}
}else{
obj[name] = value;
}
}
return obj;
},
/**
* Iterates an array calling the passed function with each item, stopping if your function returns false. If the
* passed array is not really an array, your function is called once with it.
* The supplied function is called with (Object item, Number index, Array allItems).
* @param {Array/NodeList/Mixed} array
* @param {Function} fn
* @param {Object} scope
*/
each : function(array, fn, scope){
if(typeof array.length == "undefined" || typeof array == "string"){
array = [array];
}
for(var i = 0, len = array.length; i < len; i++){
if(fn.call(scope || array[i], array[i], i, array) === false){ return i; };
}
},
// deprecated
combine : function(){
var as = arguments, l = as.length, r = [];
for(var i = 0; i < l; i++){
var a = as[i];
if(a instanceof Array){
r = r.concat(a);
}else if(a.length !== undefined && !a.substr){
r = r.concat(Array.prototype.slice.call(a, 0));
}else{
r.push(a);
}
}
return r;
},
/**
* Escapes the passed string for use in a regular expression
* @param {String} str
* @return {String}
*/
escapeRe : function(s) {
return s.replace(/([.*+?^${}()|[\]\/\\])/g, "\\$1");
},
// internal
callback : function(cb, scope, args, delay){
if(typeof cb == "function"){
if(delay){
cb.defer(delay, scope, args || []);
}else{
cb.apply(scope, args || []);
}
}
},
/**
* Return the dom node for the passed string (id), dom node, or Ext.Element
* @param {Mixed} el
* @return HTMLElement
*/
getDom : function(el){
if(!el || !document){
return null;
}
return el.dom ? el.dom : (typeof el == 'string' ? document.getElementById(el) : el);
},
/**
* Returns the current HTML document object as an {@link Ext.Element}.
* @return Ext.Element The document
*/
getDoc : function(){
return Ext.get(document);
},
/**
* Returns the current document body as an {@link Ext.Element}.
* @return Ext.Element The document body
*/
getBody : function(){
return Ext.get(document.body || document.documentElement);
},
/**
* Shorthand for {@link Ext.ComponentMgr#get}
* @param {String} id
* @return Ext.Component
*/
getCmp : function(id){
return Ext.ComponentMgr.get(id);
},
/**
* Utility method for validating that a value is numeric, returning the specified default value if it is not.
* @param {Mixed} value Should be a number, but any type will be handled appropriately
* @param {Number} defaultValue The value to return if the original value is non-numeric
* @return {Number} Value, if numeric, else defaultValue
*/
num : function(v, defaultValue){
if(typeof v != 'number'){
return defaultValue;
}
return v;
},
/**
* Attempts to destroy any objects passed to it by removing all event listeners, removing them from the
* DOM (if applicable) and calling their destroy functions (if available). This method is primarily
* intended for arguments of type {@link Ext.Element} and {@link Ext.Component}, but any subclass of
* {@link Ext.util.Observable} can be passed in. Any number of elements and/or components can be
* passed into this function in a single call as separate arguments.
* @param {Mixed} arg1 An {@link Ext.Element} or {@link Ext.Component} to destroy
* @param {Mixed} (optional) arg2
* @param {Mixed} (optional) etc...
*/
destroy : function(){
for(var i = 0, a = arguments, len = a.length; i < len; i++) {
var as = a[i];
if(as){
if(as.dom){
as.removeAllListeners();
as.remove();
continue;
}
if(typeof as.destroy == 'function'){
as.destroy();
}
}
}
},
removeNode : isIE ? function(){
var d;
return function(n){
if(n){
d = d || document.createElement('div');
d.appendChild(n);
d.innerHTML = '';
}
}
}() : function(n){
if(n && n.parentNode){
n.parentNode.removeChild(n);
}
},
// inpired by a similar function in mootools library
/**
* Returns the type of object that is passed in. If the object passed in is null or undefined it
* return false otherwise it returns one of the following values:<ul>
* <li><b>string</b>: If the object passed is a string</li>
* <li><b>number</b>: If the object passed is a number</li>
* <li><b>boolean</b>: If the object passed is a boolean value</li>
* <li><b>function</b>: If the object passed is a function reference</li>
* <li><b>object</b>: If the object passed is an object</li>
* <li><b>array</b>: If the object passed is an array</li>
* <li><b>regexp</b>: If the object passed is a regular expression</li>
* <li><b>element</b>: If the object passed is a DOM Element</li>
* <li><b>nodelist</b>: If the object passed is a DOM NodeList</li>
* <li><b>textnode</b>: If the object passed is a DOM text node and contains something other than whitespace</li>
* <li><b>whitespace</b>: If the object passed is a DOM text node and contains only whitespace</li>
* @param {Mixed} object
* @return {String}
*/
type : function(o){
if(o === undefined || o === null){
return false;
}
if(o.htmlElement){
return 'element';
}
var t = typeof o;
if(t == 'object' && o.nodeName) {
switch(o.nodeType) {
case 1: return 'element';
case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
}
}
if(t == 'object' || t == 'function') {
switch(o.constructor) {
case Array: return 'array';
case RegExp: return 'regexp';
}
if(typeof o.length == 'number' && typeof o.item == 'function') {
return 'nodelist';
}
}
return t;
},
/**
* Returns true if the passed value is null, undefined or an empty string (optional).
* @param {Mixed} value The value to test
* @param {Boolean} allowBlank (optional) Pass true if an empty string is not considered empty
* @return {Boolean}
*/
isEmpty : function(v, allowBlank){
return v === null || v === undefined || (!allowBlank ? v === '' : false);
},
value : function(v, defaultValue, allowBlank){
return Ext.isEmpty(v, allowBlank) ? defaultValue : v;
},
/** @type Boolean */
isOpera : isOpera,
/** @type Boolean */
isSafari : isSafari,
/** @type Boolean */
isIE : isIE,
/** @type Boolean */
isIE6 : isIE && !isIE7,
/** @type Boolean */
isIE7 : isIE7,
/** @type Boolean */
isGecko : isGecko,
/** @type Boolean */
isBorderBox : isBorderBox,
/** @type Boolean */
isLinux : isLinux,
/** @type Boolean */
isWindows : isWindows,
/** @type Boolean */
isMac : isMac,
/** @type Boolean */
isAir : !!window.htmlControl,
/**
By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
you may want to set this to true.
@type Boolean
*/
useShims : ((isIE && !isIE7) || (isGecko && isMac))
});
// in intellij using keyword "namespace" causes parsing errors
Ext.ns = Ext.namespace;
})();
Ext.ns("Ext", "Ext.util", "Ext.grid", "Ext.dd", "Ext.tree", "Ext.data",
"Ext.form", "Ext.menu", "Ext.state", "Ext.lib", "Ext.layout", "Ext.app", "Ext.ux");
/**
* @class Function
* These functions are available on every Function object (any JavaScript function).
*/
Ext.apply(Function.prototype, {
/**
* Creates a callback that passes arguments[0], arguments[1], arguments[2], ...
* Call directly on any function. Example: <code>myFunction.createCallback(myarg, myarg2)</code>
* Will create a function that is bound to those 2 args.
* @return {Function} The new function
*/
createCallback : function(/*args...*/){
// make args available, in function below
var args = arguments;
var method = this;
return function() {
return method.apply(window, args);
};
},
/**
* Creates a delegate (callback) that sets the scope to obj.
* Call directly on any function. Example: <code>this.myFunction.createDelegate(this)</code>
* Will create a function that is automatically scoped to this.
* @param {Object} obj (optional) The object for which the scope is set
* @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
* @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
* if a number the args are inserted at the specified position
* @return {Function} The new function
*/
createDelegate : function(obj, args, appendArgs){
var method = this;
return function() {
var callArgs = args || arguments;
if(appendArgs === true){
callArgs = Array.prototype.slice.call(arguments, 0);
callArgs = callArgs.concat(args);
}else if(typeof appendArgs == "number"){
callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
var applyArgs = [appendArgs, 0].concat(args); // create method call params
Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
}
return method.apply(obj || window, callArgs);
};
},
/**
* Calls this function after the number of millseconds specified.
* @param {Number} millis The number of milliseconds for the setTimeout call (if 0 the function is executed immediately)
* @param {Object} obj (optional) The object for which the scope is set
* @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
* @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
* if a number the args are inserted at the specified position
* @return {Number} The timeout id that can be used with clearTimeout
*/
defer : function(millis, obj, args, appendArgs){
var fn = this.createDelegate(obj, args, appendArgs);
if(millis){
return setTimeout(fn, millis);
}
fn();
return 0;
},
/**
* Create a combined function call sequence of the original function + the passed function.
* The resulting function returns the results of the original function.
* The passed fcn is called with the parameters of the original function
* @param {Function} fcn The function to sequence
* @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window)
* @return {Function} The new function
*/
createSequence : function(fcn, scope){
if(typeof fcn != "function"){
return this;
}
var method = this;
return function() {
var retval = method.apply(this || window, arguments);
fcn.apply(scope || this || window, arguments);
return retval;
};
},
/**
* Creates an interceptor function. The passed fcn is called before the original one. If it returns false, the original one is not called.
* The resulting function returns the results of the original function.
* The passed fcn is called with the parameters of the original function.
* @addon
* @param {Function} fcn The function to call before the original
* @param {Object} scope (optional) The scope of the passed fcn (Defaults to scope of original function or window)
* @return {Function} The new function
*/
createInterceptor : function(fcn, scope){
if(typeof fcn != "function"){
return this;
}
var method = this;
return function() {
fcn.target = this;
fcn.method = method;
if(fcn.apply(scope || this || window, arguments) === false){
return;
}
return method.apply(this || window, arguments);
};
}
});
/**
* @class String
* These functions are available as static methods on the JavaScript String object.
*/
Ext.applyIf(String, {
/**
* Escapes the passed string for ' and \
* @param {String} string The string to escape
* @return {String} The escaped string
* @static
*/
escape : function(string) {
return string.replace(/('|\\)/g, "\\$1");
},
/**
* Pads the left side of a string with a specified character. This is especially useful
* for normalizing number and date strings. Example usage:
* <pre><code>
var s = String.leftPad('123', 5, '0');
// s now contains the string: '00123'
</code></pre>
* @param {String} string The original string
* @param {Number} size The total length of the output string
* @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ")
* @return {String} The padded string
* @static
*/
leftPad : function (val, size, ch) {
var result = new String(val);
if(ch === null || ch === undefined || ch === '') {
ch = " ";
}
while (result.length < size) {
result = ch + result;
}
return result;
},
/**
* Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
* token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
* <pre><code>
var cls = 'my-class', text = 'Some text';
var s = String.format('<div class="{0}">{1}</div>', cls, text);
// s now contains the string: '<div class="my-class">Some text</div>'
</code></pre>
* @param {String} string The tokenized string to be formatted
* @param {String} value1 The value to replace token {0}
* @param {String} value2 Etc...
* @return {String} The formatted string
* @static
*/
format : function(format){
var args = Array.prototype.slice.call(arguments, 1);
return format.replace(/\{(\d+)\}/g, function(m, i){
return args[i];
});
}
});
/**
* Utility function that allows you to easily switch a string between two alternating values. The passed value
* is compared to the current string, and if they are equal, the other value that was passed in is returned. If
* they are already different, the first value passed in is returned. Note that this method returns the new value
* but does not change the current string.
* <pre><code>
// alternate sort directions
sort = sort.toggle('ASC', 'DESC');
// instead of conditional logic:
sort = (sort == 'ASC' ? 'DESC' : 'ASC');
</code></pre>
* @param {String} value The value to compare to the current string
* @param {String} other The new value to use if the string already equals the first value passed in
* @return {String} The new value
*/
String.prototype.toggle = function(value, other){
return this == value ? other : value;
};
/**
* Trims whitespace from either end of a string, leaving spaces within the string intact. Example:
* <pre><code>
var s = ' foo bar ';
alert('-' + s + '-'); //alerts "- foo bar -"
alert('-' + s.trim() + '-'); //alerts "-foo bar-"
</code></pre>
* @return {String} The trimmed string
*/
String.prototype.trim = function(){
var re = /^\s+|\s+$/g;
return function(){ return this.replace(re, ""); };
}();
/**
* @class Number
*/
Ext.applyIf(Number.prototype, {
/**
* Checks whether or not the current number is within a desired range. If the number is already within the
* range it is returned, otherwise the min or max value is returned depending on which side of the range is
* exceeded. Note that this method returns the constrained value but does not change the current number.
* @param {Number} min The minimum number in the range
* @param {Number} max The maximum number in the range
* @return {Number} The constrained value if outside the range, otherwise the current value
*/
constrain : function(min, max){
return Math.min(Math.max(this, min), max);
}
});
/**
* @class Array
*/
Ext.applyIf(Array.prototype, {
/**
* Checks whether or not the specified object exists in the array.
* @param {Object} o The object to check for
* @return {Number} The index of o in the array (or -1 if it is not found)
*/
indexOf : function(o){
for (var i = 0, len = this.length; i < len; i++){
if(this[i] == o) return i;
}
return -1;
},
/**
* Removes the specified object from the array. If the object is not found nothing happens.
* @param {Object} o The object to remove
* @return {Array} this array
*/
remove : function(o){
var index = this.indexOf(o);
if(index != -1){
this.splice(index, 1);
}
return this;
}
});
/**
Returns the number of milliseconds between this date and date
@param {Date} date (optional) Defaults to now
@return {Number} The diff in milliseconds
@member Date getElapsed
*/
Date.prototype.getElapsed = function(date) {
return Math.abs((date || new Date()).getTime()-this.getTime());
};
%>
|
|
| 返回顶楼 | |
|
时间:2007-12-27
lz有点本末倒置,我不否认在asp中用jscript来编写脚本的便捷性和强大(较vbscript而言)。但是,要知道,Ext还不是就是在模仿众多其他语言的特性。而且,asp也是解释性的,Ext那么大的代码量(基础库),并不适合做服务器端语言,压力是绝对扛不住的。asp是微软的东西,就老老实实的用VBScript写,VBScript足够用来写asp,VBScript的很多特性只是你还没有发觉,它甚至也能来模仿mvc,模拟代理接口,模拟RPC等等。asp毕竟已是上个时代的产物了,但是众多小企业介于它的成本低,而一直用它是很不合理的。
|
|
| 返回顶楼 | |
|
时间:2007-12-27
实际上我们已经有几套产品是基于这种方案的(Extjs+ASP Jscript+MS ISAPI/COM+)。
很高兴YUI/EXT为我们带来完整的OO JS,而且基于国内廉价的ASP主机,利用Ext.template类就可轻松实现静态方案 相对JAVA丰富的开源项目,COM组件虽丰富但大多都收费的, 不过国外也有一些资源网站如codeMaster可免费提供(大多是N年前写好)。 下一步的计划的将这种COM组件的方案无缝升级到.net环境(没办法有时客户只认.net)。 by the way,迁移到RINHO也不是未尝不可,但是如何找到与COM对应的组件和VM性能是两个最大的问题(毕竟MS COM依赖原生C/C++写成的库,效率应该较高). |
|
| 返回顶楼 | |
|
时间:2007-12-27
呵呵,请再看一下我的主题?
我的主题叫做"JScript 是最适合 ExtJS 的服务器侧语言", 而不是说"JScript 是最好的服务器侧语言"啊. 为什么有这个"最适合 ExtJS" 的限定语呢? 因为我们利用ExtJS为企业做了几套信息化 Solutions, 发现自从 Client side 使用 ExtJS 以后, 使 Server Side 的工作量大大减少, 计算量和代码量大大减少, Server CPU 负荷大大降低. 那些在传统模式下 Server side 承担的 UI 生成/Page 刷新任务, 现在都不需要了! Server 的功能被大大弱化, 我们会发现 Server Side 只需要扮演一个 Data Provider 的角色了,只需要响应Client Side的请求,提供数据, 再加上权限验证功能, 仅此而已. 对于这么一些功能, 使用 ASP/JScript 足矣. 当然,用 java 或者.NET也不是不可以,但是会有杀鸡用牛刀的感觉. java 或者 .NET 提供了强大的 OOP, 但那不也是依赖强大的基础库吗? 它们提供了那么多封装好的 Components, 在 ExtJS 框架里都用不上了, 不也是一种资源浪费吗? 当然, ExtJS 减轻了 Server 的负荷, 但却增加了 Client 的负荷, 只适合企业内部宽带 Intranet 信息化系统的开发, 我想谁也不会拿 ExtJS 做整个 Internet 网站吧. |
|
| 返回顶楼 | |
|
时间:2007-12-27
sp42 写道 实际上我们已经有几套产品是基于这种方案的(Extjs+ASP Jscript+MS ISAPI/COM+)。
很高兴YUI/EXT为我们带来完整的OO JS,而且基于国内廉价的ASP主机,利用Ext.template类就可轻松实现静态方案 相对JAVA丰富的开源项目,COM组件虽丰富但大多都收费的, 不过国外也有一些资源网站如codeMaster可免费提供(大多是N年前写好)。 下一步的计划的将这种COM组件的方案无缝升级到.net环境(没办法有时客户只认.net)。 by the way,迁移到RINHO也不是未尝不可,但是如何找到与COM对应的组件和VM性能是两个最大的问题(毕竟MS COM依赖原生C/C++写成的库,效率应该较高). 感谢你提供 ajaxjs.com 这么一个中文的 ExtJS 论坛, 也感谢你对 ExtJS 教程中文化的贡献:) |
|
| 返回顶楼 | |
|
时间:2007-12-27
Cabo 写道 呵呵,请再看一下我的主题?
我的主题叫做"JScript 是最适合 ExtJS 的服务器侧语言", 而不是说"JScript 是最好的服务器侧语言"啊. 为什么有这个"最适合 ExtJS" 的限定语呢? 因为我们利用ExtJS为企业做了几套信息化 Solutions, 发现自从 Client side 使用 ExtJS 以后, 使 Server Side 的工作量大大减少, 计算量和代码量大大减少, Server CPU 负荷大大降低. 那些在传统模式下 Server side 承担的 UI 生成/Page 刷新任务, 现在都不需要了! Server 的功能被大大弱化, 我们会发现 Server Side 只需要扮演一个 Data Provider 的角色了,只需要响应Client Side的请求,提供数据, 再加上权限验证功能, 仅此而已. 对于这么一些功能, 使用 ASP/JScript 足矣. 当然,用 java 或者.NET也不是不可以,但是会有杀鸡用牛刀的感觉. java 或者 .NET 提供了强大的 OOP, 但那不也是依赖强大的基础库吗? 它们提供了那么多封装好的 Components, 在 ExtJS 框架里都用不上了, 不也是一种资源浪费吗? 当然, ExtJS 减轻了 Server 的负荷, 但却增加了 Client 的负荷, 只适合企业内部宽带 Intranet 信息化系统的开发, 我想谁也不会拿 ExtJS 做整个 Internet 网站吧. 将JScript作为服务端语言并结合ext来构建项目,在技术上是值得探究的,但这个话题的现实意义不大(有,但不大),这好比是说主体设计由基础设施来决定。另外目前绝大多数利用了AJAX技术的web应用都是由Client来承担UI生成的,非Ext独美,倒是Ext对常用UI元素的封装以及数据呈现的细节控制让开发效率提高了不少。 |
|
| 返回顶楼 | |
|
时间:2007-12-28
也不能说意义不大
对于还在用asp的场合,用jscript甚至是支持activescript接口的脚本像python ,来改善设计还是很有必要的 再说,很多时候用户只关心使用体验,并不在意后端的东西(只是打单时另做别论) |
|
| 返回顶楼 | |
|
时间:2007-12-28
[quote="jjx"]也不能说意义不大对于还在用asp的场合,用jscript甚至是支持activescript接口的脚本像python ,来改善设计还是很有必要的 再说,很多时候用户只关心使用体验,并不在意后端的东西(只是打单时另做别论) [/quote] 用户是不关心后端的东西,但是做为一个开发者,是必须考虑服务器端的众多因素的。其中服务器的压力是主要的一点。ajax的诞生,就是为了减轻服务器压力,而在解释性语言的服务器端做“太多”的事情,同样是会加重服务器负担的。当服务器压力增大了,客户端相应就慢了,这难道还称得上好的用户体验吗? |
|
| 返回顶楼 | |
|
时间:2007-12-28
理论上解释性语言是慢,但据我所知一些大型的网站 如携程网、china-pub还是沿用asp,那他们为什么不升级到非解释性语言呢?莫非他们是掩眼法,做URL映射?
|
|
| 返回顶楼 | |






