JQuery.hx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. /*
  2. * Copyright (C)2005-2015 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package js;
  23. import js.html.Window;
  24. import js.html.Element;
  25. @:deprecated("Use js.jquery.Event instead.")
  26. typedef JqEvent = {
  27. var target : Element;
  28. var currentTarget : Element;
  29. var relatedTarget : Element;
  30. var delegateTarget : Element;
  31. var type : String;
  32. var timeStamp : Int;
  33. //var data : Dynamic;
  34. //var namespace : String;
  35. //var result : Dynamic;
  36. // position
  37. var pageX : Int;
  38. var pageY : Int;
  39. var wheelDelta : Int;
  40. // keys
  41. var keyCode : Int;
  42. var charCode : Int;
  43. var shiftKey : Bool;
  44. var ctrlKey : Bool;
  45. var altKey : Bool;
  46. var metaKey : Bool;
  47. var which : Int;
  48. // propagation
  49. function isDefaultPrevented() : Bool;
  50. function isImmediatePropagationStopped() : Bool;
  51. function isPropagationStopped() : Bool;
  52. function preventDefault() : Void;
  53. function stopImmediatePropagation() : Void;
  54. function stopPropagation() : Void;
  55. }
  56. @:deprecated("Use js.jquery.Helper instead.")
  57. extern class JQueryHelper {
  58. @:overload(function(j:JQuery):JQuery{})
  59. @:overload(function(j:Window):JQuery{})
  60. @:overload(function(j:Element):JQuery { } )
  61. public static inline function J( html : haxe.extern.EitherType<String,haxe.extern.EitherType<JQuery,haxe.extern.EitherType<Window,Element>>> ) : JQuery {
  62. return new JQuery(cast html);
  63. }
  64. public static var JTHIS(get, null) : JQuery;
  65. static inline function get_JTHIS() : JQuery {
  66. return new JQuery(js.Lib.nativeThis);
  67. }
  68. }
  69. @:deprecated("Use js.jquery.JQuery instead.")
  70. @:initPackage
  71. extern class JQuery implements ArrayAccess<Element> {
  72. var context(default,null) : Element;
  73. var length(default, null) : Int;
  74. @:selfCall
  75. @:overload(function(j:JQuery):Void{})
  76. @:overload(function(j:Window):Void{})
  77. @:overload(function(j:Element):Void{})
  78. function new( html : String ) : Void;
  79. // attributes
  80. function addClass( className : String ) : JQuery;
  81. function removeClass( ?className : String ) : JQuery;
  82. function hasClass( className : String ) : Bool;
  83. function toggleClass( className : String, ?addRemove : Bool ) : JQuery;
  84. @:overload(function(name:String,value:String):JQuery{})
  85. function attr( name : String ) : String;
  86. function removeAttr( attr : String ) : JQuery;
  87. @:overload(function(name:String,value:Dynamic):JQuery{})
  88. function prop( name : String ) : Dynamic;
  89. @:overload(function(prop:String,value:String):JQuery{})
  90. @:overload(function(map:{}):JQuery{})
  91. function css( prop : String ) : String;
  92. @:overload(function(html:String):JQuery{})
  93. @:overload(function(html:JQuery):JQuery{})
  94. function html() : String;
  95. @:overload(function(value:String):JQuery{})
  96. function val() : String;
  97. @:overload(function(text:String):JQuery{})
  98. function text() : String;
  99. // Size & Position
  100. @:overload(function(value:Int):JQuery{})
  101. function width() : Int;
  102. @:overload(function(value:Int):JQuery{})
  103. function height() : Int;
  104. @:overload(function(value:Int):JQuery{})
  105. function innerWidth() : Int;
  106. @:overload(function(value:Int):JQuery{})
  107. function innerHeight() : Int;
  108. function outerWidth( ?includeMargin : Bool ) : Int;
  109. function outerHeight( ?includeMargin : Bool ) : Int;
  110. @:overload(function(value:Int):JQuery{})
  111. function scrollLeft() : Int;
  112. @:overload(function(value:Int):JQuery{})
  113. function scrollTop() : Int;
  114. @:overload(function(value: { left : Int, top : Int }):JQuery{})
  115. function offset() : { left : Int, top : Int };
  116. function offsetParent() : JQuery;
  117. @:overload(function(value: { left : Int, top : Int }):JQuery{})
  118. function position() : { left : Int, top : Int };
  119. // current group manipulation
  120. @:overload(function(value:JQuery):JQuery{})
  121. @:overload(function(value:Element):JQuery{})
  122. @:overload(function(value:Array<Element>):JQuery{})
  123. function add( selector : String, ?context : JQuery ) : JQuery;
  124. function andSelf() : JQuery;
  125. function children( ?selector : String ) : JQuery;
  126. function clone( ?withDataAndEvents : Bool ) : JQuery;
  127. function closest( selector : String, ?context : JQuery ) : JQuery;
  128. function contents() : JQuery;
  129. @:overload(function( f : Int -> Element -> Void ):JQuery{})
  130. function each( f : Void -> Void ) : JQuery;
  131. function end() : JQuery;
  132. function eq( index : Int ) : JQuery;
  133. function filter( selector : String ) : JQuery;
  134. function find( selector : String ) : JQuery;
  135. function first() : JQuery;
  136. function index( ?selector : String ) : Int;
  137. function last( ?selector : String ) : JQuery;
  138. function has( selector : String ) : JQuery;
  139. function next( ?selector : String ) : JQuery;
  140. function nextAll( ?selector : String ) : JQuery;
  141. function nextUntil( ?selector : String ) : JQuery;
  142. function parent( ?selector : String ) : JQuery;
  143. function parents( ?selector : String ) : JQuery;
  144. function parentsUntil( ?selector : String ) : JQuery;
  145. @:overload(function(value:Element):JQuery{})
  146. function not( selector : String ) : JQuery;
  147. function prev( ?selector : String ) : JQuery;
  148. function prevAll( ?selector : String ) : JQuery;
  149. function prevUntil( ?selector : String ) : JQuery;
  150. function pushStack( elements : Array<Element> ) : JQuery;
  151. function siblings( ?selector : String ) : JQuery;
  152. function size() : Int;
  153. function slice( start : Int, ?end : Int ) : JQuery;
  154. function toArray() : Array<Element>;
  155. // DOM changes
  156. @:overload(function(value:JQuery):JQuery{})
  157. @:overload(function(value:Element):JQuery{})
  158. function before( html : String ) : JQuery;
  159. @:overload(function(value:JQuery):JQuery{})
  160. @:overload(function(value:Element):JQuery{})
  161. function after( html : String ) : JQuery;
  162. @:overload(function(value:JQuery):JQuery{})
  163. @:overload(function(value:Element):JQuery{})
  164. function append( html : String ) : JQuery;
  165. @:overload(function(value:JQuery):JQuery{})
  166. @:overload(function(value:Element):JQuery{})
  167. function appendTo( html : String ) : JQuery;
  168. function detach( ?selector : String ) : JQuery;
  169. function empty() : JQuery; // remove all texts
  170. @:overload(function(value:JQuery):JQuery{})
  171. @:overload(function(value:Element):JQuery{})
  172. function insertBefore( html : String ) : JQuery;
  173. @:overload(function(value:JQuery):JQuery{})
  174. @:overload(function(value:Element):JQuery{})
  175. function insertAfter( html : String ) : JQuery;
  176. @:overload(function(value:JQuery):JQuery{})
  177. @:overload(function(value:Element):JQuery{})
  178. function prepend( html : String ) : JQuery;
  179. @:overload(function(value:JQuery):JQuery{})
  180. @:overload(function(value:Element):JQuery{})
  181. function prependTo( html : String ) : JQuery;
  182. function remove( ?selector : String ) : JQuery;
  183. function replaceAll( selector : String ) : JQuery;
  184. @:overload(function(value:JQuery):JQuery{})
  185. @:overload(function(value:Element):JQuery{})
  186. function replaceWith( html : String ) : JQuery;
  187. function unwrap() : JQuery;
  188. @:overload(function(value:JQuery):JQuery{})
  189. @:overload(function(value:Element):JQuery{})
  190. function wrap( html : String ) : JQuery;
  191. @:overload(function(value:JQuery):JQuery{})
  192. @:overload(function(value:Element):JQuery{})
  193. function wrapAll( html : String ) : JQuery;
  194. @:overload(function(value:JQuery):JQuery{})
  195. @:overload(function(value:Element):JQuery{})
  196. function wrapInner( html : String ) : JQuery;
  197. // animation
  198. @:overload(function(properties:{},?duration:Int,?easing:String,?call:Void->Void) : JQuery{})
  199. function animate( properties : { }, ?duration : Int, ?callb : Void -> Void ) : JQuery;
  200. function delay( duration : Int, ?queueName : String ) : JQuery;
  201. @:overload(function(?duration:Int,?easing:String,?call:Void->Void) : JQuery{})
  202. function hide( ?duration : Int, ?call : Void -> Void ) : JQuery;
  203. @:overload(function(?duration:Int,?easing:String,?call:Void->Void) : JQuery{})
  204. function fadeIn( ?duration : Int, ?call : Void -> Void ) : JQuery;
  205. @:overload(function(?duration:Int,?easing:String,?call:Void->Void) : JQuery{})
  206. function fadeOut( ?duration : Int, ?call : Void -> Void ) : JQuery;
  207. @:overload(function(duration:Int,opacity:Float,?easing:String,?call:Void->Void) : JQuery{})
  208. function fadeTo( duration : Int, opacity : Float, ?call : Void -> Void ) : JQuery;
  209. @:overload(function(?duration:Int,?easing:String,?call:Void->Void) : JQuery{})
  210. function fadeToggle( ?duration : Int, ?call : Void -> Void ) : JQuery;
  211. @:overload(function(?duration:Int,?easing:String,?call:Void->Void) : JQuery{})
  212. function show( ?duration : Int, ?call : Void -> Void ) : JQuery;
  213. @:overload(function(?duration:Int,?easing:String,?call:Void->Void) : JQuery{})
  214. function slideDown( ?duration : Int, ?call : Void -> Void ) : JQuery;
  215. @:overload(function(?duration:Int,?easing:String,?call:Void->Void) : JQuery{})
  216. function slideToggle( ?duration : Int, ?call : Void -> Void ) : JQuery;
  217. @:overload(function(?duration:Int,?easing:String,?call:Void->Void) : JQuery{})
  218. function slideUp( ?duration : Int, ?call : Void -> Void ) : JQuery;
  219. function stop( ?clearQueue : Bool, ?jumpToEnd : Bool ) : JQuery;
  220. @:overload(function(?duration:Int,?easing:String,?call:Void->Void) : JQuery{})
  221. function toggle( ?duration : Int, ?call : Void -> Void ) : JQuery;
  222. // Events
  223. function blur( ?callb : JqEvent -> Void ) : JQuery;
  224. function change( ?callb : JqEvent -> Void ) : JQuery;
  225. @:overload(function(callb:Void->Void):JQuery { } )
  226. @:overload(function(callb:JQuery.JqEvent->Void):JQuery{})
  227. @:overload(function(callb:Void->Bool):JQuery{})
  228. function click( ?callb : JqEvent -> Void ) : JQuery;
  229. function dblclick( ?callb : JqEvent -> Void ) : JQuery;
  230. function error( ?callb : JqEvent -> Void ) : JQuery;
  231. function focus( ?callb : JqEvent -> Void ) : JQuery;
  232. function focusin( ?callb : JqEvent -> Void ) : JQuery;
  233. function focusout( ?callb : JqEvent -> Void ) : JQuery;
  234. @:overload(function(onInOut:JqEvent->Void):JQuery{})
  235. function hover( onIn : JqEvent -> Void, ?onOut : JqEvent -> Void ) : JQuery;
  236. @:overload(function( callb : JQuery.JqEvent -> Bool ) : JQuery {})
  237. function keydown( ?callb : JqEvent -> Void ) : JQuery;
  238. @:overload(function( callb : JQuery.JqEvent -> Bool ) : JQuery {})
  239. function keypress( ?callb : JqEvent -> Void ) : JQuery;
  240. @:overload(function( callb : JQuery.JqEvent -> Bool ) : JQuery {})
  241. function keyup( ?callb : JqEvent -> Void ) : JQuery;
  242. function mousedown( ?callb : JqEvent -> Void ) : JQuery;
  243. function mouseenter( ?callb : JqEvent -> Void ) : JQuery;
  244. function mouseleave( ?callb : JqEvent -> Void ) : JQuery;
  245. function mouseout( ?callb : JqEvent -> Void ) : JQuery;
  246. function mouseover( ?callb : JqEvent -> Void ) : JQuery;
  247. function mousemove( ?callb : JqEvent -> Void ) : JQuery;
  248. function mouseup( ?callb : JqEvent -> Void ) : JQuery;
  249. // AJAX overloads
  250. @:overload(function( url:String, ?data : {}, ?callb : String -> String -> Void ) : JQuery {})
  251. @:overload(function( url:String, ?data : {}, ?callb : String -> Void ) : JQuery {})
  252. @:overload(function( url:String, ?data : {}, ?callb : Void -> Void ) : JQuery {})
  253. function load( ?callb : JqEvent -> Void ) : JQuery;
  254. function ready( callb : JqEvent -> Void ) : JQuery;
  255. function resize( ?callb : JqEvent -> Void ) : JQuery;
  256. function scroll( ?callb : JqEvent -> Void ) : JQuery;
  257. function select( ?callb : JqEvent -> Void ) : JQuery;
  258. function submit( ?callb : JqEvent -> Void ) : JQuery;
  259. function unload( ?callb : JqEvent -> Void ) : JQuery;
  260. function bind( events : String, callb : JqEvent -> Void ) : JQuery;
  261. function delegate( selector : String, events : String, callb : JqEvent -> Void ) : JQuery;
  262. function die( ?events : String, ?callb : JqEvent -> Void ) : JQuery;
  263. function one( events : String, callb : JqEvent -> Void ) : JQuery;
  264. function live( events : String, callb : JqEvent -> Void ) : JQuery;
  265. function trigger( events : String ) : JQuery;
  266. function triggerHandler( events : String ) : JQuery;
  267. function unbind( ?events : String, ?callb : JqEvent -> Void ) : JQuery;
  268. function undelegate( ?selector : String, ?events : String, ?callb : JqEvent -> Void ) : JQuery;
  269. // JQuery 1.7+
  270. @:overload(function(events:Dynamic<JqEvent->Void>):JQuery{})
  271. function on( events : String, callb : JqEvent -> Void ) : JQuery;
  272. // queue
  273. function clearQueue( ?queueName : String ) : JQuery;
  274. function dequeue( ?queueName : String ) : JQuery;
  275. function queue( ?queueName : String, ?callb : (Void -> Void) -> Void ) : { length : Int };
  276. // ajax
  277. // TODO
  278. // deferred
  279. // TODO
  280. // other tools
  281. @:overload(function(index:Int):Element{})
  282. function get() : Array<Element>;
  283. @:overload(function(j:JQuery):Bool{})
  284. function is( selector : String ) : Bool;
  285. @:overload(function() : Dynamic {})
  286. @:overload(function( key : String ) : Dynamic {})
  287. function data( key : String, value : Dynamic ) : JQuery;
  288. function removeData( ?key : String ) : JQuery;
  289. function serialize() : String;
  290. function serializeArray() : Array<{ name : String, value : String }>;
  291. //inline function map<T>( f : JQuery -> T ) : Array<T> {
  292. // return untyped this["map"](function() return f(cur)).get();
  293. //}
  294. // Haxe addition
  295. @:runtime inline function iterator() : Iterator<JQuery> {
  296. return untyped __define_feature__('js.JQuery.iterator', this["iterator"])();
  297. }
  298. /**
  299. Return the current JQuery element (in a callback), similar to $(this) in JS.
  300. **/
  301. static var cur(get, null) : JQuery;
  302. static var fx(default, null) : { off : Bool, interval : Int };
  303. static var browser(default, null) : { webkit : Bool, opera : Bool, msie : Bool, mozilla : Bool, version : String };
  304. static function contains( parent : Element, child : Element ) : Bool;
  305. static function noConflict( ?removeAll : Bool ) : Void;
  306. static function parseJSON( json : String ) : Dynamic;
  307. static function globalEval( js : String ) : Void;
  308. //static function parseXML
  309. //static function get, post
  310. //static function getJSON, getScript, grep
  311. //static function is*, makeArray, map, merge, noop, now, param, proxy, sub, trim, type, unique
  312. private static inline function get_cur() : JQuery {
  313. return new js.JQuery(js.Lib.nativeThis);
  314. }
  315. private static function __init__() : Void untyped {
  316. #if embed_js
  317. if( untyped __js__("typeof($) == 'undefined'") )
  318. haxe.macro.Compiler.includeFile("js/jquery-latest.min.js");
  319. #end
  320. var q : Dynamic = (untyped js.Browser.window).jQuery;
  321. untyped __js__("var js = js || {}");
  322. js.JQuery = q;
  323. __feature__('js.JQuery.iterator',
  324. q.fn.iterator = function() return { pos : 0, j : __this__, hasNext : function() return __this__.pos < __this__.j.length, next : function() return $(__this__.j[__this__.pos++]) }
  325. );
  326. }
  327. }