NOTICE
Part of jQueryExtern is being merged back to the Haxe std lib, resulting in a new extern in the Haxe std lib. If you're using Haxe 3.3+, you should switch to the new std extern. You may checkout the haxe3.3 branch of jQueryExtern, which is a drop-in replacement to the new std extern with advanced functionalities.
Currently supports jQuery version up to 1.11.3 / 2.1.4. Requires Haxe 3.1.0+.
You may check my blog for updates.
Download and Install
Install via haxelib:
haxelib install jQueryExtern
Then put -lib jQueryExtern
into your hxml.
Usage
Typically:
import jQuery class Main { static public function main():Void { new JQuery{ //when document is ready //your magic }); }}
It is same as how you use jQuery in JS. But instead of $
, you refer jQuery as JQuery
.
eg. Hiding all li object:
new JQuery("li") //same as $("li").hide() in JS
Static methods of jQuery can be accessed from JQuery._static
.
eg. A ajax example:
JQueryfunction{ js});
Remember jQueryExtern is simply an extern, you have to link jQuery in your html file.
eg. In your <head>
:
<!-- from jQuery's CDN (http://jquery.com/download/#using-jquery-with-a-cdn) --> <!-- Your haxe compiled script: -->
js.JQuery in haxe std lib VS jQueryExtern
js.JQuery | jQueryExtern | |
---|---|---|
import statement | import js.JQuery; |
import jQuery.*; |
jQuery API version | partial 1.6.4 | complete 1.11.3 / 2.1.4 |
refer jQuery in output as | js.JQuery |
$ (or jQuery if --macro jQuery.haxe.Config.setNative('jQuery') ) |
include jQuery in output | no (can be opt-in by -D embed-js ) |
no, use CDN instead |
In fact, since both js.JQuery in haxe std lib and jQueryExtern are just extern files, they can be used in same project.
The following will compile and run perfectly.
function takesJQueryExtern(j:jQuery{ trace}function takesJsJQuery(j:js{ trace} var div = new js.JQuery("<div></div>");takesJQueryExterndiv);takesJQueryExterndiv); var div = new jQuerytakesJsJQuerydiv);takesJsJQuerydiv);
Like jQueryExtern?
Support me to maintain it -> http://www.patreon.com/andyli
License
jQueryExtern is released in the public domain. NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
jQuery's license can be found at http://jquery.org/license.