| author | ymh <ymh.work@gmail.com> |
| Tue, 22 Oct 2024 07:03:54 +0200 | |
| changeset 1076 | 510fd2a482f4 |
| parent 1072 | ac1eacb3aa33 |
| permissions | -rw-r--r-- |
| 998 | 1 |
/* widgets-container/metadataplayer.js - initialization and configuration of the widgets |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
2 |
*/ |
| 998 | 3 |
|
4 |
/* The Metadataplayer Object, single point of entry, replaces IriSP.init_player */ |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
5 |
import _ from "lodash"; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
6 |
import jQuery from "jquery"; |
| 1000 | 7 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
8 |
export default function (ns) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
9 |
var formerJQuery, formerUnderscore, former$; |
| 1000 | 10 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
11 |
var Metadataplayer = (ns.Metadataplayer = function (config) { |
| 1000 | 12 |
ns.log("IriSP.Metadataplayer constructor"); |
13 |
for (var key in ns.guiDefaults) { |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
14 |
if (ns.guiDefaults.hasOwnProperty(key) && !config.hasOwnProperty(key)) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
15 |
config[key] = ns.guiDefaults[key]; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
16 |
} |
| 998 | 17 |
} |
18 |
var _container = document.getElementById(config.container); |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
19 |
_container.innerHTML = |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
20 |
'<h3 class="Ldt-Loader">Loading... Chargement...</h3>'; |
| 1000 | 21 |
this.sourceManager = new ns.Model.Directory(); |
| 998 | 22 |
this.config = config; |
23 |
this.__events = {}; |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
24 |
//this.loadLibs(); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
25 |
this.onLibsLoaded(); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
26 |
}); |
| 998 | 27 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
28 |
Metadataplayer.prototype.toString = function () { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
29 |
return "Metadataplayer in #" + this.config.container; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
30 |
}; |
| 998 | 31 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
32 |
Metadataplayer.prototype.on = function (_event, _callback) { |
| 998 | 33 |
if (typeof this.__events[_event] === "undefined") { |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
34 |
this.__events[_event] = []; |
| 998 | 35 |
} |
36 |
this.__events[_event].push(_callback); |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
37 |
}; |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
38 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
39 |
Metadataplayer.prototype.trigger = function (_event, _data) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
40 |
var _element = this; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
41 |
_(this.__events[_event]).each(function (_callback) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
42 |
_callback.call(_element, _data); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
43 |
}); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
44 |
}; |
| 998 | 45 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
46 |
Metadataplayer.prototype.onLibsLoaded = function () { |
| 1000 | 47 |
ns.log("IriSP.Metadataplayer.prototype.onLibsLoaded"); |
|
1065
77658c018e83
rollback fix + changed default jquery file to load as it seems to hotfix the jquery-ui/lab.js bug
durandn
parents:
1063
diff
changeset
|
48 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
49 |
// if ( |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
50 |
// typeof jQuery === "undefined" && |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
51 |
// typeof window.jQuery !== "undefined" |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
52 |
// ) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
53 |
// jQuery = window.jQuery; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
54 |
// if (former$ || formerJQuery) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
55 |
// window.jQuery.noConflict(formerJQuery); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
56 |
// } |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
57 |
// } |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
58 |
// if (typeof _ === "undefined" && typeof window._ !== "undefined") { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
59 |
// _ = window._; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
60 |
// if (formerUnderscore) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
61 |
// _.noConflict(); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
62 |
// } |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
63 |
// } |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
64 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
65 |
this.$ = jQuery("#" + this.config.container); |
| 998 | 66 |
this.$.css({ |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
67 |
width: this.config.width, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
68 |
clear: "both", |
| 998 | 69 |
}); |
70 |
if (typeof this.config.height !== "undefined") { |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
71 |
this.$.css("height", this.config.height); |
| 998 | 72 |
} |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
73 |
|
| 998 | 74 |
this.widgets = []; |
75 |
var _this = this; |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
76 |
_(this.config.widgets).each(function (widgetconf, key) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
77 |
_this.widgets.push(null); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
78 |
_this.loadWidget(widgetconf, function (widget) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
79 |
_this.widgets[key] = widget; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
80 |
if (widget.isLoaded()) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
81 |
_this.trigger("widget-loaded"); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
82 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
83 |
}); |
| 998 | 84 |
}); |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
85 |
this.$.find(".Ldt-Loader").detach(); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
86 |
|
| 998 | 87 |
this.widgetsLoaded = false; |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
88 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
89 |
this.on("widget-loaded", function () { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
90 |
if (_this.widgetsLoaded) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
91 |
return; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
92 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
93 |
var isloaded = !_(_this.widgets).some(function (w) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
94 |
return !(w && w.isLoaded()); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
95 |
}); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
96 |
if (isloaded) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
97 |
_this.widgetsLoaded = true; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
98 |
_this.trigger("widgets-loaded"); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
99 |
} |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
100 |
}); |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
101 |
}; |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
102 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
103 |
Metadataplayer.prototype.loadLocalAnnotations = function ( |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
104 |
localsourceidentifier |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
105 |
) { |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
106 |
if (this.localSource === undefined) |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
107 |
this.localSource = this.sourceManager.newLocalSource({ |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
108 |
serializer: IriSP.serializers["ldt_localstorage"], |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
109 |
}); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
110 |
// Load current local annotations |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
111 |
if (localsourceidentifier) { |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
112 |
// Allow to override localsourceidentifier when necessary (usually at init time) |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
113 |
this.localSource.identifier = localsourceidentifier; |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
114 |
} |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
115 |
this.localSource.deSerialize( |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
116 |
window.localStorage[this.localSource.identifier] || "[]" |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
117 |
); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
118 |
return this.localSource; |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
119 |
}; |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
120 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
121 |
Metadataplayer.prototype.saveLocalAnnotations = function () { |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
122 |
// Save annotations back to localstorage |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
123 |
window.localStorage[this.localSource.identifier] = |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
124 |
this.localSource.serialize(); |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
125 |
// Merge modifications into widget source |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
126 |
// this.source.merge(this.localSource); |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
127 |
}; |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
128 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
129 |
Metadataplayer.prototype.addLocalAnnotation = function (a) { |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
130 |
this.loadLocalAnnotations(); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
131 |
this.localSource.getAnnotations().push(a); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
132 |
this.saveLocalAnnotations(); |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
133 |
}; |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
134 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
135 |
Metadataplayer.prototype.deleteLocalAnnotation = function (ident) { |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
136 |
this.localSource.getAnnotations().removeId(ident, true); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
137 |
this.saveLocalAnnotations(); |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
138 |
}; |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
139 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
140 |
Metadataplayer.prototype.getLocalAnnotation = function (ident) { |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
141 |
this.loadLocalAnnotations(); |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
142 |
// We cannot use .getElement since it fetches |
|
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
143 |
// elements from the global Directory |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
144 |
return _.first( |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
145 |
_.filter(this.localSource.getAnnotations(), function (a) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
146 |
return a.id == ident; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
147 |
}) |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
148 |
); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
149 |
}; |
| 998 | 150 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
151 |
Metadataplayer.prototype.loadMetadata = function (_metadataInfo) { |
| 998 | 152 |
if (_metadataInfo.elementType === "source") { |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
153 |
return _metadataInfo; |
| 998 | 154 |
} |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
155 |
if ( |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
156 |
typeof _metadataInfo.serializer === "undefined" && |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
157 |
typeof _metadataInfo.format !== "undefined" |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
158 |
) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
159 |
_metadataInfo.serializer = ns.serializers[_metadataInfo.format]; |
| 998 | 160 |
} |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
161 |
if ( |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
162 |
typeof _metadataInfo.url !== "undefined" && |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
163 |
typeof _metadataInfo.serializer !== "undefined" |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
164 |
) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
165 |
return this.sourceManager.remoteSource(_metadataInfo); |
| 998 | 166 |
} else { |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
167 |
return this.sourceManager.newLocalSource(_metadataInfo); |
| 998 | 168 |
} |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
169 |
}; |
| 998 | 170 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
171 |
Metadataplayer.prototype.loadWidget = function (_widgetConfig, _callback) { |
| 998 | 172 |
/* Creating containers if needed */ |
173 |
if (typeof _widgetConfig.container === "undefined") { |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
174 |
var _divs = this.layoutDivs(_widgetConfig.type); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
175 |
_widgetConfig.container = _divs[0]; |
| 998 | 176 |
} |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
177 |
|
| 998 | 178 |
var _this = this; |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
179 |
|
| 1000 | 180 |
if (typeof ns.Widgets[_widgetConfig.type] !== "undefined") { |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
181 |
_.defer(function () { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
182 |
_callback(new ns.Widgets[_widgetConfig.type](_this, _widgetConfig)); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
183 |
}); |
| 998 | 184 |
} else { |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
185 |
ns.log("Widget type " + _widgetConfig.type + " Unkown !"); |
| 998 | 186 |
} |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
187 |
}; |
| 998 | 188 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
189 |
/** create a subdiv with an unique id, and a spacer div as well. |
| 998 | 190 |
@param widgetName the name of the widget. |
191 |
@return an array of the form [createdivId, spacerdivId]. |
|
192 |
*/ |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
193 |
Metadataplayer.prototype.layoutDivs = function (_name, _height) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
194 |
if (typeof _name === "undefined") { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
195 |
_name = ""; |
| 998 | 196 |
} |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
197 |
var newDiv = _.uniqueId(this.config.container + "_widget_" + _name + "_"), |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
198 |
spacerDiv = _.uniqueId("LdtPlayer_spacer_"), |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
199 |
divHtml = jQuery("<div>") |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
200 |
.attr("id", newDiv) |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
201 |
.css({ |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
202 |
width: this.config.width + "px", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
203 |
position: "relative", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
204 |
clear: "both", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
205 |
}), |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
206 |
spacerHtml = jQuery("<div>") |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
207 |
.attr("id", spacerDiv) |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
208 |
.css({ |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
209 |
width: this.config.width + "px", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
210 |
height: this.config.spacer_div_height + "px", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
211 |
position: "relative", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
212 |
clear: "both", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
213 |
}); |
| 998 | 214 |
if (typeof _height !== "undefined") { |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
215 |
divHtml.css("height", _height); |
| 998 | 216 |
} |
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
217 |
|
| 998 | 218 |
this.$.append(divHtml); |
219 |
this.$.append(spacerHtml); |
|
220 |
||
221 |
return [newDiv, spacerDiv]; |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
222 |
}; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1068
diff
changeset
|
223 |
} |
| 1000 | 224 |
|
|
1068
7623f9af9272
merge pull request #3 from O. Auber
ymh <ymh.work@gmail.com>
parents:
1065
diff
changeset
|
225 |
/* End of widgets-container/metadataplayer.js */ |