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
300
301
302
303
304
305
306
307
308
/**
* @package anc_image
* @since 20140416
* @copyright (c) netz.coop eG
* @author netz.coop eG
*/
//$.noConflict();
var Anc_Image_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-image > 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_Image_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-image-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-image-draggable');
},
}
param_dropzone_element.droppable(droppable_opt);
}
}
/**
* fnc löscht falls vorhanden dropzone elemente
* lädt bild in div.preview-database-image und setzt id ins input
* bereitet bild für crop vor (resizeImageForImageEditor)
*
* @param int param_anc_image_id
* @param element element_input
* @param string param_anc_image_url
* @param element element_image_container
* @returns {undefined}
*/
var loadImageInto = function(param_anc_image_id, element_input, param_anc_image_url, element_image_container) {
jQuery('img ', element_image_container).remove();
jQuery('.dz-message ', element_image_container).remove();
jQuery('.dz-image-preview ', element_image_container).remove();
element_input.attr('value', param_anc_image_id);
resizeImageForImageEditor(param_anc_image_url);
}
var customerGallerysimplePrettyPhoto = function() {
jQuery("a[rel^='prettyPhoto']").prettyPhoto({});
jQuery(".ancimage-showNcImageForm").append('<img class="zoom" src="/skin/frontend/base/default/images/anc/image/zoom.png" />');
jQuery(".anc_image_wrapper > .ancimage-showNcImageForm").remove();
var css_zoom = {
'height': '20px',
'margin-right': '-20px',
'position': 'relative',
'z-index': '4',
'opacity':'1'
};
jQuery(".AncGalleryImages > .ancimage-showNcImageForm > .zoom").css(css_zoom);
}
var placeholder_width;
var placeholder_height;
var ImageEditorFactor;
var element_imageEditorArea;
var manipulateImageEditor = function() {
element_imageEditorArea = jQuery("#ancimage-imageeditorarea-id");
jQuery(document).ready(function($) {
var imageEditorArea_width = element_imageEditorArea.width();
var imageEditorArea_height = element_imageEditorArea.height();
placeholder_width = jQuery('> .dropzone ',element_imageEditorArea).data('pxwidth');
placeholder_height = jQuery('> .dropzone ',element_imageEditorArea).data('pxheight');
var maxfilesizemb = jQuery('> .dropzone ',element_imageEditorArea).data('maxfilesizemb');
jQuery('.ancimage-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 = imageEditorArea_width / placeholder_width;
ImageEditorFactor = factor;
console.log('factor: '+factor);
var css_new_size = {
'width': imageEditorArea_width,
'height': placeholder_height * factor,
}
jQuery('> .dropzone ',element_imageEditorArea).css(css_new_size);
resizeImageForImageEditor(
jQuery('> .dropzone > .preview-database-image ',element_imageEditorArea).data('imagesrc'),
jQuery('> .dropzone > .preview-database-image ',element_imageEditorArea).data()
);
});
}
var Croppic;
/**
* bereitet bild für crop bearbgeitung vor
*
* benötigt object variable @var Anc_Image_Type.ImageEditorFactor und @var Anc_Image_Type.element_imageEditorArea,
* diese werden durch @see Anc_Image_Type.manipulateImageEditor() initialisiert
*
* @param string param_imagesrc
* @returns {undefined}
*/
var resizeImageForImageEditor = function(param_imagesrc, param_cropdata) {
var newImg2 = new Image();
newImg2.src = param_imagesrc;
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>';
alert('Das Bild ist zu klein, bitte nutzen Sie ein Bild mit einer größeren Auflösung!');
}
var new_img_width = newImg2.width * ImageEditorFactor;
var new_img_height = newImg2.height * ImageEditorFactor;
jQuery('.ancimage-info > .image').html('Ihr Bild ist '+newImg2.width+'px mal '+newImg2.height+'px groß!' + warning);
if(warning) {
return;
}
var cropperOptions = {
imageUrl: param_imagesrc,
imageHeight: Math.round(new_img_height),
imageWidth: 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_imageEditorArea).remove();
Croppic = new Anc_Lib_Croppic(jQuery(' > .dropzone', element_imageEditorArea), cropperOptions);
if (typeof param_cropdata !== 'undefined') {
var cropdata = {
'cropH' : Math.round(param_cropdata.croph*ImageEditorFactor),
'cropW' : Math.round(param_cropdata.cropw*ImageEditorFactor),
'imgH' : Math.round(param_cropdata.imgh*ImageEditorFactor),
'imgW' : Math.round(param_cropdata.imgw*ImageEditorFactor),
'imgInitH' :Math.round(param_cropdata.imginith*ImageEditorFactor),
'imgInitW' :Math.round(param_cropdata.imginitw*ImageEditorFactor),
'imgX1' : Math.round(param_cropdata.imgx1*ImageEditorFactor),
'imgY1' : Math.round(param_cropdata.imgy1*ImageEditorFactor),
}
Croppic.initialWithValues(cropdata);
}
if(false) {
// @ControlRotate
var rotate = 90;
jQuery('div.cropControls').append('<i class="ControlRotate">X</i>');
jQuery('.ControlRotate').unbind("click").click(function(e){
e.preventDefault();
var css_rotate = {
'position': 'relative',
'transform': 'rotate('+rotate+'deg)',
'transform-origin': '50% 50% 0px',
}
jQuery('.ancimage-dropzone > .cropImgWrapper > img').css(css_rotate);
jQuery('.ancimage-dropzone > img').css(css_rotate);
var position = jQuery('.ancimage-dropzone > img').position();
var cropdata = {
'cropH' : Croppic.cropW,
'cropW' : Croppic.cropH,
'imgH' : Croppic.imgW,
'imgW' : Croppic.imgH,
'imgInitH' :Croppic.imgInitW,
'imgInitW' :Croppic.imgInitH,
'imgX1' : Croppic.imgX1,
'imgY1' : Croppic.imgY1,
}
Croppic.cropH = cropdata.cropH;
Croppic.cropW = cropdata.cropW;
Croppic.imgH = cropdata.imgH;
Croppic.imgW = cropdata.imgW;
Croppic.imgInitH = cropdata.imgInitH;
Croppic.imgInitW = cropdata.imgInitW;
Croppic.imgX1 = cropdata.imgX1;
Croppic.imgY1 = cropdata.imgY1;
console.log('cropH',Croppic.cropH);
console.log('cropW',Croppic.cropW);
console.log('imgH',Croppic.imgH);
console.log('imgW',Croppic.imgW);
console.log('imgInitH',Croppic.imgInitH);
console.log('imgInitW',Croppic.imgInitW);
console.log('imgX1',Croppic.imgX1);
console.log('imgY1',Croppic.imgY1);
// Croppic.initialWithValues(cropdata);
if(rotate ===270) {
rotate = 0;
} else {
rotate = rotate+90;
}
});
}
};
}
var crop = function() {
cropData = Croppic.crop();
jQuery('#product_addtocart_form * .ancSPImage_KEY_cropH > .input-box > input').attr('value', Math.round(cropData.cropH / ImageEditorFactor));
jQuery('#product_addtocart_form * .ancSPImage_KEY_cropW > .input-box > input').attr('value', Math.round(cropData.cropW / ImageEditorFactor));
jQuery('#product_addtocart_form * .ancSPImage_KEY_imgH > .input-box > input').attr('value', Math.round(cropData.imgH / ImageEditorFactor));
jQuery('#product_addtocart_form * .ancSPImage_KEY_imgInitH > .input-box > input').attr('value', Math.round(cropData.imgInitH / ImageEditorFactor));
jQuery('#product_addtocart_form * .ancSPImage_KEY_imgInitW > .input-box > input').attr('value', Math.round(cropData.imgInitW / ImageEditorFactor));
jQuery('#product_addtocart_form * .ancSPImage_KEY_imgW > .input-box > input').attr('value', Math.round(cropData.imgW / ImageEditorFactor));
jQuery('#product_addtocart_form * .ancSPImage_KEY_imgX1 > .input-box > input').attr('value', Math.round(cropData.imgX1 / ImageEditorFactor));
jQuery('#product_addtocart_form * .ancSPImage_KEY_imgY1 > .input-box > input').attr('value', Math.round(cropData.imgY1 / ImageEditorFactor));
}
return {
manipulateImageEditor:manipulateImageEditor,
droppableFile:droppableFile,
loadImageInto:loadImageInto,
customerGallerysimplePrettyPhoto:customerGallerysimplePrettyPhoto,
crop:crop
}
})();