o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1368743800.461323: @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-16T16:36:38-06:00;FI" length;Fiâ*I" digest;F"%cc4ffe9fd02999d807952c540ef52c6aI" 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(){ $body = $('body'); // Events only for crimagify without nested models $body.on("change",".uploader", function(evt){ var $this = $(this); var $div_closest = $this.closest('.global_parent'); var $cropper = $("#cropper_div"); var parent_element_id = $div_closest.attr("id"); var name_version = $div_closest.attr("name"); $div_closest.find('.crimagify_inputs').hide(); $div_closest.find('.crimagify_loader').show(); setTimeout(function(){ if($cropper.length){ $cropper.hide('slow', function(){ //$cropper.closest('div.global_parent').find('.uploader').val(''); $cropper.hide('slow', function(){ $cropper.remove(); }); 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{ $div_closest.find('.crimagify_inputs').show(); $div_closest.find('.crimagify_loader').hide(); $this.val(''); }; }); }else{ 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{ $div_closest.find('.crimagify_inputs').show(); $div_closest.find('.crimagify_loader').hide(); $this.val(''); }; } }, 1000); }); // Events only for crimagify with nested models $(".nested_crimagify_images").on("change",".nested_uploader",function(evt){ $this = $(this); var $cropper = $("#cropper_div"); var $div_closest = $this.closest('.global_parent'); // TYPE: user, big, small, etc var name_version = $div_closest.attr("name"); // SECTION CROPPER: imgaA, imgB, imgC, etc var parent_element_type = $div_closest.data("img"); // ID FIELDSET var parent_tag_id = $this.closest(".fieldset_crimagify_nested").attr("id"); $div_closest.find('.crimagify_inputs').hide(); $div_closest.find('.crimagify_loader').show(); setTimeout(function(){ 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{ $div_closest.find('.crimagify_inputs').show(); $div_closest.find('.crimagify_loader').hide(); $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{ $div_closest.find('.crimagify_inputs').show(); $div_closest.find('.crimagify_loader').hide(); $this.val(''); }; } }, 1000) }); /*===== Cancel Crop ======*/ $body.on("click",".cancel_crop",function(evt){ evt.preventDefault(); var $this = $(this); var $div_closest = $this.closest('.global_parent'); $("#cropper_div").hide("slow", function(){ $("#cropper_div").remove(); }); $div_closest.find('.crimagify_inputs').show(); $div_closest.find('.crimagify_loader').hide(); $(".nested_uploader").val(''); }); $body.on("click",'.cancel_crop',function(evt){ evt.preventDefault(); var $this = $(this); var $div_closest = $this.closest('.global_parent'); $("#cropper_div").hide("slow", function(){ $("#cropper_div").remove(); }); $div_closest.find('.crimagify_inputs').show(); $div_closest.find('.crimagify_loader').hide(); $(".uploader").val(''); }); /*====== Crop Image ========*/ $body.on("click",".crop_image",function(){ //parent_element_id is filled with the value of DIV parent closest: "imgA","imgB","imgZ" parameters($(this)); $('a.actions_links').hide(); $(this).next('img.loader_image').show(); }); $body.on("click",'.crop_image',function(){ //parent_element_id is filled with the value of DIV parent closest: "imgA","imgB","imgZ" parameters($(this)); $('a.actions_links').hide(); $(this).next('img.loader_image').show(); }); }); 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(){ setTimeout(function() { $("#cropper_div").hide("slow", function(){ $("#cropper_div").remove(); }); }, 600); $parent_tag.find('.crimagify_inputs').show(); $parent_tag.find('.crimagify_loader').hide(); }, 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); $('a.actions_links').hide(); $('a.actions_links').next('img.loader_image').show(); } }); }; ;TI"dependency_digest;F"%47647ea38406379585a4449c172fddceI"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-16T16:36:38-06:00;FI" digest;F"%b8811752a75a3abee143ece4cb920122I" _version;F"%6776f581a4329e299531e1d52aa59832