jQueryExtern: it compiles but how to interface?

59 views
Skip to first unread message

S.A. Asselbergs

unread,
Nov 8, 2017, 8:32:15 AM11/8/17
to Haxe
Hello fellow Haxers,

I did RTFM on JQuery, DIY JQuery plugins, JQueryExtern and haxe externs.
The compiler seems happy. So how to interface this extern?

 JQuery is a bit different than the externs i used in the past, is my extern as it should be?


Sincerely yours,
Simon

....... Additional Compiler options....................................................................................

-dce full
--macro js.jquery.Config.addPlugin('northstar.jquery.JQueryExtensions')

....... Libraries ...............................................................................................................

jQueryExtern


-------- File: northstar\jquery\JQueryExtensions.hx ------------------------------------------------------------

package northstar.jquery;
import js.jquery.Plugin;

extern class JQueryExtensions  implements Plugin
{   
    public function drags():Void;   
}



-------- File: bin\JQueryExtensions.js --------------------------------------------------------------------------------

(function($) {
  $.fn.drags = function(opt) {
    opt = $.extend({ handle: "", cursor: "move" }, opt);

    if (opt.handle === "") {
      var $el = this;
    } else {
      var $el = this.find(opt.handle);
    }

    return $el
      .css("cursor", opt.cursor)
      .on("mousedown", function(e) {
      if (opt.handle === "") {
        var $drag = $(this).addClass("draggable");
      } else {
        var $drag = $(this)
        .addClass("active-handle")
        .parent()
        .addClass("draggable");
      }
      var z_idx = $drag.css("z-index"),
          drg_h = $drag.outerHeight(),
          drg_w = $drag.outerWidth(),
          pos_y = $drag.offset().top + drg_h - e.pageY,
          pos_x = $drag.offset().left + drg_w - e.pageX;
      $drag
        .css("z-index", 1000)
        .parents()
        .on("mousemove", function(e) {
        $(".draggable")
          .offset({
          top: e.pageY + pos_y - drg_h,
          left: e.pageX + pos_x - drg_w
        })
          .on("mouseup", function() {
          $(this)
            .removeClass("draggable")
            .css("z-index", z_idx);
        });
      });
      e.preventDefault(); // disable selection
    })
      .on("mouseup", function() {
      if (opt.handle === "") {
        $(this).removeClass("draggable");
      } else {
        $(this)
          .removeClass("active-handle")
          .parent()
          .removeClass("draggable");
      }
    });
  };
})(jQuery);

Rafael Oliveira

unread,
Nov 9, 2017, 6:09:52 AM11/9/17
to Haxe
Hi, can you post this question here http://community.haxe.org/ ?
We are testing this a new forum on discourse.
Reply all
Reply to author
Forward
0 new messages