-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproductdesigner.js
executable file
·4185 lines (3694 loc) · 149 KB
/
productdesigner.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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* GoMage Product Designer Extension
*
* @category Extension
* @copyright Copyright (c) 2013-2016 GoMage (https://www.gomage.com)
* @author GoMage
* @license https://www.gomage.com/license-agreement/ Single domain license
* @terms of use https://www.gomage.com/terms-of-use/
* @version Release: 2.4.0
* @since Available since Release 1.0.0
*/
if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) {
if (typeof this !== 'function') throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
var aArgs = Array.prototype.slice.call(arguments, 1);
var fToBind = this;
var fNOP = function () {
};
var fBound = function () {
return fToBind.apply(this instanceof fNOP && oThis ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();
return fBound;
};
}
/**
* Convert first char in string to upper case
*/
var $ucfirst = function (str) {
str += '';
var f = str.charAt(0).toUpperCase();
return f + str.substr(1);
};
function getUrlParams() {
var paramString = window.location.search.substr(1);
var paramArray = paramString.split("&");
var params = {};
for (var i = 0; i < paramArray.length; i++) {
var tmpArray = paramArray[i].split("=");
params[tmpArray[0]] = tmpArray[1];
}
return params;
}
var ProductDesignerGlobalEval = function ProductDesignerGlobalEval(src) {
if (window.execScript) {
window.execScript(src);
return;
}
var fn = function () {
window.eval.call(window, src);
};
fn();
};
/*By Raj*/
_convertMonoToSimpleText = function (textObj){
var font = (textObj.fontFamily).toLowerCase();
var text = (textObj.text);
if(font!=='circle-monograms-three-white-alt')
return text;
/* monogram helper functions */
var characterMap= {
'1': 'a',
'2': 'b',
'3': 'c',
'4': 'd',
'5': 'e',
'6': 'f',
'7': 'g',
'8': 'h',
'9': 'i',
'0': 'j',
'!': 'k',
'@': 'l',
'#': 'm',
'$': 'n',
'%': 'o',
'^': 'p',
'&': 'q',
'*': 'r',
'(': 's',
')': 't',
'-': 'u',
'=': 'v',
'{': 'w',
'}': 'x',
'\\': 'y',
':': 'z'
}
var newString = "";
if(text.length===1){
var isSpecialChar = /[ !@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(text);
var isnum = /^\d+$/.test(text);
if(isnum || isSpecialChar){
translatedChar = (characterMap[text]!=undefined) ? characterMap[text]: '';
}else{
translatedChar = text;
}
newString = translatedChar;
}else{
var lastChar = text[text.length -1];
var translatedChar = (characterMap[lastChar]!=undefined) ? characterMap[lastChar]: '';
newString = text.slice(0, (text.length -1))+ translatedChar;
}
return newString.toLowerCase();
};
Event.observe(window, "resize", function() {
var width = document.viewport.getWidth();
var height = document.viewport.getHeight();
var dims = document.viewport.getDimensions(); // dims.width and dims.height
//console.log(dims);
var prod = window.pd.config.product.images[window.pd.currentColor][window.pd.currentSlide]
window.pd.resizeCanvas(prod)
});
/**
* Create module namespace if not defined
*/
if (typeof GoMage == 'undefined') GoMage = {};
GoMage.ProductDesigner = function (config, continueUrl, loginUrl, registrationUrl, saveDesign) {
'use strict';
this.opt = {
product_side_id: 'pd_sides',
canvasScale: 1,
scale_factor: 1.2
};
this.urls = {
continue: continueUrl,
login: loginUrl,
registration: registrationUrl,
saveDesign: saveDesign
}
this.history_storage = {};
this.history = new History();
this.layersManager = new LayersManager(this);
this.config = config;
this.prices = config.prices;
this.container = config.container;
this.navigation = config.navigation;
this.currentProd = null;
this.containerLayers = {};
this.containerCanvases = {};
this.productAdditionalImageTemplate = new Template($('product-image-template').innerHTML);
this.productAdditionalImageTemplateLabel = new Template($('product-image-template-label').innerHTML); // mmc template with label
this.isCustomerLogin = this.config.isCustomerLoggedIn;
this.currentColor = null;
this.currentSlide = null;
this.designChanged = {};
this.designId = {};
this.loadProduct(config.product);
this.observeChooseProduct();
this.observeLayerControls();
this.observeTabs();
this.observeShareBtn();
this.observeZoomBtn();
this.observeSaveDesign();
this.observeContinueBtn();
this.observeProductImageChange();
this.observeProductImageColorChange();
this.initPrices();
this.reloadPrice();
this.observePriceMoreInfo();
this.observeHelpIcons();
this.observeHistoryChanges();
this._toggleNavigationButtons('disabled');
this._toggleControlsButtons();
this._toggleHistoryButtons();
this.observeSubTabs(); // mmc 2ten monogram sub tabs
}
GoMage.ProductDesigner.prototype = {
/* monogram helper functions */
characterMap: {
'a': '1',
'b': '2',
'c': '3',
'd': '4',
'e': '5',
'f': '6',
'g': '7',
'h': '8',
'i': '9',
'j': '0',
'k': '!',
'l': '@',
'm': '#',
'n': '$',
'o': '%',
'p': '^',
'q': '&',
'r': '*',
's': '(',
't': ')',
'u': '-',
'v': '=',
'w': '{',
'x': '}',
'y': '\\',
'z': ':'
},
upperCaseMiddleLetterSpecial: function (vm, initials) {
if (initials.length === 3) {
return (
initials[0].toLowerCase() +
initials[1].toUpperCase() +
initials[2].toLowerCase()
);
}else if(initials.length === 2) {
return (
initials[0].toLowerCase() +
initials[1].toLowerCase()
);
}else if(initials.length === 1) {
return (
initials[0].toUpperCase()
);
}else{
return '';
}
},
upperCaseMiddleLetter: function (vm, initials) {
if (initials.length === 3) {
return (
initials[0].toLowerCase() +
initials[1].toUpperCase() +
initials[2].toLowerCase()
);
} else {
return '';
}
},
upperCaseLastLetter: function (vm, initials) {
if (initials.length === 1) {
return (
initials[0].toUpperCase()
);
}else if (initials.length === 2) {
return (
initials[0].toLowerCase() +
initials[1].toUpperCase()
);
} else {
return '';
}
},
upperCaseLetter: function (vm, initials, font) {
if (initials.length >= font.minChars) {
var result = '';
for (var i = 0; i < font.maxChars && i < initials.length; i++) {
result += initials[i].toUpperCase();
}
return result;
} else {
return '';
}
},
specialThirdLetter: function (vm, initials) {
if (initials.length === 3) {
return (
initials[0].toLowerCase() +
initials[1].toUpperCase() +
vm.characterMap[initials[2].toLowerCase()]
);
}else if (initials.length === 2) {
return (
initials[0].toLowerCase() +
vm.characterMap[initials[1].toLowerCase()]
);
}else if (initials.length === 1) {
return (
vm.characterMap[initials[0].toLowerCase()]
);
} else {
return '';
}
},
updateText: function (font, initials) {
if (initials.length > font.maxChars) {
initials = initials.substring(0, font.maxChars);
jQuery('#monogram_text').val(initials);
}
jQuery('#monogram_text').attr('maxlength', font.maxChars);
if (font.maxChars === 1)
jQuery('#monogram_text').next().text('Only 1 character allowed');
else if (font.minChars === font.maxChars)
jQuery('#monogram_text').next().text(font.minChars + ' characters required');
else
jQuery('#monogram_text').next().text('Only ' + font.minChars + '-' + font.maxChars + ' characters allowed');
return initials;
},
transformMonogramText: function (font_code, initials) {
var vm = this;
var font = vm.fonts()[font_code];
if (font) {
initials = vm.updateText(font, initials);
initials = font.translator(vm, initials, font);
// certain fonts require prefix - don't think we will need this
if (initials)
return font.prefix + initials;
else
return initials;
}
else
return initials;
},
getMonogramFont: function (font_code) {
var vm = this;
var font = vm.fonts()[font_code];
if (font)
return font.family;
else
return null;
},
// mmc 2ten monogram this function translates the user keystroke into the correct
// characters for the font
fonts: function () {
var vm = this;
return {
'1': {
family: 'Monoscript',
prefix: '',
sizeReduction: 10,
top: 7,
translator: vm.upperCaseMiddleLetterSpecial,
minChars: 1,
maxChars: 3,
},
'30A': {
family: 'Circle3',
prefix: '',
sizeReduction: 1,
top: 5, // mmc 2ten top position on canvas
translator: vm.specialThirdLetter,
minChars: 1,
maxChars: 3,
},
'32A': {
family: 'Circle2',
prefix: '',
sizeReduction: 1,
top: 5, // mmc 2ten top position on canvas
translator: vm.upperCaseLastLetter,
minChars: 1,
maxChars: 2,
},
// mmc 2ten monogram - below are not in use
'30B': {
family: 'circle-monograms-three-black',
prefix: '/',
sizeReduction: 2,
top: 15,
translator: vm.specialThirdLetter,
minChars: 3,
maxChars: 3
},
'30C': {
family: 'circle-monograms-three-black',
prefix: '<',
sizeReduction: 4,
top: 18,
translator: vm.specialThirdLetter,
minChars: 3,
maxChars: 3
},
'30D': {
family: 'circle-monograms-three-black',
prefix: '>',
sizeReduction: 2,
top: 16,
translator: vm.specialThirdLetter,
minChars: 3,
maxChars: 3
},
'31A': {
family: 'circle-monograms-three-white-alt',
prefix: '',
sizeReduction: 0,
top: 12,
translator: vm.specialThirdLetter,
minChars: 3,
maxChars: 3
},
'31B': {
family: 'circle-monograms-three-white-alt',
prefix: '/',
sizeReduction: 2,
top: 15,
translator: vm.specialThirdLetter,
minChars: 3,
maxChars: 3
},
'31C': {
family: 'circle-monograms-three-white-alt',
prefix: '<',
sizeReduction: 4,
top: 18,
translator: vm.specialThirdLetter,
minChars: 3,
maxChars: 3
},
'31D': {
family: 'circle-monograms-three-white-alt',
prefix: '>',
sizeReduction: 2,
top: 16,
translator: vm.specialThirdLetter,
minChars: 3,
maxChars: 3
},
'34': {
family: 'david',
prefix: '',
sizeReduction: 1,
top: 7,
translator: vm.upperCaseLetter,
minChars: 1,
maxChars: 3
},
}
},
/* end monogram */
fireEvent: function (element, event) {
if (document.createEventObject) {
// dispatch for IE
var evt = document.createEventObject();
return element.fireEvent('on' + event, evt)
}
else {
// dispatch for firefox + others
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true);
return !element.dispatchEvent(evt);
}
},
loadProduct: function (product, color) {
if (!product) {
return;
}
$('pd_current_product_name').innerHTML = product.name;
if (!color) {
color = product.default_color;
}
if (!product.images.hasOwnProperty(color)) {
return;
}
this.currentColor = color;
this.changeColorAttribute();
var images = product.images[color];
// todo make more flexible?
// mmc this won't work on single site maybe?
// mmc 2ten trying to get first image by getting the first active image thumbnail
// var firstImage = jQuery('.pd_sides_list > li.active > .product-image').data('image-id');
// var img = images[firstImage];
// this.addDesignArea(img);
// this.currentSlide = img.id;
// return;
// mmc 2ten this seems to rely on the order of the json to grab the first image
// this does not always work since the json can change order when passed from the template to this script
for (var prop in images) {
if (images.hasOwnProperty(prop)) {
var img = images[prop];
this.addDesignArea(img);
this.currentSlide = img.id;
return;
}
}
},
changeColorAttribute: function () {
if (isNaN(parseInt(this.currentColor))) {
return;
}
var color_attribute = $('attribute' + this.config.colorAttributeId);
if (color_attribute) {
color_attribute.value = this.currentColor;
this.fireEvent(color_attribute, 'change');
color_attribute.up('dd').hide();
color_attribute.up('dd').previous('dt').hide();
var options = $$('#product-options-wrapper dd');
var hide = true;
options.each(function (option) {
if (option.visible()) {
hide = false;
throw $break;
}
});
if (hide) {
$('product_options').hide();
}
}
},
observeChooseProduct: function () {
if (this.navigation.chooseProduct) {
this.navigation.chooseProduct.observe('click', function (e) {
var elm = e.target || e.srcElement;
var content = $(elm.id + '-content');
if (content) {
if (content.getStyle('display') == 'none') {
content.setStyle({display: 'block'});
} else {
content.setStyle({display: 'none'});
}
}
});
}
},
changeProductImage: function (id) {
var img = this.config.product.images[this.currentColor][id];
if (img && this.currentProd != img.id) {
this.history_storage[this.currentSlide] = this.history;
if (this.history_storage.hasOwnProperty(id)) {
this.history = this.history_storage[id];
} else {
this.history = new History();
}
this.currentSlide = id;
this.containerCanvases[this.currentProd] = this.canvas;
if(typeof(this.container.childElements()) != "undefined")
this.containerLayers[this.currentProd] = this.container.childElements()[0].remove();
jQuery("#add_text_textarea").val(''); //@Fahad: empty the canvas area
this.addDesignArea(img);
this._toggleControlsButtons();
}
},
changeProductColor: function (color) {
this.containerCanvases[this.currentProd] = this.canvas;
this.containerLayers[this.currentProd] = this.container.childElements()[0].remove();
var product = this.config.product;
this.loadProduct(product, color);
this.updateProductImages(product);
this.reloadPrice();
this._toggleControlsButtons();
},
updateProductImages: function (product) {
if (!$(this.opt.product_side_id)) {
return;
}
var productsList = $(this.opt.product_side_id).down('ul');
productsList.innerHTML = '';
var images = product.images[this.currentColor];
var imageTemplateData = {};
var imagesHtml = '';
var first = true;
for (var id in images) {
if (images.hasOwnProperty(id)) {
imageTemplateData['class'] = first ? 'active' : '';
imageTemplateData['ico'] = images[id].ico;
imageTemplateData['image-id'] = id;
imageTemplateData['data-image-id'] = images[id].id;
imageTemplateData['data-url'] = images[id].u;
if(images[id].label){
imageTemplateData['label'] = images[id].label; // mmc add label
imagesHtml += this.productAdditionalImageTemplateLabel.evaluate(imageTemplateData); // mmc evaluate label template
}else{
// mmc evaluate normal template
imagesHtml += this.productAdditionalImageTemplate.evaluate(imageTemplateData);
}
first = false;
}
}
productsList.innerHTML = imagesHtml;
},
observeTabs: function () {
$('pd_panels_nav').childElements().invoke('observe', 'click', function (e) {
var elm = e.target || e.srcElement;
elm = elm.up('button.pd-btn') || elm;
elm.siblings().invoke('removeClassName', 'active');
elm.addClassName('active');
var buttonId = elm.id;
var tabContentElement = $(buttonId + '-content');
if (tabContentElement) {
if (buttonId == 'pd_add_text') {
var event = document.createEvent('Event');
event.initEvent('textTabShow', true, true);
document.dispatchEvent(event);
}
tabContentElement.siblings().invoke('setStyle', {display: 'none'});
if (tabContentElement.getStyle('display') == 'none') {
tabContentElement.setStyle({display: 'block'});
}
}
}.bind(this));
},
// mmc 2ten monogram added for text/monogram tab switching
observeSubTabs: function () {
$('subtab-nav').childElements().invoke('observe', 'click', function (e) {
var elm = e.target || e.srcElement;
elm = elm.up('button.subtab-nav__button') || elm;
elm.siblings().invoke('removeClassName', 'active');
elm.addClassName('active');
var buttonId = elm.id;
var tabContentElement = $(buttonId + '-content');
// clear canvas
for (var canvas in this.containerCanvases) {
this.containerCanvases[canvas].clear();
}
// clear form fields
jQuery('#monogram_text').val('');
jQuery('#add_text_textarea').val('');
if (tabContentElement) {
// if (buttonId == 'pd_add_text') {
// var event = document.createEvent('Event');
// event.initEvent('textTabShow', true, true);
// document.dispatchEvent(event);
// }
tabContentElement.siblings().invoke('setStyle', {display: 'none'});
// mmc not sure the event stuff here is needed
if (buttonId == 'subtab_text') {
jQuery('#design_type').val("text");
document.getElementById("add_text_textarea").maxLength = 10; // todo get from real settings reset maxlen
// mmc 2ten if this is removed, works if don't interact with monogram form field
// mmc 2ten todo decide if this is necessary
var event = document.createEvent('Event');
event.initEvent('textTabShow', true, true);
document.dispatchEvent(event);
//GoMage.TextEditor.prototype.observeMonogramTab();
} else if (buttonId == 'subtab_monogram') { // mmc 2ten todo changed
jQuery('#design_type').val("monogram");
}
if (tabContentElement.getStyle('display') == 'none') {
tabContentElement.setStyle({display: 'block'});
}
}
}.bind(this));
},
//@Fahad: function to resize the current canvas based on the window size and canvas product size and current view
resizeCanvas: function(prod){
if (typeof prod === 'undefined') {
return;
}
//@Fahad:
var bgDim = this.getBGImageDim('#pd_container')
//console.log("bgDim:",bgDim);
var designAreaDim = {};
designAreaDim.l = parseInt(prod.l);
designAreaDim.t = parseInt(prod.t);
designAreaDim.w = parseInt(prod.w);
designAreaDim.h = parseInt(prod.h);
if(parseInt(bgDim.width) != parseInt(prod.d[0]) )
{
var ratio = parseInt(bgDim.width) / parseInt(prod.d[0]);
var top = (parseInt(prod.d[0]) - parseInt(bgDim.width))/2;
designAreaDim.l = designAreaDim.l * ratio;
designAreaDim.t = designAreaDim.t * ratio; // mmc 2ten remove " +top"
designAreaDim.w = designAreaDim.w * ratio;
designAreaDim.h = designAreaDim.h * ratio;
}
var designArea = document.getElementsByClassName("pd-design-area")[0];
designArea.style.marginLeft = designAreaDim.l + 'px';
designArea.style.marginTop = designAreaDim.t + 'px';
designArea.style.width = designAreaDim.w + 'px';//@Fahad:
designArea.style.height = designAreaDim.h + 'px';//@Fahad:
designArea.style.zIndex = '1000';
window.pd.canvas.setWidth(designAreaDim.w);
window.pd.canvas.setHeight(designAreaDim.h);
// mmc 2ten position tools over image
this.positionTools();
// mmc remove - see note about setting this in the css
// this.container.style.height = parseInt(prod.d[1]) + 'px';
// this.container.style.width = parseInt(prod.d[0]) + 'px';
window.pd.canvas.getObjects().each(function (object) {
if (object.type == 'text') {
object.center();
object.setCoords();
}
});
window.pd.canvas.renderAll();
},
positionTools: function(top){
var designArea = document.getElementsByClassName("pd-design-area")[0];
var top = designArea.style.marginTop;
// mmc 2ten adjust top position of .pd-custom-wrapper
var top = parseInt(top, 10);
var tools = document.getElementsByClassName("pd-custom-wrapper")[0];
var toolsTop = top - tools.getHeight() - 20;
tools.style.top = toolsTop + 'px';
// mmc adds padding to compensate for panel going outside the area - not needed for now
// var wrap = document.getElementsByClassName("pd-container__wrap")[0];
// if(toolsTop < 0){
// // add padding to pd-container__wrap to
// var wrapPad = Math.abs(toolsTop) + 20;
// wrap.style.paddingTop = wrapPad + 'px';
// }else{
// wrap.style.paddingTop = 0;
// }
},
addDesignArea: function (prod) {
if (typeof prod === 'undefined') {
return;
}
// mmc 2ten remove this setting to 100% height and width in css
// going to use another container to fix the width/height
// this.container.style.height = parseInt(prod.d[1]) + 'px';
// this.container.style.width = parseInt(prod.d[0]) + 'px';
this.container.style.position = 'absolute'; //@Fahad:
this.container.style.background = 'url(' + prod.u + ') no-repeat center top'; // mmc 2ten position bg top
if (typeof this.containerLayers[prod.id] === 'undefined') {
//@Fahad:
var bgDim = this.getBGImageDim('#pd_container')
//console.log("bgDim:",bgDim);
var designAreaDim = {};
designAreaDim.l = parseInt(prod.l);
designAreaDim.t = parseInt(prod.t);
designAreaDim.w = parseInt(prod.w);
designAreaDim.h = parseInt(prod.h);
if(parseInt(bgDim.width) != parseInt(prod.d[0]) )
{
var ratio = parseInt(bgDim.width) / parseInt(prod.d[0]);
var top = (parseInt(prod.d[0]) - parseInt(bgDim.width))/2;
designAreaDim.l = designAreaDim.l * ratio;
designAreaDim.t = designAreaDim.t * ratio; //mmc 2ten remove "+top";
designAreaDim.w = designAreaDim.w * ratio;
designAreaDim.h = designAreaDim.h * ratio;
}
var designArea = document.createElement('div');
designArea.setAttribute('class', 'pd-design-area');
designArea.setAttribute('id', 'designArea-' + prod.id);
designArea.style.position = 'relative'; //@Fahad:
designArea.style.marginLeft = designAreaDim.l + 'px';
designArea.style.marginTop = designAreaDim.t + 'px';
designArea.style.width = designAreaDim.w + 'px';//@Fahad:
designArea.style.height = designAreaDim.h + 'px';//@Fahad:
designArea.style.zIndex = '1000';
var canvas = document.createElement('canvas');
canvas.setAttribute('class', 'pd-canvas-pane');
canvas.setAttribute('width', designAreaDim.w);
canvas.setAttribute('height', designAreaDim.h);
designArea.appendChild(canvas);
this.container.appendChild(designArea);
this.designArea = designArea;
this.canvas = new fabric.Canvas(canvas);
this.canvas.selection = false;
this.containerCanvases[prod.id] = this.canvas;
this._observeCanvasObjects();
} else {
var designArea = this.containerLayers[prod.id];
// mmc 2ten note
// need to resize design area and canvas here
this.container.appendChild(designArea);
this.designArea = designArea;
this.canvas = this.containerCanvases[prod.id];
var currentCanvas = this.canvas;
this.canvas.selection = false;
this.canvas.getObjects().each(function (object) {
if (object.type == 'text') {
currentCanvas.setActiveObject(object);
var objSimpleText = _convertMonoToSimpleText(object);
jQuery("#add_text_textarea").val(objSimpleText);
}
});
}
// mmc 2ten position tools over image
this.positionTools();
this.currentProd = prod.id;
},
observeSaveDesign: function () {
if (this.navigation.saveDesign) {
this.navigation.saveDesign.observe('click', function (e) {
e.stop();
if (!this.canvasesHasLayers()) {
alert('Please add at least one customization');
return;
}
if (this.navigation.saveDesign.hasClassName('disabled') || !this.designChanged.hasOwnProperty(this.currentColor)
|| (this.designChanged.hasOwnProperty(this.currentColor) && this.designChanged[this.currentColor] == false )) {
return;
}
if (!this.isCustomerLogin) {
this.createCustomerLoginWindows();
if (this.loginWindow) {
this.loginWindow.showCenter(true);
setTimeout(function () {
this.loginWindow.setSize(this.loginWindow.width, $('customer-login-container').getHeight(), true);
}.bind(this), 320);
}
} else if (this.isCustomerLogin) {
this.saveDesign(this.urls.saveDesign, this.saveDesignCallback);
}
}.bind(this));
}
},
createCustomerLoginWindows: function () {
if (!this.isCustomerLogin) {
if (!this.loginWindow && $('customer-login-container')) {
this.loginWindow = this.createPopupWindow('customer-login-container', 'login-error-msg', {
className: 'magento',
title: 'Login',
width: 430,
minWidth: 430,
maximizable: false,
minimizable: false,
resizable: false,
draggable: false,
recenterAuto: false,
showEffect: Effect.BlindDown,
hideEffect: Effect.BlindUp,
showEffectOptions: {duration: 0.3},
hideEffectOptions: {duration: 0.3}
});
this.observeRegisterBtn();
this.observeLogin();
}
if (!this.registrationWindow && $('customer-register-container')) {
this.registrationWindow = this.createPopupWindow('customer-register-container', 'register-error-msg', {
className: 'magento',
title: 'Registration',
width: 900,
minWidth: 900,
minHeight: 410,
maximizable: false,
minimizable: false,
resizable: false,
draggable: false,
showEffect: Effect.BlindDown,
hideEffect: Effect.BlindUp,
showEffectOptions: {duration: 0.3},
hideEffectOptions: {duration: 0.3}
});
this.observeRegisterSubmitBtn();
}
Event.on(document.body, 'click', '#overlay_modal', function (e, elm) {
e.stop();
Windows.closeAll();
});
}
},
createPopupWindow: function (contentId, errorContainerId, params) {
var win = new Window(params);
win.errorContainerId = errorContainerId
win.setContent(contentId, true, true);
win.setZIndex(2000);
return win;
},
observeRegisterBtn: function () {
var registerBtn = $('customer-register-btn');
if (registerBtn) {
registerBtn.observe('click', function (e) {
e.stop();
this.loginWindow.close();
setTimeout(function () {
this.registrationWindow.showCenter(true);
}.bind(this), 1000);
}.bind(this));
}
},
observeRegisterSubmitBtn: function () {
var registerBtn = $('customer-register-submit-btn');
if (registerBtn) {
registerBtn.observe('click', function (e) {
e.stop();
this.loginAndSaveDesign(this.urls.registration, 'form-validate', this.registrationWindow);
}.bind(this));
}
},
observeLogin: function () {
var loginBtn = $('customer-login-btn');
if (loginBtn) {
loginBtn.observe('click', function (e) {
e.stop();
this.loginAndSaveDesign(this.urls.login, 'login-form', this.loginWindow);
}.bind(this));
}
},
loginAndSaveDesign: function (url, formId, popupWindow) {
var form = new VarienForm(formId, true);
if (form.validator.validate()) {
var elements = form.form.elements;
var data = {};
for (var index in elements) {
if (elements.hasOwnProperty(index)) {
var elm = elements[index];
if (typeof elm == "object" && elm.tagName == 'INPUT') {
if (elm.type == 'checkbox') {
data[elm.name] = elm.checked
} else {
data[elm.name] = elm.value;
}
}
}
}
;
var imagesData = this.prepareImagesForSave();
var data = Object.extend(data, imagesData);
new Ajax.DesignerRequest(url, {
method: 'post',
parameters: data,
onSuccess: function (transport) {
var response = transport.responseText.evalJSON();
if (response.status == 'success') {
this.isCustomerLogin = true;
this.clearLoginErrors(popupWindow.errorContainerId);
if (response.top_links) {
if ($$('.page-header-container').length) {
var quickAccessContainer = $$('.page-header-container');
} else {
var quickAccessContainer = $$('.quick-access');
}
var linksHtml = response.top_links;
} else if (response.account_links) {
var quickAccessContainer = $$('.header-panel');
var linksHtml = response.account_links;
}
if (quickAccessContainer && quickAccessContainer != undefined) {
var quickAccessContainer = quickAccessContainer[0];
if (response.welcome_text) {
var welcomeText = quickAccessContainer.down('.welcome-msg');