Type.js
11.9 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
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
/**
* @package anc_text
* @since 20140416
* @copyright (c) netz.coop eG
* @author netz.coop eG
*/
//$.noConflict();
var Anc_Text_Type = (function() {
var pastDraggable = '';
var droppableFile = function(param_dropzone_element, param_dropzone_params, param_input_element, param_note_element, param_gallery_ajaxData, param_DragAndDrop) {
/**
* fnc teil der die dateien aus dem dateiexplorer entgegen nimmt
*/
if(!param_dropzone_params.url) {
alert('keine url zum hochladen angegeben');
exit;
}
if(!param_dropzone_params.maxFiles) {
param_dropzone_params.maxFiles = 1;
}
param_dropzone_params.paramName = "file";
param_dropzone_params.processing = function(file) {
jQuery(" button.button ").attr("disabled", "disabled");
param_note_element.append('<div>Bild wird hochgeladen. Bitte warten!</div>');
jQuery(" > .preview-database-text > img ", param_dropzone_element).remove();
jQuery(" > img ", param_dropzone_element).remove();
this.removeAllFiles();
};
param_dropzone_params.init = function() {
this.on("complete", function (file) {
if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
// alert('file.width: '+file.width+' file.height: '+file.height);
}
});
this.on("success", function(file,rep) {
var reponse = jQuery.parseJSON( rep );
if(param_input_element) {
param_input_element.attr('value', reponse.id);
}
if(reponse.status === 'OK') {
var noteclass = 'anc-success';
var param_gallery_ajaxData_success = false;
if(jQuery.isFunction(param_gallery_ajaxData.success)) {
param_gallery_ajaxData_success = param_gallery_ajaxData.success;
}
param_gallery_ajaxData.success = function(data, textStatus, jqXhr) {
jQuery(this).html(data);
if(jQuery.isFunction(param_gallery_ajaxData_success)) {
param_gallery_ajaxData_success(reponse);
}
Anc_Text_Type.customerGallerysimplePrettyPhoto();
};
jQuery.ajax(param_gallery_ajaxData);
} else {
var noteclass = 'anc-error';
}
jQuery(" button.button ").attr("disabled", false);
jQuery(" div ", param_note_element).remove();
param_note_element.append('<div class="'+noteclass+'">'+reponse.message+'</div>');
});
};
param_dropzone_element.dropzone(param_dropzone_params);
/**
*
*/
if(param_DragAndDrop) {
alert('param_DragAndDrop:'+param_DragAndDrop);
var droppable_opt = {
accept:".anc-text-draggable",
tolerance: 'touch',
drop: function(typ, ui) {
var currentDraggable = jQuery(ui.draggable).attr('id');
jQuery(this).append(jQuery(ui.draggable).clone());
if(param_input_element) {
param_input_element.attr('value', ui.draggable.attr('id'));
}
jQuery(" > div ", param_dropzone_element).remove();
//If there is an object prior to the current one
if (this.pastDraggable != "") {
jQuery("#" + this.pastDraggable).remove(); //Place past object into its original coordinate
}
this.pastDraggable = currentDraggable;
},
activate: function(typ, ui) {},
deactivate: function(typ, ui) {},
over: function(typ, ui) {},
out: function(typ, ui) {
jQuery(ui.draggable).remove(); // jQuery(this).droppable('option', 'accept', '.anc-text-draggable');
},
}
param_dropzone_element.droppable(droppable_opt);
}
}
var draggableFile = function() {
var draggable_opt = {
revert: "invalid", // im zweifel gehts wieder zurück zum ursprung
cursor: "move", // mauszeiger ....
containment: "#ancsubbundleproduct", // element darf nur innerhalb von containment bewegt werden
opacity: .5,
snap:true, // einrasten
snapMode:"inner",
grid: [10,10],
stack: '.anc-text-draggable', // letzter drop liegt vorne
helper: 'clone', // nicht moven sondern kopieren
// snapTolerance:50,
}
jQuery(' .anc-text-draggable').draggable(draggable_opt);
}
/**
* fnc löscht falls vorhanden dropzone elemente
* lädt bild in div.preview-database-text und setzt id ins input
* bereitet bild für crop vor (resizeTextForTextEditor)
*
* @param int param_anc_text_id
* @param element element_input
* @param string param_anc_text_url
* @param element element_text_container
* @returns {undefined}
*/
var loadTextInto = function(
param_anc_text_id,
param_anc_text_url,
param_anc_admin_id,
param_ncalbum_id,
param_anc_customer_id,
param_used_byitem_id,
param_ordered ,
param_anc_text_content,
// element_text_container,
element_input,
element_input_text_id,
element_input_admin_id,
element_input_album_id,
element_input_customer_id,
element_input_used_byitem_id,
element_input_ordered,
element_input_dropzone) {
console.log('loadtextinto');
//
// console.log('loadTextInto'+'param_anc_text_id'+param_anc_text_id+' element_input '+element_input + ' param_anc_text_url: '+param_anc_text_url+', element_text_container: '+element_text_container) ;
// jQuery('textarea', element_text_container).remove();
// console.log(element_input);
// console.log(element_text_container);
// console.log('param_anc_admin_id'+param_anc_admin_id);
// console.log('param_anc_customer_id'+param_anc_customer_id);
// console.log(param_anc_text_content);
// jQuery('.dz-message ', element_text_container).remove();
// jQuery('.dz-text-preview ', element_text_container).remove();
element_input.attr('value', param_anc_text_id);
element_input_text_id.attr('value', param_anc_text_id);
element_input_admin_id.attr('value', param_anc_admin_id);
element_input_customer_id.attr('value',param_anc_customer_id);
element_input_album_id.attr('value',param_ncalbum_id);
// jQuery('#anctext-texteditorarea-id').html(param_anc_text_content);
tinyMCE.activeEditor.setContent(param_anc_text_content);
// resizeTextForTextEditor(param_anc_text_url);
}
var customerGallerysimplePrettyPhoto = function() {
jQuery("a[rel^='prettyPhoto']").prettyPhoto({});
// jQuery(".anctext-showNcTextForm").append('<img class="zoom" src="/skin/frontend/base/default/texts/anc/text/zoom.png" />');
jQuery(".anc_text_wrapper > .anctext-showNcTextForm").remove();
var css_zoom = {
'height': '20px',
'margin-right': '-20px',
'position': 'relative',
'z-index': '500',
'opacity':'1'
};
jQuery(".AncGalleryTexts > .anctext-showNcTextForm > .zoom").css(css_zoom);
}
var placeholder_width;
var placeholder_height;
var TextEditorFactor;
var element_textEditorArea;
var manipulateTextEditor = function() {
console.log('manipulateTextEditor');
element_textEditorArea = jQuery("#anctext-texteditorarea-id");
jQuery(document).ready(function($) {
var textEditorArea_width = element_textEditorArea.width();
var textEditorArea_height = element_textEditorArea.height();
placeholder_width = jQuery('> .dropzone ',element_textEditorArea).data('pxwidth');
placeholder_height = jQuery('> .dropzone ',element_textEditorArea).data('pxheight');
var maxfilesizemb = jQuery('> .dropzone ',element_textEditorArea).data('maxfilesizemb');
jQuery('.anctext-info > .editor').html('Sie haben einen Bildplatzhalterraum von '+placeholder_width+'px mal '+placeholder_height+'px zu Verfügung! Ihr Bild darf nicht mehr als '+maxfilesizemb+' mb haben.');
var factor = textEditorArea_width / placeholder_width;
TextEditorFactor = factor;
console.log('factor: '+factor);
var css_new_size = {
'width': textEditorArea_width,
'height': placeholder_height * factor,
}
jQuery('> .dropzone ',element_textEditorArea).css(css_new_size);
resizeTextForTextEditor(
jQuery('> .dropzone > .preview-database-text ',element_textEditorArea).data('textsrc'),
jQuery('> .dropzone > .preview-database-text ',element_textEditorArea).data()
);
});
}
var Croppic;
/**
* bereitet bild für crop bearbgeitung vor
*
* benötigt object variable @var Anc_Text_Type.TextEditorFactor und @var Anc_Text_Type.element_textEditorArea,
* diese werden durch @see Anc_Text_Type.manipulateTextEditor() initialisiert
*
* @param string param_textsrc
* @returns {undefined}
*/
var resizeTextForTextEditor = function(param_textsrc, param_cropdata) {
var newImg2 = new Text();
newImg2.src = param_textsrc;
newImg2.onload = function() {
var warning = '';
if(placeholder_width > newImg2.width || placeholder_height > newImg2.height ) {
warning = '<div class="anc-error">Das Bild ist zu klein, bitte nutzen Sie ein Bild mit einer größeren Auflösung!</div>';
}
var new_img_width = newImg2.width * TextEditorFactor;
var new_img_height = newImg2.height * TextEditorFactor;
jQuery('.anctext-info > .text').html('Ihr Bild ist '+newImg2.width+'px mal '+newImg2.height+'px groß!' + warning);
var cropperOptions = {
textUrl: param_textsrc,
textHeight: Math.round(new_img_height),
textWidth: Math.round(new_img_width),
onBeforeImgUpload: function(){ console.log('onBeforeImgUpload') },
onAfterImgUpload: function(){ console.log('onAfterImgUpload') },
onImgDrag: function(){ console.log('onImgDrag') },
onImgZoom: function(){ console.log('onImgZoom') },
onBeforeImgCrop: function(){ console.log('onBeforeImgCrop') },
onAfterImgCrop: function(){ console.log('onAfterImgCrop') },
}
jQuery(' > .dropzone > div', element_textEditorArea).remove();
Croppic = new Anc_Lib_Croppic(jQuery(' > .dropzone', element_textEditorArea), cropperOptions);
if (typeof param_cropdata !== 'undefined') {
var cropdata = {
'cropH' : Math.round(param_cropdata.croph*TextEditorFactor),
'cropW' : Math.round(param_cropdata.cropw*TextEditorFactor),
'imgH' : Math.round(param_cropdata.imgh*TextEditorFactor),
'imgW' : Math.round(param_cropdata.imgw*TextEditorFactor),
'imgInitH' :Math.round(param_cropdata.imginith*TextEditorFactor),
'imgInitW' :Math.round(param_cropdata.imginitw*TextEditorFactor),
'imgX1' : Math.round(param_cropdata.imgx1*TextEditorFactor),
'imgY1' : Math.round(param_cropdata.imgy1*TextEditorFactor),
}
Croppic.initialWithValues(cropdata);
}
};
}
var crop = function() {
cropData = Croppic.crop();
jQuery('#product_addtocart_form * .ancSPText_KEY_cropH > .input-box > input').attr('value', Math.round(cropData.cropH / TextEditorFactor));
jQuery('#product_addtocart_form * .ancSPText_KEY_cropW > .input-box > input').attr('value', Math.round(cropData.cropW / TextEditorFactor));
jQuery('#product_addtocart_form * .ancSPText_KEY_imgH > .input-box > input').attr('value', Math.round(cropData.imgH / TextEditorFactor));
jQuery('#product_addtocart_form * .ancSPText_KEY_imgInitH > .input-box > input').attr('value', Math.round(cropData.imgInitH / TextEditorFactor));
jQuery('#product_addtocart_form * .ancSPText_KEY_imgInitW > .input-box > input').attr('value', Math.round(cropData.imgInitW / TextEditorFactor));
jQuery('#product_addtocart_form * .ancSPText_KEY_imgW > .input-box > input').attr('value', Math.round(cropData.imgW / TextEditorFactor));
jQuery('#product_addtocart_form * .ancSPText_KEY_imgX1 > .input-box > input').attr('value', Math.round(cropData.imgX1 / TextEditorFactor));
jQuery('#product_addtocart_form * .ancSPText_KEY_imgY1 > .input-box > input').attr('value', Math.round(cropData.imgY1 / TextEditorFactor));
}
return {
manipulateTextEditor:manipulateTextEditor,
draggableFile:draggableFile,
droppableFile:droppableFile,
loadTextInto:loadTextInto,
customerGallerysimplePrettyPhoto:customerGallerysimplePrettyPhoto,
crop:crop
}
})();