├── .project ├── README.md ├── build.xml ├── build └── yuicompressor-2.4.2.jar ├── dist ├── tiquery.js └── tiquery.min.js ├── src ├── core.js ├── events.js ├── http.js ├── intro.js ├── memory.js ├── outro.js └── titanium.js ├── test ├── .fastdev.lock ├── .gitignore ├── .project ├── .settings │ └── com.appcelerator.titanium.mobile.prefs ├── CHANGELOG.txt ├── LICENSE ├── LICENSE.txt ├── README ├── Resources │ ├── KS_nav_ui.png │ ├── KS_nav_views.png │ ├── android │ │ ├── appicon.png │ │ ├── default.png │ │ └── images │ │ │ ├── res-long-land-hdpi │ │ │ └── default.png │ │ │ ├── res-long-land-ldpi │ │ │ └── default.png │ │ │ ├── res-long-port-hdpi │ │ │ └── default.png │ │ │ ├── res-long-port-ldpi │ │ │ └── default.png │ │ │ ├── res-notlong-land-hdpi │ │ │ └── default.png │ │ │ ├── res-notlong-land-ldpi │ │ │ └── default.png │ │ │ ├── res-notlong-land-mdpi │ │ │ └── default.png │ │ │ ├── res-notlong-port-hdpi │ │ │ └── default.png │ │ │ ├── res-notlong-port-ldpi │ │ │ └── default.png │ │ │ └── res-notlong-port-mdpi │ │ │ └── default.png │ ├── app.js │ ├── iphone │ │ ├── Default-Landscape.png │ │ ├── Default-Portrait.png │ │ ├── Default.png │ │ ├── Default@2x.png │ │ └── appicon.png │ ├── memory.js │ ├── qunit-titanium │ │ ├── .gitignore │ │ ├── README.md │ │ ├── package.json │ │ ├── qunit │ │ │ ├── qunit.js │ │ │ ├── titanium_adaptor.js │ │ │ └── titanium_adaptor_quiet.js │ │ ├── runner.js │ │ └── test │ │ │ ├── events.js │ │ │ ├── http.js │ │ │ └── shortcuts.js │ ├── tests.js │ └── tiquery.js ├── manifest └── tiapp.xml └── version.txt /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | TiQuery 4 | 5 | 6 | 7 | 8 | 9 | 10 | com.aptana.projects.webnature 11 | 12 | 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # What is TiQuery? 2 | 3 | TiQuery is a javascript library that makes tasks within [Appcelerator Titanium](http://www.appcelerator.com/) easier and quicker. It is based on [jQuery](http://jquery.com). 4 | 5 | # Shortcuts 6 | 7 | TiQuery provides shortcuts to Titanium methods. Here are some: 8 | 9 | // Utilities 10 | $.info('My message'); 11 | $.error('my error message'); 12 | $.include('path/to/file.js'); 13 | $.currentWindow; 14 | 15 | // create* methods 16 | var window = $.Window({ 17 | src: 'path/to/file.js' 18 | }); 19 | 20 | var view = $.View({ 21 | width: 100, 22 | height: 100, 23 | backgroundColor: 'red' 24 | }); 25 | 26 | window.add(view); 27 | 28 | # Events 29 | 30 | TiQuery makes adding and triggering events easy. 31 | 32 | $(view).click(function(event) { 33 | // do something 34 | }); 35 | 36 | $(view).click(); // triggers the click event 37 | 38 | You can also register your own custom events. 39 | 40 | $.registerEvent('myEvent'); 41 | 42 | $(window).myEvent(function() { 43 | // do something 44 | }); 45 | 46 | # HTTP Client 47 | 48 | Getting data from HTTP is simple with TiQuery with its helper functions. 49 | 50 | $.get('http://www.google.com', function(data) { 51 | // do something with text data 52 | }); 53 | 54 | $.post('http://www.example.com', {var1: 'value1', var2: 'value2'}, function(data) { 55 | // do something with text data 56 | }); 57 | 58 | $.getJSON('http://www.example.com/file.json', function(data) { 59 | // do something with json object 60 | }); 61 | 62 | $.getXML('http://www.example.com/file.xml', function(data) { 63 | // do something with xml dom object 64 | }); 65 | 66 | # Documentation 67 | 68 | View the [wiki](https://github.com/naturalcodeproject/TiQuery/wiki) for more information. -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 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 | 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 | -------------------------------------------------------------------------------- /build/yuicompressor-2.4.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wGEric/TiQuery/381b6a3a7b550e2f78510e38849ef5f1ebfaf572/build/yuicompressor-2.4.2.jar -------------------------------------------------------------------------------- /dist/tiquery.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * TiQuery Javascript Library for Titanium v0.0.1 3 | * 4 | * Copyright 2010 Eric Faerber, Natural Code Project 5 | * Released under GPL Version 2 6 | * 7 | * Includes large portions of jQuery 8 | * http://jquery.com 9 | * Copyright 2010, John Resig 10 | * Dual licensed under the MIT or GPL Version 2 licenses. 11 | */ 12 | 13 | (function(global, Titanium, undefined) { 14 | var TiQuery = (function() { 15 | var TiQuery = function(selector) { 16 | return new TiQuery.fn.init(selector); 17 | }, 18 | 19 | _TiQuery = global.TiQuery, 20 | _$ = global.$, 21 | 22 | /** 23 | * Check if a string has a non-whitespace character in it 24 | */ 25 | rnotwhite = /\S/, 26 | 27 | /** 28 | * Used for trimming whitespace 29 | */ 30 | rtrim = /^(\s|\u00A0)+|(\s|\u00A0)+$/g, 31 | 32 | 33 | // Save a reference to some core methods 34 | toString = Object.prototype.toString, 35 | hasOwnProperty = Object.prototype.hasOwnProperty, 36 | push = Array.prototype.push, 37 | slice = Array.prototype.slice, 38 | indexOf = Array.prototype.indexOf; 39 | 40 | TiQuery.fn = TiQuery.prototype = { 41 | init: function( selector, context ) { 42 | // Handle $(""), $(null), or $(undefined) 43 | if ( !selector ) { 44 | return this; 45 | } 46 | 47 | this.context = this[0] = selector; 48 | this.length = 1; 49 | return this; 50 | }, 51 | 52 | /** 53 | * The number of elements contained in the matched element set 54 | */ 55 | size: function() { 56 | return this.length; 57 | }, 58 | 59 | toArray: function() { 60 | return slice.call( this, 0 ); 61 | }, 62 | 63 | /** 64 | * Get the Nth element in the matched element set OR 65 | * Get the whole matched element set as a clean array 66 | */ 67 | get: function( num ) { 68 | return num == null ? 69 | 70 | // Return a 'clean' array 71 | this.toArray() : 72 | 73 | // Return just the object 74 | ( num < 0 ? this.slice(num)[ 0 ] : this[ num ] ); 75 | }, 76 | 77 | /** 78 | * Take an array of elements and push it onto the stack 79 | * (returning the new matched element set) 80 | */ 81 | pushStack: function( elems, name, selector ) { 82 | // Build a new TiQuery matched element set 83 | var ret = TiQuery(); 84 | 85 | if ( TiQueryuery.isArray( elems ) ) { 86 | push.apply( ret, elems ); 87 | 88 | } else { 89 | TiQuery.merge( ret, elems ); 90 | } 91 | 92 | // Add the old object onto the stack (as a reference) 93 | ret.prevObject = this; 94 | 95 | ret.context = this.context; 96 | 97 | if ( name === "find" ) { 98 | ret.selector = this.selector + (this.selector ? " " : "") + selector; 99 | } else if ( name ) { 100 | ret.selector = this.selector + "." + name + "(" + selector + ")"; 101 | } 102 | 103 | // Return the newly-formed element set 104 | return ret; 105 | }, 106 | 107 | /** 108 | * Execute a callback for every element in the matched set. 109 | * (You can seed the arguments with an array of args, but this is 110 | * only used internally.) 111 | */ 112 | each: function( callback, args ) { 113 | return TiQuery.each( this, callback, args ); 114 | }, 115 | 116 | ready: function( fn ) { 117 | 118 | 119 | return this; 120 | }, 121 | 122 | eq: function( i ) { 123 | return i === -1 ? 124 | this.slice( i ) : 125 | this.slice( i, +i + 1 ); 126 | }, 127 | 128 | first: function() { 129 | return this.eq( 0 ); 130 | }, 131 | 132 | last: function() { 133 | return this.eq( -1 ); 134 | }, 135 | 136 | slice: function() { 137 | return this.pushStack( slice.apply( this, arguments ), 138 | "slice", slice.call(arguments).join(",") ); 139 | }, 140 | 141 | map: function( callback ) { 142 | return this.pushStack( TiQuery.map(this, function( elem, i ) { 143 | return callback.call( elem, i, elem ); 144 | })); 145 | }, 146 | 147 | end: function() { 148 | return this.prevObject || TiQuery(null); 149 | }, 150 | 151 | // For internal use only. 152 | // Behaves like an Array's method, not like a TiQuery method. 153 | push: push, 154 | sort: [].sort, 155 | splice: [].splice 156 | }; 157 | 158 | // Give the init function the TiQuery prototype for later instantiation 159 | TiQuery.fn.init.prototype = TiQuery.fn; 160 | 161 | TiQuery.fn.extend = TiQuery.extend = function() { 162 | // copy reference to target object 163 | var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options, name, src, copy; 164 | 165 | // Handle a deep copy situation 166 | if ( typeof target === "boolean" ) { 167 | deep = target; 168 | target = arguments[1] || {}; 169 | // skip the boolean and the target 170 | i = 2; 171 | } 172 | 173 | // Handle case when target is a string or something (possible in deep copy) 174 | if ( typeof target !== "object" && !TiQuery.isFunction(target) ) { 175 | target = {}; 176 | } 177 | 178 | // extend TiQuery itself if only one argument is passed 179 | if ( length === i ) { 180 | target = this; 181 | --i; 182 | } 183 | 184 | for ( ; i < length; i++ ) { 185 | // Only deal with non-null/undefined values 186 | if ( (options = arguments[ i ]) != null ) { 187 | // Extend the base object 188 | for ( name in options ) { 189 | src = target[ name ]; 190 | copy = options[ name ]; 191 | 192 | // Prevent never-ending loop 193 | if ( target === copy ) { 194 | continue; 195 | } 196 | 197 | // Recurse if we're merging object literal values or arrays 198 | if ( deep && copy && ( TiQuery.isPlainObject(copy) || TiQuery.isArray(copy) ) ) { 199 | var clone = src && ( TiQuery.isPlainObject(src) || TiQuery.isArray(src) ) ? src 200 | : TiQuery.isArray(copy) ? [] : {}; 201 | 202 | // Never move original objects, clone them 203 | target[ name ] = TiQuery.extend( deep, clone, copy ); 204 | 205 | // Don't bring in undefined values 206 | } else if ( copy !== undefined ) { 207 | target[ name ] = copy; 208 | } 209 | } 210 | } 211 | } 212 | 213 | // Return the modified object 214 | return target; 215 | 216 | }; 217 | 218 | TiQuery.extend({ 219 | noConflict: function( deep ) { 220 | global.$ = _$; 221 | 222 | if ( deep ) { 223 | global.TiQuery = _TiQuery; 224 | } 225 | 226 | return TiQuery; 227 | }, 228 | 229 | /** 230 | * See test/unit/core.js for details concerning isFunction. 231 | * Since version 1.3, DOM methods and functions like alert 232 | * aren't supported. They return false on IE (#2968). 233 | */ 234 | isFunction: function( obj ) { 235 | return toString.call(obj) === "[object Function]"; 236 | }, 237 | 238 | isArray: function( obj ) { 239 | return toString.call(obj) === "[object Array]"; 240 | }, 241 | 242 | isPlainObject: function( obj ) { 243 | // Must be an Object. 244 | // Because of IE, we also have to check the presence of the constructor property. 245 | // Make sure that DOM nodes and window objects don't pass through, as well 246 | if ( !obj || toString.call(obj) !== "[object Object]" || obj.nodeType || obj.setInterval ) { 247 | return false; 248 | } 249 | 250 | // Not own constructor property must be Object 251 | if ( obj.constructor 252 | && !hasOwnProperty.call(obj, "constructor") 253 | && !hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf") ) { 254 | return false; 255 | } 256 | 257 | // Own properties are enumerated firstly, so to speed up, 258 | // if last one is own, then all properties are own. 259 | 260 | var key; 261 | for ( key in obj ) {} 262 | 263 | return key === undefined || hasOwnProperty.call( obj, key ); 264 | }, 265 | 266 | isEmptyObject: function( obj ) { 267 | for ( var name in obj ) { 268 | return false; 269 | } 270 | return true; 271 | }, 272 | 273 | error: function( msg ) { 274 | throw msg; 275 | }, 276 | 277 | parseJSON: function( data ) { 278 | if ( typeof data !== "string" || !data ) { 279 | return null; 280 | } 281 | 282 | // Make sure leading/trailing whitespace is removed (IE can't handle it) 283 | data = TiQuery.trim( data ); 284 | 285 | // Make sure the incoming data is actual JSON 286 | // Logic borrowed from http://json.org/json2.js 287 | if ( /^[\],:{}\s]*$/.test(data.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@") 288 | .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]") 289 | .replace(/(?:^|:|,)(?:\s*\[)+/g, "")) ) { 290 | return JSON.parse(data); 291 | 292 | } else { 293 | TiQuery.error( "Invalid JSON: " + data ); 294 | return false; 295 | } 296 | }, 297 | 298 | noop: function() {}, 299 | 300 | // args is for internal usage only 301 | each: function( object, callback, args ) { 302 | var name, i = 0, 303 | length = object.length, 304 | isObj = length === undefined || TiQuery.isFunction(object); 305 | 306 | if ( args ) { 307 | if ( isObj ) { 308 | for ( name in object ) { 309 | if ( callback.apply( object[ name ], args ) === false ) { 310 | break; 311 | } 312 | } 313 | } else { 314 | for ( ; i < length; ) { 315 | if ( callback.apply( object[ i++ ], args ) === false ) { 316 | break; 317 | } 318 | } 319 | } 320 | 321 | // A special, fast, case for the most common use of each 322 | } else { 323 | if ( isObj ) { 324 | for ( name in object ) { 325 | if ( callback.call( object[ name ], name, object[ name ] ) === false ) { 326 | break; 327 | } 328 | } 329 | } else { 330 | for ( var value = object[0]; 331 | i < length && callback.call( value, i, value ) !== false; value = object[++i] ) {} 332 | } 333 | } 334 | 335 | return object; 336 | }, 337 | 338 | trim: function( text ) { 339 | return (text || "").replace( rtrim, "" ); 340 | }, 341 | 342 | // results is for internal usage only 343 | makeArray: function( array, results ) { 344 | var ret = results || []; 345 | 346 | if ( array != null ) { 347 | // The window, strings (and functions) also have 'length' 348 | // The extra typeof function check is to prevent crashes 349 | // in Safari 2 (See: #3039) 350 | if ( array.length == null || typeof array === "string" || TiQuery.isFunction(array) || (typeof array !== "function" && array.setInterval) ) { 351 | push.call( ret, array ); 352 | } else { 353 | TiQuery.merge( ret, array ); 354 | } 355 | } 356 | 357 | return ret; 358 | }, 359 | 360 | inArray: function( elem, array ) { 361 | if ( array.indexOf ) { 362 | return array.indexOf( elem ); 363 | } 364 | 365 | for ( var i = 0, length = array.length; i < length; i++ ) { 366 | if ( array[ i ] === elem ) { 367 | return i; 368 | } 369 | } 370 | 371 | return -1; 372 | }, 373 | 374 | merge: function( first, second ) { 375 | var i = first.length, j = 0; 376 | 377 | if ( typeof second.length === "number" ) { 378 | for ( var l = second.length; j < l; j++ ) { 379 | first[ i++ ] = second[ j ]; 380 | } 381 | 382 | } else { 383 | while ( second[j] !== undefined ) { 384 | first[ i++ ] = second[ j++ ]; 385 | } 386 | } 387 | 388 | first.length = i; 389 | 390 | return first; 391 | }, 392 | 393 | grep: function( elems, callback, inv ) { 394 | var ret = []; 395 | 396 | // Go through the array, only saving the items 397 | // that pass the validator function 398 | for ( var i = 0, length = elems.length; i < length; i++ ) { 399 | if ( !inv !== !callback( elems[ i ], i ) ) { 400 | ret.push( elems[ i ] ); 401 | } 402 | } 403 | 404 | return ret; 405 | }, 406 | 407 | /** 408 | * arg is for internal usage only 409 | */ 410 | map: function( elems, callback, arg ) { 411 | var ret = [], value; 412 | 413 | // Go through the array, translating each of the items to their 414 | // new value (or values). 415 | for ( var i = 0, length = elems.length; i < length; i++ ) { 416 | value = callback( elems[ i ], i, arg ); 417 | 418 | if ( value != null ) { 419 | ret[ ret.length ] = value; 420 | } 421 | } 422 | 423 | return ret.concat.apply( [], ret ); 424 | }, 425 | 426 | clone: function(obj, deep) { 427 | var newObj = {}; 428 | 429 | if (deep == true) { 430 | newObj = TiQuery.extend(true, {}, obj); 431 | } else { 432 | newObj = TiQuery.extend({}, obj); 433 | } 434 | 435 | return newObj; 436 | }, 437 | 438 | // A global GUID counter for objects 439 | guid: 1, 440 | 441 | proxy: function( fn, proxy, thisObject ) { 442 | if ( arguments.length === 2 ) { 443 | if ( typeof proxy === "string" ) { 444 | thisObject = fn; 445 | fn = thisObject[ proxy ]; 446 | proxy = undefined; 447 | 448 | } else if ( proxy && !TiQuery.isFunction( proxy ) ) { 449 | thisObject = proxy; 450 | proxy = undefined; 451 | } 452 | } 453 | 454 | if ( !proxy && fn ) { 455 | proxy = function() { 456 | return fn.apply( thisObject || this, arguments ); 457 | }; 458 | } 459 | 460 | // Set the guid of unique handler to the same of original handler, so it can be removed 461 | if ( fn ) { 462 | proxy.guid = fn.guid = fn.guid || proxy.guid || TiQuery.guid++; 463 | } 464 | 465 | // So proxy can be declared as an argument 466 | return proxy; 467 | } 468 | }); 469 | 470 | // expose TiQuery to the global object 471 | return (global.TiQuery = global.$ = TiQuery); 472 | })(); 473 | 474 | function now() { 475 | return (new Date).getTime(); 476 | } 477 | /** 478 | * events 479 | */ 480 | (function(TiQuery) { 481 | TiQuery.extend({ 482 | /** 483 | * registers an event shortcut 484 | */ 485 | registerEvent: function(event) { 486 | TiQuery.fn[event] = function(fn) { 487 | if (fn == null) { 488 | return this.trigger(event); 489 | } else { 490 | return this.bind(event, fn); 491 | } 492 | } 493 | } 494 | }); 495 | 496 | TiQuery.fn.extend({ 497 | /** 498 | * binds an event to an object 499 | */ 500 | bind: function(type, fn) { 501 | this[0].addEventListener(type, fn); 502 | 503 | return this; 504 | }, 505 | 506 | /** 507 | * removes an event 508 | */ 509 | unbind: function(type, fn) { 510 | this[0].removeEventListener(type, fn); 511 | 512 | return this; 513 | }, 514 | 515 | /** 516 | * triggers an event on an object 517 | */ 518 | trigger: function(type) { 519 | this[0].fireEvent(type); 520 | 521 | return this; 522 | } 523 | }); 524 | 525 | var events = ['blur', 'cancel', 'click', 'dblclick', 'doubletap', 'focus', 'orientationchange', 'scroll', 'shake', 'singletap', 'swipe', 'touchcancel', 'touchend', 'touchmove', 'touchstart', 'twofingertap']; 526 | 527 | for(var i = 0, total = events.length; i < total; i++) { 528 | TiQuery.registerEvent(events[i]); 529 | } 530 | 531 | })(TiQuery);/** 532 | * http client 533 | */ 534 | (function(TiQuery) { 535 | TiQuery.extend({ 536 | httpSettings: { 537 | type: 'get', 538 | data: '', 539 | dataType: '', 540 | timeout: 3000, // milliseconds 541 | headers: {}, 542 | onError: null, 543 | onLoad: null, 544 | onDataStream: null, 545 | onReadyStateChange: null, 546 | onSendStream: null 547 | }, 548 | 549 | http: function(origSettings) { 550 | var s = TiQuery.extend(true, {}, TiQuery.httpSettings, origSettings); 551 | 552 | if (s.url == null) { 553 | return false; 554 | } 555 | 556 | s.type = s.type.toUpperCase(); 557 | s.dataType = s.dataType.toUpperCase(); 558 | 559 | // create the connection 560 | var http = Titanium.Network.createHTTPClient(); 561 | 562 | // set callbacks 563 | http.ondatastream = s.onDataStream; 564 | http.onsendstream = s.onSendStream; 565 | http.onreadystatechange = s.onReadyStateChange; 566 | 567 | // set timeout 568 | http.setTimeout(s.timeout); 569 | 570 | // on load 571 | http.onload = function(event) { 572 | Titanium.API.debug('http complete'); 573 | 574 | var results = false; 575 | 576 | if (s.dataType == 'XML') { 577 | // data is XML so parse it 578 | try { 579 | results = this.responseXML; 580 | } 581 | catch(E) { 582 | // not valid XML 583 | Titanium.API.error(E); 584 | results = false; 585 | } 586 | } else if (s.dataType == 'JSON') { 587 | // data is JSON so parse it 588 | results = TiQuery.parseJSON(this.responseText); 589 | } else { 590 | // no data type specified so don't do anything with it 591 | results = this.responseText; 592 | } 593 | 594 | if (TiQuery.isFunction(s.onLoad)) { 595 | s.onLoad(results, http, event); 596 | } 597 | } 598 | 599 | // on error 600 | http.onerror = function(event) { 601 | Titanium.API.error('http error: ' + event.error); 602 | 603 | if (TiQuery.isFunction(s.onError)) { 604 | s.onError(http, event); 605 | } 606 | } 607 | 608 | // open request 609 | http.open(s.type, s.url); 610 | 611 | // set headers 612 | if ($.isPlainObject(s.headers)) { 613 | for(var key in s.headers) { 614 | http.setRequestHeader(key, s.headers[key]); 615 | } 616 | } 617 | 618 | // send request 619 | http.send(s.data); 620 | 621 | // clear the object 622 | http = null; 623 | 624 | return true; 625 | } 626 | }); 627 | 628 | var shortcuts = ['get', 'getJSON', 'getXML', 'post', 'postJSON', 'postXML']; 629 | 630 | for(var i = 0, total = shortcuts.length; i < total; i++) { 631 | (function(name) { 632 | var type = (name.indexOf('get') != -1) ? 'get' : 'post', 633 | dataType; 634 | 635 | if (name.indexOf('JSON') != -1) { 636 | dataType = 'JSON'; 637 | } else if (name.indexOf('XML') != -1) { 638 | dataType = 'XML'; 639 | } 640 | 641 | TiQuery[name] = function(url, data, fn, headers) { 642 | if (TiQuery.isFunction(data)) { 643 | headers = fn || {}; 644 | fn = data; 645 | data = {}; 646 | } 647 | 648 | this.http({ 649 | type: type, 650 | url: url, 651 | data: data, 652 | dataType: dataType, 653 | headers: headers, 654 | onLoad: fn 655 | }); 656 | } 657 | })(shortcuts[i]); 658 | } 659 | })(TiQuery); 660 | /** 661 | * Memory management 662 | * 663 | * see http://developer.appcelerator.com/question/116867/this-is-a-solution-to-your-memory-woes 664 | */ 665 | (function(TiQuery) { 666 | TiQuery.extend({ 667 | release: function(view, window) { 668 | if (!view) { 669 | return false; 670 | } 671 | 672 | if (!window) { 673 | window = Titanium.UI.currentWindow; 674 | } 675 | 676 | // create the hidden window 677 | memWindow = Titanium.UI.createWindow(); 678 | memWindow.hide(); 679 | memWindow.open(); 680 | 681 | // remove the view from the window 682 | window.remove(view); 683 | 684 | // add the view to the hidden window 685 | if (TiQuery.isArray(view)) { 686 | for(var i = 0, total = view.length; i < total; i += 1) { 687 | memWindow.add(view[i]); 688 | } 689 | } else { 690 | memWindow.add(view); 691 | } 692 | 693 | // close the window releasing memory 694 | memWindow.close(); 695 | 696 | memWindow = null; 697 | view = null; 698 | } 699 | }); 700 | })(TiQuery);/** 701 | * Titanium shortcuts 702 | */ 703 | (function(TiQuery) { 704 | TiQuery.extend({ 705 | // shortcuts for Titanium.API.info, Titanium.API.error, etc 706 | info: function(message) { Titanium.API.info(message); }, 707 | error: function(message) { Titanium.API.error(message); }, 708 | warn: function(message) { Titanium.API.warn(message); }, 709 | log: function(message) { Titanium.API.log(message); }, 710 | include: function(file) { Titanium.include(file); }, 711 | db: function(name) { return Titanium.Database.open(name); }, 712 | currentWindow: function() { return Titanium.UI.currentWindow; }, 713 | currenTab: function() { return Titanium.UI.currentTab; }, 714 | 715 | // registers shortcuts 716 | registerShortcut: function(_namespace, _name, _shortcut, prefix) { 717 | if (_shortcut === undefined) { 718 | _shortcut = _name; 719 | } 720 | 721 | if (prefix === undefined) { 722 | prefix = 'create'; 723 | } 724 | 725 | TiQuery[_shortcut] = function(args) { 726 | if (args === undefined) { 727 | args = {}; 728 | } 729 | return Titanium[_namespace][prefix + _name](args); 730 | }; 731 | } 732 | }); 733 | 734 | /** 735 | * creates shortcuts to for create* methods within Titanium 736 | * 737 | * Idea/some code taken from Redux by Dawson Toth (https://github.com/dawsontoth/Appcelerator-Titanium-Redux) 738 | */ 739 | var classes = { 740 | Android: ['BroadcastIntent', 'Intent', 'IntentChooser', 'Notification', 'PendingIntent', 'Service', 'ServiceIntent'], 741 | Contacts: ['Group', 'Person'], 742 | Facebook: ['LoginButton'], 743 | Filesystem: ['File', 'TempDirectory', 'TempFile'], 744 | Map: ['Annotation'], 745 | Media: ['AudioPlayer', 'AudioRecorder', 'Item', 'MusicPlayer', 'Sound', 'VideoPlayer'], 746 | Network: ['BonjourBrowser', 'BonjourService', 'HTTPClient', 'TCPSocket'], 747 | Platform: ['UUID'], 748 | Stream: ['Stream'], 749 | UI: ['2DMatrix', '3DMatrix', 'ActivityIndicator', 'AlertDialog', 'Animation', 'Button', 'ButtonBar', 'CoverFlowView', 'DashboardItem', 'DashboardView', 'EmailDialog', 'ImageView', 'Label', 'OptionDialog', 'Picker', 'PickerColumn', 'PickerRow', 'ProgressBar', 'ScrollView', 'ScrollableView', 'SearchBar', 'Slider', 'Switch', 'Tab', 'TabGroup', 'TabbedBar', 'TableView', 'TableViewRow', 'TableViewSection', 'TextArea', 'TextField', 'Toolbar', 'View', 'WebView', 'Window'] 750 | } 751 | 752 | for(var namespace in classes) { 753 | for(var i = 0, total = classes[namespace].length; i < total; i++) { 754 | TiQuery.registerShortcut(namespace, classes[namespace][i]) 755 | } 756 | } 757 | 758 | // A couple of methods don't follow the same pattern above so here they are 759 | TiQuery.registerShortcut('Map', 'View', 'MapView'); 760 | })(TiQuery);})(this, Titanium); -------------------------------------------------------------------------------- /dist/tiquery.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | * TiQuery Javascript Library for Titanium v0.0.1 3 | * 4 | * Copyright 2010 Eric Faerber, Natural Code Project 5 | * Released under GPL Version 2 6 | * 7 | * Includes large portions of jQuery 8 | * http://jquery.com 9 | * Copyright 2010, John Resig 10 | * Dual licensed under the MIT or GPL Version 2 licenses. 11 | */ 12 | (function(c,e,d){var b=(function(){var i=function(p){return new i.fn.init(p)},h=c.TiQuery,k=c.$,o=/\S/,j=/^(\s|\u00A0)+|(\s|\u00A0)+$/g,f=Object.prototype.toString,g=Object.prototype.hasOwnProperty,l=Array.prototype.push,n=Array.prototype.slice,m=Array.prototype.indexOf;i.fn=i.prototype={init:function(p,q){if(!p){return this}this.context=this[0]=p;this.length=1;return this},size:function(){return this.length},toArray:function(){return n.call(this,0)},get:function(p){return p==null?this.toArray():(p<0?this.slice(p)[0]:this[p])},pushStack:function(q,s,p){var r=i();if(TiQueryuery.isArray(q)){l.apply(r,q)}else{i.merge(r,q)}r.prevObject=this;r.context=this.context;if(s==="find"){r.selector=this.selector+(this.selector?" ":"")+p}else{if(s){r.selector=this.selector+"."+s+"("+p+")"}}return r},each:function(q,p){return i.each(this,q,p)},ready:function(p){return this},eq:function(p){return p===-1?this.slice(p):this.slice(p,+p+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(n.apply(this,arguments),"slice",n.call(arguments).join(","))},map:function(p){return this.pushStack(i.map(this,function(r,q){return p.call(r,q,r)}))},end:function(){return this.prevObject||i(null)},push:l,sort:[].sort,splice:[].splice};i.fn.init.prototype=i.fn;i.fn.extend=i.extend=function(){var u=arguments[0]||{},t=1,s=arguments.length,w=false,x,r,p,q;if(typeof u==="boolean"){w=u;u=arguments[1]||{};t=2}if(typeof u!=="object"&&!i.isFunction(u)){u={}}if(s===t){u=this;--t}for(;t