Guest User

absrtract

a guest
Mar 24th, 2017
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.67 KB | None | 0 0
  1. var Aitcg_View_Abstract = Class.create(
  2. {
  3. id : '',
  4. option : null,
  5. editor : null,
  6. preview: null,
  7.  
  8. templateSyntax: /(^|.|\r|\n)({{(\w+)}})/,
  9. templateSettings: null,
  10. scr: null,
  11.  
  12. initialize: function( option ) {
  13. this.option = option;
  14. this.config = option.config;
  15. this.id = this.config.optionId;
  16. this.editor = option.editor;
  17. if(typeof(AitPopupHtml)!= 'undefined') {
  18. Event.observe(document, 'dom:loaded', function(){
  19. $$('body')[0].insert( {bottom:AitPopupHtml} );
  20. });
  21. }
  22. },
  23.  
  24. /**
  25. * @abstract
  26. */
  27. closeEditor: function(){},
  28.  
  29. /**
  30. * Return an array of data necessary to render an editor
  31. *
  32. * @return Object
  33. */
  34. getTemplateSetting: function() {
  35. return this.templateSettings;
  36. },
  37.  
  38. /**
  39. * Init an array of data necessary to render an editor
  40. */
  41. _setTemplateSetting: function()
  42. {
  43. var c = this.config,
  44. t = this.config.text,
  45. scr = this.scr,
  46. options = {
  47. full_image: c.productImage.fullUrl,
  48. rand : c.rand,
  49. option_id : this.id,
  50.  
  51. close_text : t.close,
  52. apply_text : t.apply,
  53. applytext : t.applytext,
  54. reset_text : t.reset,
  55. cancel_text : t.cancel,
  56. save_text : t.save,
  57. edit_text : t.edit,
  58. required_text : t.required,
  59. texttoadd_text : t.texttoadd,
  60. addtext_text : t.addtext,
  61. pickcolor_text : t.pickcolor,
  62. pickcoloroutline_text: t.pickcoloroutline,
  63. pickcolorshadow_text : t.pickcolorshadow,
  64. widthoutline_text : t.widthoutline,
  65. outline_text : t.outline,
  66. shadow_text : t.shadow,
  67. shadowalpha_text : t.shadowalpha,
  68. shadowoffsetx_text : t.shadowoffsetx,
  69. shadowoffsety_text : t.shadowoffsety,
  70. addimage_text : t.addimage,
  71. addmasks_text : t.addmasks,
  72. delmasks_text : t.delmasks,
  73. svg_text : t.svg,
  74. pdf_text : t.pdf,
  75. png_text : t.png,
  76. font_text : t.font,
  77. fontpreview_text : t.fontpreview,
  78. scale_text : t.scale,
  79. print_text : t.print_text,
  80. print_type_top : t.print_type_top,
  81. print_type_bottom : t.print_type_bottom,
  82. print_type_bg : t.print_type_bg,
  83. print_type_mask : t.print_type_mask,
  84. print_type_error : t.print_type_error,
  85.  
  86. masks_title : t.masks_title,
  87. predefined_title : t.predefined_title,
  88. user_title : t.user_title,
  89. text_title : t.text_title,
  90. under_template_text : t.under_template_text,
  91. save_title : t.save_title,
  92. save_about : t.save_about,
  93. buttonHelp : t.buttonHelp,
  94.  
  95. areaSizeX : c.area.sizeX,
  96. areaSizeY : c.area.sizeY,
  97. areaOffsetX : c.area.offsetX,
  98. areaOffsetY : c.area.offsetY,
  99.  
  100. fontOptions : c.tools.Text.fontOptions,
  101. empty_img_url: c.emptyImgUrl
  102. };
  103.  
  104. if (scr) {
  105. // some window rendering variables for template
  106. options['img_width'] = scr.curr.width;
  107. options['img_height'] = scr.curr.height;
  108. options['width'] = Math.floor(c.area.sizeX * scr.mult) + 'px';
  109. options['height'] = Math.floor(c.area.sizeY * scr.mult) + 'px';
  110. options['left'] = Math.max(0, Math.round(c.area.offsetX * scr.mult - 1)) + 'px';
  111. options['top'] = Math.max(0, Math.round(c.area.offsetY * scr.mult - 1)) + 'px';
  112. }
  113.  
  114. Aitoc_Common_Events.dispatch('aitcg_view_set_template_settings', {view: this, options: options});
  115.  
  116. this.templateSettings = options;
  117. },
  118.  
  119. /**
  120. * Render a bottom control panel of the editor
  121. *
  122. * @return string
  123. */
  124. _getControlPanelHtml: function()
  125. {
  126. if (this.config.editorEnabled) {
  127. return '<div id="aitcg-control-panel">' +
  128. '<button class="aitcg-button apply-but" id="submit-editorApply-{{rand}}" title="{{apply_text}}">{{apply_text}}</button>' +
  129. '<button class="aitcg-button reset-but" id="submit-editorReset-{{rand}}" title="{{reset_text}}">{{reset_text}}</button>' +
  130. '</div>';
  131. }
  132. return '';
  133. },
  134.  
  135. /**
  136. * Init Apply and Reset buttons events
  137. */
  138. initObservers: function()
  139. {
  140. if (this.config.editorEnabled) {
  141. $('submit-editorApply-' + this.config.rand).observe('click', this.submitApply.bindAsEventListener(this));
  142. $('submit-editorReset-' + this.config.rand).observe('click', this.submitReset.bindAsEventListener(this));
  143. }
  144. },
  145.  
  146. submitApply: function(event)
  147. {
  148. Event.stop(event);
  149. this.option.apply();
  150. },
  151.  
  152. submitReset: function(event)
  153. {
  154. Event.stop(event);
  155. this.option.reset();
  156. },
  157.  
  158. /**
  159. * Render editor popup header and
  160. * toolbox if editor in enabled
  161. *
  162. * @return string
  163. */
  164. _getToolsHtml: function()
  165. {
  166. return this.option.tools.render();
  167. },
  168.  
  169. initPreview: function()
  170. {
  171. var scale = this.option.calcScale(),
  172. elementId = this.config.previewContainer,
  173. container = $(elementId),
  174. c = this.config,
  175. area = c.area,
  176. thumb = c.productImage.thumb;
  177. this.previewScale = scale;
  178.  
  179. var areaParams = {
  180. width : Math.round(area.sizeX * scale),
  181. height: Math.round(area.sizeY * scale),
  182. left : Math.round(area.offsetX * scale),
  183. top : Math.round(area.offsetY * scale)
  184. };
  185.  
  186. var html =
  187. '<div class="aitraph aitraph-bot"></div>' +
  188. '<img class="aitcg_preview_bg" src="' + thumb.fullUrl + '" />'+
  189. '<div class="aitraph aitraph-top"></div>' +
  190. '<div class="aitcg-overlay" style="width:'+ thumb.sizeX +'px;height:'+thumb.sizeY+'px;"></div>';
  191. container.update(html);
  192.  
  193. this._showPreviewBlock( container );
  194.  
  195. container.observe('click', this.onPreviewClick.bind(this));
  196.  
  197. var title = c.editorEnabled ? c.text.thumbTooltipEdit : c.text.thumbTooltipPreview,
  198. viewIconClass = c.editorEnabled ? '' : 'view-icon';
  199. container.select('.aitcg-overlay')[0]
  200. .observe('mouseover', function(){Aitcg.tooltip().update(title).show()})
  201. .observe('mouseout', function(){Aitcg.tooltip().hide()})
  202. .addClassName(viewIconClass);
  203.  
  204.  
  205. var styleParams = Aitcg.addPxToValue(areaParams);
  206. $$('#' + elementId + ' .aitraph').each( function(element) {
  207. element.setStyle(styleParams);
  208. });
  209.  
  210. Aitoc_Common_Events.dispatch('aitcg_option_preview_create_after_' + this.id, {element: container});
  211.  
  212. this.preview = new Aitcg_Editor(this.option);
  213. this.preview.init(container, Aitcg_Editor.MODE_PREVIEW, true, this.previewScale);
  214. this.preview.load( $('options_' + this.id).getValue() );
  215. this.switchToEditor();
  216. this.startEditor();
  217. },
  218.  
  219. previewReset: function()
  220. {
  221. this.preview.reset();
  222. this.preview.load( $('options_' + this.id).getValue() );
  223. },
  224.  
  225. /**
  226. * @abstract
  227. *
  228. * @param container
  229. * @private
  230. */
  231. _showPreviewBlock: function( container ){},
  232.  
  233. /**
  234. * @abstract
  235. */
  236. onPreviewClick: function(){},
  237.  
  238. /**
  239. * Render some template using current view options
  240. *
  241. * @param template String
  242. * @return string.
  243. */
  244. renderTemplate: function( template )
  245. {
  246. var tempObj = new Template(template, this.templateSyntax),
  247. options = this.getTemplateSetting();
  248. return tempObj.evaluate(options)
  249. },
  250.  
  251. _setVYAProductImage: function()
  252. {
  253. this._setTemplateSetting();
  254. this.initPreview();
  255. }
  256. });
Add Comment
Please, Sign In to add comment