pophint.js
4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* Pophint
* Code in 2014/10/16
* By van
*/
define( 'pophint' ,function( require, exports, module ){
require( 'fancybox' );
var pophint = function( target,options ){
this.target = target;
this.href = null;
this._opts = {
showid : "s-cancel-ensure", // 弹层容器ID
content : "您确定要继续操作吗?",
on : "s-f-confirm",
off : "s-f-remove",
onName : "确定",
offName : "取消",
operation : function( target ){}, //点击确定按钮执行的回调
cancelOpera : function( target ){}, //点击取消按钮可传入的回调
showButton: true,
head: null
}
this._opts = $.extend( this._opts,options );
this.init();
};
pophint.prototype = {
//初始化
init: function(){
var _this = this;
if( $( _this.target ).is( 'a' ) ){
_this.href = $( _this.target ).attr( 'href' );
$( _this.target ).attr( 'href' , 'javascript:void( 0 )' );
}
if ( !$( "#s-cancel-ensure" ).length > 0 ){
this.makeHtml();
};
this.setContent();
_this.setpop();
},
// 创建弹层内容
makeHtml: function(){
var _this = this;
// 创建html
var html = '<span href="#s-cancel-ensure" id="fancybox-cancel-ensure"></span>'+
'<div class="cancel-ensure" id="s-cancel-ensure" style="display: none;">'+
'<div class="s-chd"></div>'+
'<div class="cbd">您确定要继续操作吗?</div>'+
'<div class="s-cft">'+
'<button class="submitBtn s-f-confirm">'+ _this._opts.onName +
'</button>'+
'<button class="submitBtn grayBtn s-f-remove">'+ _this._opts.offName +
'</button>'+
'</div></div>';
if ( !$( "#s-cancel-ensure" ).length > 0 ){
$( "body" ).append( html );
};
$( '#fancybox-cancel-ensure' ).click(function(){
}).fancybox({
padding:0,
closeBtn:false,
scrolling:'visible',
keys:{
close: null
},
helpers:{
overlay:{
closeClick : false
}
},
afterClose:function(){
_this._opts.operation = function(){};
_this._opts.cancelOpera = function(){};
}
});
//$( '#fancybox-cancel-ensure' ).trigger( "click" );
},
//获取弹层事件
setpop:function(){
var _this = this;
$( '#fancybox-cancel-ensure' ).trigger( "click" );
if( !_this._opts.showButton ){
$( '.s-cft .s-f-remove' ).hide();
}else{
$( '.s-cft .s-f-remove' ).show();
}
// 确定操作事件绑定
$( '.s-f-confirm' ).bind( 'click' ,function(){
_this._opts.operation.call( _this , _this.target );
//如果是链接 允许其跳转
if( $( _this.target ).is( 'a' ) ){
window.location.href = _this.href ;
}
_this._opts.operation = function(){};
_this._opts.cancelOpera = function(){};
$.fancybox.close();
});
//取消操作事件绑定
$( '.s-f-remove' ).bind( 'click' ,function(){
_this._opts.cancelOpera.call( _this , _this.target );
//如果是链接 还原链接
if( $( _this.target ).is( 'a' ) ){
$( _this.target ).attr( 'href', _this.href );
}
_this._opts.cancelOpera = function(){};
_this._opts.operation = function(){};
$.fancybox.close();
return false;
});
},
//设置弹层内容
setContent: function(){
var _this = this,
head = this._opts.head;
$( "#"+_this._opts.showid ).find( ".cbd" ).html( _this._opts.content );
$( "#"+_this._opts.showid ).find( ".s-f-confirm" ).html( _this._opts.onName );
$( "#"+_this._opts.showid ).find( ".s-f-remove" ).html( _this._opts.offName );
if ( typeof head == "string" && head.length ){
$( "#"+_this._opts.showid ).find( ".s-chd" ).html( head ).show();
}
}
}
return pophint;
});