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