You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
182 lines
5.2 KiB
JavaScript
182 lines
5.2 KiB
JavaScript
|
|
function checkPwdStrong(pwd) {
|
|
var c0 = pwd.length >= 6;
|
|
var c1 = /[a-z]+/.test(pwd);
|
|
var c2 = /[A-Z]+/.test(pwd);
|
|
var c3 = /[0-9]+/.test(pwd);
|
|
if (c0 && c1 && c2 && c3) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
$.fn.serializeObject = function () {
|
|
var o = {};
|
|
var a = this.serializeArray();
|
|
$.each(a, function () {
|
|
if (o[this.name]) {
|
|
if (!o[this.name].push) {
|
|
o[this.name] = [o[this.name]];
|
|
}
|
|
o[this.name].push(this.value || '');
|
|
} else {
|
|
o[this.name] = this.value || '';
|
|
}
|
|
});
|
|
return o;
|
|
}
|
|
|
|
|
|
$.fn.toJson = function () {
|
|
var self = this,
|
|
json = {},
|
|
push_counters = {},
|
|
patterns = {
|
|
"validate": /^[a-zA-Z][a-zA-Z0-9_]*(?:\[(?:\d*|[a-zA-Z0-9_]+)\])*$/,
|
|
"key": /[a-zA-Z0-9_]+|(?=\[\])/g,
|
|
"push": /^$/,
|
|
"fixed": /^\d+$/,
|
|
"named": /^[a-zA-Z0-9_]+$/
|
|
};
|
|
|
|
this.build = function (base, key, value) {
|
|
base[key] = value;
|
|
return base;
|
|
};
|
|
|
|
this.push_counter = function (key) {
|
|
if (push_counters[key] === undefined) {
|
|
push_counters[key] = 0;
|
|
}
|
|
return push_counters[key]++;
|
|
};
|
|
|
|
$.each($(this).serializeArray(), function () {
|
|
// skip invalid keys
|
|
if (!patterns.validate.test(this.name)) {
|
|
return;
|
|
}
|
|
|
|
var k,
|
|
keys = this.name.match(patterns.key),
|
|
merge = this.value,
|
|
reverse_key = this.name;
|
|
|
|
while ((k = keys.pop()) !== undefined) {
|
|
// adjust reverse_key
|
|
reverse_key = reverse_key.replace(new RegExp("\\[" + k + "\\]$"), '');
|
|
|
|
// push
|
|
if (k.match(patterns.push)) {
|
|
merge = self.build([], self.push_counter(reverse_key), merge);
|
|
}
|
|
|
|
// fixed
|
|
else if (k.match(patterns.fixed)) {
|
|
merge = self.build([], k, merge);
|
|
}
|
|
|
|
// named
|
|
else if (k.match(patterns.named)) {
|
|
merge = self.build({}, k, merge);
|
|
}
|
|
}
|
|
|
|
json = $.extend(true, json, merge);
|
|
});
|
|
|
|
return json;
|
|
};
|
|
|
|
|
|
$.fn.loadData = function (obj) {
|
|
var key, value, tagName, type, arr;
|
|
|
|
this.resetForm();
|
|
|
|
for (var x in obj) {
|
|
if (obj.hasOwnProperty(x)) {
|
|
key = x;
|
|
value = obj[x];
|
|
|
|
this.find("[name='" + key + "'],[name='" + key + "[]']").each(function () {
|
|
tagName = $(this)[0].tagName.toUpperCase();
|
|
type = $(this).attr('type');
|
|
if (tagName == 'INPUT') {
|
|
if (type == 'radio') {
|
|
if ($(this).val() == value) {
|
|
$(this).attr('checked', true);
|
|
}
|
|
} else if (type == 'checkbox') {
|
|
if (value) {
|
|
$(this).prop('checked', true);
|
|
} else {
|
|
$(this).prop('checked', false);
|
|
}
|
|
} else {
|
|
$(this).val(value);
|
|
}
|
|
} else if (tagName == 'SELECT' || tagName == 'TEXTAREA') {
|
|
$(this).val(value);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
$(function () {
|
|
$(document).on('click', 'a.tabs', function () {
|
|
var url = $(this).data('url');
|
|
if (url != undefined && url.length > 0) {
|
|
var title = $(this).data('title');
|
|
if (title == undefined) {
|
|
title = "New Page";
|
|
}
|
|
|
|
//debugger;
|
|
if (url.indexOf('?') > -1) {
|
|
url += "&rnd=" + new Date()
|
|
} else {
|
|
url += "?rnd=" + new Date()
|
|
}
|
|
|
|
parent.addMenuTab(url, title, 0)
|
|
}
|
|
});
|
|
})
|
|
|
|
|
|
function formatTextarea(len, id) {
|
|
var textareaFiled = $("#" + id);
|
|
var value = textareaFiled.val();
|
|
//var textArr = value.match(/([\w]+[ ]*)|([^u4e00-u9fa5|\r|\n]+[ ]*)|([@|=|^|<|>]+[ ]*)/g);//匹配字母数字汉字及特殊字符{Array<string>}
|
|
var textArr = value.match(/.+[\n]*/g);//按行匹配
|
|
var subValue = "";
|
|
|
|
for (var j = 0; j < textArr.length; j++) {
|
|
var subArr = textArr[j].match(/[\w]+[ ]*[\n]*|[\d]+[ ]*[\n]*|[^\w\d]+[ ]*[\n]*/g);
|
|
var count = 0;
|
|
for (var i = 0; i < subArr.length; i++) {
|
|
count += subArr[i].replace(/\n/g, "").length;
|
|
while (count > len) {
|
|
subValue += "\n";
|
|
count = subArr[i].replace(/\n/g, "").length;
|
|
if (count > len) {
|
|
subValue += subArr[i].substring(0, len);
|
|
subValue += "\n";
|
|
subArr[i] = subArr[i].substring(len);
|
|
count = subArr[i].replace(/\n/g, "").length;
|
|
}
|
|
}
|
|
subValue += subArr[i];
|
|
}
|
|
if (j + 1 < textArr.length)
|
|
subValue += "\n";
|
|
}
|
|
subValue = subValue.replace(/[\n]+/g, "\n");//多个换行变为一个换行
|
|
subValue = subValue.replace(/[ ]+[\n]+/g, '\n');//去除每行末尾空格
|
|
subValue = subValue.replace(/[ ]+$/g, '');//去除末行空格
|
|
textareaFiled.val(subValue);
|
|
} |