/* * @class * @param {string} owner * @example * var tracer = new Tracer( 'owner' ); */ function Tracer(owner, type) { this.id = new Date().getMilliseconds(); this.name = "New Tracer"; this.owner = owner; this.orientation = ""; this.pictures = {length : 0}; this.thumbs = []; this.picturesRequired = 1; this.previewUrl = "/transform/TransformImage.php"; this.type = ''; this.types = {}; this.showJqueryPreviewer = 'true'; this.isShowTab = false; if (jQuery(jQuery('.foot').html()).attr('data') == 'js') { this.showJqueryPreviewer = 'true'; } if (type) { this.setType(type); } if (effects_var) { this.types = effects_var; } if (product_var) { this.size = product_var.Size; this.scale = product_var.scale; this.effect_offset_x = product_var.landscapeActionWindowMarginX; this.effect_offset_y = product_var.landscapeActionWindowMarginY; this.portrait_offset_x = product_var.portraitActionWindowMarginX; this.portrait_offset_y = product_var.portraitActionWindowMarginY; this.preview_image1 = product_var.PreviewImage1; this.preview_image2 = product_var.PreviewImage2; if (product_var.text) { this.text = product_var.text; this.text.user_text = item_var['text'+this.text.card]; this.text.text_size = item_var['size_select'+this.text.card]; this.text.text_color = item_var['color'+this.text.card]; this.text.centrics_image1 = '/uploads/Products/product_'+product_var.id +'/'+product_var.PreviewTemplate1; this.text.centrics_image2 = '/uploads/Products/product_'+product_var.id +'/'+product_var.PreviewTemplate2; } } /* if (jQuery('#transform_data').text() != '') { var i = 0; var setup_obj = JSON.parse(jQuery('#transform_data').text()); if (setup_obj.hasOwnProperty("id")) { this.owner = setup_obj.id; this.type = setup_obj.type; this.orientation = setup_obj.orientation; this.pictures = setup_obj.pictures; } else { this.effect_offset_x = setup_obj.effect_pivot_x; this.effect_offset_y = setup_obj.effect_pivot_y; this.image_size_x = setup_obj.image_size_x; this.image_size_y = setup_obj.image_size_y; this.preview_image1 = setup_obj.preview_template1; this.preview_image2 = setup_obj.preview_template2; if( setup_obj.hasOwnProperty('text0') ) { this.text = setup_obj.text0; this.text.user_text = jQuery("#text_input"+this.text.card).val(); this.text.text_size = jQuery("input:radio[name=size_select"+this.text.card+"]:checked").val(); this.text.text_color = jQuery("#Preview"+this.text.card+" .preview_text").css('color'); } } } */ } Tracer.prototype.error = function(error) { error.time = 'RIGHT NOW'; return error; }; /* * @returns {object} data to send to TransformImage.php */ Tracer.prototype.getPreviewData = function() { if (!this.validate()) { return this.error({ 'error': 'validationError' }); } var transform = {}; transform.id = this.owner; transform.type = this.type; transform.orientation = this.orientation; if (this.pictures.length === 1) { transform.image1 = this.pictures["picture" + 0].thumbnail.path; transform.zoom_area = (this.pictures["picture" + 0].selection.x1 + (this.pictures["picture" + 0].selection.x2 / 2)) + ',' + (this.pictures["picture" + 0].selection.y1 + (this.pictures["picture" + 0].selection.y2 / 2)); } if (this.pictures.length === 2) { transform.image1 = this.pictures["picture" + 0].thumbnail.path; transform.offset1X = this.pictures["picture" + 0].thumbnail.offsetX; transform.offset1Y = this.pictures["picture" + 0].thumbnail.offsetY; transform.image2 = this.pictures["picture" + 1].thumbnail.path; transform.offset2X = this.pictures["picture" + 1].thumbnail.offsetX; transform.offset2Y = this.pictures["picture" + 1].thumbnail.offsetY; } if (this.pictures.length === 3) { transform.image1 = this.pictures["picture" + 0].thumbnail.path; transform.offset1X = this.pictures["picture" + 0].thumbnail.offsetX; transform.offset1Y = this.pictures["picture" + 0].thumbnail.offsetY; transform.image2 = this.pictures["picture" + 1].thumbnail.path; transform.offset2X = this.pictures["picture" + 1].thumbnail.offsetX; transform.offset2Y = this.pictures["picture" + 1].thumbnail.offsetY transform.image3 = this.pictures["picture" + 2].thumbnail.path; transform.offset3X = this.pictures["picture" + 2].thumbnail.offsetX; transform.offset3Y = this.pictures["picture" + 2].thumbnail.offsetY; } return transform; }; Tracer.prototype.getPictureData = function() { if( !this.validate() ) { return this.error( { 'error': 'validationError' } ); } var transform = {}; transform.id = this.owner; transform.type = this.type; transform.orientation = this.orientation; transform.pictures = this.pictures; transform.text = this.text; return transform; }; Tracer.prototype.setName = function(name) { this.name = name; }; /* * @param {array} order set the current order to order [ 0, 1, 2 ] -> [ 1, 0, 2 ] */ Tracer.prototype.setOrder = function(order) { var i = 0; if (order.length !== this.pictures.length) { return this.error({ 'error': 'setOrderLength' }); } // copy pictures to temp var temp = jQuery.extend(true, {}, this.pictures); // set pictures in order for (i; i < order.length; i++) { // console.log(i, '=>', order[ i ], temp[ i ], '=>', temp[ order[ i ] ]); this.pictures["picture" + i] = temp["picture" + order[i]]; } }; /* * @param {string} orientation "landscape" or "portrait" */ Tracer.prototype.setOrientation = function(orientation) { this.orientation = orientation; }; /* * @param {object} image that has been moved * @param {int} index of the image that has been moved */ Tracer.prototype.setOffset = function(img, index) { this.pictures["picture" + index].preview.offsetX = ( jQuery(img).css('left') == "0px")? 0: jQuery(img).css('left').slice(0,-2) / img.clientWidth; this.pictures["picture" + index].preview.offsetY = ( jQuery(img).css('top') == "0px")? 0: jQuery(img).css('top').slice(0,-2) / img.clientHeight; }; Tracer.prototype.swapPictures = function(order) { }; /* * @param {string} type "zoom" or "2flip" or "3flip" */ Tracer.prototype.setType = function(type) { // set pictures required if ( typeof this.types[ type.toUpperCase() ] != 'undefined' ) { this.effect = type.toUpperCase(); switch (type.toUpperCase()) { case this.types.ZOOM.sku: this.type = 'ZOOM'; this.picturesRequired = 1; break; case this.types.FLIP2.sku: this.type = '2FLIP'; this.picturesRequired = 2; break; case this.types.ZOOM2.sku: this.type = '2ZOOM'; this.picturesRequired = 2; break; case this.types.FLIP3.sku: this.type = '3FLIP'; this.picturesRequired = 3; break; } return true; } return false; }; /* * @param {string} type "zoom" or "2flip" or "3flip" */ Tracer.prototype.getEffectID = function() { id = 0; return this.types[this.effect].attrib_id; }; /* * @returns {boolean} true if the tracer is ready for transform */ Tracer.prototype.validate = function() { var i = 0, count = 0; // each for (i; i < this.pictures.length; ++i) { if (typeof this.pictures["picture" + i] != "undefined") { count++; } } if (count === this.picturesRequired) { return true; } return false; }; /* * @param {object} picture * @param {number} index optional index of the new picture */ Tracer.prototype.pictureAdd = function(picture, index) { var i = 0; if (typeof picture === "undefined" || typeof picture === "number" || typeof picture === "string") { return false; } try { //if (this.pictures.length === 0 || typeof this.pictures[this.pictures.length - 1] === "undefined") { if (typeof this.pictures["picture" + index] === "undefined") { this.pictures.length = this.pictures.length + 1; } if ( index < this.picturesRequired) { this.pictures["picture" + index] = picture; } } catch (error) { return this.error({ 'error': 'pictureAdd' }); } }; /* * @param {number} index tracer picture to remove */ Tracer.prototype.pictureRemove = function(index) { if (typeof this.pictures["picture" + index] != "undefined") { delete this.pictures["picture" + index]; this.pictures.length = this.pictures.length - 1; } }; /* * @param {number} index tracer picture to check */ Tracer.prototype.pictureExists = function(index) { if (typeof this.pictures["picture" + index] != "undefined") { return true; } return false; }; /* * @param {object} picture * @return {boolean} is the picture a valid tracer picture */ Tracer.prototype.pictureValidate = function(picture) { if (!picture) { return false; } // TODO // test resolution // pass if ((picture.width > 719 && picture.height > 477) || (picture.height > 719 && picture.width > 477)) { return true; } // failed else { return false; } };