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