Ready/Init event for Kendo Upload? -
we use mvc builders kendo upload, need this:
$("#someuploadid").data("kendoupload").setoptions({ //some options }); (i realize can set things via wrapper, there custom javascript need handle special cases.)
however, if put in doc.ready fail because doesn't locate kendoupload property. it's matter of timing in doc ready kendouploader still initializing , doesn't exist yet. can use settimeout wait second , work because gives kendo control time initialize, using settimeout in way hack , might not reliable.
usually libraries have sort of event signals control ready/initialized. haven't been able find documentation indicates similar construct kendoupload. how can determine when kendoupload ready?
unfortunately, there's no such event.
however, js generated mvc builders wrapped in jquery ready blocks, have put code needs access widget in jquery ready block below builder directive said widget.
this work since ready blocks executed sequentially , widget ready plugin method invoked (there's no async initialization).
you try implementing event yourself, e.g. creating initializer object:
var deferred = $.deferred(); var kendoinitializer = { widgets: [], total: 0, waitfor: function (name, number) { this.widgets[name] = number; this.total += number; }, deferred: deferred, promise: deferred.promise(), resolveone: function (name) { console.log(name, "initialized", this.total); this.removeone(name); if (this.total <= 0) { // resolve per widget type etc. this.deferred.resolve(); } }, removeone: function (name) { if (this.widgets.hasownproperty(name)) { this.widgets[name] -= 1; this.total -= 1; } } }; then making each widget register initializer:
kendo.ui.widget.fn.init = function (originalfn) { return function () { originalfn.apply(this, arguments); // mark 1 widget initialized; // pass this.options.name , resolve per widget type kendoinitializer.resolveone(this.options.name); }; }(kendo.ui.widget.fn.init); then use this:
kendoinitializer.waitfor("dropdownlist", 1); kendoinitializer.waitfor("window", 1); kendoinitializer.promise.done(function () { console.log("all widgets initialized"); }); this prototype requires declare number of widgets want wait for; there may way around that.
(demo)
Comments
Post a Comment