Skip to content

andyli/jQueryExternForHaxe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

168 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jQueryExtern Build Status

jQuery extern for Haxe.

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(function():Void { //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").hide(); //same as $("li").hide() in JS

Static methods of jQuery can be accessed from JQuery._static.

eg. A ajax example:

JQuery._static.get("ajax/test.html", function(data) {
	js.Lib.alert(data);
});

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) -->
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>

<!-- Your haxe compiled script: -->
<script type="text/javascript" src="Main.js"></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.JQuery):Void {
	trace(j);
}
function takesJsJQuery(j:js.JQuery):Void {
	trace(j);
}

var div = new js.JQuery("<div></div>");
takesJQueryExtern(untyped div);
takesJQueryExtern(cast div);

var div = new jQuery.JQuery("<div></div>");
takesJsJQuery(untyped div);
takesJsJQuery(cast div);

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.

About

Unleash the full power of jQuery in Haxe.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors