interval-braining-ui-asset-pack 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/asset_pack/engine.rb +5 -2
- data/lib/asset_pack/version.rb +1 -1
- data/vendor/assets/bower_components/angular/angular.js +23377 -0
- data/vendor/assets/bower_components/angular-animate/angular-animate.js +1729 -0
- data/vendor/assets/bower_components/angular-growl-notifications/dist/growl-notifications.js +241 -0
- data/vendor/assets/bower_components/angular-input-match/dist/angular-input-match.js +39 -0
- data/vendor/assets/bower_components/angular-messages/angular-messages.js +400 -0
- data/vendor/assets/bower_components/angular-mocks/angular-mocks.js +2228 -0
- data/vendor/assets/bower_components/angular-resource/angular-resource.js +660 -0
- data/vendor/assets/bower_components/angular-sanitize/angular-sanitize.js +640 -0
- data/vendor/assets/bower_components/angular-ui-router/release/angular-ui-router.js +3223 -0
- data/vendor/assets/bower_components/angular-ui-router-breadcrumbs/dist/angular-ui-router-breadcrumbs.js +82 -0
- data/vendor/assets/bower_components/angular-ui-router-helpers/dist/angular-ui-router-helpers.js +52 -0
- data/vendor/assets/bower_components/angular-ui-router-hooks-before-state/dist/angular-ui-router-hooks-before-state.js +56 -0
- data/vendor/assets/bower_components/angular-validate-in-set/dist/angular-validate-in-set.js +77 -0
- data/vendor/assets/bower_components/animate.css/animate.css +3125 -0
- data/vendor/assets/bower_components/bootstrap/dist/css/bootstrap.css +5785 -0
- data/vendor/assets/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.eot +0 -0
- data/vendor/assets/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.svg +229 -0
- data/vendor/assets/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/vendor/assets/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff +0 -0
- data/vendor/assets/bower_components/bootstrap/dist/js/bootstrap.js +1951 -0
- data/vendor/assets/bower_components/cardigan/dist/cardigan.css +37 -0
- data/vendor/assets/bower_components/cardigan/dist/cardigan.js +239 -0
- data/vendor/assets/bower_components/font-awesome-bower/css/font-awesome.css +1338 -0
- data/vendor/assets/bower_components/font-awesome-bower/fonts/FontAwesome.otf +0 -0
- data/vendor/assets/bower_components/font-awesome-bower/fonts/fontawesome-webfont.eot +0 -0
- data/vendor/assets/bower_components/font-awesome-bower/fonts/fontawesome-webfont.svg +414 -0
- data/vendor/assets/bower_components/font-awesome-bower/fonts/fontawesome-webfont.ttf +0 -0
- data/vendor/assets/bower_components/font-awesome-bower/fonts/fontawesome-webfont.woff +0 -0
- data/vendor/assets/bower_components/jquery/dist/jquery.js +9190 -0
- data/vendor/assets/bower_components/webfont-OpenSans-Light/dist/OpenSans-Light.css +10 -0
- data/vendor/assets/bower_components/webfont-OpenSans-Light/dist/OpenSans-Light.eot +0 -0
- data/vendor/assets/bower_components/webfont-OpenSans-Light/dist/OpenSans-Light.svg +1831 -0
- data/vendor/assets/bower_components/webfont-OpenSans-Light/dist/OpenSans-Light.ttf +0 -0
- data/vendor/assets/bower_components/webfont-OpenSans-Light/dist/OpenSans-Light.woff +0 -0
- metadata +36 -2
@@ -0,0 +1,640 @@
|
|
1
|
+
/**
|
2
|
+
* @license AngularJS v1.2.21
|
3
|
+
* (c) 2010-2014 Google, Inc. http://angularjs.org
|
4
|
+
* License: MIT
|
5
|
+
*/
|
6
|
+
(function(window, angular, undefined) {'use strict';
|
7
|
+
|
8
|
+
var $sanitizeMinErr = angular.$$minErr('$sanitize');
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @ngdoc module
|
12
|
+
* @name ngSanitize
|
13
|
+
* @description
|
14
|
+
*
|
15
|
+
* # ngSanitize
|
16
|
+
*
|
17
|
+
* The `ngSanitize` module provides functionality to sanitize HTML.
|
18
|
+
*
|
19
|
+
*
|
20
|
+
* <div doc-module-components="ngSanitize"></div>
|
21
|
+
*
|
22
|
+
* See {@link ngSanitize.$sanitize `$sanitize`} for usage.
|
23
|
+
*/
|
24
|
+
|
25
|
+
/*
|
26
|
+
* HTML Parser By Misko Hevery (misko@hevery.com)
|
27
|
+
* based on: HTML Parser By John Resig (ejohn.org)
|
28
|
+
* Original code by Erik Arvidsson, Mozilla Public License
|
29
|
+
* http://erik.eae.net/simplehtmlparser/simplehtmlparser.js
|
30
|
+
*
|
31
|
+
* // Use like so:
|
32
|
+
* htmlParser(htmlString, {
|
33
|
+
* start: function(tag, attrs, unary) {},
|
34
|
+
* end: function(tag) {},
|
35
|
+
* chars: function(text) {},
|
36
|
+
* comment: function(text) {}
|
37
|
+
* });
|
38
|
+
*
|
39
|
+
*/
|
40
|
+
|
41
|
+
|
42
|
+
/**
|
43
|
+
* @ngdoc service
|
44
|
+
* @name $sanitize
|
45
|
+
* @kind function
|
46
|
+
*
|
47
|
+
* @description
|
48
|
+
* The input is sanitized by parsing the html into tokens. All safe tokens (from a whitelist) are
|
49
|
+
* then serialized back to properly escaped html string. This means that no unsafe input can make
|
50
|
+
* it into the returned string, however, since our parser is more strict than a typical browser
|
51
|
+
* parser, it's possible that some obscure input, which would be recognized as valid HTML by a
|
52
|
+
* browser, won't make it through the sanitizer.
|
53
|
+
* The whitelist is configured using the functions `aHrefSanitizationWhitelist` and
|
54
|
+
* `imgSrcSanitizationWhitelist` of {@link ng.$compileProvider `$compileProvider`}.
|
55
|
+
*
|
56
|
+
* @param {string} html Html input.
|
57
|
+
* @returns {string} Sanitized html.
|
58
|
+
*
|
59
|
+
* @example
|
60
|
+
<example module="sanitizeExample" deps="angular-sanitize.js">
|
61
|
+
<file name="index.html">
|
62
|
+
<script>
|
63
|
+
angular.module('sanitizeExample', ['ngSanitize'])
|
64
|
+
.controller('ExampleController', ['$scope', '$sce', function($scope, $sce) {
|
65
|
+
$scope.snippet =
|
66
|
+
'<p style="color:blue">an html\n' +
|
67
|
+
'<em onmouseover="this.textContent=\'PWN3D!\'">click here</em>\n' +
|
68
|
+
'snippet</p>';
|
69
|
+
$scope.deliberatelyTrustDangerousSnippet = function() {
|
70
|
+
return $sce.trustAsHtml($scope.snippet);
|
71
|
+
};
|
72
|
+
}]);
|
73
|
+
</script>
|
74
|
+
<div ng-controller="ExampleController">
|
75
|
+
Snippet: <textarea ng-model="snippet" cols="60" rows="3"></textarea>
|
76
|
+
<table>
|
77
|
+
<tr>
|
78
|
+
<td>Directive</td>
|
79
|
+
<td>How</td>
|
80
|
+
<td>Source</td>
|
81
|
+
<td>Rendered</td>
|
82
|
+
</tr>
|
83
|
+
<tr id="bind-html-with-sanitize">
|
84
|
+
<td>ng-bind-html</td>
|
85
|
+
<td>Automatically uses $sanitize</td>
|
86
|
+
<td><pre><div ng-bind-html="snippet"><br/></div></pre></td>
|
87
|
+
<td><div ng-bind-html="snippet"></div></td>
|
88
|
+
</tr>
|
89
|
+
<tr id="bind-html-with-trust">
|
90
|
+
<td>ng-bind-html</td>
|
91
|
+
<td>Bypass $sanitize by explicitly trusting the dangerous value</td>
|
92
|
+
<td>
|
93
|
+
<pre><div ng-bind-html="deliberatelyTrustDangerousSnippet()">
|
94
|
+
</div></pre>
|
95
|
+
</td>
|
96
|
+
<td><div ng-bind-html="deliberatelyTrustDangerousSnippet()"></div></td>
|
97
|
+
</tr>
|
98
|
+
<tr id="bind-default">
|
99
|
+
<td>ng-bind</td>
|
100
|
+
<td>Automatically escapes</td>
|
101
|
+
<td><pre><div ng-bind="snippet"><br/></div></pre></td>
|
102
|
+
<td><div ng-bind="snippet"></div></td>
|
103
|
+
</tr>
|
104
|
+
</table>
|
105
|
+
</div>
|
106
|
+
</file>
|
107
|
+
<file name="protractor.js" type="protractor">
|
108
|
+
it('should sanitize the html snippet by default', function() {
|
109
|
+
expect(element(by.css('#bind-html-with-sanitize div')).getInnerHtml()).
|
110
|
+
toBe('<p>an html\n<em>click here</em>\nsnippet</p>');
|
111
|
+
});
|
112
|
+
|
113
|
+
it('should inline raw snippet if bound to a trusted value', function() {
|
114
|
+
expect(element(by.css('#bind-html-with-trust div')).getInnerHtml()).
|
115
|
+
toBe("<p style=\"color:blue\">an html\n" +
|
116
|
+
"<em onmouseover=\"this.textContent='PWN3D!'\">click here</em>\n" +
|
117
|
+
"snippet</p>");
|
118
|
+
});
|
119
|
+
|
120
|
+
it('should escape snippet without any filter', function() {
|
121
|
+
expect(element(by.css('#bind-default div')).getInnerHtml()).
|
122
|
+
toBe("<p style=\"color:blue\">an html\n" +
|
123
|
+
"<em onmouseover=\"this.textContent='PWN3D!'\">click here</em>\n" +
|
124
|
+
"snippet</p>");
|
125
|
+
});
|
126
|
+
|
127
|
+
it('should update', function() {
|
128
|
+
element(by.model('snippet')).clear();
|
129
|
+
element(by.model('snippet')).sendKeys('new <b onclick="alert(1)">text</b>');
|
130
|
+
expect(element(by.css('#bind-html-with-sanitize div')).getInnerHtml()).
|
131
|
+
toBe('new <b>text</b>');
|
132
|
+
expect(element(by.css('#bind-html-with-trust div')).getInnerHtml()).toBe(
|
133
|
+
'new <b onclick="alert(1)">text</b>');
|
134
|
+
expect(element(by.css('#bind-default div')).getInnerHtml()).toBe(
|
135
|
+
"new <b onclick=\"alert(1)\">text</b>");
|
136
|
+
});
|
137
|
+
</file>
|
138
|
+
</example>
|
139
|
+
*/
|
140
|
+
function $SanitizeProvider() {
|
141
|
+
this.$get = ['$$sanitizeUri', function($$sanitizeUri) {
|
142
|
+
return function(html) {
|
143
|
+
var buf = [];
|
144
|
+
htmlParser(html, htmlSanitizeWriter(buf, function(uri, isImage) {
|
145
|
+
return !/^unsafe/.test($$sanitizeUri(uri, isImage));
|
146
|
+
}));
|
147
|
+
return buf.join('');
|
148
|
+
};
|
149
|
+
}];
|
150
|
+
}
|
151
|
+
|
152
|
+
function sanitizeText(chars) {
|
153
|
+
var buf = [];
|
154
|
+
var writer = htmlSanitizeWriter(buf, angular.noop);
|
155
|
+
writer.chars(chars);
|
156
|
+
return buf.join('');
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
// Regular Expressions for parsing tags and attributes
|
161
|
+
var START_TAG_REGEXP =
|
162
|
+
/^<((?:[a-zA-Z])[\w:-]*)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)\s*(>?)/,
|
163
|
+
END_TAG_REGEXP = /^<\/\s*([\w:-]+)[^>]*>/,
|
164
|
+
ATTR_REGEXP = /([\w:-]+)(?:\s*=\s*(?:(?:"((?:[^"])*)")|(?:'((?:[^'])*)')|([^>\s]+)))?/g,
|
165
|
+
BEGIN_TAG_REGEXP = /^</,
|
166
|
+
BEGING_END_TAGE_REGEXP = /^<\//,
|
167
|
+
COMMENT_REGEXP = /<!--(.*?)-->/g,
|
168
|
+
DOCTYPE_REGEXP = /<!DOCTYPE([^>]*?)>/i,
|
169
|
+
CDATA_REGEXP = /<!\[CDATA\[(.*?)]]>/g,
|
170
|
+
SURROGATE_PAIR_REGEXP = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
|
171
|
+
// Match everything outside of normal chars and " (quote character)
|
172
|
+
NON_ALPHANUMERIC_REGEXP = /([^\#-~| |!])/g;
|
173
|
+
|
174
|
+
|
175
|
+
// Good source of info about elements and attributes
|
176
|
+
// http://dev.w3.org/html5/spec/Overview.html#semantics
|
177
|
+
// http://simon.html5.org/html-elements
|
178
|
+
|
179
|
+
// Safe Void Elements - HTML5
|
180
|
+
// http://dev.w3.org/html5/spec/Overview.html#void-elements
|
181
|
+
var voidElements = makeMap("area,br,col,hr,img,wbr");
|
182
|
+
|
183
|
+
// Elements that you can, intentionally, leave open (and which close themselves)
|
184
|
+
// http://dev.w3.org/html5/spec/Overview.html#optional-tags
|
185
|
+
var optionalEndTagBlockElements = makeMap("colgroup,dd,dt,li,p,tbody,td,tfoot,th,thead,tr"),
|
186
|
+
optionalEndTagInlineElements = makeMap("rp,rt"),
|
187
|
+
optionalEndTagElements = angular.extend({},
|
188
|
+
optionalEndTagInlineElements,
|
189
|
+
optionalEndTagBlockElements);
|
190
|
+
|
191
|
+
// Safe Block Elements - HTML5
|
192
|
+
var blockElements = angular.extend({}, optionalEndTagBlockElements, makeMap("address,article," +
|
193
|
+
"aside,blockquote,caption,center,del,dir,div,dl,figure,figcaption,footer,h1,h2,h3,h4,h5," +
|
194
|
+
"h6,header,hgroup,hr,ins,map,menu,nav,ol,pre,script,section,table,ul"));
|
195
|
+
|
196
|
+
// Inline Elements - HTML5
|
197
|
+
var inlineElements = angular.extend({}, optionalEndTagInlineElements, makeMap("a,abbr,acronym,b," +
|
198
|
+
"bdi,bdo,big,br,cite,code,del,dfn,em,font,i,img,ins,kbd,label,map,mark,q,ruby,rp,rt,s," +
|
199
|
+
"samp,small,span,strike,strong,sub,sup,time,tt,u,var"));
|
200
|
+
|
201
|
+
|
202
|
+
// Special Elements (can contain anything)
|
203
|
+
var specialElements = makeMap("script,style");
|
204
|
+
|
205
|
+
var validElements = angular.extend({},
|
206
|
+
voidElements,
|
207
|
+
blockElements,
|
208
|
+
inlineElements,
|
209
|
+
optionalEndTagElements);
|
210
|
+
|
211
|
+
//Attributes that have href and hence need to be sanitized
|
212
|
+
var uriAttrs = makeMap("background,cite,href,longdesc,src,usemap");
|
213
|
+
var validAttrs = angular.extend({}, uriAttrs, makeMap(
|
214
|
+
'abbr,align,alt,axis,bgcolor,border,cellpadding,cellspacing,class,clear,'+
|
215
|
+
'color,cols,colspan,compact,coords,dir,face,headers,height,hreflang,hspace,'+
|
216
|
+
'ismap,lang,language,nohref,nowrap,rel,rev,rows,rowspan,rules,'+
|
217
|
+
'scope,scrolling,shape,size,span,start,summary,target,title,type,'+
|
218
|
+
'valign,value,vspace,width'));
|
219
|
+
|
220
|
+
function makeMap(str) {
|
221
|
+
var obj = {}, items = str.split(','), i;
|
222
|
+
for (i = 0; i < items.length; i++) obj[items[i]] = true;
|
223
|
+
return obj;
|
224
|
+
}
|
225
|
+
|
226
|
+
|
227
|
+
/**
|
228
|
+
* @example
|
229
|
+
* htmlParser(htmlString, {
|
230
|
+
* start: function(tag, attrs, unary) {},
|
231
|
+
* end: function(tag) {},
|
232
|
+
* chars: function(text) {},
|
233
|
+
* comment: function(text) {}
|
234
|
+
* });
|
235
|
+
*
|
236
|
+
* @param {string} html string
|
237
|
+
* @param {object} handler
|
238
|
+
*/
|
239
|
+
function htmlParser( html, handler ) {
|
240
|
+
var index, chars, match, stack = [], last = html, text;
|
241
|
+
stack.last = function() { return stack[ stack.length - 1 ]; };
|
242
|
+
|
243
|
+
while ( html ) {
|
244
|
+
text = '';
|
245
|
+
chars = true;
|
246
|
+
|
247
|
+
// Make sure we're not in a script or style element
|
248
|
+
if ( !stack.last() || !specialElements[ stack.last() ] ) {
|
249
|
+
|
250
|
+
// Comment
|
251
|
+
if ( html.indexOf("<!--") === 0 ) {
|
252
|
+
// comments containing -- are not allowed unless they terminate the comment
|
253
|
+
index = html.indexOf("--", 4);
|
254
|
+
|
255
|
+
if ( index >= 0 && html.lastIndexOf("-->", index) === index) {
|
256
|
+
if (handler.comment) handler.comment( html.substring( 4, index ) );
|
257
|
+
html = html.substring( index + 3 );
|
258
|
+
chars = false;
|
259
|
+
}
|
260
|
+
// DOCTYPE
|
261
|
+
} else if ( DOCTYPE_REGEXP.test(html) ) {
|
262
|
+
match = html.match( DOCTYPE_REGEXP );
|
263
|
+
|
264
|
+
if ( match ) {
|
265
|
+
html = html.replace( match[0], '');
|
266
|
+
chars = false;
|
267
|
+
}
|
268
|
+
// end tag
|
269
|
+
} else if ( BEGING_END_TAGE_REGEXP.test(html) ) {
|
270
|
+
match = html.match( END_TAG_REGEXP );
|
271
|
+
|
272
|
+
if ( match ) {
|
273
|
+
html = html.substring( match[0].length );
|
274
|
+
match[0].replace( END_TAG_REGEXP, parseEndTag );
|
275
|
+
chars = false;
|
276
|
+
}
|
277
|
+
|
278
|
+
// start tag
|
279
|
+
} else if ( BEGIN_TAG_REGEXP.test(html) ) {
|
280
|
+
match = html.match( START_TAG_REGEXP );
|
281
|
+
|
282
|
+
if ( match ) {
|
283
|
+
// We only have a valid start-tag if there is a '>'.
|
284
|
+
if ( match[4] ) {
|
285
|
+
html = html.substring( match[0].length );
|
286
|
+
match[0].replace( START_TAG_REGEXP, parseStartTag );
|
287
|
+
}
|
288
|
+
chars = false;
|
289
|
+
} else {
|
290
|
+
// no ending tag found --- this piece should be encoded as an entity.
|
291
|
+
text += '<';
|
292
|
+
html = html.substring(1);
|
293
|
+
}
|
294
|
+
}
|
295
|
+
|
296
|
+
if ( chars ) {
|
297
|
+
index = html.indexOf("<");
|
298
|
+
|
299
|
+
text += index < 0 ? html : html.substring( 0, index );
|
300
|
+
html = index < 0 ? "" : html.substring( index );
|
301
|
+
|
302
|
+
if (handler.chars) handler.chars( decodeEntities(text) );
|
303
|
+
}
|
304
|
+
|
305
|
+
} else {
|
306
|
+
html = html.replace(new RegExp("(.*)<\\s*\\/\\s*" + stack.last() + "[^>]*>", 'i'),
|
307
|
+
function(all, text){
|
308
|
+
text = text.replace(COMMENT_REGEXP, "$1").replace(CDATA_REGEXP, "$1");
|
309
|
+
|
310
|
+
if (handler.chars) handler.chars( decodeEntities(text) );
|
311
|
+
|
312
|
+
return "";
|
313
|
+
});
|
314
|
+
|
315
|
+
parseEndTag( "", stack.last() );
|
316
|
+
}
|
317
|
+
|
318
|
+
if ( html == last ) {
|
319
|
+
throw $sanitizeMinErr('badparse', "The sanitizer was unable to parse the following block " +
|
320
|
+
"of html: {0}", html);
|
321
|
+
}
|
322
|
+
last = html;
|
323
|
+
}
|
324
|
+
|
325
|
+
// Clean up any remaining tags
|
326
|
+
parseEndTag();
|
327
|
+
|
328
|
+
function parseStartTag( tag, tagName, rest, unary ) {
|
329
|
+
tagName = angular.lowercase(tagName);
|
330
|
+
if ( blockElements[ tagName ] ) {
|
331
|
+
while ( stack.last() && inlineElements[ stack.last() ] ) {
|
332
|
+
parseEndTag( "", stack.last() );
|
333
|
+
}
|
334
|
+
}
|
335
|
+
|
336
|
+
if ( optionalEndTagElements[ tagName ] && stack.last() == tagName ) {
|
337
|
+
parseEndTag( "", tagName );
|
338
|
+
}
|
339
|
+
|
340
|
+
unary = voidElements[ tagName ] || !!unary;
|
341
|
+
|
342
|
+
if ( !unary )
|
343
|
+
stack.push( tagName );
|
344
|
+
|
345
|
+
var attrs = {};
|
346
|
+
|
347
|
+
rest.replace(ATTR_REGEXP,
|
348
|
+
function(match, name, doubleQuotedValue, singleQuotedValue, unquotedValue) {
|
349
|
+
var value = doubleQuotedValue
|
350
|
+
|| singleQuotedValue
|
351
|
+
|| unquotedValue
|
352
|
+
|| '';
|
353
|
+
|
354
|
+
attrs[name] = decodeEntities(value);
|
355
|
+
});
|
356
|
+
if (handler.start) handler.start( tagName, attrs, unary );
|
357
|
+
}
|
358
|
+
|
359
|
+
function parseEndTag( tag, tagName ) {
|
360
|
+
var pos = 0, i;
|
361
|
+
tagName = angular.lowercase(tagName);
|
362
|
+
if ( tagName )
|
363
|
+
// Find the closest opened tag of the same type
|
364
|
+
for ( pos = stack.length - 1; pos >= 0; pos-- )
|
365
|
+
if ( stack[ pos ] == tagName )
|
366
|
+
break;
|
367
|
+
|
368
|
+
if ( pos >= 0 ) {
|
369
|
+
// Close all the open elements, up the stack
|
370
|
+
for ( i = stack.length - 1; i >= pos; i-- )
|
371
|
+
if (handler.end) handler.end( stack[ i ] );
|
372
|
+
|
373
|
+
// Remove the open elements from the stack
|
374
|
+
stack.length = pos;
|
375
|
+
}
|
376
|
+
}
|
377
|
+
}
|
378
|
+
|
379
|
+
var hiddenPre=document.createElement("pre");
|
380
|
+
var spaceRe = /^(\s*)([\s\S]*?)(\s*)$/;
|
381
|
+
/**
|
382
|
+
* decodes all entities into regular string
|
383
|
+
* @param value
|
384
|
+
* @returns {string} A string with decoded entities.
|
385
|
+
*/
|
386
|
+
function decodeEntities(value) {
|
387
|
+
if (!value) { return ''; }
|
388
|
+
|
389
|
+
// Note: IE8 does not preserve spaces at the start/end of innerHTML
|
390
|
+
// so we must capture them and reattach them afterward
|
391
|
+
var parts = spaceRe.exec(value);
|
392
|
+
var spaceBefore = parts[1];
|
393
|
+
var spaceAfter = parts[3];
|
394
|
+
var content = parts[2];
|
395
|
+
if (content) {
|
396
|
+
hiddenPre.innerHTML=content.replace(/</g,"<");
|
397
|
+
// innerText depends on styling as it doesn't display hidden elements.
|
398
|
+
// Therefore, it's better to use textContent not to cause unnecessary
|
399
|
+
// reflows. However, IE<9 don't support textContent so the innerText
|
400
|
+
// fallback is necessary.
|
401
|
+
content = 'textContent' in hiddenPre ?
|
402
|
+
hiddenPre.textContent : hiddenPre.innerText;
|
403
|
+
}
|
404
|
+
return spaceBefore + content + spaceAfter;
|
405
|
+
}
|
406
|
+
|
407
|
+
/**
|
408
|
+
* Escapes all potentially dangerous characters, so that the
|
409
|
+
* resulting string can be safely inserted into attribute or
|
410
|
+
* element text.
|
411
|
+
* @param value
|
412
|
+
* @returns {string} escaped text
|
413
|
+
*/
|
414
|
+
function encodeEntities(value) {
|
415
|
+
return value.
|
416
|
+
replace(/&/g, '&').
|
417
|
+
replace(SURROGATE_PAIR_REGEXP, function (value) {
|
418
|
+
var hi = value.charCodeAt(0);
|
419
|
+
var low = value.charCodeAt(1);
|
420
|
+
return '&#' + (((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000) + ';';
|
421
|
+
}).
|
422
|
+
replace(NON_ALPHANUMERIC_REGEXP, function(value){
|
423
|
+
return '&#' + value.charCodeAt(0) + ';';
|
424
|
+
}).
|
425
|
+
replace(/</g, '<').
|
426
|
+
replace(/>/g, '>');
|
427
|
+
}
|
428
|
+
|
429
|
+
/**
|
430
|
+
* create an HTML/XML writer which writes to buffer
|
431
|
+
* @param {Array} buf use buf.jain('') to get out sanitized html string
|
432
|
+
* @returns {object} in the form of {
|
433
|
+
* start: function(tag, attrs, unary) {},
|
434
|
+
* end: function(tag) {},
|
435
|
+
* chars: function(text) {},
|
436
|
+
* comment: function(text) {}
|
437
|
+
* }
|
438
|
+
*/
|
439
|
+
function htmlSanitizeWriter(buf, uriValidator){
|
440
|
+
var ignore = false;
|
441
|
+
var out = angular.bind(buf, buf.push);
|
442
|
+
return {
|
443
|
+
start: function(tag, attrs, unary){
|
444
|
+
tag = angular.lowercase(tag);
|
445
|
+
if (!ignore && specialElements[tag]) {
|
446
|
+
ignore = tag;
|
447
|
+
}
|
448
|
+
if (!ignore && validElements[tag] === true) {
|
449
|
+
out('<');
|
450
|
+
out(tag);
|
451
|
+
angular.forEach(attrs, function(value, key){
|
452
|
+
var lkey=angular.lowercase(key);
|
453
|
+
var isImage = (tag === 'img' && lkey === 'src') || (lkey === 'background');
|
454
|
+
if (validAttrs[lkey] === true &&
|
455
|
+
(uriAttrs[lkey] !== true || uriValidator(value, isImage))) {
|
456
|
+
out(' ');
|
457
|
+
out(key);
|
458
|
+
out('="');
|
459
|
+
out(encodeEntities(value));
|
460
|
+
out('"');
|
461
|
+
}
|
462
|
+
});
|
463
|
+
out(unary ? '/>' : '>');
|
464
|
+
}
|
465
|
+
},
|
466
|
+
end: function(tag){
|
467
|
+
tag = angular.lowercase(tag);
|
468
|
+
if (!ignore && validElements[tag] === true) {
|
469
|
+
out('</');
|
470
|
+
out(tag);
|
471
|
+
out('>');
|
472
|
+
}
|
473
|
+
if (tag == ignore) {
|
474
|
+
ignore = false;
|
475
|
+
}
|
476
|
+
},
|
477
|
+
chars: function(chars){
|
478
|
+
if (!ignore) {
|
479
|
+
out(encodeEntities(chars));
|
480
|
+
}
|
481
|
+
}
|
482
|
+
};
|
483
|
+
}
|
484
|
+
|
485
|
+
|
486
|
+
// define ngSanitize module and register $sanitize service
|
487
|
+
angular.module('ngSanitize', []).provider('$sanitize', $SanitizeProvider);
|
488
|
+
|
489
|
+
/* global sanitizeText: false */
|
490
|
+
|
491
|
+
/**
|
492
|
+
* @ngdoc filter
|
493
|
+
* @name linky
|
494
|
+
* @kind function
|
495
|
+
*
|
496
|
+
* @description
|
497
|
+
* Finds links in text input and turns them into html links. Supports http/https/ftp/mailto and
|
498
|
+
* plain email address links.
|
499
|
+
*
|
500
|
+
* Requires the {@link ngSanitize `ngSanitize`} module to be installed.
|
501
|
+
*
|
502
|
+
* @param {string} text Input text.
|
503
|
+
* @param {string} target Window (_blank|_self|_parent|_top) or named frame to open links in.
|
504
|
+
* @returns {string} Html-linkified text.
|
505
|
+
*
|
506
|
+
* @usage
|
507
|
+
<span ng-bind-html="linky_expression | linky"></span>
|
508
|
+
*
|
509
|
+
* @example
|
510
|
+
<example module="linkyExample" deps="angular-sanitize.js">
|
511
|
+
<file name="index.html">
|
512
|
+
<script>
|
513
|
+
angular.module('linkyExample', ['ngSanitize'])
|
514
|
+
.controller('ExampleController', ['$scope', function($scope) {
|
515
|
+
$scope.snippet =
|
516
|
+
'Pretty text with some links:\n'+
|
517
|
+
'http://angularjs.org/,\n'+
|
518
|
+
'mailto:us@somewhere.org,\n'+
|
519
|
+
'another@somewhere.org,\n'+
|
520
|
+
'and one more: ftp://127.0.0.1/.';
|
521
|
+
$scope.snippetWithTarget = 'http://angularjs.org/';
|
522
|
+
}]);
|
523
|
+
</script>
|
524
|
+
<div ng-controller="ExampleController">
|
525
|
+
Snippet: <textarea ng-model="snippet" cols="60" rows="3"></textarea>
|
526
|
+
<table>
|
527
|
+
<tr>
|
528
|
+
<td>Filter</td>
|
529
|
+
<td>Source</td>
|
530
|
+
<td>Rendered</td>
|
531
|
+
</tr>
|
532
|
+
<tr id="linky-filter">
|
533
|
+
<td>linky filter</td>
|
534
|
+
<td>
|
535
|
+
<pre><div ng-bind-html="snippet | linky"><br></div></pre>
|
536
|
+
</td>
|
537
|
+
<td>
|
538
|
+
<div ng-bind-html="snippet | linky"></div>
|
539
|
+
</td>
|
540
|
+
</tr>
|
541
|
+
<tr id="linky-target">
|
542
|
+
<td>linky target</td>
|
543
|
+
<td>
|
544
|
+
<pre><div ng-bind-html="snippetWithTarget | linky:'_blank'"><br></div></pre>
|
545
|
+
</td>
|
546
|
+
<td>
|
547
|
+
<div ng-bind-html="snippetWithTarget | linky:'_blank'"></div>
|
548
|
+
</td>
|
549
|
+
</tr>
|
550
|
+
<tr id="escaped-html">
|
551
|
+
<td>no filter</td>
|
552
|
+
<td><pre><div ng-bind="snippet"><br></div></pre></td>
|
553
|
+
<td><div ng-bind="snippet"></div></td>
|
554
|
+
</tr>
|
555
|
+
</table>
|
556
|
+
</file>
|
557
|
+
<file name="protractor.js" type="protractor">
|
558
|
+
it('should linkify the snippet with urls', function() {
|
559
|
+
expect(element(by.id('linky-filter')).element(by.binding('snippet | linky')).getText()).
|
560
|
+
toBe('Pretty text with some links: http://angularjs.org/, us@somewhere.org, ' +
|
561
|
+
'another@somewhere.org, and one more: ftp://127.0.0.1/.');
|
562
|
+
expect(element.all(by.css('#linky-filter a')).count()).toEqual(4);
|
563
|
+
});
|
564
|
+
|
565
|
+
it('should not linkify snippet without the linky filter', function() {
|
566
|
+
expect(element(by.id('escaped-html')).element(by.binding('snippet')).getText()).
|
567
|
+
toBe('Pretty text with some links: http://angularjs.org/, mailto:us@somewhere.org, ' +
|
568
|
+
'another@somewhere.org, and one more: ftp://127.0.0.1/.');
|
569
|
+
expect(element.all(by.css('#escaped-html a')).count()).toEqual(0);
|
570
|
+
});
|
571
|
+
|
572
|
+
it('should update', function() {
|
573
|
+
element(by.model('snippet')).clear();
|
574
|
+
element(by.model('snippet')).sendKeys('new http://link.');
|
575
|
+
expect(element(by.id('linky-filter')).element(by.binding('snippet | linky')).getText()).
|
576
|
+
toBe('new http://link.');
|
577
|
+
expect(element.all(by.css('#linky-filter a')).count()).toEqual(1);
|
578
|
+
expect(element(by.id('escaped-html')).element(by.binding('snippet')).getText())
|
579
|
+
.toBe('new http://link.');
|
580
|
+
});
|
581
|
+
|
582
|
+
it('should work with the target property', function() {
|
583
|
+
expect(element(by.id('linky-target')).
|
584
|
+
element(by.binding("snippetWithTarget | linky:'_blank'")).getText()).
|
585
|
+
toBe('http://angularjs.org/');
|
586
|
+
expect(element(by.css('#linky-target a')).getAttribute('target')).toEqual('_blank');
|
587
|
+
});
|
588
|
+
</file>
|
589
|
+
</example>
|
590
|
+
*/
|
591
|
+
angular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) {
|
592
|
+
var LINKY_URL_REGEXP =
|
593
|
+
/((ftp|https?):\/\/|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s.;,(){}<>]/,
|
594
|
+
MAILTO_REGEXP = /^mailto:/;
|
595
|
+
|
596
|
+
return function(text, target) {
|
597
|
+
if (!text) return text;
|
598
|
+
var match;
|
599
|
+
var raw = text;
|
600
|
+
var html = [];
|
601
|
+
var url;
|
602
|
+
var i;
|
603
|
+
while ((match = raw.match(LINKY_URL_REGEXP))) {
|
604
|
+
// We can not end in these as they are sometimes found at the end of the sentence
|
605
|
+
url = match[0];
|
606
|
+
// if we did not match ftp/http/mailto then assume mailto
|
607
|
+
if (match[2] == match[3]) url = 'mailto:' + url;
|
608
|
+
i = match.index;
|
609
|
+
addText(raw.substr(0, i));
|
610
|
+
addLink(url, match[0].replace(MAILTO_REGEXP, ''));
|
611
|
+
raw = raw.substring(i + match[0].length);
|
612
|
+
}
|
613
|
+
addText(raw);
|
614
|
+
return $sanitize(html.join(''));
|
615
|
+
|
616
|
+
function addText(text) {
|
617
|
+
if (!text) {
|
618
|
+
return;
|
619
|
+
}
|
620
|
+
html.push(sanitizeText(text));
|
621
|
+
}
|
622
|
+
|
623
|
+
function addLink(url, text) {
|
624
|
+
html.push('<a ');
|
625
|
+
if (angular.isDefined(target)) {
|
626
|
+
html.push('target="');
|
627
|
+
html.push(target);
|
628
|
+
html.push('" ');
|
629
|
+
}
|
630
|
+
html.push('href="');
|
631
|
+
html.push(url);
|
632
|
+
html.push('">');
|
633
|
+
addText(text);
|
634
|
+
html.push('</a>');
|
635
|
+
}
|
636
|
+
};
|
637
|
+
}]);
|
638
|
+
|
639
|
+
|
640
|
+
})(window, window.angular);
|