[livejournal] r22303: LJSUP-12631: Implement widget initializa...
Committer: anazarov
LJSUP-12631: Implement widget initialization framework.U trunk/htdocs/js/basic.js
Modified: trunk/htdocs/js/basic.js
===================================================================
--- trunk/htdocs/js/basic.js 2012-06-21 14:55:10 UTC (rev 22302)
+++ trunk/htdocs/js/basic.js 2012-06-22 06:54:36 UTC (rev 22303)
@@ -712,7 +712,7 @@
(function () {
var widgets = {},
- unique = 1,
+ unique = 0,
baseClass = 'lj-widget',
selector = '.' + baseClass;
@@ -746,16 +746,26 @@
*/
LJ.UI.initWidget = function (node, force) {
var widget = node.data('widget'),
+ options = node.data('widget-options'),
bootstrap = node.data('bootstrap') || null;
+
if (node.attr('data-widget-id')) {
/* Widget already has unique id */
return;
}
+ if (typeof options !== 'object') {
+ if (options) {
+ LJ.console.warn('Invalid options string: ' + options);
+ }
+
+ options = {};
+ }
+
if (force) {
if (typeof jQuery.fn[widget] === 'function') {
- jQuery.fn[widget].apply(node);
+ jQuery.fn[widget].apply(node, [options]);
} else {
LJ.console.warn('Widget ' + widget + ' was not loaded');
return;
@@ -765,6 +775,7 @@
widgets[++unique] = {
ready: !!force,
entryPoint: bootstrap,
+ options: options,
name: widget,
node: node
};
@@ -823,7 +834,7 @@
fn = jQuery.fn[widget.name];
if (typeof fn === 'function') {
- fn.apply(widget.node);
+ fn.apply(widget.node, [widget.options]);
widget.ready = true;
} else {
LJ.console.warn('Widget ' + widget.name + ' was not loaded');
