Jump to content

Canvas Object - Add JavaScript 3rd Party Code - How ?


andyhill

Recommended Posts

I am trying to add JavaScript 3rd Party Crop to a canvas (cArea) object.

This usually works in unigui when dealing with an element within a htmlframe but I am struggling with canvas implementation - please advise how ? Thanks

 

SERVERMODULE // https://cdnjs.com/libraries/jquery-jcrop
 
CustomFiles.Add('<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.15/js/jquery.Jcrop.min.js" integrity="sha512-KKpgpD20ujD3yJ5gIJqfesYNuisuxguvTMcIrSnqGQP767QNHjEP+2s1WONIQ7j6zkdzGD4zgBHUwYmro5vMAw==" crossorigin="anonymous"></script>');
 
CustomCSS.Add('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.15/css/jquery.Jcrop.min.css" integrity="sha512-bbAsdySYlqC/kxg7Id5vEUVWy3nOfYKzVHCKDFgiT+GsHG/3MD7ywtJnJNSgw++HBc+w4j71MLiaeVm1XY5KDQ==" crossorigin="anonymous" />');

 

FORM CREATE
  Script.Clear;
  s:= '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.15/css/jquery.Jcrop.min.css">';
  //Script.Add(s); FAILS

  cArea ExtEvents
  s:= 'updatePreview=function updatePreview(c) '+
      '{ '+
      '  if(parseInt(c.w) > 0) '+
      '  { '+
      '    ajaxRequest(fMain.cArea, "getCroppedXY", ["cx="+c.x, "cy="+c.y, "cw="+c.w, "ch="+c.h]); '+
      '  } '+
      '}';
  cArea.ClientEvents.ExtEvents.Add(s);
 
  s:= 'fetchImage=function fetchImage(c) '+
      '{ '+
      '  ajaxRequest(fMain.cArea, "getCroppedImg", ["cx="+c.x, "cy="+c.y, "cw="+c.w, "ch="+c.h]); '+
      '}';
  cArea.ClientEvents.ExtEvents.Add(s);

 

...


FORM CANVAS REQUEST VIA BUTTON EVENT (Jcrop / a.Jcrop FAILS ???)
    with cArea, JSInterface do begin
      JSCode('var a = document.getElementById("'+JSName+'_canvas"); a.Jcrop({'+
                                                                             'options: {'+
                                                                             '           allowResize: true, '+
                                                                             '           allowMove: true, '+
                                                                             '           enableHandles: true'+
                                                                             '         }, '+
                                                                             'onSelect: a.updatePreview, '+
                                                                             'onDblClick: a.fetchImage'+
                                                                             '});');
    end; // with
 

Link to comment
Share on other sites

  • andyhill changed the title to Canvas Object - Add JavaScript 3rd Party Code - How ?

Here is one of my many attempts, does not crash, does not work.

    with cArea, JSInterface do begin
      JSCode('$('#1'.getEl().select("_canvas").elements[0]).Jcrop('+
             '{'+
             '  options: '+
             '  {'+
             '    allowResize: true, '+
             '    allowMove: true, '+
             '    enableHandles: true'+
             '  }, '+
             '  onSelect: '+JSName+'.updatePreview, '+
             '  onDblClick: '+JSName+'.fetchImage'+
             '});');
    end; // with
 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...