o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1367856780.3765178: @value"Ú%{I" class:EFI"ProcessedAsset;FI"logical_path;FI"!crimagify/actions_cropper.js;TI" pathname;FI"`/Users/juantrejo/projects/crimagify/app/assets/javascripts/crimagify/actions_cropper.js.erb;TI"content_type;FI"application/javascript;FI" mtime;FI"2013-05-06T09:12:23-06:00;FI" length;Fi”"I" digest;F"%5142c70e668847ad14c9b949ef4052b5I" source;FI"”"//section for read ENV variables var ajstring = '{"User":{"imgA":{"big":{"width":"800","height":"700"},"user":{"width":"50","height":"50"}},"imgB":{"big":{"width":"600","height":"300"},"user":{"width":"600","height":"600"}},"imgC":{"big":{"width":"57","height":"59"},"user":{"width":"600","height":"600"}},"imgD":{"big":{"width":"57","height":"59"},"user":{"width":"600","height":"600"}},"imgE":{"big":{"width":"57","height":"59"},"user":{"width":"600","height":"600"},"gigant":{"width":"600","height":"600"}},"imgF":{"big":{"width":"57","height":"59"},"user":{"width":"600","height":"600"}}},"Product":{"imgA":{"big":{"width":"800","height":"700"},"user":{"width":"50","height":"50"}},"imgB":{"big":{"width":"600","height":"300"},"user":{"width":"600","height":"600"}},"imgC":{"big":{"width":"600","height":"300"},"user":{"width":"600","height":"600"},"gigant":{"width":"300","height":"600"}}}}'; var ajson = JSON.parse(ajstring); //======================================================================================== var render_image = ""; var array_names = []; $(function(){ // Events only for crimagify without nested models $(".uploader").on("change", function(evt){ //this variable is used for identify on what section pu the resultant image var $this = $(this); var parent_element_id = $this.closest('.global_parent').attr("id"); var name_version = $this.closest('.global_parent').attr("name"); if (validate_image(evt) == true) { var reader =  new FileReader(); reader.onloadend = function(e){ render_image_temporal(e.target.result, parent_element_id, name_version); render_image = e.target.result; }; reader.readAsDataURL(evt.target.files[0]); }else{ $this.val(''); }; }); // Events only for crimagify with nested models $(".nested_crimagify_images").on("change",".nested_uploader",function(evt){ $this = $(this); var $cropper = $("#cropper_div"); // TYPE: user, big, small, etc var name_version = $this.closest(".global_parent").attr("name"); // SECTION CROPPER: imgaA, imgB, imgC, etc var parent_element_type = $this.closest(".global_parent").data("img"); // ID FIELDSET var parent_tag_id = $this.closest(".fieldset_crimagify_nested").attr("id"); if($cropper.length){ $cropper.fadeOut(1000, function(){ $cropper.remove(); if (validate_image(evt) == true) { var reader =  new FileReader(); reader.onloadend = function(e){ render_image_temporal_nested(e.target.result,parent_tag_id,name_version,parent_element_type); render_image = e.target.result; }; reader.readAsDataURL(evt.target.files[0]); }else{ $this.val(''); }; }); }else{ if (validate_image(evt) == true) { var reader =  new FileReader(); reader.onloadend = function(e){ render_image_temporal_nested(e.target.result,parent_tag_id,name_version,parent_element_type); render_image = e.target.result; }; reader.readAsDataURL(evt.target.files[0]); }else{ $this.val(''); }; } }); $(".nested_crimagify_images").on("click",".cancel_crop",function(evt){ evt.preventDefault(); $("#cropper_div").hide("slow", function(){ $("#cropper_div").remove(); }); $(".nested_uploader").val(''); }); // $(".parent_image").on("click",".crop_image",function(){ $(".nested_crimagify_images").on("click",".crop_image",function(){ //parent_element_id is filled with the value of DIV parent closest: "imgA","imgB","imgZ" parameters($(this)); }); // $(".nested_crimagify_images").on("click", ".crop_image", function(){ // var parent_element_id = $(this).closest('.global_parent').data("img"); // console.log(parent_element_id); // //parameters(parent_element_id); //    }); }); function validate_image(evt,callback){ var size = evt.target.files[0].size/1024; var type = evt.target.files[0].type; var max_size = '0.5' if (max_size != "") { max_size = max_size*1024 } else{ max_size = 2048; }; if (type == "image/jpeg" || type == "image/png") { if (size <= max_size) { return true; } else{ alert("Please select an image more than small "); return false; }; } else{ alert("Please select an image file"); return false; }; }; function render_image_temporal_nested(url, parent_tag_id, name_version, type_img){ $.ajax({ url: "/crimagify/partial_nested_cropper", type: "POST", data: { "image": url, "parent_element_id" : parent_tag_id, "type_img":type_img }, dataType: "script", complete: function(event){ load_partial_nested(parent_tag_id, name_version, type_img); }, error: function(x,y,z){ console.log(x); console.log(y); console.log(z); } }); } function render_image_temporal(url, parent_element_id, name_version){ $.ajax({ url: "/crimagify/partial_cropper", type: "POST", data: { "image": url, "parent_element_id" : parent_element_id }, dataType: "script", complete: function(event){ load_partial(parent_element_id, name_version); }, error: function(x,y,z){ console.log(x); console.log(y); console.log(z); } }); }; function update_crop(coords){ $("#crop_x").val(coords.x); $("#crop_y").val(coords.y); $("#crop_w").val(coords.w); $("#crop_h").val(coords.h); // updatePreview(coords); }; function updatePreview(coords){ $('#preview').css({ width: Math.round(100/coords.w * $('#cropbox').width()) + 'px', height: Math.round(100/coords.h * $('#cropbox').height()) + 'px', marginLeft: '-' + Math.round(100/coords.w * coords.x) + 'px', marginTop: '-' + Math.round(100/coords.h * coords.y) + 'px' }); }; function load_partial(parent_tag_id, name_version){ var select = []; var ratio; var parent = $("#parent").val(); var ratio_vals = ajson[parent][parent_tag_id][name_version] var max_width_box = '' var max_height_box = '' if (max_width_box == "") { max_width_box = 500; }; if (max_height_box == "") { max_height_box = 500; }; select = [0,0,ratio_vals['width'],ratio_vals['height']] ratio = ratio_vals['width']/ratio_vals['height'] if ($("#cropbox").length) { $('#cropbox').Jcrop({ onChange: update_crop, onSelect: update_crop, setSelect: select, aspectRatio: ratio, boxWidth: max_width_box, boxHeight: max_height_box }, function(){ var api = this; api.ui.holder.addClass('jcrop-dark'); api.setOptions({ bgColor: 'black', bgOpacity: 0.5}); }); } else{ alert("el elemento no se encuentra en la pagina") }; }; function load_partial_nested(parent_tag_id, name_version, type_img){ var select = []; var parent = $("#"+parent_tag_id).find(".parent").val(); var ratio_vals = ajson[parent][type_img][name_version]; var max_width_box = ''; var max_height_box = ''; if (max_width_box == "") { max_width_box = 500; } if (max_height_box == "") { max_height_box = 500; } select = [0,0,ratio_vals.width,ratio_vals.height]; var ratio = ratio_vals.width/ratio_vals.height; if ($("#cropper_div").find(".cropbox").length) { $("#cropper_div").find(".cropbox").Jcrop({ onChange: update_crop, onSelect: update_crop, setSelect: select, aspectRatio: ratio, boxWidth: max_width_box, boxHeight: max_height_box }, function(){ var api = this; api.ui.holder.addClass('jcrop-dark'); api.setOptions({ bgColor: 'black', bgOpacity: 0.5}); }); } else{ alert("el elemento no se encuentra en la pagina"); }; }; function parameters($crop){ var $parent_tag = $crop.closest(".global_parent"); var parent_tag_id = $parent_tag.attr("id")==undefined?$parent_tag.data("img"):$parent_tag.attr("id"); var data = {}; if($parent_tag.closest(".fieldset_crimagify_nested").length){ data = {"image": render_image, "parent_id": $parent_tag.closest(".fieldset_crimagify_nested").find(".parent_id").val(), "crop_x": $("#crop_x").val(), "crop_y": $("#crop_y").val(), "crop_w": $("#crop_w").val(), "crop_h": $("#crop_h").val(), "parent": $parent_tag.closest(".fieldset_crimagify_nested").find(".parent").val(), "parent_element_id" : parent_tag_id, "parent_fieldset": $parent_tag.closest(".fieldset_crimagify_nested").attr("id") }; }else{ data = {"image": render_image, "parent_id": $("#parent_id").val(), "crop_x": $("#crop_x").val(), "crop_y": $("#crop_y").val(), "crop_w": $("#crop_w").val(), "crop_h": $("#crop_h").val(), "parent": $("#parent").val(), "parent_element_id" : parent_tag_id }; array_names.push(parent_tag_id); } $.ajax({ url: "/crimagify/params_cropper", type: "POST", data: data, dataType: "script", success: function(){ $("#cropper_div").hide("slow", function(){ $("#cropper_div").remove(); }); }, error: function(a,b,c){ console.log("error a"); console.dir(a); console.log("error b"); console.dir(b); console.log("error c"); console.dir(c); } }); }; ;TI"dependency_digest;F"%e6f642c86fe366a4ca53573b95c2c49aI"required_paths;F[I"`/Users/juantrejo/projects/crimagify/app/assets/javascripts/crimagify/actions_cropper.js.erb;TI"dependency_paths;F[{I" path;FI"`/Users/juantrejo/projects/crimagify/app/assets/javascripts/crimagify/actions_cropper.js.erb;TI" mtime;FI"2013-05-06T09:12:23-06:00;FI" digest;F"%2953a0dedc65ef7fbdcb2dbdaa4134ecI" _version;F"%6776f581a4329e299531e1d52aa59832