Commit 4403f71f454d8341fba830db1f0aaf95ef2dc54b
1 parent
2465a4fd
Exists in
master
and in
4 other branches
added sanitize and linkify functions. Moved some js to lib/
Showing
8 changed files
with
471 additions
and
464 deletions
Show diff stats
app/assets/javascripts/jquery.timeago.js
... | ... | @@ -1,181 +0,0 @@ |
1 | -/** | |
2 | - * Timeago is a jQuery plugin that makes it easy to support automatically | |
3 | - * updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago"). | |
4 | - * | |
5 | - * @name timeago | |
6 | - * @version 1.1.0 | |
7 | - * @requires jQuery v1.2.3+ | |
8 | - * @author Ryan McGeary | |
9 | - * @license MIT License - http://www.opensource.org/licenses/mit-license.php | |
10 | - * | |
11 | - * For usage and examples, visit: | |
12 | - * http://timeago.yarp.com/ | |
13 | - * | |
14 | - * Copyright (c) 2008-2013, Ryan McGeary (ryan -[at]- mcgeary [*dot*] org) | |
15 | - */ | |
16 | - | |
17 | -(function (factory) { | |
18 | - if (typeof define === 'function' && define.amd) { | |
19 | - // AMD. Register as an anonymous module. | |
20 | - define(['jquery'], factory); | |
21 | - } else { | |
22 | - // Browser globals | |
23 | - factory(jQuery); | |
24 | - } | |
25 | -}(function ($) { | |
26 | - $.timeago = function(timestamp) { | |
27 | - if (timestamp instanceof Date) { | |
28 | - return inWords(timestamp); | |
29 | - } else if (typeof timestamp === "string") { | |
30 | - return inWords($.timeago.parse(timestamp)); | |
31 | - } else if (typeof timestamp === "number") { | |
32 | - return inWords(new Date(timestamp)); | |
33 | - } else { | |
34 | - return inWords($.timeago.datetime(timestamp)); | |
35 | - } | |
36 | - }; | |
37 | - var $t = $.timeago; | |
38 | - | |
39 | - $.extend($.timeago, { | |
40 | - settings: { | |
41 | - refreshMillis: 60000, | |
42 | - allowFuture: false, | |
43 | - strings: { | |
44 | - prefixAgo: null, | |
45 | - prefixFromNow: null, | |
46 | - suffixAgo: "ago", | |
47 | - suffixFromNow: "from now", | |
48 | - seconds: "less than a minute", | |
49 | - minute: "about a minute", | |
50 | - minutes: "%d minutes", | |
51 | - hour: "about an hour", | |
52 | - hours: "about %d hours", | |
53 | - day: "a day", | |
54 | - days: "%d days", | |
55 | - month: "about a month", | |
56 | - months: "%d months", | |
57 | - year: "about a year", | |
58 | - years: "%d years", | |
59 | - wordSeparator: " ", | |
60 | - numbers: [] | |
61 | - } | |
62 | - }, | |
63 | - inWords: function(distanceMillis) { | |
64 | - var $l = this.settings.strings; | |
65 | - var prefix = $l.prefixAgo; | |
66 | - var suffix = $l.suffixAgo; | |
67 | - if (this.settings.allowFuture) { | |
68 | - if (distanceMillis < 0) { | |
69 | - prefix = $l.prefixFromNow; | |
70 | - suffix = $l.suffixFromNow; | |
71 | - } | |
72 | - } | |
73 | - | |
74 | - var seconds = Math.abs(distanceMillis) / 1000; | |
75 | - var minutes = seconds / 60; | |
76 | - var hours = minutes / 60; | |
77 | - var days = hours / 24; | |
78 | - var years = days / 365; | |
79 | - | |
80 | - function substitute(stringOrFunction, number) { | |
81 | - var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction; | |
82 | - var value = ($l.numbers && $l.numbers[number]) || number; | |
83 | - return string.replace(/%d/i, value); | |
84 | - } | |
85 | - | |
86 | - var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) || | |
87 | - seconds < 90 && substitute($l.minute, 1) || | |
88 | - minutes < 45 && substitute($l.minutes, Math.round(minutes)) || | |
89 | - minutes < 90 && substitute($l.hour, 1) || | |
90 | - hours < 24 && substitute($l.hours, Math.round(hours)) || | |
91 | - hours < 42 && substitute($l.day, 1) || | |
92 | - days < 30 && substitute($l.days, Math.round(days)) || | |
93 | - days < 45 && substitute($l.month, 1) || | |
94 | - days < 365 && substitute($l.months, Math.round(days / 30)) || | |
95 | - years < 1.5 && substitute($l.year, 1) || | |
96 | - substitute($l.years, Math.round(years)); | |
97 | - | |
98 | - var separator = $l.wordSeparator || ""; | |
99 | - if ($l.wordSeparator === undefined) { separator = " "; } | |
100 | - return $.trim([prefix, words, suffix].join(separator)); | |
101 | - }, | |
102 | - parse: function(iso8601) { | |
103 | - var s = $.trim(iso8601); | |
104 | - s = s.replace(/\.\d+/,""); // remove milliseconds | |
105 | - s = s.replace(/-/,"/").replace(/-/,"/"); | |
106 | - s = s.replace(/T/," ").replace(/Z/," UTC"); | |
107 | - s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400 | |
108 | - return new Date(s); | |
109 | - }, | |
110 | - datetime: function(elem) { | |
111 | - var iso8601 = $t.isTime(elem) ? $(elem).attr("datetime") : $(elem).attr("title"); | |
112 | - return $t.parse(iso8601); | |
113 | - }, | |
114 | - isTime: function(elem) { | |
115 | - // jQuery's `is()` doesn't play well with HTML5 in IE | |
116 | - return $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time"); | |
117 | - } | |
118 | - }); | |
119 | - | |
120 | - // functions that can be called via $(el).timeago('action') | |
121 | - // init is default when no action is given | |
122 | - // functions are called with context of a single element | |
123 | - var functions = { | |
124 | - init: function(){ | |
125 | - var refresh_el = $.proxy(refresh, this); | |
126 | - refresh_el(); | |
127 | - var $s = $t.settings; | |
128 | - if ($s.refreshMillis > 0) { | |
129 | - setInterval(refresh_el, $s.refreshMillis); | |
130 | - } | |
131 | - }, | |
132 | - update: function(time){ | |
133 | - $(this).data('timeago', { datetime: $t.parse(time) }); | |
134 | - refresh.apply(this); | |
135 | - } | |
136 | - }; | |
137 | - | |
138 | - $.fn.timeago = function(action, options) { | |
139 | - var fn = action ? functions[action] : functions.init; | |
140 | - if(!fn){ | |
141 | - throw new Error("Unknown function name '"+ action +"' for timeago"); | |
142 | - } | |
143 | - // each over objects here and call the requested function | |
144 | - this.each(function(){ | |
145 | - fn.call(this, options); | |
146 | - }); | |
147 | - return this; | |
148 | - }; | |
149 | - | |
150 | - function refresh() { | |
151 | - var data = prepareData(this); | |
152 | - if (!isNaN(data.datetime)) { | |
153 | - $(this).text(inWords(data.datetime)); | |
154 | - } | |
155 | - return this; | |
156 | - } | |
157 | - | |
158 | - function prepareData(element) { | |
159 | - element = $(element); | |
160 | - if (!element.data("timeago")) { | |
161 | - element.data("timeago", { datetime: $t.datetime(element) }); | |
162 | - var text = $.trim(element.text()); | |
163 | - if (text.length > 0 && !($t.isTime(element) && element.attr("title"))) { | |
164 | - element.attr("title", text); | |
165 | - } | |
166 | - } | |
167 | - return element.data("timeago"); | |
168 | - } | |
169 | - | |
170 | - function inWords(date) { | |
171 | - return $t.inWords(distance(date)); | |
172 | - } | |
173 | - | |
174 | - function distance(date) { | |
175 | - return (new Date().getTime() - date.getTime()); | |
176 | - } | |
177 | - | |
178 | - // fix for IE6 suckage | |
179 | - document.createElement("abbr"); | |
180 | - document.createElement("time"); | |
181 | -})); |
... | ... | @@ -0,0 +1,181 @@ |
1 | +/** | |
2 | + * Timeago is a jQuery plugin that makes it easy to support automatically | |
3 | + * updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago"). | |
4 | + * | |
5 | + * @name timeago | |
6 | + * @version 1.1.0 | |
7 | + * @requires jQuery v1.2.3+ | |
8 | + * @author Ryan McGeary | |
9 | + * @license MIT License - http://www.opensource.org/licenses/mit-license.php | |
10 | + * | |
11 | + * For usage and examples, visit: | |
12 | + * http://timeago.yarp.com/ | |
13 | + * | |
14 | + * Copyright (c) 2008-2013, Ryan McGeary (ryan -[at]- mcgeary [*dot*] org) | |
15 | + */ | |
16 | + | |
17 | +(function (factory) { | |
18 | + if (typeof define === 'function' && define.amd) { | |
19 | + // AMD. Register as an anonymous module. | |
20 | + define(['jquery'], factory); | |
21 | + } else { | |
22 | + // Browser globals | |
23 | + factory(jQuery); | |
24 | + } | |
25 | +}(function ($) { | |
26 | + $.timeago = function(timestamp) { | |
27 | + if (timestamp instanceof Date) { | |
28 | + return inWords(timestamp); | |
29 | + } else if (typeof timestamp === "string") { | |
30 | + return inWords($.timeago.parse(timestamp)); | |
31 | + } else if (typeof timestamp === "number") { | |
32 | + return inWords(new Date(timestamp)); | |
33 | + } else { | |
34 | + return inWords($.timeago.datetime(timestamp)); | |
35 | + } | |
36 | + }; | |
37 | + var $t = $.timeago; | |
38 | + | |
39 | + $.extend($.timeago, { | |
40 | + settings: { | |
41 | + refreshMillis: 60000, | |
42 | + allowFuture: false, | |
43 | + strings: { | |
44 | + prefixAgo: null, | |
45 | + prefixFromNow: null, | |
46 | + suffixAgo: "ago", | |
47 | + suffixFromNow: "from now", | |
48 | + seconds: "less than a minute", | |
49 | + minute: "about a minute", | |
50 | + minutes: "%d minutes", | |
51 | + hour: "about an hour", | |
52 | + hours: "about %d hours", | |
53 | + day: "a day", | |
54 | + days: "%d days", | |
55 | + month: "about a month", | |
56 | + months: "%d months", | |
57 | + year: "about a year", | |
58 | + years: "%d years", | |
59 | + wordSeparator: " ", | |
60 | + numbers: [] | |
61 | + } | |
62 | + }, | |
63 | + inWords: function(distanceMillis) { | |
64 | + var $l = this.settings.strings; | |
65 | + var prefix = $l.prefixAgo; | |
66 | + var suffix = $l.suffixAgo; | |
67 | + if (this.settings.allowFuture) { | |
68 | + if (distanceMillis < 0) { | |
69 | + prefix = $l.prefixFromNow; | |
70 | + suffix = $l.suffixFromNow; | |
71 | + } | |
72 | + } | |
73 | + | |
74 | + var seconds = Math.abs(distanceMillis) / 1000; | |
75 | + var minutes = seconds / 60; | |
76 | + var hours = minutes / 60; | |
77 | + var days = hours / 24; | |
78 | + var years = days / 365; | |
79 | + | |
80 | + function substitute(stringOrFunction, number) { | |
81 | + var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction; | |
82 | + var value = ($l.numbers && $l.numbers[number]) || number; | |
83 | + return string.replace(/%d/i, value); | |
84 | + } | |
85 | + | |
86 | + var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) || | |
87 | + seconds < 90 && substitute($l.minute, 1) || | |
88 | + minutes < 45 && substitute($l.minutes, Math.round(minutes)) || | |
89 | + minutes < 90 && substitute($l.hour, 1) || | |
90 | + hours < 24 && substitute($l.hours, Math.round(hours)) || | |
91 | + hours < 42 && substitute($l.day, 1) || | |
92 | + days < 30 && substitute($l.days, Math.round(days)) || | |
93 | + days < 45 && substitute($l.month, 1) || | |
94 | + days < 365 && substitute($l.months, Math.round(days / 30)) || | |
95 | + years < 1.5 && substitute($l.year, 1) || | |
96 | + substitute($l.years, Math.round(years)); | |
97 | + | |
98 | + var separator = $l.wordSeparator || ""; | |
99 | + if ($l.wordSeparator === undefined) { separator = " "; } | |
100 | + return $.trim([prefix, words, suffix].join(separator)); | |
101 | + }, | |
102 | + parse: function(iso8601) { | |
103 | + var s = $.trim(iso8601); | |
104 | + s = s.replace(/\.\d+/,""); // remove milliseconds | |
105 | + s = s.replace(/-/,"/").replace(/-/,"/"); | |
106 | + s = s.replace(/T/," ").replace(/Z/," UTC"); | |
107 | + s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400 | |
108 | + return new Date(s); | |
109 | + }, | |
110 | + datetime: function(elem) { | |
111 | + var iso8601 = $t.isTime(elem) ? $(elem).attr("datetime") : $(elem).attr("title"); | |
112 | + return $t.parse(iso8601); | |
113 | + }, | |
114 | + isTime: function(elem) { | |
115 | + // jQuery's `is()` doesn't play well with HTML5 in IE | |
116 | + return $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time"); | |
117 | + } | |
118 | + }); | |
119 | + | |
120 | + // functions that can be called via $(el).timeago('action') | |
121 | + // init is default when no action is given | |
122 | + // functions are called with context of a single element | |
123 | + var functions = { | |
124 | + init: function(){ | |
125 | + var refresh_el = $.proxy(refresh, this); | |
126 | + refresh_el(); | |
127 | + var $s = $t.settings; | |
128 | + if ($s.refreshMillis > 0) { | |
129 | + setInterval(refresh_el, $s.refreshMillis); | |
130 | + } | |
131 | + }, | |
132 | + update: function(time){ | |
133 | + $(this).data('timeago', { datetime: $t.parse(time) }); | |
134 | + refresh.apply(this); | |
135 | + } | |
136 | + }; | |
137 | + | |
138 | + $.fn.timeago = function(action, options) { | |
139 | + var fn = action ? functions[action] : functions.init; | |
140 | + if(!fn){ | |
141 | + throw new Error("Unknown function name '"+ action +"' for timeago"); | |
142 | + } | |
143 | + // each over objects here and call the requested function | |
144 | + this.each(function(){ | |
145 | + fn.call(this, options); | |
146 | + }); | |
147 | + return this; | |
148 | + }; | |
149 | + | |
150 | + function refresh() { | |
151 | + var data = prepareData(this); | |
152 | + if (!isNaN(data.datetime)) { | |
153 | + $(this).text(inWords(data.datetime)); | |
154 | + } | |
155 | + return this; | |
156 | + } | |
157 | + | |
158 | + function prepareData(element) { | |
159 | + element = $(element); | |
160 | + if (!element.data("timeago")) { | |
161 | + element.data("timeago", { datetime: $t.datetime(element) }); | |
162 | + var text = $.trim(element.text()); | |
163 | + if (text.length > 0 && !($t.isTime(element) && element.attr("title"))) { | |
164 | + element.attr("title", text); | |
165 | + } | |
166 | + } | |
167 | + return element.data("timeago"); | |
168 | + } | |
169 | + | |
170 | + function inWords(date) { | |
171 | + return $t.inWords(distance(date)); | |
172 | + } | |
173 | + | |
174 | + function distance(date) { | |
175 | + return (new Date().getTime() - date.getTime()); | |
176 | + } | |
177 | + | |
178 | + // fix for IE6 suckage | |
179 | + document.createElement("abbr"); | |
180 | + document.createElement("time"); | |
181 | +})); | ... | ... |
... | ... | @@ -0,0 +1,211 @@ |
1 | +function md5 (str) { | |
2 | + // http://kevin.vanzonneveld.net | |
3 | + // + original by: Webtoolkit.info (http://www.webtoolkit.info/) | |
4 | + // + namespaced by: Michael White (http://getsprink.com) | |
5 | + // + tweaked by: Jack | |
6 | + // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
7 | + // + input by: Brett Zamir (http://brett-zamir.me) | |
8 | + // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
9 | + // - depends on: utf8_encode | |
10 | + // * example 1: md5('Kevin van Zonneveld'); | |
11 | + // * returns 1: '6e658d4bfcb59cc13f96c14450ac40b9' | |
12 | + var xl; | |
13 | + | |
14 | + var rotateLeft = function (lValue, iShiftBits) { | |
15 | + return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits)); | |
16 | + }; | |
17 | + | |
18 | + var addUnsigned = function (lX, lY) { | |
19 | + var lX4, lY4, lX8, lY8, lResult; | |
20 | + lX8 = (lX & 0x80000000); | |
21 | + lY8 = (lY & 0x80000000); | |
22 | + lX4 = (lX & 0x40000000); | |
23 | + lY4 = (lY & 0x40000000); | |
24 | + lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF); | |
25 | + if (lX4 & lY4) { | |
26 | + return (lResult ^ 0x80000000 ^ lX8 ^ lY8); | |
27 | + } | |
28 | + if (lX4 | lY4) { | |
29 | + if (lResult & 0x40000000) { | |
30 | + return (lResult ^ 0xC0000000 ^ lX8 ^ lY8); | |
31 | + } else { | |
32 | + return (lResult ^ 0x40000000 ^ lX8 ^ lY8); | |
33 | + } | |
34 | + } else { | |
35 | + return (lResult ^ lX8 ^ lY8); | |
36 | + } | |
37 | + }; | |
38 | + | |
39 | + var _F = function (x, y, z) { | |
40 | + return (x & y) | ((~x) & z); | |
41 | + }; | |
42 | + var _G = function (x, y, z) { | |
43 | + return (x & z) | (y & (~z)); | |
44 | + }; | |
45 | + var _H = function (x, y, z) { | |
46 | + return (x ^ y ^ z); | |
47 | + }; | |
48 | + var _I = function (x, y, z) { | |
49 | + return (y ^ (x | (~z))); | |
50 | + }; | |
51 | + | |
52 | + var _FF = function (a, b, c, d, x, s, ac) { | |
53 | + a = addUnsigned(a, addUnsigned(addUnsigned(_F(b, c, d), x), ac)); | |
54 | + return addUnsigned(rotateLeft(a, s), b); | |
55 | + }; | |
56 | + | |
57 | + var _GG = function (a, b, c, d, x, s, ac) { | |
58 | + a = addUnsigned(a, addUnsigned(addUnsigned(_G(b, c, d), x), ac)); | |
59 | + return addUnsigned(rotateLeft(a, s), b); | |
60 | + }; | |
61 | + | |
62 | + var _HH = function (a, b, c, d, x, s, ac) { | |
63 | + a = addUnsigned(a, addUnsigned(addUnsigned(_H(b, c, d), x), ac)); | |
64 | + return addUnsigned(rotateLeft(a, s), b); | |
65 | + }; | |
66 | + | |
67 | + var _II = function (a, b, c, d, x, s, ac) { | |
68 | + a = addUnsigned(a, addUnsigned(addUnsigned(_I(b, c, d), x), ac)); | |
69 | + return addUnsigned(rotateLeft(a, s), b); | |
70 | + }; | |
71 | + | |
72 | + var convertToWordArray = function (str) { | |
73 | + var lWordCount; | |
74 | + var lMessageLength = str.length; | |
75 | + var lNumberOfWords_temp1 = lMessageLength + 8; | |
76 | + var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64; | |
77 | + var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16; | |
78 | + var lWordArray = new Array(lNumberOfWords - 1); | |
79 | + var lBytePosition = 0; | |
80 | + var lByteCount = 0; | |
81 | + while (lByteCount < lMessageLength) { | |
82 | + lWordCount = (lByteCount - (lByteCount % 4)) / 4; | |
83 | + lBytePosition = (lByteCount % 4) * 8; | |
84 | + lWordArray[lWordCount] = (lWordArray[lWordCount] | (str.charCodeAt(lByteCount) << lBytePosition)); | |
85 | + lByteCount++; | |
86 | + } | |
87 | + lWordCount = (lByteCount - (lByteCount % 4)) / 4; | |
88 | + lBytePosition = (lByteCount % 4) * 8; | |
89 | + lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition); | |
90 | + lWordArray[lNumberOfWords - 2] = lMessageLength << 3; | |
91 | + lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29; | |
92 | + return lWordArray; | |
93 | + }; | |
94 | + | |
95 | + var wordToHex = function (lValue) { | |
96 | + var wordToHexValue = "", | |
97 | + wordToHexValue_temp = "", | |
98 | + lByte, lCount; | |
99 | + for (lCount = 0; lCount <= 3; lCount++) { | |
100 | + lByte = (lValue >>> (lCount * 8)) & 255; | |
101 | + wordToHexValue_temp = "0" + lByte.toString(16); | |
102 | + wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length - 2, 2); | |
103 | + } | |
104 | + return wordToHexValue; | |
105 | + }; | |
106 | + | |
107 | + var x = [], | |
108 | + k, AA, BB, CC, DD, a, b, c, d, S11 = 7, | |
109 | + S12 = 12, | |
110 | + S13 = 17, | |
111 | + S14 = 22, | |
112 | + S21 = 5, | |
113 | + S22 = 9, | |
114 | + S23 = 14, | |
115 | + S24 = 20, | |
116 | + S31 = 4, | |
117 | + S32 = 11, | |
118 | + S33 = 16, | |
119 | + S34 = 23, | |
120 | + S41 = 6, | |
121 | + S42 = 10, | |
122 | + S43 = 15, | |
123 | + S44 = 21; | |
124 | + | |
125 | + str = this.utf8_encode(str); | |
126 | + x = convertToWordArray(str); | |
127 | + a = 0x67452301; | |
128 | + b = 0xEFCDAB89; | |
129 | + c = 0x98BADCFE; | |
130 | + d = 0x10325476; | |
131 | + | |
132 | + xl = x.length; | |
133 | + for (k = 0; k < xl; k += 16) { | |
134 | + AA = a; | |
135 | + BB = b; | |
136 | + CC = c; | |
137 | + DD = d; | |
138 | + a = _FF(a, b, c, d, x[k + 0], S11, 0xD76AA478); | |
139 | + d = _FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756); | |
140 | + c = _FF(c, d, a, b, x[k + 2], S13, 0x242070DB); | |
141 | + b = _FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE); | |
142 | + a = _FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF); | |
143 | + d = _FF(d, a, b, c, x[k + 5], S12, 0x4787C62A); | |
144 | + c = _FF(c, d, a, b, x[k + 6], S13, 0xA8304613); | |
145 | + b = _FF(b, c, d, a, x[k + 7], S14, 0xFD469501); | |
146 | + a = _FF(a, b, c, d, x[k + 8], S11, 0x698098D8); | |
147 | + d = _FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF); | |
148 | + c = _FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1); | |
149 | + b = _FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE); | |
150 | + a = _FF(a, b, c, d, x[k + 12], S11, 0x6B901122); | |
151 | + d = _FF(d, a, b, c, x[k + 13], S12, 0xFD987193); | |
152 | + c = _FF(c, d, a, b, x[k + 14], S13, 0xA679438E); | |
153 | + b = _FF(b, c, d, a, x[k + 15], S14, 0x49B40821); | |
154 | + a = _GG(a, b, c, d, x[k + 1], S21, 0xF61E2562); | |
155 | + d = _GG(d, a, b, c, x[k + 6], S22, 0xC040B340); | |
156 | + c = _GG(c, d, a, b, x[k + 11], S23, 0x265E5A51); | |
157 | + b = _GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA); | |
158 | + a = _GG(a, b, c, d, x[k + 5], S21, 0xD62F105D); | |
159 | + d = _GG(d, a, b, c, x[k + 10], S22, 0x2441453); | |
160 | + c = _GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681); | |
161 | + b = _GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8); | |
162 | + a = _GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6); | |
163 | + d = _GG(d, a, b, c, x[k + 14], S22, 0xC33707D6); | |
164 | + c = _GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87); | |
165 | + b = _GG(b, c, d, a, x[k + 8], S24, 0x455A14ED); | |
166 | + a = _GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905); | |
167 | + d = _GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8); | |
168 | + c = _GG(c, d, a, b, x[k + 7], S23, 0x676F02D9); | |
169 | + b = _GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A); | |
170 | + a = _HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942); | |
171 | + d = _HH(d, a, b, c, x[k + 8], S32, 0x8771F681); | |
172 | + c = _HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122); | |
173 | + b = _HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C); | |
174 | + a = _HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44); | |
175 | + d = _HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9); | |
176 | + c = _HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60); | |
177 | + b = _HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70); | |
178 | + a = _HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6); | |
179 | + d = _HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA); | |
180 | + c = _HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085); | |
181 | + b = _HH(b, c, d, a, x[k + 6], S34, 0x4881D05); | |
182 | + a = _HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039); | |
183 | + d = _HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5); | |
184 | + c = _HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8); | |
185 | + b = _HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665); | |
186 | + a = _II(a, b, c, d, x[k + 0], S41, 0xF4292244); | |
187 | + d = _II(d, a, b, c, x[k + 7], S42, 0x432AFF97); | |
188 | + c = _II(c, d, a, b, x[k + 14], S43, 0xAB9423A7); | |
189 | + b = _II(b, c, d, a, x[k + 5], S44, 0xFC93A039); | |
190 | + a = _II(a, b, c, d, x[k + 12], S41, 0x655B59C3); | |
191 | + d = _II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92); | |
192 | + c = _II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D); | |
193 | + b = _II(b, c, d, a, x[k + 1], S44, 0x85845DD1); | |
194 | + a = _II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F); | |
195 | + d = _II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0); | |
196 | + c = _II(c, d, a, b, x[k + 6], S43, 0xA3014314); | |
197 | + b = _II(b, c, d, a, x[k + 13], S44, 0x4E0811A1); | |
198 | + a = _II(a, b, c, d, x[k + 4], S41, 0xF7537E82); | |
199 | + d = _II(d, a, b, c, x[k + 11], S42, 0xBD3AF235); | |
200 | + c = _II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB); | |
201 | + b = _II(b, c, d, a, x[k + 9], S44, 0xEB86D391); | |
202 | + a = addUnsigned(a, AA); | |
203 | + b = addUnsigned(b, BB); | |
204 | + c = addUnsigned(c, CC); | |
205 | + d = addUnsigned(d, DD); | |
206 | + } | |
207 | + | |
208 | + var temp = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d); | |
209 | + | |
210 | + return temp.toLowerCase(); | |
211 | +} | ... | ... |
... | ... | @@ -0,0 +1,70 @@ |
1 | +function utf8_encode (argString) { | |
2 | + // http://kevin.vanzonneveld.net | |
3 | + // + original by: Webtoolkit.info (http://www.webtoolkit.info/) | |
4 | + // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
5 | + // + improved by: sowberry | |
6 | + // + tweaked by: Jack | |
7 | + // + bugfixed by: Onno Marsman | |
8 | + // + improved by: Yves Sucaet | |
9 | + // + bugfixed by: Onno Marsman | |
10 | + // + bugfixed by: Ulrich | |
11 | + // + bugfixed by: Rafal Kukawski | |
12 | + // + improved by: kirilloid | |
13 | + // + bugfixed by: kirilloid | |
14 | + // * example 1: utf8_encode('Kevin van Zonneveld'); | |
15 | + // * returns 1: 'Kevin van Zonneveld' | |
16 | + | |
17 | + if (argString === null || typeof argString === "undefined") { | |
18 | + return ""; | |
19 | + } | |
20 | + | |
21 | + var string = (argString + ''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n"); | |
22 | + var utftext = '', | |
23 | + start, end, stringl = 0; | |
24 | + | |
25 | + start = end = 0; | |
26 | + stringl = string.length; | |
27 | + for (var n = 0; n < stringl; n++) { | |
28 | + var c1 = string.charCodeAt(n); | |
29 | + var enc = null; | |
30 | + | |
31 | + if (c1 < 128) { | |
32 | + end++; | |
33 | + } else if (c1 > 127 && c1 < 2048) { | |
34 | + enc = String.fromCharCode( | |
35 | + (c1 >> 6) | 192, | |
36 | + ( c1 & 63) | 128 | |
37 | + ); | |
38 | + } else if (c1 & 0xF800 != 0xD800) { | |
39 | + enc = String.fromCharCode( | |
40 | + (c1 >> 12) | 224, | |
41 | + ((c1 >> 6) & 63) | 128, | |
42 | + ( c1 & 63) | 128 | |
43 | + ); | |
44 | + } else { // surrogate pairs | |
45 | + if (c1 & 0xFC00 != 0xD800) { throw new RangeError("Unmatched trail surrogate at " + n); } | |
46 | + var c2 = string.charCodeAt(++n); | |
47 | + if (c2 & 0xFC00 != 0xDC00) { throw new RangeError("Unmatched lead surrogate at " + (n-1)); } | |
48 | + c1 = ((c1 & 0x3FF) << 10) + (c2 & 0x3FF) + 0x10000; | |
49 | + enc = String.fromCharCode( | |
50 | + (c1 >> 18) | 240, | |
51 | + ((c1 >> 12) & 63) | 128, | |
52 | + ((c1 >> 6) & 63) | 128, | |
53 | + ( c1 & 63) | 128 | |
54 | + ); | |
55 | + } | |
56 | + if (enc !== null) { | |
57 | + if (end > start) { | |
58 | + utftext += string.slice(start, end); | |
59 | + } | |
60 | + utftext += enc; | |
61 | + start = end = n + 1; | |
62 | + } | |
63 | + } | |
64 | + | |
65 | + if (end > start) { | |
66 | + utftext += string.slice(start, stringl); | |
67 | + } | |
68 | + | |
69 | + return utftext; | |
70 | +} | ... | ... |
app/assets/javascripts/main.js.coffee
... | ... | @@ -32,6 +32,14 @@ window.disableButtonIfEmptyField = (field_selector, button_selector) -> |
32 | 32 | else |
33 | 33 | closest_submit.enable() |
34 | 34 | |
35 | +window.sanitize = (str) -> | |
36 | + return str.replace(/<(?:.|\n)*?>/gm, '') | |
37 | + | |
38 | +window.linkify = (str) -> | |
39 | + exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig | |
40 | + return str.replace(exp,"<a href='$1'>$1</a>") | |
41 | + | |
42 | + | |
35 | 43 | $ -> |
36 | 44 | # Click a .one_click_select field, select the contents |
37 | 45 | $(".one_click_select").on 'click', -> $(@).select() | ... | ... |
app/assets/javascripts/md5.js
... | ... | @@ -1,211 +0,0 @@ |
1 | -function md5 (str) { | |
2 | - // http://kevin.vanzonneveld.net | |
3 | - // + original by: Webtoolkit.info (http://www.webtoolkit.info/) | |
4 | - // + namespaced by: Michael White (http://getsprink.com) | |
5 | - // + tweaked by: Jack | |
6 | - // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
7 | - // + input by: Brett Zamir (http://brett-zamir.me) | |
8 | - // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
9 | - // - depends on: utf8_encode | |
10 | - // * example 1: md5('Kevin van Zonneveld'); | |
11 | - // * returns 1: '6e658d4bfcb59cc13f96c14450ac40b9' | |
12 | - var xl; | |
13 | - | |
14 | - var rotateLeft = function (lValue, iShiftBits) { | |
15 | - return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits)); | |
16 | - }; | |
17 | - | |
18 | - var addUnsigned = function (lX, lY) { | |
19 | - var lX4, lY4, lX8, lY8, lResult; | |
20 | - lX8 = (lX & 0x80000000); | |
21 | - lY8 = (lY & 0x80000000); | |
22 | - lX4 = (lX & 0x40000000); | |
23 | - lY4 = (lY & 0x40000000); | |
24 | - lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF); | |
25 | - if (lX4 & lY4) { | |
26 | - return (lResult ^ 0x80000000 ^ lX8 ^ lY8); | |
27 | - } | |
28 | - if (lX4 | lY4) { | |
29 | - if (lResult & 0x40000000) { | |
30 | - return (lResult ^ 0xC0000000 ^ lX8 ^ lY8); | |
31 | - } else { | |
32 | - return (lResult ^ 0x40000000 ^ lX8 ^ lY8); | |
33 | - } | |
34 | - } else { | |
35 | - return (lResult ^ lX8 ^ lY8); | |
36 | - } | |
37 | - }; | |
38 | - | |
39 | - var _F = function (x, y, z) { | |
40 | - return (x & y) | ((~x) & z); | |
41 | - }; | |
42 | - var _G = function (x, y, z) { | |
43 | - return (x & z) | (y & (~z)); | |
44 | - }; | |
45 | - var _H = function (x, y, z) { | |
46 | - return (x ^ y ^ z); | |
47 | - }; | |
48 | - var _I = function (x, y, z) { | |
49 | - return (y ^ (x | (~z))); | |
50 | - }; | |
51 | - | |
52 | - var _FF = function (a, b, c, d, x, s, ac) { | |
53 | - a = addUnsigned(a, addUnsigned(addUnsigned(_F(b, c, d), x), ac)); | |
54 | - return addUnsigned(rotateLeft(a, s), b); | |
55 | - }; | |
56 | - | |
57 | - var _GG = function (a, b, c, d, x, s, ac) { | |
58 | - a = addUnsigned(a, addUnsigned(addUnsigned(_G(b, c, d), x), ac)); | |
59 | - return addUnsigned(rotateLeft(a, s), b); | |
60 | - }; | |
61 | - | |
62 | - var _HH = function (a, b, c, d, x, s, ac) { | |
63 | - a = addUnsigned(a, addUnsigned(addUnsigned(_H(b, c, d), x), ac)); | |
64 | - return addUnsigned(rotateLeft(a, s), b); | |
65 | - }; | |
66 | - | |
67 | - var _II = function (a, b, c, d, x, s, ac) { | |
68 | - a = addUnsigned(a, addUnsigned(addUnsigned(_I(b, c, d), x), ac)); | |
69 | - return addUnsigned(rotateLeft(a, s), b); | |
70 | - }; | |
71 | - | |
72 | - var convertToWordArray = function (str) { | |
73 | - var lWordCount; | |
74 | - var lMessageLength = str.length; | |
75 | - var lNumberOfWords_temp1 = lMessageLength + 8; | |
76 | - var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64; | |
77 | - var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16; | |
78 | - var lWordArray = new Array(lNumberOfWords - 1); | |
79 | - var lBytePosition = 0; | |
80 | - var lByteCount = 0; | |
81 | - while (lByteCount < lMessageLength) { | |
82 | - lWordCount = (lByteCount - (lByteCount % 4)) / 4; | |
83 | - lBytePosition = (lByteCount % 4) * 8; | |
84 | - lWordArray[lWordCount] = (lWordArray[lWordCount] | (str.charCodeAt(lByteCount) << lBytePosition)); | |
85 | - lByteCount++; | |
86 | - } | |
87 | - lWordCount = (lByteCount - (lByteCount % 4)) / 4; | |
88 | - lBytePosition = (lByteCount % 4) * 8; | |
89 | - lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition); | |
90 | - lWordArray[lNumberOfWords - 2] = lMessageLength << 3; | |
91 | - lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29; | |
92 | - return lWordArray; | |
93 | - }; | |
94 | - | |
95 | - var wordToHex = function (lValue) { | |
96 | - var wordToHexValue = "", | |
97 | - wordToHexValue_temp = "", | |
98 | - lByte, lCount; | |
99 | - for (lCount = 0; lCount <= 3; lCount++) { | |
100 | - lByte = (lValue >>> (lCount * 8)) & 255; | |
101 | - wordToHexValue_temp = "0" + lByte.toString(16); | |
102 | - wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length - 2, 2); | |
103 | - } | |
104 | - return wordToHexValue; | |
105 | - }; | |
106 | - | |
107 | - var x = [], | |
108 | - k, AA, BB, CC, DD, a, b, c, d, S11 = 7, | |
109 | - S12 = 12, | |
110 | - S13 = 17, | |
111 | - S14 = 22, | |
112 | - S21 = 5, | |
113 | - S22 = 9, | |
114 | - S23 = 14, | |
115 | - S24 = 20, | |
116 | - S31 = 4, | |
117 | - S32 = 11, | |
118 | - S33 = 16, | |
119 | - S34 = 23, | |
120 | - S41 = 6, | |
121 | - S42 = 10, | |
122 | - S43 = 15, | |
123 | - S44 = 21; | |
124 | - | |
125 | - str = this.utf8_encode(str); | |
126 | - x = convertToWordArray(str); | |
127 | - a = 0x67452301; | |
128 | - b = 0xEFCDAB89; | |
129 | - c = 0x98BADCFE; | |
130 | - d = 0x10325476; | |
131 | - | |
132 | - xl = x.length; | |
133 | - for (k = 0; k < xl; k += 16) { | |
134 | - AA = a; | |
135 | - BB = b; | |
136 | - CC = c; | |
137 | - DD = d; | |
138 | - a = _FF(a, b, c, d, x[k + 0], S11, 0xD76AA478); | |
139 | - d = _FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756); | |
140 | - c = _FF(c, d, a, b, x[k + 2], S13, 0x242070DB); | |
141 | - b = _FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE); | |
142 | - a = _FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF); | |
143 | - d = _FF(d, a, b, c, x[k + 5], S12, 0x4787C62A); | |
144 | - c = _FF(c, d, a, b, x[k + 6], S13, 0xA8304613); | |
145 | - b = _FF(b, c, d, a, x[k + 7], S14, 0xFD469501); | |
146 | - a = _FF(a, b, c, d, x[k + 8], S11, 0x698098D8); | |
147 | - d = _FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF); | |
148 | - c = _FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1); | |
149 | - b = _FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE); | |
150 | - a = _FF(a, b, c, d, x[k + 12], S11, 0x6B901122); | |
151 | - d = _FF(d, a, b, c, x[k + 13], S12, 0xFD987193); | |
152 | - c = _FF(c, d, a, b, x[k + 14], S13, 0xA679438E); | |
153 | - b = _FF(b, c, d, a, x[k + 15], S14, 0x49B40821); | |
154 | - a = _GG(a, b, c, d, x[k + 1], S21, 0xF61E2562); | |
155 | - d = _GG(d, a, b, c, x[k + 6], S22, 0xC040B340); | |
156 | - c = _GG(c, d, a, b, x[k + 11], S23, 0x265E5A51); | |
157 | - b = _GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA); | |
158 | - a = _GG(a, b, c, d, x[k + 5], S21, 0xD62F105D); | |
159 | - d = _GG(d, a, b, c, x[k + 10], S22, 0x2441453); | |
160 | - c = _GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681); | |
161 | - b = _GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8); | |
162 | - a = _GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6); | |
163 | - d = _GG(d, a, b, c, x[k + 14], S22, 0xC33707D6); | |
164 | - c = _GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87); | |
165 | - b = _GG(b, c, d, a, x[k + 8], S24, 0x455A14ED); | |
166 | - a = _GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905); | |
167 | - d = _GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8); | |
168 | - c = _GG(c, d, a, b, x[k + 7], S23, 0x676F02D9); | |
169 | - b = _GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A); | |
170 | - a = _HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942); | |
171 | - d = _HH(d, a, b, c, x[k + 8], S32, 0x8771F681); | |
172 | - c = _HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122); | |
173 | - b = _HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C); | |
174 | - a = _HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44); | |
175 | - d = _HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9); | |
176 | - c = _HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60); | |
177 | - b = _HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70); | |
178 | - a = _HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6); | |
179 | - d = _HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA); | |
180 | - c = _HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085); | |
181 | - b = _HH(b, c, d, a, x[k + 6], S34, 0x4881D05); | |
182 | - a = _HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039); | |
183 | - d = _HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5); | |
184 | - c = _HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8); | |
185 | - b = _HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665); | |
186 | - a = _II(a, b, c, d, x[k + 0], S41, 0xF4292244); | |
187 | - d = _II(d, a, b, c, x[k + 7], S42, 0x432AFF97); | |
188 | - c = _II(c, d, a, b, x[k + 14], S43, 0xAB9423A7); | |
189 | - b = _II(b, c, d, a, x[k + 5], S44, 0xFC93A039); | |
190 | - a = _II(a, b, c, d, x[k + 12], S41, 0x655B59C3); | |
191 | - d = _II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92); | |
192 | - c = _II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D); | |
193 | - b = _II(b, c, d, a, x[k + 1], S44, 0x85845DD1); | |
194 | - a = _II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F); | |
195 | - d = _II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0); | |
196 | - c = _II(c, d, a, b, x[k + 6], S43, 0xA3014314); | |
197 | - b = _II(b, c, d, a, x[k + 13], S44, 0x4E0811A1); | |
198 | - a = _II(a, b, c, d, x[k + 4], S41, 0xF7537E82); | |
199 | - d = _II(d, a, b, c, x[k + 11], S42, 0xBD3AF235); | |
200 | - c = _II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB); | |
201 | - b = _II(b, c, d, a, x[k + 9], S44, 0xEB86D391); | |
202 | - a = addUnsigned(a, AA); | |
203 | - b = addUnsigned(b, BB); | |
204 | - c = addUnsigned(c, CC); | |
205 | - d = addUnsigned(d, DD); | |
206 | - } | |
207 | - | |
208 | - var temp = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d); | |
209 | - | |
210 | - return temp.toLowerCase(); | |
211 | -} |
app/assets/javascripts/utf8_encode.js
... | ... | @@ -1,70 +0,0 @@ |
1 | -function utf8_encode (argString) { | |
2 | - // http://kevin.vanzonneveld.net | |
3 | - // + original by: Webtoolkit.info (http://www.webtoolkit.info/) | |
4 | - // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
5 | - // + improved by: sowberry | |
6 | - // + tweaked by: Jack | |
7 | - // + bugfixed by: Onno Marsman | |
8 | - // + improved by: Yves Sucaet | |
9 | - // + bugfixed by: Onno Marsman | |
10 | - // + bugfixed by: Ulrich | |
11 | - // + bugfixed by: Rafal Kukawski | |
12 | - // + improved by: kirilloid | |
13 | - // + bugfixed by: kirilloid | |
14 | - // * example 1: utf8_encode('Kevin van Zonneveld'); | |
15 | - // * returns 1: 'Kevin van Zonneveld' | |
16 | - | |
17 | - if (argString === null || typeof argString === "undefined") { | |
18 | - return ""; | |
19 | - } | |
20 | - | |
21 | - var string = (argString + ''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n"); | |
22 | - var utftext = '', | |
23 | - start, end, stringl = 0; | |
24 | - | |
25 | - start = end = 0; | |
26 | - stringl = string.length; | |
27 | - for (var n = 0; n < stringl; n++) { | |
28 | - var c1 = string.charCodeAt(n); | |
29 | - var enc = null; | |
30 | - | |
31 | - if (c1 < 128) { | |
32 | - end++; | |
33 | - } else if (c1 > 127 && c1 < 2048) { | |
34 | - enc = String.fromCharCode( | |
35 | - (c1 >> 6) | 192, | |
36 | - ( c1 & 63) | 128 | |
37 | - ); | |
38 | - } else if (c1 & 0xF800 != 0xD800) { | |
39 | - enc = String.fromCharCode( | |
40 | - (c1 >> 12) | 224, | |
41 | - ((c1 >> 6) & 63) | 128, | |
42 | - ( c1 & 63) | 128 | |
43 | - ); | |
44 | - } else { // surrogate pairs | |
45 | - if (c1 & 0xFC00 != 0xD800) { throw new RangeError("Unmatched trail surrogate at " + n); } | |
46 | - var c2 = string.charCodeAt(++n); | |
47 | - if (c2 & 0xFC00 != 0xDC00) { throw new RangeError("Unmatched lead surrogate at " + (n-1)); } | |
48 | - c1 = ((c1 & 0x3FF) << 10) + (c2 & 0x3FF) + 0x10000; | |
49 | - enc = String.fromCharCode( | |
50 | - (c1 >> 18) | 240, | |
51 | - ((c1 >> 12) & 63) | 128, | |
52 | - ((c1 >> 6) & 63) | 128, | |
53 | - ( c1 & 63) | 128 | |
54 | - ); | |
55 | - } | |
56 | - if (enc !== null) { | |
57 | - if (end > start) { | |
58 | - utftext += string.slice(start, end); | |
59 | - } | |
60 | - utftext += enc; | |
61 | - start = end = n + 1; | |
62 | - } | |
63 | - } | |
64 | - | |
65 | - if (end > start) { | |
66 | - utftext += string.slice(start, stringl); | |
67 | - } | |
68 | - | |
69 | - return utftext; | |
70 | -} |
app/assets/javascripts/wall.js.coffee
... | ... | @@ -70,7 +70,7 @@ |
70 | 70 | |
71 | 71 | renderNote: (note) -> |
72 | 72 | author = '<strong class="wall-author">' + note.author.name + '</strong>' |
73 | - body = '<span class="wall-text">' + note.body + '</span>' | |
73 | + body = '<span class="wall-text">' + linkify(sanitize(note.body)) + '</span>' | |
74 | 74 | file = '' |
75 | 75 | time = '<abbr class="timeago" title="' + note.created_at + '">' + note.created_at + '</time>' |
76 | 76 | |
... | ... | @@ -80,4 +80,3 @@ |
80 | 80 | html = '<li>' + author + body + file + time + '</li>' |
81 | 81 | |
82 | 82 | $('ul.notes').append(html) |
83 | - | ... | ... |