Reputation: 131
This is a part of my javascript taken from a jquery plugin. This plugin let me to make a div widgets with remote html content loaded inside and a tools header with a refresh button that reload the remote content. I need to call a _loadAjaxFile function for reload content from a others functions outside this plugin (for example a button) but I can't to undestand if this is possible and how.
(function ($, window, document, undefined) {
function Plugin(element, options) {
this.obj = $(element);
this.o = $.extend({}, $.fn[pluginName].defaults, options);
this.objId = this.obj.attr('id');
this.pwCtrls = '.jarviswidget-ctrls';
this.widget = this.obj.find(this.o.widgets);
this.toggleClass = this.o.toggleClass.split('|');
this.editClass = this.o.editClass.split('|');
this.fullscreenClass = this.o.fullscreenClass.split('|');
this.customClass = this.o.customClass.split('|');
this.storage = {enabled: this.o.localStorage};
this.initialized = false;
this.init();
}
Plugin.prototype = {
_loadAjaxFile: function (awidget, file, loader) {
var self = this;
awidget.find('.widget-body')
.load(file, function (response, status, xhr) {
var $this = $(this);
if (status == "error") {
$this.html('<h4 class="alert alert-danger">' + self.o.labelError + '<b> ' +
xhr.status + " " + xhr.statusText + '</b></h4>');
}
if (status == "success") {
var aPalceholder = awidget.find(self.o.timestampPlaceholder);
if (aPalceholder.length) {
aPalceholder.html(self._getPastTimestamp(new Date()));
}
if (typeof self.o.afterLoad == 'function') {
self.o.afterLoad.call(this, awidget);
}
}
self = null;
});
this._runLoaderWidget(loader);
},
}
})(jQuery, window, document);
This is the complete code of the plugin
Upvotes: 0
Views: 104
Reputation: 1074979
The _
on it is the author telling you not to call it directly. It doesn't mean you can't, but you shouldn't. You'd be using internals that aren't meant to be used directly.
I assume what you've quoted is incomplete, but the fact that that function is on Plugin.prototype
means you would be able to call it on plugin instances. How you get an instance of the plugin to call it on (and whether you can) depends on the plugin (look in its documentation); it may well never expose an instance directly to your code, instead just making its features available via the name it adds to jQuery.fn
.
Upvotes: 3