Skip to content

Commit 20e1c55

Browse files
author
nfrasser
committed
Delete undefined options from hash provided by jQuery plugin
Should fix bug from #24
1 parent 0f8cce2 commit 20e1c55

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

dist/jquery.linkify.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Made by SoapBox Innovations, Inc.
77
* Under MIT License
88
*/
9-
!function($, window, document, undefined) {
9+
!function($, window, document) {
1010
"use strict";
1111
function Linkified(element, options) {
1212
this._defaults = defaults, this.element = element, this.setOptions(options), this.init();
@@ -73,11 +73,12 @@
7373
}, $.fn.linkify.Constructor = Linkified, $(window).on("load", function() {
7474
$("[data-linkify]").each(function() {
7575
var $target, $this = $(this), target = $this.attr("data-linkify"), options = {
76-
tagName: $this.attr("data-linkify-tagname") || undefined,
77-
newLine: $this.attr("data-linkify-newline") || undefined,
78-
target: $this.attr("data-linkify-target") || undefined,
79-
linkClass: $this.attr("data-linkify-linkclass") || undefined
76+
tagName: $this.attr("data-linkify-tagname"),
77+
newLine: $this.attr("data-linkify-newline"),
78+
target: $this.attr("data-linkify-target"),
79+
linkClass: $this.attr("data-linkify-linkclass")
8080
};
81+
for (var option in options) "undefined" == typeof options[option] && delete options[option];
8182
$target = "this" === target ? $this : $this.find(target), $target.linkify(options);
8283
});
8384
}), $("body").on("click", ".linkified", function() {

dist/jquery.linkify.min.js

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

src/jquery.linkify.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,19 @@ $(window).on('load', function () {
3333
$target,
3434
target = $this.attr('data-linkify'),
3535
options = {
36-
tagName: $this.attr('data-linkify-tagname') || undefined,
37-
newLine: $this.attr('data-linkify-newline') || undefined,
38-
target: $this.attr('data-linkify-target') || undefined,
39-
linkClass: $this.attr('data-linkify-linkclass') || undefined
36+
tagName: $this.attr('data-linkify-tagname'),
37+
newLine: $this.attr('data-linkify-newline'),
38+
target: $this.attr('data-linkify-target'),
39+
linkClass: $this.attr('data-linkify-linkclass')
4040
};
4141

42+
// Delete undefined options
43+
for (var option in options) {
44+
if (typeof options[option] === 'undefined') {
45+
delete options[option];
46+
}
47+
}
48+
4249
$target = target === 'this' ? $this : $this.find(target);
4350
$target.linkify(options);
4451

0 commit comments

Comments
 (0)