Skip to content

Commit eb66d3f

Browse files
author
nfrasser
committed
Fixed jQuery interface build step
All seems to be working for now!
1 parent 6308e2c commit eb66d3f

File tree

5 files changed

+29
-9
lines changed

5 files changed

+29
-9
lines changed

gulpfile.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ gulp.task('build-interfaces', ['babel-amd'], function () {
108108
var interface, interfaces = [
109109
'string',
110110
'element',
111-
// ['element', 'jquery'] // jQuery interface requires both element and jquery
111+
['element', 'jquery'] // jQuery interface requires both element and jquery
112112
];
113113

114114
var files = {js: null, amd: null};
@@ -122,8 +122,8 @@ gulp.task('build-interfaces', ['babel-amd'], function () {
122122
files.js = [];
123123
files.amd = [];
124124
for (var j = 0; j < interface.length; j++) {
125-
files.js.push('src/linkify-' + interface[i] + '.js');
126-
files.amd.push('build/amd/linkify-' + interface[i] + '.js');
125+
files.js.push('src/linkify-' + interface[j] + '.js');
126+
files.amd.push('build/amd/linkify-' + interface[j] + '.js');
127127
}
128128

129129
// The last dependency is the name of the interface
@@ -140,16 +140,16 @@ gulp.task('build-interfaces', ['babel-amd'], function () {
140140
modules: 'ignore',
141141
format: babelformat
142142
}))
143-
.pipe(wrap({src: 'templates/linkify-' + interface + '.js'}))
144143
.pipe(concat('linkify-' + interface + '.js'))
144+
.pipe(wrap({src: 'templates/linkify-' + interface + '.js'}))
145145
.pipe(gulp.dest('build'));
146146

147147
streams.push(stream);
148148

149149
// AMD interface
150150
stream = gulp.src(files.amd)
151-
.pipe(wrap({src: 'templates/linkify-' + interface + '.amd.js'}))
152151
.pipe(concat('linkify-' + interface + '.amd.js'))
152+
.pipe(wrap({src: 'templates/linkify-' + interface + '.amd.js'}))
153153
.pipe(gulp.dest('build'));
154154

155155
streams.push(stream);

src/linkify-element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function linkifyElementHelper(element, opts, doc) {
8585
case TXT_NODE:
8686

8787
let
88-
str = childElement.nodeValue,
88+
str = childElement.nodeValue.replace(/^\s+|\s+$/g, ''), // trim
8989
tokens = tokenize(str);
9090
children.push(...tokensToNodes(tokens, opts, doc));
9191

templates/linkify-jquery.amd.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<%= contents %>
2+
require(['jquery', 'linkify-jquery'], function ($, apply) {
3+
if (typeof $.fn.linkify !== 'function') {
4+
apply($);
5+
}
6+
});

templates/linkify-jquery.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
;(function (jQuery, linkify) {
2+
"use strict";
3+
var tokenize = linkify.tokenize, options = linkify.options;
4+
<%= contents %>
5+
window.linkifyElement = linkifyElement;
6+
})(window.jQuery, window.linkify);

test/index.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,22 @@
88
</body>
99
<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
1010
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.15/require.js" data-main="build/amd/linkify"></script>
11-
<script src="build/linkify-string.amd.js"></script>
12-
<script src="build/linkify-element.amd.js"></script>
11+
<script>
12+
/* global define */
13+
define('jquery', ['exports', 'module'], function (exports, module) {
14+
module.exports = window.jQuery;
15+
});
16+
</script>
17+
<script src="build/linkify.amd.js"></script>
1318
<script src="build/linkify-plugin-hashtag.amd.js"></script>
14-
<p id="yolo" data-linkify="this" data-linkify-tagname="span">
19+
<script src="build/linkify-string.amd.js"></script>
20+
<script src="build/linkify-jquery.amd.js"></script>
21+
<p id="yolo" data-linkify="this" data-linkify-tagname="b">
1522
You let's get all up in the
1623
http://element.co/?wat=this and the #swag
1724
</p>
1825
<script>
26+
/* global require */
1927
require(['linkify'], function (linkify) {
2028
console.log(linkify.find('google.com'));
2129
});

0 commit comments

Comments
 (0)