jqueryPlugin.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /*!
  2. * jQuery Cookie Plugin v1.4.1
  3. * https://github.com/carhartl/jquery-cookie
  4. *
  5. * Copyright 2013 Klaus Hartl
  6. * Released under the MIT license
  7. */
  8. (function (factory) {
  9. if (typeof define === 'function' && define.amd) {
  10. // AMD
  11. define(['jquery'], factory);
  12. } else if (typeof exports === 'object') {
  13. // CommonJS
  14. factory(require('jquery'));
  15. } else {
  16. // Browser globals
  17. factory(jQuery);
  18. }
  19. }(function ($) {
  20. var pluses = /\+/g;
  21. function encode(s) {
  22. return config.raw ? s : encodeURIComponent(s);
  23. }
  24. function decode(s) {
  25. return config.raw ? s : decodeURIComponent(s);
  26. }
  27. function stringifyCookieValue(value) {
  28. return encode(config.json ? JSON.stringify(value) : String(value));
  29. }
  30. function parseCookieValue(s) {
  31. if (s.indexOf('"') === 0) {
  32. // This is a quoted cookie as according to RFC2068, unescape...
  33. s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
  34. }
  35. try {
  36. // Replace server-side written pluses with spaces.
  37. // If we can't decode the cookie, ignore it, it's unusable.
  38. // If we can't parse the cookie, ignore it, it's unusable.
  39. s = decodeURIComponent(s.replace(pluses, ' '));
  40. return config.json ? JSON.parse(s) : s;
  41. } catch (e) { }
  42. }
  43. function read(s, converter) {
  44. var value = config.raw ? s : parseCookieValue(s);
  45. return $.isFunction(converter) ? converter(value) : value;
  46. }
  47. var config = $.cookie = function (key, value, options) {
  48. // Write
  49. if (value !== undefined && !$.isFunction(value)) {
  50. options = $.extend({}, config.defaults, options);
  51. if (typeof options.expires === 'number') {
  52. var days = options.expires, t = options.expires = new Date();
  53. t.setTime(+t + days * 864e+5);
  54. }
  55. return (document.cookie = [
  56. encode(key), '=', stringifyCookieValue(value),
  57. options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
  58. options.path ? '; path=' + options.path : '',
  59. options.domain ? '; domain=' + options.domain : '',
  60. options.secure ? '; secure' : ''
  61. ].join(''));
  62. }
  63. // Read
  64. var result = key ? undefined : {};
  65. // To prevent the for loop in the first place assign an empty array
  66. // in case there are no cookies at all. Also prevents odd result when
  67. // calling $.cookie().
  68. var cookies = document.cookie ? document.cookie.split('; ') : [];
  69. for (var i = 0, l = cookies.length; i < l; i++) {
  70. var parts = cookies[i].split('=');
  71. var name = decode(parts.shift());
  72. var cookie = parts.join('=');
  73. if (key && key === name) {
  74. // If second argument (value) is a function it's a converter...
  75. result = read(cookie, value);
  76. break;
  77. }
  78. // Prevent storing a cookie that we couldn't decode.
  79. if (!key && (cookie = read(cookie)) !== undefined) {
  80. result[name] = cookie;
  81. }
  82. }
  83. return result;
  84. };
  85. config.defaults = {};
  86. $.removeCookie = function (key, options) {
  87. if ($.cookie(key) === undefined) {
  88. return false;
  89. }
  90. // Must not alter options, thus extending a fresh object...
  91. $.cookie(key, '', $.extend({}, options, { expires: -1 }));
  92. return !$.cookie(key);
  93. };
  94. }));
  95. (function ($) {
  96. $.getUrlParam = function (name) {
  97. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  98. var r = window.location.search.substr(1).match(reg);
  99. if (r != null) return decodeURI(r[2]); return null;
  100. };
  101. //知识点划线处理
  102. $.MarkKnowledge = function (htmls, Knowledge) {
  103. var WordReg = "";
  104. var reg = /[>]([^<>]*)[<]/gi;
  105. htmls = htmls.replace(reg, function (match, group) {
  106. var matchVal = group;
  107. //var matchVal = " " + group + " ";
  108. if (matchVal.replace(/\s*/gi, "").length != 0) {
  109. for (var n = 0; n < Knowledge.length; n++) {
  110. if (Knowledge[n] != "--") {
  111. Knowledge[n] = Knowledge[n].replace("(", "").replace(")", "");
  112. WordReg = "(\"|'|\\s|\\b|[^@]){1}(" + Knowledge[n] + ")(d|ed|s|es|er|ers|ing)?(,|\\.|\\?|'|\"|\\s){1}";
  113. var RegWord = new RegExp(WordReg, 'i');
  114. matchVal = matchVal.replace(RegWord, " $1#¥@$2#¥@$3$4 ");
  115. if (matchVal != group) {
  116. group = matchVal;
  117. Knowledge[n] = "--";
  118. }
  119. }
  120. }
  121. //去掉未能标志的知识点标志
  122. //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>")
  123. matchVal = matchVal.replace(/#¥@((\w+\s*-?)+)#¥@(d|ed|s|es|er|ers|ing)?/gi, "<a class='TextMark' title='点击可查看知识点课件' word='$1'>$1$3</a>")
  124. matchVal = matchVal.replace(/#¥@/g, "");
  125. return ">" + matchVal + "<";
  126. }
  127. else {
  128. return match;
  129. }
  130. });
  131. return htmls;
  132. }
  133. //将页面视图转换成HTML格式
  134. $.HTMLDecode = function (text) {
  135. var s = "";
  136. if (text.length == 0) return "";
  137. s = text.replace(/<br \/>/ig, "\r\n");
  138. s = s.replace(/<BR>/ig, "\r\n");
  139. s = s.replace(/&quot;/g, "\"");
  140. s = s.replace(/&#39;/g, "\'");
  141. s = s.replace(/&nbsp;/g, " ");
  142. s = s.replace(/&gt;/g, ">");
  143. s = s.replace(/&lt;/g, "<");
  144. s = s.replace(/&_br/ig, "\n");
  145. s = s.replace(/&amp;/g, "&");
  146. return s;
  147. }
  148. //转换成HTML标签的特殊字符
  149. $.HTMLEncode = function (html) {
  150. var s = "";
  151. if (html.length == 0) return "";
  152. s = html.replace(/&/ig, "&amp;");
  153. s = s.replace(/</ig, "&lt;");
  154. s = s.replace(/>/ig, "&gt;");
  155. s = s.replace(/ /ig, "&nbsp;");
  156. s = s.replace(/\'/ig, "&#39;");
  157. s = s.replace(/\"/ig, "&quot;");
  158. s = s.replace(/\r/ig, "");
  159. s = s.replace(/\n/ig, "<br />");
  160. return s;
  161. }
  162. $.SendEncode = function (text) {
  163. var s = "";
  164. if (text.length == 0) return "";
  165. s = text.replace(/&/ig, "#__amp__#");
  166. s = s.replace(/</ig, "#__lt__#");
  167. s = s.replace(/>/ig, "#__gt__#");
  168. return s;
  169. }
  170. //用模版加载数据
  171. //模板ID 数据模型 作用对象ID 是否拼接
  172. $.DataTemplate = function (TemplateID, data, ListID, isAppend) {
  173. //用jquery获取模板
  174. var source = $("#" + TemplateID).html();
  175. //拓展方法
  176. Handlebars.registerHelper("compare", function (v1, v2, v3, options) {
  177. if (v1 >= v2 && v1 <= v3) {
  178. //满足添加继续执行
  179. return options.fn(this);
  180. } else {
  181. //不满足条件执行{{else}}部分
  182. return options.inverse(this);
  183. }
  184. });
  185. Handlebars.registerHelper("equals", function (v1, v2, options) {
  186. if (v1 == v2) {
  187. //满足添加继续执行
  188. return options.fn(this);
  189. } else {
  190. //不满足条件执行{{else}}部分
  191. return options.inverse(this);
  192. }
  193. });
  194. Handlebars.registerHelper('breaklines', function (text) {
  195. text = Handlebars.Utils.escapeExpression(text);
  196. text = text.toString();
  197. text = text.replace(/(\r\n|\n|\r)/gm, '<br>');
  198. return new Handlebars.SafeString(text);
  199. });
  200. Handlebars.registerHelper('substring', function (text, num) {
  201. text = Handlebars.Utils.escapeExpression(text);
  202. text = text.toString();
  203. text = text.replace(/\&lt;BR&gt;/gi, "__")
  204. text = GetStrOfLength(text, num);
  205. return new Handlebars.SafeString(text);
  206. });
  207. Handlebars.registerHelper('substringHtml', function (text, num) {
  208. text = HTMLDecode(text);
  209. text = unescape(text);
  210. text = GetStrOfLength(text, num);
  211. text = Handlebars.Utils.escapeExpression(text);
  212. text = text.toString();
  213. text = text.replace(/\&lt;BR&gt;/gi, "__");
  214. return new Handlebars.SafeString(text);
  215. });
  216. //注册一个Handlebars Helper,用来将索引+1,因为默认是从0开始的
  217. Handlebars.registerHelper("addOne", function (index, options) {
  218. return parseInt(index) + 1;
  219. });
  220. //注册一个翻译用的Helper,将index翻译成A,B,C...
  221. Handlebars.registerHelper("Transindex", function (index, options) {
  222. index = parseInt(index);
  223. var x = String.fromCharCode(index + 1 + 64);
  224. return x;
  225. });
  226. //预编译模板
  227. var template = Handlebars.compile(source);
  228. //匹配json内容
  229. var html = template(data);
  230. //填充数据UI
  231. if (isAppend) {
  232. $("#" + ListID).append(html);
  233. }
  234. else {
  235. $("#" + ListID).html(html);
  236. }
  237. }
  238. $.GetTemplate = function (TemplateID, tmpdata, path) {
  239. var source = $("#" + TemplateID).html();
  240. $.each(tmpdata, function (index, ele) {
  241. this.Path = path + "," + this.DirID + "|" + this.DirName;
  242. });
  243. Handlebars.registerHelper("compare", function (v1, v2, v3, options) {
  244. if (v1 >= v2 && v1 <= v3) {
  245. return options.fn(this);
  246. } else {
  247. return options.inverse(this);
  248. }
  249. });
  250. Handlebars.registerHelper("equals", function (v1, v2, options) {
  251. if (v1 == v2) {
  252. return options.fn(this);
  253. } else {
  254. return options.inverse(this);
  255. }
  256. });
  257. Handlebars.registerHelper('substring', function (text, num) {
  258. text = Handlebars.Utils.escapeExpression(text);
  259. text = text.toString();
  260. text = text.replace(/\&lt;BR&gt;/gi, "__")
  261. text = GetStrOfLength(text, num);
  262. return new Handlebars.SafeString(text);
  263. });
  264. var template = Handlebars.compile(source);
  265. var html = template(tmpdata);
  266. return html;
  267. }
  268. $.AppendTemplate = function (TemplateID, data, ListID) {
  269. var source = $("#" + TemplateID).html();
  270. Handlebars.registerHelper("compare", function (v1, v2, v3, options) {
  271. if (v1 >= v2 && v1 <= v3) {
  272. return options.fn(this);
  273. } else {
  274. return options.inverse(this);
  275. }
  276. });
  277. Handlebars.registerHelper("equals", function (v1, v2, options) {
  278. if (v1 == v2) {
  279. return options.fn(this);
  280. } else {
  281. return options.inverse(this);
  282. }
  283. });
  284. Handlebars.registerHelper("contains", function (value, options) {
  285. if ($.inArray(value, window.timeLineArr) == -1) {
  286. window.timeLineArr.push(value);
  287. return options.fn(this);
  288. } else {
  289. return options.inverse(this);
  290. }
  291. });
  292. Handlebars.registerHelper('substring', function (text, num) {
  293. text = Handlebars.Utils.escapeExpression(text);
  294. text = text.toString();
  295. text = text.replace(/\&lt;BR&gt;/gi, "__")
  296. text = GetStrOfLength(text, num);
  297. return new Handlebars.SafeString(text);
  298. });
  299. var template = Handlebars.compile(source);
  300. var html = template(data);
  301. $("#" + ListID).append(html);
  302. }
  303. $.RenderMainViewTemplate = function (TemplateID, datatemp, ListID) {
  304. var source = $("#" + TemplateID).html();
  305. $.each(datatemp, function (index, item) {
  306. var temp = item.ImporKnText.split("|").slice(1, 4);
  307. var theme = this.ThemeText;
  308. var themeName = "";
  309. var arr = [];
  310. var docImage = "";
  311. $.each($.ThemeListMaps, function (ix, it) {
  312. themeName = this.ThemeText;
  313. });
  314. $.each(temp, function (ix, it) {
  315. if (it != "") {
  316. arr.push({
  317. knowledge: it
  318. });
  319. }
  320. });
  321. switch (this.ResType) {
  322. case "1":
  323. case "2":
  324. docImage = "/Images/Icon/u1582.png";
  325. break;
  326. case "3":
  327. case "5":
  328. docImage = "/Images/Icon/u1450.png";
  329. break;
  330. case "4":
  331. case "6":
  332. docImage = "/Images/Icon/u1545.png";
  333. break;
  334. default:
  335. docImage = "/Images/Icon/u1582.png";
  336. break;
  337. }
  338. this.categoryName = $("#CategoryItemContainer .CategoryItem .SelectedItem").attr("title");
  339. this.docImage = docImage;
  340. this.ThemeName = themeName;
  341. this.IcoPath = this.IcoPath || "/Images/Icon/u1468.png";
  342. this.Knowledge = arr;
  343. this.Index = index + 1;
  344. });
  345. Handlebars.registerHelper("compare", function (v1, v2, v3, options) {
  346. if (v1 >= v2 && v1 <= v3) {
  347. return options.fn(this);
  348. } else {
  349. return options.inverse(this);
  350. }
  351. });
  352. Handlebars.registerHelper("equals", function (v1, v2, options) {
  353. if (v1 == v2) {
  354. return options.fn(this);
  355. } else {
  356. return options.inverse(this);
  357. }
  358. });
  359. Handlebars.registerHelper('substring', function (text, num) {
  360. text = Handlebars.Utils.escapeExpression(text);
  361. text = text.toString();
  362. text = text.replace(/\&lt;BR&gt;/gi, "__")
  363. text = GetStrOfLength(text, num);
  364. return new Handlebars.SafeString(text);
  365. });
  366. var template = Handlebars.compile(source);
  367. var html = template(datatemp);
  368. $("#" + ListID).html(html);
  369. }
  370. String.prototype.trim = function () {
  371. return this.replace(/(^\s*)|(\s*$)/g, "");
  372. }
  373. String.prototype.ltrim = function () {
  374. return this.replace(/(^\s*)/g, "");
  375. }
  376. String.prototype.rtrim = function () {
  377. return this.replace(/(\s*$)/g, "");
  378. }
  379. $.browserVersion = (function () {
  380. var userAgent = navigator && navigator.userAgent || "";
  381. if ((/(msie)/i).test(userAgent)) {
  382. return (userAgent.split(";")[1]).trim();
  383. } else {
  384. return "Advanced Browser.";
  385. }
  386. })();
  387. $.CompatibleOffsetX = function (event) {
  388. var evt = event || window.event;
  389. var srcObj = evt.target || evt.srcElement;
  390. if (evt.offsetX) {
  391. return evt.offsetX;
  392. } else {
  393. var rect = srcObj.getBoundingClientRect();
  394. var clientx = evt.clientX;
  395. return clientx - rect.left;
  396. }
  397. }
  398. $.PlaceholderSupport = (function () {
  399. var test = document.createElement('input');
  400. return ('placeholder' in test);
  401. })();
  402. })(jQuery);