title: How to activate Jcrop selection after ajax load
body: <p>I am using Jcrop on my project. The problem is not critical but would be better if I can fix it.</p>
  
  <p>I can upload an image via ajax request (not Jquery ajax) and image could load to page after upload without page refresh. Until now, everything works great. After image loaded into page, Jrop doesn't become active without refreshing page. Here is Jcrop activator script:</p>
  
  <pre><code>    jQuery(window).load(function(){
        jQuery('#cropbox').Jcrop({
          onChange: showPreview,
          onSelect: showPreview,
          aspectRatio: 3/4
        });
      });
  </code></pre>
  
  <p>I am not sure is it important, this script is not inside $(document).ready(function(){}. </p>
  
  <p>I tried triggering Jcrop with $('#cropbox').load and $('#cropbox').click functions instead of jQuery(window).load(function(){} function but nothing happened. </p>
  
  <p>Do you have any idea? Is that possible to activate Jcrop just after loading image into page via ajax request without refreshing browser?</p>
  
  <p>Here is Jcrop usage:</p>
  
  <pre><code>// Remember to invoke within jQuery(window).load(...)
  // If you don't, Jcrop may not initialize properly
  $(window).load(function(){
                  var imgWidth = $('#cropbox').width();
                  var imgHeight = $('#cropbox').height();
  
                  $('#cropbox').Jcrop({
  
                      onChange: showPreview,
                      onSelect: showPreview,
                      aspectRatio: 3/4,
                      setSelect: [ ((imgWidth/2)-60), 60, ((imgWidth/2)+60), 220 ],
                      addClass: 'custom',
                      bgColor: 'yellow',
                      bgOpacity: .8,
                      sideHandles: false
  
                  });
  
              });
  </code></pre>
  
  <p>And image upload button:</p>
  
  <pre><code>&lt;button onclick="ajaxUpload(this.form,'http://www.yemeklog.com/ajax/ajaxupload.php?filename=filename&amp;amp;maxSize=9999999999&amp;amp;maxW=400&amp;amp;fullPath=http://www.yemeklog.com/images/users/160/&amp;amp;relPath=../images/users/160/&amp;amp;colorR=120&amp;amp;colorG=120&amp;amp;colorB=120&amp;amp;maxH=600','upload_area','&amp;lt;img src=\'http://static.yemeklog.com/images/ajax-bar-loader.gif\' width=\'220\' height=\'19\' border=\'0\' /&amp;gt;','&amp;lt;img src=\'images/error.gif\' width=\'16\' height=\'16\' border=\'0\' /&amp;gt; An error occured. Please contact.'); return false;"&gt;Upload Image&lt;/button&gt;
  </code></pre>
  
  <p>And ajaxupload.js file:</p>
  
  <pre><code>function $m(theVar){
      return document.getElementById(theVar)
  }
  function remove(theVar){
      var theParent = theVar.parentNode;
      theParent.removeChild(theVar);
  }
  function addEvent(obj, evType, fn){
      if(obj.addEventListener)
          obj.addEventListener(evType, fn, true)
      if(obj.attachEvent)
          obj.attachEvent("on"+evType, fn)
  }
  function removeEvent(obj, type, fn){
      if(obj.detachEvent){
          obj.detachEvent('on'+type, fn);
      }else{
          obj.removeEventListener(type, fn, false);
      }
  }
  function isWebKit(){
      return RegExp(" AppleWebKit/").test(navigator.userAgent);
  }
  function ajaxUpload(form,url_action,id_element,html_show_loading,html_error_http){
      var detectWebKit = isWebKit();
      form = typeof(form)=="string"?$m(form):form;
      var erro="";
      if(form==null || typeof(form)=="undefined"){
          erro += "Hata kodu: 1.\n";
      }else if(form.nodeName.toLowerCase()!="form"){
          erro += "Hata kodu: 2.\n";
      }
      if($m(id_element)==null){
          erro += "Hata kodu: 3.\n";
      }
      if(erro.length&gt;0){
          alert("Yükleme esnasında hata oluştu:\n" + erro);
          return;
      }
      var iframe = document.createElement("iframe");
      iframe.setAttribute("id","ajax-temp");
      iframe.setAttribute("name","ajax-temp");
      iframe.setAttribute("width","0");
      iframe.setAttribute("height","0");
      iframe.setAttribute("border","0");
      iframe.setAttribute("style","width: 0; height: 0; border: none;");
      form.parentNode.appendChild(iframe);
      window.frames['ajax-temp'].name="ajax-temp";
      var doUpload = function(){
          removeEvent($m('ajax-temp'),"load", doUpload);
          var cross = "javascript: ";
          cross += "window.parent.$m('"+id_element+"').innerHTML = document.body.innerHTML; void(0);";
          $m(id_element).innerHTML = html_error_http;
          $m('ajax-temp').src = cross;
          if(detectWebKit){
              remove($m('ajax-temp'));
          }else{
              setTimeout(function(){ remove($m('ajax-temp'))}, 250);
          }
          $('#ajax_image_container').slideDown('slow');
      }
      addEvent($m('ajax-temp'),"load", doUpload);
      form.setAttribute("target","ajax-temp");
      form.setAttribute("action",url_action);
      form.setAttribute("method","post");
      form.setAttribute("enctype","multipart/form-data");
      form.setAttribute("encoding","multipart/form-data");
      if(html_show_loading.length &gt; 0){
          $m(id_element).innerHTML = html_show_loading;
      }
      form.submit();
  }
  </code></pre>