Event fired an extra time on each subsequent request.
Hi,
I'm pretty new to plugin development (stared the weekend) and was wondering if someone could tell me why the following event will occur one more time it did the last time on each subsequent time it's being fired?
It's pretty much just opening a modal which will allow the user to create a new record. Upon close, the callback in the client get called that will update the list on the calling page with the new record.
Plugin:
- (function ($) {
- $.fn.extend({
- addCustomService: function (options, callback) {
- var defaults = {
- saveButton: $('#btnSave'),
- url: ''
- };
- options = $.extend(defaults, options);
- var url = options["url"];
- var saveButton = options["saveButton"];
- return this.each(function () {
- $('#modalContent', this).load(url);
- $(this).modal('show');
- saveButton.live("click", function () {
- callback.call(this, 123, "new name");
- });
- });
- }
- });
- })(jQuery);
Parent Page Script:
- $(document).ready(function() {
- $('#template_row').hide();
- $('#addCustomService').live("click", function(event) {
- $('#modalTemplate').addCustomService(
- {
- saveButton: $('#btnSave'),
- url: '..to be set...'
- },
- function(id, name) {
- var clone = $('#template_row').clone();
- clone.appendTo('#selectedServiceTable');
- $('td span', clone).text(name);
- var box = $('input:checkbox', clone);
- box.attr('checked', 'checked');
- box.attr('value', id);
- clone.show();
- }
- );
- event.preventDefault();
- });
- });
The Modal:
- <!-- ***** Modal Template ***** -->
- <div id="modalTemplate" class="modal hide fade">
- <div class="modal-header">
- <button type="button" class="close" data-dismiss="modal">×</button>
- <h4>....add own service....</h4>
- </div>
- <div class="modal-body" id="modalContent"></div>
- <div class="modal-footer">
- <a id="btnCancel" href="#" class="btn" data-dismiss="modal" >Close</a>
- <a id="btnSave" href="#" class="btn" data-dismiss="modal" >Save</a>
- </div>
- </div>
- <!-- ***** End Modal ***** -->
Also, any critic about the way I'm going about is welcome. Like I said, I just started.