|
|
/**
|
|
|
* Modal 组件: 仿BOOTSTRAP:MODAL
|
|
|
* @author xuan.chen@yoho.cn
|
|
|
*/
|
|
|
'use strict';
|
|
|
|
|
|
/* config */
|
|
|
var NAME = 'YModal';
|
|
|
var DATA_KEY = 'yoho.modal';
|
|
|
var Event = {
|
|
|
CLICK_DATA_API: 'click.yoho.modal.data-api'
|
|
|
};
|
|
|
var Selector = {
|
|
|
DATA_TOGGLE: '[data-toggle="ymodal"]'
|
|
|
};
|
|
|
|
|
|
var Modal = function(elem, config) {
|
|
|
|
|
|
};
|
|
|
|
|
|
/* ------------------------static attribute ------------------*/
|
|
|
Modal.DEFAULT = {};
|
|
|
|
|
|
/* ------------------------public method ------------------*/
|
|
|
Modal.prototype.show = function() {
|
|
|
|
|
|
};
|
|
|
|
|
|
Modal.prototype.hide = function() {
|
|
|
|
|
|
};
|
|
|
|
|
|
Modal.prototype.toggle = function() {
|
|
|
|
|
|
};
|
|
|
|
|
|
/* ------------------------private method ------------------*/
|
|
|
|
|
|
|
|
|
/* ------------------------static method ------------------*/
|
|
|
Modal._jqueryBridge = function(config, relatedTarget) {
|
|
|
return this.each(function() {
|
|
|
var data = this.data(DATA_KEY);
|
|
|
var configs = $.extend(
|
|
|
{},
|
|
|
Modal.DEFAULT,
|
|
|
toString.call(config) === '[object Object]' && config
|
|
|
);
|
|
|
|
|
|
if (!data) {
|
|
|
this.data(DATA_KEY, data = new Modal(this, configs));
|
|
|
}
|
|
|
|
|
|
if (typeof config === 'string') {
|
|
|
data[config](relatedTarget);
|
|
|
} else if (config.show) {
|
|
|
data.show(relatedTarget);
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/* ----------------------- DATA-API ----------------------*/
|
|
|
|
|
|
$(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function(event) {
|
|
|
var selector = this.getAttribute('data-target');
|
|
|
var $target = $(selector);
|
|
|
|
|
|
if ($target[0].tagName.toUpperCase() === 'A') {
|
|
|
event.preventDefault();
|
|
|
}
|
|
|
|
|
|
Modal._jqueryBridge($target, {}, this);
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
$.fn[NAME] = Modal._jqueryBridge;
|
|
|
$.fn[NAME].constructor = Modal;
|
|
|
|
|
|
module.exports = Modal;
|
|
|
|
...
|
...
|
|