Last active
January 3, 2016 05:48
-
-
Save mwmaleks/8417846 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by mwmaleks on 14.01.14. | |
*/ | |
var MyModal = (function() { | |
/** | |
* sets the callBack function calls when modal is completely shown | |
* @param callBack | |
*/ | |
function onShownListener(callBack) { | |
$(this.$modal).on('shown.bs.modal', function() { | |
callBack(); | |
}); | |
} | |
/** | |
* sets the callBack function calls when modal is completely hidden | |
* @param callBack | |
*/ | |
function onHiddenListener(callBack) { | |
$(this.$modal).on('hidden.bs.modal', function() { | |
callBack(); | |
}); | |
} | |
/** | |
* row bootstrap modal constructor | |
* @param {object} modalOption - initial options to setup modal | |
* @param {String} [modalOption.$modal] - modals DOM id or jQuery object | |
* @param {String} [modalOption.$modalBody] - modals body DOM id or jQuery object | |
* @constructor | |
*/ | |
// var MyModal = function(options) { | |
// | |
// $.extend( true, this, options ); | |
// | |
// this.$modal = $(this.$modal || '#myModal'); | |
// this.$modalBody = $(this.$modalBody || '.modal-body'); | |
// | |
// }; | |
var MyModal = function(modalOption) { | |
var $elem, options, Modal; | |
Modal = $.fn.modal.Constructor; | |
$elem = $( modalOption ? modalOption.$modal || '#myModal' : '#myModal' ); | |
console.log($elem); | |
options = $.extend({}, Modal.DEFAULTS, $elem.data()); | |
// call father constructor | |
Modal.call(this, $elem, options); | |
this.$body =$( modalOption ? modalOption.$modalBody || '.modal-body' : '.modal-body'); | |
/** | |
* | |
* set modal shown state to false | |
*/ | |
this.isVisible = false; | |
/** | |
* | |
* set up listeners to observe modal "shown" state | |
* | |
*/ | |
var _this = this; | |
this.onShownListener( function() { | |
_this.isVisible = true; | |
}); | |
this.onHiddenListener( function() { | |
_this.isVisible = false; | |
}); | |
}; | |
MyModal.prototype = $.fn.modal.Constructor.prototype; | |
MyModal.prototype.onShownListener = onShownListener; | |
MyModal.prototype.onHiddenListener = onHiddenListener; | |
return MyModal; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment