){2,}/gim, '
');
html = html.replace(/(<\/div>){2,}/gim, '
');
html = html.replace(/(
]*>)/gim, '');
html = html.replace(/(<\/span>)/gim, '');
html = html.replace(/<\/div>/gim, '');
// 过滤除div以外的标签
// html = html.replace(tagReg, '');
// html = html.replace(/
]?>([^<]?)<\/span>/gim, function() {
// debugger;
// console.log(arguments);
// });
html = face.imgs2MoblieCode(html);
html = face.imgs2Code(html);
return {
text: text,
rich: html
};
};
renderIntro.isModify = function(intro) {
// debugger;
return this.getIntro().rich !== unescape(intro).replace(/ /g, ' '); // face.decode(intro);
};
module.exports = renderIntro;
},{"../../lib/util":19,"./editor":24,"./face":25,"./report":31,"./xss":37,"lodash.escape":1,"lodash.unescape":12}],28:[function(require,module,exports){
'use strict';
var $ = window.Zepto || window.$;
var cgi = require('./cgi');
var widget = require('../../lib/widget');
var catalog = require('./catalog');
var client = require('../../lib/callClient');
var tmpl = {
select: require('./tmpl/select')
};
// 配置项
var schoolConfig = require('./jxconfig');
var $selectOuter = $('#jxCity .select-outer');
var $selectOuter2 = $('#jxSchool .select-outer');
var $selectOuter3 = $('#jxClass .select-outer');
// var gradeInput = '';
function gradeInput(value) {
return '';
}
// var $jxSchoolInput = $('#jxSchoolInput');
// var $jxClassInput = $('#jxClassInput');
// 临时变量
var newClassDetail = [undefined, undefined, undefined, undefined, undefined, undefined];
var newProvince;
var category;
// 获取前6年
function getYears() {
var d = new Date();
var year = d.getFullYear();
var list = [];
for (var i = year; i > year - 7; i--) {
list.push({
value: i,
text: i + '级'
});
}
return list;
}
function isOtherGrade(schoolType) {
return schoolType === '培训机构' || schoolType === '其他';
}
// 设置学校信息
function setSchoolType(schoolType, schoolName) {
category = schoolType || '';
schoolType = schoolType || '在读类型';
schoolName = schoolName || '';
var select = tmpl.select({
list: schoolConfig.schoolType
});
select = '' + select + '
';
$selectOuter2.html(select);
widget.transSelect($selectOuter2.find('select'), function(id, text) {
void 0;
var list = schoolConfig.getGradeById(id);
setClassSelect(list);
newClassDetail[1] = text;
newClassDetail[4] = undefined;
category = text;
}, {
default: schoolType
});
createSuggestion($('#jxSchoolInput'), $('#jxSchoolList'));
}
// 设置班级信息
function setClass(schoolType, year, grade, className) {
// debugger;
if (year) ~year.indexOf('级') || (year += '级');
else year = '入学年份';
className = className || '';
var list = getYears();
var select = tmpl.select({
list: list
});
var html = '' + select + '
' + (isOtherGrade(schoolType) ? gradeInput(grade) : '') + '
';
$selectOuter3.html(html);
widget.transSelect($selectOuter3.find('.select-wrap:first-child select'), function(id, text) {
void 0;
newClassDetail[3] = id;
}, {
default: year
});
list = schoolConfig.getGradeByName(schoolType);
setClassSelect(list, grade);
}
function setClassSelect(list, defaultGrade) {
list || (list = ['选择年级']);
defaultGrade = defaultGrade || '选择年级';
var $select = $selectOuter3.find('.select-wrap:nth-child(2)');
// 常规类型
if (list.length) {
var select = tmpl.select({
list: list
});
$select.html(select);
widget.transSelect($select.find('select'), function(id, text) {
newClassDetail[4] = text;
}, {
default: defaultGrade,
stopDefault: function() {
if (typeof newClassDetail[1] === 'undefined') {
client.alert(1, '群资料卡', '请先选择在读类型');
return true;
}
return false;
}
});
} else {
// 培训和其他
$select.html(gradeInput(defaultGrade));
}
}
function setCity(cityId) {
// debugger;
var defaultProvince = {
text: '省/直辖市'
};
cityId && (defaultProvince = catalog.getProvinceByCity(cityId));
// 取同城的城市数据
var list = catalog.getProvinceList();
var select = tmpl.select({
list: list
});
select = '' + select + '
';
$selectOuter.html(select);
function selectCity(province, city) {
var defaultCity = {
text: '市/区'
};
city && (defaultCity = catalog.getCityById(city));
var $s = $selectOuter.find('.location:nth-child(2)');
var list = ['市/区'];
province && (list = catalog.getCityList(province));
var select = tmpl.select({
list: list
});
$s.html(select);
newClassDetail[0] = defaultCity.value;
widget.transSelect($s.find('select'), function(city, name) {
void 0;
newClassDetail[0] = city;
}, {
default: defaultCity.text
});
}
widget.transSelect($selectOuter.find('.location:first-child select'), function(province, name) {
void 0;
newProvince = province;
newClassDetail[0] = undefined;
selectCity(province);
}, {
default: defaultProvince.text
});
newProvince = defaultProvince.value;
selectCity(defaultProvince.value, cityId);
}
function createSuggestion($input, $container) {
var done;
var querying = false;
function onKeyup() {
void 0;
if (querying) return;
if (category === '其他') return hideContainer();
var s = this.value.trim();
// 中文输入法正在输入,可能会误杀带'名字的学校,不过肯定不多
if (!s || ~s.indexOf("'")) return hideContainer();
var city = catalog.getCityById(newClassDetail[0]).text;
var param = {
keyword: s
};
// 直辖市
if (catalog.isMunicipality(newProvince)) {
newProvince && (param.city = catalog.getCityById(newProvince).text);
city && (param.district = city);
} else {
city && (param.city = city);
}
// cgi数据需要整理
if (category === '初中' || category === '高中') category = '中学';
else if (category === '中专') category = '职业技术学校';
else if (category === '培训机构') category = '培训';
category && (param.category = category);
querying = true;
cgi.querySchool(param).done(function(res) {
querying = false;
void 0;
var result = res.sch_all;
if (!result || !result.data || !result.data.length) return hideContainer();
result = result.data;
var list = result.map(function(item) {
return {
value: item.name,
text: item.name
};
});
var select = tmpl.select({
list: list
});
var $select = $container.html('' + select + '
').show().find('select');
widget.transSelect($select, function(text) {
$input.val(text);
hideContainer();
done && done(text);
});
}).fail(function() {
querying = false;
});
// 5s后重置,避免引起麻烦
setTimeout(function() {
querying = false;
}, 5000);
function hideContainer() {
$container.html('').hide();
}
}
$input.off('input', onKeyup);
$input.on('input', onKeyup);
return function(fn) {
done = fn;
}
}
// 根据cgi数据展示家校群额外信息
exports.renderSchool = function(classDetail) {
// debugger;
var items = classDetail.split('|');
// items = items.map(function(item) {
// return decodeURIComponent(item);
// });
// 将省市名称换算成城市id
var province = items[0];
var city = items[1];
city = catalog.getCityIdByProvinceAndCity(province, city);
if (items.length > 6) {
items.splice(0, 1);
items[0] = city;
}
newClassDetail = items;
setCity(items[0]);
setSchoolType(items[1], items[2]);
setClass(items[1], items[3], items[4], items[5]);
};
/*
家校群字段校验
*/
function validateDetail() {
void 0;
var msg;
if (typeof newProvince === 'undefined') msg = '请选择省/直辖市';
else if (typeof newClassDetail[0] === 'undefined') msg = '请选择市/区';
else if (typeof newClassDetail[1] === 'undefined') msg = '请选择在读类型';
else if (!newClassDetail[2]) msg = '请填写学校名称';
else if (~newClassDetail[2].indexOf('|')) msg = '学校名称不能包含特殊字符 |';
else if (typeof newClassDetail[3] === 'undefined') msg = '请选择入学年份';
else if (!newClassDetail[4]) msg = '请选择年级';
else if (!newClassDetail[5]) msg = '请填写班级';
else if (~newClassDetail[5].indexOf('|')) msg = '班级不能包含特殊字符 |';
if (msg) throw new Error(msg);
}
// 保存的时候获取额外信息
exports.getClassDetail = function() {
// debugger;
newClassDetail[2] = $('#jxSchoolInput').val().trim();
newClassDetail[5] = $('#jxClassInput').val().trim();
isOtherGrade(newClassDetail[1]) && (newClassDetail[4] = $('#jxGradeInput').val().trim());
validateDetail();
// debugger;
// 将城市id换算成省市名称
var city = newClassDetail[0];
if (typeof city === 'number') {
var province = catalog.getProvinceByCity(city).text;
city = catalog.getCityById(city).text;
if (!province || !city) throw new Error('请选择地区');
newClassDetail[0] = province + '|' + city;
}
return newClassDetail.join('|');
};
},{"../../lib/callClient":15,"../../lib/widget":20,"./catalog":21,"./cgi":22,"./jxconfig":29,"./tmpl/select":34}],29:[function(require,module,exports){
'use strict';
// 配置项
var schoolType = exports.schoolType = [{
value: 1,
text: '幼儿园',
grade: [{
value: 1,
text: '小小班'
}, {
value: 2,
text: '小班'
}, {
value: 3,
text: '中班'
}, {
value: 4,
text: '大班'
}]
}, {
value: 2,
text: '小学',
grade: [{
value: 1,
text: '一年级'
}, {
value: 2,
text: '二年级'
}, {
value: 3,
text: '三年级'
}, {
value: 4,
text: '四年级'
}, {
value: 5,
text: '五年级'
}, {
value: 6,
text: '六年级'
}]
}, {
value: 3,
text: '初中',
grade: [{
value: 1,
text: '初一'
}, {
value: 2,
text: '初二'
}, {
value: 3,
text: '初三'
}, {
value: 4,
text: '初四'
}]
}, {
value: 4,
text: '高中',
grade: [{
value: 1,
text: '高一'
}, {
value: 2,
text: '高二'
}, {
value: 3,
text: '高三'
}]
}, {
value: 5,
text: '中专',
grade: [{
value: 1,
text: '专一'
}, {
value: 2,
text: '专二'
}, {
value: 3,
text: '专三'
}, {
value: 4,
text: '专四'
}, {
value: 0,
text: '其他'
}]
}, {
value: 6,
text: '培训机构',
// grade: [{
// value: 0,
// text: '其他'
// }]
grade: []
}, {
value: 0,
text: '其他',
// grade: [{
// value: 0,
// text: '其他'
// }]
grade: []
}];
exports.getGradeById = function(id) {
var list = [];
schoolType.some(function(item) {
if (item.value != id) return false;
list = item.grade;
return true;
});
return list;
};
exports.getGradeByName = function(name) {
if (!name) return;
var list = [];
schoolType.some(function(item) {
if (item.text !== name) return false;
list = item.grade;
return true;
});
return list;
};
},{}],30:[function(require,module,exports){
'use strict';
var $ = window.Zepto || window.$;
var util = require('../../lib/util');
var $name = $('#name');
// $name.on('keydown', function(e) {
// var n = util.getTextLength(this.value.trim(), 3);
// console.log(n);
// if(n > 30) {
// e.preventDefault();
// e.stopPropagation();
// e.returnValue = false;
// e.cancelBubble = true;
// return false;
// }
// });
// $name.on('keyup', function(e) {
// // debugger;
// console.log('input', e.keyCode);
// // 左右键
// if(e.keyCode == 37 || e.keyCode == 39) return;
// var v = util.subStr($name.val().trim(), 30);
// console.log(v);
// $name.val(v);
// });
util.setMaxInput($name);
$name.on('click', function() {
$('.item .option-list').addClass('hide');
});
function renderName(name) {
$name.val(util.decodeHtml(name));
// 默认群名称输入框全选状态
$name[0].focus();
$name[0].select();
};
renderName.isModify = function(name) {
return $name.val().trim() !== util.decodeHtml(name);
};
renderName.getName = function() {
return $name.val().trim();
};
module.exports = renderName;
},{"../../lib/util":19}],31:[function(require,module,exports){
'use strict';
var util = require('../../lib/util');
var client = require('../../lib/callClient');
var report = require('../../lib/report');
var uin = client.getSelfUin() || util.getUin();
var version = client.getVersion().version;
var _gtype;
function tdw(action, ver3) {
// 稍后做延迟上报
var opt = {
module: 'edit',
action: action || ''
};
_gtype && (opt.ver2 = _gtype);
ver3 && (opt.ver3 = ver3);
report.tdw(opt);
}
tdw.setType = function(gtype) {
_gtype = gtype;
};
tdw.jx = function(param) {
param = param || {};
var opt = {
uin: uin,
platform: 'PC',
ver: version
};
Object.keys(param).forEach(function(key) {
opt[key] = param[key];
});
report.tdw(opt, false, 'dc00593');
}
module.exports = tdw;
},{"../../lib/callClient":15,"../../lib/report":16,"../../lib/util":19}],32:[function(require,module,exports){
'use strict';
var $ = window.Zepto || window.$;
var tdw = require('./report');
var util = require('../../lib/util');
var client = require('../../lib/callClient');
var cgi = require('./cgi');
var getGinfo = require('./ginfo');
var tmpl = {
label: require('./tmpl/label')
};
var $label = $('#label');
var $keyword = $('#keyword');
var oriTags = [];
var lock = false; // 提交锁
function addTag() {
var label = $keyword.val().trim();
if (!label) return;
var escapedLabel = require('lodash.escape')(label);
if (~oriTags.indexOf(escapedLabel)) return client.alert(1, '温馨提示', '该标签已存在');
// 最多允许输入20个标签
if (oriTags.length >= 20) {
client.alert(1, '温馨提示', '群标签数目已达上限');
tdw('cue_wordtl');
return;
}
if (!window.DEBUG && !client.online()) return client.alert(1, '群资料卡', '您已处于离线状态,请上线后再次尝试');
if (lock) return;
lock = true;
cgi.addTag(label).done(function(res) {
// 先添加标签
oriTags.push(escapedLabel);
void 0;
var html = tmpl.label({
tag: escapedLabel,
md: res.md,
n: '自己',
u: res.u || util.getUin()
});
$label.append(html);
$keyword.val('');
// 通知客户端更新数据
client.onSave(0);
tdw('write_newword');
}).fail(function(err) {
// oriTags.pop(); // 坑了自己
var aTips = ['群不存在', '群已被删除', '没有权限', '标签内容不合法', '24小时内只能贴一次', '标签数目超过上限', '没有权限删除群标签', '群分类信息包含敏感词', '标签不存在', '标签含有敏感词'];
var tips = aTips[err.ec - 11];
(err.ec == 16) && tdw('cue_wordtl');
(err.ec == 504) && (tips = '操作超时了');
tips || (tips = '贴群标签出错了');
client.alert(1, '温馨提示', tips);
}).always(function() {
lock = false;
});
}
$('#labelUp').on('click', addTag);
$keyword.on('keyup', function(e) {
(e.keyCode == 13) && addTag();
});
util.setMaxInput($keyword);
$label.on('click', '.icon-del', function() {
if (!window.DEBUG && !client.online()) return client.alert(1, '群资料卡', '您已处于离线状态,请上线后再次尝试');
var tagID = this.dataset.id;
var label = $(this).prev('span').html();
cgi.removeTag(label, tagID).done(function(res) {
oriTags.splice(oriTags.indexOf(label), 1);
void 0;
$(this).parent().remove();
// 通知客户端更新数据
client.onSave(0);
tdw('del_oldword');
}.bind(this)).fail(function() {
client.alert(1, '温馨提示', '删除群标签出错了');
});
});
module.exports = function renderTags(tags) {
if (!tags || !tags.length) return;
getGinfo(function(err, res) {
if (err || !res) res = {
ns: {}
};
var html = tags.reduce(function(prev, item) {
oriTags.push(item.tag);
item.n = res.ns[item.u] || '';
return prev + tmpl.label(item);
}, '');
$label.html(html);
});
};
},{"../../lib/callClient":15,"../../lib/util":19,"./cgi":22,"./ginfo":26,"./report":31,"./tmpl/label":33,"lodash.escape":1}],33:[function(require,module,exports){
'use strict;'
var _ = {};
var escapeMap = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};
var escapeRegexp = new RegExp('[' + Object.keys(escapeMap).join('') + ']', 'g');
_.escape = function(string) {
if (!string) return '';
return String(string).replace(escapeRegexp, function(match) {
return escapeMap[match];
});
};
module.exports = function(obj) {
obj || (obj = {});
var __t, __p = '', __e = _.escape;
with (obj) {
__p += '\r\n
' +
((__t = (tag)) == null ? '' : __t) +
'\r\n
\r\n \r\n \r\n
';
}
return __p
}
},{}],34:[function(require,module,exports){
'use strict;'
var _ = {};
var escapeMap = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};
var escapeRegexp = new RegExp('[' + Object.keys(escapeMap).join('') + ']', 'g');
_.escape = function(string) {
if (!string) return '';
return String(string).replace(escapeRegexp, function(match) {
return escapeMap[match];
});
};
module.exports = function(obj) {
obj || (obj = {});
var __t, __p = '', __e = _.escape, __j = Array.prototype.join;
function print() { __p += __j.call(arguments, '') }
with (obj) {
__p += '';
}
return __p
}
},{}],35:[function(require,module,exports){
'use strict';
var $ = window.Zepto || window.$;
var unescape = require('lodash.unescape');
var util = require('../../lib/util');
var widget = require('../../lib/widget');
var catalog = require('./catalog');
var detail = require('./detail');
var jiaxiao = require('./jiaxiao');
var tdw = require('./report');
var tmpl = {
select: require('./tmpl/select')
};
var $type = $('#type');
var $tagSection = $('#tagSection');
var $jxSection = $('#jxSection');
var $selectOuter = $('#nameSection .select-outer');
var $selectOuter2 = $('#detailSection .select-outer');
function bindDropdown() {
$type.on('click', function() {
$selectOuter.toggleClass('hide');
$selectOuter2.addClass('hide');
});
}
$(document.body).on('click', function(e) {
if (!$(e.target).is('#type, #detailInput, #detail') && !$.contains($selectOuter[0], e.target) && !$.contains($selectOuter2[0], e.target)) {
$selectOuter.addClass('hide');
$selectOuter2.addClass('hide');
}
});
var newType;
var newDetail;
var hasSubClass = true;
var hasRenderedSchool = false;
// 数据上报
var oriPid;
var oriId;
// 在家校群和普通群之间切换,对应ui需要切换
function toggleType(classID, classDetail) {
// 家校群
// '32' == 32
if (classID == 32) {
void 0;
if (!hasRenderedSchool) {
hasRenderedSchool = true;
jiaxiao.renderSchool(classDetail);
}
$tagSection.hide();
$jxSection.show();
// 切换到家校群
// 上报 PV
tdw.jx({
module: 'createedit',
action: 'view',
obj2: ''
});
} else {
$jxSection.hide();
$tagSection.show();
}
}
function renderType(classID, classDetail) {
newType = classID;
// toggleType(classID);
// var pid = catalog.getPID(classID);
// (pid == 0) && (pid = classID);
var cat = catalog.getCatNamePath(classID);
detail.upDetail(cat.splice(2));
var pid = oriPid = catalog.findIdByName(cat[0]);
classID = oriId = catalog.findSubIdByName(pid, cat[1]);
classID && (newType = classID);
void 0;
$type.html(cat.join('-'));
var list = catalog.getCatLeaf(0);
void 0;
list = list.map(function(item) {
return {
value: item[0],
text: item[1]
};
});
var select = tmpl.select({
list: list
});
var $select = $('#typeSelect1');
var $select2 = $('#typeSelect2');
$select.html(select);
widget.transSelect($select.find('select'), function(id, text) {
newType = id;
$type.text(text);
renderSubType(id, text);
}, {
'default': cat[0]
});
renderSubType(pid, cat[0], cat[1], 1);
bindDropdown();
function renderSubType(id, text, defaultV, init) {
// debugger;
if (init) hasSubClass = true;
else if (id == 0) hasSubClass = true;
else hasSubClass = false;
if (id == 0) return;
// if (init) toggleType(id, classDetail);
// else toggleType(id);
toggleType(id, classDetail);
var done;
var list = catalog.getCatLeaf(id);
void 0;
if (!list || !list.length) {
hasSubClass = true;
$select2.html('');
$selectOuter.addClass('hide');
// $('#type').removeClass('active');
detail.changeDetailState(id, -2, init);
} else {
init || detail.reset();
list = list.map(function(item) {
return {
value: item[0],
text: item[1]
};
});
var select = tmpl.select({
list: list
});
$select2.html(select);
widget.transSelect($select2.find('select'), function(subId, subText) {
newType = subId;
hasSubClass = true;
if (done) return done(subId, subText);
$selectOuter2.html('');
void 0;
if (subText == '其他') detail.changeOther();
else detail.changeDetailState(id, subId);
$type.html(text + '-' + subText);
$selectOuter.addClass('hide');
// $('#type').removeClass('active');
}, {
'default': defaultV || '-'
});
if (!init) return;
detail.changeDetailState(id, classID, init);
}
return function(fn) {
done = fn;
}
}
}
// 检查分类是否有修改
renderType.isModify = function(classID) {
// return this.getType() !== classID;
return newType != classID;
};
// 获取分类id
renderType.getType = function() {
return catalog.getItemIdByPathStr(newType, detail.getType());
};
// 检查是否有选择子分类
renderType.hasSubClass = function() {
return hasSubClass;
};
// 展开分类选择框
renderType.showType = function() {
$selectOuter.removeClass('hide');
};
// 检查一级分类是否被修改,用于上报
renderType.isTypeModify = function() {
var pid = catalog.getPID(newType);
if (pid === 0) return oriPid === parseInt(newType);
return oriPid === pid;
void 0;
};
// 检查二级分类是否被修改,用户上报
renderType.isSubTypeModify = function() {
var pid = catalog.getPID(newType);
if (pid === 0) return Boolean(oriId);
return oriId == newType;
};
renderType.isDetailModify = function(detail) {
var oldDetail = unescape(detail).replace(/ /g, ' ');
var newDetail = this.getClassDetail();
void 0;
return oldDetail !== newDetail;
};
renderType.getClassDetail = function() {
if (newType == 32) return jiaxiao.getClassDetail();
return '';
};
module.exports = renderType;
},{"../../lib/util":19,"../../lib/widget":20,"./catalog":21,"./detail":23,"./jiaxiao":28,"./report":31,"./tmpl/select":34,"lodash.unescape":12}],36:[function(require,module,exports){
'use strict';
var $ = window.Zepto || window.$;
var $wrap = $('#wrap');
var $wording = $('#topWording');
var texts = ['本群是同城群,资料修改需要人工审核,请认真填写。', '群资料已提交同城群审核,通过后才会更新外部显示。'];
$wording.find('.icon-close').on('click', function() {
$wording.remove();
$wrap.removeClass('mt26');
});
module.exports = function(gtype) {
var $text = $wording.find('.text');
if(gtype === 2) {
$wording.removeClass('hide');
$wrap.addClass('mt26');
$text.text(texts[0]);
} else if(gtype === 4) {
$wording.removeClass('hide');
$wrap.addClass('mt26');
$text.text(texts[1]);
}
};
},{}],37:[function(require,module,exports){
'use strict';
// 正则表达式
var REGEXP_LT = //g;
var REGEXP_QUOTE = /"/g;
var REGEXP_ATTR_TAG = /<(\/)*([a-zA-Z0-9_:\.\-]+)([^>a-zA-Z0-9_:\.\-]+[^>]*)*(>|$)/ig;
var REGEXP_ATTR_NAME = /[^>a-zA-Z0-9_:\.\-]*([a-zA-Z0-9_:\.\-]+)=[\"\']?([^\"\'\s>]*)[\"\']?/ig;
var REGEXP_ATTR_VALUE = /([a-zA-Z0-9]*);?/img;
var REGEXP_ATTR_NO_NAME = /[^>a-zA-Z0-9_:\.\-]/ig;
var REGEXP_DEFAULT_ON_TAG_ATTR_1 = /\/\*|\*\//mg;
var REGEXP_DEFAULT_ON_TAG_ATTR_2 = /^[\s"'`]*((j\s*a\s*v\s*a|v\s*b|l\s*i\s*v\s*e)\s*s\s*c\s*r\s*i\s*p\s*t\s*|m\s*o\s*c\s*h\s*a):/ig;
var REGEXP_DEFAULT_ON_TAG_ATTR_3 = /\/\*|\*\//mg;
var REGEXP_DEFAULT_ON_TAG_ATTR_4 = /((j\s*a\s*v\s*a|v\s*b|l\s*i\s*v\s*e)\s*s\s*c\s*r\s*i\s*p\s*t\s*|m\s*o\s*c\s*h\s*a):/ig;
var REGEXP_DEFAULT_ON_TAG_ATTR_5 = /e\s*x\s*p\s*r\s*e\s*s\s*s\s*i\s*o\s*n/ig;
var REGEXP_URL = new RegExp("((news|telnet|nttp|file|http|ftp|https)://){1}(([-A-Za-z0-9]+(\\.[-A-Za-z0-9]+)*(\\.[-A-Za-z]{2,5}))|([0-9]{1,3}(\\.[0-9]{1,3}){3}))(:[0-9]*)?(/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*)*", "gi");
//var IMG_EXP = /([^'"]+)[^>]*/ig
var REGEXP_NONE_URL = new RegExp("(?:[^\\\'\\\"]|^|\s+)((((news|telnet|nttp|file|http|ftp|https)://)|(www\\.))(([-A-Za-z0-9]+(\\.[-A-Za-z0-9]+)*(\\.[-A-Za-z]{2,5}))|([0-9]{1,3}(\\.[0-9]{1,3}){3}))(:[0-9]*)?(/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*)*)(?![^<]*)", "gi");
var REGEXP_SPACE = /^\s|\s$/ig;
/*
* 默认HTML标签白名单
* 标签名=>属性列表
*/
var defaultWhiteList = {
h1: {},
h2: {},
h3: {},
h4: {},
h5: {},
h6: {},
hr: {},
span: {},
strong: {},
b: {},
i: {},
br: {},
p: {},
pre: {},
code: {},
a: {
'target': {
'default': '_blank'
},
'href': true,
'title': true
},
img: {
'src': true,
'alt': true,
'title': true,
'rel': true
},
div: {},
table: {
'border': true
},
tr: {
'rowspan': true
},
td: {
'colspan': true
},
th: {
'colspan': true
},
tbody: {},
thead: {},
ul: {},
li: {},
ol: {},
dl: {},
dt: {},
em: {},
cite: {},
section: {},
header: {},
footer: {},
blockquote: {},
audio: {
'autoplay': true,
'controls': true,
'loop': true,
'preload': true,
'src': true
},
video: {
'autoplay': true,
'controls': true,
'loop': true,
'preload': true,
'src': true
}
};
var defaultWhiteAttrList = {
'width': true,
'height': true,
'style': true
}
/**
* 判断对象是否为空
*
* @param {String} obj 对象
* @return {String}返回true or false
*/
var isNUll = function(obj) {
if (!obj) return true;
for (var i in obj) {
return false;
}
return true;
}
/**
* 过滤属性值
*
* @param {String} tag 标签名
* @param {String} attr 属性名
* @param {String} value 属性值
* @return {String} 若不需要修改属性值,不返回任何值
*/
function defaultOnTagAttr(tag, attr, value) {
if (REGEXP_ATTR_NO_NAME.test(attr)) {
return '';
}
var _default = defaultWhiteList[tag][attr];
var regexp = _default && _default['regexp'];
var _dfvalue = _default && _default['default'];
if (attr === 'href' || attr === 'src') {
REGEXP_DEFAULT_ON_TAG_ATTR_1.lastIndex = 0;
if (REGEXP_DEFAULT_ON_TAG_ATTR_1.test(value)) {
return _dfvalue || '#';
}
REGEXP_DEFAULT_ON_TAG_ATTR_2.lastIndex = 0;
if (REGEXP_DEFAULT_ON_TAG_ATTR_2.test(value)) {
return _dfvalue || '#';
}
REGEXP_URL.lastIndex = 0;
if (!REGEXP_URL.test(value)) { //合格URL
return _dfvalue || '#';
}
if (regexp) {
regexp.lastIndex = 0;
if (!regexp.test(value)) { //合格URL
return _dfvalue || '#';
}
}
return value;
} else if (_default || defaultWhiteAttrList[attr]) { //白名单属性
REGEXP_DEFAULT_ON_TAG_ATTR_3.lastIndex = 0;
if (REGEXP_DEFAULT_ON_TAG_ATTR_3.test(value)) {
return _dfvalue || '';
}
REGEXP_DEFAULT_ON_TAG_ATTR_4.lastIndex = 0;
if (REGEXP_DEFAULT_ON_TAG_ATTR_4.test(value)) {
return _dfvalue || '';
}
if (attr === 'style') {
REGEXP_DEFAULT_ON_TAG_ATTR_5.lastIndex = 0;
if (REGEXP_DEFAULT_ON_TAG_ATTR_5.test(value)) {
return _dfvalue || '';
}
}
return value;
}
return '';
}
/**
* 过滤unicode字符(与REGEXP_ATTR_VALUE配合使用)
*
*/
function replaceUnicode(str, code) {
return String.fromCharCode(parseInt(code, 10));
}
/**
* @param {String} html 需要过滤的字符串
* @param {String} args 保留原始字符串,不进行强制转义,在发表的时候需
*
*/
var filter = function(html, args) {
var DataObj = {},
DataIndex = 0,
currReplace = {};
REGEXP_ATTR_TAG.lastIndex = 0;
html = html.replace(REGEXP_ATTR_TAG, function() {
var _targName = arguments[2] || '';
_targName = _targName.toLowerCase();
var _defaultWhiteList = defaultWhiteList[_targName];
if (!_targName || !_defaultWhiteList) return arguments[0] || ''; //没有标签名,过滤标签
if (arguments[1]) { //结束标记
if (currReplace[_targName] && currReplace[_targName].length) {
currReplace[_targName].pop();
if (!currReplace[_targName].length) delete currReplace[_targName];
DataObj[DataIndex] = '' + arguments[2] + '>';
return '{%DataIndex_' + (DataIndex++) + '%}';
} else {
return '' + arguments[2] + '>';
}
} else {
var _classStr = (arguments[3] || '').replace(REGEXP_SPACE, ''); //获取属性值
if ((_classStr === '/' || !_classStr) && !isNUll(_defaultWhiteList)) arguments[0] || ''; //需要有属性值
if (_classStr) {
REGEXP_ATTR_NAME.lastIndex = 0;
//console.log(_classStr , REGEXP_ATTR_NAME.test(_classStr), '++++++++++++++++++');
if (REGEXP_ATTR_NAME.test(_classStr)) {
REGEXP_ATTR_NAME.lastIndex = 0;
var _lastClassStr = [];
_classStr.replace(REGEXP_ATTR_NAME, function() { //依次判断属性类型
var _attrName = arguments[1].toLowerCase();
var _attrValue = arguments[2];
var value = defaultOnTagAttr(_targName, _attrName, _attrValue);
_lastClassStr.push(value ? ' ' + _attrName + '="' + value + '"' : '');
});
_classStr = _lastClassStr.join('');
} else {
_classStr = '';
}
//console.log(_classStr , '=============');
}
if ((_classStr === '/' || !_classStr) && !isNUll(_defaultWhiteList)) return arguments[0] || ''; //需要有属性值
if (!currReplace[_targName]) currReplace[_targName] = [];
currReplace[_targName].push(_targName);
DataObj[DataIndex] = '<' + _targName + (_classStr ? (' ' + _classStr) : '') + '>';
return '{%DataIndex_' + (DataIndex++) + '%}';
}
});
if (!args) {
html = html.replace(REGEXP_LT, '<')
.replace(REGEXP_GT, '>');
}
html = html.replace(/\{\%DataIndex_(\d+)\%\}/ig, function() {
return DataObj[arguments[1]] || '';
})
.replace(REGEXP_NONE_URL, function($1, $2, match, text) {
var start = '';
$1 += '';
if ($1.length == $2.length + 1) {
start = $1[0];
$1 = $2;
}
var href = '';
if ($1.indexOf('://') == -1) {
href = 'http://' + $1;
} else {
href = $1;
}
return start + '' + $1 + '';
});
var _tags = [];
for (var i in currReplace) {
if (i === 'img' || i === 'br' || i === 'p' || i === 'hr') continue;
var _len;
if (_len = currReplace[i].length) {
for (var j = 0; j < _len; j++) {
_tags.push('' + i + '>');
}
}
}
if (_tags.length) {
html += _tags.join('');
}
return html;
};
exports.filter = filter;
},{}]},{},[14]);