Skip to content

Commit

Permalink
feat: allow to pass settings object to the live initialization methods (
Browse files Browse the repository at this point in the history
#870)

* feat: allow to pass settings through live initialization methods

* chore: add demo page
  • Loading branch information
nd0ut authored Oct 13, 2021
1 parent 9cc459b commit b23d446
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions dummy/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
<li><a href="/dnd.html">d&amp;d</a></li>
<li><a href="/system.html">system dialog</a></li>
<li><a href="/debug-uploads.html">debug uploads</a></li>
<li><a href="/live.html">live</a></li>
</ul>
18 changes: 18 additions & 0 deletions dummy/live.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<meta charset="UTF-8">
<meta content="width=device-width,initial-scale=1" name="viewport"/>
<script src="./uploadcare.full.js"></script>
<script>
$ = uploadcare.jQuery;
jQuery = uploadcare.jQuery;
</script>

<input
type="text"
id="uploader"
hidden
/>

<script>
var $ = uploadcare.jQuery;
var widget = uploadcare.MultipleWidget("#uploader", {multiple: true, publicKey: 'demopublickey'});
</script>
19 changes: 11 additions & 8 deletions src/widget/live.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ const _initialize = function (targets) {
return results
}

const SingleWidget = function (el) {
return initializeWidget(el, WidgetClass)
const SingleWidget = function (el, settings) {
return initializeWidget(el, settings, WidgetClass)
}

const MultipleWidget = function (el) {
return initializeWidget(el, MultipleWidgetClass)
const MultipleWidget = function (el, settings) {
return initializeWidget(el, settings, MultipleWidgetClass)
}

const Widget = function (el) {
return initializeWidget(el)
const Widget = function (el, settings) {
return initializeWidget(el, settings)
}

const initializeWidget = function (input, targetClass) {
const initializeWidget = function (input, settings = {}, targetClass) {
const inputArr = $(input)

if (inputArr.length === 0) {
Expand All @@ -61,7 +61,10 @@ const initializeWidget = function (input, targetClass) {

input = inputArr.eq(0)

const s = build(input.data())
const s = build({
...settings,
...input.data()
})
const Widget = s.multiple ? MultipleWidgetClass : WidgetClass

if (targetClass && Widget !== targetClass) {
Expand Down

0 comments on commit b23d446

Please sign in to comment.