@g2crowd/widget
Advanced tools
Comparing version 1.1.5 to 1.2.0
@@ -65,12 +65,12 @@ // @format | ||
const strategies = initiationStrategies({ | ||
nextTick(pluginFn, $$, options, ready) { | ||
return window.setTimeout(() => pluginFn.call($$, options, ready), 0); | ||
nextTick(pluginFn, $$) { | ||
return window.setTimeout(() => pluginFn(), 0); | ||
}, | ||
immediate(pluginFn, $$, options, ready) { | ||
return pluginFn.call($$, options, ready) || {}; | ||
immediate(pluginFn, $$) { | ||
return pluginFn() || {}; | ||
}, | ||
hover(pluginFn, $$, options, ready) { | ||
return $$.one('mouseover', () => pluginFn.call($$, options, ready)); | ||
hover(pluginFn, $$) { | ||
return $$.one('mouseover', () => pluginFn()); | ||
} | ||
@@ -105,3 +105,15 @@ | ||
const loadWidget = function ($$, name, data) { | ||
const wrapPlugin = function wrapPlugin(name, pluginFn, $$) { | ||
const ready = function ready() { | ||
emit($$, 'vvidget:initialized'); | ||
}; | ||
return function () { | ||
const pluginName = camelize(name); | ||
const options = $.extend({}, pluginFn.defaults, extractOptions($$.data(), pluginName)); | ||
pluginFn.call($$, options, ready); | ||
}; | ||
}; | ||
const loadWidget = function ($$, name) { | ||
if (name) { | ||
@@ -115,11 +127,7 @@ const existingPlugin = $$.data(`vvidget:${name}`); | ||
const ready = () => { | ||
emit($$, 'vvidget:initialized'); | ||
}; | ||
const wrapped = wrapPlugin(name, pluginFn, $$); | ||
if (!existingPlugin) { | ||
const pluginName = camelize(name); | ||
const options = $.extend({}, pluginFn.defaults, extractOptions(data, pluginName)); | ||
widgetQueue.add(() => { | ||
strategies.get(pluginFn.init)(pluginFn, $$, options, ready); | ||
strategies.get(pluginFn.init)(wrapped, $$); | ||
}); | ||
@@ -136,3 +144,3 @@ widgetQueue.flush(); | ||
const names = `${$$.data(data) || ''} ${$$.attr(attr) || ''}`; | ||
names.split(' ').forEach(name => loadWidget($$, name, $$.data())); | ||
names.split(' ').forEach(name => loadWidget($$, name)); | ||
}); | ||
@@ -139,0 +147,0 @@ }; |
@@ -225,13 +225,13 @@ import 'core-js/modules/es6.array.find'; | ||
var strategies = initiationStrategies({ | ||
nextTick: function nextTick(pluginFn, $$, options, ready) { | ||
nextTick: function nextTick(pluginFn, $$) { | ||
return window.setTimeout(function () { | ||
return pluginFn.call($$, options, ready); | ||
return pluginFn(); | ||
}, 0); | ||
}, | ||
immediate: function immediate(pluginFn, $$, options, ready) { | ||
return pluginFn.call($$, options, ready) || {}; | ||
immediate: function immediate(pluginFn, $$) { | ||
return pluginFn() || {}; | ||
}, | ||
hover: function hover(pluginFn, $$, options, ready) { | ||
hover: function hover(pluginFn, $$) { | ||
return $$.one('mouseover', function () { | ||
return pluginFn.call($$, options, ready); | ||
return pluginFn(); | ||
}); | ||
@@ -267,3 +267,15 @@ } | ||
var loadWidget = function loadWidget($$, name, data) { | ||
var wrapPlugin = function wrapPlugin(name, pluginFn, $$) { | ||
var ready = function ready() { | ||
emit($$, 'vvidget:initialized'); | ||
}; | ||
return function () { | ||
var pluginName = camelize(name); | ||
var options = $.extend({}, pluginFn.defaults, extractOptions($$.data(), pluginName)); | ||
pluginFn.call($$, options, ready); | ||
}; | ||
}; | ||
var loadWidget = function loadWidget($$, name) { | ||
if (name) { | ||
@@ -277,11 +289,7 @@ var existingPlugin = $$.data("vvidget:".concat(name)); | ||
var ready = function ready() { | ||
emit($$, 'vvidget:initialized'); | ||
}; | ||
var wrapped = wrapPlugin(name, pluginFn, $$); | ||
if (!existingPlugin) { | ||
var pluginName = camelize(name); | ||
var options = $.extend({}, pluginFn.defaults, extractOptions(data, pluginName)); | ||
widgetQueue.add(function () { | ||
strategies.get(pluginFn.init)(pluginFn, $$, options, ready); | ||
strategies.get(pluginFn.init)(wrapped, $$); | ||
}); | ||
@@ -299,3 +307,3 @@ widgetQueue.flush(); | ||
names.split(' ').forEach(function (name) { | ||
return loadWidget($$, name, $$.data()); | ||
return loadWidget($$, name); | ||
}); | ||
@@ -302,0 +310,0 @@ }); |
{ | ||
"name": "@g2crowd/widget", | ||
"description": "Rails-friendly jquery plugin wrapper", | ||
"version": "1.1.5", | ||
"version": "1.2.0", | ||
"license": "MIT", | ||
@@ -27,3 +27,4 @@ "files": [ | ||
"jest": "^24.8.0", | ||
"npm": "^6.8.0" | ||
"npm": "^6.8.0", | ||
"prettier": "^1.18.2" | ||
}, | ||
@@ -30,0 +31,0 @@ "private": false, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13836
465
9