jquery.string.js
/**
* jquery.string - Prototype string functions for jQuery
* version: 1.1.0
* (c) 2008-2011 David E. Still (http://stilldesigning.com)
* Original Prototype extensions (c) 2005-2011 Sam Stephenson (http://prototypejs.org)
*/
(function (f) {
f.extend({
__stringPrototype: function (h) {
function i(a) {
if (!a.source)return a;
return RegExp(a.source, "g" + (a.ignoreCase ? "i" : "") + (a.multiline ? "m" : ""))
} var j = "a b".split(/\w/)[0] == " ";
this.str = h;
this.JSONFilter = /^\/\*-secure-([\s\S]*)\*\/\s*$/;
this.ScriptFragment = "<script[^>]*>([\\S\\s]*?)<\/script>";
this.specialChar = {"\u0008": "\\b", "\t": "\\t", "\n": "\\n", "\u000c": "\\f", "\r": "\\r", "\\": "\\\\"};
this.blank = function (a) {
return /^\s*$/.test(this.s(a) || " ")
};
this.camelize = function (a) {
var b = this.s(a).split("-"),
c, a = [b[0]];
for (c = 1; c < b.length; c++)a.push(b[c].charAt(0).toUpperCase() + b[c].substring(1));
this.str = a.join("");
return this
};
this.capitalize = function (a) {
a = this.s(a);
this.str = a.charAt(0).toUpperCase() + a.substring(1).toLowerCase();
return this
};
this.dasherize = function (a) {
this.str = this.s(a).split("_").join("-");
return this
};
this.empty = function (a) {
return a ? a == "" : this.str == ""
};
this.endsWith = function (a, b) {
var b = this.s(b), c = b.length - a.length;
return c >= 0 && b.lastIndexOf(a) === c
};
this.escapeHTML = function (a) {
this.str =
this.s(a).split("&").join("&").split("<").join("<").split(">").join(">");
return this
};
this.evalJSON = function (a, b) {
var b = this.s(b), c = this.unfilterJSON(!1, b).str;
try {
if (!a || this.isJSON(c))return eval("(" + c + ")")
} catch (d) {
}
throw new SyntaxError("Badly formed JSON string: " + b);
};
this.evalScripts = function (a) {
var a = this.extractScripts(this.s(a)), b = [];
if (a.length > 0)for (var c = 0; c < a.length; c++)b.push(eval(a[c]));
return b
};
this.extractScripts = function (a) {
var b = RegExp(this.ScriptFragment, "img"), c = RegExp(this.ScriptFragment,
"im"), a = this.s(a).match(b) || [], b = [];
if (a.length > 0)for (var d = 0; d < a.length; d++)b.push(a[d].match(c)[1] || "");
return b
};
this.gsub = function (a, b, c) {
c = this.s(c);
if (f.isFunction(b)) {
var d = c.match(i(a));
if (d == null)return this;
c = this.sub(a, b, d.length, c).str
} else c = c.split(a).join(b);
this.str = c;
return this
};
this.include = function (a, b) {
return this.s(b).indexOf(a) > -1
};
this.inspect = function (a, b) {
var b = this.s(b), c = this.specialChar, d = this.gsub(/[\x00-\x1f\\]/, function (a) {
var b = c[a[0]];
return b ? b : "\\u00" + a[0].charCodeAt().toPaddedString(2,
16)
}, b).str;
this.str = a ? '"' + d.replace(/"/g, '\\"') + '"' : "'" + d.replace(/'/g, "\\'") + "'";
return this
};
this.interpolate = function (a, b, c) {
c = this.s(c);
b || (b = /(^|.|\r|\n)(\#\{\s*(\w+)\s*\})/);
for (var d = 0, g = c.length, e; b.match(c) && d++ < g;)e = b.exec(c), c = this.gsub(e[2], a[e[3]], c).str;
this.str = c;
return this
};
this.isJSON = function (a) {
a = this.s(a);
if (this.blank(a))return !1;
a = a.replace(/\\./g, "@").replace(/"[^"\\\n\r]*"/g, "");
return /^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/.test(a)
};
this.scan = function (a, b, c) {
c = this.s(c);
this.gsub(a,
b, c).str = c;
return this
};
this.startsWith = function (a, b) {
return this.s(b).indexOf(a) === 0
};
this.strip = function (a) {
this.str = f.trim(this.s(a));
return this
};
this.stripScripts = function (a) {
this.str = this.s(a).replace(RegExp(this.ScriptFragment, "img"), "");
return this
};
this.stripTags = function (a) {
this.str = this.s(a).replace(/<\/?[^>]+>/gi, "");
return this
};
this.sub = function (a, b, c, d) {
d = this.s(d);
c = !c ? 1 : c;
if (c < 0 || isNaN(c))return this;
var a = i(a), g = d.split(a), e = d.match(a);
j && typeof a == "object" && (c == e.length && ++c, d.indexOf(e[0]) ==
0 && g.unshift(""), d.lastIndexOf(e[e.length - 1]) == d.length - e[e.length - 1].length && g.push(""));
d = g[0];
for (a = 1; a < g.length; a++)d += a <= c ? f.isFunction(b) ? b(e[a - 1] || e) + g[a] : b + g[a] : (e[a - 1] || e) + g[a];
this.str = d;
return this
};
this.succ = function (a) {
a = this.s(a);
this.str = a.slice(0, a.length - 1) + String.fromCharCode(a.charCodeAt(a.length - 1) + 1);
return this
};
this.times = function (a, b) {
this.str = a < 1 ? "" : Array(a + 1).join(this.s(b));
return this
};
this.toJSON = function (a) {
return this.inspect(!0, this.s(a))
};
this.toQueryParams = function (a,
b) {
var b = this.s(b), c = b.substring(b.indexOf("?") + 1).split("#")[0].split(a || "&"), d = {}, g, e, f;
for (g = 0; g < c.length; g++)f = c[g].split("="), e = decodeURIComponent(f[0]), f = f[1] ? decodeURIComponent(f[1]) : void 0, d[e] ? (typeof d[e] == "string" && (d[e] = [d[e]]), d[e].push(f)) : d[e] = f;
return d
};
this.truncate = function (a, b, c) {
c = this.s(c);
a = a || 30;
b = !b ? "..." : b;
this.str = c = c.length > a ? c.slice(0, a - b.length) + b : String(c);
return this
};
this.underscore = function (a) {
this.gsub(/[A-Z]/, function (a) {
return "_" + a.toLowerCase()
}, this.s(a));
if (this.str.substring(0,
1) == "_")this.str = this.str.substring(1);
return this
};
this.unescapeHTML = function (a) {
this.str = this.stripTags(this.s(a)).str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
return this
};
this.unfilterJSON = function (a, b) {
var b = this.s(b), a = a || this.JSONFilter, c = b.match(a);
this.str = c !== null ? c[1] : b;
return this
};
this.value = function () {
return this.str
};
this.s = function (a) {
return a ? a : this.str
}
}, string: function (h) {
if (h === String.prototype)f.extend(String.prototype, new f.__stringPrototype); else return new f.__stringPrototype(h)
}
});
f.__stringPrototype.parseQuery = f.__stringPrototype.toQueryParams
})(jQuery);
jquery.string.js的更多相关文章
- 动态生成二维码插件 jquery.qrcode.js
前段时间做项目,需要动态生成一个二维码,于是就在网上找了一下发现一个jquery插件jquery.qrcode.js,所以今天就简单说一下这个插件的使用: jquery.qrcode.js是依赖jqu ...
- jQuery插件 -- Cookie插件jquery.cookie.js(转)
Cookie是网站设计者放置在客户端的小文本文件.Cookie能为用户提供很多的使得,例如购物网站存储用户曾经浏览过的产品列表,或者门户网站记住用户喜欢选择浏览哪类新闻. 在用户允许的情况下,还可以存 ...
- jQuery验证控件jquery.validate.js使用说明
官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery plugin: Validation 使用说明 转载 ...
- jquery.validate.js插件使用
jQuery验证控件jquery.validate.js使用说明+中文API 官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-valid ...
- jquery.validate.js表单验证
一.用前必备官方网站:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API: http://jquery.bassist ...
- jquery.cookie.js && java后台代码 操作cookie实现记住当前用户输入信息代码
下载jquery.cookie.js地址看这里:http://pan.baidu.com/s/1gdCPaN5 //初始化页面时验证是否记住了密码 $(document).ready(function ...
- 当 jquery.unobtrusive-ajax.js 遇上Web API
最近在熟悉Abp框架,其基于DDD领域驱动设计...前段可以绕过mvc直接调用根据app层动态生成的webapi,有点神奇~,Web API之前有简单接触过,WCF的轻量级版,一般用于做一写开发性的服 ...
- jQuery String Functions
In today's post, I have put together all jQuery String Functions. Well, I should say that these are ...
- Jquery.cookie.js 源码和使用方法
jquery.cookie.js源码和使用方法 jQuery操作cookie的插件,大概的使用方法如下 $.cookie(‘the_cookie’); //读取Cookie值$.cookie(’the ...
随机推荐
- Jmeter 逻辑控制器总结
本文主要总结Jmeter的逻辑控制器: 逻辑控制器下一共16个控制器: 1.foreach controller循环控制器 定义变量数组,按数组遍历循环 2.simple controller 简 ...
- Kettle中并行执行测试
整个作业截图: 设置并行方法:右键 START 组件,勾选最后一个选项: Run Next Entries In Parallel 设置aa, bb, cc, dd, ee 都是shell脚本,内容都 ...
- 责任链模式-Chain of Responsibility(Java实现), 例2
责任链模式-Chain of Responsibility 在这种模式中,通常每个接收者都包含对另一个接收者的引用.如果一个对象不能处理该请求,那么它会把相同的请求传给下一个接收者,依此类推. 咱们在 ...
- 一段充满bug的R程序,慎入 ...
twitter的AnomalyDetection 官网效果图如下: 尝试写了下面这个R程序: get_specify_df <- function(start_ts,stop_ts,categ ...
- GCC 警告
-w -W禁止/开启 编译警告的打印.这个警告不建议使用.大约2012年底,公司代码进行一次大重构,另外从Codeblock集成开发环境转向Makefile管理,Makefile里面默认使用了-w,因 ...
- knockoutjs复杂对象的可观察性
问题 对于一般数据结构: 1. 对于基本类型的数据的变更的可观察性(observable), 可以使用 ko.observable(xxx) 来声明一个 observable对象, 或将其绑定到视图 ...
- Hper-V卸载
1.txt文件输入以下内容,后缀改为cmd,以管理员身份执行 mountvol X: /s copy %WINDIR%\System32\SecConfig.efi X:\EFI\Microsoft\ ...
- 通用RSA加密 - PHP+Java+Javascript加密解密
php端生成 公钥私钥 1.openssl genrsa -out rsa_private_key.pem 1024 私钥 2.openssl rsa -in rsa_private_key.p ...
- WebApi-2 自定义路由与默认路由
向Web API添加路由 public static void Register(HttpConfiguration config) { //// Web API 配置和服务 //// 将 Web A ...
- memcache的基本操作
1.linux下启动memcache [root@localhost ~]# memcached -d -m 512 -u root -p 12266 -c 256 参数名称及意义: -d 以守护 ...