| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- /*!
- * jQuery Cookie Plugin v1.4.1
- * https://github.com/carhartl/jquery-cookie
- *
- * Copyright 2013 Klaus Hartl
- * Released under the MIT license
- */
- (function (factory) {
- if (typeof define === 'function' && define.amd) {
- // AMD
- define(['jquery'], factory);
- } else if (typeof exports === 'object') {
- // CommonJS
- factory(require('jquery'));
- } else {
- // Browser globals
- factory(jQuery);
- }
- }(function ($) {
- var pluses = /\+/g;
- function encode(s) {
- return config.raw ? s : encodeURIComponent(s);
- }
- function decode(s) {
- return config.raw ? s : decodeURIComponent(s);
- }
- function stringifyCookieValue(value) {
- return encode(config.json ? JSON.stringify(value) : String(value));
- }
- function parseCookieValue(s) {
- if (s.indexOf('"') === 0) {
- // This is a quoted cookie as according to RFC2068, unescape...
- s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
- }
- try {
- // Replace server-side written pluses with spaces.
- // If we can't decode the cookie, ignore it, it's unusable.
- // If we can't parse the cookie, ignore it, it's unusable.
- s = decodeURIComponent(s.replace(pluses, ' '));
- return config.json ? JSON.parse(s) : s;
- } catch (e) { }
- }
- function read(s, converter) {
- var value = config.raw ? s : parseCookieValue(s);
- return $.isFunction(converter) ? converter(value) : value;
- }
- var config = $.cookie = function (key, value, options) {
- // Write
- if (value !== undefined && !$.isFunction(value)) {
- options = $.extend({}, config.defaults, options);
- if (typeof options.expires === 'number') {
- var days = options.expires, t = options.expires = new Date();
- t.setTime(+t + days * 864e+5);
- }
- return (document.cookie = [
- encode(key), '=', stringifyCookieValue(value),
- options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
- options.path ? '; path=' + options.path : '',
- options.domain ? '; domain=' + options.domain : '',
- options.secure ? '; secure' : ''
- ].join(''));
- }
- // Read
- var result = key ? undefined : {};
- // To prevent the for loop in the first place assign an empty array
- // in case there are no cookies at all. Also prevents odd result when
- // calling $.cookie().
- var cookies = document.cookie ? document.cookie.split('; ') : [];
- for (var i = 0, l = cookies.length; i < l; i++) {
- var parts = cookies[i].split('=');
- var name = decode(parts.shift());
- var cookie = parts.join('=');
- if (key && key === name) {
- // If second argument (value) is a function it's a converter...
- result = read(cookie, value);
- break;
- }
- // Prevent storing a cookie that we couldn't decode.
- if (!key && (cookie = read(cookie)) !== undefined) {
- result[name] = cookie;
- }
- }
- return result;
- };
- config.defaults = {};
- $.removeCookie = function (key, options) {
- if ($.cookie(key) === undefined) {
- return false;
- }
- // Must not alter options, thus extending a fresh object...
- $.cookie(key, '', $.extend({}, options, { expires: -1 }));
- return !$.cookie(key);
- };
- }));
- (function ($) {
- $.getUrlParam = function (name) {
- var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
- var r = window.location.search.substr(1).match(reg);
- if (r != null) return decodeURI(r[2]); return null;
- };
- //知识点划线处理
- $.MarkKnowledge = function (htmls, Knowledge) {
- var WordReg = "";
- var reg = /[>]([^<>]*)[<]/gi;
- htmls = htmls.replace(reg, function (match, group) {
- var matchVal = group;
- //var matchVal = " " + group + " ";
- if (matchVal.replace(/\s*/gi, "").length != 0) {
- for (var n = 0; n < Knowledge.length; n++) {
- if (Knowledge[n] != "--") {
- Knowledge[n] = Knowledge[n].replace("(", "").replace(")", "");
- WordReg = "(\"|'|\\s|\\b|[^@]){1}(" + Knowledge[n] + ")(d|ed|s|es|er|ers|ing)?(,|\\.|\\?|'|\"|\\s){1}";
- var RegWord = new RegExp(WordReg, 'i');
- matchVal = matchVal.replace(RegWord, " $1#¥@$2#¥@$3$4 ");
- if (matchVal != group) {
- group = matchVal;
- Knowledge[n] = "--";
- }
- }
- }
- //去掉未能标志的知识点标志
- //matchVal = matchVal.replace(/#¥@(\w+\s*-?\w+\s*-?\w+)#¥@(d|ed|s|es|er|ers|ing)?/gi, "<a class='TextMark' title='点击可查看知识点课件' word='$1'>$1$2</a>")
- matchVal = matchVal.replace(/#¥@((\w+\s*-?)+)#¥@(d|ed|s|es|er|ers|ing)?/gi, "<a class='TextMark' title='点击可查看知识点课件' word='$1'>$1$3</a>")
- matchVal = matchVal.replace(/#¥@/g, "");
- return ">" + matchVal + "<";
- }
- else {
- return match;
- }
- });
- return htmls;
- }
- //将页面视图转换成HTML格式
- $.HTMLDecode = function (text) {
- var s = "";
- if (text.length == 0) return "";
- s = text.replace(/<br \/>/ig, "\r\n");
- s = s.replace(/<BR>/ig, "\r\n");
- s = s.replace(/"/g, "\"");
- s = s.replace(/'/g, "\'");
- s = s.replace(/ /g, " ");
- s = s.replace(/>/g, ">");
- s = s.replace(/</g, "<");
- s = s.replace(/&_br/ig, "\n");
- s = s.replace(/&/g, "&");
- return s;
- }
- //转换成HTML标签的特殊字符
- $.HTMLEncode = function (html) {
- var s = "";
- if (html.length == 0) return "";
- s = html.replace(/&/ig, "&");
- s = s.replace(/</ig, "<");
- s = s.replace(/>/ig, ">");
- s = s.replace(/ /ig, " ");
- s = s.replace(/\'/ig, "'");
- s = s.replace(/\"/ig, """);
- s = s.replace(/\r/ig, "");
- s = s.replace(/\n/ig, "<br />");
- return s;
- }
- $.SendEncode = function (text) {
- var s = "";
- if (text.length == 0) return "";
- s = text.replace(/&/ig, "#__amp__#");
- s = s.replace(/</ig, "#__lt__#");
- s = s.replace(/>/ig, "#__gt__#");
- return s;
- }
- //用模版加载数据
- //模板ID 数据模型 作用对象ID 是否拼接
- $.DataTemplate = function (TemplateID, data, ListID, isAppend) {
- //用jquery获取模板
- var source = $("#" + TemplateID).html();
- //拓展方法
- Handlebars.registerHelper("compare", function (v1, v2, v3, options) {
- if (v1 >= v2 && v1 <= v3) {
- //满足添加继续执行
- return options.fn(this);
- } else {
- //不满足条件执行{{else}}部分
- return options.inverse(this);
- }
- });
- Handlebars.registerHelper("equals", function (v1, v2, options) {
- if (v1 == v2) {
- //满足添加继续执行
- return options.fn(this);
- } else {
- //不满足条件执行{{else}}部分
- return options.inverse(this);
- }
- });
- Handlebars.registerHelper('breaklines', function (text) {
- text = Handlebars.Utils.escapeExpression(text);
- text = text.toString();
- text = text.replace(/(\r\n|\n|\r)/gm, '<br>');
- return new Handlebars.SafeString(text);
- });
- Handlebars.registerHelper('substring', function (text, num) {
- text = Handlebars.Utils.escapeExpression(text);
- text = text.toString();
- text = text.replace(/\<BR>/gi, "__")
- text = GetStrOfLength(text, num);
- return new Handlebars.SafeString(text);
- });
- Handlebars.registerHelper('substringHtml', function (text, num) {
- text = HTMLDecode(text);
- text = unescape(text);
- text = GetStrOfLength(text, num);
- text = Handlebars.Utils.escapeExpression(text);
- text = text.toString();
- text = text.replace(/\<BR>/gi, "__");
- return new Handlebars.SafeString(text);
- });
- //注册一个Handlebars Helper,用来将索引+1,因为默认是从0开始的
- Handlebars.registerHelper("addOne", function (index, options) {
- return parseInt(index) + 1;
- });
- //注册一个翻译用的Helper,将index翻译成A,B,C...
- Handlebars.registerHelper("Transindex", function (index, options) {
- index = parseInt(index);
- var x = String.fromCharCode(index + 1 + 64);
- return x;
- });
- //预编译模板
- var template = Handlebars.compile(source);
- //匹配json内容
- var html = template(data);
- //填充数据UI
- if (isAppend) {
- $("#" + ListID).append(html);
- }
- else {
- $("#" + ListID).html(html);
- }
- }
- $.GetTemplate = function (TemplateID, tmpdata, path) {
- var source = $("#" + TemplateID).html();
- $.each(tmpdata, function (index, ele) {
- this.Path = path + "," + this.DirID + "|" + this.DirName;
- });
- Handlebars.registerHelper("compare", function (v1, v2, v3, options) {
- if (v1 >= v2 && v1 <= v3) {
- return options.fn(this);
- } else {
- return options.inverse(this);
- }
- });
- Handlebars.registerHelper("equals", function (v1, v2, options) {
- if (v1 == v2) {
- return options.fn(this);
- } else {
- return options.inverse(this);
- }
- });
- Handlebars.registerHelper('substring', function (text, num) {
- text = Handlebars.Utils.escapeExpression(text);
- text = text.toString();
- text = text.replace(/\<BR>/gi, "__")
- text = GetStrOfLength(text, num);
- return new Handlebars.SafeString(text);
- });
- var template = Handlebars.compile(source);
- var html = template(tmpdata);
- return html;
- }
- $.AppendTemplate = function (TemplateID, data, ListID) {
- var source = $("#" + TemplateID).html();
- Handlebars.registerHelper("compare", function (v1, v2, v3, options) {
- if (v1 >= v2 && v1 <= v3) {
- return options.fn(this);
- } else {
- return options.inverse(this);
- }
- });
- Handlebars.registerHelper("equals", function (v1, v2, options) {
- if (v1 == v2) {
- return options.fn(this);
- } else {
- return options.inverse(this);
- }
- });
- Handlebars.registerHelper("contains", function (value, options) {
- if ($.inArray(value, window.timeLineArr) == -1) {
- window.timeLineArr.push(value);
- return options.fn(this);
- } else {
- return options.inverse(this);
- }
- });
- Handlebars.registerHelper('substring', function (text, num) {
- text = Handlebars.Utils.escapeExpression(text);
- text = text.toString();
- text = text.replace(/\<BR>/gi, "__")
- text = GetStrOfLength(text, num);
- return new Handlebars.SafeString(text);
- });
- var template = Handlebars.compile(source);
- var html = template(data);
- $("#" + ListID).append(html);
- }
- $.RenderMainViewTemplate = function (TemplateID, datatemp, ListID) {
- var source = $("#" + TemplateID).html();
- $.each(datatemp, function (index, item) {
- var temp = item.ImporKnText.split("|").slice(1, 4);
- var theme = this.ThemeText;
- var themeName = "";
- var arr = [];
- var docImage = "";
- $.each($.ThemeListMaps, function (ix, it) {
- themeName = this.ThemeText;
- });
- $.each(temp, function (ix, it) {
- if (it != "") {
- arr.push({
- knowledge: it
- });
- }
- });
- switch (this.ResType) {
- case "1":
- case "2":
- docImage = "/Images/Icon/u1582.png";
- break;
- case "3":
- case "5":
- docImage = "/Images/Icon/u1450.png";
- break;
- case "4":
- case "6":
- docImage = "/Images/Icon/u1545.png";
- break;
- default:
- docImage = "/Images/Icon/u1582.png";
- break;
- }
- this.categoryName = $("#CategoryItemContainer .CategoryItem .SelectedItem").attr("title");
- this.docImage = docImage;
- this.ThemeName = themeName;
- this.IcoPath = this.IcoPath || "/Images/Icon/u1468.png";
- this.Knowledge = arr;
- this.Index = index + 1;
- });
- Handlebars.registerHelper("compare", function (v1, v2, v3, options) {
- if (v1 >= v2 && v1 <= v3) {
- return options.fn(this);
- } else {
- return options.inverse(this);
- }
- });
- Handlebars.registerHelper("equals", function (v1, v2, options) {
- if (v1 == v2) {
- return options.fn(this);
- } else {
- return options.inverse(this);
- }
- });
- Handlebars.registerHelper('substring', function (text, num) {
- text = Handlebars.Utils.escapeExpression(text);
- text = text.toString();
- text = text.replace(/\<BR>/gi, "__")
- text = GetStrOfLength(text, num);
- return new Handlebars.SafeString(text);
- });
- var template = Handlebars.compile(source);
- var html = template(datatemp);
- $("#" + ListID).html(html);
- }
- String.prototype.trim = function () {
- return this.replace(/(^\s*)|(\s*$)/g, "");
- }
- String.prototype.ltrim = function () {
- return this.replace(/(^\s*)/g, "");
- }
- String.prototype.rtrim = function () {
- return this.replace(/(\s*$)/g, "");
- }
- $.browserVersion = (function () {
- var userAgent = navigator && navigator.userAgent || "";
- if ((/(msie)/i).test(userAgent)) {
- return (userAgent.split(";")[1]).trim();
- } else {
- return "Advanced Browser.";
- }
- })();
-
- $.CompatibleOffsetX = function (event) {
- var evt = event || window.event;
- var srcObj = evt.target || evt.srcElement;
- if (evt.offsetX) {
- return evt.offsetX;
- } else {
- var rect = srcObj.getBoundingClientRect();
- var clientx = evt.clientX;
- return clientx - rect.left;
- }
- }
- $.PlaceholderSupport = (function () {
- var test = document.createElement('input');
- return ('placeholder' in test);
- })();
- })(jQuery);
|