artboxModal.js
4.8 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
/**
* первая ";" нужна и это не глюк.
* Если будет сжатие и объединение нескольких файлов и предыдущий код
* закончится на var a = 5 без ";", то мы получим следующий код :
* var a=5(function($){...}(jQuery)), а это приведет к ошибке
*/
;(function($) {
$.fn.artboxModal = function() {
if (!Array.isArray) {
Array.isArray = function(arg) {
return Object.prototype.toString.call(arg) === '[object Array]';
};
}
if (!Object.isObject) {
Object.isObject = function(arg) {
return Object.prototype.toString.call(arg) === '[object Object]';
};
}
var that = this; // jq object from which the method was called => $("#asdas")
return {
open : function(jqSelector) {
// var pos = ($(window).scrollTop()+30+50);
// console.log(pos);
if (
jqSelector !== undefined &&
jqSelector !== null &&
jqSelector !== '' &&
typeof(jqSelector) === "string"
){
$('#overlay').fadeIn(400,
function(){
$(jqSelector).first()
.css('display', 'block')
.animate({opacity: 1, top: 0}, 200);
});
$("body").addClass("off-scroll");
return $(jqSelector);
}
else{
if (that.selector !== ""){
$('#overlay').fadeIn(400,
function(){
console.log("that",that);
that
.css('display', 'block')
.animate({opacity: 1, top: 0}, 200);
});
$("body").addClass("off-scroll");
return that;
}
else {
throw 'Don\'t call this function from $.fn without selector in argument';
}
}
},
close : function() {
return this.closeAll();
},
closeAll : function() {
$('.forms_').animate({opacity: 0, top: '0'}, 200,function(){
$(this).css('display', 'none');
$('#overlay').fadeOut(400);
});
$('#success_modal').animate({opacity: 0, top: '0'}, 200,function(){
$(this).css('display', 'none');
$(this).css({top:'50%'});
$('#overlay').fadeOut(400);
});
$("body").removeClass("off-scroll");
return that;
},
openSuccessModal : function(arg) {
try {
if (arguments.length === 1){
if (
Object.isObject(arg) &&
arg.hasOwnProperty("header") &&
arg.hasOwnProperty("message")
){
$("#Success").text(arg.header);
$("#success-body").text(arg.message);
}
else {
throw new SyntaxError("Argument must be an object with properties: 'header' and 'message'");
}
}
else if (arguments.length === 2){
if (
typeof arguments[0] === "string" &&
typeof arguments[1] === "string"
){
var header = arguments[0],
message = arguments[1];
$("#Success").text(header);
$("#success-body").text(message);
}
else {
throw new SyntaxError("Both params (header and message) must be a string");
}
}
else {
throw new SyntaxError("You can specify only 1(as object) or 2(as strings) arguments");
}
// $('#success-modal').modal('show');
that.artboxModal().open("#success-modal");
return $('#success-modal');
}
catch (err){
console.log(err);
}
}
};
}
}(jQuery));