Skip to content

Commit c73be50

Browse files
author
Caden Lovelace
committed
Exclude diff.js from build as it pollutes global namespace.
1 parent 0c1b234 commit c73be50

File tree

3 files changed

+3
-165
lines changed

3 files changed

+3
-165
lines changed

angular-diff.js

100755100644
Lines changed: 0 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -176,164 +176,3 @@ angular.module('diff', [])
176176
return $sce.trustAsHtml(diffString(input, match));
177177
};
178178
});
179-
180-
/*
181-
* Javascript Diff Algorithm
182-
* By John Resig (http://ejohn.org/)
183-
* Modified by Chu Alan "sprite"
184-
*
185-
* Released under the MIT license.
186-
*
187-
* More Info:
188-
* http://ejohn.org/projects/javascript-diff-algorithm/
189-
*/
190-
191-
function escape(s) {
192-
var n = s;
193-
n = n.replace(/&/g, "&");
194-
n = n.replace(/</g, "&lt;");
195-
n = n.replace(/>/g, "&gt;");
196-
n = n.replace(/"/g, "&quot;");
197-
198-
return n;
199-
}
200-
201-
function diffString( o, n ) {
202-
o = o.replace(/\s+$/, '');
203-
n = n.replace(/\s+$/, '');
204-
205-
var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/) );
206-
var str = "";
207-
208-
var oSpace = o.match(/\s+/g);
209-
if (oSpace == null) {
210-
oSpace = ["\n"];
211-
} else {
212-
oSpace.push("\n");
213-
}
214-
var nSpace = n.match(/\s+/g);
215-
if (nSpace == null) {
216-
nSpace = ["\n"];
217-
} else {
218-
nSpace.push("\n");
219-
}
220-
221-
if (out.n.length == 0) {
222-
for (var i = 0; i < out.o.length; i++) {
223-
str += '<del>' + escape(out.o[i]) + oSpace[i] + "</del>";
224-
}
225-
} else {
226-
if (out.n[0].text == null) {
227-
for (n = 0; n < out.o.length && out.o[n].text == null; n++) {
228-
str += '<del>' + escape(out.o[n]) + oSpace[n] + "</del>";
229-
}
230-
}
231-
232-
for ( var i = 0; i < out.n.length; i++ ) {
233-
if (out.n[i].text == null) {
234-
str += '<ins>' + escape(out.n[i]) + nSpace[i] + "</ins>";
235-
} else {
236-
var pre = "";
237-
238-
for (n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) {
239-
pre += '<del>' + escape(out.o[n]) + oSpace[n] + "</del>";
240-
}
241-
str += " " + out.n[i].text + nSpace[i] + pre;
242-
}
243-
}
244-
}
245-
246-
return str;
247-
}
248-
249-
function randomColor() {
250-
return "rgb(" + (Math.random() * 100) + "%, " +
251-
(Math.random() * 100) + "%, " +
252-
(Math.random() * 100) + "%)";
253-
}
254-
function diffString2( o, n ) {
255-
o = o.replace(/\s+$/, '');
256-
n = n.replace(/\s+$/, '');
257-
258-
var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/) );
259-
260-
var oSpace = o.match(/\s+/g);
261-
if (oSpace == null) {
262-
oSpace = ["\n"];
263-
} else {
264-
oSpace.push("\n");
265-
}
266-
var nSpace = n.match(/\s+/g);
267-
if (nSpace == null) {
268-
nSpace = ["\n"];
269-
} else {
270-
nSpace.push("\n");
271-
}
272-
273-
var os = "";
274-
var colors = new Array();
275-
for (var i = 0; i < out.o.length; i++) {
276-
colors[i] = randomColor();
277-
278-
if (out.o[i].text != null) {
279-
os += '<span style="background-color: ' +colors[i]+ '">' +
280-
escape(out.o[i].text) + oSpace[i] + "</span>";
281-
} else {
282-
os += "<del>" + escape(out.o[i]) + oSpace[i] + "</del>";
283-
}
284-
}
285-
286-
var ns = "";
287-
for (var i = 0; i < out.n.length; i++) {
288-
if (out.n[i].text != null) {
289-
ns += '<span style="background-color: ' +colors[out.n[i].row]+ '">' +
290-
escape(out.n[i].text) + nSpace[i] + "</span>";
291-
} else {
292-
ns += "<ins>" + escape(out.n[i]) + nSpace[i] + "</ins>";
293-
}
294-
}
295-
296-
return { o : os , n : ns };
297-
}
298-
299-
function diff( o, n ) {
300-
var ns = new Object();
301-
var os = new Object();
302-
303-
for ( var i = 0; i < n.length; i++ ) {
304-
if ( ns[ n[i] ] == null )
305-
ns[ n[i] ] = { rows: new Array(), o: null };
306-
ns[ n[i] ].rows.push( i );
307-
}
308-
309-
for ( var i = 0; i < o.length; i++ ) {
310-
if ( os[ o[i] ] == null )
311-
os[ o[i] ] = { rows: new Array(), n: null };
312-
os[ o[i] ].rows.push( i );
313-
}
314-
315-
for ( var i in ns ) {
316-
if ( ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1 ) {
317-
n[ ns[i].rows[0] ] = { text: n[ ns[i].rows[0] ], row: os[i].rows[0] };
318-
o[ os[i].rows[0] ] = { text: o[ os[i].rows[0] ], row: ns[i].rows[0] };
319-
}
320-
}
321-
322-
for ( var i = 0; i < n.length - 1; i++ ) {
323-
if ( n[i].text != null && n[i+1].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null &&
324-
n[i+1] == o[ n[i].row + 1 ] ) {
325-
n[i+1] = { text: n[i+1], row: n[i].row + 1 };
326-
o[n[i].row+1] = { text: o[n[i].row+1], row: i + 1 };
327-
}
328-
}
329-
330-
for ( var i = n.length - 1; i > 0; i-- ) {
331-
if ( n[i].text != null && n[i-1].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null &&
332-
n[i-1] == o[ n[i].row - 1 ] ) {
333-
n[i-1] = { text: n[i-1], row: n[i].row - 1 };
334-
o[n[i].row-1] = { text: o[n[i].row-1], row: i - 1 };
335-
}
336-
}
337-
338-
return { o: o, n: n };
339-
}

angular-diff.min.js

100755100644
Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ gulp.task('karma', function() {
2626

2727
/* Build a concat and minified version of the source files */
2828
gulp.task('build:concat', function () {
29-
return gulp.src('src/*.js')
29+
return gulp.src('src/diff.filter.js')
3030
.pipe(concat('angular-diff.js'))
3131
.pipe(gulp.dest('.'));
3232
});
3333

3434
gulp.task('build:minify', function () {
35-
return gulp.src('src/*.js')
35+
return gulp.src('src/diff.filter.js')
3636
.pipe(ngmin())
3737
.pipe(uglify())
3838
.pipe(concat('angular-diff.min.js'))

0 commit comments

Comments
 (0)