Advertisement
Guest User

Untitled

a guest
Aug 5th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 37.90 KB | None | 0 0
  1. /**********************************************************************************
  2.             Funções uteis
  3.             Copyright (c) 2013 Tuyoshi Vinicius (tuyoshi_vinicius@hotmail.com))
  4.             Version: 1.1
  5. ***********************************************************************************/
  6. $(function() {
  7.     __IMAGE_LOADING = "";
  8.     PcDialog = function(c, a, b, d, f, h, k, l, e, g) {
  9.         a = null === a ? "PictureCutDialog" + Math.round(99 * Math.random()) : a;
  10.         $dialog = $("<div></div>").attr({
  11.             id: a
  12.         });
  13.         if (0 < $("#" + a).size()) {
  14.             return !1;
  15.         }
  16.         $dialog.css({
  17.             overflow: "hidden",
  18.             "background-image": "url(" + __IMAGE_LOADING + ")",
  19.             "background-repeat": "no-repeat",
  20.             "background-position": "center"
  21.         });
  22.         $("body").prepend($dialog);
  23.         $dialog.dialog({
  24.             draggable: k,
  25.             modal: h,
  26.             width: d,
  27.             height: f,
  28.             title: b,
  29.             resizable: l,
  30.             zIndex: 100,
  31.             close: function(a, b) {
  32.                 $(this).dialog("destroy").remove();
  33.             }
  34.         });
  35.         e = null === e ? {} : e;
  36.         $.post(c, e, function(a) {
  37.             $dialog.html(a);
  38.             $dialog.css({
  39.                 "background-image": "none"
  40.             });
  41.             "function" === typeof g && g.call(this, $dialog)
  42.         });
  43.     };
  44.     PcAlert = function(c, a, b) {
  45.         b = "undefined" === typeof b ? function() {} : b;
  46.         a = "undefined" === typeof b ? "" : a;
  47.         $Dialog = $('<div id="dialog-PcAlert" ></div>').html(c).css({
  48.             padding: "15px",
  49.             "max-height": 405,
  50.             overflow: "auto"
  51.         });
  52.         $("body").prepend($Dialog);
  53.         $Dialog.dialog({
  54.             modal: !0,
  55.             resizable: !1,
  56.             zIndex: 100,
  57.             width: 450,
  58.             title: a,
  59.             buttons: {
  60.                 Ok: function() {
  61.                     $(this).dialog("destroy").remove();
  62.                     "function" === typeof b && b.call(this);
  63.                 }
  64.             },
  65.             beforeClose: function(a, b) {
  66.                 $(this).dialog("destroy").remove();
  67.             }
  68.         })
  69.     };
  70.     PcLoading = {
  71.         show: function(c, a) {
  72.             var b = $("<div id='dialog-UiConfirm' ></div>");
  73.             c = "undefined" === typeof c ? "Wait..." : c;
  74.             a = "undefined" === typeof a ? "Wait!" : a;
  75.             var d = $("<div></div>").css("margin", "15px"),
  76.                 f = $("<img src='" + __IMAGE_LOADING + "' >").css({
  77.                     "float": "left",
  78.                     "margin-right": "20px",
  79.                     "margin-top": "-5px"
  80.                 });
  81.             $MsgContent = $("<div>" + c + "</div>");
  82.             d.append(f).append($MsgContent);
  83.             b.append(d);
  84.             $("body").prepend(b);
  85.             b.dialog({
  86.                 modal: !0,
  87.                 resizable: !1,
  88.                 zIndex: 100,
  89.                 width: 450,
  90.                 title: a,
  91.                 create: function(a, b) {
  92.                     $(this).parent().children(".ui-dialog-titlebar").children(".ui-dialog-titlebar-close").hide()
  93.                 }
  94.             })
  95.         },
  96.         hide: function() {
  97.             var c = $("#dialog-UiConfirm");
  98.             0 < c.size() && c.dialog("destroy").remove();
  99.         }
  100.     }
  101. });
  102. /**********************************************************************************
  103.             uploadAjax plugin para jQuery
  104.             Copyright (c) 2013 Tuyoshi Vinicius (tuyoshi_vinicius@hotmail.com))
  105.             Version: 1.3
  106. ***********************************************************************************/
  107. (function(a) {
  108.     var f;
  109.     a.fn.uploadAjax = function(g) {
  110.         var b = a.extend({
  111.             accept: /^(jpg|png|gif)/gi,
  112.             acceptEx: "",
  113.             name: "file",
  114.             method: "POST",
  115.             url: "/",
  116.             data: !1,
  117.             onSubmit: function() {
  118.                 return !0;
  119.             },
  120.             onComplete: function() {
  121.                 return !0;
  122.             },
  123.             extError: function() {
  124.                 return !1;
  125.             }
  126.         }, g);
  127.         return this.each(function() {
  128.             var e = a(this);
  129.             e.css("position", "relative");
  130.             e.setData = function(a) {
  131.                 b.data = a;
  132.             };
  133.             var c = a('<form  method="' + b.method + '" enctype="multipart/form-data" action="' + b.url + '"> <input name="' + b.name + '" type="file" accept="' + b.acceptEx + '" /></form>'),
  134.                 h = c.find("input[name=" + b.name + "]");
  135.             h.css({
  136.                 display: "block",
  137.                 position: "absolute",
  138.                 left: 0,
  139.                 top: 0,
  140.                 width: e.width(),
  141.                 height: e.height(),
  142.                 "font-size": "100pt",
  143.                 cursor: "hand",
  144.                 opacity: 0,
  145.                 filter: "alpha(opacity=0)",
  146.                 "z-index": 10,
  147.                 overflow: "hidden"
  148.             }).attr("title", "Choose a picture");
  149.             h.on("change", function(d) {
  150.                 d = h.val().replace(/C:\\fakepath\\/i, "");
  151.                 d = d.substring(d.lastIndexOf(".") + 1);
  152.                 if (!b.accept.test(d)) {
  153.                     return b.extError.call(e, this), c.get(0).reset(), !1;
  154.                 }
  155.                 c.find("input[type=hidden]").remove();
  156.                 b.onSubmit.call(e, a(this));
  157.                 b.data && a.each(b.data, function(b, d) {
  158.                     c.append(a('<input type="hidden" name="' + b + '" value="' + d + '">'));
  159.                 });
  160.                 c.submit();
  161.                 a(c).find("input[type=file]").attr("disabled", "disabled");
  162.             });
  163.             a(e).append(c);
  164.             f || (f = a('<iframe id="picture-element-iframe" name="picture-element-iframe"></iframe>').attr("style", 'style="width:0px;height:0px;border:0px solid #fff;"').hide(), f.attr("src", ""), a(document.body).append(f));
  165.             var g = function() {
  166.                 a(c).find("input[type=file]").removeAttr("disabled");
  167.                 var d = a(this).contents().find("html body").text();
  168.                 a(c).get(0).reset();
  169.                 b.onComplete.call(e, d);
  170.                 f.unbind();
  171.             };
  172.             c.submit(function(a) {
  173.                 f.load(g);
  174.                 c.attr("target", "picture-element-iframe");
  175.                 a.stopPropagation();
  176.             });
  177.         });
  178.     };
  179. })(jQuery);
  180. /**********************************************************************************
  181.             PictureCut plugin para jQuery
  182.             Copyright (c) 2013 Tuyoshi Vinicius (tuyoshi_vinicius@hotmail.com))
  183.             Version: 1.1
  184. ***********************************************************************************/
  185. (function($) {
  186.     var methods = {
  187.         clear: function(Options) {
  188.             return this.each(function() {
  189.                 var InputOfImageDirectory = $(this).find(".picture-element-image-directory");
  190.                 InputOfImageDirectory.val("").change();
  191.             })
  192.         },
  193.         init: function(Options) {
  194.             var OptionsIfEmpty = {
  195.                 ActionToSubmitUpload: "src/php/upload.php",
  196.                 ActionToSubmitCrop: "src/php/crop.php",
  197.                 DefaultImageButton: "src/img/icon_add_image2.png"
  198.             };
  199.             var defaults = {
  200.                 Extensions: ["jpg", "png", "gif"],
  201.                 InputOfImageDirectory: "image",
  202.                 InputOfImageDirectoryAttr: {},
  203.                 InputOfFile: "",
  204.                 ActionToSubmitUpload: "",
  205.                 ActionToSubmitCrop: "",
  206.                 FolderOnServer: "",
  207.                 ThumbFolderOnServer: "",
  208.                 DataPost: {},
  209.                 DefaultImageButton: "",
  210.                 EnableCrop: false,
  211.                 EnableResize: true,
  212.                 MinimumWidthToResize: 1024,
  213.                 MinimumHeightToResize: 630,
  214.                 MaximumSize: 1024,
  215.                 EnableMaximumSize: false,
  216.                 PluginFolderOnServer: "",
  217.                 CropWindowStyle: "bootstrap",
  218.                 ImageNameRandom: true,
  219.                 EnableButton: false,
  220.                 ImageButtonCSS: {
  221.                     border: "1px #CCC solid",
  222.                     width: 170,
  223.                     height: 150
  224.                 },
  225.                 CropModes: {
  226.                     widescreen: true,
  227.                     letterbox: true,
  228.                     free: true
  229.                 },
  230.                 CropOrientation: true,
  231.                 UploadedCallback: function(response) {}
  232.             };
  233.             if (Options.ImageButtonCSS !== undefined) Options.ImageButtonCSS = $.extend(defaults.ImageButtonCSS, Options.ImageButtonCSS);
  234.             var Options = $.extend(defaults, Options);
  235.             if (Options.CropModes !== undefined) Options.CropModes = $.extend(defaults.CropModes, Options.CropModes);
  236.             if (Options.FolderOnServer === "") {
  237.                 alert("ATTENTION:\nFolderOnServer parameter must be set");
  238.                 return false;
  239.             };
  240.             if (Options.PluginFolderOnServer === "") {
  241.                 alert("ATTENTION:\nPluginFolderOnServer parameter must be set");
  242.                 return false;
  243.             } else {
  244.                 if (Options.PluginFolderOnServer.length > 0) {
  245.                     if (Options.PluginFolderOnServer.charAt(Options.PluginFolderOnServer.length - 1) !== "/") Options.PluginFolderOnServer += "/";
  246.                     if (Options.PluginFolderOnServer.charAt(0) !== "/") {
  247.                         Options.PluginFolderOnServer = "/" + Options.PluginFolderOnServer;
  248.                     }
  249.                 }
  250.             };
  251.             Options.ActionToSubmitUpload = (Options.ActionToSubmitUpload === "") ? Options.PluginFolderOnServer + OptionsIfEmpty.ActionToSubmitUpload : Options.ActionToSubmitUpload;
  252.             Options.ActionToSubmitCrop = (Options.ActionToSubmitCrop === "") ? Options.PluginFolderOnServer + OptionsIfEmpty.ActionToSubmitCrop : Options.ActionToSubmitCrop;
  253.             Options.DefaultImageButton = (Options.DefaultImageButton === "") ? Options.PluginFolderOnServer + OptionsIfEmpty.DefaultImageButton : Options.DefaultImageButton;
  254.             Options.CropWindowStyle = Options.CropWindowStyle.toLowerCase();
  255.             if (Options.InputOfFile === "") {
  256.                 Options.InputOfFile = "file-" + Options.InputOfImageDirectory;
  257.             };
  258.             __IMAGE_LOADING = Options.PluginFolderOnServer + "src/img/ajaxloader.gif";
  259.             if (Options.PastaCrop !== undefined) Options.PluginFolderOnServer = Options.PastaCrop;
  260.             if (Options.CropWindowStyle.toLowerCase() === "bootstrap") {
  261.                 var id = "picture_element_css_to_bootstrap";
  262.                 if ($("#" + id).size() === 0) {
  263.                     $('<link/>', {
  264.                         id: id,
  265.                         rel: 'stylesheet',
  266.                         type: 'text/css',
  267.                         href: Options.PluginFolderOnServer + 'src/windows/JanelaBootstrap/jquery-ui-1.10.0.custom.css'
  268.                     }).appendTo('head');
  269.                 }
  270.             };
  271.             var basic_dependence_css_id = "picture_basic_dependence_css";
  272.             if ($("#" + basic_dependence_css_id).size() === 0) {
  273.                 $('<style type="text/css" id="' + basic_dependence_css_id + '">' + ".picture-element-principal{background:url(" + Options.DefaultImageButton + ") no-repeat 50% 50%}" + ".picture-dropped{border:2px #666 dashed!important;}" + '</style>').appendTo('head')
  274.             };
  275.             return this.each(function() {
  276.                 var Elemento;
  277.                 var CropWindowStyle = {
  278.                     "jqueryui": "src/windows/window.jqueryui.php",
  279.                     "popstyle": "src/windows/window.popstyle.php",
  280.                     "bootstrap": "src/windows/window.bootstrap.php"
  281.                 };
  282.                 var $EnableButton;
  283.                 JpaneDialogCrop = function(action, titulo, w, h, wmodal, drag, resize, post, Call) {
  284.                     var Jid = "JtuyoshiCrop";
  285.                     $dialog = $("<div id='" + Jid + "' class='JtuyoshiContainerElement' ></div>");
  286.                     var posx = ($(window).width() - w) / 2;
  287.                     var posy = ($(window).height() - h) / 2;
  288.                     $dialog.css({
  289.                         "position": "absolute",
  290.                         "left": posx,
  291.                         "top": posy,
  292.                         "width": w,
  293.                         "height": h,
  294.                         "border": "1px #CCC solid",
  295.                         "background-color": "#FFF",
  296.                         "background-image": "url(" + __IMAGE_LOADING + ")",
  297.                         "background-repeat": "no-repeat",
  298.                         "background-position": "center",
  299.                         "z-index": 600,
  300.                         "-webkit-box-shadow": "0px 0px 80px 0px rgba(0, 0, 0, 0.7)",
  301.                         "box-shadow": "0px 0px 80px 0px rgba(0, 0, 0, 0.7)"
  302.                     });
  303.                     var $modal = $("<div id='JtuyoshiCrop_model' />").css({
  304.                         "position": "absolute",
  305.                         "left": 0,
  306.                         "top": 0,
  307.                         "width": "100%",
  308.                         "height": "100%",
  309.                         "border": "1px #CCC solid",
  310.                         "background-image": "url(" + __IMAGE_LOADING + ")",
  311.                         "background-image": "url(" + Options.PluginFolderOnServer + "src/img/fundo_crop.png)",
  312.                         "z-index": 598
  313.                     });
  314.                     if (wmodal) $("body").append($modal);
  315.                     $("body").append($dialog);
  316.                     $.post(action, post, function(data) {
  317.                         $dialog.html(data);
  318.                         $dialog.css({
  319.                             "background-image": "none"
  320.                         });
  321.                         if (typeof Call === "function") Call.call(this, $dialog)
  322.                     });
  323.                 };
  324.                 var TuyoshiCrop = function(element, response) {
  325.                     var response = response;
  326.                     var MontarSelecaoRecorte = function(SelecaoRecorte, state) {
  327.                         var ElemSelectProporcao,ElemSelectOrientacao;
  328.                         var Swidth = (response.currentWidth / 100) * 80;
  329.                         var Sheight = (Swidth / 16) * 9;
  330.                         SelecaoRecorte.css({
  331.                             "width": Swidth,
  332.                             "height": Sheight,
  333.                             "left": (response.currentWidth - Swidth) / 2,
  334.                             "top": (response.currentHeight - Sheight) / 2
  335.                         });
  336.                         ElemSelectProporcao = $("#JtuyoshiCrop #SelectProporcao");
  337.                         ElemSelectOrientacao = $("#JtuyoshiCrop #SelectOrientacao");
  338.                         if (state === "create") {                            
  339.                             if (Options.CropModes.widescreen || Options.CropModes.letterbox || Options.CropModes.free) {
  340.                                 ElemSelectProporcao.show()
  341.                             } else {
  342.                                 ElemSelectProporcao.hide();
  343.                                 ElemSelectOrientacao.parent().hide();
  344.                                 ElemSelectOrientacao.hide();
  345.                                 ElemSelectOrientacao.parent().hide()
  346.                             }; if (Options.CropModes.widescreen) ElemSelectProporcao.append($('<option value="wide">16:9</option>'));
  347.                             if (Options.CropModes.letterbox) ElemSelectProporcao.append($('<option value="box">4:3</option>'));
  348.                             if (Options.CropModes.free) ElemSelectProporcao.append($('<option value="livre">Free</option>'));
  349.                             if (Options.CropModes.widescreen || Options.CropModes.letterbox && (Options.CropOrientation)) {
  350.                                 ElemSelectOrientacao.append('<option value="Horizontal">Landscape</option>').append('<option value="Vertical">Portrait</option>  ')
  351.                             } else {
  352.                                 ElemSelectOrientacao.append('<option value="Horizontal" selected>Portrait</option>');
  353.                                 ElemSelectOrientacao.hide();
  354.                                 ElemSelectOrientacao.parent().hide();
  355.                             }; if (ElemSelectProporcao.find("option").size() > 0) {
  356.                                 ElemSelectProporcao.find("option:first-child").attr("selected", "selected")
  357.                             };
  358.                             SelecaoRecorte.draggable({
  359.                                 containment: "parent"
  360.                             });
  361.                             if (ElemSelectProporcao.val() === "livre") {
  362.                                 Swidth = (response.currentWidth / 100) * 80;
  363.                                 Sheight = Swidth;
  364.                                 SelecaoRecorte.css({
  365.                                     "width": Swidth,
  366.                                     "height": Sheight,
  367.                                     "left": (response.currentWidth - Swidth) / 2,
  368.                                     "top": (response.currentHeight - Sheight) / 2
  369.                                 });
  370.                                 SelecaoRecorte.resizable({
  371.                                     containment: "parent",
  372.                                     minWidth: (Swidth / 100) * 10,
  373.                                     minHeight: (Sheight / 100) * 10
  374.                                 });
  375.                             } else {
  376.                                 var InitRatio = 0;
  377.                                 if (ElemSelectProporcao.val() === "wide") {
  378.                                     InitRatio = 16 / 9;
  379.                                     Swidth = (response.currentWidth / 100) * 80;
  380.                                     Sheight = (Swidth / 16) * 9;
  381.                                 } else {
  382.                                     InitRatio = 4 / 3;
  383.                                     Swidth = (response.currentWidth / 100) * 80;
  384.                                     Sheight = (Swidth / 4) * 3;
  385.                                 };
  386.                                 SelecaoRecorte.css({
  387.                                     "width": Swidth,
  388.                                     "height": Sheight,
  389.                                     "left": (response.currentWidth - Swidth) / 2,
  390.                                     "top": (response.currentHeight - Sheight) / 2
  391.                                 });
  392.                                 SelecaoRecorte.resizable({
  393.                                     containment: "parent",
  394.                                     aspectRatio: InitRatio,
  395.                                     minWidth: (Swidth / 100) * 10,
  396.                                     minHeight: (Sheight / 100) * 10
  397.                                 });
  398.                             }
  399.                         };
  400.                         if (Sheight > response.currentHeight) {
  401.                             Sheight = (response.currentHeight / 100) * 80;
  402.                             Swidth = (Sheight * 16) / 9;
  403.                             SelecaoRecorte.css({
  404.                                 "width": Swidth,
  405.                                 "height": Sheight,
  406.                                 "left": (response.currentWidth - Swidth) / 2,
  407.                                 "top": (response.currentHeight - Sheight) / 2
  408.                             });                                                                            
  409.                         };
  410.                         ElemSelectProporcao.change();
  411.                     };
  412.                     var Redimencionar_Janela = function() {
  413.                         if ((response.currentWidth + 80) > 410) {
  414.                             if (Options.CropWindowStyle === "jqueryui") {
  415.                                 $("#JtuyoshiCrop").dialog("option", {
  416.                                     "width": response.currentWidth + 40,
  417.                                     "height": response.currentHeight + 110
  418.                                 });
  419.                                 $("#JtuyoshiCrop").dialog("option", "position", {
  420.                                     my: "center",
  421.                                     at: "center",
  422.                                     of: window
  423.                                 });
  424.                             } else if (Options.CropWindowStyle === "popstyle") {
  425.                                 var posx = ($(window).width() - response.currentWidth) / 2;
  426.                                 var posy = ($(window).height() - response.currentHeight) / 2;
  427.                                 $("#JtuyoshiCrop").css({
  428.                                     "width": response.currentWidth,
  429.                                     "height": response.currentHeight,
  430.                                     "left": posx,
  431.                                     "top": posy
  432.                                 });
  433.                             } else if (Options.CropWindowStyle === "bootstrap") {
  434.                                 $("#JtuyoshiCrop").dialog("option", {
  435.                                     "width": response.currentWidth + 40,
  436.                                     "height": response.currentHeight + 130
  437.                                 });
  438.                                 $("#JtuyoshiCrop").dialog("option", "position", {
  439.                                     my: "center",
  440.                                     at: "center",
  441.                                     of: window
  442.                                 });
  443.                             }
  444.                         } else {
  445.                             if (Options.CropWindowStyle === "jqueryui") {
  446.                                 $("#JtuyoshiCrop").dialog("option", {
  447.                                     "width": 410,
  448.                                     "height": response.currentHeight + 110
  449.                                 });
  450.                                 $("#JtuyoshiCrop").dialog("option", "position", {
  451.                                     my: "center",
  452.                                     at: "center",
  453.                                     of: window
  454.                                 });
  455.                             } else if (Options.CropWindowStyle === "popstyle") {
  456.                                 var posx = ($(window).width() - 410) / 2;
  457.                                 var posy = ($(window).height() - response.currentHeight) / 2;
  458.                                 $("#JtuyoshiCrop").css({
  459.                                     "width": 410,
  460.                                     "height": response.currentHeight,
  461.                                     "left": posx,
  462.                                     "top": posy
  463.                                 });
  464.                             } else if (Options.CropWindowStyle === "bootstrap") {
  465.                                 $("#JtuyoshiCrop").dialog("option", {
  466.                                     "width": 410,
  467.                                     "height": response.currentHeight + 130
  468.                                 });
  469.                                 $("#JtuyoshiCrop").dialog("option", "position", {
  470.                                     my: "center",
  471.                                     at: "center",
  472.                                     of: window
  473.                                 });
  474.                             }
  475.                         }
  476.                     };
  477.                     var Dborder = 2;
  478.                     var Carregar_Imagem = function(Principal, Imagem) {
  479.                         Principal.css({
  480.                             "border": Dborder + "px #ccc solid",
  481.                             "width": response.currentWidth,
  482.                             "height": response.currentHeight
  483.                         });
  484.                         Imagem.css({
  485.                             "width": response.currentWidth,
  486.                             "height": response.currentHeight
  487.                         }).attr("src", Options.FolderOnServer + response.currentFileName + "?" + Math.round(Math.random() * 9999))
  488.                     };
  489.                     var JpaneDialogCallBack = function() {
  490.                         $.getScript(Options.PluginFolderOnServer + "src/windows/core/window.pc.js");
  491.                         var Principal = $("#JtuyoshiCrop #Principal");
  492.                         var Imagem = $("<img />");
  493.                         Principal.append(Imagem);
  494.                         Carregar_Imagem(Principal, Imagem);
  495.                         MontarSelecaoRecorte($("#JtuyoshiCrop #SelecaoRecorte"), "create");
  496.                         Redimencionar_Janela();
  497.                         $("#JtuyoshiCrop #button_crop_original").bind("click", function() {
  498.                             Retorno_Requisicao(element, response, 1)
  499.                         });
  500.                         $("#JtuyoshiCrop #button_crop_recortar").bind("click", function() {
  501.                             var thisRecort = $(this);
  502.                             thisRecort.attr("disabled", "disabled");
  503.                             PcLoading.show();
  504.                             var data = response;
  505.                             data["request"] = "crop";
  506.                             data["folderOnServer"] = Options.FolderOnServer;
  507.                             data["inputOfFile"] = Options.InputOfFile;
  508.                             data["maximumSize"] = Options.MaximumSize;
  509.                             data["enableMaximumSize"] = Options.EnableMaximumSize;
  510.                             data["toCropImgX"] = $("#JtuyoshiCrop #SelecaoRecorte").position().left;
  511.                             data["toCropImgY"] = $("#JtuyoshiCrop #SelecaoRecorte").position().top;
  512.                             data["toCropImgW"] = $("#JtuyoshiCrop #SelecaoRecorte").width();
  513.                             data["toCropImgH"] = $("#JtuyoshiCrop #SelecaoRecorte").height();
  514.                             data["currentFileName"] = response["currentFileName"].substring(response["currentFileName"].lastIndexOf('/') + 1);
  515.                             var url = (Options.ActionToSubmitCrop === "") ? Options.ActionToSubmitUpload : Options.ActionToSubmitCrop;
  516.                             $.post(url, data, function(data) {
  517.                                 thisRecort.removeAttr("disabled");
  518.                                 PcLoading.hide();
  519.                                 response = data;
  520.                                 response.currentWidth = parseInt(response.currentWidth);
  521.                                 response.currentHeight = parseInt(response.currentHeight);
  522.                                 Carregar_Imagem(Principal, Imagem);
  523.                                 MontarSelecaoRecorte($("#JtuyoshiCrop #SelecaoRecorte"));
  524.                                 Redimencionar_Janela();
  525.                             }, "JSON");
  526.                         });
  527.                     };
  528.                     if (Options.CropWindowStyle === "jqueryui") PcDialog(Options.PluginFolderOnServer + CropWindowStyle[Options.CropWindowStyle], "JtuyoshiCrop", "Crop image", 900, 555, true, true, false, null, JpaneDialogCallBack);
  529.                     else if (Options.CropWindowStyle === "popstyle") JpaneDialogCrop(Options.PluginFolderOnServer + CropWindowStyle[Options.CropWindowStyle], "Crop image", 980, 555, true, false, false, null, JpaneDialogCallBack);
  530.                     else if (Options.CropWindowStyle === "bootstrap") PcDialog(Options.PluginFolderOnServer + CropWindowStyle[Options.CropWindowStyle], "JtuyoshiCrop", "Crop image", 900, 555, true, true, false, null, JpaneDialogCallBack)
  531.                 };
  532.                 var Construir_Widget = function(element) {
  533.                     element.css($.extend(Options.ImageButtonCSS, {
  534.                         "position": "relative",
  535.                         "cursor": "pointer",
  536.                         "overflow": "hidden"
  537.                     })).addClass("picture-element-principal");
  538.                     element.on('dragenter', function(e) {
  539.                         if ($(e.target).attr("name") === Options.InputOfFile) {
  540.                             element.addClass("picture-dropped")
  541.                         } else {
  542.                             element.removeClass("picture-dropped")
  543.                         };
  544.                         e.stopPropagation();
  545.                         e.preventDefault();
  546.                     });
  547.                     $(document).on('drop dragend', function(e) {
  548.                         console.log(element);
  549.                         element.removeClass("picture-dropped");
  550.                         e.stopPropagation();
  551.                     });
  552.                     element.on("mouseout", function(e) {
  553.                         element.removeClass("picture-dropped");
  554.                         e.stopPropagation()
  555.                     });
  556.                     var $image = $("<img src='data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==' class='picture-element-image'>");
  557.                     $image.css({
  558.                         "position": "relative",
  559.                         "cursor": "pointer"
  560.                     });
  561.                     $image.css({
  562.                         "height": Options.ImageButtonCSS.height
  563.                     });
  564.                     element.append($image);
  565.                     var $inputHidden = $("<input type='hidden' name='" + Options.InputOfImageDirectory + "' id='" + Options.InputOfImageDirectory + "'>");
  566.                     $inputHidden.addClass("picture-element-image-directory");
  567.                     element.append($inputHidden);
  568.                     $inputHidden.attr(Options.InputOfImageDirectoryAttr);
  569.                     $inputHidden.bind('change', function() {
  570.                         if ($(this).val() !== "") {
  571.                             var image_thumb;
  572.                             if (Options.ThumbFolderOnServer !== "") image_thumb = Options.ThumbFolderOnServer + $(this).val().substring($(this).val().lastIndexOf("/") + 1);
  573.                             else image_thumb = Options.FolderOnServer + $(this).val().substring($(this).val().lastIndexOf("/") + 1);
  574.                             $image.removeAttr("style");
  575.                             $image.css({
  576.                                 "position": "relative",
  577.                                 "cursor": "pointer"
  578.                             });
  579.                             $image.attr("src", image_thumb);
  580.                             if (Options.EnableButton) {
  581.                                 $EnableButton.unbind("click").bind("click", function() {
  582.                                     $inputHidden.val("").change();
  583.                                 }).val("Remove Picture");
  584.                             };
  585.                             $image.on("load", function() {
  586.                                 console.log("load");
  587.                                 if ($(this).height() < $(this).width()) {
  588.                                     $(this).css({
  589.                                         "height": Options.ImageButtonCSS.height
  590.                                     });
  591.                                     $(this).css({
  592.                                         "width": "none"
  593.                                     });
  594.                                 } else if ($(this).width() < $(this).height()) {
  595.                                     $(this).css({
  596.                                         "width": Options.ImageButtonCSS.width
  597.                                     });
  598.                                     $(this).css({
  599.                                         "height": "none"
  600.                                     });
  601.                                 } else {
  602.                                     $(this).css({
  603.                                         "width": Options.ImageButtonCSS.width
  604.                                     });
  605.                                     $(this).css({
  606.                                         "height": Options.ImageButtonCSS.height
  607.                                     });
  608.                                 }
  609.                             }).each(function() {
  610.                                 if (this.complete) $(this).load();
  611.                             })
  612.                         } else {
  613.                             $image.attr("src", 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');
  614.                             if (Options.EnableButton) {
  615.                                 $EnableButton.unbind("click").bind("click", function() {
  616.                                     Elemento.find("input[name='" + Options.InputOfFile + "']:file").click()
  617.                                 }).val("Selecionar imagem")
  618.                             }
  619.                         }
  620.                     })
  621.                 };
  622.                 var getExt = function(name) {
  623.                     return name.slice(name.lastIndexOf(".") + 1);
  624.                 };
  625.                 var Setando_AjaxUpload = function(element) {
  626.                     var post = Options.DataPost;
  627.                     post["request"] = "upload";
  628.                     post["inputOfFile"] = Options.InputOfFile;
  629.                     post["enableResize"] = Options.EnableResize;
  630.                     post["minimumWidthToResize"] = Options.MinimumWidthToResize;
  631.                     post["minimumHeightToResize"] = Options.MinimumHeightToResize;
  632.                     post["folderOnServer"] = Options.FolderOnServer;
  633.                     post["imageNameRandom"] = Options.ImageNameRandom;
  634.                     post["maximumSize"] = Options.MaximumSize;
  635.                     post["enableMaximumSize"] = Options.EnableMaximumSize;
  636.                     var CustomRegex = new RegExp("^(" + Options.Extensions.join("|") + ")", "i");
  637.                     element.uploadAjax({
  638.                         accept: CustomRegex,
  639.                         acceptEx: "image/*",
  640.                         name: Options.InputOfFile,
  641.                         method: 'POST',
  642.                         url: Options.ActionToSubmitUpload,
  643.                         data: post,
  644.                         onSubmit: function() {
  645.                             PcLoading.show()
  646.                         },
  647.                         onComplete: function(response) {
  648.                             var response = $.parseJSON(response);
  649.                             PcLoading.hide();
  650.                             if (response.status) {
  651.                                 Retorno_Requisicao(element, response);
  652.                             } else {
  653.                                 PcAlert(response.errorMessage, "Attention");
  654.                             }
  655.                         },
  656.                         extError: function() {
  657.                             PcAlert("types are supported: " + (Options.Extensions.join(",")).toString(), "Attention")
  658.                         }
  659.                     });
  660.                     element.find(":file[name='" + Options.InputOfFile + "']").mouseenter(function() {
  661.                         element.addClass("TuyoshiImageUpload_div");
  662.                     }).mouseout(function() {
  663.                         element.removeClass("TuyoshiImageUpload_div");
  664.                     })
  665.                 };
  666.                 var Retorno_Requisicao = function(element, response, concluir) {
  667.                     var response = response;
  668.                     var ColocarImagemNoBox = function() {
  669.                         var InputOfImage = element.children("input[name='" + Options.InputOfImageDirectory + "']");
  670.                         InputOfImage.val(Options.FolderOnServer + response.currentFileName).change();
  671.                         if (typeof(Options.UploadedCallback) === 'function') {
  672.                             var data_response = response;
  673.                             data_response["options"] = {
  674.                                 "FolderOnServer": Options.FolderOnServer
  675.                             };
  676.                             Options.UploadedCallback.call(this, response)
  677.                         }
  678.                     };
  679.                     if (concluir === 1 || !Options.EnableCrop) {
  680.                         if (Options.CropWindowStyle === "jqueryui" || Options.CropWindowStyle === "bootstrap") {
  681.                             $("#JtuyoshiCrop").dialog("destroy").remove();
  682.                         } else if (Options.CropWindowStyle === "popstyle") {
  683.                             $("#JtuyoshiCrop").remove();
  684.                             $("#JtuyoshiCrop_model").remove();
  685.                         };
  686.                         ColocarImagemNoBox();
  687.                     } else {
  688.                         TuyoshiCrop(element, response);
  689.                     }
  690.                 };
  691.                 $(this).html("");
  692.                 Elemento = $(this);
  693.                 Construir_Widget(Elemento);
  694.                 Setando_AjaxUpload(Elemento);
  695.                 if (Options.EnableButton) {
  696.                     $EnableButton = $("<input type='button' value='Selecionar imagem' />").button().css({
  697.                         "font-size": "12px",
  698.                         "margin-top": 5,
  699.                         "margin-left": "-0.5px"
  700.                     });
  701.                     Elemento.after($EnableButton);
  702.                     $EnableButton.unbind("click").bind("click", function() {
  703.                         Elemento.find("input[name='" + Options.InputOfFile + "']:file").click()
  704.                     });
  705.                 }
  706.             });
  707.         }
  708.     };
  709.     $.fn.PictureCut = function(MetodoOuOptions) {
  710.         if (window.jQuery.ui === undefined) alert("Could not instantiate the PictureCut is missing jquery.ui");
  711.         else {
  712.             if (methods[MetodoOuOptions]) return methods[MetodoOuOptions].apply(this, Array.prototype.slice.call(arguments, 1));
  713.             else if (typeof MetodoOuOptions === 'object' || !MetodoOuOptions) return methods.init.apply(this, arguments);
  714.         }
  715.     };
  716. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement