-
Notifications
You must be signed in to change notification settings - Fork 1
/
its.js
316 lines (275 loc) · 21.1 KB
/
its.js
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/**
The MIT License (MIT)
Copyright (c) 2013 Juaumlol
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function ( $ ) {
var i = 0, //i holds a incremental integer so the ids will never be the same
STATUS = {
NO_IMAGE: "noimage",
IMAGE: "image"
},
ACTIONS = {
SELECT: "select",
CHANGE: "change",
DELETE: "delete"
},
MENU = {
noimage: [
{
action: ACTIONS.SELECT,
name: "select_image",
css: "its-menu-select-image"
}
],
image: [
{
action: ACTIONS.DELETE,
name: "delete_image",
css: "its-menu-delete-image"
},
{
action: ACTIONS.SELECT,
name: "change_image",
css: "its-menu-select-image"
}
]
},
ALERTS_ACTIONS = {
CLOSE: "close"
},
ALERTS = {
delete: {
text: "alert_delete_text",
options: [{key:"yes", text:"yes"}, {key:"no", text:"no"}],
on: {
yes: function(self) {
$("#"+self.attr("data-its")).children("input[name=action]").val("delete");
$("#"+self.attr("data-its")).submit();
return ALERTS_ACTIONS.CLOSE;
},
no: ALERTS_ACTIONS.CLOSE
},
css: "its-alert-icon"
}
};
//This is the customizable part of the logic.
//Any layout customization can be done by extending the css rules
//Default Options
var defaultOptions = {
id: "",
image: "",
onComplete: function(data) {}
};
/**
*
* Creates the CSS
* Its using pure CSS because yes
*
*/
var ss1 = document.createElement('style');
var def = '.its{overflow:hidden;position:relative;cursor:default}.its .its-loading{width:100%;height:100%;top:0;left:0;background-color:rgba(0,0,0,0.8);background-position:center center;background-repeat:no-repeat;display:none;position:absolute;z-index:999999999999}.its .its-loading .its-loading-txt{line-height:100%;color:#fff;font-size:12px;font-family:verdana;height:100%;width:100%;text-align:center;top:46%;position:relative}.its.its-default-bg{background-color:#959595;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABMCAYAAACS9rJ1AAAAGXRF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ACYUmKRfb6N0AAAAAElFTkSuQmCC);background-position:center;background-repeat:no-repeat;background-size:auto}.its.its-image-bg{background-position:center center;background-size:cover}.its .its-menu{position:absolute;background-color:rgba(0,0,0,0.7);width:100%;height:35px;bottom:0px}.its .its-menu .its-menu-item{height:100%;float:right;font-family:verdana;font-size:12px;color:#fff;line-height:35px;padding-left:20px;padding-right:10px;cursor:pointer;background-repeat:no-repeat;background-position:center left}.its .its-menu .its-menu-item:hover{text-decoration:underline}.its .its-menu .its-menu-item.its-menu-select-image{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAALCAYAAABLcGxfAAAACXBIWXMAABcSAAAXEgFnn9JSAAABNmlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjarY6xSsNQFEDPi6LiUCsEcXB4kygotupgxqQtRRCs1SHJ1qShSmkSXl7VfoSjWwcXd7/AyVFwUPwC/0Bx6uAQIYODCJ7p3MPlcsGo2HWnYZRhEGvVbjrS9Xw5+8QMUwDQCbPUbrUOAOIkjvjB5ysC4HnTrjsN/sZ8mCoNTIDtbpSFICpA/0KnGsQYMIN+qkHcAaY6addAPAClXu4vQCnI/Q0oKdfzQXwAZs/1fDDmADPIfQUwdXSpAWpJOlJnvVMtq5ZlSbubBJE8HmU6GmRyPw4TlSaqo6MukP8HwGK+2G46cq1qWXvr/DOu58vc3o8QgFh6LFpBOFTn3yqMnd/n4sZ4GQ5vYXpStN0ruNmAheuirVahvAX34y/Axk/96FpPYgAAACBjSFJNAAB6JQAAgIMAAPn/AACA6AAAUggAARVYAAA6lwAAF2/XWh+QAAAAgklEQVR42oyRsQ2DQAxFHylSRWIA2gySnoXY4PZBpM8e7BBFIg3VoznQ6ZQg/8qy35MsGzUZT2rUD9ASy/sCjMTzRO3UJbDOonaoqENAGFR24arOJ/CcmUNA7U+EfudKAXX6AU8lUwt3dS3gNff+ClSPTPW8Uetb34BXrh/AtxxuAwDCYGM2Xz+wWAAAAABJRU5ErkJggg==)}.its .its-menu .its-menu-item.its-menu-delete-image{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAT5JREFUeNqUU0uKhDAQjUOvBBFRXIjgTr2Al+hzeAbPIC5cuBahL9FX8A4uXIgIIohL/5lJoCRmtIcJFFUvqXr18hMwxuhuRFGEi6JAtm2jIAiEq5yvu2Lf9ylzmqYCi/khsAqyLMPbtqF1Xakty0L9PM80BkwsjmPhRPB6vbDneTRpmqbDxnGkBjHxhLAsS5QkifCA7oQoz3MECqAjSWYxKIDGpy2EYYhd1z0kE08MugJZVVXH2ZwOUVVVZJrmgR3HOTpZlkXXFUVBoihe3wJJ3vcdGYZxYF3X6Rxg/tp/EQAJGcSzRTy+VQAJPGZJLglgkdwEq4hX8PElgnyIeUUftwAFrAKY+xcB25H3f26hrmtKIkkS6vuexpqmoa7raPEwDCeSB1v880Debds+m6Y5fSj2CROTZfkNNd8CDABg938S/VLKaAAAAABJRU5ErkJggg==)}.its .its-alert-content{float:left;position:relative;top:35%;width:100%;background-color:rgba(0,0,0,0.7)}.its .its-alert-content .its-alert{display:table;margin:0 auto;width:100%;height:65px;background-repeat:no-repeat;background-position:20px center}.its .its-alert-content .its-alert.its-alert-icon{background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJbSURBVHja7Fo7bsJAEPUiDuAjmBtARWtuQHoKhwoJIQOigAqLAgqEHGioEIkoKMMN4pYquQEcgQPwyS7ajUjiz9q7a68lP+lJeA3G4zfzPGMAt9tNSTNySsqRBZAFwIj8fr8XcdwqZBHSwfREuVxmC0CAC+mQ7/j1ELISFARTANfrlfcx1y7bhbQE0IbU/qyhbQuTfxGjFOJEFXLosc/E+//tk0kBlO+qxz60bkM+y5pCGk4fPxiQb7wLOn+5XEQUrp9KjmwK6Ji070VKvMqkwDpCrewgTzIo4GabtPViJa2Aiq9mVMdCaXRMMgAv2wQua26Gj2z1KakUorFNmoZPZ3WlqAqsOZkIc5+UQwGEpI6pcKC23W6ZlASbzSbsZw4BzkNbAwTITgu1Wu0URwpFsU1aN+tEUmC1WoX5ooNPwxZVAYJSvV7/EqmATXHyLLDx9BZOgeVySfM+NN9+0h4zogIIT41GYxdKgfP5THt14oCN+ySuNlrlaJuBtjqfz0P1SGA2m7HaJs8UIrZa6na7Rx5FbAmwTVpbpRo/wWQyYbVN3goQVPr9vsOiQFTb5PWkjGr89CriIqQRU+F69lyj0cgIDAC10y60Pdbjpm1Zlho2haohhnSRNUDq0Hf8BIPBgNU2RQZAUBiPx0eaiSwJ26S9Q7uOn6DX67HaZhwK3G11Op06fgqI7jaFjJ/ANE3yxOxDkR+dF4hfAbRaLQWfvJ6CAO7j52KxOD2mkJGSk3cdP3M+P0rIynaz2dQeFdCU9EEjjyVRACfJ3cetDn5uaiD7s0cWABu+BRgAPhdgwoJRL5IAAAAASUVORK5CYII=)}.its .its-alert-content .its-alert .its-alert-txt{padding-left:75px;widows:100%;float:left;padding-right:15px;color:#fff;margin-top:10px;font-family:verdana;font-size:12px}.its .its-alert-content .its-alert .its-alert-options{padding-left:75px;padding-right:15px;width:100%;margin-top:5px;float:left;color:#fff;font-family:verdana;font-size:12px}.its .its-alert-content .its-alert .its-alert-options .its-alert-option{float:left;cursor:pointer;margin-right:15px}.its .its-alert-content .its-alert .its-alert-options .its-alert-option:hover{text-decoration:underline}';
ss1.setAttribute("type", "text/css");
var hh1 = document.getElementsByTagName('head')[0];
hh1.appendChild(ss1);
if (ss1.styleSheet) { // IE
ss1.styleSheet.cssText = def;
} else { // the world
var tt1 = document.createTextNode(def);
ss1.appendChild(tt1);
}
/**
*
* Provide a image upload component given one or more containers (jquery selector)
*
*/
$.fn.ITS = function(options) {
//Merge options to default
if(options == undefined) options = {};
var o = $.extend({}, defaultOptions, options);
/**
*
* Create the div that will hold the forms
* this is responsible for submmiting the images to the server
*
*/
if($("#its-frms").length === 0){
//this div is invisible that's why the css is inline and "not" customizable
$("body").prepend("<div id='its-frms'></div>");
$("#its-frms")
.css("visibility", "hidden")
.css("height", "0px")
.css("overflow", "hidden");
}
/**
*
* Loop for each element returned by the jQuery Selector and creates the upload component
*
*/
this.each(function () {
var self = $(this), //self
status = (o.image != "" ? STATUS.IMAGE : STATUS.NO_IMAGE), //this is the actual status of this specific component
id = (o.id == "" ? "its_"+(i++) : o.id);
//if the user sets the ID for ITS and it already exists throw a error and return
if($("*[data-its="+id+"]").length > 0) {
throw new Error("ITS(): the ID "+id+" already exist.");
return;
}
//sets the its id to the container
//it will be a incremental or the one defined in the initialization
self.attr("data-its", id);
/**
*
* Creates the form for this ITS component
* This form holds:
* id - ID of this ITS component
* action - The action that is beeing made (look at ACTIONS var)
* url - URL that the form will be posted
* image - input of type file that will hold the image uploaded
*
*/
$("#its-frms").prepend('<form id="'+id+'" action="" method="post" enctype="multipart/form-data"><input type="hidden" name="id" value="'+id+'"><input type="hidden" name="action" value=""><input type="hidden" name="url" value=""><input type="file" name="image"><br></form>');
self
.addClass("ITS-"+id) //add a class preppended by "ITS-" so the user can customize it individually
.addClass("its") //add class to say its a ITS component
.append("<div class='its-loading'><div class='its-loading-txt'>100%</div></div>") //append loading container
.append("<div class='its-menu'></div>") //append the menu
.append("<div class='its-alert-content'><div class='its-alert its-alert-icon'><div class='its-alert-txt'></div><div class='its-alert-options'></div></div></div>"); // alert
self.children(".its-alert-content").hide();
/* REMOVED TEMP
$(this)
.css("-webkit-touch-callout", "none")
.css("-webkit-user-select", "none")
.css("-khtml-user-select", "none")
.css("-moz-user-select", "none")
.css("-ms-user-select", "none")
.css("-user-select", "none");
*/
/**
*
* This function is responsible for changing the BG
*
*/
var changeBG = function() {
//clean classes
self.removeClass("its-default-bg");
self.removeClass("its-image-bg");
self.css("background-image", "");
//set new
if(status == STATUS.NO_IMAGE) {
//set the bg to the default
self.addClass("its-default-bg");
}else if(status == STATUS.IMAGE) {
//set the bf to the image class and url
self.addClass("its-image-bg");
self.css("background-image", "url("+o.image+")");
}
};
/**
*
* Updates the content of the ITS component
*
*/
var update = function(){
changeBG();
self.children(".its-menu").html(""); //clean menu
var menu = MENU[status];
var mi = 0, ml = menu.length, mitem;
for(mi; mi < ml; mi++){
mitem = menu[mi];
self
.children(".its-menu")
.append("<div data-its-menu='"+mitem.action+"' class='its-menu-item "+mitem.css+"'>"+$.fn.ITS.lang[mitem.name]+"</div>");
}
};
/**
*
* Opens a alert in the box
*
*/
var openAlert = function(alertID) {
var alert = ALERTS[alertID];
self.find(".its-alert-txt").html($.fn.ITS.lang[alert.text]);
var options = self.find(".its-alert-options");
options.html("");
var op = 0,
option,
ol = alert.options.length;
for(op; op < ol; op++) {
option = alert.options[op];
options.append("<div data-its-key='"+option.key+"' class='its-alert-option'>"+$.fn.ITS.lang[option.text]+"</div>");
}
self.find(".its-alert").attr("data-its-alert-id", alertID);
self.children(".its-alert-content").fadeIn();
};
var onClickAlertOption = function (e) {
var action = ALERTS[self.find(".its-alert").attr("data-its-alert-id")].on[$(this).attr("data-its-key")];
if(typeof action === "function") action = action(self);
if(action == ALERTS_ACTIONS.CLOSE) self.children(".its-alert-content").fadeOut();
};
//ADD events
//select and change click
self.children(".its-menu").delegate(".its-menu-item[data-its-menu="+ACTIONS.SELECT+"], .its-menu-item[data-its-menu="+ACTIONS.CHANGE+"]", "click", function(e) {
$("#"+id).children("input[name=action]").val($(this).attr("data-its-menu"));
$("#"+id).children("input[type=file]").trigger("click");
});
//delete click
self.children(".its-menu").delegate(".its-menu-item[data-its-menu="+ACTIONS.DELETE+"]", "click", function(e) {
openAlert(ACTIONS.DELETE);
});
//alert options click
self.find(".its-alert-options").delegate(".its-alert-option", "click", onClickAlertOption);
//when the input of the file changes its value submit the form
$("#"+id).children("input[type=file]").on("change", function(e){
if($(this).val() == "") return; //return if the value is empty
$("#"+id).submit();
});
//this is called after submit() is called
$("#"+id).ajaxForm({
url: "",
dataType: "json",
beforeSend: function() {
self.children(".its-loading").css("display", "inline-block");
var percentVal = '0%';
self.find(".its-loading-txt").html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
self.find(".its-loading-txt").html(percentVal);
},
success: function(data) {
var percentVal = '100%';
self.find(".its-loading-txt").html(percentVal);
self.children(".its-loading").css("display", "none");
$("#"+id).children("input[type=file]").val("");
$("#"+id).children("input[name=url]").val("");
if(data.action == ACTIONS.DELETE) {
o.image = "";
status = STATUS.NO_IMAGE;
} else if(data.action == ACTIONS.SELECT || data.action == ACTIONS.CHANGE) {
o.image = data.url;
status = STATUS.IMAGE;
}
update();
o.onComplete(data);
}
});
update();
return;
});
return this; //returns the object so it can be chained with another function
}; //end of ITS function
}( jQuery ));