I'm trying to write a simple jquery plugin but code gets huge and messy below is a portion to explain the idea I'm trying to achieve.
(function( $ ) {
$.fn.pageBuilder = function( options ) {
var lb = $.extend({
self: this,
modal_edit: $("#vz_edit_modal"),
modal_delete: $("#vz_delete_modal"),
onSlideElements: function() {},
onInsertElement: function() {},
onSaveElement: function() {},
}, options);
// Disabling all link clicks default action within page layout builder
this.on( 'click', 'a', function(event) {
event.preventDefault();
});
// Changing class of layout builder elements while dragging for cursor change purposes
this.on('mousedown', '.element .inner', function(){
$(this).addClass('grabbing');
}).on('mouseup', '.element .inner', function(){
$(this).removeClass('grabbing');
});
};
}( jQuery ));
So this code is core of plugin and want to keep in jquery.myplugin.js and now when I try to create a new file jquery.myplugin.elements.js and add this code:
(function( $ ){
$.extend($.fn, {
pageBuilder: function( options ){
// Extended action
this.find(".element a").on('click', function() {
console.log( lb.modal_edit ); // Access to core plugin option
});
}
});
})( jQuery );
The matter is I can't get the extended plugin working, the this.find(".element a").on('click', function() { doesn't work, I mean console.log is never fired weather can't get access to lb.modal_edit or extending in wrong way...
Also I need both of functionality to work the core plugin and the extended one, extending plugin shouldn't deactivate core functions..
Thanks in advance.