Index: branches/uploadwizard/phase3/includes/upload/UploadFromFile.php |
— | — | @@ -52,4 +52,14 @@ |
53 | 53 | |
54 | 54 | return parent::verifyUpload(); |
55 | 55 | } |
| 56 | + |
| 57 | + /** |
| 58 | + * Get the path to the file underlying the upload |
| 59 | + * @return String path to file |
| 60 | + */ |
| 61 | + public function getFileTempname() { |
| 62 | + return $this->mUpload->getTempname(); |
| 63 | + } |
| 64 | + |
| 65 | + |
56 | 66 | } |
Index: branches/uploadwizard/phase3/includes/Defines.php |
— | — | @@ -63,6 +63,7 @@ |
64 | 64 | define('NS_HELP_TALK', 13); |
65 | 65 | define('NS_CATEGORY', 14); |
66 | 66 | define('NS_CATEGORY_TALK', 15); |
| 67 | +define('NS_STASH', 16); |
67 | 68 | /** |
68 | 69 | * NS_IMAGE and NS_IMAGE_TALK are the pre-v1.14 names for NS_FILE and |
69 | 70 | * NS_FILE_TALK respectively, and are kept for compatibility. |
Index: branches/uploadwizard/phase3/includes/MimeMagic.php |
— | — | @@ -492,6 +492,7 @@ |
493 | 493 | } |
494 | 494 | |
495 | 495 | private function doGuessMimeType( $file, $ext ) { # TODO: remove $ext param |
| 496 | + wfDebug( __METHOD__ . " in guess mime type for $file, $ext " ); |
496 | 497 | // Read a chunk of the file |
497 | 498 | wfSuppressWarnings(); |
498 | 499 | $f = fopen( $file, "rt" ); |
Index: branches/uploadwizard/phase3/includes/filerepo/File.php |
— | — | @@ -528,7 +528,7 @@ |
529 | 529 | * @param $params Array: an associative array of handler-specific parameters. |
530 | 530 | * Typical keys are width, height and page. |
531 | 531 | * @param $flags Integer: a bitfield, may contain self::RENDER_NOW to force rendering |
532 | | - * @return MediaTransformOutput |
| 532 | + * @return MediaTransformOutput | false |
533 | 533 | */ |
534 | 534 | function transform( $params, $flags = 0 ) { |
535 | 535 | global $wgUseSquid, $wgIgnoreImageErrors, $wgThumbnailEpoch, $wgServer; |
— | — | @@ -562,7 +562,7 @@ |
563 | 563 | $thumbPath = $this->getThumbPath( $thumbName ); |
564 | 564 | $thumbUrl = $this->getThumbUrl( $thumbName ); |
565 | 565 | |
566 | | - if ( $this->repo->canTransformVia404() && !($flags & self::RENDER_NOW ) ) { |
| 566 | + if ( $this->repo && $this->repo->canTransformVia404() && !($flags & self::RENDER_NOW ) ) { |
567 | 567 | $thumb = $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params ); |
568 | 568 | break; |
569 | 569 | } |
Index: branches/uploadwizard/phase3/includes/api/ApiUpload.php |
— | — | @@ -84,14 +84,90 @@ |
85 | 85 | $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
86 | 86 | } |
87 | 87 | |
88 | | - // Check warnings if necessary |
89 | | - $warnings = $this->checkForWarnings(); |
90 | | - if ( $warnings ) { |
91 | | - $this->getResult()->addValue( null, $this->getModuleName(), $warnings ); |
| 88 | + |
| 89 | + //xdebug_start_trace(); |
| 90 | + // die("right before xdebug_break"); |
| 91 | + // xdebug_break(); |
| 92 | + |
| 93 | + if ( $this->mParams['stash'] ) { |
| 94 | + wfDebug( "in stash\n" ); |
| 95 | + $result = array(); |
| 96 | + |
| 97 | + $warnings = $this->getApiWarnings(); |
| 98 | + if ( $warnings ) { |
| 99 | + // is it really necessary to say 'result=warning' ? |
| 100 | + $result['result'] = 'Warning'; |
| 101 | + $result['warnings'] = $warnings; |
| 102 | + } |
| 103 | + |
| 104 | + // this saves the file to a temp area and |
| 105 | + // stores the path in the session |
| 106 | + $key = $this->mUpload->stashSession(); |
| 107 | + if ( !$key ) { |
| 108 | + $this->dieUsage( 'Stashing temporary file failed', 'stashfailed' ); |
| 109 | + } |
| 110 | + $result['sessionkey'] = $key; |
| 111 | + |
| 112 | + try { |
| 113 | + $stash = new SessionStash(); |
| 114 | + $file = $stash->getFile( $key ); |
| 115 | + } catch (Exception $e) { |
| 116 | + $this->dieUsage( 'Obtaining stash file failed: ' . $e->getText(), 'stashfailed' ); |
| 117 | + } |
| 118 | + |
| 119 | + // move all this to the session, so it can look up the thumbnail itself, and return opaque url |
| 120 | + // with proper extension. |
| 121 | + |
| 122 | + // thumbnail |
| 123 | + // XXX get default thumbnail width. Isn't this a global? Can't find in docs. |
| 124 | + $thumbWidth = 120; |
| 125 | + if ( array_key_exists( 'thumbWidth', $this->mParams ) ) { |
| 126 | + $thumbWidthParam = ( int )( $this->mParams['thumbWidth'] ); |
| 127 | + if ( $thumbWidthParam > 0 and $thumbWidthParam <= $file->getWidth() ) { |
| 128 | + $thumbWidth = $thumbWidthParam; |
| 129 | + } |
| 130 | + } |
| 131 | + if ( ! $thumb = $file->getThumbnail( $thumbWidth ) ) { |
| 132 | + $this->dieUsageMsg( 'Could not obtain thumbnail', 'nothumb' ); |
| 133 | + } |
| 134 | + |
| 135 | + // get thumbnail urls from the SessionRepo, add to results |
| 136 | + // XXX make this more like the usual imageinfo / thumbnail info API |
| 137 | + $result[ 'thumbnail' ] = array( |
| 138 | + 'url' => $thumb->getUrl(), |
| 139 | + 'width' => $thumb->getWidth(), |
| 140 | + 'height' => $thumb->getHeight(), |
| 141 | + ); |
| 142 | + |
| 143 | + |
| 144 | + // XXX get the rest of the image info including exif data and so on |
| 145 | + |
| 146 | + $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
| 147 | + |
92 | 148 | } else { |
93 | | - // Perform the upload |
94 | | - $result = $this->performUpload(); |
95 | | - $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
| 149 | + |
| 150 | + // Check warnings if necessary |
| 151 | + $warnings = $this->getApiWarnings(); |
| 152 | + |
| 153 | + if ( $warnings ) { |
| 154 | + $sessionKey = $this->mUpload->stashSession(); |
| 155 | + if ( !$sessionKey ) { |
| 156 | + $this->dieUsage( 'Stashing temporary file failed', 'stashfailed' ); |
| 157 | + } |
| 158 | + |
| 159 | + $result['sessionkey'] = $sessionKey; |
| 160 | + |
| 161 | + // is it really necessary to say 'result=warning' |
| 162 | + $result['result'] = 'Warning'; |
| 163 | + $result['warnings'] = $warnings; |
| 164 | + $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
| 165 | + |
| 166 | + } else { |
| 167 | + // Perform the upload |
| 168 | + $result = $this->performUpload(); |
| 169 | + $this->getResult()->addValue( null, $this->getModuleName(), $result ); |
| 170 | + } |
| 171 | + |
96 | 172 | } |
97 | 173 | |
98 | 174 | // Cleanup any temporary mess |
— | — | @@ -249,16 +325,39 @@ |
250 | 326 | } |
251 | 327 | } |
252 | 328 | |
| 329 | + |
253 | 330 | /** |
254 | 331 | * Check warnings if ignorewarnings is not set. |
255 | | - * Returns a suitable result array if there were warnings |
| 332 | + * Returns a suitable array for inclusion into API results if there were warnings |
| 333 | + * Returns the empty array if there were no warnings |
| 334 | + * |
| 335 | + * @return array |
256 | 336 | */ |
257 | | - protected function checkForWarnings() { |
258 | | - $result = array(); |
| 337 | + protected function getApiWarnings() { |
| 338 | + $warnings = array(); |
259 | 339 | |
260 | 340 | if ( !$this->mParams['ignorewarnings'] ) { |
261 | 341 | $warnings = $this->mUpload->checkWarnings(); |
262 | 342 | if ( $warnings ) { |
| 343 | + // Add indices |
| 344 | + $this->getResult()->setIndexedTagName( $warnings, 'warning' ); |
| 345 | + |
| 346 | + if ( isset( $warnings['duplicate'] ) ) { |
| 347 | + $dupes = array(); |
| 348 | + foreach ( $warnings['duplicate'] as $key => $dupe ) { |
| 349 | + $dupes[] = $dupe->getName(); |
| 350 | + } |
| 351 | + // despite 'set' in the name of this function, it just formats $dupes |
| 352 | + $this->getResult()->setIndexedTagName( $dupes, 'duplicate' ); |
| 353 | + $warnings['duplicate'] = $dupes; |
| 354 | + } |
| 355 | + |
| 356 | + if ( isset( $warnings['exists'] ) ) { |
| 357 | + $warning = $warnings['exists']; |
| 358 | + unset( $warnings['exists'] ); |
| 359 | + $warnings[$warning['warning']] = $warning['file']->getName(); |
| 360 | + } |
| 361 | + |
263 | 362 | $result['result'] = 'Warning'; |
264 | 363 | $result['warnings'] = $this->transformWarnings( $warnings ); |
265 | 364 | |
— | — | @@ -272,7 +371,8 @@ |
273 | 372 | return $result; |
274 | 373 | } |
275 | 374 | } |
276 | | - return; |
| 375 | + |
| 376 | + return $warnings; |
277 | 377 | } |
278 | 378 | |
279 | 379 | /** |
— | — | @@ -386,6 +486,9 @@ |
387 | 487 | 'url' => null, |
388 | 488 | |
389 | 489 | 'sessionkey' => null, |
| 490 | + 'stash' => array( |
| 491 | + ApiBase::PARAM_DFLT => false, |
| 492 | + ) |
390 | 493 | ); |
391 | 494 | |
392 | 495 | global $wgAllowAsyncCopyUploads; |
— | — | @@ -410,7 +513,8 @@ |
411 | 514 | 'ignorewarnings' => 'Ignore any warnings', |
412 | 515 | 'file' => 'File contents', |
413 | 516 | 'url' => 'Url to fetch the file from', |
414 | | - 'sessionkey' => 'Session key returned by a previous upload that failed due to warnings', |
| 517 | + 'sessionkey' => 'Session key that identifies a previous upload that was stashed temporarily.', |
| 518 | + 'stash' => 'If set to a true value, the server will not add the file to the repository and stash it temporarily.' |
415 | 519 | ); |
416 | 520 | |
417 | 521 | global $wgAllowAsyncCopyUploads; |
Index: branches/uploadwizard/phase3/includes/Namespace.php |
— | — | @@ -26,6 +26,7 @@ |
27 | 27 | NS_HELP_TALK => 'Help_talk', |
28 | 28 | NS_CATEGORY => 'Category', |
29 | 29 | NS_CATEGORY_TALK => 'Category_talk', |
| 30 | + NS_STASH => 'Stash' |
30 | 31 | ); |
31 | 32 | |
32 | 33 | /// @todo UGLY UGLY |
Index: branches/uploadwizard/phase3/config/Installer.php |
— | — | @@ -893,7 +893,7 @@ |
894 | 894 | switch( $errno ) { |
895 | 895 | case 1045: |
896 | 896 | case 2000: |
897 | | - echo( "failed due to authentication errors. Check passwords.</li>" ); |
| 897 | + echo( "failed due to authentication errors. Check passwords. (Error [$errno] $errtx)</li>" ); |
898 | 898 | if( $conf->Root ) { |
899 | 899 | # The superuser details are wrong |
900 | 900 | $errs["RootUser"] = "Check username"; |
Index: branches/uploadwizard/phase3/languages/Language.php |
— | — | @@ -192,9 +192,12 @@ |
193 | 193 | function __construct() { |
194 | 194 | $this->mConverter = new FakeConverter( $this ); |
195 | 195 | // Set the code to the name of the descendant |
196 | | - if ( get_class( $this ) == 'Language' ) { |
| 196 | + if ( $this->mCode ) { |
| 197 | + return $this->mCode; |
| 198 | + } elseif ( get_class( $this ) == 'Language' ) { |
197 | 199 | $this->mCode = 'en'; |
198 | 200 | } else { |
| 201 | + // XXX this is a bad idea, to assume regular naming -- can't pass in test or other custom objects |
199 | 202 | $this->mCode = str_replace( '_', '-', strtolower( substr( get_class( $this ), 8 ) ) ); |
200 | 203 | } |
201 | 204 | self::getLocalisationCache(); |
— | — | @@ -2553,6 +2556,11 @@ |
2554 | 2557 | * @return string Correct form of plural for $count in this language |
2555 | 2558 | */ |
2556 | 2559 | function convertPlural( $count, $forms ) { |
| 2560 | + |
| 2561 | + // print '<pre>'; |
| 2562 | + // var_dump( debug_backtrace() ); |
| 2563 | + // print '</pre>'; |
| 2564 | + // die( "the end" ); |
2557 | 2565 | if ( !count( $forms ) ) { |
2558 | 2566 | return ''; |
2559 | 2567 | } |
Index: branches/uploadwizard/phase3/languages/classes/LanguageAr.php |
— | — | @@ -7,6 +7,7 @@ |
8 | 8 | */ |
9 | 9 | class LanguageAr extends Language { |
10 | 10 | function convertPlural( $count, $forms ) { |
| 11 | + echo "in the Arabic convertPlural<br/>"; |
11 | 12 | if ( !count( $forms ) ) { return ''; } |
12 | 13 | $forms = $this->preConvertPlural( $forms, 6 ); |
13 | 14 | |
Index: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/samples.js |
— | — | @@ -0,0 +1,16 @@ |
| 2 | +$.mockjaxSettings = { |
| 3 | + responseTime: 650 |
| 4 | +}; |
| 5 | + |
| 6 | +$.mockjax({ |
| 7 | + url: '/some/url', |
| 8 | + responseTime: 1500 |
| 9 | +}); |
| 10 | + |
| 11 | +$.mockjax({ |
| 12 | + url: '/another/url' |
| 13 | +}); |
| 14 | + |
| 15 | +$.mockjax({ |
| 16 | + url: '*', |
| 17 | +}); |
\ No newline at end of file |
Property changes on: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/samples.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 18 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/jquery.mockjax.js |
— | — | @@ -0,0 +1,317 @@ |
| 2 | +/*! |
| 3 | + * MockJax - Mock for Ajax requests |
| 4 | + * |
| 5 | + * Version: 1.3.1 |
| 6 | + * Released: 2010-08-11 |
| 7 | + * Source: http://github.com/appendto/jquery-mockjax |
| 8 | + * Plugin: mockjax |
| 9 | + * Author: Jonathan Sharp (http://jdsharp.com) |
| 10 | + * License: MIT,GPL |
| 11 | + * |
| 12 | + * Copyright (c) 2010 appendTo LLC. |
| 13 | + * Dual licensed under the MIT or GPL licenses. |
| 14 | + * http://appendto.com/open-source-licenses |
| 15 | + */ |
| 16 | +(function($) { |
| 17 | + var _ajax = $.ajax, |
| 18 | + mockHandlers = []; |
| 19 | + |
| 20 | + $.extend({ |
| 21 | + ajax: function(origSettings) { |
| 22 | + var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings), |
| 23 | + mock = false; |
| 24 | + // Iterate over our mock handlers (in registration order) until we find |
| 25 | + // one that is willing to intercept the request |
| 26 | + $.each(mockHandlers, function(k, v) { |
| 27 | + if ( !mockHandlers[k] ) { |
| 28 | + return; |
| 29 | + } |
| 30 | + var m = null; |
| 31 | + // If the mock was registered with a function, let the function decide if we |
| 32 | + // want to mock this request |
| 33 | + if ( $.isFunction(mockHandlers[k]) ) { |
| 34 | + m = mockHandlers[k](s); |
| 35 | + } else { |
| 36 | + m = mockHandlers[k]; |
| 37 | + // Inspect the URL of the request and check if the mock handler's url |
| 38 | + // matches the url for this ajax request |
| 39 | + if ( $.isFunction(m.url.test) ) { |
| 40 | + // The user provided a regex for the url, test it |
| 41 | + if ( !m.url.test( s.url ) ) { |
| 42 | + m = null; |
| 43 | + } |
| 44 | + } else { |
| 45 | + // Look for a simple wildcard '*' or a direct URL match |
| 46 | + var star = m.url.indexOf('*'); |
| 47 | + if ( ( m.url != '*' && m.url != s.url && star == -1 ) || |
| 48 | + ( star > -1 && m.url.substr(0, star) != s.url.substr(0, star) ) ) { |
| 49 | + // The url we tested did not match the wildcard * |
| 50 | + m = null; |
| 51 | + } |
| 52 | + } |
| 53 | + if ( m ) { |
| 54 | + // Inspect the data submitted in the request (either POST body or GET query string) |
| 55 | + if ( m.data && s.data ) { |
| 56 | + var identical = false; |
| 57 | + // Deep inspect the identity of the objects |
| 58 | + (function ident(mock, live) { |
| 59 | + $.each(mock, function(k, v) { |
| 60 | + if ( live[k] === undefined ) { |
| 61 | + identical = false; |
| 62 | + return false; |
| 63 | + } else { |
| 64 | + identical = true; |
| 65 | + if ( typeof live[k] == 'object' ) { |
| 66 | + return ident(mock[k], live[k]); |
| 67 | + } else { |
| 68 | + if ( $.isFunction( mock[k].test ) ) { |
| 69 | + identical = mock[k].test(live[k]); |
| 70 | + } else { |
| 71 | + identical = ( mock[k] == live[k] ); |
| 72 | + } |
| 73 | + return identical; |
| 74 | + } |
| 75 | + } |
| 76 | + }); |
| 77 | + })(m.data, s.data); |
| 78 | + // They're not identical, do not mock this request |
| 79 | + if ( identical == false ) { |
| 80 | + m = null; |
| 81 | + } |
| 82 | + } |
| 83 | + // Inspect the request type |
| 84 | + if ( m && m.type && m.type != s.type ) { |
| 85 | + // The request type doesn't match (GET vs. POST) |
| 86 | + m = null; |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + if ( m ) { |
| 91 | + if ( typeof console !== 'undefined' && console.log ) { |
| 92 | + console.log('MOCK GET: ' + s.url); |
| 93 | + } |
| 94 | + mock = true; |
| 95 | + |
| 96 | + // Handle JSONP Parameter Callbacks, we need to replicate some of the jQuery core here |
| 97 | + // because there isn't an easy hook for the cross domain script tag of jsonp |
| 98 | + if ( s.dataType === "jsonp" ) { |
| 99 | + if ( type === "GET" ) { |
| 100 | + if ( !jsre.test( s.url ) ) { |
| 101 | + s.url += (rquery.test( s.url ) ? "&" : "?") + (s.jsonp || "callback") + "=?"; |
| 102 | + } |
| 103 | + } else if ( !s.data || !jsre.test(s.data) ) { |
| 104 | + s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?"; |
| 105 | + } |
| 106 | + s.dataType = "json"; |
| 107 | + } |
| 108 | + |
| 109 | + // Build temporary JSONP function |
| 110 | + var jsre = /=\?(&|$)/; |
| 111 | + if ( s.dataType === "json" && (s.data && jsre.test(s.data) || jsre.test(s.url)) ) { |
| 112 | + jsonp = s.jsonpCallback || ("jsonp" + jsc++); |
| 113 | + |
| 114 | + // Replace the =? sequence both in the query string and the data |
| 115 | + if ( s.data ) { |
| 116 | + s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1"); |
| 117 | + } |
| 118 | + |
| 119 | + s.url = s.url.replace(jsre, "=" + jsonp + "$1"); |
| 120 | + |
| 121 | + // We need to make sure |
| 122 | + // that a JSONP style response is executed properly |
| 123 | + s.dataType = "script"; |
| 124 | + |
| 125 | + // Handle JSONP-style loading |
| 126 | + window[ jsonp ] = window[ jsonp ] || function( tmp ) { |
| 127 | + data = tmp; |
| 128 | + success(); |
| 129 | + complete(); |
| 130 | + // Garbage collect |
| 131 | + window[ jsonp ] = undefined; |
| 132 | + |
| 133 | + try { |
| 134 | + delete window[ jsonp ]; |
| 135 | + } catch(e) {} |
| 136 | + |
| 137 | + if ( head ) { |
| 138 | + head.removeChild( script ); |
| 139 | + } |
| 140 | + }; |
| 141 | + } |
| 142 | + |
| 143 | + var rurl = /^(\w+:)?\/\/([^\/?#]+)/, |
| 144 | + parts = rurl.exec( s.url ), |
| 145 | + remote = parts && (parts[1] && parts[1] !== location.protocol || parts[2] !== location.host); |
| 146 | + |
| 147 | + // Test if we are going to create a script tag (if so, intercept & mock) |
| 148 | + if ( s.dataType === "script" && s.type === "GET" && remote ) { |
| 149 | + // Synthesize the mock request for adding a script tag |
| 150 | + var callbackContext = origSettings && origSettings.context || s; |
| 151 | + |
| 152 | + function success() { |
| 153 | + // If a local callback was specified, fire it and pass it the data |
| 154 | + if ( s.success ) { |
| 155 | + s.success.call( callbackContext, ( m.response ? m.response.toString() : m.responseText || ''), status, {} ); |
| 156 | + } |
| 157 | + |
| 158 | + // Fire the global callback |
| 159 | + if ( s.global ) { |
| 160 | + trigger( "ajaxSuccess", [{}, s] ); |
| 161 | + } |
| 162 | + } |
| 163 | + |
| 164 | + function complete() { |
| 165 | + // Process result |
| 166 | + if ( s.complete ) { |
| 167 | + s.complete.call( callbackContext, {} , status ); |
| 168 | + } |
| 169 | + |
| 170 | + // The request was completed |
| 171 | + if ( s.global ) { |
| 172 | + trigger( "ajaxComplete", [{}, s] ); |
| 173 | + } |
| 174 | + |
| 175 | + // Handle the global AJAX counter |
| 176 | + if ( s.global && ! --jQuery.active ) { |
| 177 | + jQuery.event.trigger( "ajaxStop" ); |
| 178 | + } |
| 179 | + } |
| 180 | + |
| 181 | + function trigger(type, args) { |
| 182 | + (s.context ? jQuery(s.context) : jQuery.event).trigger(type, args); |
| 183 | + } |
| 184 | + |
| 185 | + //if ( m.response && $.isFunction(m.response) ) { |
| 186 | + // m.response(); |
| 187 | + //} else { |
| 188 | + $.globalEval(m.responseText); |
| 189 | + //} |
| 190 | + success(); |
| 191 | + complete(); |
| 192 | + return false; |
| 193 | + } |
| 194 | + _ajax.call($, $.extend(true, {}, origSettings, { |
| 195 | + // Mock the XHR object |
| 196 | + xhr: function() { |
| 197 | + // Extend with our default mockjax settings |
| 198 | + m = $.extend({}, $.mockjaxSettings, m); |
| 199 | + // Return our mock xhr object |
| 200 | + return { |
| 201 | + status: m.status, |
| 202 | + readyState: 1, |
| 203 | + open: function() { }, |
| 204 | + send: function() { |
| 205 | + var process = $.proxy(function() { |
| 206 | + // The request has returned |
| 207 | + this.status = m.status; |
| 208 | + this.readyState = 4; |
| 209 | + |
| 210 | + // We have an executable function, call it to give |
| 211 | + // the mock a chance to update it's data |
| 212 | + if ( $.isFunction(m.response) ) { |
| 213 | + m.response(); |
| 214 | + } |
| 215 | + // Copy over our mock to our xhr object before passing control back to |
| 216 | + // jQuery's onreadystatechange callback |
| 217 | + if ( s.dataType == 'json' && ( typeof m.responseText == 'object' ) ) { |
| 218 | + this.responseText = JSON.stringify(m.responseText); |
| 219 | + } else if ( s.dataType == 'xml' ) { |
| 220 | + if ( $.xmlDOM && typeof m.responseXML == 'string' ) { |
| 221 | + // Parse the XML from a string into a DOM |
| 222 | + this.responseXML = $.xmlDOM( m.responseXML )[0]; |
| 223 | + } else { |
| 224 | + this.responseXML = m.responseXML; |
| 225 | + } |
| 226 | + } else { |
| 227 | + this.responseText = m.responseText; |
| 228 | + } |
| 229 | + this.onreadystatechange( m.isTimeout ? 'timeout' : undefined ); |
| 230 | + }, this); |
| 231 | + |
| 232 | + if ( m.proxy ) { |
| 233 | + // We're proxying this request and loading in an external file instead |
| 234 | + _ajax({ |
| 235 | + global: false, |
| 236 | + url: m.proxy, |
| 237 | + type: m.type, |
| 238 | + data: m.data, |
| 239 | + dataType: s.dataType, |
| 240 | + complete: function(xhr, txt) { |
| 241 | + m.responseXML = xhr.responseXML; |
| 242 | + m.responseText = xhr.responseText; |
| 243 | + process(); |
| 244 | + } |
| 245 | + }); |
| 246 | + } else { |
| 247 | + // type == 'POST' || 'GET' || 'DELETE' |
| 248 | + if ( s.async === false ) { |
| 249 | + // TODO: Blocking delay |
| 250 | + process(); |
| 251 | + } else { |
| 252 | + this.responseTimer = setTimeout(process, m.responseTime || 50); |
| 253 | + } |
| 254 | + } |
| 255 | + }, |
| 256 | + abort: function() { |
| 257 | + clearTimeout(this.responseTimer); |
| 258 | + }, |
| 259 | + setRequestHeader: function() { }, |
| 260 | + getResponseHeader: function(header) { |
| 261 | + // 'Last-modified', 'Etag', 'content-type' are all checked by jQuery |
| 262 | + if ( m.headers && m.headers[header] ) { |
| 263 | + // Return arbitrary headers |
| 264 | + return m.headers[header]; |
| 265 | + } else if ( header == 'Last-modified' ) { |
| 266 | + return m.lastModified || (new Date()).toString(); |
| 267 | + } else if ( header == 'Etag' ) { |
| 268 | + return m.etag || ''; |
| 269 | + } else if ( header == 'content-type' ) { |
| 270 | + return m.contentType || 'text/plain'; |
| 271 | + } |
| 272 | + } |
| 273 | + }; |
| 274 | + } |
| 275 | + })); |
| 276 | + return false; |
| 277 | + } |
| 278 | + }); |
| 279 | + // We don't have a mock request, trigger a normal request |
| 280 | + if ( !mock ) { |
| 281 | + return _ajax.apply($, arguments); |
| 282 | + } |
| 283 | + } |
| 284 | + }); |
| 285 | + |
| 286 | + $.mockjaxSettings = { |
| 287 | + //url: null, |
| 288 | + //type: 'GET', |
| 289 | + status: 200, |
| 290 | + responseTime: 500, |
| 291 | + isTimeout: false, |
| 292 | + contentType: 'text/plain', |
| 293 | + response: '', |
| 294 | + responseText: '', |
| 295 | + responseXML: '', |
| 296 | + proxy: '', |
| 297 | + |
| 298 | + lastModified: null, |
| 299 | + etag: '', |
| 300 | + headers: { |
| 301 | + etag: 'IJF@H#@923uf8023hFO@I#H#', |
| 302 | + 'content-type' : 'text/plain' |
| 303 | + } |
| 304 | + }; |
| 305 | + |
| 306 | + $.mockjax = function(settings) { |
| 307 | + var i = mockHandlers.length; |
| 308 | + mockHandlers[i] = settings; |
| 309 | + return i; |
| 310 | + }; |
| 311 | + $.mockjaxClear = function(i) { |
| 312 | + if ( arguments.length == 1 ) { |
| 313 | + mockHandlers[i] = null; |
| 314 | + } else { |
| 315 | + mockHandlers = []; |
| 316 | + } |
| 317 | + }; |
| 318 | +})(jQuery); |
Property changes on: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/jquery.mockjax.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 319 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/lib/json2.js |
— | — | @@ -0,0 +1,483 @@ |
| 2 | +/* |
| 3 | + http://www.JSON.org/json2.js |
| 4 | + 2010-03-20 |
| 5 | + |
| 6 | + Public Domain. |
| 7 | + |
| 8 | + NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. |
| 9 | + |
| 10 | + See http://www.JSON.org/js.html |
| 11 | + |
| 12 | + |
| 13 | + This code should be minified before deployment. |
| 14 | + See http://javascript.crockford.com/jsmin.html |
| 15 | + |
| 16 | + USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO |
| 17 | + NOT CONTROL. |
| 18 | + |
| 19 | + |
| 20 | + This file creates a global JSON object containing two methods: stringify |
| 21 | + and parse. |
| 22 | + |
| 23 | + JSON.stringify(value, replacer, space) |
| 24 | + value any JavaScript value, usually an object or array. |
| 25 | + |
| 26 | + replacer an optional parameter that determines how object |
| 27 | + values are stringified for objects. It can be a |
| 28 | + function or an array of strings. |
| 29 | + |
| 30 | + space an optional parameter that specifies the indentation |
| 31 | + of nested structures. If it is omitted, the text will |
| 32 | + be packed without extra whitespace. If it is a number, |
| 33 | + it will specify the number of spaces to indent at each |
| 34 | + level. If it is a string (such as '\t' or ' '), |
| 35 | + it contains the characters used to indent at each level. |
| 36 | + |
| 37 | + This method produces a JSON text from a JavaScript value. |
| 38 | + |
| 39 | + When an object value is found, if the object contains a toJSON |
| 40 | + method, its toJSON method will be called and the result will be |
| 41 | + stringified. A toJSON method does not serialize: it returns the |
| 42 | + value represented by the name/value pair that should be serialized, |
| 43 | + or undefined if nothing should be serialized. The toJSON method |
| 44 | + will be passed the key associated with the value, and this will be |
| 45 | + bound to the value |
| 46 | + |
| 47 | + For example, this would serialize Dates as ISO strings. |
| 48 | + |
| 49 | + Date.prototype.toJSON = function (key) { |
| 50 | + function f(n) { |
| 51 | + // Format integers to have at least two digits. |
| 52 | + return n < 10 ? '0' + n : n; |
| 53 | + } |
| 54 | + |
| 55 | + return this.getUTCFullYear() + '-' + |
| 56 | + f(this.getUTCMonth() + 1) + '-' + |
| 57 | + f(this.getUTCDate()) + 'T' + |
| 58 | + f(this.getUTCHours()) + ':' + |
| 59 | + f(this.getUTCMinutes()) + ':' + |
| 60 | + f(this.getUTCSeconds()) + 'Z'; |
| 61 | + }; |
| 62 | + |
| 63 | + You can provide an optional replacer method. It will be passed the |
| 64 | + key and value of each member, with this bound to the containing |
| 65 | + object. The value that is returned from your method will be |
| 66 | + serialized. If your method returns undefined, then the member will |
| 67 | + be excluded from the serialization. |
| 68 | + |
| 69 | + If the replacer parameter is an array of strings, then it will be |
| 70 | + used to select the members to be serialized. It filters the results |
| 71 | + such that only members with keys listed in the replacer array are |
| 72 | + stringified. |
| 73 | + |
| 74 | + Values that do not have JSON representations, such as undefined or |
| 75 | + functions, will not be serialized. Such values in objects will be |
| 76 | + dropped; in arrays they will be replaced with null. You can use |
| 77 | + a replacer function to replace those with JSON values. |
| 78 | + JSON.stringify(undefined) returns undefined. |
| 79 | + |
| 80 | + The optional space parameter produces a stringification of the |
| 81 | + value that is filled with line breaks and indentation to make it |
| 82 | + easier to read. |
| 83 | + |
| 84 | + If the space parameter is a non-empty string, then that string will |
| 85 | + be used for indentation. If the space parameter is a number, then |
| 86 | + the indentation will be that many spaces. |
| 87 | + |
| 88 | + Example: |
| 89 | + |
| 90 | + text = JSON.stringify(['e', {pluribus: 'unum'}]); |
| 91 | + // text is '["e",{"pluribus":"unum"}]' |
| 92 | + |
| 93 | + |
| 94 | + text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t'); |
| 95 | + // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' |
| 96 | + |
| 97 | + text = JSON.stringify([new Date()], function (key, value) { |
| 98 | + return this[key] instanceof Date ? |
| 99 | + 'Date(' + this[key] + ')' : value; |
| 100 | + }); |
| 101 | + // text is '["Date(---current time---)"]' |
| 102 | + |
| 103 | + |
| 104 | + JSON.parse(text, reviver) |
| 105 | + This method parses a JSON text to produce an object or array. |
| 106 | + It can throw a SyntaxError exception. |
| 107 | + |
| 108 | + The optional reviver parameter is a function that can filter and |
| 109 | + transform the results. It receives each of the keys and values, |
| 110 | + and its return value is used instead of the original value. |
| 111 | + If it returns what it received, then the structure is not modified. |
| 112 | + If it returns undefined then the member is deleted. |
| 113 | + |
| 114 | + Example: |
| 115 | + |
| 116 | + // Parse the text. Values that look like ISO date strings will |
| 117 | + // be converted to Date objects. |
| 118 | + |
| 119 | + myData = JSON.parse(text, function (key, value) { |
| 120 | + var a; |
| 121 | + if (typeof value === 'string') { |
| 122 | + a = |
| 123 | +/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); |
| 124 | + if (a) { |
| 125 | + return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], |
| 126 | + +a[5], +a[6])); |
| 127 | + } |
| 128 | + } |
| 129 | + return value; |
| 130 | + }); |
| 131 | + |
| 132 | + myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) { |
| 133 | + var d; |
| 134 | + if (typeof value === 'string' && |
| 135 | + value.slice(0, 5) === 'Date(' && |
| 136 | + value.slice(-1) === ')') { |
| 137 | + d = new Date(value.slice(5, -1)); |
| 138 | + if (d) { |
| 139 | + return d; |
| 140 | + } |
| 141 | + } |
| 142 | + return value; |
| 143 | + }); |
| 144 | + |
| 145 | + |
| 146 | + This is a reference implementation. You are free to copy, modify, or |
| 147 | + redistribute. |
| 148 | +*/ |
| 149 | + |
| 150 | +/*jslint evil: true, strict: false */ |
| 151 | + |
| 152 | +/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply, |
| 153 | + call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, |
| 154 | + getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, |
| 155 | + lastIndex, length, parse, prototype, push, replace, slice, stringify, |
| 156 | + test, toJSON, toString, valueOf |
| 157 | +*/ |
| 158 | + |
| 159 | + |
| 160 | +// Create a JSON object only if one does not already exist. We create the |
| 161 | +// methods in a closure to avoid creating global variables. |
| 162 | + |
| 163 | +if (!this.JSON) { |
| 164 | + this.JSON = {}; |
| 165 | +} |
| 166 | + |
| 167 | +(function () { |
| 168 | + |
| 169 | + function f(n) { |
| 170 | + // Format integers to have at least two digits. |
| 171 | + return n < 10 ? '0' + n : n; |
| 172 | + } |
| 173 | + |
| 174 | + if (typeof Date.prototype.toJSON !== 'function') { |
| 175 | + |
| 176 | + Date.prototype.toJSON = function (key) { |
| 177 | + |
| 178 | + return isFinite(this.valueOf()) ? |
| 179 | + this.getUTCFullYear() + '-' + |
| 180 | + f(this.getUTCMonth() + 1) + '-' + |
| 181 | + f(this.getUTCDate()) + 'T' + |
| 182 | + f(this.getUTCHours()) + ':' + |
| 183 | + f(this.getUTCMinutes()) + ':' + |
| 184 | + f(this.getUTCSeconds()) + 'Z' : null; |
| 185 | + }; |
| 186 | + |
| 187 | + String.prototype.toJSON = |
| 188 | + Number.prototype.toJSON = |
| 189 | + Boolean.prototype.toJSON = function (key) { |
| 190 | + return this.valueOf(); |
| 191 | + }; |
| 192 | + } |
| 193 | + |
| 194 | + var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, |
| 195 | + escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, |
| 196 | + gap, |
| 197 | + indent, |
| 198 | + meta = { // table of character substitutions |
| 199 | + '\b': '\\b', |
| 200 | + '\t': '\\t', |
| 201 | + '\n': '\\n', |
| 202 | + '\f': '\\f', |
| 203 | + '\r': '\\r', |
| 204 | + '"' : '\\"', |
| 205 | + '\\': '\\\\' |
| 206 | + }, |
| 207 | + rep; |
| 208 | + |
| 209 | + |
| 210 | + function quote(string) { |
| 211 | + |
| 212 | +// If the string contains no control characters, no quote characters, and no |
| 213 | +// backslash characters, then we can safely slap some quotes around it. |
| 214 | +// Otherwise we must also replace the offending characters with safe escape |
| 215 | +// sequences. |
| 216 | + |
| 217 | + escapable.lastIndex = 0; |
| 218 | + return escapable.test(string) ? |
| 219 | + '"' + string.replace(escapable, function (a) { |
| 220 | + var c = meta[a]; |
| 221 | + return typeof c === 'string' ? c : |
| 222 | + '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); |
| 223 | + }) + '"' : |
| 224 | + '"' + string + '"'; |
| 225 | + } |
| 226 | + |
| 227 | + |
| 228 | + function str(key, holder) { |
| 229 | + |
| 230 | +// Produce a string from holder[key]. |
| 231 | + |
| 232 | + var i, // The loop counter. |
| 233 | + k, // The member key. |
| 234 | + v, // The member value. |
| 235 | + length, |
| 236 | + mind = gap, |
| 237 | + partial, |
| 238 | + value = holder[key]; |
| 239 | + |
| 240 | +// If the value has a toJSON method, call it to obtain a replacement value. |
| 241 | + |
| 242 | + if (value && typeof value === 'object' && |
| 243 | + typeof value.toJSON === 'function') { |
| 244 | + value = value.toJSON(key); |
| 245 | + } |
| 246 | + |
| 247 | +// If we were called with a replacer function, then call the replacer to |
| 248 | +// obtain a replacement value. |
| 249 | + |
| 250 | + if (typeof rep === 'function') { |
| 251 | + value = rep.call(holder, key, value); |
| 252 | + } |
| 253 | + |
| 254 | +// What happens next depends on the value's type. |
| 255 | + |
| 256 | + switch (typeof value) { |
| 257 | + case 'string': |
| 258 | + return quote(value); |
| 259 | + |
| 260 | + case 'number': |
| 261 | + |
| 262 | +// JSON numbers must be finite. Encode non-finite numbers as null. |
| 263 | + |
| 264 | + return isFinite(value) ? String(value) : 'null'; |
| 265 | + |
| 266 | + case 'boolean': |
| 267 | + case 'null': |
| 268 | + |
| 269 | +// If the value is a boolean or null, convert it to a string. Note: |
| 270 | +// typeof null does not produce 'null'. The case is included here in |
| 271 | +// the remote chance that this gets fixed someday. |
| 272 | + |
| 273 | + return String(value); |
| 274 | + |
| 275 | +// If the type is 'object', we might be dealing with an object or an array or |
| 276 | +// null. |
| 277 | + |
| 278 | + case 'object': |
| 279 | + |
| 280 | +// Due to a specification blunder in ECMAScript, typeof null is 'object', |
| 281 | +// so watch out for that case. |
| 282 | + |
| 283 | + if (!value) { |
| 284 | + return 'null'; |
| 285 | + } |
| 286 | + |
| 287 | +// Make an array to hold the partial results of stringifying this object value. |
| 288 | + |
| 289 | + gap += indent; |
| 290 | + partial = []; |
| 291 | + |
| 292 | +// Is the value an array? |
| 293 | + |
| 294 | + if (Object.prototype.toString.apply(value) === '[object Array]') { |
| 295 | + |
| 296 | +// The value is an array. Stringify every element. Use null as a placeholder |
| 297 | +// for non-JSON values. |
| 298 | + |
| 299 | + length = value.length; |
| 300 | + for (i = 0; i < length; i += 1) { |
| 301 | + partial[i] = str(i, value) || 'null'; |
| 302 | + } |
| 303 | + |
| 304 | +// Join all of the elements together, separated with commas, and wrap them in |
| 305 | +// brackets. |
| 306 | + |
| 307 | + v = partial.length === 0 ? '[]' : |
| 308 | + gap ? '[\n' + gap + |
| 309 | + partial.join(',\n' + gap) + '\n' + |
| 310 | + mind + ']' : |
| 311 | + '[' + partial.join(',') + ']'; |
| 312 | + gap = mind; |
| 313 | + return v; |
| 314 | + } |
| 315 | + |
| 316 | +// If the replacer is an array, use it to select the members to be stringified. |
| 317 | + |
| 318 | + if (rep && typeof rep === 'object') { |
| 319 | + length = rep.length; |
| 320 | + for (i = 0; i < length; i += 1) { |
| 321 | + k = rep[i]; |
| 322 | + if (typeof k === 'string') { |
| 323 | + v = str(k, value); |
| 324 | + if (v) { |
| 325 | + partial.push(quote(k) + (gap ? ': ' : ':') + v); |
| 326 | + } |
| 327 | + } |
| 328 | + } |
| 329 | + } else { |
| 330 | + |
| 331 | +// Otherwise, iterate through all of the keys in the object. |
| 332 | + |
| 333 | + for (k in value) { |
| 334 | + if (Object.hasOwnProperty.call(value, k)) { |
| 335 | + v = str(k, value); |
| 336 | + if (v) { |
| 337 | + partial.push(quote(k) + (gap ? ': ' : ':') + v); |
| 338 | + } |
| 339 | + } |
| 340 | + } |
| 341 | + } |
| 342 | + |
| 343 | +// Join all of the member texts together, separated with commas, |
| 344 | +// and wrap them in braces. |
| 345 | + |
| 346 | + v = partial.length === 0 ? '{}' : |
| 347 | + gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + |
| 348 | + mind + '}' : '{' + partial.join(',') + '}'; |
| 349 | + gap = mind; |
| 350 | + return v; |
| 351 | + } |
| 352 | + } |
| 353 | + |
| 354 | +// If the JSON object does not yet have a stringify method, give it one. |
| 355 | + |
| 356 | + if (typeof JSON.stringify !== 'function') { |
| 357 | + JSON.stringify = function (value, replacer, space) { |
| 358 | + |
| 359 | +// The stringify method takes a value and an optional replacer, and an optional |
| 360 | +// space parameter, and returns a JSON text. The replacer can be a function |
| 361 | +// that can replace values, or an array of strings that will select the keys. |
| 362 | +// A default replacer method can be provided. Use of the space parameter can |
| 363 | +// produce text that is more easily readable. |
| 364 | + |
| 365 | + var i; |
| 366 | + gap = ''; |
| 367 | + indent = ''; |
| 368 | + |
| 369 | +// If the space parameter is a number, make an indent string containing that |
| 370 | +// many spaces. |
| 371 | + |
| 372 | + if (typeof space === 'number') { |
| 373 | + for (i = 0; i < space; i += 1) { |
| 374 | + indent += ' '; |
| 375 | + } |
| 376 | + |
| 377 | +// If the space parameter is a string, it will be used as the indent string. |
| 378 | + |
| 379 | + } else if (typeof space === 'string') { |
| 380 | + indent = space; |
| 381 | + } |
| 382 | + |
| 383 | +// If there is a replacer, it must be a function or an array. |
| 384 | +// Otherwise, throw an error. |
| 385 | + |
| 386 | + rep = replacer; |
| 387 | + if (replacer && typeof replacer !== 'function' && |
| 388 | + (typeof replacer !== 'object' || |
| 389 | + typeof replacer.length !== 'number')) { |
| 390 | + throw new Error('JSON.stringify'); |
| 391 | + } |
| 392 | + |
| 393 | +// Make a fake root object containing our value under the key of ''. |
| 394 | +// Return the result of stringifying the value. |
| 395 | + |
| 396 | + return str('', {'': value}); |
| 397 | + }; |
| 398 | + } |
| 399 | + |
| 400 | + |
| 401 | +// If the JSON object does not yet have a parse method, give it one. |
| 402 | + |
| 403 | + if (typeof JSON.parse !== 'function') { |
| 404 | + JSON.parse = function (text, reviver) { |
| 405 | + |
| 406 | +// The parse method takes a text and an optional reviver function, and returns |
| 407 | +// a JavaScript value if the text is a valid JSON text. |
| 408 | + |
| 409 | + var j; |
| 410 | + |
| 411 | + function walk(holder, key) { |
| 412 | + |
| 413 | +// The walk method is used to recursively walk the resulting structure so |
| 414 | +// that modifications can be made. |
| 415 | + |
| 416 | + var k, v, value = holder[key]; |
| 417 | + if (value && typeof value === 'object') { |
| 418 | + for (k in value) { |
| 419 | + if (Object.hasOwnProperty.call(value, k)) { |
| 420 | + v = walk(value, k); |
| 421 | + if (v !== undefined) { |
| 422 | + value[k] = v; |
| 423 | + } else { |
| 424 | + delete value[k]; |
| 425 | + } |
| 426 | + } |
| 427 | + } |
| 428 | + } |
| 429 | + return reviver.call(holder, key, value); |
| 430 | + } |
| 431 | + |
| 432 | + |
| 433 | +// Parsing happens in four stages. In the first stage, we replace certain |
| 434 | +// Unicode characters with escape sequences. JavaScript handles many characters |
| 435 | +// incorrectly, either silently deleting them, or treating them as line endings. |
| 436 | + |
| 437 | + text = String(text); |
| 438 | + cx.lastIndex = 0; |
| 439 | + if (cx.test(text)) { |
| 440 | + text = text.replace(cx, function (a) { |
| 441 | + return '\\u' + |
| 442 | + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); |
| 443 | + }); |
| 444 | + } |
| 445 | + |
| 446 | +// In the second stage, we run the text against regular expressions that look |
| 447 | +// for non-JSON patterns. We are especially concerned with '()' and 'new' |
| 448 | +// because they can cause invocation, and '=' because it can cause mutation. |
| 449 | +// But just to be safe, we want to reject all unexpected forms. |
| 450 | + |
| 451 | +// We split the second stage into 4 regexp operations in order to work around |
| 452 | +// crippling inefficiencies in IE's and Safari's regexp engines. First we |
| 453 | +// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we |
| 454 | +// replace all simple value tokens with ']' characters. Third, we delete all |
| 455 | +// open brackets that follow a colon or comma or that begin the text. Finally, |
| 456 | +// we look to see that the remaining characters are only whitespace or ']' or |
| 457 | +// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval. |
| 458 | + |
| 459 | + if (/^[\],:{}\s]*$/. |
| 460 | +test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@'). |
| 461 | +replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'). |
| 462 | +replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { |
| 463 | + |
| 464 | +// In the third stage we use the eval function to compile the text into a |
| 465 | +// JavaScript structure. The '{' operator is subject to a syntactic ambiguity |
| 466 | +// in JavaScript: it can begin a block or an object literal. We wrap the text |
| 467 | +// in parens to eliminate the ambiguity. |
| 468 | + |
| 469 | + j = eval('(' + text + ')'); |
| 470 | + |
| 471 | +// In the optional fourth stage, we recursively walk the new structure, passing |
| 472 | +// each name/value pair to a reviver function for possible transformation. |
| 473 | + |
| 474 | + return typeof reviver === 'function' ? |
| 475 | + walk({'': j}, '') : j; |
| 476 | + } |
| 477 | + |
| 478 | +// If the text is not JSON parseable, then a SyntaxError is thrown. |
| 479 | + |
| 480 | + throw new SyntaxError('JSON.parse'); |
| 481 | + }; |
| 482 | + } |
| 483 | +}()); |
| 484 | + |
Property changes on: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/lib/json2.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 485 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/lib/jquery.xmldom.js |
— | — | @@ -0,0 +1,46 @@ |
| 2 | +/*! |
| 3 | + * jQuery xmlDOM Plugin v1.0 |
| 4 | + * http://outwestmedia.com/jquery-plugins/xmldom/ |
| 5 | + * |
| 6 | + * Released: 2009-04-06 |
| 7 | + * Version: 1.0 |
| 8 | + * |
| 9 | + * Copyright (c) 2009 Jonathan Sharp, Out West Media LLC. |
| 10 | + * Dual licensed under the MIT and GPL licenses. |
| 11 | + * http://docs.jquery.com/License |
| 12 | + */ |
| 13 | +(function($) { |
| 14 | + // IE DOMParser wrapper |
| 15 | + if ( window['DOMParser'] == undefined && window.ActiveXObject ) { |
| 16 | + DOMParser = function() { }; |
| 17 | + DOMParser.prototype.parseFromString = function( xmlString ) { |
| 18 | + var doc = new ActiveXObject('Microsoft.XMLDOM'); |
| 19 | + doc.async = 'false'; |
| 20 | + doc.loadXML( xmlString ); |
| 21 | + return doc; |
| 22 | + }; |
| 23 | + } |
| 24 | + |
| 25 | + $.xmlDOM = function(xml, onErrorFn) { |
| 26 | + try { |
| 27 | + var xmlDoc = ( new DOMParser() ).parseFromString( xml, 'text/xml' ); |
| 28 | + if ( $.isXMLDoc( xmlDoc ) ) { |
| 29 | + var err = $('parsererror', xmlDoc); |
| 30 | + if ( err.length == 1 ) { |
| 31 | + throw('Error: ' + $(xmlDoc).text() ); |
| 32 | + } |
| 33 | + } else { |
| 34 | + throw('Unable to parse XML'); |
| 35 | + } |
| 36 | + } catch( e ) { |
| 37 | + var msg = ( e.name == undefined ? e : e.name + ': ' + e.message ); |
| 38 | + if ( $.isFunction( onErrorFn ) ) { |
| 39 | + onErrorFn( msg ); |
| 40 | + } else { |
| 41 | + $(document).trigger('xmlParseError', [ msg ]); |
| 42 | + } |
| 43 | + return $([]); |
| 44 | + } |
| 45 | + return $( xmlDoc ); |
| 46 | + }; |
| 47 | +})(jQuery); |
\ No newline at end of file |
Property changes on: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/lib/jquery.xmldom.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 48 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/lib/jquery-1.4.2.js |
— | — | @@ -0,0 +1,6240 @@ |
| 2 | +/*! |
| 3 | + * jQuery JavaScript Library v1.4.2 |
| 4 | + * http://jquery.com/ |
| 5 | + * |
| 6 | + * Copyright 2010, John Resig |
| 7 | + * Dual licensed under the MIT or GPL Version 2 licenses. |
| 8 | + * http://jquery.org/license |
| 9 | + * |
| 10 | + * Includes Sizzle.js |
| 11 | + * http://sizzlejs.com/ |
| 12 | + * Copyright 2010, The Dojo Foundation |
| 13 | + * Released under the MIT, BSD, and GPL Licenses. |
| 14 | + * |
| 15 | + * Date: Sat Feb 13 22:33:48 2010 -0500 |
| 16 | + */ |
| 17 | +(function( window, undefined ) { |
| 18 | + |
| 19 | +// Define a local copy of jQuery |
| 20 | +var jQuery = function( selector, context ) { |
| 21 | + // The jQuery object is actually just the init constructor 'enhanced' |
| 22 | + return new jQuery.fn.init( selector, context ); |
| 23 | + }, |
| 24 | + |
| 25 | + // Map over jQuery in case of overwrite |
| 26 | + _jQuery = window.jQuery, |
| 27 | + |
| 28 | + // Map over the $ in case of overwrite |
| 29 | + _$ = window.$, |
| 30 | + |
| 31 | + // Use the correct document accordingly with window argument (sandbox) |
| 32 | + document = window.document, |
| 33 | + |
| 34 | + // A central reference to the root jQuery(document) |
| 35 | + rootjQuery, |
| 36 | + |
| 37 | + // A simple way to check for HTML strings or ID strings |
| 38 | + // (both of which we optimize for) |
| 39 | + quickExpr = /^[^<]*(<[\w\W]+>)[^>]*$|^#([\w-]+)$/, |
| 40 | + |
| 41 | + // Is it a simple selector |
| 42 | + isSimple = /^.[^:#\[\.,]*$/, |
| 43 | + |
| 44 | + // Check if a string has a non-whitespace character in it |
| 45 | + rnotwhite = /\S/, |
| 46 | + |
| 47 | + // Used for trimming whitespace |
| 48 | + rtrim = /^(\s|\u00A0)+|(\s|\u00A0)+$/g, |
| 49 | + |
| 50 | + // Match a standalone tag |
| 51 | + rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/, |
| 52 | + |
| 53 | + // Keep a UserAgent string for use with jQuery.browser |
| 54 | + userAgent = navigator.userAgent, |
| 55 | + |
| 56 | + // For matching the engine and version of the browser |
| 57 | + browserMatch, |
| 58 | + |
| 59 | + // Has the ready events already been bound? |
| 60 | + readyBound = false, |
| 61 | + |
| 62 | + // The functions to execute on DOM ready |
| 63 | + readyList = [], |
| 64 | + |
| 65 | + // The ready event handler |
| 66 | + DOMContentLoaded, |
| 67 | + |
| 68 | + // Save a reference to some core methods |
| 69 | + toString = Object.prototype.toString, |
| 70 | + hasOwnProperty = Object.prototype.hasOwnProperty, |
| 71 | + push = Array.prototype.push, |
| 72 | + slice = Array.prototype.slice, |
| 73 | + indexOf = Array.prototype.indexOf; |
| 74 | + |
| 75 | +jQuery.fn = jQuery.prototype = { |
| 76 | + init: function( selector, context ) { |
| 77 | + var match, elem, ret, doc; |
| 78 | + |
| 79 | + // Handle $(""), $(null), or $(undefined) |
| 80 | + if ( !selector ) { |
| 81 | + return this; |
| 82 | + } |
| 83 | + |
| 84 | + // Handle $(DOMElement) |
| 85 | + if ( selector.nodeType ) { |
| 86 | + this.context = this[0] = selector; |
| 87 | + this.length = 1; |
| 88 | + return this; |
| 89 | + } |
| 90 | + |
| 91 | + // The body element only exists once, optimize finding it |
| 92 | + if ( selector === "body" && !context ) { |
| 93 | + this.context = document; |
| 94 | + this[0] = document.body; |
| 95 | + this.selector = "body"; |
| 96 | + this.length = 1; |
| 97 | + return this; |
| 98 | + } |
| 99 | + |
| 100 | + // Handle HTML strings |
| 101 | + if ( typeof selector === "string" ) { |
| 102 | + // Are we dealing with HTML string or an ID? |
| 103 | + match = quickExpr.exec( selector ); |
| 104 | + |
| 105 | + // Verify a match, and that no context was specified for #id |
| 106 | + if ( match && (match[1] || !context) ) { |
| 107 | + |
| 108 | + // HANDLE: $(html) -> $(array) |
| 109 | + if ( match[1] ) { |
| 110 | + doc = (context ? context.ownerDocument || context : document); |
| 111 | + |
| 112 | + // If a single string is passed in and it's a single tag |
| 113 | + // just do a createElement and skip the rest |
| 114 | + ret = rsingleTag.exec( selector ); |
| 115 | + |
| 116 | + if ( ret ) { |
| 117 | + if ( jQuery.isPlainObject( context ) ) { |
| 118 | + selector = [ document.createElement( ret[1] ) ]; |
| 119 | + jQuery.fn.attr.call( selector, context, true ); |
| 120 | + |
| 121 | + } else { |
| 122 | + selector = [ doc.createElement( ret[1] ) ]; |
| 123 | + } |
| 124 | + |
| 125 | + } else { |
| 126 | + ret = buildFragment( [ match[1] ], [ doc ] ); |
| 127 | + selector = (ret.cacheable ? ret.fragment.cloneNode(true) : ret.fragment).childNodes; |
| 128 | + } |
| 129 | + |
| 130 | + return jQuery.merge( this, selector ); |
| 131 | + |
| 132 | + // HANDLE: $("#id") |
| 133 | + } else { |
| 134 | + elem = document.getElementById( match[2] ); |
| 135 | + |
| 136 | + if ( elem ) { |
| 137 | + // Handle the case where IE and Opera return items |
| 138 | + // by name instead of ID |
| 139 | + if ( elem.id !== match[2] ) { |
| 140 | + return rootjQuery.find( selector ); |
| 141 | + } |
| 142 | + |
| 143 | + // Otherwise, we inject the element directly into the jQuery object |
| 144 | + this.length = 1; |
| 145 | + this[0] = elem; |
| 146 | + } |
| 147 | + |
| 148 | + this.context = document; |
| 149 | + this.selector = selector; |
| 150 | + return this; |
| 151 | + } |
| 152 | + |
| 153 | + // HANDLE: $("TAG") |
| 154 | + } else if ( !context && /^\w+$/.test( selector ) ) { |
| 155 | + this.selector = selector; |
| 156 | + this.context = document; |
| 157 | + selector = document.getElementsByTagName( selector ); |
| 158 | + return jQuery.merge( this, selector ); |
| 159 | + |
| 160 | + // HANDLE: $(expr, $(...)) |
| 161 | + } else if ( !context || context.jquery ) { |
| 162 | + return (context || rootjQuery).find( selector ); |
| 163 | + |
| 164 | + // HANDLE: $(expr, context) |
| 165 | + // (which is just equivalent to: $(context).find(expr) |
| 166 | + } else { |
| 167 | + return jQuery( context ).find( selector ); |
| 168 | + } |
| 169 | + |
| 170 | + // HANDLE: $(function) |
| 171 | + // Shortcut for document ready |
| 172 | + } else if ( jQuery.isFunction( selector ) ) { |
| 173 | + return rootjQuery.ready( selector ); |
| 174 | + } |
| 175 | + |
| 176 | + if (selector.selector !== undefined) { |
| 177 | + this.selector = selector.selector; |
| 178 | + this.context = selector.context; |
| 179 | + } |
| 180 | + |
| 181 | + return jQuery.makeArray( selector, this ); |
| 182 | + }, |
| 183 | + |
| 184 | + // Start with an empty selector |
| 185 | + selector: "", |
| 186 | + |
| 187 | + // The current version of jQuery being used |
| 188 | + jquery: "1.4.2", |
| 189 | + |
| 190 | + // The default length of a jQuery object is 0 |
| 191 | + length: 0, |
| 192 | + |
| 193 | + // The number of elements contained in the matched element set |
| 194 | + size: function() { |
| 195 | + return this.length; |
| 196 | + }, |
| 197 | + |
| 198 | + toArray: function() { |
| 199 | + return slice.call( this, 0 ); |
| 200 | + }, |
| 201 | + |
| 202 | + // Get the Nth element in the matched element set OR |
| 203 | + // Get the whole matched element set as a clean array |
| 204 | + get: function( num ) { |
| 205 | + return num == null ? |
| 206 | + |
| 207 | + // Return a 'clean' array |
| 208 | + this.toArray() : |
| 209 | + |
| 210 | + // Return just the object |
| 211 | + ( num < 0 ? this.slice(num)[ 0 ] : this[ num ] ); |
| 212 | + }, |
| 213 | + |
| 214 | + // Take an array of elements and push it onto the stack |
| 215 | + // (returning the new matched element set) |
| 216 | + pushStack: function( elems, name, selector ) { |
| 217 | + // Build a new jQuery matched element set |
| 218 | + var ret = jQuery(); |
| 219 | + |
| 220 | + if ( jQuery.isArray( elems ) ) { |
| 221 | + push.apply( ret, elems ); |
| 222 | + |
| 223 | + } else { |
| 224 | + jQuery.merge( ret, elems ); |
| 225 | + } |
| 226 | + |
| 227 | + // Add the old object onto the stack (as a reference) |
| 228 | + ret.prevObject = this; |
| 229 | + |
| 230 | + ret.context = this.context; |
| 231 | + |
| 232 | + if ( name === "find" ) { |
| 233 | + ret.selector = this.selector + (this.selector ? " " : "") + selector; |
| 234 | + } else if ( name ) { |
| 235 | + ret.selector = this.selector + "." + name + "(" + selector + ")"; |
| 236 | + } |
| 237 | + |
| 238 | + // Return the newly-formed element set |
| 239 | + return ret; |
| 240 | + }, |
| 241 | + |
| 242 | + // Execute a callback for every element in the matched set. |
| 243 | + // (You can seed the arguments with an array of args, but this is |
| 244 | + // only used internally.) |
| 245 | + each: function( callback, args ) { |
| 246 | + return jQuery.each( this, callback, args ); |
| 247 | + }, |
| 248 | + |
| 249 | + ready: function( fn ) { |
| 250 | + // Attach the listeners |
| 251 | + jQuery.bindReady(); |
| 252 | + |
| 253 | + // If the DOM is already ready |
| 254 | + if ( jQuery.isReady ) { |
| 255 | + // Execute the function immediately |
| 256 | + fn.call( document, jQuery ); |
| 257 | + |
| 258 | + // Otherwise, remember the function for later |
| 259 | + } else if ( readyList ) { |
| 260 | + // Add the function to the wait list |
| 261 | + readyList.push( fn ); |
| 262 | + } |
| 263 | + |
| 264 | + return this; |
| 265 | + }, |
| 266 | + |
| 267 | + eq: function( i ) { |
| 268 | + return i === -1 ? |
| 269 | + this.slice( i ) : |
| 270 | + this.slice( i, +i + 1 ); |
| 271 | + }, |
| 272 | + |
| 273 | + first: function() { |
| 274 | + return this.eq( 0 ); |
| 275 | + }, |
| 276 | + |
| 277 | + last: function() { |
| 278 | + return this.eq( -1 ); |
| 279 | + }, |
| 280 | + |
| 281 | + slice: function() { |
| 282 | + return this.pushStack( slice.apply( this, arguments ), |
| 283 | + "slice", slice.call(arguments).join(",") ); |
| 284 | + }, |
| 285 | + |
| 286 | + map: function( callback ) { |
| 287 | + return this.pushStack( jQuery.map(this, function( elem, i ) { |
| 288 | + return callback.call( elem, i, elem ); |
| 289 | + })); |
| 290 | + }, |
| 291 | + |
| 292 | + end: function() { |
| 293 | + return this.prevObject || jQuery(null); |
| 294 | + }, |
| 295 | + |
| 296 | + // For internal use only. |
| 297 | + // Behaves like an Array's method, not like a jQuery method. |
| 298 | + push: push, |
| 299 | + sort: [].sort, |
| 300 | + splice: [].splice |
| 301 | +}; |
| 302 | + |
| 303 | +// Give the init function the jQuery prototype for later instantiation |
| 304 | +jQuery.fn.init.prototype = jQuery.fn; |
| 305 | + |
| 306 | +jQuery.extend = jQuery.fn.extend = function() { |
| 307 | + // copy reference to target object |
| 308 | + var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options, name, src, copy; |
| 309 | + |
| 310 | + // Handle a deep copy situation |
| 311 | + if ( typeof target === "boolean" ) { |
| 312 | + deep = target; |
| 313 | + target = arguments[1] || {}; |
| 314 | + // skip the boolean and the target |
| 315 | + i = 2; |
| 316 | + } |
| 317 | + |
| 318 | + // Handle case when target is a string or something (possible in deep copy) |
| 319 | + if ( typeof target !== "object" && !jQuery.isFunction(target) ) { |
| 320 | + target = {}; |
| 321 | + } |
| 322 | + |
| 323 | + // extend jQuery itself if only one argument is passed |
| 324 | + if ( length === i ) { |
| 325 | + target = this; |
| 326 | + --i; |
| 327 | + } |
| 328 | + |
| 329 | + for ( ; i < length; i++ ) { |
| 330 | + // Only deal with non-null/undefined values |
| 331 | + if ( (options = arguments[ i ]) != null ) { |
| 332 | + // Extend the base object |
| 333 | + for ( name in options ) { |
| 334 | + src = target[ name ]; |
| 335 | + copy = options[ name ]; |
| 336 | + |
| 337 | + // Prevent never-ending loop |
| 338 | + if ( target === copy ) { |
| 339 | + continue; |
| 340 | + } |
| 341 | + |
| 342 | + // Recurse if we're merging object literal values or arrays |
| 343 | + if ( deep && copy && ( jQuery.isPlainObject(copy) || jQuery.isArray(copy) ) ) { |
| 344 | + var clone = src && ( jQuery.isPlainObject(src) || jQuery.isArray(src) ) ? src |
| 345 | + : jQuery.isArray(copy) ? [] : {}; |
| 346 | + |
| 347 | + // Never move original objects, clone them |
| 348 | + target[ name ] = jQuery.extend( deep, clone, copy ); |
| 349 | + |
| 350 | + // Don't bring in undefined values |
| 351 | + } else if ( copy !== undefined ) { |
| 352 | + target[ name ] = copy; |
| 353 | + } |
| 354 | + } |
| 355 | + } |
| 356 | + } |
| 357 | + |
| 358 | + // Return the modified object |
| 359 | + return target; |
| 360 | +}; |
| 361 | + |
| 362 | +jQuery.extend({ |
| 363 | + noConflict: function( deep ) { |
| 364 | + window.$ = _$; |
| 365 | + |
| 366 | + if ( deep ) { |
| 367 | + window.jQuery = _jQuery; |
| 368 | + } |
| 369 | + |
| 370 | + return jQuery; |
| 371 | + }, |
| 372 | + |
| 373 | + // Is the DOM ready to be used? Set to true once it occurs. |
| 374 | + isReady: false, |
| 375 | + |
| 376 | + // Handle when the DOM is ready |
| 377 | + ready: function() { |
| 378 | + // Make sure that the DOM is not already loaded |
| 379 | + if ( !jQuery.isReady ) { |
| 380 | + // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). |
| 381 | + if ( !document.body ) { |
| 382 | + return setTimeout( jQuery.ready, 13 ); |
| 383 | + } |
| 384 | + |
| 385 | + // Remember that the DOM is ready |
| 386 | + jQuery.isReady = true; |
| 387 | + |
| 388 | + // If there are functions bound, to execute |
| 389 | + if ( readyList ) { |
| 390 | + // Execute all of them |
| 391 | + var fn, i = 0; |
| 392 | + while ( (fn = readyList[ i++ ]) ) { |
| 393 | + fn.call( document, jQuery ); |
| 394 | + } |
| 395 | + |
| 396 | + // Reset the list of functions |
| 397 | + readyList = null; |
| 398 | + } |
| 399 | + |
| 400 | + // Trigger any bound ready events |
| 401 | + if ( jQuery.fn.triggerHandler ) { |
| 402 | + jQuery( document ).triggerHandler( "ready" ); |
| 403 | + } |
| 404 | + } |
| 405 | + }, |
| 406 | + |
| 407 | + bindReady: function() { |
| 408 | + if ( readyBound ) { |
| 409 | + return; |
| 410 | + } |
| 411 | + |
| 412 | + readyBound = true; |
| 413 | + |
| 414 | + // Catch cases where $(document).ready() is called after the |
| 415 | + // browser event has already occurred. |
| 416 | + if ( document.readyState === "complete" ) { |
| 417 | + return jQuery.ready(); |
| 418 | + } |
| 419 | + |
| 420 | + // Mozilla, Opera and webkit nightlies currently support this event |
| 421 | + if ( document.addEventListener ) { |
| 422 | + // Use the handy event callback |
| 423 | + document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false ); |
| 424 | + |
| 425 | + // A fallback to window.onload, that will always work |
| 426 | + window.addEventListener( "load", jQuery.ready, false ); |
| 427 | + |
| 428 | + // If IE event model is used |
| 429 | + } else if ( document.attachEvent ) { |
| 430 | + // ensure firing before onload, |
| 431 | + // maybe late but safe also for iframes |
| 432 | + document.attachEvent("onreadystatechange", DOMContentLoaded); |
| 433 | + |
| 434 | + // A fallback to window.onload, that will always work |
| 435 | + window.attachEvent( "onload", jQuery.ready ); |
| 436 | + |
| 437 | + // If IE and not a frame |
| 438 | + // continually check to see if the document is ready |
| 439 | + var toplevel = false; |
| 440 | + |
| 441 | + try { |
| 442 | + toplevel = window.frameElement == null; |
| 443 | + } catch(e) {} |
| 444 | + |
| 445 | + if ( document.documentElement.doScroll && toplevel ) { |
| 446 | + doScrollCheck(); |
| 447 | + } |
| 448 | + } |
| 449 | + }, |
| 450 | + |
| 451 | + // See test/unit/core.js for details concerning isFunction. |
| 452 | + // Since version 1.3, DOM methods and functions like alert |
| 453 | + // aren't supported. They return false on IE (#2968). |
| 454 | + isFunction: function( obj ) { |
| 455 | + return toString.call(obj) === "[object Function]"; |
| 456 | + }, |
| 457 | + |
| 458 | + isArray: function( obj ) { |
| 459 | + return toString.call(obj) === "[object Array]"; |
| 460 | + }, |
| 461 | + |
| 462 | + isPlainObject: function( obj ) { |
| 463 | + // Must be an Object. |
| 464 | + // Because of IE, we also have to check the presence of the constructor property. |
| 465 | + // Make sure that DOM nodes and window objects don't pass through, as well |
| 466 | + if ( !obj || toString.call(obj) !== "[object Object]" || obj.nodeType || obj.setInterval ) { |
| 467 | + return false; |
| 468 | + } |
| 469 | + |
| 470 | + // Not own constructor property must be Object |
| 471 | + if ( obj.constructor |
| 472 | + && !hasOwnProperty.call(obj, "constructor") |
| 473 | + && !hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf") ) { |
| 474 | + return false; |
| 475 | + } |
| 476 | + |
| 477 | + // Own properties are enumerated firstly, so to speed up, |
| 478 | + // if last one is own, then all properties are own. |
| 479 | + |
| 480 | + var key; |
| 481 | + for ( key in obj ) {} |
| 482 | + |
| 483 | + return key === undefined || hasOwnProperty.call( obj, key ); |
| 484 | + }, |
| 485 | + |
| 486 | + isEmptyObject: function( obj ) { |
| 487 | + for ( var name in obj ) { |
| 488 | + return false; |
| 489 | + } |
| 490 | + return true; |
| 491 | + }, |
| 492 | + |
| 493 | + error: function( msg ) { |
| 494 | + throw msg; |
| 495 | + }, |
| 496 | + |
| 497 | + parseJSON: function( data ) { |
| 498 | + if ( typeof data !== "string" || !data ) { |
| 499 | + return null; |
| 500 | + } |
| 501 | + |
| 502 | + // Make sure leading/trailing whitespace is removed (IE can't handle it) |
| 503 | + data = jQuery.trim( data ); |
| 504 | + |
| 505 | + // Make sure the incoming data is actual JSON |
| 506 | + // Logic borrowed from http://json.org/json2.js |
| 507 | + if ( /^[\],:{}\s]*$/.test(data.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@") |
| 508 | + .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]") |
| 509 | + .replace(/(?:^|:|,)(?:\s*\[)+/g, "")) ) { |
| 510 | + |
| 511 | + // Try to use the native JSON parser first |
| 512 | + return window.JSON && window.JSON.parse ? |
| 513 | + window.JSON.parse( data ) : |
| 514 | + (new Function("return " + data))(); |
| 515 | + |
| 516 | + } else { |
| 517 | + jQuery.error( "Invalid JSON: " + data ); |
| 518 | + } |
| 519 | + }, |
| 520 | + |
| 521 | + noop: function() {}, |
| 522 | + |
| 523 | + // Evalulates a script in a global context |
| 524 | + globalEval: function( data ) { |
| 525 | + if ( data && rnotwhite.test(data) ) { |
| 526 | + // Inspired by code by Andrea Giammarchi |
| 527 | + // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html |
| 528 | + var head = document.getElementsByTagName("head")[0] || document.documentElement, |
| 529 | + script = document.createElement("script"); |
| 530 | + |
| 531 | + script.type = "text/javascript"; |
| 532 | + |
| 533 | + if ( jQuery.support.scriptEval ) { |
| 534 | + script.appendChild( document.createTextNode( data ) ); |
| 535 | + } else { |
| 536 | + script.text = data; |
| 537 | + } |
| 538 | + |
| 539 | + // Use insertBefore instead of appendChild to circumvent an IE6 bug. |
| 540 | + // This arises when a base node is used (#2709). |
| 541 | + head.insertBefore( script, head.firstChild ); |
| 542 | + head.removeChild( script ); |
| 543 | + } |
| 544 | + }, |
| 545 | + |
| 546 | + nodeName: function( elem, name ) { |
| 547 | + return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase(); |
| 548 | + }, |
| 549 | + |
| 550 | + // args is for internal usage only |
| 551 | + each: function( object, callback, args ) { |
| 552 | + var name, i = 0, |
| 553 | + length = object.length, |
| 554 | + isObj = length === undefined || jQuery.isFunction(object); |
| 555 | + |
| 556 | + if ( args ) { |
| 557 | + if ( isObj ) { |
| 558 | + for ( name in object ) { |
| 559 | + if ( callback.apply( object[ name ], args ) === false ) { |
| 560 | + break; |
| 561 | + } |
| 562 | + } |
| 563 | + } else { |
| 564 | + for ( ; i < length; ) { |
| 565 | + if ( callback.apply( object[ i++ ], args ) === false ) { |
| 566 | + break; |
| 567 | + } |
| 568 | + } |
| 569 | + } |
| 570 | + |
| 571 | + // A special, fast, case for the most common use of each |
| 572 | + } else { |
| 573 | + if ( isObj ) { |
| 574 | + for ( name in object ) { |
| 575 | + if ( callback.call( object[ name ], name, object[ name ] ) === false ) { |
| 576 | + break; |
| 577 | + } |
| 578 | + } |
| 579 | + } else { |
| 580 | + for ( var value = object[0]; |
| 581 | + i < length && callback.call( value, i, value ) !== false; value = object[++i] ) {} |
| 582 | + } |
| 583 | + } |
| 584 | + |
| 585 | + return object; |
| 586 | + }, |
| 587 | + |
| 588 | + trim: function( text ) { |
| 589 | + return (text || "").replace( rtrim, "" ); |
| 590 | + }, |
| 591 | + |
| 592 | + // results is for internal usage only |
| 593 | + makeArray: function( array, results ) { |
| 594 | + var ret = results || []; |
| 595 | + |
| 596 | + if ( array != null ) { |
| 597 | + // The window, strings (and functions) also have 'length' |
| 598 | + // The extra typeof function check is to prevent crashes |
| 599 | + // in Safari 2 (See: #3039) |
| 600 | + if ( array.length == null || typeof array === "string" || jQuery.isFunction(array) || (typeof array !== "function" && array.setInterval) ) { |
| 601 | + push.call( ret, array ); |
| 602 | + } else { |
| 603 | + jQuery.merge( ret, array ); |
| 604 | + } |
| 605 | + } |
| 606 | + |
| 607 | + return ret; |
| 608 | + }, |
| 609 | + |
| 610 | + inArray: function( elem, array ) { |
| 611 | + if ( array.indexOf ) { |
| 612 | + return array.indexOf( elem ); |
| 613 | + } |
| 614 | + |
| 615 | + for ( var i = 0, length = array.length; i < length; i++ ) { |
| 616 | + if ( array[ i ] === elem ) { |
| 617 | + return i; |
| 618 | + } |
| 619 | + } |
| 620 | + |
| 621 | + return -1; |
| 622 | + }, |
| 623 | + |
| 624 | + merge: function( first, second ) { |
| 625 | + var i = first.length, j = 0; |
| 626 | + |
| 627 | + if ( typeof second.length === "number" ) { |
| 628 | + for ( var l = second.length; j < l; j++ ) { |
| 629 | + first[ i++ ] = second[ j ]; |
| 630 | + } |
| 631 | + |
| 632 | + } else { |
| 633 | + while ( second[j] !== undefined ) { |
| 634 | + first[ i++ ] = second[ j++ ]; |
| 635 | + } |
| 636 | + } |
| 637 | + |
| 638 | + first.length = i; |
| 639 | + |
| 640 | + return first; |
| 641 | + }, |
| 642 | + |
| 643 | + grep: function( elems, callback, inv ) { |
| 644 | + var ret = []; |
| 645 | + |
| 646 | + // Go through the array, only saving the items |
| 647 | + // that pass the validator function |
| 648 | + for ( var i = 0, length = elems.length; i < length; i++ ) { |
| 649 | + if ( !inv !== !callback( elems[ i ], i ) ) { |
| 650 | + ret.push( elems[ i ] ); |
| 651 | + } |
| 652 | + } |
| 653 | + |
| 654 | + return ret; |
| 655 | + }, |
| 656 | + |
| 657 | + // arg is for internal usage only |
| 658 | + map: function( elems, callback, arg ) { |
| 659 | + var ret = [], value; |
| 660 | + |
| 661 | + // Go through the array, translating each of the items to their |
| 662 | + // new value (or values). |
| 663 | + for ( var i = 0, length = elems.length; i < length; i++ ) { |
| 664 | + value = callback( elems[ i ], i, arg ); |
| 665 | + |
| 666 | + if ( value != null ) { |
| 667 | + ret[ ret.length ] = value; |
| 668 | + } |
| 669 | + } |
| 670 | + |
| 671 | + return ret.concat.apply( [], ret ); |
| 672 | + }, |
| 673 | + |
| 674 | + // A global GUID counter for objects |
| 675 | + guid: 1, |
| 676 | + |
| 677 | + proxy: function( fn, proxy, thisObject ) { |
| 678 | + if ( arguments.length === 2 ) { |
| 679 | + if ( typeof proxy === "string" ) { |
| 680 | + thisObject = fn; |
| 681 | + fn = thisObject[ proxy ]; |
| 682 | + proxy = undefined; |
| 683 | + |
| 684 | + } else if ( proxy && !jQuery.isFunction( proxy ) ) { |
| 685 | + thisObject = proxy; |
| 686 | + proxy = undefined; |
| 687 | + } |
| 688 | + } |
| 689 | + |
| 690 | + if ( !proxy && fn ) { |
| 691 | + proxy = function() { |
| 692 | + return fn.apply( thisObject || this, arguments ); |
| 693 | + }; |
| 694 | + } |
| 695 | + |
| 696 | + // Set the guid of unique handler to the same of original handler, so it can be removed |
| 697 | + if ( fn ) { |
| 698 | + proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++; |
| 699 | + } |
| 700 | + |
| 701 | + // So proxy can be declared as an argument |
| 702 | + return proxy; |
| 703 | + }, |
| 704 | + |
| 705 | + // Use of jQuery.browser is frowned upon. |
| 706 | + // More details: http://docs.jquery.com/Utilities/jQuery.browser |
| 707 | + uaMatch: function( ua ) { |
| 708 | + ua = ua.toLowerCase(); |
| 709 | + |
| 710 | + var match = /(webkit)[ \/]([\w.]+)/.exec( ua ) || |
| 711 | + /(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) || |
| 712 | + /(msie) ([\w.]+)/.exec( ua ) || |
| 713 | + !/compatible/.test( ua ) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) || |
| 714 | + []; |
| 715 | + |
| 716 | + return { browser: match[1] || "", version: match[2] || "0" }; |
| 717 | + }, |
| 718 | + |
| 719 | + browser: {} |
| 720 | +}); |
| 721 | + |
| 722 | +browserMatch = jQuery.uaMatch( userAgent ); |
| 723 | +if ( browserMatch.browser ) { |
| 724 | + jQuery.browser[ browserMatch.browser ] = true; |
| 725 | + jQuery.browser.version = browserMatch.version; |
| 726 | +} |
| 727 | + |
| 728 | +// Deprecated, use jQuery.browser.webkit instead |
| 729 | +if ( jQuery.browser.webkit ) { |
| 730 | + jQuery.browser.safari = true; |
| 731 | +} |
| 732 | + |
| 733 | +if ( indexOf ) { |
| 734 | + jQuery.inArray = function( elem, array ) { |
| 735 | + return indexOf.call( array, elem ); |
| 736 | + }; |
| 737 | +} |
| 738 | + |
| 739 | +// All jQuery objects should point back to these |
| 740 | +rootjQuery = jQuery(document); |
| 741 | + |
| 742 | +// Cleanup functions for the document ready method |
| 743 | +if ( document.addEventListener ) { |
| 744 | + DOMContentLoaded = function() { |
| 745 | + document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false ); |
| 746 | + jQuery.ready(); |
| 747 | + }; |
| 748 | + |
| 749 | +} else if ( document.attachEvent ) { |
| 750 | + DOMContentLoaded = function() { |
| 751 | + // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). |
| 752 | + if ( document.readyState === "complete" ) { |
| 753 | + document.detachEvent( "onreadystatechange", DOMContentLoaded ); |
| 754 | + jQuery.ready(); |
| 755 | + } |
| 756 | + }; |
| 757 | +} |
| 758 | + |
| 759 | +// The DOM ready check for Internet Explorer |
| 760 | +function doScrollCheck() { |
| 761 | + if ( jQuery.isReady ) { |
| 762 | + return; |
| 763 | + } |
| 764 | + |
| 765 | + try { |
| 766 | + // If IE is used, use the trick by Diego Perini |
| 767 | + // http://javascript.nwbox.com/IEContentLoaded/ |
| 768 | + document.documentElement.doScroll("left"); |
| 769 | + } catch( error ) { |
| 770 | + setTimeout( doScrollCheck, 1 ); |
| 771 | + return; |
| 772 | + } |
| 773 | + |
| 774 | + // and execute any waiting functions |
| 775 | + jQuery.ready(); |
| 776 | +} |
| 777 | + |
| 778 | +function evalScript( i, elem ) { |
| 779 | + if ( elem.src ) { |
| 780 | + jQuery.ajax({ |
| 781 | + url: elem.src, |
| 782 | + async: false, |
| 783 | + dataType: "script" |
| 784 | + }); |
| 785 | + } else { |
| 786 | + jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" ); |
| 787 | + } |
| 788 | + |
| 789 | + if ( elem.parentNode ) { |
| 790 | + elem.parentNode.removeChild( elem ); |
| 791 | + } |
| 792 | +} |
| 793 | + |
| 794 | +// Mutifunctional method to get and set values to a collection |
| 795 | +// The value/s can be optionally by executed if its a function |
| 796 | +function access( elems, key, value, exec, fn, pass ) { |
| 797 | + var length = elems.length; |
| 798 | + |
| 799 | + // Setting many attributes |
| 800 | + if ( typeof key === "object" ) { |
| 801 | + for ( var k in key ) { |
| 802 | + access( elems, k, key[k], exec, fn, value ); |
| 803 | + } |
| 804 | + return elems; |
| 805 | + } |
| 806 | + |
| 807 | + // Setting one attribute |
| 808 | + if ( value !== undefined ) { |
| 809 | + // Optionally, function values get executed if exec is true |
| 810 | + exec = !pass && exec && jQuery.isFunction(value); |
| 811 | + |
| 812 | + for ( var i = 0; i < length; i++ ) { |
| 813 | + fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass ); |
| 814 | + } |
| 815 | + |
| 816 | + return elems; |
| 817 | + } |
| 818 | + |
| 819 | + // Getting an attribute |
| 820 | + return length ? fn( elems[0], key ) : undefined; |
| 821 | +} |
| 822 | + |
| 823 | +function now() { |
| 824 | + return (new Date).getTime(); |
| 825 | +} |
| 826 | +(function() { |
| 827 | + |
| 828 | + jQuery.support = {}; |
| 829 | + |
| 830 | + var root = document.documentElement, |
| 831 | + script = document.createElement("script"), |
| 832 | + div = document.createElement("div"), |
| 833 | + id = "script" + now(); |
| 834 | + |
| 835 | + div.style.display = "none"; |
| 836 | + div.innerHTML = " <link/><table></table><a href='/a' style='color:red;float:left;opacity:.55;'>a</a><input type='checkbox'/>"; |
| 837 | + |
| 838 | + var all = div.getElementsByTagName("*"), |
| 839 | + a = div.getElementsByTagName("a")[0]; |
| 840 | + |
| 841 | + // Can't get basic test support |
| 842 | + if ( !all || !all.length || !a ) { |
| 843 | + return; |
| 844 | + } |
| 845 | + |
| 846 | + jQuery.support = { |
| 847 | + // IE strips leading whitespace when .innerHTML is used |
| 848 | + leadingWhitespace: div.firstChild.nodeType === 3, |
| 849 | + |
| 850 | + // Make sure that tbody elements aren't automatically inserted |
| 851 | + // IE will insert them into empty tables |
| 852 | + tbody: !div.getElementsByTagName("tbody").length, |
| 853 | + |
| 854 | + // Make sure that link elements get serialized correctly by innerHTML |
| 855 | + // This requires a wrapper element in IE |
| 856 | + htmlSerialize: !!div.getElementsByTagName("link").length, |
| 857 | + |
| 858 | + // Get the style information from getAttribute |
| 859 | + // (IE uses .cssText insted) |
| 860 | + style: /red/.test( a.getAttribute("style") ), |
| 861 | + |
| 862 | + // Make sure that URLs aren't manipulated |
| 863 | + // (IE normalizes it by default) |
| 864 | + hrefNormalized: a.getAttribute("href") === "/a", |
| 865 | + |
| 866 | + // Make sure that element opacity exists |
| 867 | + // (IE uses filter instead) |
| 868 | + // Use a regex to work around a WebKit issue. See #5145 |
| 869 | + opacity: /^0.55$/.test( a.style.opacity ), |
| 870 | + |
| 871 | + // Verify style float existence |
| 872 | + // (IE uses styleFloat instead of cssFloat) |
| 873 | + cssFloat: !!a.style.cssFloat, |
| 874 | + |
| 875 | + // Make sure that if no value is specified for a checkbox |
| 876 | + // that it defaults to "on". |
| 877 | + // (WebKit defaults to "" instead) |
| 878 | + checkOn: div.getElementsByTagName("input")[0].value === "on", |
| 879 | + |
| 880 | + // Make sure that a selected-by-default option has a working selected property. |
| 881 | + // (WebKit defaults to false instead of true, IE too, if it's in an optgroup) |
| 882 | + optSelected: document.createElement("select").appendChild( document.createElement("option") ).selected, |
| 883 | + |
| 884 | + parentNode: div.removeChild( div.appendChild( document.createElement("div") ) ).parentNode === null, |
| 885 | + |
| 886 | + // Will be defined later |
| 887 | + deleteExpando: true, |
| 888 | + checkClone: false, |
| 889 | + scriptEval: false, |
| 890 | + noCloneEvent: true, |
| 891 | + boxModel: null |
| 892 | + }; |
| 893 | + |
| 894 | + script.type = "text/javascript"; |
| 895 | + try { |
| 896 | + script.appendChild( document.createTextNode( "window." + id + "=1;" ) ); |
| 897 | + } catch(e) {} |
| 898 | + |
| 899 | + root.insertBefore( script, root.firstChild ); |
| 900 | + |
| 901 | + // Make sure that the execution of code works by injecting a script |
| 902 | + // tag with appendChild/createTextNode |
| 903 | + // (IE doesn't support this, fails, and uses .text instead) |
| 904 | + if ( window[ id ] ) { |
| 905 | + jQuery.support.scriptEval = true; |
| 906 | + delete window[ id ]; |
| 907 | + } |
| 908 | + |
| 909 | + // Test to see if it's possible to delete an expando from an element |
| 910 | + // Fails in Internet Explorer |
| 911 | + try { |
| 912 | + delete script.test; |
| 913 | + |
| 914 | + } catch(e) { |
| 915 | + jQuery.support.deleteExpando = false; |
| 916 | + } |
| 917 | + |
| 918 | + root.removeChild( script ); |
| 919 | + |
| 920 | + if ( div.attachEvent && div.fireEvent ) { |
| 921 | + div.attachEvent("onclick", function click() { |
| 922 | + // Cloning a node shouldn't copy over any |
| 923 | + // bound event handlers (IE does this) |
| 924 | + jQuery.support.noCloneEvent = false; |
| 925 | + div.detachEvent("onclick", click); |
| 926 | + }); |
| 927 | + div.cloneNode(true).fireEvent("onclick"); |
| 928 | + } |
| 929 | + |
| 930 | + div = document.createElement("div"); |
| 931 | + div.innerHTML = "<input type='radio' name='radiotest' checked='checked'/>"; |
| 932 | + |
| 933 | + var fragment = document.createDocumentFragment(); |
| 934 | + fragment.appendChild( div.firstChild ); |
| 935 | + |
| 936 | + // WebKit doesn't clone checked state correctly in fragments |
| 937 | + jQuery.support.checkClone = fragment.cloneNode(true).cloneNode(true).lastChild.checked; |
| 938 | + |
| 939 | + // Figure out if the W3C box model works as expected |
| 940 | + // document.body must exist before we can do this |
| 941 | + jQuery(function() { |
| 942 | + var div = document.createElement("div"); |
| 943 | + div.style.width = div.style.paddingLeft = "1px"; |
| 944 | + |
| 945 | + document.body.appendChild( div ); |
| 946 | + jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2; |
| 947 | + document.body.removeChild( div ).style.display = 'none'; |
| 948 | + |
| 949 | + div = null; |
| 950 | + }); |
| 951 | + |
| 952 | + // Technique from Juriy Zaytsev |
| 953 | + // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/ |
| 954 | + var eventSupported = function( eventName ) { |
| 955 | + var el = document.createElement("div"); |
| 956 | + eventName = "on" + eventName; |
| 957 | + |
| 958 | + var isSupported = (eventName in el); |
| 959 | + if ( !isSupported ) { |
| 960 | + el.setAttribute(eventName, "return;"); |
| 961 | + isSupported = typeof el[eventName] === "function"; |
| 962 | + } |
| 963 | + el = null; |
| 964 | + |
| 965 | + return isSupported; |
| 966 | + }; |
| 967 | + |
| 968 | + jQuery.support.submitBubbles = eventSupported("submit"); |
| 969 | + jQuery.support.changeBubbles = eventSupported("change"); |
| 970 | + |
| 971 | + // release memory in IE |
| 972 | + root = script = div = all = a = null; |
| 973 | +})(); |
| 974 | + |
| 975 | +jQuery.props = { |
| 976 | + "for": "htmlFor", |
| 977 | + "class": "className", |
| 978 | + readonly: "readOnly", |
| 979 | + maxlength: "maxLength", |
| 980 | + cellspacing: "cellSpacing", |
| 981 | + rowspan: "rowSpan", |
| 982 | + colspan: "colSpan", |
| 983 | + tabindex: "tabIndex", |
| 984 | + usemap: "useMap", |
| 985 | + frameborder: "frameBorder" |
| 986 | +}; |
| 987 | +var expando = "jQuery" + now(), uuid = 0, windowData = {}; |
| 988 | + |
| 989 | +jQuery.extend({ |
| 990 | + cache: {}, |
| 991 | + |
| 992 | + expando:expando, |
| 993 | + |
| 994 | + // The following elements throw uncatchable exceptions if you |
| 995 | + // attempt to add expando properties to them. |
| 996 | + noData: { |
| 997 | + "embed": true, |
| 998 | + "object": true, |
| 999 | + "applet": true |
| 1000 | + }, |
| 1001 | + |
| 1002 | + data: function( elem, name, data ) { |
| 1003 | + if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) { |
| 1004 | + return; |
| 1005 | + } |
| 1006 | + |
| 1007 | + elem = elem == window ? |
| 1008 | + windowData : |
| 1009 | + elem; |
| 1010 | + |
| 1011 | + var id = elem[ expando ], cache = jQuery.cache, thisCache; |
| 1012 | + |
| 1013 | + if ( !id && typeof name === "string" && data === undefined ) { |
| 1014 | + return null; |
| 1015 | + } |
| 1016 | + |
| 1017 | + // Compute a unique ID for the element |
| 1018 | + if ( !id ) { |
| 1019 | + id = ++uuid; |
| 1020 | + } |
| 1021 | + |
| 1022 | + // Avoid generating a new cache unless none exists and we |
| 1023 | + // want to manipulate it. |
| 1024 | + if ( typeof name === "object" ) { |
| 1025 | + elem[ expando ] = id; |
| 1026 | + thisCache = cache[ id ] = jQuery.extend(true, {}, name); |
| 1027 | + |
| 1028 | + } else if ( !cache[ id ] ) { |
| 1029 | + elem[ expando ] = id; |
| 1030 | + cache[ id ] = {}; |
| 1031 | + } |
| 1032 | + |
| 1033 | + thisCache = cache[ id ]; |
| 1034 | + |
| 1035 | + // Prevent overriding the named cache with undefined values |
| 1036 | + if ( data !== undefined ) { |
| 1037 | + thisCache[ name ] = data; |
| 1038 | + } |
| 1039 | + |
| 1040 | + return typeof name === "string" ? thisCache[ name ] : thisCache; |
| 1041 | + }, |
| 1042 | + |
| 1043 | + removeData: function( elem, name ) { |
| 1044 | + if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) { |
| 1045 | + return; |
| 1046 | + } |
| 1047 | + |
| 1048 | + elem = elem == window ? |
| 1049 | + windowData : |
| 1050 | + elem; |
| 1051 | + |
| 1052 | + var id = elem[ expando ], cache = jQuery.cache, thisCache = cache[ id ]; |
| 1053 | + |
| 1054 | + // If we want to remove a specific section of the element's data |
| 1055 | + if ( name ) { |
| 1056 | + if ( thisCache ) { |
| 1057 | + // Remove the section of cache data |
| 1058 | + delete thisCache[ name ]; |
| 1059 | + |
| 1060 | + // If we've removed all the data, remove the element's cache |
| 1061 | + if ( jQuery.isEmptyObject(thisCache) ) { |
| 1062 | + jQuery.removeData( elem ); |
| 1063 | + } |
| 1064 | + } |
| 1065 | + |
| 1066 | + // Otherwise, we want to remove all of the element's data |
| 1067 | + } else { |
| 1068 | + if ( jQuery.support.deleteExpando ) { |
| 1069 | + delete elem[ jQuery.expando ]; |
| 1070 | + |
| 1071 | + } else if ( elem.removeAttribute ) { |
| 1072 | + elem.removeAttribute( jQuery.expando ); |
| 1073 | + } |
| 1074 | + |
| 1075 | + // Completely remove the data cache |
| 1076 | + delete cache[ id ]; |
| 1077 | + } |
| 1078 | + } |
| 1079 | +}); |
| 1080 | + |
| 1081 | +jQuery.fn.extend({ |
| 1082 | + data: function( key, value ) { |
| 1083 | + if ( typeof key === "undefined" && this.length ) { |
| 1084 | + return jQuery.data( this[0] ); |
| 1085 | + |
| 1086 | + } else if ( typeof key === "object" ) { |
| 1087 | + return this.each(function() { |
| 1088 | + jQuery.data( this, key ); |
| 1089 | + }); |
| 1090 | + } |
| 1091 | + |
| 1092 | + var parts = key.split("."); |
| 1093 | + parts[1] = parts[1] ? "." + parts[1] : ""; |
| 1094 | + |
| 1095 | + if ( value === undefined ) { |
| 1096 | + var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]); |
| 1097 | + |
| 1098 | + if ( data === undefined && this.length ) { |
| 1099 | + data = jQuery.data( this[0], key ); |
| 1100 | + } |
| 1101 | + return data === undefined && parts[1] ? |
| 1102 | + this.data( parts[0] ) : |
| 1103 | + data; |
| 1104 | + } else { |
| 1105 | + return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function() { |
| 1106 | + jQuery.data( this, key, value ); |
| 1107 | + }); |
| 1108 | + } |
| 1109 | + }, |
| 1110 | + |
| 1111 | + removeData: function( key ) { |
| 1112 | + return this.each(function() { |
| 1113 | + jQuery.removeData( this, key ); |
| 1114 | + }); |
| 1115 | + } |
| 1116 | +}); |
| 1117 | +jQuery.extend({ |
| 1118 | + queue: function( elem, type, data ) { |
| 1119 | + if ( !elem ) { |
| 1120 | + return; |
| 1121 | + } |
| 1122 | + |
| 1123 | + type = (type || "fx") + "queue"; |
| 1124 | + var q = jQuery.data( elem, type ); |
| 1125 | + |
| 1126 | + // Speed up dequeue by getting out quickly if this is just a lookup |
| 1127 | + if ( !data ) { |
| 1128 | + return q || []; |
| 1129 | + } |
| 1130 | + |
| 1131 | + if ( !q || jQuery.isArray(data) ) { |
| 1132 | + q = jQuery.data( elem, type, jQuery.makeArray(data) ); |
| 1133 | + |
| 1134 | + } else { |
| 1135 | + q.push( data ); |
| 1136 | + } |
| 1137 | + |
| 1138 | + return q; |
| 1139 | + }, |
| 1140 | + |
| 1141 | + dequeue: function( elem, type ) { |
| 1142 | + type = type || "fx"; |
| 1143 | + |
| 1144 | + var queue = jQuery.queue( elem, type ), fn = queue.shift(); |
| 1145 | + |
| 1146 | + // If the fx queue is dequeued, always remove the progress sentinel |
| 1147 | + if ( fn === "inprogress" ) { |
| 1148 | + fn = queue.shift(); |
| 1149 | + } |
| 1150 | + |
| 1151 | + if ( fn ) { |
| 1152 | + // Add a progress sentinel to prevent the fx queue from being |
| 1153 | + // automatically dequeued |
| 1154 | + if ( type === "fx" ) { |
| 1155 | + queue.unshift("inprogress"); |
| 1156 | + } |
| 1157 | + |
| 1158 | + fn.call(elem, function() { |
| 1159 | + jQuery.dequeue(elem, type); |
| 1160 | + }); |
| 1161 | + } |
| 1162 | + } |
| 1163 | +}); |
| 1164 | + |
| 1165 | +jQuery.fn.extend({ |
| 1166 | + queue: function( type, data ) { |
| 1167 | + if ( typeof type !== "string" ) { |
| 1168 | + data = type; |
| 1169 | + type = "fx"; |
| 1170 | + } |
| 1171 | + |
| 1172 | + if ( data === undefined ) { |
| 1173 | + return jQuery.queue( this[0], type ); |
| 1174 | + } |
| 1175 | + return this.each(function( i, elem ) { |
| 1176 | + var queue = jQuery.queue( this, type, data ); |
| 1177 | + |
| 1178 | + if ( type === "fx" && queue[0] !== "inprogress" ) { |
| 1179 | + jQuery.dequeue( this, type ); |
| 1180 | + } |
| 1181 | + }); |
| 1182 | + }, |
| 1183 | + dequeue: function( type ) { |
| 1184 | + return this.each(function() { |
| 1185 | + jQuery.dequeue( this, type ); |
| 1186 | + }); |
| 1187 | + }, |
| 1188 | + |
| 1189 | + // Based off of the plugin by Clint Helfers, with permission. |
| 1190 | + // http://blindsignals.com/index.php/2009/07/jquery-delay/ |
| 1191 | + delay: function( time, type ) { |
| 1192 | + time = jQuery.fx ? jQuery.fx.speeds[time] || time : time; |
| 1193 | + type = type || "fx"; |
| 1194 | + |
| 1195 | + return this.queue( type, function() { |
| 1196 | + var elem = this; |
| 1197 | + setTimeout(function() { |
| 1198 | + jQuery.dequeue( elem, type ); |
| 1199 | + }, time ); |
| 1200 | + }); |
| 1201 | + }, |
| 1202 | + |
| 1203 | + clearQueue: function( type ) { |
| 1204 | + return this.queue( type || "fx", [] ); |
| 1205 | + } |
| 1206 | +}); |
| 1207 | +var rclass = /[\n\t]/g, |
| 1208 | + rspace = /\s+/, |
| 1209 | + rreturn = /\r/g, |
| 1210 | + rspecialurl = /href|src|style/, |
| 1211 | + rtype = /(button|input)/i, |
| 1212 | + rfocusable = /(button|input|object|select|textarea)/i, |
| 1213 | + rclickable = /^(a|area)$/i, |
| 1214 | + rradiocheck = /radio|checkbox/; |
| 1215 | + |
| 1216 | +jQuery.fn.extend({ |
| 1217 | + attr: function( name, value ) { |
| 1218 | + return access( this, name, value, true, jQuery.attr ); |
| 1219 | + }, |
| 1220 | + |
| 1221 | + removeAttr: function( name, fn ) { |
| 1222 | + return this.each(function(){ |
| 1223 | + jQuery.attr( this, name, "" ); |
| 1224 | + if ( this.nodeType === 1 ) { |
| 1225 | + this.removeAttribute( name ); |
| 1226 | + } |
| 1227 | + }); |
| 1228 | + }, |
| 1229 | + |
| 1230 | + addClass: function( value ) { |
| 1231 | + if ( jQuery.isFunction(value) ) { |
| 1232 | + return this.each(function(i) { |
| 1233 | + var self = jQuery(this); |
| 1234 | + self.addClass( value.call(this, i, self.attr("class")) ); |
| 1235 | + }); |
| 1236 | + } |
| 1237 | + |
| 1238 | + if ( value && typeof value === "string" ) { |
| 1239 | + var classNames = (value || "").split( rspace ); |
| 1240 | + |
| 1241 | + for ( var i = 0, l = this.length; i < l; i++ ) { |
| 1242 | + var elem = this[i]; |
| 1243 | + |
| 1244 | + if ( elem.nodeType === 1 ) { |
| 1245 | + if ( !elem.className ) { |
| 1246 | + elem.className = value; |
| 1247 | + |
| 1248 | + } else { |
| 1249 | + var className = " " + elem.className + " ", setClass = elem.className; |
| 1250 | + for ( var c = 0, cl = classNames.length; c < cl; c++ ) { |
| 1251 | + if ( className.indexOf( " " + classNames[c] + " " ) < 0 ) { |
| 1252 | + setClass += " " + classNames[c]; |
| 1253 | + } |
| 1254 | + } |
| 1255 | + elem.className = jQuery.trim( setClass ); |
| 1256 | + } |
| 1257 | + } |
| 1258 | + } |
| 1259 | + } |
| 1260 | + |
| 1261 | + return this; |
| 1262 | + }, |
| 1263 | + |
| 1264 | + removeClass: function( value ) { |
| 1265 | + if ( jQuery.isFunction(value) ) { |
| 1266 | + return this.each(function(i) { |
| 1267 | + var self = jQuery(this); |
| 1268 | + self.removeClass( value.call(this, i, self.attr("class")) ); |
| 1269 | + }); |
| 1270 | + } |
| 1271 | + |
| 1272 | + if ( (value && typeof value === "string") || value === undefined ) { |
| 1273 | + var classNames = (value || "").split(rspace); |
| 1274 | + |
| 1275 | + for ( var i = 0, l = this.length; i < l; i++ ) { |
| 1276 | + var elem = this[i]; |
| 1277 | + |
| 1278 | + if ( elem.nodeType === 1 && elem.className ) { |
| 1279 | + if ( value ) { |
| 1280 | + var className = (" " + elem.className + " ").replace(rclass, " "); |
| 1281 | + for ( var c = 0, cl = classNames.length; c < cl; c++ ) { |
| 1282 | + className = className.replace(" " + classNames[c] + " ", " "); |
| 1283 | + } |
| 1284 | + elem.className = jQuery.trim( className ); |
| 1285 | + |
| 1286 | + } else { |
| 1287 | + elem.className = ""; |
| 1288 | + } |
| 1289 | + } |
| 1290 | + } |
| 1291 | + } |
| 1292 | + |
| 1293 | + return this; |
| 1294 | + }, |
| 1295 | + |
| 1296 | + toggleClass: function( value, stateVal ) { |
| 1297 | + var type = typeof value, isBool = typeof stateVal === "boolean"; |
| 1298 | + |
| 1299 | + if ( jQuery.isFunction( value ) ) { |
| 1300 | + return this.each(function(i) { |
| 1301 | + var self = jQuery(this); |
| 1302 | + self.toggleClass( value.call(this, i, self.attr("class"), stateVal), stateVal ); |
| 1303 | + }); |
| 1304 | + } |
| 1305 | + |
| 1306 | + return this.each(function() { |
| 1307 | + if ( type === "string" ) { |
| 1308 | + // toggle individual class names |
| 1309 | + var className, i = 0, self = jQuery(this), |
| 1310 | + state = stateVal, |
| 1311 | + classNames = value.split( rspace ); |
| 1312 | + |
| 1313 | + while ( (className = classNames[ i++ ]) ) { |
| 1314 | + // check each className given, space seperated list |
| 1315 | + state = isBool ? state : !self.hasClass( className ); |
| 1316 | + self[ state ? "addClass" : "removeClass" ]( className ); |
| 1317 | + } |
| 1318 | + |
| 1319 | + } else if ( type === "undefined" || type === "boolean" ) { |
| 1320 | + if ( this.className ) { |
| 1321 | + // store className if set |
| 1322 | + jQuery.data( this, "__className__", this.className ); |
| 1323 | + } |
| 1324 | + |
| 1325 | + // toggle whole className |
| 1326 | + this.className = this.className || value === false ? "" : jQuery.data( this, "__className__" ) || ""; |
| 1327 | + } |
| 1328 | + }); |
| 1329 | + }, |
| 1330 | + |
| 1331 | + hasClass: function( selector ) { |
| 1332 | + var className = " " + selector + " "; |
| 1333 | + for ( var i = 0, l = this.length; i < l; i++ ) { |
| 1334 | + if ( (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) { |
| 1335 | + return true; |
| 1336 | + } |
| 1337 | + } |
| 1338 | + |
| 1339 | + return false; |
| 1340 | + }, |
| 1341 | + |
| 1342 | + val: function( value ) { |
| 1343 | + if ( value === undefined ) { |
| 1344 | + var elem = this[0]; |
| 1345 | + |
| 1346 | + if ( elem ) { |
| 1347 | + if ( jQuery.nodeName( elem, "option" ) ) { |
| 1348 | + return (elem.attributes.value || {}).specified ? elem.value : elem.text; |
| 1349 | + } |
| 1350 | + |
| 1351 | + // We need to handle select boxes special |
| 1352 | + if ( jQuery.nodeName( elem, "select" ) ) { |
| 1353 | + var index = elem.selectedIndex, |
| 1354 | + values = [], |
| 1355 | + options = elem.options, |
| 1356 | + one = elem.type === "select-one"; |
| 1357 | + |
| 1358 | + // Nothing was selected |
| 1359 | + if ( index < 0 ) { |
| 1360 | + return null; |
| 1361 | + } |
| 1362 | + |
| 1363 | + // Loop through all the selected options |
| 1364 | + for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) { |
| 1365 | + var option = options[ i ]; |
| 1366 | + |
| 1367 | + if ( option.selected ) { |
| 1368 | + // Get the specifc value for the option |
| 1369 | + value = jQuery(option).val(); |
| 1370 | + |
| 1371 | + // We don't need an array for one selects |
| 1372 | + if ( one ) { |
| 1373 | + return value; |
| 1374 | + } |
| 1375 | + |
| 1376 | + // Multi-Selects return an array |
| 1377 | + values.push( value ); |
| 1378 | + } |
| 1379 | + } |
| 1380 | + |
| 1381 | + return values; |
| 1382 | + } |
| 1383 | + |
| 1384 | + // Handle the case where in Webkit "" is returned instead of "on" if a value isn't specified |
| 1385 | + if ( rradiocheck.test( elem.type ) && !jQuery.support.checkOn ) { |
| 1386 | + return elem.getAttribute("value") === null ? "on" : elem.value; |
| 1387 | + } |
| 1388 | + |
| 1389 | + |
| 1390 | + // Everything else, we just grab the value |
| 1391 | + return (elem.value || "").replace(rreturn, ""); |
| 1392 | + |
| 1393 | + } |
| 1394 | + |
| 1395 | + return undefined; |
| 1396 | + } |
| 1397 | + |
| 1398 | + var isFunction = jQuery.isFunction(value); |
| 1399 | + |
| 1400 | + return this.each(function(i) { |
| 1401 | + var self = jQuery(this), val = value; |
| 1402 | + |
| 1403 | + if ( this.nodeType !== 1 ) { |
| 1404 | + return; |
| 1405 | + } |
| 1406 | + |
| 1407 | + if ( isFunction ) { |
| 1408 | + val = value.call(this, i, self.val()); |
| 1409 | + } |
| 1410 | + |
| 1411 | + // Typecast each time if the value is a Function and the appended |
| 1412 | + // value is therefore different each time. |
| 1413 | + if ( typeof val === "number" ) { |
| 1414 | + val += ""; |
| 1415 | + } |
| 1416 | + |
| 1417 | + if ( jQuery.isArray(val) && rradiocheck.test( this.type ) ) { |
| 1418 | + this.checked = jQuery.inArray( self.val(), val ) >= 0; |
| 1419 | + |
| 1420 | + } else if ( jQuery.nodeName( this, "select" ) ) { |
| 1421 | + var values = jQuery.makeArray(val); |
| 1422 | + |
| 1423 | + jQuery( "option", this ).each(function() { |
| 1424 | + this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0; |
| 1425 | + }); |
| 1426 | + |
| 1427 | + if ( !values.length ) { |
| 1428 | + this.selectedIndex = -1; |
| 1429 | + } |
| 1430 | + |
| 1431 | + } else { |
| 1432 | + this.value = val; |
| 1433 | + } |
| 1434 | + }); |
| 1435 | + } |
| 1436 | +}); |
| 1437 | + |
| 1438 | +jQuery.extend({ |
| 1439 | + attrFn: { |
| 1440 | + val: true, |
| 1441 | + css: true, |
| 1442 | + html: true, |
| 1443 | + text: true, |
| 1444 | + data: true, |
| 1445 | + width: true, |
| 1446 | + height: true, |
| 1447 | + offset: true |
| 1448 | + }, |
| 1449 | + |
| 1450 | + attr: function( elem, name, value, pass ) { |
| 1451 | + // don't set attributes on text and comment nodes |
| 1452 | + if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) { |
| 1453 | + return undefined; |
| 1454 | + } |
| 1455 | + |
| 1456 | + if ( pass && name in jQuery.attrFn ) { |
| 1457 | + return jQuery(elem)[name](value); |
| 1458 | + } |
| 1459 | + |
| 1460 | + var notxml = elem.nodeType !== 1 || !jQuery.isXMLDoc( elem ), |
| 1461 | + // Whether we are setting (or getting) |
| 1462 | + set = value !== undefined; |
| 1463 | + |
| 1464 | + // Try to normalize/fix the name |
| 1465 | + name = notxml && jQuery.props[ name ] || name; |
| 1466 | + |
| 1467 | + // Only do all the following if this is a node (faster for style) |
| 1468 | + if ( elem.nodeType === 1 ) { |
| 1469 | + // These attributes require special treatment |
| 1470 | + var special = rspecialurl.test( name ); |
| 1471 | + |
| 1472 | + // Safari mis-reports the default selected property of an option |
| 1473 | + // Accessing the parent's selectedIndex property fixes it |
| 1474 | + if ( name === "selected" && !jQuery.support.optSelected ) { |
| 1475 | + var parent = elem.parentNode; |
| 1476 | + if ( parent ) { |
| 1477 | + parent.selectedIndex; |
| 1478 | + |
| 1479 | + // Make sure that it also works with optgroups, see #5701 |
| 1480 | + if ( parent.parentNode ) { |
| 1481 | + parent.parentNode.selectedIndex; |
| 1482 | + } |
| 1483 | + } |
| 1484 | + } |
| 1485 | + |
| 1486 | + // If applicable, access the attribute via the DOM 0 way |
| 1487 | + if ( name in elem && notxml && !special ) { |
| 1488 | + if ( set ) { |
| 1489 | + // We can't allow the type property to be changed (since it causes problems in IE) |
| 1490 | + if ( name === "type" && rtype.test( elem.nodeName ) && elem.parentNode ) { |
| 1491 | + jQuery.error( "type property can't be changed" ); |
| 1492 | + } |
| 1493 | + |
| 1494 | + elem[ name ] = value; |
| 1495 | + } |
| 1496 | + |
| 1497 | + // browsers index elements by id/name on forms, give priority to attributes. |
| 1498 | + if ( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) ) { |
| 1499 | + return elem.getAttributeNode( name ).nodeValue; |
| 1500 | + } |
| 1501 | + |
| 1502 | + // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set |
| 1503 | + // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/ |
| 1504 | + if ( name === "tabIndex" ) { |
| 1505 | + var attributeNode = elem.getAttributeNode( "tabIndex" ); |
| 1506 | + |
| 1507 | + return attributeNode && attributeNode.specified ? |
| 1508 | + attributeNode.value : |
| 1509 | + rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ? |
| 1510 | + 0 : |
| 1511 | + undefined; |
| 1512 | + } |
| 1513 | + |
| 1514 | + return elem[ name ]; |
| 1515 | + } |
| 1516 | + |
| 1517 | + if ( !jQuery.support.style && notxml && name === "style" ) { |
| 1518 | + if ( set ) { |
| 1519 | + elem.style.cssText = "" + value; |
| 1520 | + } |
| 1521 | + |
| 1522 | + return elem.style.cssText; |
| 1523 | + } |
| 1524 | + |
| 1525 | + if ( set ) { |
| 1526 | + // convert the value to a string (all browsers do this but IE) see #1070 |
| 1527 | + elem.setAttribute( name, "" + value ); |
| 1528 | + } |
| 1529 | + |
| 1530 | + var attr = !jQuery.support.hrefNormalized && notxml && special ? |
| 1531 | + // Some attributes require a special call on IE |
| 1532 | + elem.getAttribute( name, 2 ) : |
| 1533 | + elem.getAttribute( name ); |
| 1534 | + |
| 1535 | + // Non-existent attributes return null, we normalize to undefined |
| 1536 | + return attr === null ? undefined : attr; |
| 1537 | + } |
| 1538 | + |
| 1539 | + // elem is actually elem.style ... set the style |
| 1540 | + // Using attr for specific style information is now deprecated. Use style instead. |
| 1541 | + return jQuery.style( elem, name, value ); |
| 1542 | + } |
| 1543 | +}); |
| 1544 | +var rnamespaces = /\.(.*)$/, |
| 1545 | + fcleanup = function( nm ) { |
| 1546 | + return nm.replace(/[^\w\s\.\|`]/g, function( ch ) { |
| 1547 | + return "\\" + ch; |
| 1548 | + }); |
| 1549 | + }; |
| 1550 | + |
| 1551 | +/* |
| 1552 | + * A number of helper functions used for managing events. |
| 1553 | + * Many of the ideas behind this code originated from |
| 1554 | + * Dean Edwards' addEvent library. |
| 1555 | + */ |
| 1556 | +jQuery.event = { |
| 1557 | + |
| 1558 | + // Bind an event to an element |
| 1559 | + // Original by Dean Edwards |
| 1560 | + add: function( elem, types, handler, data ) { |
| 1561 | + if ( elem.nodeType === 3 || elem.nodeType === 8 ) { |
| 1562 | + return; |
| 1563 | + } |
| 1564 | + |
| 1565 | + // For whatever reason, IE has trouble passing the window object |
| 1566 | + // around, causing it to be cloned in the process |
| 1567 | + if ( elem.setInterval && ( elem !== window && !elem.frameElement ) ) { |
| 1568 | + elem = window; |
| 1569 | + } |
| 1570 | + |
| 1571 | + var handleObjIn, handleObj; |
| 1572 | + |
| 1573 | + if ( handler.handler ) { |
| 1574 | + handleObjIn = handler; |
| 1575 | + handler = handleObjIn.handler; |
| 1576 | + } |
| 1577 | + |
| 1578 | + // Make sure that the function being executed has a unique ID |
| 1579 | + if ( !handler.guid ) { |
| 1580 | + handler.guid = jQuery.guid++; |
| 1581 | + } |
| 1582 | + |
| 1583 | + // Init the element's event structure |
| 1584 | + var elemData = jQuery.data( elem ); |
| 1585 | + |
| 1586 | + // If no elemData is found then we must be trying to bind to one of the |
| 1587 | + // banned noData elements |
| 1588 | + if ( !elemData ) { |
| 1589 | + return; |
| 1590 | + } |
| 1591 | + |
| 1592 | + var events = elemData.events = elemData.events || {}, |
| 1593 | + eventHandle = elemData.handle, eventHandle; |
| 1594 | + |
| 1595 | + if ( !eventHandle ) { |
| 1596 | + elemData.handle = eventHandle = function() { |
| 1597 | + // Handle the second event of a trigger and when |
| 1598 | + // an event is called after a page has unloaded |
| 1599 | + return typeof jQuery !== "undefined" && !jQuery.event.triggered ? |
| 1600 | + jQuery.event.handle.apply( eventHandle.elem, arguments ) : |
| 1601 | + undefined; |
| 1602 | + }; |
| 1603 | + } |
| 1604 | + |
| 1605 | + // Add elem as a property of the handle function |
| 1606 | + // This is to prevent a memory leak with non-native events in IE. |
| 1607 | + eventHandle.elem = elem; |
| 1608 | + |
| 1609 | + // Handle multiple events separated by a space |
| 1610 | + // jQuery(...).bind("mouseover mouseout", fn); |
| 1611 | + types = types.split(" "); |
| 1612 | + |
| 1613 | + var type, i = 0, namespaces; |
| 1614 | + |
| 1615 | + while ( (type = types[ i++ ]) ) { |
| 1616 | + handleObj = handleObjIn ? |
| 1617 | + jQuery.extend({}, handleObjIn) : |
| 1618 | + { handler: handler, data: data }; |
| 1619 | + |
| 1620 | + // Namespaced event handlers |
| 1621 | + if ( type.indexOf(".") > -1 ) { |
| 1622 | + namespaces = type.split("."); |
| 1623 | + type = namespaces.shift(); |
| 1624 | + handleObj.namespace = namespaces.slice(0).sort().join("."); |
| 1625 | + |
| 1626 | + } else { |
| 1627 | + namespaces = []; |
| 1628 | + handleObj.namespace = ""; |
| 1629 | + } |
| 1630 | + |
| 1631 | + handleObj.type = type; |
| 1632 | + handleObj.guid = handler.guid; |
| 1633 | + |
| 1634 | + // Get the current list of functions bound to this event |
| 1635 | + var handlers = events[ type ], |
| 1636 | + special = jQuery.event.special[ type ] || {}; |
| 1637 | + |
| 1638 | + // Init the event handler queue |
| 1639 | + if ( !handlers ) { |
| 1640 | + handlers = events[ type ] = []; |
| 1641 | + |
| 1642 | + // Check for a special event handler |
| 1643 | + // Only use addEventListener/attachEvent if the special |
| 1644 | + // events handler returns false |
| 1645 | + if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) { |
| 1646 | + // Bind the global event handler to the element |
| 1647 | + if ( elem.addEventListener ) { |
| 1648 | + elem.addEventListener( type, eventHandle, false ); |
| 1649 | + |
| 1650 | + } else if ( elem.attachEvent ) { |
| 1651 | + elem.attachEvent( "on" + type, eventHandle ); |
| 1652 | + } |
| 1653 | + } |
| 1654 | + } |
| 1655 | + |
| 1656 | + if ( special.add ) { |
| 1657 | + special.add.call( elem, handleObj ); |
| 1658 | + |
| 1659 | + if ( !handleObj.handler.guid ) { |
| 1660 | + handleObj.handler.guid = handler.guid; |
| 1661 | + } |
| 1662 | + } |
| 1663 | + |
| 1664 | + // Add the function to the element's handler list |
| 1665 | + handlers.push( handleObj ); |
| 1666 | + |
| 1667 | + // Keep track of which events have been used, for global triggering |
| 1668 | + jQuery.event.global[ type ] = true; |
| 1669 | + } |
| 1670 | + |
| 1671 | + // Nullify elem to prevent memory leaks in IE |
| 1672 | + elem = null; |
| 1673 | + }, |
| 1674 | + |
| 1675 | + global: {}, |
| 1676 | + |
| 1677 | + // Detach an event or set of events from an element |
| 1678 | + remove: function( elem, types, handler, pos ) { |
| 1679 | + // don't do events on text and comment nodes |
| 1680 | + if ( elem.nodeType === 3 || elem.nodeType === 8 ) { |
| 1681 | + return; |
| 1682 | + } |
| 1683 | + |
| 1684 | + var ret, type, fn, i = 0, all, namespaces, namespace, special, eventType, handleObj, origType, |
| 1685 | + elemData = jQuery.data( elem ), |
| 1686 | + events = elemData && elemData.events; |
| 1687 | + |
| 1688 | + if ( !elemData || !events ) { |
| 1689 | + return; |
| 1690 | + } |
| 1691 | + |
| 1692 | + // types is actually an event object here |
| 1693 | + if ( types && types.type ) { |
| 1694 | + handler = types.handler; |
| 1695 | + types = types.type; |
| 1696 | + } |
| 1697 | + |
| 1698 | + // Unbind all events for the element |
| 1699 | + if ( !types || typeof types === "string" && types.charAt(0) === "." ) { |
| 1700 | + types = types || ""; |
| 1701 | + |
| 1702 | + for ( type in events ) { |
| 1703 | + jQuery.event.remove( elem, type + types ); |
| 1704 | + } |
| 1705 | + |
| 1706 | + return; |
| 1707 | + } |
| 1708 | + |
| 1709 | + // Handle multiple events separated by a space |
| 1710 | + // jQuery(...).unbind("mouseover mouseout", fn); |
| 1711 | + types = types.split(" "); |
| 1712 | + |
| 1713 | + while ( (type = types[ i++ ]) ) { |
| 1714 | + origType = type; |
| 1715 | + handleObj = null; |
| 1716 | + all = type.indexOf(".") < 0; |
| 1717 | + namespaces = []; |
| 1718 | + |
| 1719 | + if ( !all ) { |
| 1720 | + // Namespaced event handlers |
| 1721 | + namespaces = type.split("."); |
| 1722 | + type = namespaces.shift(); |
| 1723 | + |
| 1724 | + namespace = new RegExp("(^|\\.)" + |
| 1725 | + jQuery.map( namespaces.slice(0).sort(), fcleanup ).join("\\.(?:.*\\.)?") + "(\\.|$)") |
| 1726 | + } |
| 1727 | + |
| 1728 | + eventType = events[ type ]; |
| 1729 | + |
| 1730 | + if ( !eventType ) { |
| 1731 | + continue; |
| 1732 | + } |
| 1733 | + |
| 1734 | + if ( !handler ) { |
| 1735 | + for ( var j = 0; j < eventType.length; j++ ) { |
| 1736 | + handleObj = eventType[ j ]; |
| 1737 | + |
| 1738 | + if ( all || namespace.test( handleObj.namespace ) ) { |
| 1739 | + jQuery.event.remove( elem, origType, handleObj.handler, j ); |
| 1740 | + eventType.splice( j--, 1 ); |
| 1741 | + } |
| 1742 | + } |
| 1743 | + |
| 1744 | + continue; |
| 1745 | + } |
| 1746 | + |
| 1747 | + special = jQuery.event.special[ type ] || {}; |
| 1748 | + |
| 1749 | + for ( var j = pos || 0; j < eventType.length; j++ ) { |
| 1750 | + handleObj = eventType[ j ]; |
| 1751 | + |
| 1752 | + if ( handler.guid === handleObj.guid ) { |
| 1753 | + // remove the given handler for the given type |
| 1754 | + if ( all || namespace.test( handleObj.namespace ) ) { |
| 1755 | + if ( pos == null ) { |
| 1756 | + eventType.splice( j--, 1 ); |
| 1757 | + } |
| 1758 | + |
| 1759 | + if ( special.remove ) { |
| 1760 | + special.remove.call( elem, handleObj ); |
| 1761 | + } |
| 1762 | + } |
| 1763 | + |
| 1764 | + if ( pos != null ) { |
| 1765 | + break; |
| 1766 | + } |
| 1767 | + } |
| 1768 | + } |
| 1769 | + |
| 1770 | + // remove generic event handler if no more handlers exist |
| 1771 | + if ( eventType.length === 0 || pos != null && eventType.length === 1 ) { |
| 1772 | + if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) { |
| 1773 | + removeEvent( elem, type, elemData.handle ); |
| 1774 | + } |
| 1775 | + |
| 1776 | + ret = null; |
| 1777 | + delete events[ type ]; |
| 1778 | + } |
| 1779 | + } |
| 1780 | + |
| 1781 | + // Remove the expando if it's no longer used |
| 1782 | + if ( jQuery.isEmptyObject( events ) ) { |
| 1783 | + var handle = elemData.handle; |
| 1784 | + if ( handle ) { |
| 1785 | + handle.elem = null; |
| 1786 | + } |
| 1787 | + |
| 1788 | + delete elemData.events; |
| 1789 | + delete elemData.handle; |
| 1790 | + |
| 1791 | + if ( jQuery.isEmptyObject( elemData ) ) { |
| 1792 | + jQuery.removeData( elem ); |
| 1793 | + } |
| 1794 | + } |
| 1795 | + }, |
| 1796 | + |
| 1797 | + // bubbling is internal |
| 1798 | + trigger: function( event, data, elem /*, bubbling */ ) { |
| 1799 | + // Event object or event type |
| 1800 | + var type = event.type || event, |
| 1801 | + bubbling = arguments[3]; |
| 1802 | + |
| 1803 | + if ( !bubbling ) { |
| 1804 | + event = typeof event === "object" ? |
| 1805 | + // jQuery.Event object |
| 1806 | + event[expando] ? event : |
| 1807 | + // Object literal |
| 1808 | + jQuery.extend( jQuery.Event(type), event ) : |
| 1809 | + // Just the event type (string) |
| 1810 | + jQuery.Event(type); |
| 1811 | + |
| 1812 | + if ( type.indexOf("!") >= 0 ) { |
| 1813 | + event.type = type = type.slice(0, -1); |
| 1814 | + event.exclusive = true; |
| 1815 | + } |
| 1816 | + |
| 1817 | + // Handle a global trigger |
| 1818 | + if ( !elem ) { |
| 1819 | + // Don't bubble custom events when global (to avoid too much overhead) |
| 1820 | + event.stopPropagation(); |
| 1821 | + |
| 1822 | + // Only trigger if we've ever bound an event for it |
| 1823 | + if ( jQuery.event.global[ type ] ) { |
| 1824 | + jQuery.each( jQuery.cache, function() { |
| 1825 | + if ( this.events && this.events[type] ) { |
| 1826 | + jQuery.event.trigger( event, data, this.handle.elem ); |
| 1827 | + } |
| 1828 | + }); |
| 1829 | + } |
| 1830 | + } |
| 1831 | + |
| 1832 | + // Handle triggering a single element |
| 1833 | + |
| 1834 | + // don't do events on text and comment nodes |
| 1835 | + if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) { |
| 1836 | + return undefined; |
| 1837 | + } |
| 1838 | + |
| 1839 | + // Clean up in case it is reused |
| 1840 | + event.result = undefined; |
| 1841 | + event.target = elem; |
| 1842 | + |
| 1843 | + // Clone the incoming data, if any |
| 1844 | + data = jQuery.makeArray( data ); |
| 1845 | + data.unshift( event ); |
| 1846 | + } |
| 1847 | + |
| 1848 | + event.currentTarget = elem; |
| 1849 | + |
| 1850 | + // Trigger the event, it is assumed that "handle" is a function |
| 1851 | + var handle = jQuery.data( elem, "handle" ); |
| 1852 | + if ( handle ) { |
| 1853 | + handle.apply( elem, data ); |
| 1854 | + } |
| 1855 | + |
| 1856 | + var parent = elem.parentNode || elem.ownerDocument; |
| 1857 | + |
| 1858 | + // Trigger an inline bound script |
| 1859 | + try { |
| 1860 | + if ( !(elem && elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()]) ) { |
| 1861 | + if ( elem[ "on" + type ] && elem[ "on" + type ].apply( elem, data ) === false ) { |
| 1862 | + event.result = false; |
| 1863 | + } |
| 1864 | + } |
| 1865 | + |
| 1866 | + // prevent IE from throwing an error for some elements with some event types, see #3533 |
| 1867 | + } catch (e) {} |
| 1868 | + |
| 1869 | + if ( !event.isPropagationStopped() && parent ) { |
| 1870 | + jQuery.event.trigger( event, data, parent, true ); |
| 1871 | + |
| 1872 | + } else if ( !event.isDefaultPrevented() ) { |
| 1873 | + var target = event.target, old, |
| 1874 | + isClick = jQuery.nodeName(target, "a") && type === "click", |
| 1875 | + special = jQuery.event.special[ type ] || {}; |
| 1876 | + |
| 1877 | + if ( (!special._default || special._default.call( elem, event ) === false) && |
| 1878 | + !isClick && !(target && target.nodeName && jQuery.noData[target.nodeName.toLowerCase()]) ) { |
| 1879 | + |
| 1880 | + try { |
| 1881 | + if ( target[ type ] ) { |
| 1882 | + // Make sure that we don't accidentally re-trigger the onFOO events |
| 1883 | + old = target[ "on" + type ]; |
| 1884 | + |
| 1885 | + if ( old ) { |
| 1886 | + target[ "on" + type ] = null; |
| 1887 | + } |
| 1888 | + |
| 1889 | + jQuery.event.triggered = true; |
| 1890 | + target[ type ](); |
| 1891 | + } |
| 1892 | + |
| 1893 | + // prevent IE from throwing an error for some elements with some event types, see #3533 |
| 1894 | + } catch (e) {} |
| 1895 | + |
| 1896 | + if ( old ) { |
| 1897 | + target[ "on" + type ] = old; |
| 1898 | + } |
| 1899 | + |
| 1900 | + jQuery.event.triggered = false; |
| 1901 | + } |
| 1902 | + } |
| 1903 | + }, |
| 1904 | + |
| 1905 | + handle: function( event ) { |
| 1906 | + var all, handlers, namespaces, namespace, events; |
| 1907 | + |
| 1908 | + event = arguments[0] = jQuery.event.fix( event || window.event ); |
| 1909 | + event.currentTarget = this; |
| 1910 | + |
| 1911 | + // Namespaced event handlers |
| 1912 | + all = event.type.indexOf(".") < 0 && !event.exclusive; |
| 1913 | + |
| 1914 | + if ( !all ) { |
| 1915 | + namespaces = event.type.split("."); |
| 1916 | + event.type = namespaces.shift(); |
| 1917 | + namespace = new RegExp("(^|\\.)" + namespaces.slice(0).sort().join("\\.(?:.*\\.)?") + "(\\.|$)"); |
| 1918 | + } |
| 1919 | + |
| 1920 | + var events = jQuery.data(this, "events"), handlers = events[ event.type ]; |
| 1921 | + |
| 1922 | + if ( events && handlers ) { |
| 1923 | + // Clone the handlers to prevent manipulation |
| 1924 | + handlers = handlers.slice(0); |
| 1925 | + |
| 1926 | + for ( var j = 0, l = handlers.length; j < l; j++ ) { |
| 1927 | + var handleObj = handlers[ j ]; |
| 1928 | + |
| 1929 | + // Filter the functions by class |
| 1930 | + if ( all || namespace.test( handleObj.namespace ) ) { |
| 1931 | + // Pass in a reference to the handler function itself |
| 1932 | + // So that we can later remove it |
| 1933 | + event.handler = handleObj.handler; |
| 1934 | + event.data = handleObj.data; |
| 1935 | + event.handleObj = handleObj; |
| 1936 | + |
| 1937 | + var ret = handleObj.handler.apply( this, arguments ); |
| 1938 | + |
| 1939 | + if ( ret !== undefined ) { |
| 1940 | + event.result = ret; |
| 1941 | + if ( ret === false ) { |
| 1942 | + event.preventDefault(); |
| 1943 | + event.stopPropagation(); |
| 1944 | + } |
| 1945 | + } |
| 1946 | + |
| 1947 | + if ( event.isImmediatePropagationStopped() ) { |
| 1948 | + break; |
| 1949 | + } |
| 1950 | + } |
| 1951 | + } |
| 1952 | + } |
| 1953 | + |
| 1954 | + return event.result; |
| 1955 | + }, |
| 1956 | + |
| 1957 | + props: "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode layerX layerY metaKey newValue offsetX offsetY originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "), |
| 1958 | + |
| 1959 | + fix: function( event ) { |
| 1960 | + if ( event[ expando ] ) { |
| 1961 | + return event; |
| 1962 | + } |
| 1963 | + |
| 1964 | + // store a copy of the original event object |
| 1965 | + // and "clone" to set read-only properties |
| 1966 | + var originalEvent = event; |
| 1967 | + event = jQuery.Event( originalEvent ); |
| 1968 | + |
| 1969 | + for ( var i = this.props.length, prop; i; ) { |
| 1970 | + prop = this.props[ --i ]; |
| 1971 | + event[ prop ] = originalEvent[ prop ]; |
| 1972 | + } |
| 1973 | + |
| 1974 | + // Fix target property, if necessary |
| 1975 | + if ( !event.target ) { |
| 1976 | + event.target = event.srcElement || document; // Fixes #1925 where srcElement might not be defined either |
| 1977 | + } |
| 1978 | + |
| 1979 | + // check if target is a textnode (safari) |
| 1980 | + if ( event.target.nodeType === 3 ) { |
| 1981 | + event.target = event.target.parentNode; |
| 1982 | + } |
| 1983 | + |
| 1984 | + // Add relatedTarget, if necessary |
| 1985 | + if ( !event.relatedTarget && event.fromElement ) { |
| 1986 | + event.relatedTarget = event.fromElement === event.target ? event.toElement : event.fromElement; |
| 1987 | + } |
| 1988 | + |
| 1989 | + // Calculate pageX/Y if missing and clientX/Y available |
| 1990 | + if ( event.pageX == null && event.clientX != null ) { |
| 1991 | + var doc = document.documentElement, body = document.body; |
| 1992 | + event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0); |
| 1993 | + event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0); |
| 1994 | + } |
| 1995 | + |
| 1996 | + // Add which for key events |
| 1997 | + if ( !event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode) ) { |
| 1998 | + event.which = event.charCode || event.keyCode; |
| 1999 | + } |
| 2000 | + |
| 2001 | + // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs) |
| 2002 | + if ( !event.metaKey && event.ctrlKey ) { |
| 2003 | + event.metaKey = event.ctrlKey; |
| 2004 | + } |
| 2005 | + |
| 2006 | + // Add which for click: 1 === left; 2 === middle; 3 === right |
| 2007 | + // Note: button is not normalized, so don't use it |
| 2008 | + if ( !event.which && event.button !== undefined ) { |
| 2009 | + event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) )); |
| 2010 | + } |
| 2011 | + |
| 2012 | + return event; |
| 2013 | + }, |
| 2014 | + |
| 2015 | + // Deprecated, use jQuery.guid instead |
| 2016 | + guid: 1E8, |
| 2017 | + |
| 2018 | + // Deprecated, use jQuery.proxy instead |
| 2019 | + proxy: jQuery.proxy, |
| 2020 | + |
| 2021 | + special: { |
| 2022 | + ready: { |
| 2023 | + // Make sure the ready event is setup |
| 2024 | + setup: jQuery.bindReady, |
| 2025 | + teardown: jQuery.noop |
| 2026 | + }, |
| 2027 | + |
| 2028 | + live: { |
| 2029 | + add: function( handleObj ) { |
| 2030 | + jQuery.event.add( this, handleObj.origType, jQuery.extend({}, handleObj, {handler: liveHandler}) ); |
| 2031 | + }, |
| 2032 | + |
| 2033 | + remove: function( handleObj ) { |
| 2034 | + var remove = true, |
| 2035 | + type = handleObj.origType.replace(rnamespaces, ""); |
| 2036 | + |
| 2037 | + jQuery.each( jQuery.data(this, "events").live || [], function() { |
| 2038 | + if ( type === this.origType.replace(rnamespaces, "") ) { |
| 2039 | + remove = false; |
| 2040 | + return false; |
| 2041 | + } |
| 2042 | + }); |
| 2043 | + |
| 2044 | + if ( remove ) { |
| 2045 | + jQuery.event.remove( this, handleObj.origType, liveHandler ); |
| 2046 | + } |
| 2047 | + } |
| 2048 | + |
| 2049 | + }, |
| 2050 | + |
| 2051 | + beforeunload: { |
| 2052 | + setup: function( data, namespaces, eventHandle ) { |
| 2053 | + // We only want to do this special case on windows |
| 2054 | + if ( this.setInterval ) { |
| 2055 | + this.onbeforeunload = eventHandle; |
| 2056 | + } |
| 2057 | + |
| 2058 | + return false; |
| 2059 | + }, |
| 2060 | + teardown: function( namespaces, eventHandle ) { |
| 2061 | + if ( this.onbeforeunload === eventHandle ) { |
| 2062 | + this.onbeforeunload = null; |
| 2063 | + } |
| 2064 | + } |
| 2065 | + } |
| 2066 | + } |
| 2067 | +}; |
| 2068 | + |
| 2069 | +var removeEvent = document.removeEventListener ? |
| 2070 | + function( elem, type, handle ) { |
| 2071 | + elem.removeEventListener( type, handle, false ); |
| 2072 | + } : |
| 2073 | + function( elem, type, handle ) { |
| 2074 | + elem.detachEvent( "on" + type, handle ); |
| 2075 | + }; |
| 2076 | + |
| 2077 | +jQuery.Event = function( src ) { |
| 2078 | + // Allow instantiation without the 'new' keyword |
| 2079 | + if ( !this.preventDefault ) { |
| 2080 | + return new jQuery.Event( src ); |
| 2081 | + } |
| 2082 | + |
| 2083 | + // Event object |
| 2084 | + if ( src && src.type ) { |
| 2085 | + this.originalEvent = src; |
| 2086 | + this.type = src.type; |
| 2087 | + // Event type |
| 2088 | + } else { |
| 2089 | + this.type = src; |
| 2090 | + } |
| 2091 | + |
| 2092 | + // timeStamp is buggy for some events on Firefox(#3843) |
| 2093 | + // So we won't rely on the native value |
| 2094 | + this.timeStamp = now(); |
| 2095 | + |
| 2096 | + // Mark it as fixed |
| 2097 | + this[ expando ] = true; |
| 2098 | +}; |
| 2099 | + |
| 2100 | +function returnFalse() { |
| 2101 | + return false; |
| 2102 | +} |
| 2103 | +function returnTrue() { |
| 2104 | + return true; |
| 2105 | +} |
| 2106 | + |
| 2107 | +// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding |
| 2108 | +// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html |
| 2109 | +jQuery.Event.prototype = { |
| 2110 | + preventDefault: function() { |
| 2111 | + this.isDefaultPrevented = returnTrue; |
| 2112 | + |
| 2113 | + var e = this.originalEvent; |
| 2114 | + if ( !e ) { |
| 2115 | + return; |
| 2116 | + } |
| 2117 | + |
| 2118 | + // if preventDefault exists run it on the original event |
| 2119 | + if ( e.preventDefault ) { |
| 2120 | + e.preventDefault(); |
| 2121 | + } |
| 2122 | + // otherwise set the returnValue property of the original event to false (IE) |
| 2123 | + e.returnValue = false; |
| 2124 | + }, |
| 2125 | + stopPropagation: function() { |
| 2126 | + this.isPropagationStopped = returnTrue; |
| 2127 | + |
| 2128 | + var e = this.originalEvent; |
| 2129 | + if ( !e ) { |
| 2130 | + return; |
| 2131 | + } |
| 2132 | + // if stopPropagation exists run it on the original event |
| 2133 | + if ( e.stopPropagation ) { |
| 2134 | + e.stopPropagation(); |
| 2135 | + } |
| 2136 | + // otherwise set the cancelBubble property of the original event to true (IE) |
| 2137 | + e.cancelBubble = true; |
| 2138 | + }, |
| 2139 | + stopImmediatePropagation: function() { |
| 2140 | + this.isImmediatePropagationStopped = returnTrue; |
| 2141 | + this.stopPropagation(); |
| 2142 | + }, |
| 2143 | + isDefaultPrevented: returnFalse, |
| 2144 | + isPropagationStopped: returnFalse, |
| 2145 | + isImmediatePropagationStopped: returnFalse |
| 2146 | +}; |
| 2147 | + |
| 2148 | +// Checks if an event happened on an element within another element |
| 2149 | +// Used in jQuery.event.special.mouseenter and mouseleave handlers |
| 2150 | +var withinElement = function( event ) { |
| 2151 | + // Check if mouse(over|out) are still within the same parent element |
| 2152 | + var parent = event.relatedTarget; |
| 2153 | + |
| 2154 | + // Firefox sometimes assigns relatedTarget a XUL element |
| 2155 | + // which we cannot access the parentNode property of |
| 2156 | + try { |
| 2157 | + // Traverse up the tree |
| 2158 | + while ( parent && parent !== this ) { |
| 2159 | + parent = parent.parentNode; |
| 2160 | + } |
| 2161 | + |
| 2162 | + if ( parent !== this ) { |
| 2163 | + // set the correct event type |
| 2164 | + event.type = event.data; |
| 2165 | + |
| 2166 | + // handle event if we actually just moused on to a non sub-element |
| 2167 | + jQuery.event.handle.apply( this, arguments ); |
| 2168 | + } |
| 2169 | + |
| 2170 | + // assuming we've left the element since we most likely mousedover a xul element |
| 2171 | + } catch(e) { } |
| 2172 | +}, |
| 2173 | + |
| 2174 | +// In case of event delegation, we only need to rename the event.type, |
| 2175 | +// liveHandler will take care of the rest. |
| 2176 | +delegate = function( event ) { |
| 2177 | + event.type = event.data; |
| 2178 | + jQuery.event.handle.apply( this, arguments ); |
| 2179 | +}; |
| 2180 | + |
| 2181 | +// Create mouseenter and mouseleave events |
| 2182 | +jQuery.each({ |
| 2183 | + mouseenter: "mouseover", |
| 2184 | + mouseleave: "mouseout" |
| 2185 | +}, function( orig, fix ) { |
| 2186 | + jQuery.event.special[ orig ] = { |
| 2187 | + setup: function( data ) { |
| 2188 | + jQuery.event.add( this, fix, data && data.selector ? delegate : withinElement, orig ); |
| 2189 | + }, |
| 2190 | + teardown: function( data ) { |
| 2191 | + jQuery.event.remove( this, fix, data && data.selector ? delegate : withinElement ); |
| 2192 | + } |
| 2193 | + }; |
| 2194 | +}); |
| 2195 | + |
| 2196 | +// submit delegation |
| 2197 | +if ( !jQuery.support.submitBubbles ) { |
| 2198 | + |
| 2199 | + jQuery.event.special.submit = { |
| 2200 | + setup: function( data, namespaces ) { |
| 2201 | + if ( this.nodeName.toLowerCase() !== "form" ) { |
| 2202 | + jQuery.event.add(this, "click.specialSubmit", function( e ) { |
| 2203 | + var elem = e.target, type = elem.type; |
| 2204 | + |
| 2205 | + if ( (type === "submit" || type === "image") && jQuery( elem ).closest("form").length ) { |
| 2206 | + return trigger( "submit", this, arguments ); |
| 2207 | + } |
| 2208 | + }); |
| 2209 | + |
| 2210 | + jQuery.event.add(this, "keypress.specialSubmit", function( e ) { |
| 2211 | + var elem = e.target, type = elem.type; |
| 2212 | + |
| 2213 | + if ( (type === "text" || type === "password") && jQuery( elem ).closest("form").length && e.keyCode === 13 ) { |
| 2214 | + return trigger( "submit", this, arguments ); |
| 2215 | + } |
| 2216 | + }); |
| 2217 | + |
| 2218 | + } else { |
| 2219 | + return false; |
| 2220 | + } |
| 2221 | + }, |
| 2222 | + |
| 2223 | + teardown: function( namespaces ) { |
| 2224 | + jQuery.event.remove( this, ".specialSubmit" ); |
| 2225 | + } |
| 2226 | + }; |
| 2227 | + |
| 2228 | +} |
| 2229 | + |
| 2230 | +// change delegation, happens here so we have bind. |
| 2231 | +if ( !jQuery.support.changeBubbles ) { |
| 2232 | + |
| 2233 | + var formElems = /textarea|input|select/i, |
| 2234 | + |
| 2235 | + changeFilters, |
| 2236 | + |
| 2237 | + getVal = function( elem ) { |
| 2238 | + var type = elem.type, val = elem.value; |
| 2239 | + |
| 2240 | + if ( type === "radio" || type === "checkbox" ) { |
| 2241 | + val = elem.checked; |
| 2242 | + |
| 2243 | + } else if ( type === "select-multiple" ) { |
| 2244 | + val = elem.selectedIndex > -1 ? |
| 2245 | + jQuery.map( elem.options, function( elem ) { |
| 2246 | + return elem.selected; |
| 2247 | + }).join("-") : |
| 2248 | + ""; |
| 2249 | + |
| 2250 | + } else if ( elem.nodeName.toLowerCase() === "select" ) { |
| 2251 | + val = elem.selectedIndex; |
| 2252 | + } |
| 2253 | + |
| 2254 | + return val; |
| 2255 | + }, |
| 2256 | + |
| 2257 | + testChange = function testChange( e ) { |
| 2258 | + var elem = e.target, data, val; |
| 2259 | + |
| 2260 | + if ( !formElems.test( elem.nodeName ) || elem.readOnly ) { |
| 2261 | + return; |
| 2262 | + } |
| 2263 | + |
| 2264 | + data = jQuery.data( elem, "_change_data" ); |
| 2265 | + val = getVal(elem); |
| 2266 | + |
| 2267 | + // the current data will be also retrieved by beforeactivate |
| 2268 | + if ( e.type !== "focusout" || elem.type !== "radio" ) { |
| 2269 | + jQuery.data( elem, "_change_data", val ); |
| 2270 | + } |
| 2271 | + |
| 2272 | + if ( data === undefined || val === data ) { |
| 2273 | + return; |
| 2274 | + } |
| 2275 | + |
| 2276 | + if ( data != null || val ) { |
| 2277 | + e.type = "change"; |
| 2278 | + return jQuery.event.trigger( e, arguments[1], elem ); |
| 2279 | + } |
| 2280 | + }; |
| 2281 | + |
| 2282 | + jQuery.event.special.change = { |
| 2283 | + filters: { |
| 2284 | + focusout: testChange, |
| 2285 | + |
| 2286 | + click: function( e ) { |
| 2287 | + var elem = e.target, type = elem.type; |
| 2288 | + |
| 2289 | + if ( type === "radio" || type === "checkbox" || elem.nodeName.toLowerCase() === "select" ) { |
| 2290 | + return testChange.call( this, e ); |
| 2291 | + } |
| 2292 | + }, |
| 2293 | + |
| 2294 | + // Change has to be called before submit |
| 2295 | + // Keydown will be called before keypress, which is used in submit-event delegation |
| 2296 | + keydown: function( e ) { |
| 2297 | + var elem = e.target, type = elem.type; |
| 2298 | + |
| 2299 | + if ( (e.keyCode === 13 && elem.nodeName.toLowerCase() !== "textarea") || |
| 2300 | + (e.keyCode === 32 && (type === "checkbox" || type === "radio")) || |
| 2301 | + type === "select-multiple" ) { |
| 2302 | + return testChange.call( this, e ); |
| 2303 | + } |
| 2304 | + }, |
| 2305 | + |
| 2306 | + // Beforeactivate happens also before the previous element is blurred |
| 2307 | + // with this event you can't trigger a change event, but you can store |
| 2308 | + // information/focus[in] is not needed anymore |
| 2309 | + beforeactivate: function( e ) { |
| 2310 | + var elem = e.target; |
| 2311 | + jQuery.data( elem, "_change_data", getVal(elem) ); |
| 2312 | + } |
| 2313 | + }, |
| 2314 | + |
| 2315 | + setup: function( data, namespaces ) { |
| 2316 | + if ( this.type === "file" ) { |
| 2317 | + return false; |
| 2318 | + } |
| 2319 | + |
| 2320 | + for ( var type in changeFilters ) { |
| 2321 | + jQuery.event.add( this, type + ".specialChange", changeFilters[type] ); |
| 2322 | + } |
| 2323 | + |
| 2324 | + return formElems.test( this.nodeName ); |
| 2325 | + }, |
| 2326 | + |
| 2327 | + teardown: function( namespaces ) { |
| 2328 | + jQuery.event.remove( this, ".specialChange" ); |
| 2329 | + |
| 2330 | + return formElems.test( this.nodeName ); |
| 2331 | + } |
| 2332 | + }; |
| 2333 | + |
| 2334 | + changeFilters = jQuery.event.special.change.filters; |
| 2335 | +} |
| 2336 | + |
| 2337 | +function trigger( type, elem, args ) { |
| 2338 | + args[0].type = type; |
| 2339 | + return jQuery.event.handle.apply( elem, args ); |
| 2340 | +} |
| 2341 | + |
| 2342 | +// Create "bubbling" focus and blur events |
| 2343 | +if ( document.addEventListener ) { |
| 2344 | + jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) { |
| 2345 | + jQuery.event.special[ fix ] = { |
| 2346 | + setup: function() { |
| 2347 | + this.addEventListener( orig, handler, true ); |
| 2348 | + }, |
| 2349 | + teardown: function() { |
| 2350 | + this.removeEventListener( orig, handler, true ); |
| 2351 | + } |
| 2352 | + }; |
| 2353 | + |
| 2354 | + function handler( e ) { |
| 2355 | + e = jQuery.event.fix( e ); |
| 2356 | + e.type = fix; |
| 2357 | + return jQuery.event.handle.call( this, e ); |
| 2358 | + } |
| 2359 | + }); |
| 2360 | +} |
| 2361 | + |
| 2362 | +jQuery.each(["bind", "one"], function( i, name ) { |
| 2363 | + jQuery.fn[ name ] = function( type, data, fn ) { |
| 2364 | + // Handle object literals |
| 2365 | + if ( typeof type === "object" ) { |
| 2366 | + for ( var key in type ) { |
| 2367 | + this[ name ](key, data, type[key], fn); |
| 2368 | + } |
| 2369 | + return this; |
| 2370 | + } |
| 2371 | + |
| 2372 | + if ( jQuery.isFunction( data ) ) { |
| 2373 | + fn = data; |
| 2374 | + data = undefined; |
| 2375 | + } |
| 2376 | + |
| 2377 | + var handler = name === "one" ? jQuery.proxy( fn, function( event ) { |
| 2378 | + jQuery( this ).unbind( event, handler ); |
| 2379 | + return fn.apply( this, arguments ); |
| 2380 | + }) : fn; |
| 2381 | + |
| 2382 | + if ( type === "unload" && name !== "one" ) { |
| 2383 | + this.one( type, data, fn ); |
| 2384 | + |
| 2385 | + } else { |
| 2386 | + for ( var i = 0, l = this.length; i < l; i++ ) { |
| 2387 | + jQuery.event.add( this[i], type, handler, data ); |
| 2388 | + } |
| 2389 | + } |
| 2390 | + |
| 2391 | + return this; |
| 2392 | + }; |
| 2393 | +}); |
| 2394 | + |
| 2395 | +jQuery.fn.extend({ |
| 2396 | + unbind: function( type, fn ) { |
| 2397 | + // Handle object literals |
| 2398 | + if ( typeof type === "object" && !type.preventDefault ) { |
| 2399 | + for ( var key in type ) { |
| 2400 | + this.unbind(key, type[key]); |
| 2401 | + } |
| 2402 | + |
| 2403 | + } else { |
| 2404 | + for ( var i = 0, l = this.length; i < l; i++ ) { |
| 2405 | + jQuery.event.remove( this[i], type, fn ); |
| 2406 | + } |
| 2407 | + } |
| 2408 | + |
| 2409 | + return this; |
| 2410 | + }, |
| 2411 | + |
| 2412 | + delegate: function( selector, types, data, fn ) { |
| 2413 | + return this.live( types, data, fn, selector ); |
| 2414 | + }, |
| 2415 | + |
| 2416 | + undelegate: function( selector, types, fn ) { |
| 2417 | + if ( arguments.length === 0 ) { |
| 2418 | + return this.unbind( "live" ); |
| 2419 | + |
| 2420 | + } else { |
| 2421 | + return this.die( types, null, fn, selector ); |
| 2422 | + } |
| 2423 | + }, |
| 2424 | + |
| 2425 | + trigger: function( type, data ) { |
| 2426 | + return this.each(function() { |
| 2427 | + jQuery.event.trigger( type, data, this ); |
| 2428 | + }); |
| 2429 | + }, |
| 2430 | + |
| 2431 | + triggerHandler: function( type, data ) { |
| 2432 | + if ( this[0] ) { |
| 2433 | + var event = jQuery.Event( type ); |
| 2434 | + event.preventDefault(); |
| 2435 | + event.stopPropagation(); |
| 2436 | + jQuery.event.trigger( event, data, this[0] ); |
| 2437 | + return event.result; |
| 2438 | + } |
| 2439 | + }, |
| 2440 | + |
| 2441 | + toggle: function( fn ) { |
| 2442 | + // Save reference to arguments for access in closure |
| 2443 | + var args = arguments, i = 1; |
| 2444 | + |
| 2445 | + // link all the functions, so any of them can unbind this click handler |
| 2446 | + while ( i < args.length ) { |
| 2447 | + jQuery.proxy( fn, args[ i++ ] ); |
| 2448 | + } |
| 2449 | + |
| 2450 | + return this.click( jQuery.proxy( fn, function( event ) { |
| 2451 | + // Figure out which function to execute |
| 2452 | + var lastToggle = ( jQuery.data( this, "lastToggle" + fn.guid ) || 0 ) % i; |
| 2453 | + jQuery.data( this, "lastToggle" + fn.guid, lastToggle + 1 ); |
| 2454 | + |
| 2455 | + // Make sure that clicks stop |
| 2456 | + event.preventDefault(); |
| 2457 | + |
| 2458 | + // and execute the function |
| 2459 | + return args[ lastToggle ].apply( this, arguments ) || false; |
| 2460 | + })); |
| 2461 | + }, |
| 2462 | + |
| 2463 | + hover: function( fnOver, fnOut ) { |
| 2464 | + return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver ); |
| 2465 | + } |
| 2466 | +}); |
| 2467 | + |
| 2468 | +var liveMap = { |
| 2469 | + focus: "focusin", |
| 2470 | + blur: "focusout", |
| 2471 | + mouseenter: "mouseover", |
| 2472 | + mouseleave: "mouseout" |
| 2473 | +}; |
| 2474 | + |
| 2475 | +jQuery.each(["live", "die"], function( i, name ) { |
| 2476 | + jQuery.fn[ name ] = function( types, data, fn, origSelector /* Internal Use Only */ ) { |
| 2477 | + var type, i = 0, match, namespaces, preType, |
| 2478 | + selector = origSelector || this.selector, |
| 2479 | + context = origSelector ? this : jQuery( this.context ); |
| 2480 | + |
| 2481 | + if ( jQuery.isFunction( data ) ) { |
| 2482 | + fn = data; |
| 2483 | + data = undefined; |
| 2484 | + } |
| 2485 | + |
| 2486 | + types = (types || "").split(" "); |
| 2487 | + |
| 2488 | + while ( (type = types[ i++ ]) != null ) { |
| 2489 | + match = rnamespaces.exec( type ); |
| 2490 | + namespaces = ""; |
| 2491 | + |
| 2492 | + if ( match ) { |
| 2493 | + namespaces = match[0]; |
| 2494 | + type = type.replace( rnamespaces, "" ); |
| 2495 | + } |
| 2496 | + |
| 2497 | + if ( type === "hover" ) { |
| 2498 | + types.push( "mouseenter" + namespaces, "mouseleave" + namespaces ); |
| 2499 | + continue; |
| 2500 | + } |
| 2501 | + |
| 2502 | + preType = type; |
| 2503 | + |
| 2504 | + if ( type === "focus" || type === "blur" ) { |
| 2505 | + types.push( liveMap[ type ] + namespaces ); |
| 2506 | + type = type + namespaces; |
| 2507 | + |
| 2508 | + } else { |
| 2509 | + type = (liveMap[ type ] || type) + namespaces; |
| 2510 | + } |
| 2511 | + |
| 2512 | + if ( name === "live" ) { |
| 2513 | + // bind live handler |
| 2514 | + context.each(function(){ |
| 2515 | + jQuery.event.add( this, liveConvert( type, selector ), |
| 2516 | + { data: data, selector: selector, handler: fn, origType: type, origHandler: fn, preType: preType } ); |
| 2517 | + }); |
| 2518 | + |
| 2519 | + } else { |
| 2520 | + // unbind live handler |
| 2521 | + context.unbind( liveConvert( type, selector ), fn ); |
| 2522 | + } |
| 2523 | + } |
| 2524 | + |
| 2525 | + return this; |
| 2526 | + } |
| 2527 | +}); |
| 2528 | + |
| 2529 | +function liveHandler( event ) { |
| 2530 | + var stop, elems = [], selectors = [], args = arguments, |
| 2531 | + related, match, handleObj, elem, j, i, l, data, |
| 2532 | + events = jQuery.data( this, "events" ); |
| 2533 | + |
| 2534 | + // Make sure we avoid non-left-click bubbling in Firefox (#3861) |
| 2535 | + if ( event.liveFired === this || !events || !events.live || event.button && event.type === "click" ) { |
| 2536 | + return; |
| 2537 | + } |
| 2538 | + |
| 2539 | + event.liveFired = this; |
| 2540 | + |
| 2541 | + var live = events.live.slice(0); |
| 2542 | + |
| 2543 | + for ( j = 0; j < live.length; j++ ) { |
| 2544 | + handleObj = live[j]; |
| 2545 | + |
| 2546 | + if ( handleObj.origType.replace( rnamespaces, "" ) === event.type ) { |
| 2547 | + selectors.push( handleObj.selector ); |
| 2548 | + |
| 2549 | + } else { |
| 2550 | + live.splice( j--, 1 ); |
| 2551 | + } |
| 2552 | + } |
| 2553 | + |
| 2554 | + match = jQuery( event.target ).closest( selectors, event.currentTarget ); |
| 2555 | + |
| 2556 | + for ( i = 0, l = match.length; i < l; i++ ) { |
| 2557 | + for ( j = 0; j < live.length; j++ ) { |
| 2558 | + handleObj = live[j]; |
| 2559 | + |
| 2560 | + if ( match[i].selector === handleObj.selector ) { |
| 2561 | + elem = match[i].elem; |
| 2562 | + related = null; |
| 2563 | + |
| 2564 | + // Those two events require additional checking |
| 2565 | + if ( handleObj.preType === "mouseenter" || handleObj.preType === "mouseleave" ) { |
| 2566 | + related = jQuery( event.relatedTarget ).closest( handleObj.selector )[0]; |
| 2567 | + } |
| 2568 | + |
| 2569 | + if ( !related || related !== elem ) { |
| 2570 | + elems.push({ elem: elem, handleObj: handleObj }); |
| 2571 | + } |
| 2572 | + } |
| 2573 | + } |
| 2574 | + } |
| 2575 | + |
| 2576 | + for ( i = 0, l = elems.length; i < l; i++ ) { |
| 2577 | + match = elems[i]; |
| 2578 | + event.currentTarget = match.elem; |
| 2579 | + event.data = match.handleObj.data; |
| 2580 | + event.handleObj = match.handleObj; |
| 2581 | + |
| 2582 | + if ( match.handleObj.origHandler.apply( match.elem, args ) === false ) { |
| 2583 | + stop = false; |
| 2584 | + break; |
| 2585 | + } |
| 2586 | + } |
| 2587 | + |
| 2588 | + return stop; |
| 2589 | +} |
| 2590 | + |
| 2591 | +function liveConvert( type, selector ) { |
| 2592 | + return "live." + (type && type !== "*" ? type + "." : "") + selector.replace(/\./g, "`").replace(/ /g, "&"); |
| 2593 | +} |
| 2594 | + |
| 2595 | +jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " + |
| 2596 | + "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " + |
| 2597 | + "change select submit keydown keypress keyup error").split(" "), function( i, name ) { |
| 2598 | + |
| 2599 | + // Handle event binding |
| 2600 | + jQuery.fn[ name ] = function( fn ) { |
| 2601 | + return fn ? this.bind( name, fn ) : this.trigger( name ); |
| 2602 | + }; |
| 2603 | + |
| 2604 | + if ( jQuery.attrFn ) { |
| 2605 | + jQuery.attrFn[ name ] = true; |
| 2606 | + } |
| 2607 | +}); |
| 2608 | + |
| 2609 | +// Prevent memory leaks in IE |
| 2610 | +// Window isn't included so as not to unbind existing unload events |
| 2611 | +// More info: |
| 2612 | +// - http://isaacschlueter.com/2006/10/msie-memory-leaks/ |
| 2613 | +if ( window.attachEvent && !window.addEventListener ) { |
| 2614 | + window.attachEvent("onunload", function() { |
| 2615 | + for ( var id in jQuery.cache ) { |
| 2616 | + if ( jQuery.cache[ id ].handle ) { |
| 2617 | + // Try/Catch is to handle iframes being unloaded, see #4280 |
| 2618 | + try { |
| 2619 | + jQuery.event.remove( jQuery.cache[ id ].handle.elem ); |
| 2620 | + } catch(e) {} |
| 2621 | + } |
| 2622 | + } |
| 2623 | + }); |
| 2624 | +} |
| 2625 | +/*! |
| 2626 | + * Sizzle CSS Selector Engine - v1.0 |
| 2627 | + * Copyright 2009, The Dojo Foundation |
| 2628 | + * Released under the MIT, BSD, and GPL Licenses. |
| 2629 | + * More information: http://sizzlejs.com/ |
| 2630 | + */ |
| 2631 | +(function(){ |
| 2632 | + |
| 2633 | +var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g, |
| 2634 | + done = 0, |
| 2635 | + toString = Object.prototype.toString, |
| 2636 | + hasDuplicate = false, |
| 2637 | + baseHasDuplicate = true; |
| 2638 | + |
| 2639 | +// Here we check if the JavaScript engine is using some sort of |
| 2640 | +// optimization where it does not always call our comparision |
| 2641 | +// function. If that is the case, discard the hasDuplicate value. |
| 2642 | +// Thus far that includes Google Chrome. |
| 2643 | +[0, 0].sort(function(){ |
| 2644 | + baseHasDuplicate = false; |
| 2645 | + return 0; |
| 2646 | +}); |
| 2647 | + |
| 2648 | +var Sizzle = function(selector, context, results, seed) { |
| 2649 | + results = results || []; |
| 2650 | + var origContext = context = context || document; |
| 2651 | + |
| 2652 | + if ( context.nodeType !== 1 && context.nodeType !== 9 ) { |
| 2653 | + return []; |
| 2654 | + } |
| 2655 | + |
| 2656 | + if ( !selector || typeof selector !== "string" ) { |
| 2657 | + return results; |
| 2658 | + } |
| 2659 | + |
| 2660 | + var parts = [], m, set, checkSet, extra, prune = true, contextXML = isXML(context), |
| 2661 | + soFar = selector; |
| 2662 | + |
| 2663 | + // Reset the position of the chunker regexp (start from head) |
| 2664 | + while ( (chunker.exec(""), m = chunker.exec(soFar)) !== null ) { |
| 2665 | + soFar = m[3]; |
| 2666 | + |
| 2667 | + parts.push( m[1] ); |
| 2668 | + |
| 2669 | + if ( m[2] ) { |
| 2670 | + extra = m[3]; |
| 2671 | + break; |
| 2672 | + } |
| 2673 | + } |
| 2674 | + |
| 2675 | + if ( parts.length > 1 && origPOS.exec( selector ) ) { |
| 2676 | + if ( parts.length === 2 && Expr.relative[ parts[0] ] ) { |
| 2677 | + set = posProcess( parts[0] + parts[1], context ); |
| 2678 | + } else { |
| 2679 | + set = Expr.relative[ parts[0] ] ? |
| 2680 | + [ context ] : |
| 2681 | + Sizzle( parts.shift(), context ); |
| 2682 | + |
| 2683 | + while ( parts.length ) { |
| 2684 | + selector = parts.shift(); |
| 2685 | + |
| 2686 | + if ( Expr.relative[ selector ] ) { |
| 2687 | + selector += parts.shift(); |
| 2688 | + } |
| 2689 | + |
| 2690 | + set = posProcess( selector, set ); |
| 2691 | + } |
| 2692 | + } |
| 2693 | + } else { |
| 2694 | + // Take a shortcut and set the context if the root selector is an ID |
| 2695 | + // (but not if it'll be faster if the inner selector is an ID) |
| 2696 | + if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML && |
| 2697 | + Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) { |
| 2698 | + var ret = Sizzle.find( parts.shift(), context, contextXML ); |
| 2699 | + context = ret.expr ? Sizzle.filter( ret.expr, ret.set )[0] : ret.set[0]; |
| 2700 | + } |
| 2701 | + |
| 2702 | + if ( context ) { |
| 2703 | + var ret = seed ? |
| 2704 | + { expr: parts.pop(), set: makeArray(seed) } : |
| 2705 | + Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML ); |
| 2706 | + set = ret.expr ? Sizzle.filter( ret.expr, ret.set ) : ret.set; |
| 2707 | + |
| 2708 | + if ( parts.length > 0 ) { |
| 2709 | + checkSet = makeArray(set); |
| 2710 | + } else { |
| 2711 | + prune = false; |
| 2712 | + } |
| 2713 | + |
| 2714 | + while ( parts.length ) { |
| 2715 | + var cur = parts.pop(), pop = cur; |
| 2716 | + |
| 2717 | + if ( !Expr.relative[ cur ] ) { |
| 2718 | + cur = ""; |
| 2719 | + } else { |
| 2720 | + pop = parts.pop(); |
| 2721 | + } |
| 2722 | + |
| 2723 | + if ( pop == null ) { |
| 2724 | + pop = context; |
| 2725 | + } |
| 2726 | + |
| 2727 | + Expr.relative[ cur ]( checkSet, pop, contextXML ); |
| 2728 | + } |
| 2729 | + } else { |
| 2730 | + checkSet = parts = []; |
| 2731 | + } |
| 2732 | + } |
| 2733 | + |
| 2734 | + if ( !checkSet ) { |
| 2735 | + checkSet = set; |
| 2736 | + } |
| 2737 | + |
| 2738 | + if ( !checkSet ) { |
| 2739 | + Sizzle.error( cur || selector ); |
| 2740 | + } |
| 2741 | + |
| 2742 | + if ( toString.call(checkSet) === "[object Array]" ) { |
| 2743 | + if ( !prune ) { |
| 2744 | + results.push.apply( results, checkSet ); |
| 2745 | + } else if ( context && context.nodeType === 1 ) { |
| 2746 | + for ( var i = 0; checkSet[i] != null; i++ ) { |
| 2747 | + if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) { |
| 2748 | + results.push( set[i] ); |
| 2749 | + } |
| 2750 | + } |
| 2751 | + } else { |
| 2752 | + for ( var i = 0; checkSet[i] != null; i++ ) { |
| 2753 | + if ( checkSet[i] && checkSet[i].nodeType === 1 ) { |
| 2754 | + results.push( set[i] ); |
| 2755 | + } |
| 2756 | + } |
| 2757 | + } |
| 2758 | + } else { |
| 2759 | + makeArray( checkSet, results ); |
| 2760 | + } |
| 2761 | + |
| 2762 | + if ( extra ) { |
| 2763 | + Sizzle( extra, origContext, results, seed ); |
| 2764 | + Sizzle.uniqueSort( results ); |
| 2765 | + } |
| 2766 | + |
| 2767 | + return results; |
| 2768 | +}; |
| 2769 | + |
| 2770 | +Sizzle.uniqueSort = function(results){ |
| 2771 | + if ( sortOrder ) { |
| 2772 | + hasDuplicate = baseHasDuplicate; |
| 2773 | + results.sort(sortOrder); |
| 2774 | + |
| 2775 | + if ( hasDuplicate ) { |
| 2776 | + for ( var i = 1; i < results.length; i++ ) { |
| 2777 | + if ( results[i] === results[i-1] ) { |
| 2778 | + results.splice(i--, 1); |
| 2779 | + } |
| 2780 | + } |
| 2781 | + } |
| 2782 | + } |
| 2783 | + |
| 2784 | + return results; |
| 2785 | +}; |
| 2786 | + |
| 2787 | +Sizzle.matches = function(expr, set){ |
| 2788 | + return Sizzle(expr, null, null, set); |
| 2789 | +}; |
| 2790 | + |
| 2791 | +Sizzle.find = function(expr, context, isXML){ |
| 2792 | + var set, match; |
| 2793 | + |
| 2794 | + if ( !expr ) { |
| 2795 | + return []; |
| 2796 | + } |
| 2797 | + |
| 2798 | + for ( var i = 0, l = Expr.order.length; i < l; i++ ) { |
| 2799 | + var type = Expr.order[i], match; |
| 2800 | + |
| 2801 | + if ( (match = Expr.leftMatch[ type ].exec( expr )) ) { |
| 2802 | + var left = match[1]; |
| 2803 | + match.splice(1,1); |
| 2804 | + |
| 2805 | + if ( left.substr( left.length - 1 ) !== "\\" ) { |
| 2806 | + match[1] = (match[1] || "").replace(/\\/g, ""); |
| 2807 | + set = Expr.find[ type ]( match, context, isXML ); |
| 2808 | + if ( set != null ) { |
| 2809 | + expr = expr.replace( Expr.match[ type ], "" ); |
| 2810 | + break; |
| 2811 | + } |
| 2812 | + } |
| 2813 | + } |
| 2814 | + } |
| 2815 | + |
| 2816 | + if ( !set ) { |
| 2817 | + set = context.getElementsByTagName("*"); |
| 2818 | + } |
| 2819 | + |
| 2820 | + return {set: set, expr: expr}; |
| 2821 | +}; |
| 2822 | + |
| 2823 | +Sizzle.filter = function(expr, set, inplace, not){ |
| 2824 | + var old = expr, result = [], curLoop = set, match, anyFound, |
| 2825 | + isXMLFilter = set && set[0] && isXML(set[0]); |
| 2826 | + |
| 2827 | + while ( expr && set.length ) { |
| 2828 | + for ( var type in Expr.filter ) { |
| 2829 | + if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) { |
| 2830 | + var filter = Expr.filter[ type ], found, item, left = match[1]; |
| 2831 | + anyFound = false; |
| 2832 | + |
| 2833 | + match.splice(1,1); |
| 2834 | + |
| 2835 | + if ( left.substr( left.length - 1 ) === "\\" ) { |
| 2836 | + continue; |
| 2837 | + } |
| 2838 | + |
| 2839 | + if ( curLoop === result ) { |
| 2840 | + result = []; |
| 2841 | + } |
| 2842 | + |
| 2843 | + if ( Expr.preFilter[ type ] ) { |
| 2844 | + match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter ); |
| 2845 | + |
| 2846 | + if ( !match ) { |
| 2847 | + anyFound = found = true; |
| 2848 | + } else if ( match === true ) { |
| 2849 | + continue; |
| 2850 | + } |
| 2851 | + } |
| 2852 | + |
| 2853 | + if ( match ) { |
| 2854 | + for ( var i = 0; (item = curLoop[i]) != null; i++ ) { |
| 2855 | + if ( item ) { |
| 2856 | + found = filter( item, match, i, curLoop ); |
| 2857 | + var pass = not ^ !!found; |
| 2858 | + |
| 2859 | + if ( inplace && found != null ) { |
| 2860 | + if ( pass ) { |
| 2861 | + anyFound = true; |
| 2862 | + } else { |
| 2863 | + curLoop[i] = false; |
| 2864 | + } |
| 2865 | + } else if ( pass ) { |
| 2866 | + result.push( item ); |
| 2867 | + anyFound = true; |
| 2868 | + } |
| 2869 | + } |
| 2870 | + } |
| 2871 | + } |
| 2872 | + |
| 2873 | + if ( found !== undefined ) { |
| 2874 | + if ( !inplace ) { |
| 2875 | + curLoop = result; |
| 2876 | + } |
| 2877 | + |
| 2878 | + expr = expr.replace( Expr.match[ type ], "" ); |
| 2879 | + |
| 2880 | + if ( !anyFound ) { |
| 2881 | + return []; |
| 2882 | + } |
| 2883 | + |
| 2884 | + break; |
| 2885 | + } |
| 2886 | + } |
| 2887 | + } |
| 2888 | + |
| 2889 | + // Improper expression |
| 2890 | + if ( expr === old ) { |
| 2891 | + if ( anyFound == null ) { |
| 2892 | + Sizzle.error( expr ); |
| 2893 | + } else { |
| 2894 | + break; |
| 2895 | + } |
| 2896 | + } |
| 2897 | + |
| 2898 | + old = expr; |
| 2899 | + } |
| 2900 | + |
| 2901 | + return curLoop; |
| 2902 | +}; |
| 2903 | + |
| 2904 | +Sizzle.error = function( msg ) { |
| 2905 | + throw "Syntax error, unrecognized expression: " + msg; |
| 2906 | +}; |
| 2907 | + |
| 2908 | +var Expr = Sizzle.selectors = { |
| 2909 | + order: [ "ID", "NAME", "TAG" ], |
| 2910 | + match: { |
| 2911 | + ID: /#((?:[\w\u00c0-\uFFFF-]|\\.)+)/, |
| 2912 | + CLASS: /\.((?:[\w\u00c0-\uFFFF-]|\\.)+)/, |
| 2913 | + NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF-]|\\.)+)['"]*\]/, |
| 2914 | + ATTR: /\[\s*((?:[\w\u00c0-\uFFFF-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/, |
| 2915 | + TAG: /^((?:[\w\u00c0-\uFFFF\*-]|\\.)+)/, |
| 2916 | + CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+-]*)\))?/, |
| 2917 | + POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^-]|$)/, |
| 2918 | + PSEUDO: /:((?:[\w\u00c0-\uFFFF-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/ |
| 2919 | + }, |
| 2920 | + leftMatch: {}, |
| 2921 | + attrMap: { |
| 2922 | + "class": "className", |
| 2923 | + "for": "htmlFor" |
| 2924 | + }, |
| 2925 | + attrHandle: { |
| 2926 | + href: function(elem){ |
| 2927 | + return elem.getAttribute("href"); |
| 2928 | + } |
| 2929 | + }, |
| 2930 | + relative: { |
| 2931 | + "+": function(checkSet, part){ |
| 2932 | + var isPartStr = typeof part === "string", |
| 2933 | + isTag = isPartStr && !/\W/.test(part), |
| 2934 | + isPartStrNotTag = isPartStr && !isTag; |
| 2935 | + |
| 2936 | + if ( isTag ) { |
| 2937 | + part = part.toLowerCase(); |
| 2938 | + } |
| 2939 | + |
| 2940 | + for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) { |
| 2941 | + if ( (elem = checkSet[i]) ) { |
| 2942 | + while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {} |
| 2943 | + |
| 2944 | + checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ? |
| 2945 | + elem || false : |
| 2946 | + elem === part; |
| 2947 | + } |
| 2948 | + } |
| 2949 | + |
| 2950 | + if ( isPartStrNotTag ) { |
| 2951 | + Sizzle.filter( part, checkSet, true ); |
| 2952 | + } |
| 2953 | + }, |
| 2954 | + ">": function(checkSet, part){ |
| 2955 | + var isPartStr = typeof part === "string"; |
| 2956 | + |
| 2957 | + if ( isPartStr && !/\W/.test(part) ) { |
| 2958 | + part = part.toLowerCase(); |
| 2959 | + |
| 2960 | + for ( var i = 0, l = checkSet.length; i < l; i++ ) { |
| 2961 | + var elem = checkSet[i]; |
| 2962 | + if ( elem ) { |
| 2963 | + var parent = elem.parentNode; |
| 2964 | + checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false; |
| 2965 | + } |
| 2966 | + } |
| 2967 | + } else { |
| 2968 | + for ( var i = 0, l = checkSet.length; i < l; i++ ) { |
| 2969 | + var elem = checkSet[i]; |
| 2970 | + if ( elem ) { |
| 2971 | + checkSet[i] = isPartStr ? |
| 2972 | + elem.parentNode : |
| 2973 | + elem.parentNode === part; |
| 2974 | + } |
| 2975 | + } |
| 2976 | + |
| 2977 | + if ( isPartStr ) { |
| 2978 | + Sizzle.filter( part, checkSet, true ); |
| 2979 | + } |
| 2980 | + } |
| 2981 | + }, |
| 2982 | + "": function(checkSet, part, isXML){ |
| 2983 | + var doneName = done++, checkFn = dirCheck; |
| 2984 | + |
| 2985 | + if ( typeof part === "string" && !/\W/.test(part) ) { |
| 2986 | + var nodeCheck = part = part.toLowerCase(); |
| 2987 | + checkFn = dirNodeCheck; |
| 2988 | + } |
| 2989 | + |
| 2990 | + checkFn("parentNode", part, doneName, checkSet, nodeCheck, isXML); |
| 2991 | + }, |
| 2992 | + "~": function(checkSet, part, isXML){ |
| 2993 | + var doneName = done++, checkFn = dirCheck; |
| 2994 | + |
| 2995 | + if ( typeof part === "string" && !/\W/.test(part) ) { |
| 2996 | + var nodeCheck = part = part.toLowerCase(); |
| 2997 | + checkFn = dirNodeCheck; |
| 2998 | + } |
| 2999 | + |
| 3000 | + checkFn("previousSibling", part, doneName, checkSet, nodeCheck, isXML); |
| 3001 | + } |
| 3002 | + }, |
| 3003 | + find: { |
| 3004 | + ID: function(match, context, isXML){ |
| 3005 | + if ( typeof context.getElementById !== "undefined" && !isXML ) { |
| 3006 | + var m = context.getElementById(match[1]); |
| 3007 | + return m ? [m] : []; |
| 3008 | + } |
| 3009 | + }, |
| 3010 | + NAME: function(match, context){ |
| 3011 | + if ( typeof context.getElementsByName !== "undefined" ) { |
| 3012 | + var ret = [], results = context.getElementsByName(match[1]); |
| 3013 | + |
| 3014 | + for ( var i = 0, l = results.length; i < l; i++ ) { |
| 3015 | + if ( results[i].getAttribute("name") === match[1] ) { |
| 3016 | + ret.push( results[i] ); |
| 3017 | + } |
| 3018 | + } |
| 3019 | + |
| 3020 | + return ret.length === 0 ? null : ret; |
| 3021 | + } |
| 3022 | + }, |
| 3023 | + TAG: function(match, context){ |
| 3024 | + return context.getElementsByTagName(match[1]); |
| 3025 | + } |
| 3026 | + }, |
| 3027 | + preFilter: { |
| 3028 | + CLASS: function(match, curLoop, inplace, result, not, isXML){ |
| 3029 | + match = " " + match[1].replace(/\\/g, "") + " "; |
| 3030 | + |
| 3031 | + if ( isXML ) { |
| 3032 | + return match; |
| 3033 | + } |
| 3034 | + |
| 3035 | + for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) { |
| 3036 | + if ( elem ) { |
| 3037 | + if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n]/g, " ").indexOf(match) >= 0) ) { |
| 3038 | + if ( !inplace ) { |
| 3039 | + result.push( elem ); |
| 3040 | + } |
| 3041 | + } else if ( inplace ) { |
| 3042 | + curLoop[i] = false; |
| 3043 | + } |
| 3044 | + } |
| 3045 | + } |
| 3046 | + |
| 3047 | + return false; |
| 3048 | + }, |
| 3049 | + ID: function(match){ |
| 3050 | + return match[1].replace(/\\/g, ""); |
| 3051 | + }, |
| 3052 | + TAG: function(match, curLoop){ |
| 3053 | + return match[1].toLowerCase(); |
| 3054 | + }, |
| 3055 | + CHILD: function(match){ |
| 3056 | + if ( match[1] === "nth" ) { |
| 3057 | + // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6' |
| 3058 | + var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec( |
| 3059 | + match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" || |
| 3060 | + !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]); |
| 3061 | + |
| 3062 | + // calculate the numbers (first)n+(last) including if they are negative |
| 3063 | + match[2] = (test[1] + (test[2] || 1)) - 0; |
| 3064 | + match[3] = test[3] - 0; |
| 3065 | + } |
| 3066 | + |
| 3067 | + // TODO: Move to normal caching system |
| 3068 | + match[0] = done++; |
| 3069 | + |
| 3070 | + return match; |
| 3071 | + }, |
| 3072 | + ATTR: function(match, curLoop, inplace, result, not, isXML){ |
| 3073 | + var name = match[1].replace(/\\/g, ""); |
| 3074 | + |
| 3075 | + if ( !isXML && Expr.attrMap[name] ) { |
| 3076 | + match[1] = Expr.attrMap[name]; |
| 3077 | + } |
| 3078 | + |
| 3079 | + if ( match[2] === "~=" ) { |
| 3080 | + match[4] = " " + match[4] + " "; |
| 3081 | + } |
| 3082 | + |
| 3083 | + return match; |
| 3084 | + }, |
| 3085 | + PSEUDO: function(match, curLoop, inplace, result, not){ |
| 3086 | + if ( match[1] === "not" ) { |
| 3087 | + // If we're dealing with a complex expression, or a simple one |
| 3088 | + if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) { |
| 3089 | + match[3] = Sizzle(match[3], null, null, curLoop); |
| 3090 | + } else { |
| 3091 | + var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not); |
| 3092 | + if ( !inplace ) { |
| 3093 | + result.push.apply( result, ret ); |
| 3094 | + } |
| 3095 | + return false; |
| 3096 | + } |
| 3097 | + } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) { |
| 3098 | + return true; |
| 3099 | + } |
| 3100 | + |
| 3101 | + return match; |
| 3102 | + }, |
| 3103 | + POS: function(match){ |
| 3104 | + match.unshift( true ); |
| 3105 | + return match; |
| 3106 | + } |
| 3107 | + }, |
| 3108 | + filters: { |
| 3109 | + enabled: function(elem){ |
| 3110 | + return elem.disabled === false && elem.type !== "hidden"; |
| 3111 | + }, |
| 3112 | + disabled: function(elem){ |
| 3113 | + return elem.disabled === true; |
| 3114 | + }, |
| 3115 | + checked: function(elem){ |
| 3116 | + return elem.checked === true; |
| 3117 | + }, |
| 3118 | + selected: function(elem){ |
| 3119 | + // Accessing this property makes selected-by-default |
| 3120 | + // options in Safari work properly |
| 3121 | + elem.parentNode.selectedIndex; |
| 3122 | + return elem.selected === true; |
| 3123 | + }, |
| 3124 | + parent: function(elem){ |
| 3125 | + return !!elem.firstChild; |
| 3126 | + }, |
| 3127 | + empty: function(elem){ |
| 3128 | + return !elem.firstChild; |
| 3129 | + }, |
| 3130 | + has: function(elem, i, match){ |
| 3131 | + return !!Sizzle( match[3], elem ).length; |
| 3132 | + }, |
| 3133 | + header: function(elem){ |
| 3134 | + return /h\d/i.test( elem.nodeName ); |
| 3135 | + }, |
| 3136 | + text: function(elem){ |
| 3137 | + return "text" === elem.type; |
| 3138 | + }, |
| 3139 | + radio: function(elem){ |
| 3140 | + return "radio" === elem.type; |
| 3141 | + }, |
| 3142 | + checkbox: function(elem){ |
| 3143 | + return "checkbox" === elem.type; |
| 3144 | + }, |
| 3145 | + file: function(elem){ |
| 3146 | + return "file" === elem.type; |
| 3147 | + }, |
| 3148 | + password: function(elem){ |
| 3149 | + return "password" === elem.type; |
| 3150 | + }, |
| 3151 | + submit: function(elem){ |
| 3152 | + return "submit" === elem.type; |
| 3153 | + }, |
| 3154 | + image: function(elem){ |
| 3155 | + return "image" === elem.type; |
| 3156 | + }, |
| 3157 | + reset: function(elem){ |
| 3158 | + return "reset" === elem.type; |
| 3159 | + }, |
| 3160 | + button: function(elem){ |
| 3161 | + return "button" === elem.type || elem.nodeName.toLowerCase() === "button"; |
| 3162 | + }, |
| 3163 | + input: function(elem){ |
| 3164 | + return /input|select|textarea|button/i.test(elem.nodeName); |
| 3165 | + } |
| 3166 | + }, |
| 3167 | + setFilters: { |
| 3168 | + first: function(elem, i){ |
| 3169 | + return i === 0; |
| 3170 | + }, |
| 3171 | + last: function(elem, i, match, array){ |
| 3172 | + return i === array.length - 1; |
| 3173 | + }, |
| 3174 | + even: function(elem, i){ |
| 3175 | + return i % 2 === 0; |
| 3176 | + }, |
| 3177 | + odd: function(elem, i){ |
| 3178 | + return i % 2 === 1; |
| 3179 | + }, |
| 3180 | + lt: function(elem, i, match){ |
| 3181 | + return i < match[3] - 0; |
| 3182 | + }, |
| 3183 | + gt: function(elem, i, match){ |
| 3184 | + return i > match[3] - 0; |
| 3185 | + }, |
| 3186 | + nth: function(elem, i, match){ |
| 3187 | + return match[3] - 0 === i; |
| 3188 | + }, |
| 3189 | + eq: function(elem, i, match){ |
| 3190 | + return match[3] - 0 === i; |
| 3191 | + } |
| 3192 | + }, |
| 3193 | + filter: { |
| 3194 | + PSEUDO: function(elem, match, i, array){ |
| 3195 | + var name = match[1], filter = Expr.filters[ name ]; |
| 3196 | + |
| 3197 | + if ( filter ) { |
| 3198 | + return filter( elem, i, match, array ); |
| 3199 | + } else if ( name === "contains" ) { |
| 3200 | + return (elem.textContent || elem.innerText || getText([ elem ]) || "").indexOf(match[3]) >= 0; |
| 3201 | + } else if ( name === "not" ) { |
| 3202 | + var not = match[3]; |
| 3203 | + |
| 3204 | + for ( var i = 0, l = not.length; i < l; i++ ) { |
| 3205 | + if ( not[i] === elem ) { |
| 3206 | + return false; |
| 3207 | + } |
| 3208 | + } |
| 3209 | + |
| 3210 | + return true; |
| 3211 | + } else { |
| 3212 | + Sizzle.error( "Syntax error, unrecognized expression: " + name ); |
| 3213 | + } |
| 3214 | + }, |
| 3215 | + CHILD: function(elem, match){ |
| 3216 | + var type = match[1], node = elem; |
| 3217 | + switch (type) { |
| 3218 | + case 'only': |
| 3219 | + case 'first': |
| 3220 | + while ( (node = node.previousSibling) ) { |
| 3221 | + if ( node.nodeType === 1 ) { |
| 3222 | + return false; |
| 3223 | + } |
| 3224 | + } |
| 3225 | + if ( type === "first" ) { |
| 3226 | + return true; |
| 3227 | + } |
| 3228 | + node = elem; |
| 3229 | + case 'last': |
| 3230 | + while ( (node = node.nextSibling) ) { |
| 3231 | + if ( node.nodeType === 1 ) { |
| 3232 | + return false; |
| 3233 | + } |
| 3234 | + } |
| 3235 | + return true; |
| 3236 | + case 'nth': |
| 3237 | + var first = match[2], last = match[3]; |
| 3238 | + |
| 3239 | + if ( first === 1 && last === 0 ) { |
| 3240 | + return true; |
| 3241 | + } |
| 3242 | + |
| 3243 | + var doneName = match[0], |
| 3244 | + parent = elem.parentNode; |
| 3245 | + |
| 3246 | + if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) { |
| 3247 | + var count = 0; |
| 3248 | + for ( node = parent.firstChild; node; node = node.nextSibling ) { |
| 3249 | + if ( node.nodeType === 1 ) { |
| 3250 | + node.nodeIndex = ++count; |
| 3251 | + } |
| 3252 | + } |
| 3253 | + parent.sizcache = doneName; |
| 3254 | + } |
| 3255 | + |
| 3256 | + var diff = elem.nodeIndex - last; |
| 3257 | + if ( first === 0 ) { |
| 3258 | + return diff === 0; |
| 3259 | + } else { |
| 3260 | + return ( diff % first === 0 && diff / first >= 0 ); |
| 3261 | + } |
| 3262 | + } |
| 3263 | + }, |
| 3264 | + ID: function(elem, match){ |
| 3265 | + return elem.nodeType === 1 && elem.getAttribute("id") === match; |
| 3266 | + }, |
| 3267 | + TAG: function(elem, match){ |
| 3268 | + return (match === "*" && elem.nodeType === 1) || elem.nodeName.toLowerCase() === match; |
| 3269 | + }, |
| 3270 | + CLASS: function(elem, match){ |
| 3271 | + return (" " + (elem.className || elem.getAttribute("class")) + " ") |
| 3272 | + .indexOf( match ) > -1; |
| 3273 | + }, |
| 3274 | + ATTR: function(elem, match){ |
| 3275 | + var name = match[1], |
| 3276 | + result = Expr.attrHandle[ name ] ? |
| 3277 | + Expr.attrHandle[ name ]( elem ) : |
| 3278 | + elem[ name ] != null ? |
| 3279 | + elem[ name ] : |
| 3280 | + elem.getAttribute( name ), |
| 3281 | + value = result + "", |
| 3282 | + type = match[2], |
| 3283 | + check = match[4]; |
| 3284 | + |
| 3285 | + return result == null ? |
| 3286 | + type === "!=" : |
| 3287 | + type === "=" ? |
| 3288 | + value === check : |
| 3289 | + type === "*=" ? |
| 3290 | + value.indexOf(check) >= 0 : |
| 3291 | + type === "~=" ? |
| 3292 | + (" " + value + " ").indexOf(check) >= 0 : |
| 3293 | + !check ? |
| 3294 | + value && result !== false : |
| 3295 | + type === "!=" ? |
| 3296 | + value !== check : |
| 3297 | + type === "^=" ? |
| 3298 | + value.indexOf(check) === 0 : |
| 3299 | + type === "$=" ? |
| 3300 | + value.substr(value.length - check.length) === check : |
| 3301 | + type === "|=" ? |
| 3302 | + value === check || value.substr(0, check.length + 1) === check + "-" : |
| 3303 | + false; |
| 3304 | + }, |
| 3305 | + POS: function(elem, match, i, array){ |
| 3306 | + var name = match[2], filter = Expr.setFilters[ name ]; |
| 3307 | + |
| 3308 | + if ( filter ) { |
| 3309 | + return filter( elem, i, match, array ); |
| 3310 | + } |
| 3311 | + } |
| 3312 | + } |
| 3313 | +}; |
| 3314 | + |
| 3315 | +var origPOS = Expr.match.POS; |
| 3316 | + |
| 3317 | +for ( var type in Expr.match ) { |
| 3318 | + Expr.match[ type ] = new RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source ); |
| 3319 | + Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, function(all, num){ |
| 3320 | + return "\\" + (num - 0 + 1); |
| 3321 | + })); |
| 3322 | +} |
| 3323 | + |
| 3324 | +var makeArray = function(array, results) { |
| 3325 | + array = Array.prototype.slice.call( array, 0 ); |
| 3326 | + |
| 3327 | + if ( results ) { |
| 3328 | + results.push.apply( results, array ); |
| 3329 | + return results; |
| 3330 | + } |
| 3331 | + |
| 3332 | + return array; |
| 3333 | +}; |
| 3334 | + |
| 3335 | +// Perform a simple check to determine if the browser is capable of |
| 3336 | +// converting a NodeList to an array using builtin methods. |
| 3337 | +// Also verifies that the returned array holds DOM nodes |
| 3338 | +// (which is not the case in the Blackberry browser) |
| 3339 | +try { |
| 3340 | + Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType; |
| 3341 | + |
| 3342 | +// Provide a fallback method if it does not work |
| 3343 | +} catch(e){ |
| 3344 | + makeArray = function(array, results) { |
| 3345 | + var ret = results || []; |
| 3346 | + |
| 3347 | + if ( toString.call(array) === "[object Array]" ) { |
| 3348 | + Array.prototype.push.apply( ret, array ); |
| 3349 | + } else { |
| 3350 | + if ( typeof array.length === "number" ) { |
| 3351 | + for ( var i = 0, l = array.length; i < l; i++ ) { |
| 3352 | + ret.push( array[i] ); |
| 3353 | + } |
| 3354 | + } else { |
| 3355 | + for ( var i = 0; array[i]; i++ ) { |
| 3356 | + ret.push( array[i] ); |
| 3357 | + } |
| 3358 | + } |
| 3359 | + } |
| 3360 | + |
| 3361 | + return ret; |
| 3362 | + }; |
| 3363 | +} |
| 3364 | + |
| 3365 | +var sortOrder; |
| 3366 | + |
| 3367 | +if ( document.documentElement.compareDocumentPosition ) { |
| 3368 | + sortOrder = function( a, b ) { |
| 3369 | + if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) { |
| 3370 | + if ( a == b ) { |
| 3371 | + hasDuplicate = true; |
| 3372 | + } |
| 3373 | + return a.compareDocumentPosition ? -1 : 1; |
| 3374 | + } |
| 3375 | + |
| 3376 | + var ret = a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1; |
| 3377 | + if ( ret === 0 ) { |
| 3378 | + hasDuplicate = true; |
| 3379 | + } |
| 3380 | + return ret; |
| 3381 | + }; |
| 3382 | +} else if ( "sourceIndex" in document.documentElement ) { |
| 3383 | + sortOrder = function( a, b ) { |
| 3384 | + if ( !a.sourceIndex || !b.sourceIndex ) { |
| 3385 | + if ( a == b ) { |
| 3386 | + hasDuplicate = true; |
| 3387 | + } |
| 3388 | + return a.sourceIndex ? -1 : 1; |
| 3389 | + } |
| 3390 | + |
| 3391 | + var ret = a.sourceIndex - b.sourceIndex; |
| 3392 | + if ( ret === 0 ) { |
| 3393 | + hasDuplicate = true; |
| 3394 | + } |
| 3395 | + return ret; |
| 3396 | + }; |
| 3397 | +} else if ( document.createRange ) { |
| 3398 | + sortOrder = function( a, b ) { |
| 3399 | + if ( !a.ownerDocument || !b.ownerDocument ) { |
| 3400 | + if ( a == b ) { |
| 3401 | + hasDuplicate = true; |
| 3402 | + } |
| 3403 | + return a.ownerDocument ? -1 : 1; |
| 3404 | + } |
| 3405 | + |
| 3406 | + var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange(); |
| 3407 | + aRange.setStart(a, 0); |
| 3408 | + aRange.setEnd(a, 0); |
| 3409 | + bRange.setStart(b, 0); |
| 3410 | + bRange.setEnd(b, 0); |
| 3411 | + var ret = aRange.compareBoundaryPoints(Range.START_TO_END, bRange); |
| 3412 | + if ( ret === 0 ) { |
| 3413 | + hasDuplicate = true; |
| 3414 | + } |
| 3415 | + return ret; |
| 3416 | + }; |
| 3417 | +} |
| 3418 | + |
| 3419 | +// Utility function for retreiving the text value of an array of DOM nodes |
| 3420 | +function getText( elems ) { |
| 3421 | + var ret = "", elem; |
| 3422 | + |
| 3423 | + for ( var i = 0; elems[i]; i++ ) { |
| 3424 | + elem = elems[i]; |
| 3425 | + |
| 3426 | + // Get the text from text nodes and CDATA nodes |
| 3427 | + if ( elem.nodeType === 3 || elem.nodeType === 4 ) { |
| 3428 | + ret += elem.nodeValue; |
| 3429 | + |
| 3430 | + // Traverse everything else, except comment nodes |
| 3431 | + } else if ( elem.nodeType !== 8 ) { |
| 3432 | + ret += getText( elem.childNodes ); |
| 3433 | + } |
| 3434 | + } |
| 3435 | + |
| 3436 | + return ret; |
| 3437 | +} |
| 3438 | + |
| 3439 | +// Check to see if the browser returns elements by name when |
| 3440 | +// querying by getElementById (and provide a workaround) |
| 3441 | +(function(){ |
| 3442 | + // We're going to inject a fake input element with a specified name |
| 3443 | + var form = document.createElement("div"), |
| 3444 | + id = "script" + (new Date).getTime(); |
| 3445 | + form.innerHTML = "<a name='" + id + "'/>"; |
| 3446 | + |
| 3447 | + // Inject it into the root element, check its status, and remove it quickly |
| 3448 | + var root = document.documentElement; |
| 3449 | + root.insertBefore( form, root.firstChild ); |
| 3450 | + |
| 3451 | + // The workaround has to do additional checks after a getElementById |
| 3452 | + // Which slows things down for other browsers (hence the branching) |
| 3453 | + if ( document.getElementById( id ) ) { |
| 3454 | + Expr.find.ID = function(match, context, isXML){ |
| 3455 | + if ( typeof context.getElementById !== "undefined" && !isXML ) { |
| 3456 | + var m = context.getElementById(match[1]); |
| 3457 | + return m ? m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : []; |
| 3458 | + } |
| 3459 | + }; |
| 3460 | + |
| 3461 | + Expr.filter.ID = function(elem, match){ |
| 3462 | + var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id"); |
| 3463 | + return elem.nodeType === 1 && node && node.nodeValue === match; |
| 3464 | + }; |
| 3465 | + } |
| 3466 | + |
| 3467 | + root.removeChild( form ); |
| 3468 | + root = form = null; // release memory in IE |
| 3469 | +})(); |
| 3470 | + |
| 3471 | +(function(){ |
| 3472 | + // Check to see if the browser returns only elements |
| 3473 | + // when doing getElementsByTagName("*") |
| 3474 | + |
| 3475 | + // Create a fake element |
| 3476 | + var div = document.createElement("div"); |
| 3477 | + div.appendChild( document.createComment("") ); |
| 3478 | + |
| 3479 | + // Make sure no comments are found |
| 3480 | + if ( div.getElementsByTagName("*").length > 0 ) { |
| 3481 | + Expr.find.TAG = function(match, context){ |
| 3482 | + var results = context.getElementsByTagName(match[1]); |
| 3483 | + |
| 3484 | + // Filter out possible comments |
| 3485 | + if ( match[1] === "*" ) { |
| 3486 | + var tmp = []; |
| 3487 | + |
| 3488 | + for ( var i = 0; results[i]; i++ ) { |
| 3489 | + if ( results[i].nodeType === 1 ) { |
| 3490 | + tmp.push( results[i] ); |
| 3491 | + } |
| 3492 | + } |
| 3493 | + |
| 3494 | + results = tmp; |
| 3495 | + } |
| 3496 | + |
| 3497 | + return results; |
| 3498 | + }; |
| 3499 | + } |
| 3500 | + |
| 3501 | + // Check to see if an attribute returns normalized href attributes |
| 3502 | + div.innerHTML = "<a href='#'></a>"; |
| 3503 | + if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" && |
| 3504 | + div.firstChild.getAttribute("href") !== "#" ) { |
| 3505 | + Expr.attrHandle.href = function(elem){ |
| 3506 | + return elem.getAttribute("href", 2); |
| 3507 | + }; |
| 3508 | + } |
| 3509 | + |
| 3510 | + div = null; // release memory in IE |
| 3511 | +})(); |
| 3512 | + |
| 3513 | +if ( document.querySelectorAll ) { |
| 3514 | + (function(){ |
| 3515 | + var oldSizzle = Sizzle, div = document.createElement("div"); |
| 3516 | + div.innerHTML = "<p class='TEST'></p>"; |
| 3517 | + |
| 3518 | + // Safari can't handle uppercase or unicode characters when |
| 3519 | + // in quirks mode. |
| 3520 | + if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) { |
| 3521 | + return; |
| 3522 | + } |
| 3523 | + |
| 3524 | + Sizzle = function(query, context, extra, seed){ |
| 3525 | + context = context || document; |
| 3526 | + |
| 3527 | + // Only use querySelectorAll on non-XML documents |
| 3528 | + // (ID selectors don't work in non-HTML documents) |
| 3529 | + if ( !seed && context.nodeType === 9 && !isXML(context) ) { |
| 3530 | + try { |
| 3531 | + return makeArray( context.querySelectorAll(query), extra ); |
| 3532 | + } catch(e){} |
| 3533 | + } |
| 3534 | + |
| 3535 | + return oldSizzle(query, context, extra, seed); |
| 3536 | + }; |
| 3537 | + |
| 3538 | + for ( var prop in oldSizzle ) { |
| 3539 | + Sizzle[ prop ] = oldSizzle[ prop ]; |
| 3540 | + } |
| 3541 | + |
| 3542 | + div = null; // release memory in IE |
| 3543 | + })(); |
| 3544 | +} |
| 3545 | + |
| 3546 | +(function(){ |
| 3547 | + var div = document.createElement("div"); |
| 3548 | + |
| 3549 | + div.innerHTML = "<div class='test e'></div><div class='test'></div>"; |
| 3550 | + |
| 3551 | + // Opera can't find a second classname (in 9.6) |
| 3552 | + // Also, make sure that getElementsByClassName actually exists |
| 3553 | + if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) { |
| 3554 | + return; |
| 3555 | + } |
| 3556 | + |
| 3557 | + // Safari caches class attributes, doesn't catch changes (in 3.2) |
| 3558 | + div.lastChild.className = "e"; |
| 3559 | + |
| 3560 | + if ( div.getElementsByClassName("e").length === 1 ) { |
| 3561 | + return; |
| 3562 | + } |
| 3563 | + |
| 3564 | + Expr.order.splice(1, 0, "CLASS"); |
| 3565 | + Expr.find.CLASS = function(match, context, isXML) { |
| 3566 | + if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) { |
| 3567 | + return context.getElementsByClassName(match[1]); |
| 3568 | + } |
| 3569 | + }; |
| 3570 | + |
| 3571 | + div = null; // release memory in IE |
| 3572 | +})(); |
| 3573 | + |
| 3574 | +function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { |
| 3575 | + for ( var i = 0, l = checkSet.length; i < l; i++ ) { |
| 3576 | + var elem = checkSet[i]; |
| 3577 | + if ( elem ) { |
| 3578 | + elem = elem[dir]; |
| 3579 | + var match = false; |
| 3580 | + |
| 3581 | + while ( elem ) { |
| 3582 | + if ( elem.sizcache === doneName ) { |
| 3583 | + match = checkSet[elem.sizset]; |
| 3584 | + break; |
| 3585 | + } |
| 3586 | + |
| 3587 | + if ( elem.nodeType === 1 && !isXML ){ |
| 3588 | + elem.sizcache = doneName; |
| 3589 | + elem.sizset = i; |
| 3590 | + } |
| 3591 | + |
| 3592 | + if ( elem.nodeName.toLowerCase() === cur ) { |
| 3593 | + match = elem; |
| 3594 | + break; |
| 3595 | + } |
| 3596 | + |
| 3597 | + elem = elem[dir]; |
| 3598 | + } |
| 3599 | + |
| 3600 | + checkSet[i] = match; |
| 3601 | + } |
| 3602 | + } |
| 3603 | +} |
| 3604 | + |
| 3605 | +function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { |
| 3606 | + for ( var i = 0, l = checkSet.length; i < l; i++ ) { |
| 3607 | + var elem = checkSet[i]; |
| 3608 | + if ( elem ) { |
| 3609 | + elem = elem[dir]; |
| 3610 | + var match = false; |
| 3611 | + |
| 3612 | + while ( elem ) { |
| 3613 | + if ( elem.sizcache === doneName ) { |
| 3614 | + match = checkSet[elem.sizset]; |
| 3615 | + break; |
| 3616 | + } |
| 3617 | + |
| 3618 | + if ( elem.nodeType === 1 ) { |
| 3619 | + if ( !isXML ) { |
| 3620 | + elem.sizcache = doneName; |
| 3621 | + elem.sizset = i; |
| 3622 | + } |
| 3623 | + if ( typeof cur !== "string" ) { |
| 3624 | + if ( elem === cur ) { |
| 3625 | + match = true; |
| 3626 | + break; |
| 3627 | + } |
| 3628 | + |
| 3629 | + } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) { |
| 3630 | + match = elem; |
| 3631 | + break; |
| 3632 | + } |
| 3633 | + } |
| 3634 | + |
| 3635 | + elem = elem[dir]; |
| 3636 | + } |
| 3637 | + |
| 3638 | + checkSet[i] = match; |
| 3639 | + } |
| 3640 | + } |
| 3641 | +} |
| 3642 | + |
| 3643 | +var contains = document.compareDocumentPosition ? function(a, b){ |
| 3644 | + return !!(a.compareDocumentPosition(b) & 16); |
| 3645 | +} : function(a, b){ |
| 3646 | + return a !== b && (a.contains ? a.contains(b) : true); |
| 3647 | +}; |
| 3648 | + |
| 3649 | +var isXML = function(elem){ |
| 3650 | + // documentElement is verified for cases where it doesn't yet exist |
| 3651 | + // (such as loading iframes in IE - #4833) |
| 3652 | + var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement; |
| 3653 | + return documentElement ? documentElement.nodeName !== "HTML" : false; |
| 3654 | +}; |
| 3655 | + |
| 3656 | +var posProcess = function(selector, context){ |
| 3657 | + var tmpSet = [], later = "", match, |
| 3658 | + root = context.nodeType ? [context] : context; |
| 3659 | + |
| 3660 | + // Position selectors must be done after the filter |
| 3661 | + // And so must :not(positional) so we move all PSEUDOs to the end |
| 3662 | + while ( (match = Expr.match.PSEUDO.exec( selector )) ) { |
| 3663 | + later += match[0]; |
| 3664 | + selector = selector.replace( Expr.match.PSEUDO, "" ); |
| 3665 | + } |
| 3666 | + |
| 3667 | + selector = Expr.relative[selector] ? selector + "*" : selector; |
| 3668 | + |
| 3669 | + for ( var i = 0, l = root.length; i < l; i++ ) { |
| 3670 | + Sizzle( selector, root[i], tmpSet ); |
| 3671 | + } |
| 3672 | + |
| 3673 | + return Sizzle.filter( later, tmpSet ); |
| 3674 | +}; |
| 3675 | + |
| 3676 | +// EXPOSE |
| 3677 | +jQuery.find = Sizzle; |
| 3678 | +jQuery.expr = Sizzle.selectors; |
| 3679 | +jQuery.expr[":"] = jQuery.expr.filters; |
| 3680 | +jQuery.unique = Sizzle.uniqueSort; |
| 3681 | +jQuery.text = getText; |
| 3682 | +jQuery.isXMLDoc = isXML; |
| 3683 | +jQuery.contains = contains; |
| 3684 | + |
| 3685 | +return; |
| 3686 | + |
| 3687 | +window.Sizzle = Sizzle; |
| 3688 | + |
| 3689 | +})(); |
| 3690 | +var runtil = /Until$/, |
| 3691 | + rparentsprev = /^(?:parents|prevUntil|prevAll)/, |
| 3692 | + // Note: This RegExp should be improved, or likely pulled from Sizzle |
| 3693 | + rmultiselector = /,/, |
| 3694 | + slice = Array.prototype.slice; |
| 3695 | + |
| 3696 | +// Implement the identical functionality for filter and not |
| 3697 | +var winnow = function( elements, qualifier, keep ) { |
| 3698 | + if ( jQuery.isFunction( qualifier ) ) { |
| 3699 | + return jQuery.grep(elements, function( elem, i ) { |
| 3700 | + return !!qualifier.call( elem, i, elem ) === keep; |
| 3701 | + }); |
| 3702 | + |
| 3703 | + } else if ( qualifier.nodeType ) { |
| 3704 | + return jQuery.grep(elements, function( elem, i ) { |
| 3705 | + return (elem === qualifier) === keep; |
| 3706 | + }); |
| 3707 | + |
| 3708 | + } else if ( typeof qualifier === "string" ) { |
| 3709 | + var filtered = jQuery.grep(elements, function( elem ) { |
| 3710 | + return elem.nodeType === 1; |
| 3711 | + }); |
| 3712 | + |
| 3713 | + if ( isSimple.test( qualifier ) ) { |
| 3714 | + return jQuery.filter(qualifier, filtered, !keep); |
| 3715 | + } else { |
| 3716 | + qualifier = jQuery.filter( qualifier, filtered ); |
| 3717 | + } |
| 3718 | + } |
| 3719 | + |
| 3720 | + return jQuery.grep(elements, function( elem, i ) { |
| 3721 | + return (jQuery.inArray( elem, qualifier ) >= 0) === keep; |
| 3722 | + }); |
| 3723 | +}; |
| 3724 | + |
| 3725 | +jQuery.fn.extend({ |
| 3726 | + find: function( selector ) { |
| 3727 | + var ret = this.pushStack( "", "find", selector ), length = 0; |
| 3728 | + |
| 3729 | + for ( var i = 0, l = this.length; i < l; i++ ) { |
| 3730 | + length = ret.length; |
| 3731 | + jQuery.find( selector, this[i], ret ); |
| 3732 | + |
| 3733 | + if ( i > 0 ) { |
| 3734 | + // Make sure that the results are unique |
| 3735 | + for ( var n = length; n < ret.length; n++ ) { |
| 3736 | + for ( var r = 0; r < length; r++ ) { |
| 3737 | + if ( ret[r] === ret[n] ) { |
| 3738 | + ret.splice(n--, 1); |
| 3739 | + break; |
| 3740 | + } |
| 3741 | + } |
| 3742 | + } |
| 3743 | + } |
| 3744 | + } |
| 3745 | + |
| 3746 | + return ret; |
| 3747 | + }, |
| 3748 | + |
| 3749 | + has: function( target ) { |
| 3750 | + var targets = jQuery( target ); |
| 3751 | + return this.filter(function() { |
| 3752 | + for ( var i = 0, l = targets.length; i < l; i++ ) { |
| 3753 | + if ( jQuery.contains( this, targets[i] ) ) { |
| 3754 | + return true; |
| 3755 | + } |
| 3756 | + } |
| 3757 | + }); |
| 3758 | + }, |
| 3759 | + |
| 3760 | + not: function( selector ) { |
| 3761 | + return this.pushStack( winnow(this, selector, false), "not", selector); |
| 3762 | + }, |
| 3763 | + |
| 3764 | + filter: function( selector ) { |
| 3765 | + return this.pushStack( winnow(this, selector, true), "filter", selector ); |
| 3766 | + }, |
| 3767 | + |
| 3768 | + is: function( selector ) { |
| 3769 | + return !!selector && jQuery.filter( selector, this ).length > 0; |
| 3770 | + }, |
| 3771 | + |
| 3772 | + closest: function( selectors, context ) { |
| 3773 | + if ( jQuery.isArray( selectors ) ) { |
| 3774 | + var ret = [], cur = this[0], match, matches = {}, selector; |
| 3775 | + |
| 3776 | + if ( cur && selectors.length ) { |
| 3777 | + for ( var i = 0, l = selectors.length; i < l; i++ ) { |
| 3778 | + selector = selectors[i]; |
| 3779 | + |
| 3780 | + if ( !matches[selector] ) { |
| 3781 | + matches[selector] = jQuery.expr.match.POS.test( selector ) ? |
| 3782 | + jQuery( selector, context || this.context ) : |
| 3783 | + selector; |
| 3784 | + } |
| 3785 | + } |
| 3786 | + |
| 3787 | + while ( cur && cur.ownerDocument && cur !== context ) { |
| 3788 | + for ( selector in matches ) { |
| 3789 | + match = matches[selector]; |
| 3790 | + |
| 3791 | + if ( match.jquery ? match.index(cur) > -1 : jQuery(cur).is(match) ) { |
| 3792 | + ret.push({ selector: selector, elem: cur }); |
| 3793 | + delete matches[selector]; |
| 3794 | + } |
| 3795 | + } |
| 3796 | + cur = cur.parentNode; |
| 3797 | + } |
| 3798 | + } |
| 3799 | + |
| 3800 | + return ret; |
| 3801 | + } |
| 3802 | + |
| 3803 | + var pos = jQuery.expr.match.POS.test( selectors ) ? |
| 3804 | + jQuery( selectors, context || this.context ) : null; |
| 3805 | + |
| 3806 | + return this.map(function( i, cur ) { |
| 3807 | + while ( cur && cur.ownerDocument && cur !== context ) { |
| 3808 | + if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selectors) ) { |
| 3809 | + return cur; |
| 3810 | + } |
| 3811 | + cur = cur.parentNode; |
| 3812 | + } |
| 3813 | + return null; |
| 3814 | + }); |
| 3815 | + }, |
| 3816 | + |
| 3817 | + // Determine the position of an element within |
| 3818 | + // the matched set of elements |
| 3819 | + index: function( elem ) { |
| 3820 | + if ( !elem || typeof elem === "string" ) { |
| 3821 | + return jQuery.inArray( this[0], |
| 3822 | + // If it receives a string, the selector is used |
| 3823 | + // If it receives nothing, the siblings are used |
| 3824 | + elem ? jQuery( elem ) : this.parent().children() ); |
| 3825 | + } |
| 3826 | + // Locate the position of the desired element |
| 3827 | + return jQuery.inArray( |
| 3828 | + // If it receives a jQuery object, the first element is used |
| 3829 | + elem.jquery ? elem[0] : elem, this ); |
| 3830 | + }, |
| 3831 | + |
| 3832 | + add: function( selector, context ) { |
| 3833 | + var set = typeof selector === "string" ? |
| 3834 | + jQuery( selector, context || this.context ) : |
| 3835 | + jQuery.makeArray( selector ), |
| 3836 | + all = jQuery.merge( this.get(), set ); |
| 3837 | + |
| 3838 | + return this.pushStack( isDisconnected( set[0] ) || isDisconnected( all[0] ) ? |
| 3839 | + all : |
| 3840 | + jQuery.unique( all ) ); |
| 3841 | + }, |
| 3842 | + |
| 3843 | + andSelf: function() { |
| 3844 | + return this.add( this.prevObject ); |
| 3845 | + } |
| 3846 | +}); |
| 3847 | + |
| 3848 | +// A painfully simple check to see if an element is disconnected |
| 3849 | +// from a document (should be improved, where feasible). |
| 3850 | +function isDisconnected( node ) { |
| 3851 | + return !node || !node.parentNode || node.parentNode.nodeType === 11; |
| 3852 | +} |
| 3853 | + |
| 3854 | +jQuery.each({ |
| 3855 | + parent: function( elem ) { |
| 3856 | + var parent = elem.parentNode; |
| 3857 | + return parent && parent.nodeType !== 11 ? parent : null; |
| 3858 | + }, |
| 3859 | + parents: function( elem ) { |
| 3860 | + return jQuery.dir( elem, "parentNode" ); |
| 3861 | + }, |
| 3862 | + parentsUntil: function( elem, i, until ) { |
| 3863 | + return jQuery.dir( elem, "parentNode", until ); |
| 3864 | + }, |
| 3865 | + next: function( elem ) { |
| 3866 | + return jQuery.nth( elem, 2, "nextSibling" ); |
| 3867 | + }, |
| 3868 | + prev: function( elem ) { |
| 3869 | + return jQuery.nth( elem, 2, "previousSibling" ); |
| 3870 | + }, |
| 3871 | + nextAll: function( elem ) { |
| 3872 | + return jQuery.dir( elem, "nextSibling" ); |
| 3873 | + }, |
| 3874 | + prevAll: function( elem ) { |
| 3875 | + return jQuery.dir( elem, "previousSibling" ); |
| 3876 | + }, |
| 3877 | + nextUntil: function( elem, i, until ) { |
| 3878 | + return jQuery.dir( elem, "nextSibling", until ); |
| 3879 | + }, |
| 3880 | + prevUntil: function( elem, i, until ) { |
| 3881 | + return jQuery.dir( elem, "previousSibling", until ); |
| 3882 | + }, |
| 3883 | + siblings: function( elem ) { |
| 3884 | + return jQuery.sibling( elem.parentNode.firstChild, elem ); |
| 3885 | + }, |
| 3886 | + children: function( elem ) { |
| 3887 | + return jQuery.sibling( elem.firstChild ); |
| 3888 | + }, |
| 3889 | + contents: function( elem ) { |
| 3890 | + return jQuery.nodeName( elem, "iframe" ) ? |
| 3891 | + elem.contentDocument || elem.contentWindow.document : |
| 3892 | + jQuery.makeArray( elem.childNodes ); |
| 3893 | + } |
| 3894 | +}, function( name, fn ) { |
| 3895 | + jQuery.fn[ name ] = function( until, selector ) { |
| 3896 | + var ret = jQuery.map( this, fn, until ); |
| 3897 | + |
| 3898 | + if ( !runtil.test( name ) ) { |
| 3899 | + selector = until; |
| 3900 | + } |
| 3901 | + |
| 3902 | + if ( selector && typeof selector === "string" ) { |
| 3903 | + ret = jQuery.filter( selector, ret ); |
| 3904 | + } |
| 3905 | + |
| 3906 | + ret = this.length > 1 ? jQuery.unique( ret ) : ret; |
| 3907 | + |
| 3908 | + if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( name ) ) { |
| 3909 | + ret = ret.reverse(); |
| 3910 | + } |
| 3911 | + |
| 3912 | + return this.pushStack( ret, name, slice.call(arguments).join(",") ); |
| 3913 | + }; |
| 3914 | +}); |
| 3915 | + |
| 3916 | +jQuery.extend({ |
| 3917 | + filter: function( expr, elems, not ) { |
| 3918 | + if ( not ) { |
| 3919 | + expr = ":not(" + expr + ")"; |
| 3920 | + } |
| 3921 | + |
| 3922 | + return jQuery.find.matches(expr, elems); |
| 3923 | + }, |
| 3924 | + |
| 3925 | + dir: function( elem, dir, until ) { |
| 3926 | + var matched = [], cur = elem[dir]; |
| 3927 | + while ( cur && cur.nodeType !== 9 && (until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until )) ) { |
| 3928 | + if ( cur.nodeType === 1 ) { |
| 3929 | + matched.push( cur ); |
| 3930 | + } |
| 3931 | + cur = cur[dir]; |
| 3932 | + } |
| 3933 | + return matched; |
| 3934 | + }, |
| 3935 | + |
| 3936 | + nth: function( cur, result, dir, elem ) { |
| 3937 | + result = result || 1; |
| 3938 | + var num = 0; |
| 3939 | + |
| 3940 | + for ( ; cur; cur = cur[dir] ) { |
| 3941 | + if ( cur.nodeType === 1 && ++num === result ) { |
| 3942 | + break; |
| 3943 | + } |
| 3944 | + } |
| 3945 | + |
| 3946 | + return cur; |
| 3947 | + }, |
| 3948 | + |
| 3949 | + sibling: function( n, elem ) { |
| 3950 | + var r = []; |
| 3951 | + |
| 3952 | + for ( ; n; n = n.nextSibling ) { |
| 3953 | + if ( n.nodeType === 1 && n !== elem ) { |
| 3954 | + r.push( n ); |
| 3955 | + } |
| 3956 | + } |
| 3957 | + |
| 3958 | + return r; |
| 3959 | + } |
| 3960 | +}); |
| 3961 | +var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g, |
| 3962 | + rleadingWhitespace = /^\s+/, |
| 3963 | + rxhtmlTag = /(<([\w:]+)[^>]*?)\/>/g, |
| 3964 | + rselfClosing = /^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i, |
| 3965 | + rtagName = /<([\w:]+)/, |
| 3966 | + rtbody = /<tbody/i, |
| 3967 | + rhtml = /<|&#?\w+;/, |
| 3968 | + rnocache = /<script|<object|<embed|<option|<style/i, |
| 3969 | + rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i, // checked="checked" or checked (html5) |
| 3970 | + fcloseTag = function( all, front, tag ) { |
| 3971 | + return rselfClosing.test( tag ) ? |
| 3972 | + all : |
| 3973 | + front + "></" + tag + ">"; |
| 3974 | + }, |
| 3975 | + wrapMap = { |
| 3976 | + option: [ 1, "<select multiple='multiple'>", "</select>" ], |
| 3977 | + legend: [ 1, "<fieldset>", "</fieldset>" ], |
| 3978 | + thead: [ 1, "<table>", "</table>" ], |
| 3979 | + tr: [ 2, "<table><tbody>", "</tbody></table>" ], |
| 3980 | + td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ], |
| 3981 | + col: [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ], |
| 3982 | + area: [ 1, "<map>", "</map>" ], |
| 3983 | + _default: [ 0, "", "" ] |
| 3984 | + }; |
| 3985 | + |
| 3986 | +wrapMap.optgroup = wrapMap.option; |
| 3987 | +wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; |
| 3988 | +wrapMap.th = wrapMap.td; |
| 3989 | + |
| 3990 | +// IE can't serialize <link> and <script> tags normally |
| 3991 | +if ( !jQuery.support.htmlSerialize ) { |
| 3992 | + wrapMap._default = [ 1, "div<div>", "</div>" ]; |
| 3993 | +} |
| 3994 | + |
| 3995 | +jQuery.fn.extend({ |
| 3996 | + text: function( text ) { |
| 3997 | + if ( jQuery.isFunction(text) ) { |
| 3998 | + return this.each(function(i) { |
| 3999 | + var self = jQuery(this); |
| 4000 | + self.text( text.call(this, i, self.text()) ); |
| 4001 | + }); |
| 4002 | + } |
| 4003 | + |
| 4004 | + if ( typeof text !== "object" && text !== undefined ) { |
| 4005 | + return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) ); |
| 4006 | + } |
| 4007 | + |
| 4008 | + return jQuery.text( this ); |
| 4009 | + }, |
| 4010 | + |
| 4011 | + wrapAll: function( html ) { |
| 4012 | + if ( jQuery.isFunction( html ) ) { |
| 4013 | + return this.each(function(i) { |
| 4014 | + jQuery(this).wrapAll( html.call(this, i) ); |
| 4015 | + }); |
| 4016 | + } |
| 4017 | + |
| 4018 | + if ( this[0] ) { |
| 4019 | + // The elements to wrap the target around |
| 4020 | + var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true); |
| 4021 | + |
| 4022 | + if ( this[0].parentNode ) { |
| 4023 | + wrap.insertBefore( this[0] ); |
| 4024 | + } |
| 4025 | + |
| 4026 | + wrap.map(function() { |
| 4027 | + var elem = this; |
| 4028 | + |
| 4029 | + while ( elem.firstChild && elem.firstChild.nodeType === 1 ) { |
| 4030 | + elem = elem.firstChild; |
| 4031 | + } |
| 4032 | + |
| 4033 | + return elem; |
| 4034 | + }).append(this); |
| 4035 | + } |
| 4036 | + |
| 4037 | + return this; |
| 4038 | + }, |
| 4039 | + |
| 4040 | + wrapInner: function( html ) { |
| 4041 | + if ( jQuery.isFunction( html ) ) { |
| 4042 | + return this.each(function(i) { |
| 4043 | + jQuery(this).wrapInner( html.call(this, i) ); |
| 4044 | + }); |
| 4045 | + } |
| 4046 | + |
| 4047 | + return this.each(function() { |
| 4048 | + var self = jQuery( this ), contents = self.contents(); |
| 4049 | + |
| 4050 | + if ( contents.length ) { |
| 4051 | + contents.wrapAll( html ); |
| 4052 | + |
| 4053 | + } else { |
| 4054 | + self.append( html ); |
| 4055 | + } |
| 4056 | + }); |
| 4057 | + }, |
| 4058 | + |
| 4059 | + wrap: function( html ) { |
| 4060 | + return this.each(function() { |
| 4061 | + jQuery( this ).wrapAll( html ); |
| 4062 | + }); |
| 4063 | + }, |
| 4064 | + |
| 4065 | + unwrap: function() { |
| 4066 | + return this.parent().each(function() { |
| 4067 | + if ( !jQuery.nodeName( this, "body" ) ) { |
| 4068 | + jQuery( this ).replaceWith( this.childNodes ); |
| 4069 | + } |
| 4070 | + }).end(); |
| 4071 | + }, |
| 4072 | + |
| 4073 | + append: function() { |
| 4074 | + return this.domManip(arguments, true, function( elem ) { |
| 4075 | + if ( this.nodeType === 1 ) { |
| 4076 | + this.appendChild( elem ); |
| 4077 | + } |
| 4078 | + }); |
| 4079 | + }, |
| 4080 | + |
| 4081 | + prepend: function() { |
| 4082 | + return this.domManip(arguments, true, function( elem ) { |
| 4083 | + if ( this.nodeType === 1 ) { |
| 4084 | + this.insertBefore( elem, this.firstChild ); |
| 4085 | + } |
| 4086 | + }); |
| 4087 | + }, |
| 4088 | + |
| 4089 | + before: function() { |
| 4090 | + if ( this[0] && this[0].parentNode ) { |
| 4091 | + return this.domManip(arguments, false, function( elem ) { |
| 4092 | + this.parentNode.insertBefore( elem, this ); |
| 4093 | + }); |
| 4094 | + } else if ( arguments.length ) { |
| 4095 | + var set = jQuery(arguments[0]); |
| 4096 | + set.push.apply( set, this.toArray() ); |
| 4097 | + return this.pushStack( set, "before", arguments ); |
| 4098 | + } |
| 4099 | + }, |
| 4100 | + |
| 4101 | + after: function() { |
| 4102 | + if ( this[0] && this[0].parentNode ) { |
| 4103 | + return this.domManip(arguments, false, function( elem ) { |
| 4104 | + this.parentNode.insertBefore( elem, this.nextSibling ); |
| 4105 | + }); |
| 4106 | + } else if ( arguments.length ) { |
| 4107 | + var set = this.pushStack( this, "after", arguments ); |
| 4108 | + set.push.apply( set, jQuery(arguments[0]).toArray() ); |
| 4109 | + return set; |
| 4110 | + } |
| 4111 | + }, |
| 4112 | + |
| 4113 | + // keepData is for internal use only--do not document |
| 4114 | + remove: function( selector, keepData ) { |
| 4115 | + for ( var i = 0, elem; (elem = this[i]) != null; i++ ) { |
| 4116 | + if ( !selector || jQuery.filter( selector, [ elem ] ).length ) { |
| 4117 | + if ( !keepData && elem.nodeType === 1 ) { |
| 4118 | + jQuery.cleanData( elem.getElementsByTagName("*") ); |
| 4119 | + jQuery.cleanData( [ elem ] ); |
| 4120 | + } |
| 4121 | + |
| 4122 | + if ( elem.parentNode ) { |
| 4123 | + elem.parentNode.removeChild( elem ); |
| 4124 | + } |
| 4125 | + } |
| 4126 | + } |
| 4127 | + |
| 4128 | + return this; |
| 4129 | + }, |
| 4130 | + |
| 4131 | + empty: function() { |
| 4132 | + for ( var i = 0, elem; (elem = this[i]) != null; i++ ) { |
| 4133 | + // Remove element nodes and prevent memory leaks |
| 4134 | + if ( elem.nodeType === 1 ) { |
| 4135 | + jQuery.cleanData( elem.getElementsByTagName("*") ); |
| 4136 | + } |
| 4137 | + |
| 4138 | + // Remove any remaining nodes |
| 4139 | + while ( elem.firstChild ) { |
| 4140 | + elem.removeChild( elem.firstChild ); |
| 4141 | + } |
| 4142 | + } |
| 4143 | + |
| 4144 | + return this; |
| 4145 | + }, |
| 4146 | + |
| 4147 | + clone: function( events ) { |
| 4148 | + // Do the clone |
| 4149 | + var ret = this.map(function() { |
| 4150 | + if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) { |
| 4151 | + // IE copies events bound via attachEvent when |
| 4152 | + // using cloneNode. Calling detachEvent on the |
| 4153 | + // clone will also remove the events from the orignal |
| 4154 | + // In order to get around this, we use innerHTML. |
| 4155 | + // Unfortunately, this means some modifications to |
| 4156 | + // attributes in IE that are actually only stored |
| 4157 | + // as properties will not be copied (such as the |
| 4158 | + // the name attribute on an input). |
| 4159 | + var html = this.outerHTML, ownerDocument = this.ownerDocument; |
| 4160 | + if ( !html ) { |
| 4161 | + var div = ownerDocument.createElement("div"); |
| 4162 | + div.appendChild( this.cloneNode(true) ); |
| 4163 | + html = div.innerHTML; |
| 4164 | + } |
| 4165 | + |
| 4166 | + return jQuery.clean([html.replace(rinlinejQuery, "") |
| 4167 | + // Handle the case in IE 8 where action=/test/> self-closes a tag |
| 4168 | + .replace(/=([^="'>\s]+\/)>/g, '="$1">') |
| 4169 | + .replace(rleadingWhitespace, "")], ownerDocument)[0]; |
| 4170 | + } else { |
| 4171 | + return this.cloneNode(true); |
| 4172 | + } |
| 4173 | + }); |
| 4174 | + |
| 4175 | + // Copy the events from the original to the clone |
| 4176 | + if ( events === true ) { |
| 4177 | + cloneCopyEvent( this, ret ); |
| 4178 | + cloneCopyEvent( this.find("*"), ret.find("*") ); |
| 4179 | + } |
| 4180 | + |
| 4181 | + // Return the cloned set |
| 4182 | + return ret; |
| 4183 | + }, |
| 4184 | + |
| 4185 | + html: function( value ) { |
| 4186 | + if ( value === undefined ) { |
| 4187 | + return this[0] && this[0].nodeType === 1 ? |
| 4188 | + this[0].innerHTML.replace(rinlinejQuery, "") : |
| 4189 | + null; |
| 4190 | + |
| 4191 | + // See if we can take a shortcut and just use innerHTML |
| 4192 | + } else if ( typeof value === "string" && !rnocache.test( value ) && |
| 4193 | + (jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) && |
| 4194 | + !wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) { |
| 4195 | + |
| 4196 | + value = value.replace(rxhtmlTag, fcloseTag); |
| 4197 | + |
| 4198 | + try { |
| 4199 | + for ( var i = 0, l = this.length; i < l; i++ ) { |
| 4200 | + // Remove element nodes and prevent memory leaks |
| 4201 | + if ( this[i].nodeType === 1 ) { |
| 4202 | + jQuery.cleanData( this[i].getElementsByTagName("*") ); |
| 4203 | + this[i].innerHTML = value; |
| 4204 | + } |
| 4205 | + } |
| 4206 | + |
| 4207 | + // If using innerHTML throws an exception, use the fallback method |
| 4208 | + } catch(e) { |
| 4209 | + this.empty().append( value ); |
| 4210 | + } |
| 4211 | + |
| 4212 | + } else if ( jQuery.isFunction( value ) ) { |
| 4213 | + this.each(function(i){ |
| 4214 | + var self = jQuery(this), old = self.html(); |
| 4215 | + self.empty().append(function(){ |
| 4216 | + return value.call( this, i, old ); |
| 4217 | + }); |
| 4218 | + }); |
| 4219 | + |
| 4220 | + } else { |
| 4221 | + this.empty().append( value ); |
| 4222 | + } |
| 4223 | + |
| 4224 | + return this; |
| 4225 | + }, |
| 4226 | + |
| 4227 | + replaceWith: function( value ) { |
| 4228 | + if ( this[0] && this[0].parentNode ) { |
| 4229 | + // Make sure that the elements are removed from the DOM before they are inserted |
| 4230 | + // this can help fix replacing a parent with child elements |
| 4231 | + if ( jQuery.isFunction( value ) ) { |
| 4232 | + return this.each(function(i) { |
| 4233 | + var self = jQuery(this), old = self.html(); |
| 4234 | + self.replaceWith( value.call( this, i, old ) ); |
| 4235 | + }); |
| 4236 | + } |
| 4237 | + |
| 4238 | + if ( typeof value !== "string" ) { |
| 4239 | + value = jQuery(value).detach(); |
| 4240 | + } |
| 4241 | + |
| 4242 | + return this.each(function() { |
| 4243 | + var next = this.nextSibling, parent = this.parentNode; |
| 4244 | + |
| 4245 | + jQuery(this).remove(); |
| 4246 | + |
| 4247 | + if ( next ) { |
| 4248 | + jQuery(next).before( value ); |
| 4249 | + } else { |
| 4250 | + jQuery(parent).append( value ); |
| 4251 | + } |
| 4252 | + }); |
| 4253 | + } else { |
| 4254 | + return this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value ); |
| 4255 | + } |
| 4256 | + }, |
| 4257 | + |
| 4258 | + detach: function( selector ) { |
| 4259 | + return this.remove( selector, true ); |
| 4260 | + }, |
| 4261 | + |
| 4262 | + domManip: function( args, table, callback ) { |
| 4263 | + var results, first, value = args[0], scripts = [], fragment, parent; |
| 4264 | + |
| 4265 | + // We can't cloneNode fragments that contain checked, in WebKit |
| 4266 | + if ( !jQuery.support.checkClone && arguments.length === 3 && typeof value === "string" && rchecked.test( value ) ) { |
| 4267 | + return this.each(function() { |
| 4268 | + jQuery(this).domManip( args, table, callback, true ); |
| 4269 | + }); |
| 4270 | + } |
| 4271 | + |
| 4272 | + if ( jQuery.isFunction(value) ) { |
| 4273 | + return this.each(function(i) { |
| 4274 | + var self = jQuery(this); |
| 4275 | + args[0] = value.call(this, i, table ? self.html() : undefined); |
| 4276 | + self.domManip( args, table, callback ); |
| 4277 | + }); |
| 4278 | + } |
| 4279 | + |
| 4280 | + if ( this[0] ) { |
| 4281 | + parent = value && value.parentNode; |
| 4282 | + |
| 4283 | + // If we're in a fragment, just use that instead of building a new one |
| 4284 | + if ( jQuery.support.parentNode && parent && parent.nodeType === 11 && parent.childNodes.length === this.length ) { |
| 4285 | + results = { fragment: parent }; |
| 4286 | + |
| 4287 | + } else { |
| 4288 | + results = buildFragment( args, this, scripts ); |
| 4289 | + } |
| 4290 | + |
| 4291 | + fragment = results.fragment; |
| 4292 | + |
| 4293 | + if ( fragment.childNodes.length === 1 ) { |
| 4294 | + first = fragment = fragment.firstChild; |
| 4295 | + } else { |
| 4296 | + first = fragment.firstChild; |
| 4297 | + } |
| 4298 | + |
| 4299 | + if ( first ) { |
| 4300 | + table = table && jQuery.nodeName( first, "tr" ); |
| 4301 | + |
| 4302 | + for ( var i = 0, l = this.length; i < l; i++ ) { |
| 4303 | + callback.call( |
| 4304 | + table ? |
| 4305 | + root(this[i], first) : |
| 4306 | + this[i], |
| 4307 | + i > 0 || results.cacheable || this.length > 1 ? |
| 4308 | + fragment.cloneNode(true) : |
| 4309 | + fragment |
| 4310 | + ); |
| 4311 | + } |
| 4312 | + } |
| 4313 | + |
| 4314 | + if ( scripts.length ) { |
| 4315 | + jQuery.each( scripts, evalScript ); |
| 4316 | + } |
| 4317 | + } |
| 4318 | + |
| 4319 | + return this; |
| 4320 | + |
| 4321 | + function root( elem, cur ) { |
| 4322 | + return jQuery.nodeName(elem, "table") ? |
| 4323 | + (elem.getElementsByTagName("tbody")[0] || |
| 4324 | + elem.appendChild(elem.ownerDocument.createElement("tbody"))) : |
| 4325 | + elem; |
| 4326 | + } |
| 4327 | + } |
| 4328 | +}); |
| 4329 | + |
| 4330 | +function cloneCopyEvent(orig, ret) { |
| 4331 | + var i = 0; |
| 4332 | + |
| 4333 | + ret.each(function() { |
| 4334 | + if ( this.nodeName !== (orig[i] && orig[i].nodeName) ) { |
| 4335 | + return; |
| 4336 | + } |
| 4337 | + |
| 4338 | + var oldData = jQuery.data( orig[i++] ), curData = jQuery.data( this, oldData ), events = oldData && oldData.events; |
| 4339 | + |
| 4340 | + if ( events ) { |
| 4341 | + delete curData.handle; |
| 4342 | + curData.events = {}; |
| 4343 | + |
| 4344 | + for ( var type in events ) { |
| 4345 | + for ( var handler in events[ type ] ) { |
| 4346 | + jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data ); |
| 4347 | + } |
| 4348 | + } |
| 4349 | + } |
| 4350 | + }); |
| 4351 | +} |
| 4352 | + |
| 4353 | +function buildFragment( args, nodes, scripts ) { |
| 4354 | + var fragment, cacheable, cacheresults, |
| 4355 | + doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document); |
| 4356 | + |
| 4357 | + // Only cache "small" (1/2 KB) strings that are associated with the main document |
| 4358 | + // Cloning options loses the selected state, so don't cache them |
| 4359 | + // IE 6 doesn't like it when you put <object> or <embed> elements in a fragment |
| 4360 | + // Also, WebKit does not clone 'checked' attributes on cloneNode, so don't cache |
| 4361 | + if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && doc === document && |
| 4362 | + !rnocache.test( args[0] ) && (jQuery.support.checkClone || !rchecked.test( args[0] )) ) { |
| 4363 | + |
| 4364 | + cacheable = true; |
| 4365 | + cacheresults = jQuery.fragments[ args[0] ]; |
| 4366 | + if ( cacheresults ) { |
| 4367 | + if ( cacheresults !== 1 ) { |
| 4368 | + fragment = cacheresults; |
| 4369 | + } |
| 4370 | + } |
| 4371 | + } |
| 4372 | + |
| 4373 | + if ( !fragment ) { |
| 4374 | + fragment = doc.createDocumentFragment(); |
| 4375 | + jQuery.clean( args, doc, fragment, scripts ); |
| 4376 | + } |
| 4377 | + |
| 4378 | + if ( cacheable ) { |
| 4379 | + jQuery.fragments[ args[0] ] = cacheresults ? fragment : 1; |
| 4380 | + } |
| 4381 | + |
| 4382 | + return { fragment: fragment, cacheable: cacheable }; |
| 4383 | +} |
| 4384 | + |
| 4385 | +jQuery.fragments = {}; |
| 4386 | + |
| 4387 | +jQuery.each({ |
| 4388 | + appendTo: "append", |
| 4389 | + prependTo: "prepend", |
| 4390 | + insertBefore: "before", |
| 4391 | + insertAfter: "after", |
| 4392 | + replaceAll: "replaceWith" |
| 4393 | +}, function( name, original ) { |
| 4394 | + jQuery.fn[ name ] = function( selector ) { |
| 4395 | + var ret = [], insert = jQuery( selector ), |
| 4396 | + parent = this.length === 1 && this[0].parentNode; |
| 4397 | + |
| 4398 | + if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) { |
| 4399 | + insert[ original ]( this[0] ); |
| 4400 | + return this; |
| 4401 | + |
| 4402 | + } else { |
| 4403 | + for ( var i = 0, l = insert.length; i < l; i++ ) { |
| 4404 | + var elems = (i > 0 ? this.clone(true) : this).get(); |
| 4405 | + jQuery.fn[ original ].apply( jQuery(insert[i]), elems ); |
| 4406 | + ret = ret.concat( elems ); |
| 4407 | + } |
| 4408 | + |
| 4409 | + return this.pushStack( ret, name, insert.selector ); |
| 4410 | + } |
| 4411 | + }; |
| 4412 | +}); |
| 4413 | + |
| 4414 | +jQuery.extend({ |
| 4415 | + clean: function( elems, context, fragment, scripts ) { |
| 4416 | + context = context || document; |
| 4417 | + |
| 4418 | + // !context.createElement fails in IE with an error but returns typeof 'object' |
| 4419 | + if ( typeof context.createElement === "undefined" ) { |
| 4420 | + context = context.ownerDocument || context[0] && context[0].ownerDocument || document; |
| 4421 | + } |
| 4422 | + |
| 4423 | + var ret = []; |
| 4424 | + |
| 4425 | + for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) { |
| 4426 | + if ( typeof elem === "number" ) { |
| 4427 | + elem += ""; |
| 4428 | + } |
| 4429 | + |
| 4430 | + if ( !elem ) { |
| 4431 | + continue; |
| 4432 | + } |
| 4433 | + |
| 4434 | + // Convert html string into DOM nodes |
| 4435 | + if ( typeof elem === "string" && !rhtml.test( elem ) ) { |
| 4436 | + elem = context.createTextNode( elem ); |
| 4437 | + |
| 4438 | + } else if ( typeof elem === "string" ) { |
| 4439 | + // Fix "XHTML"-style tags in all browsers |
| 4440 | + elem = elem.replace(rxhtmlTag, fcloseTag); |
| 4441 | + |
| 4442 | + // Trim whitespace, otherwise indexOf won't work as expected |
| 4443 | + var tag = (rtagName.exec( elem ) || ["", ""])[1].toLowerCase(), |
| 4444 | + wrap = wrapMap[ tag ] || wrapMap._default, |
| 4445 | + depth = wrap[0], |
| 4446 | + div = context.createElement("div"); |
| 4447 | + |
| 4448 | + // Go to html and back, then peel off extra wrappers |
| 4449 | + div.innerHTML = wrap[1] + elem + wrap[2]; |
| 4450 | + |
| 4451 | + // Move to the right depth |
| 4452 | + while ( depth-- ) { |
| 4453 | + div = div.lastChild; |
| 4454 | + } |
| 4455 | + |
| 4456 | + // Remove IE's autoinserted <tbody> from table fragments |
| 4457 | + if ( !jQuery.support.tbody ) { |
| 4458 | + |
| 4459 | + // String was a <table>, *may* have spurious <tbody> |
| 4460 | + var hasBody = rtbody.test(elem), |
| 4461 | + tbody = tag === "table" && !hasBody ? |
| 4462 | + div.firstChild && div.firstChild.childNodes : |
| 4463 | + |
| 4464 | + // String was a bare <thead> or <tfoot> |
| 4465 | + wrap[1] === "<table>" && !hasBody ? |
| 4466 | + div.childNodes : |
| 4467 | + []; |
| 4468 | + |
| 4469 | + for ( var j = tbody.length - 1; j >= 0 ; --j ) { |
| 4470 | + if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) { |
| 4471 | + tbody[ j ].parentNode.removeChild( tbody[ j ] ); |
| 4472 | + } |
| 4473 | + } |
| 4474 | + |
| 4475 | + } |
| 4476 | + |
| 4477 | + // IE completely kills leading whitespace when innerHTML is used |
| 4478 | + if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) { |
| 4479 | + div.insertBefore( context.createTextNode( rleadingWhitespace.exec(elem)[0] ), div.firstChild ); |
| 4480 | + } |
| 4481 | + |
| 4482 | + elem = div.childNodes; |
| 4483 | + } |
| 4484 | + |
| 4485 | + if ( elem.nodeType ) { |
| 4486 | + ret.push( elem ); |
| 4487 | + } else { |
| 4488 | + ret = jQuery.merge( ret, elem ); |
| 4489 | + } |
| 4490 | + } |
| 4491 | + |
| 4492 | + if ( fragment ) { |
| 4493 | + for ( var i = 0; ret[i]; i++ ) { |
| 4494 | + if ( scripts && jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) { |
| 4495 | + scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] ); |
| 4496 | + |
| 4497 | + } else { |
| 4498 | + if ( ret[i].nodeType === 1 ) { |
| 4499 | + ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) ); |
| 4500 | + } |
| 4501 | + fragment.appendChild( ret[i] ); |
| 4502 | + } |
| 4503 | + } |
| 4504 | + } |
| 4505 | + |
| 4506 | + return ret; |
| 4507 | + }, |
| 4508 | + |
| 4509 | + cleanData: function( elems ) { |
| 4510 | + var data, id, cache = jQuery.cache, |
| 4511 | + special = jQuery.event.special, |
| 4512 | + deleteExpando = jQuery.support.deleteExpando; |
| 4513 | + |
| 4514 | + for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) { |
| 4515 | + id = elem[ jQuery.expando ]; |
| 4516 | + |
| 4517 | + if ( id ) { |
| 4518 | + data = cache[ id ]; |
| 4519 | + |
| 4520 | + if ( data.events ) { |
| 4521 | + for ( var type in data.events ) { |
| 4522 | + if ( special[ type ] ) { |
| 4523 | + jQuery.event.remove( elem, type ); |
| 4524 | + |
| 4525 | + } else { |
| 4526 | + removeEvent( elem, type, data.handle ); |
| 4527 | + } |
| 4528 | + } |
| 4529 | + } |
| 4530 | + |
| 4531 | + if ( deleteExpando ) { |
| 4532 | + delete elem[ jQuery.expando ]; |
| 4533 | + |
| 4534 | + } else if ( elem.removeAttribute ) { |
| 4535 | + elem.removeAttribute( jQuery.expando ); |
| 4536 | + } |
| 4537 | + |
| 4538 | + delete cache[ id ]; |
| 4539 | + } |
| 4540 | + } |
| 4541 | + } |
| 4542 | +}); |
| 4543 | +// exclude the following css properties to add px |
| 4544 | +var rexclude = /z-?index|font-?weight|opacity|zoom|line-?height/i, |
| 4545 | + ralpha = /alpha\([^)]*\)/, |
| 4546 | + ropacity = /opacity=([^)]*)/, |
| 4547 | + rfloat = /float/i, |
| 4548 | + rdashAlpha = /-([a-z])/ig, |
| 4549 | + rupper = /([A-Z])/g, |
| 4550 | + rnumpx = /^-?\d+(?:px)?$/i, |
| 4551 | + rnum = /^-?\d/, |
| 4552 | + |
| 4553 | + cssShow = { position: "absolute", visibility: "hidden", display:"block" }, |
| 4554 | + cssWidth = [ "Left", "Right" ], |
| 4555 | + cssHeight = [ "Top", "Bottom" ], |
| 4556 | + |
| 4557 | + // cache check for defaultView.getComputedStyle |
| 4558 | + getComputedStyle = document.defaultView && document.defaultView.getComputedStyle, |
| 4559 | + // normalize float css property |
| 4560 | + styleFloat = jQuery.support.cssFloat ? "cssFloat" : "styleFloat", |
| 4561 | + fcamelCase = function( all, letter ) { |
| 4562 | + return letter.toUpperCase(); |
| 4563 | + }; |
| 4564 | + |
| 4565 | +jQuery.fn.css = function( name, value ) { |
| 4566 | + return access( this, name, value, true, function( elem, name, value ) { |
| 4567 | + if ( value === undefined ) { |
| 4568 | + return jQuery.curCSS( elem, name ); |
| 4569 | + } |
| 4570 | + |
| 4571 | + if ( typeof value === "number" && !rexclude.test(name) ) { |
| 4572 | + value += "px"; |
| 4573 | + } |
| 4574 | + |
| 4575 | + jQuery.style( elem, name, value ); |
| 4576 | + }); |
| 4577 | +}; |
| 4578 | + |
| 4579 | +jQuery.extend({ |
| 4580 | + style: function( elem, name, value ) { |
| 4581 | + // don't set styles on text and comment nodes |
| 4582 | + if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) { |
| 4583 | + return undefined; |
| 4584 | + } |
| 4585 | + |
| 4586 | + // ignore negative width and height values #1599 |
| 4587 | + if ( (name === "width" || name === "height") && parseFloat(value) < 0 ) { |
| 4588 | + value = undefined; |
| 4589 | + } |
| 4590 | + |
| 4591 | + var style = elem.style || elem, set = value !== undefined; |
| 4592 | + |
| 4593 | + // IE uses filters for opacity |
| 4594 | + if ( !jQuery.support.opacity && name === "opacity" ) { |
| 4595 | + if ( set ) { |
| 4596 | + // IE has trouble with opacity if it does not have layout |
| 4597 | + // Force it by setting the zoom level |
| 4598 | + style.zoom = 1; |
| 4599 | + |
| 4600 | + // Set the alpha filter to set the opacity |
| 4601 | + var opacity = parseInt( value, 10 ) + "" === "NaN" ? "" : "alpha(opacity=" + value * 100 + ")"; |
| 4602 | + var filter = style.filter || jQuery.curCSS( elem, "filter" ) || ""; |
| 4603 | + style.filter = ralpha.test(filter) ? filter.replace(ralpha, opacity) : opacity; |
| 4604 | + } |
| 4605 | + |
| 4606 | + return style.filter && style.filter.indexOf("opacity=") >= 0 ? |
| 4607 | + (parseFloat( ropacity.exec(style.filter)[1] ) / 100) + "": |
| 4608 | + ""; |
| 4609 | + } |
| 4610 | + |
| 4611 | + // Make sure we're using the right name for getting the float value |
| 4612 | + if ( rfloat.test( name ) ) { |
| 4613 | + name = styleFloat; |
| 4614 | + } |
| 4615 | + |
| 4616 | + name = name.replace(rdashAlpha, fcamelCase); |
| 4617 | + |
| 4618 | + if ( set ) { |
| 4619 | + style[ name ] = value; |
| 4620 | + } |
| 4621 | + |
| 4622 | + return style[ name ]; |
| 4623 | + }, |
| 4624 | + |
| 4625 | + css: function( elem, name, force, extra ) { |
| 4626 | + if ( name === "width" || name === "height" ) { |
| 4627 | + var val, props = cssShow, which = name === "width" ? cssWidth : cssHeight; |
| 4628 | + |
| 4629 | + function getWH() { |
| 4630 | + val = name === "width" ? elem.offsetWidth : elem.offsetHeight; |
| 4631 | + |
| 4632 | + if ( extra === "border" ) { |
| 4633 | + return; |
| 4634 | + } |
| 4635 | + |
| 4636 | + jQuery.each( which, function() { |
| 4637 | + if ( !extra ) { |
| 4638 | + val -= parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0; |
| 4639 | + } |
| 4640 | + |
| 4641 | + if ( extra === "margin" ) { |
| 4642 | + val += parseFloat(jQuery.curCSS( elem, "margin" + this, true)) || 0; |
| 4643 | + } else { |
| 4644 | + val -= parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0; |
| 4645 | + } |
| 4646 | + }); |
| 4647 | + } |
| 4648 | + |
| 4649 | + if ( elem.offsetWidth !== 0 ) { |
| 4650 | + getWH(); |
| 4651 | + } else { |
| 4652 | + jQuery.swap( elem, props, getWH ); |
| 4653 | + } |
| 4654 | + |
| 4655 | + return Math.max(0, Math.round(val)); |
| 4656 | + } |
| 4657 | + |
| 4658 | + return jQuery.curCSS( elem, name, force ); |
| 4659 | + }, |
| 4660 | + |
| 4661 | + curCSS: function( elem, name, force ) { |
| 4662 | + var ret, style = elem.style, filter; |
| 4663 | + |
| 4664 | + // IE uses filters for opacity |
| 4665 | + if ( !jQuery.support.opacity && name === "opacity" && elem.currentStyle ) { |
| 4666 | + ret = ropacity.test(elem.currentStyle.filter || "") ? |
| 4667 | + (parseFloat(RegExp.$1) / 100) + "" : |
| 4668 | + ""; |
| 4669 | + |
| 4670 | + return ret === "" ? |
| 4671 | + "1" : |
| 4672 | + ret; |
| 4673 | + } |
| 4674 | + |
| 4675 | + // Make sure we're using the right name for getting the float value |
| 4676 | + if ( rfloat.test( name ) ) { |
| 4677 | + name = styleFloat; |
| 4678 | + } |
| 4679 | + |
| 4680 | + if ( !force && style && style[ name ] ) { |
| 4681 | + ret = style[ name ]; |
| 4682 | + |
| 4683 | + } else if ( getComputedStyle ) { |
| 4684 | + |
| 4685 | + // Only "float" is needed here |
| 4686 | + if ( rfloat.test( name ) ) { |
| 4687 | + name = "float"; |
| 4688 | + } |
| 4689 | + |
| 4690 | + name = name.replace( rupper, "-$1" ).toLowerCase(); |
| 4691 | + |
| 4692 | + var defaultView = elem.ownerDocument.defaultView; |
| 4693 | + |
| 4694 | + if ( !defaultView ) { |
| 4695 | + return null; |
| 4696 | + } |
| 4697 | + |
| 4698 | + var computedStyle = defaultView.getComputedStyle( elem, null ); |
| 4699 | + |
| 4700 | + if ( computedStyle ) { |
| 4701 | + ret = computedStyle.getPropertyValue( name ); |
| 4702 | + } |
| 4703 | + |
| 4704 | + // We should always get a number back from opacity |
| 4705 | + if ( name === "opacity" && ret === "" ) { |
| 4706 | + ret = "1"; |
| 4707 | + } |
| 4708 | + |
| 4709 | + } else if ( elem.currentStyle ) { |
| 4710 | + var camelCase = name.replace(rdashAlpha, fcamelCase); |
| 4711 | + |
| 4712 | + ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ]; |
| 4713 | + |
| 4714 | + // From the awesome hack by Dean Edwards |
| 4715 | + // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291 |
| 4716 | + |
| 4717 | + // If we're not dealing with a regular pixel number |
| 4718 | + // but a number that has a weird ending, we need to convert it to pixels |
| 4719 | + if ( !rnumpx.test( ret ) && rnum.test( ret ) ) { |
| 4720 | + // Remember the original values |
| 4721 | + var left = style.left, rsLeft = elem.runtimeStyle.left; |
| 4722 | + |
| 4723 | + // Put in the new values to get a computed value out |
| 4724 | + elem.runtimeStyle.left = elem.currentStyle.left; |
| 4725 | + style.left = camelCase === "fontSize" ? "1em" : (ret || 0); |
| 4726 | + ret = style.pixelLeft + "px"; |
| 4727 | + |
| 4728 | + // Revert the changed values |
| 4729 | + style.left = left; |
| 4730 | + elem.runtimeStyle.left = rsLeft; |
| 4731 | + } |
| 4732 | + } |
| 4733 | + |
| 4734 | + return ret; |
| 4735 | + }, |
| 4736 | + |
| 4737 | + // A method for quickly swapping in/out CSS properties to get correct calculations |
| 4738 | + swap: function( elem, options, callback ) { |
| 4739 | + var old = {}; |
| 4740 | + |
| 4741 | + // Remember the old values, and insert the new ones |
| 4742 | + for ( var name in options ) { |
| 4743 | + old[ name ] = elem.style[ name ]; |
| 4744 | + elem.style[ name ] = options[ name ]; |
| 4745 | + } |
| 4746 | + |
| 4747 | + callback.call( elem ); |
| 4748 | + |
| 4749 | + // Revert the old values |
| 4750 | + for ( var name in options ) { |
| 4751 | + elem.style[ name ] = old[ name ]; |
| 4752 | + } |
| 4753 | + } |
| 4754 | +}); |
| 4755 | + |
| 4756 | +if ( jQuery.expr && jQuery.expr.filters ) { |
| 4757 | + jQuery.expr.filters.hidden = function( elem ) { |
| 4758 | + var width = elem.offsetWidth, height = elem.offsetHeight, |
| 4759 | + skip = elem.nodeName.toLowerCase() === "tr"; |
| 4760 | + |
| 4761 | + return width === 0 && height === 0 && !skip ? |
| 4762 | + true : |
| 4763 | + width > 0 && height > 0 && !skip ? |
| 4764 | + false : |
| 4765 | + jQuery.curCSS(elem, "display") === "none"; |
| 4766 | + }; |
| 4767 | + |
| 4768 | + jQuery.expr.filters.visible = function( elem ) { |
| 4769 | + return !jQuery.expr.filters.hidden( elem ); |
| 4770 | + }; |
| 4771 | +} |
| 4772 | +var jsc = now(), |
| 4773 | + rscript = /<script(.|\s)*?\/script>/gi, |
| 4774 | + rselectTextarea = /select|textarea/i, |
| 4775 | + rinput = /color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week/i, |
| 4776 | + jsre = /=\?(&|$)/, |
| 4777 | + rquery = /\?/, |
| 4778 | + rts = /(\?|&)_=.*?(&|$)/, |
| 4779 | + rurl = /^(\w+:)?\/\/([^\/?#]+)/, |
| 4780 | + r20 = /%20/g, |
| 4781 | + |
| 4782 | + // Keep a copy of the old load method |
| 4783 | + _load = jQuery.fn.load; |
| 4784 | + |
| 4785 | +jQuery.fn.extend({ |
| 4786 | + load: function( url, params, callback ) { |
| 4787 | + if ( typeof url !== "string" ) { |
| 4788 | + return _load.call( this, url ); |
| 4789 | + |
| 4790 | + // Don't do a request if no elements are being requested |
| 4791 | + } else if ( !this.length ) { |
| 4792 | + return this; |
| 4793 | + } |
| 4794 | + |
| 4795 | + var off = url.indexOf(" "); |
| 4796 | + if ( off >= 0 ) { |
| 4797 | + var selector = url.slice(off, url.length); |
| 4798 | + url = url.slice(0, off); |
| 4799 | + } |
| 4800 | + |
| 4801 | + // Default to a GET request |
| 4802 | + var type = "GET"; |
| 4803 | + |
| 4804 | + // If the second parameter was provided |
| 4805 | + if ( params ) { |
| 4806 | + // If it's a function |
| 4807 | + if ( jQuery.isFunction( params ) ) { |
| 4808 | + // We assume that it's the callback |
| 4809 | + callback = params; |
| 4810 | + params = null; |
| 4811 | + |
| 4812 | + // Otherwise, build a param string |
| 4813 | + } else if ( typeof params === "object" ) { |
| 4814 | + params = jQuery.param( params, jQuery.ajaxSettings.traditional ); |
| 4815 | + type = "POST"; |
| 4816 | + } |
| 4817 | + } |
| 4818 | + |
| 4819 | + var self = this; |
| 4820 | + |
| 4821 | + // Request the remote document |
| 4822 | + jQuery.ajax({ |
| 4823 | + url: url, |
| 4824 | + type: type, |
| 4825 | + dataType: "html", |
| 4826 | + data: params, |
| 4827 | + complete: function( res, status ) { |
| 4828 | + // If successful, inject the HTML into all the matched elements |
| 4829 | + if ( status === "success" || status === "notmodified" ) { |
| 4830 | + // See if a selector was specified |
| 4831 | + self.html( selector ? |
| 4832 | + // Create a dummy div to hold the results |
| 4833 | + jQuery("<div />") |
| 4834 | + // inject the contents of the document in, removing the scripts |
| 4835 | + // to avoid any 'Permission Denied' errors in IE |
| 4836 | + .append(res.responseText.replace(rscript, "")) |
| 4837 | + |
| 4838 | + // Locate the specified elements |
| 4839 | + .find(selector) : |
| 4840 | + |
| 4841 | + // If not, just inject the full result |
| 4842 | + res.responseText ); |
| 4843 | + } |
| 4844 | + |
| 4845 | + if ( callback ) { |
| 4846 | + self.each( callback, [res.responseText, status, res] ); |
| 4847 | + } |
| 4848 | + } |
| 4849 | + }); |
| 4850 | + |
| 4851 | + return this; |
| 4852 | + }, |
| 4853 | + |
| 4854 | + serialize: function() { |
| 4855 | + return jQuery.param(this.serializeArray()); |
| 4856 | + }, |
| 4857 | + serializeArray: function() { |
| 4858 | + return this.map(function() { |
| 4859 | + return this.elements ? jQuery.makeArray(this.elements) : this; |
| 4860 | + }) |
| 4861 | + .filter(function() { |
| 4862 | + return this.name && !this.disabled && |
| 4863 | + (this.checked || rselectTextarea.test(this.nodeName) || |
| 4864 | + rinput.test(this.type)); |
| 4865 | + }) |
| 4866 | + .map(function( i, elem ) { |
| 4867 | + var val = jQuery(this).val(); |
| 4868 | + |
| 4869 | + return val == null ? |
| 4870 | + null : |
| 4871 | + jQuery.isArray(val) ? |
| 4872 | + jQuery.map( val, function( val, i ) { |
| 4873 | + return { name: elem.name, value: val }; |
| 4874 | + }) : |
| 4875 | + { name: elem.name, value: val }; |
| 4876 | + }).get(); |
| 4877 | + } |
| 4878 | +}); |
| 4879 | + |
| 4880 | +// Attach a bunch of functions for handling common AJAX events |
| 4881 | +jQuery.each( "ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "), function( i, o ) { |
| 4882 | + jQuery.fn[o] = function( f ) { |
| 4883 | + return this.bind(o, f); |
| 4884 | + }; |
| 4885 | +}); |
| 4886 | + |
| 4887 | +jQuery.extend({ |
| 4888 | + |
| 4889 | + get: function( url, data, callback, type ) { |
| 4890 | + // shift arguments if data argument was omited |
| 4891 | + if ( jQuery.isFunction( data ) ) { |
| 4892 | + type = type || callback; |
| 4893 | + callback = data; |
| 4894 | + data = null; |
| 4895 | + } |
| 4896 | + |
| 4897 | + return jQuery.ajax({ |
| 4898 | + type: "GET", |
| 4899 | + url: url, |
| 4900 | + data: data, |
| 4901 | + success: callback, |
| 4902 | + dataType: type |
| 4903 | + }); |
| 4904 | + }, |
| 4905 | + |
| 4906 | + getScript: function( url, callback ) { |
| 4907 | + return jQuery.get(url, null, callback, "script"); |
| 4908 | + }, |
| 4909 | + |
| 4910 | + getJSON: function( url, data, callback ) { |
| 4911 | + return jQuery.get(url, data, callback, "json"); |
| 4912 | + }, |
| 4913 | + |
| 4914 | + post: function( url, data, callback, type ) { |
| 4915 | + // shift arguments if data argument was omited |
| 4916 | + if ( jQuery.isFunction( data ) ) { |
| 4917 | + type = type || callback; |
| 4918 | + callback = data; |
| 4919 | + data = {}; |
| 4920 | + } |
| 4921 | + |
| 4922 | + return jQuery.ajax({ |
| 4923 | + type: "POST", |
| 4924 | + url: url, |
| 4925 | + data: data, |
| 4926 | + success: callback, |
| 4927 | + dataType: type |
| 4928 | + }); |
| 4929 | + }, |
| 4930 | + |
| 4931 | + ajaxSetup: function( settings ) { |
| 4932 | + jQuery.extend( jQuery.ajaxSettings, settings ); |
| 4933 | + }, |
| 4934 | + |
| 4935 | + ajaxSettings: { |
| 4936 | + url: location.href, |
| 4937 | + global: true, |
| 4938 | + type: "GET", |
| 4939 | + contentType: "application/x-www-form-urlencoded", |
| 4940 | + processData: true, |
| 4941 | + async: true, |
| 4942 | + /* |
| 4943 | + timeout: 0, |
| 4944 | + data: null, |
| 4945 | + username: null, |
| 4946 | + password: null, |
| 4947 | + traditional: false, |
| 4948 | + */ |
| 4949 | + // Create the request object; Microsoft failed to properly |
| 4950 | + // implement the XMLHttpRequest in IE7 (can't request local files), |
| 4951 | + // so we use the ActiveXObject when it is available |
| 4952 | + // This function can be overriden by calling jQuery.ajaxSetup |
| 4953 | + xhr: window.XMLHttpRequest && (window.location.protocol !== "file:" || !window.ActiveXObject) ? |
| 4954 | + function() { |
| 4955 | + return new window.XMLHttpRequest(); |
| 4956 | + } : |
| 4957 | + function() { |
| 4958 | + try { |
| 4959 | + return new window.ActiveXObject("Microsoft.XMLHTTP"); |
| 4960 | + } catch(e) {} |
| 4961 | + }, |
| 4962 | + accepts: { |
| 4963 | + xml: "application/xml, text/xml", |
| 4964 | + html: "text/html", |
| 4965 | + script: "text/javascript, application/javascript", |
| 4966 | + json: "application/json, text/javascript", |
| 4967 | + text: "text/plain", |
| 4968 | + _default: "*/*" |
| 4969 | + } |
| 4970 | + }, |
| 4971 | + |
| 4972 | + // Last-Modified header cache for next request |
| 4973 | + lastModified: {}, |
| 4974 | + etag: {}, |
| 4975 | + |
| 4976 | + ajax: function( origSettings ) { |
| 4977 | + var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings); |
| 4978 | + |
| 4979 | + var jsonp, status, data, |
| 4980 | + callbackContext = origSettings && origSettings.context || s, |
| 4981 | + type = s.type.toUpperCase(); |
| 4982 | + |
| 4983 | + // convert data if not already a string |
| 4984 | + if ( s.data && s.processData && typeof s.data !== "string" ) { |
| 4985 | + s.data = jQuery.param( s.data, s.traditional ); |
| 4986 | + } |
| 4987 | + |
| 4988 | + // Handle JSONP Parameter Callbacks |
| 4989 | + if ( s.dataType === "jsonp" ) { |
| 4990 | + if ( type === "GET" ) { |
| 4991 | + if ( !jsre.test( s.url ) ) { |
| 4992 | + s.url += (rquery.test( s.url ) ? "&" : "?") + (s.jsonp || "callback") + "=?"; |
| 4993 | + } |
| 4994 | + } else if ( !s.data || !jsre.test(s.data) ) { |
| 4995 | + s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?"; |
| 4996 | + } |
| 4997 | + s.dataType = "json"; |
| 4998 | + } |
| 4999 | + |
| 5000 | + // Build temporary JSONP function |
| 5001 | + if ( s.dataType === "json" && (s.data && jsre.test(s.data) || jsre.test(s.url)) ) { |
| 5002 | + jsonp = s.jsonpCallback || ("jsonp" + jsc++); |
| 5003 | + |
| 5004 | + // Replace the =? sequence both in the query string and the data |
| 5005 | + if ( s.data ) { |
| 5006 | + s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1"); |
| 5007 | + } |
| 5008 | + |
| 5009 | + s.url = s.url.replace(jsre, "=" + jsonp + "$1"); |
| 5010 | + |
| 5011 | + // We need to make sure |
| 5012 | + // that a JSONP style response is executed properly |
| 5013 | + s.dataType = "script"; |
| 5014 | + |
| 5015 | + // Handle JSONP-style loading |
| 5016 | + window[ jsonp ] = window[ jsonp ] || function( tmp ) { |
| 5017 | + data = tmp; |
| 5018 | + success(); |
| 5019 | + complete(); |
| 5020 | + // Garbage collect |
| 5021 | + window[ jsonp ] = undefined; |
| 5022 | + |
| 5023 | + try { |
| 5024 | + delete window[ jsonp ]; |
| 5025 | + } catch(e) {} |
| 5026 | + |
| 5027 | + if ( head ) { |
| 5028 | + head.removeChild( script ); |
| 5029 | + } |
| 5030 | + }; |
| 5031 | + } |
| 5032 | + |
| 5033 | + if ( s.dataType === "script" && s.cache === null ) { |
| 5034 | + s.cache = false; |
| 5035 | + } |
| 5036 | + |
| 5037 | + if ( s.cache === false && type === "GET" ) { |
| 5038 | + var ts = now(); |
| 5039 | + |
| 5040 | + // try replacing _= if it is there |
| 5041 | + var ret = s.url.replace(rts, "$1_=" + ts + "$2"); |
| 5042 | + |
| 5043 | + // if nothing was replaced, add timestamp to the end |
| 5044 | + s.url = ret + ((ret === s.url) ? (rquery.test(s.url) ? "&" : "?") + "_=" + ts : ""); |
| 5045 | + } |
| 5046 | + |
| 5047 | + // If data is available, append data to url for get requests |
| 5048 | + if ( s.data && type === "GET" ) { |
| 5049 | + s.url += (rquery.test(s.url) ? "&" : "?") + s.data; |
| 5050 | + } |
| 5051 | + |
| 5052 | + // Watch for a new set of requests |
| 5053 | + if ( s.global && ! jQuery.active++ ) { |
| 5054 | + jQuery.event.trigger( "ajaxStart" ); |
| 5055 | + } |
| 5056 | + |
| 5057 | + // Matches an absolute URL, and saves the domain |
| 5058 | + var parts = rurl.exec( s.url ), |
| 5059 | + remote = parts && (parts[1] && parts[1] !== location.protocol || parts[2] !== location.host); |
| 5060 | + |
| 5061 | + // If we're requesting a remote document |
| 5062 | + // and trying to load JSON or Script with a GET |
| 5063 | + if ( s.dataType === "script" && type === "GET" && remote ) { |
| 5064 | + var head = document.getElementsByTagName("head")[0] || document.documentElement; |
| 5065 | + var script = document.createElement("script"); |
| 5066 | + script.src = s.url; |
| 5067 | + if ( s.scriptCharset ) { |
| 5068 | + script.charset = s.scriptCharset; |
| 5069 | + } |
| 5070 | + |
| 5071 | + // Handle Script loading |
| 5072 | + if ( !jsonp ) { |
| 5073 | + var done = false; |
| 5074 | + |
| 5075 | + // Attach handlers for all browsers |
| 5076 | + script.onload = script.onreadystatechange = function() { |
| 5077 | + if ( !done && (!this.readyState || |
| 5078 | + this.readyState === "loaded" || this.readyState === "complete") ) { |
| 5079 | + done = true; |
| 5080 | + success(); |
| 5081 | + complete(); |
| 5082 | + |
| 5083 | + // Handle memory leak in IE |
| 5084 | + script.onload = script.onreadystatechange = null; |
| 5085 | + if ( head && script.parentNode ) { |
| 5086 | + head.removeChild( script ); |
| 5087 | + } |
| 5088 | + } |
| 5089 | + }; |
| 5090 | + } |
| 5091 | + |
| 5092 | + // Use insertBefore instead of appendChild to circumvent an IE6 bug. |
| 5093 | + // This arises when a base node is used (#2709 and #4378). |
| 5094 | + head.insertBefore( script, head.firstChild ); |
| 5095 | + |
| 5096 | + // We handle everything using the script element injection |
| 5097 | + return undefined; |
| 5098 | + } |
| 5099 | + |
| 5100 | + var requestDone = false; |
| 5101 | + |
| 5102 | + // Create the request object |
| 5103 | + var xhr = s.xhr(); |
| 5104 | + |
| 5105 | + if ( !xhr ) { |
| 5106 | + return; |
| 5107 | + } |
| 5108 | + |
| 5109 | + // Open the socket |
| 5110 | + // Passing null username, generates a login popup on Opera (#2865) |
| 5111 | + if ( s.username ) { |
| 5112 | + xhr.open(type, s.url, s.async, s.username, s.password); |
| 5113 | + } else { |
| 5114 | + xhr.open(type, s.url, s.async); |
| 5115 | + } |
| 5116 | + |
| 5117 | + // Need an extra try/catch for cross domain requests in Firefox 3 |
| 5118 | + try { |
| 5119 | + // Set the correct header, if data is being sent |
| 5120 | + if ( s.data || origSettings && origSettings.contentType ) { |
| 5121 | + xhr.setRequestHeader("Content-Type", s.contentType); |
| 5122 | + } |
| 5123 | + |
| 5124 | + // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode. |
| 5125 | + if ( s.ifModified ) { |
| 5126 | + if ( jQuery.lastModified[s.url] ) { |
| 5127 | + xhr.setRequestHeader("If-Modified-Since", jQuery.lastModified[s.url]); |
| 5128 | + } |
| 5129 | + |
| 5130 | + if ( jQuery.etag[s.url] ) { |
| 5131 | + xhr.setRequestHeader("If-None-Match", jQuery.etag[s.url]); |
| 5132 | + } |
| 5133 | + } |
| 5134 | + |
| 5135 | + // Set header so the called script knows that it's an XMLHttpRequest |
| 5136 | + // Only send the header if it's not a remote XHR |
| 5137 | + if ( !remote ) { |
| 5138 | + xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); |
| 5139 | + } |
| 5140 | + |
| 5141 | + // Set the Accepts header for the server, depending on the dataType |
| 5142 | + xhr.setRequestHeader("Accept", s.dataType && s.accepts[ s.dataType ] ? |
| 5143 | + s.accepts[ s.dataType ] + ", */*" : |
| 5144 | + s.accepts._default ); |
| 5145 | + } catch(e) {} |
| 5146 | + |
| 5147 | + // Allow custom headers/mimetypes and early abort |
| 5148 | + if ( s.beforeSend && s.beforeSend.call(callbackContext, xhr, s) === false ) { |
| 5149 | + // Handle the global AJAX counter |
| 5150 | + if ( s.global && ! --jQuery.active ) { |
| 5151 | + jQuery.event.trigger( "ajaxStop" ); |
| 5152 | + } |
| 5153 | + |
| 5154 | + // close opended socket |
| 5155 | + xhr.abort(); |
| 5156 | + return false; |
| 5157 | + } |
| 5158 | + |
| 5159 | + if ( s.global ) { |
| 5160 | + trigger("ajaxSend", [xhr, s]); |
| 5161 | + } |
| 5162 | + |
| 5163 | + // Wait for a response to come back |
| 5164 | + var onreadystatechange = xhr.onreadystatechange = function( isTimeout ) { |
| 5165 | + // The request was aborted |
| 5166 | + if ( !xhr || xhr.readyState === 0 || isTimeout === "abort" ) { |
| 5167 | + // Opera doesn't call onreadystatechange before this point |
| 5168 | + // so we simulate the call |
| 5169 | + if ( !requestDone ) { |
| 5170 | + complete(); |
| 5171 | + } |
| 5172 | + |
| 5173 | + requestDone = true; |
| 5174 | + if ( xhr ) { |
| 5175 | + xhr.onreadystatechange = jQuery.noop; |
| 5176 | + } |
| 5177 | + |
| 5178 | + // The transfer is complete and the data is available, or the request timed out |
| 5179 | + } else if ( !requestDone && xhr && (xhr.readyState === 4 || isTimeout === "timeout") ) { |
| 5180 | + requestDone = true; |
| 5181 | + xhr.onreadystatechange = jQuery.noop; |
| 5182 | + |
| 5183 | + status = isTimeout === "timeout" ? |
| 5184 | + "timeout" : |
| 5185 | + !jQuery.httpSuccess( xhr ) ? |
| 5186 | + "error" : |
| 5187 | + s.ifModified && jQuery.httpNotModified( xhr, s.url ) ? |
| 5188 | + "notmodified" : |
| 5189 | + "success"; |
| 5190 | + |
| 5191 | + var errMsg; |
| 5192 | + |
| 5193 | + if ( status === "success" ) { |
| 5194 | + // Watch for, and catch, XML document parse errors |
| 5195 | + try { |
| 5196 | + // process the data (runs the xml through httpData regardless of callback) |
| 5197 | + data = jQuery.httpData( xhr, s.dataType, s ); |
| 5198 | + } catch(err) { |
| 5199 | + status = "parsererror"; |
| 5200 | + errMsg = err; |
| 5201 | + } |
| 5202 | + } |
| 5203 | + |
| 5204 | + // Make sure that the request was successful or notmodified |
| 5205 | + if ( status === "success" || status === "notmodified" ) { |
| 5206 | + // JSONP handles its own success callback |
| 5207 | + if ( !jsonp ) { |
| 5208 | + success(); |
| 5209 | + } |
| 5210 | + } else { |
| 5211 | + jQuery.handleError(s, xhr, status, errMsg); |
| 5212 | + } |
| 5213 | + |
| 5214 | + // Fire the complete handlers |
| 5215 | + complete(); |
| 5216 | + |
| 5217 | + if ( isTimeout === "timeout" ) { |
| 5218 | + xhr.abort(); |
| 5219 | + } |
| 5220 | + |
| 5221 | + // Stop memory leaks |
| 5222 | + if ( s.async ) { |
| 5223 | + xhr = null; |
| 5224 | + } |
| 5225 | + } |
| 5226 | + }; |
| 5227 | + |
| 5228 | + // Override the abort handler, if we can (IE doesn't allow it, but that's OK) |
| 5229 | + // Opera doesn't fire onreadystatechange at all on abort |
| 5230 | + try { |
| 5231 | + var oldAbort = xhr.abort; |
| 5232 | + xhr.abort = function() { |
| 5233 | + if ( xhr ) { |
| 5234 | + oldAbort.call( xhr ); |
| 5235 | + } |
| 5236 | + |
| 5237 | + onreadystatechange( "abort" ); |
| 5238 | + }; |
| 5239 | + } catch(e) { } |
| 5240 | + |
| 5241 | + // Timeout checker |
| 5242 | + if ( s.async && s.timeout > 0 ) { |
| 5243 | + setTimeout(function() { |
| 5244 | + // Check to see if the request is still happening |
| 5245 | + if ( xhr && !requestDone ) { |
| 5246 | + onreadystatechange( "timeout" ); |
| 5247 | + } |
| 5248 | + }, s.timeout); |
| 5249 | + } |
| 5250 | + |
| 5251 | + // Send the data |
| 5252 | + try { |
| 5253 | + xhr.send( type === "POST" || type === "PUT" || type === "DELETE" ? s.data : null ); |
| 5254 | + } catch(e) { |
| 5255 | + jQuery.handleError(s, xhr, null, e); |
| 5256 | + // Fire the complete handlers |
| 5257 | + complete(); |
| 5258 | + } |
| 5259 | + |
| 5260 | + // firefox 1.5 doesn't fire statechange for sync requests |
| 5261 | + if ( !s.async ) { |
| 5262 | + onreadystatechange(); |
| 5263 | + } |
| 5264 | + |
| 5265 | + function success() { |
| 5266 | + // If a local callback was specified, fire it and pass it the data |
| 5267 | + if ( s.success ) { |
| 5268 | + s.success.call( callbackContext, data, status, xhr ); |
| 5269 | + } |
| 5270 | + |
| 5271 | + // Fire the global callback |
| 5272 | + if ( s.global ) { |
| 5273 | + trigger( "ajaxSuccess", [xhr, s] ); |
| 5274 | + } |
| 5275 | + } |
| 5276 | + |
| 5277 | + function complete() { |
| 5278 | + // Process result |
| 5279 | + if ( s.complete ) { |
| 5280 | + s.complete.call( callbackContext, xhr, status); |
| 5281 | + } |
| 5282 | + |
| 5283 | + // The request was completed |
| 5284 | + if ( s.global ) { |
| 5285 | + trigger( "ajaxComplete", [xhr, s] ); |
| 5286 | + } |
| 5287 | + |
| 5288 | + // Handle the global AJAX counter |
| 5289 | + if ( s.global && ! --jQuery.active ) { |
| 5290 | + jQuery.event.trigger( "ajaxStop" ); |
| 5291 | + } |
| 5292 | + } |
| 5293 | + |
| 5294 | + function trigger(type, args) { |
| 5295 | + (s.context ? jQuery(s.context) : jQuery.event).trigger(type, args); |
| 5296 | + } |
| 5297 | + |
| 5298 | + // return XMLHttpRequest to allow aborting the request etc. |
| 5299 | + return xhr; |
| 5300 | + }, |
| 5301 | + |
| 5302 | + handleError: function( s, xhr, status, e ) { |
| 5303 | + // If a local callback was specified, fire it |
| 5304 | + if ( s.error ) { |
| 5305 | + s.error.call( s.context || s, xhr, status, e ); |
| 5306 | + } |
| 5307 | + |
| 5308 | + // Fire the global callback |
| 5309 | + if ( s.global ) { |
| 5310 | + (s.context ? jQuery(s.context) : jQuery.event).trigger( "ajaxError", [xhr, s, e] ); |
| 5311 | + } |
| 5312 | + }, |
| 5313 | + |
| 5314 | + // Counter for holding the number of active queries |
| 5315 | + active: 0, |
| 5316 | + |
| 5317 | + // Determines if an XMLHttpRequest was successful or not |
| 5318 | + httpSuccess: function( xhr ) { |
| 5319 | + try { |
| 5320 | + // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450 |
| 5321 | + return !xhr.status && location.protocol === "file:" || |
| 5322 | + // Opera returns 0 when status is 304 |
| 5323 | + ( xhr.status >= 200 && xhr.status < 300 ) || |
| 5324 | + xhr.status === 304 || xhr.status === 1223 || xhr.status === 0; |
| 5325 | + } catch(e) {} |
| 5326 | + |
| 5327 | + return false; |
| 5328 | + }, |
| 5329 | + |
| 5330 | + // Determines if an XMLHttpRequest returns NotModified |
| 5331 | + httpNotModified: function( xhr, url ) { |
| 5332 | + var lastModified = xhr.getResponseHeader("Last-Modified"), |
| 5333 | + etag = xhr.getResponseHeader("Etag"); |
| 5334 | + |
| 5335 | + if ( lastModified ) { |
| 5336 | + jQuery.lastModified[url] = lastModified; |
| 5337 | + } |
| 5338 | + |
| 5339 | + if ( etag ) { |
| 5340 | + jQuery.etag[url] = etag; |
| 5341 | + } |
| 5342 | + |
| 5343 | + // Opera returns 0 when status is 304 |
| 5344 | + return xhr.status === 304 || xhr.status === 0; |
| 5345 | + }, |
| 5346 | + |
| 5347 | + httpData: function( xhr, type, s ) { |
| 5348 | + var ct = xhr.getResponseHeader("content-type") || "", |
| 5349 | + xml = type === "xml" || !type && ct.indexOf("xml") >= 0, |
| 5350 | + data = xml ? xhr.responseXML : xhr.responseText; |
| 5351 | + |
| 5352 | + if ( xml && data.documentElement.nodeName === "parsererror" ) { |
| 5353 | + jQuery.error( "parsererror" ); |
| 5354 | + } |
| 5355 | + |
| 5356 | + // Allow a pre-filtering function to sanitize the response |
| 5357 | + // s is checked to keep backwards compatibility |
| 5358 | + if ( s && s.dataFilter ) { |
| 5359 | + data = s.dataFilter( data, type ); |
| 5360 | + } |
| 5361 | + |
| 5362 | + // The filter can actually parse the response |
| 5363 | + if ( typeof data === "string" ) { |
| 5364 | + // Get the JavaScript object, if JSON is used. |
| 5365 | + if ( type === "json" || !type && ct.indexOf("json") >= 0 ) { |
| 5366 | + data = jQuery.parseJSON( data ); |
| 5367 | + |
| 5368 | + // If the type is "script", eval it in global context |
| 5369 | + } else if ( type === "script" || !type && ct.indexOf("javascript") >= 0 ) { |
| 5370 | + jQuery.globalEval( data ); |
| 5371 | + } |
| 5372 | + } |
| 5373 | + |
| 5374 | + return data; |
| 5375 | + }, |
| 5376 | + |
| 5377 | + // Serialize an array of form elements or a set of |
| 5378 | + // key/values into a query string |
| 5379 | + param: function( a, traditional ) { |
| 5380 | + var s = []; |
| 5381 | + |
| 5382 | + // Set traditional to true for jQuery <= 1.3.2 behavior. |
| 5383 | + if ( traditional === undefined ) { |
| 5384 | + traditional = jQuery.ajaxSettings.traditional; |
| 5385 | + } |
| 5386 | + |
| 5387 | + // If an array was passed in, assume that it is an array of form elements. |
| 5388 | + if ( jQuery.isArray(a) || a.jquery ) { |
| 5389 | + // Serialize the form elements |
| 5390 | + jQuery.each( a, function() { |
| 5391 | + add( this.name, this.value ); |
| 5392 | + }); |
| 5393 | + |
| 5394 | + } else { |
| 5395 | + // If traditional, encode the "old" way (the way 1.3.2 or older |
| 5396 | + // did it), otherwise encode params recursively. |
| 5397 | + for ( var prefix in a ) { |
| 5398 | + buildParams( prefix, a[prefix] ); |
| 5399 | + } |
| 5400 | + } |
| 5401 | + |
| 5402 | + // Return the resulting serialization |
| 5403 | + return s.join("&").replace(r20, "+"); |
| 5404 | + |
| 5405 | + function buildParams( prefix, obj ) { |
| 5406 | + if ( jQuery.isArray(obj) ) { |
| 5407 | + // Serialize array item. |
| 5408 | + jQuery.each( obj, function( i, v ) { |
| 5409 | + if ( traditional || /\[\]$/.test( prefix ) ) { |
| 5410 | + // Treat each array item as a scalar. |
| 5411 | + add( prefix, v ); |
| 5412 | + } else { |
| 5413 | + // If array item is non-scalar (array or object), encode its |
| 5414 | + // numeric index to resolve deserialization ambiguity issues. |
| 5415 | + // Note that rack (as of 1.0.0) can't currently deserialize |
| 5416 | + // nested arrays properly, and attempting to do so may cause |
| 5417 | + // a server error. Possible fixes are to modify rack's |
| 5418 | + // deserialization algorithm or to provide an option or flag |
| 5419 | + // to force array serialization to be shallow. |
| 5420 | + buildParams( prefix + "[" + ( typeof v === "object" || jQuery.isArray(v) ? i : "" ) + "]", v ); |
| 5421 | + } |
| 5422 | + }); |
| 5423 | + |
| 5424 | + } else if ( !traditional && obj != null && typeof obj === "object" ) { |
| 5425 | + // Serialize object item. |
| 5426 | + jQuery.each( obj, function( k, v ) { |
| 5427 | + buildParams( prefix + "[" + k + "]", v ); |
| 5428 | + }); |
| 5429 | + |
| 5430 | + } else { |
| 5431 | + // Serialize scalar item. |
| 5432 | + add( prefix, obj ); |
| 5433 | + } |
| 5434 | + } |
| 5435 | + |
| 5436 | + function add( key, value ) { |
| 5437 | + // If value is a function, invoke it and return its value |
| 5438 | + value = jQuery.isFunction(value) ? value() : value; |
| 5439 | + s[ s.length ] = encodeURIComponent(key) + "=" + encodeURIComponent(value); |
| 5440 | + } |
| 5441 | + } |
| 5442 | +}); |
| 5443 | +var elemdisplay = {}, |
| 5444 | + rfxtypes = /toggle|show|hide/, |
| 5445 | + rfxnum = /^([+-]=)?([\d+-.]+)(.*)$/, |
| 5446 | + timerId, |
| 5447 | + fxAttrs = [ |
| 5448 | + // height animations |
| 5449 | + [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ], |
| 5450 | + // width animations |
| 5451 | + [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ], |
| 5452 | + // opacity animations |
| 5453 | + [ "opacity" ] |
| 5454 | + ]; |
| 5455 | + |
| 5456 | +jQuery.fn.extend({ |
| 5457 | + show: function( speed, callback ) { |
| 5458 | + if ( speed || speed === 0) { |
| 5459 | + return this.animate( genFx("show", 3), speed, callback); |
| 5460 | + |
| 5461 | + } else { |
| 5462 | + for ( var i = 0, l = this.length; i < l; i++ ) { |
| 5463 | + var old = jQuery.data(this[i], "olddisplay"); |
| 5464 | + |
| 5465 | + this[i].style.display = old || ""; |
| 5466 | + |
| 5467 | + if ( jQuery.css(this[i], "display") === "none" ) { |
| 5468 | + var nodeName = this[i].nodeName, display; |
| 5469 | + |
| 5470 | + if ( elemdisplay[ nodeName ] ) { |
| 5471 | + display = elemdisplay[ nodeName ]; |
| 5472 | + |
| 5473 | + } else { |
| 5474 | + var elem = jQuery("<" + nodeName + " />").appendTo("body"); |
| 5475 | + |
| 5476 | + display = elem.css("display"); |
| 5477 | + |
| 5478 | + if ( display === "none" ) { |
| 5479 | + display = "block"; |
| 5480 | + } |
| 5481 | + |
| 5482 | + elem.remove(); |
| 5483 | + |
| 5484 | + elemdisplay[ nodeName ] = display; |
| 5485 | + } |
| 5486 | + |
| 5487 | + jQuery.data(this[i], "olddisplay", display); |
| 5488 | + } |
| 5489 | + } |
| 5490 | + |
| 5491 | + // Set the display of the elements in a second loop |
| 5492 | + // to avoid the constant reflow |
| 5493 | + for ( var j = 0, k = this.length; j < k; j++ ) { |
| 5494 | + this[j].style.display = jQuery.data(this[j], "olddisplay") || ""; |
| 5495 | + } |
| 5496 | + |
| 5497 | + return this; |
| 5498 | + } |
| 5499 | + }, |
| 5500 | + |
| 5501 | + hide: function( speed, callback ) { |
| 5502 | + if ( speed || speed === 0 ) { |
| 5503 | + return this.animate( genFx("hide", 3), speed, callback); |
| 5504 | + |
| 5505 | + } else { |
| 5506 | + for ( var i = 0, l = this.length; i < l; i++ ) { |
| 5507 | + var old = jQuery.data(this[i], "olddisplay"); |
| 5508 | + if ( !old && old !== "none" ) { |
| 5509 | + jQuery.data(this[i], "olddisplay", jQuery.css(this[i], "display")); |
| 5510 | + } |
| 5511 | + } |
| 5512 | + |
| 5513 | + // Set the display of the elements in a second loop |
| 5514 | + // to avoid the constant reflow |
| 5515 | + for ( var j = 0, k = this.length; j < k; j++ ) { |
| 5516 | + this[j].style.display = "none"; |
| 5517 | + } |
| 5518 | + |
| 5519 | + return this; |
| 5520 | + } |
| 5521 | + }, |
| 5522 | + |
| 5523 | + // Save the old toggle function |
| 5524 | + _toggle: jQuery.fn.toggle, |
| 5525 | + |
| 5526 | + toggle: function( fn, fn2 ) { |
| 5527 | + var bool = typeof fn === "boolean"; |
| 5528 | + |
| 5529 | + if ( jQuery.isFunction(fn) && jQuery.isFunction(fn2) ) { |
| 5530 | + this._toggle.apply( this, arguments ); |
| 5531 | + |
| 5532 | + } else if ( fn == null || bool ) { |
| 5533 | + this.each(function() { |
| 5534 | + var state = bool ? fn : jQuery(this).is(":hidden"); |
| 5535 | + jQuery(this)[ state ? "show" : "hide" ](); |
| 5536 | + }); |
| 5537 | + |
| 5538 | + } else { |
| 5539 | + this.animate(genFx("toggle", 3), fn, fn2); |
| 5540 | + } |
| 5541 | + |
| 5542 | + return this; |
| 5543 | + }, |
| 5544 | + |
| 5545 | + fadeTo: function( speed, to, callback ) { |
| 5546 | + return this.filter(":hidden").css("opacity", 0).show().end() |
| 5547 | + .animate({opacity: to}, speed, callback); |
| 5548 | + }, |
| 5549 | + |
| 5550 | + animate: function( prop, speed, easing, callback ) { |
| 5551 | + var optall = jQuery.speed(speed, easing, callback); |
| 5552 | + |
| 5553 | + if ( jQuery.isEmptyObject( prop ) ) { |
| 5554 | + return this.each( optall.complete ); |
| 5555 | + } |
| 5556 | + |
| 5557 | + return this[ optall.queue === false ? "each" : "queue" ](function() { |
| 5558 | + var opt = jQuery.extend({}, optall), p, |
| 5559 | + hidden = this.nodeType === 1 && jQuery(this).is(":hidden"), |
| 5560 | + self = this; |
| 5561 | + |
| 5562 | + for ( p in prop ) { |
| 5563 | + var name = p.replace(rdashAlpha, fcamelCase); |
| 5564 | + |
| 5565 | + if ( p !== name ) { |
| 5566 | + prop[ name ] = prop[ p ]; |
| 5567 | + delete prop[ p ]; |
| 5568 | + p = name; |
| 5569 | + } |
| 5570 | + |
| 5571 | + if ( prop[p] === "hide" && hidden || prop[p] === "show" && !hidden ) { |
| 5572 | + return opt.complete.call(this); |
| 5573 | + } |
| 5574 | + |
| 5575 | + if ( ( p === "height" || p === "width" ) && this.style ) { |
| 5576 | + // Store display property |
| 5577 | + opt.display = jQuery.css(this, "display"); |
| 5578 | + |
| 5579 | + // Make sure that nothing sneaks out |
| 5580 | + opt.overflow = this.style.overflow; |
| 5581 | + } |
| 5582 | + |
| 5583 | + if ( jQuery.isArray( prop[p] ) ) { |
| 5584 | + // Create (if needed) and add to specialEasing |
| 5585 | + (opt.specialEasing = opt.specialEasing || {})[p] = prop[p][1]; |
| 5586 | + prop[p] = prop[p][0]; |
| 5587 | + } |
| 5588 | + } |
| 5589 | + |
| 5590 | + if ( opt.overflow != null ) { |
| 5591 | + this.style.overflow = "hidden"; |
| 5592 | + } |
| 5593 | + |
| 5594 | + opt.curAnim = jQuery.extend({}, prop); |
| 5595 | + |
| 5596 | + jQuery.each( prop, function( name, val ) { |
| 5597 | + var e = new jQuery.fx( self, opt, name ); |
| 5598 | + |
| 5599 | + if ( rfxtypes.test(val) ) { |
| 5600 | + e[ val === "toggle" ? hidden ? "show" : "hide" : val ]( prop ); |
| 5601 | + |
| 5602 | + } else { |
| 5603 | + var parts = rfxnum.exec(val), |
| 5604 | + start = e.cur(true) || 0; |
| 5605 | + |
| 5606 | + if ( parts ) { |
| 5607 | + var end = parseFloat( parts[2] ), |
| 5608 | + unit = parts[3] || "px"; |
| 5609 | + |
| 5610 | + // We need to compute starting value |
| 5611 | + if ( unit !== "px" ) { |
| 5612 | + self.style[ name ] = (end || 1) + unit; |
| 5613 | + start = ((end || 1) / e.cur(true)) * start; |
| 5614 | + self.style[ name ] = start + unit; |
| 5615 | + } |
| 5616 | + |
| 5617 | + // If a +=/-= token was provided, we're doing a relative animation |
| 5618 | + if ( parts[1] ) { |
| 5619 | + end = ((parts[1] === "-=" ? -1 : 1) * end) + start; |
| 5620 | + } |
| 5621 | + |
| 5622 | + e.custom( start, end, unit ); |
| 5623 | + |
| 5624 | + } else { |
| 5625 | + e.custom( start, val, "" ); |
| 5626 | + } |
| 5627 | + } |
| 5628 | + }); |
| 5629 | + |
| 5630 | + // For JS strict compliance |
| 5631 | + return true; |
| 5632 | + }); |
| 5633 | + }, |
| 5634 | + |
| 5635 | + stop: function( clearQueue, gotoEnd ) { |
| 5636 | + var timers = jQuery.timers; |
| 5637 | + |
| 5638 | + if ( clearQueue ) { |
| 5639 | + this.queue([]); |
| 5640 | + } |
| 5641 | + |
| 5642 | + this.each(function() { |
| 5643 | + // go in reverse order so anything added to the queue during the loop is ignored |
| 5644 | + for ( var i = timers.length - 1; i >= 0; i-- ) { |
| 5645 | + if ( timers[i].elem === this ) { |
| 5646 | + if (gotoEnd) { |
| 5647 | + // force the next step to be the last |
| 5648 | + timers[i](true); |
| 5649 | + } |
| 5650 | + |
| 5651 | + timers.splice(i, 1); |
| 5652 | + } |
| 5653 | + } |
| 5654 | + }); |
| 5655 | + |
| 5656 | + // start the next in the queue if the last step wasn't forced |
| 5657 | + if ( !gotoEnd ) { |
| 5658 | + this.dequeue(); |
| 5659 | + } |
| 5660 | + |
| 5661 | + return this; |
| 5662 | + } |
| 5663 | + |
| 5664 | +}); |
| 5665 | + |
| 5666 | +// Generate shortcuts for custom animations |
| 5667 | +jQuery.each({ |
| 5668 | + slideDown: genFx("show", 1), |
| 5669 | + slideUp: genFx("hide", 1), |
| 5670 | + slideToggle: genFx("toggle", 1), |
| 5671 | + fadeIn: { opacity: "show" }, |
| 5672 | + fadeOut: { opacity: "hide" } |
| 5673 | +}, function( name, props ) { |
| 5674 | + jQuery.fn[ name ] = function( speed, callback ) { |
| 5675 | + return this.animate( props, speed, callback ); |
| 5676 | + }; |
| 5677 | +}); |
| 5678 | + |
| 5679 | +jQuery.extend({ |
| 5680 | + speed: function( speed, easing, fn ) { |
| 5681 | + var opt = speed && typeof speed === "object" ? speed : { |
| 5682 | + complete: fn || !fn && easing || |
| 5683 | + jQuery.isFunction( speed ) && speed, |
| 5684 | + duration: speed, |
| 5685 | + easing: fn && easing || easing && !jQuery.isFunction(easing) && easing |
| 5686 | + }; |
| 5687 | + |
| 5688 | + opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration : |
| 5689 | + jQuery.fx.speeds[opt.duration] || jQuery.fx.speeds._default; |
| 5690 | + |
| 5691 | + // Queueing |
| 5692 | + opt.old = opt.complete; |
| 5693 | + opt.complete = function() { |
| 5694 | + if ( opt.queue !== false ) { |
| 5695 | + jQuery(this).dequeue(); |
| 5696 | + } |
| 5697 | + if ( jQuery.isFunction( opt.old ) ) { |
| 5698 | + opt.old.call( this ); |
| 5699 | + } |
| 5700 | + }; |
| 5701 | + |
| 5702 | + return opt; |
| 5703 | + }, |
| 5704 | + |
| 5705 | + easing: { |
| 5706 | + linear: function( p, n, firstNum, diff ) { |
| 5707 | + return firstNum + diff * p; |
| 5708 | + }, |
| 5709 | + swing: function( p, n, firstNum, diff ) { |
| 5710 | + return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum; |
| 5711 | + } |
| 5712 | + }, |
| 5713 | + |
| 5714 | + timers: [], |
| 5715 | + |
| 5716 | + fx: function( elem, options, prop ) { |
| 5717 | + this.options = options; |
| 5718 | + this.elem = elem; |
| 5719 | + this.prop = prop; |
| 5720 | + |
| 5721 | + if ( !options.orig ) { |
| 5722 | + options.orig = {}; |
| 5723 | + } |
| 5724 | + } |
| 5725 | + |
| 5726 | +}); |
| 5727 | + |
| 5728 | +jQuery.fx.prototype = { |
| 5729 | + // Simple function for setting a style value |
| 5730 | + update: function() { |
| 5731 | + if ( this.options.step ) { |
| 5732 | + this.options.step.call( this.elem, this.now, this ); |
| 5733 | + } |
| 5734 | + |
| 5735 | + (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this ); |
| 5736 | + |
| 5737 | + // Set display property to block for height/width animations |
| 5738 | + if ( ( this.prop === "height" || this.prop === "width" ) && this.elem.style ) { |
| 5739 | + this.elem.style.display = "block"; |
| 5740 | + } |
| 5741 | + }, |
| 5742 | + |
| 5743 | + // Get the current size |
| 5744 | + cur: function( force ) { |
| 5745 | + if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) { |
| 5746 | + return this.elem[ this.prop ]; |
| 5747 | + } |
| 5748 | + |
| 5749 | + var r = parseFloat(jQuery.css(this.elem, this.prop, force)); |
| 5750 | + return r && r > -10000 ? r : parseFloat(jQuery.curCSS(this.elem, this.prop)) || 0; |
| 5751 | + }, |
| 5752 | + |
| 5753 | + // Start an animation from one number to another |
| 5754 | + custom: function( from, to, unit ) { |
| 5755 | + this.startTime = now(); |
| 5756 | + this.start = from; |
| 5757 | + this.end = to; |
| 5758 | + this.unit = unit || this.unit || "px"; |
| 5759 | + this.now = this.start; |
| 5760 | + this.pos = this.state = 0; |
| 5761 | + |
| 5762 | + var self = this; |
| 5763 | + function t( gotoEnd ) { |
| 5764 | + return self.step(gotoEnd); |
| 5765 | + } |
| 5766 | + |
| 5767 | + t.elem = this.elem; |
| 5768 | + |
| 5769 | + if ( t() && jQuery.timers.push(t) && !timerId ) { |
| 5770 | + timerId = setInterval(jQuery.fx.tick, 13); |
| 5771 | + } |
| 5772 | + }, |
| 5773 | + |
| 5774 | + // Simple 'show' function |
| 5775 | + show: function() { |
| 5776 | + // Remember where we started, so that we can go back to it later |
| 5777 | + this.options.orig[this.prop] = jQuery.style( this.elem, this.prop ); |
| 5778 | + this.options.show = true; |
| 5779 | + |
| 5780 | + // Begin the animation |
| 5781 | + // Make sure that we start at a small width/height to avoid any |
| 5782 | + // flash of content |
| 5783 | + this.custom(this.prop === "width" || this.prop === "height" ? 1 : 0, this.cur()); |
| 5784 | + |
| 5785 | + // Start by showing the element |
| 5786 | + jQuery( this.elem ).show(); |
| 5787 | + }, |
| 5788 | + |
| 5789 | + // Simple 'hide' function |
| 5790 | + hide: function() { |
| 5791 | + // Remember where we started, so that we can go back to it later |
| 5792 | + this.options.orig[this.prop] = jQuery.style( this.elem, this.prop ); |
| 5793 | + this.options.hide = true; |
| 5794 | + |
| 5795 | + // Begin the animation |
| 5796 | + this.custom(this.cur(), 0); |
| 5797 | + }, |
| 5798 | + |
| 5799 | + // Each step of an animation |
| 5800 | + step: function( gotoEnd ) { |
| 5801 | + var t = now(), done = true; |
| 5802 | + |
| 5803 | + if ( gotoEnd || t >= this.options.duration + this.startTime ) { |
| 5804 | + this.now = this.end; |
| 5805 | + this.pos = this.state = 1; |
| 5806 | + this.update(); |
| 5807 | + |
| 5808 | + this.options.curAnim[ this.prop ] = true; |
| 5809 | + |
| 5810 | + for ( var i in this.options.curAnim ) { |
| 5811 | + if ( this.options.curAnim[i] !== true ) { |
| 5812 | + done = false; |
| 5813 | + } |
| 5814 | + } |
| 5815 | + |
| 5816 | + if ( done ) { |
| 5817 | + if ( this.options.display != null ) { |
| 5818 | + // Reset the overflow |
| 5819 | + this.elem.style.overflow = this.options.overflow; |
| 5820 | + |
| 5821 | + // Reset the display |
| 5822 | + var old = jQuery.data(this.elem, "olddisplay"); |
| 5823 | + this.elem.style.display = old ? old : this.options.display; |
| 5824 | + |
| 5825 | + if ( jQuery.css(this.elem, "display") === "none" ) { |
| 5826 | + this.elem.style.display = "block"; |
| 5827 | + } |
| 5828 | + } |
| 5829 | + |
| 5830 | + // Hide the element if the "hide" operation was done |
| 5831 | + if ( this.options.hide ) { |
| 5832 | + jQuery(this.elem).hide(); |
| 5833 | + } |
| 5834 | + |
| 5835 | + // Reset the properties, if the item has been hidden or shown |
| 5836 | + if ( this.options.hide || this.options.show ) { |
| 5837 | + for ( var p in this.options.curAnim ) { |
| 5838 | + jQuery.style(this.elem, p, this.options.orig[p]); |
| 5839 | + } |
| 5840 | + } |
| 5841 | + |
| 5842 | + // Execute the complete function |
| 5843 | + this.options.complete.call( this.elem ); |
| 5844 | + } |
| 5845 | + |
| 5846 | + return false; |
| 5847 | + |
| 5848 | + } else { |
| 5849 | + var n = t - this.startTime; |
| 5850 | + this.state = n / this.options.duration; |
| 5851 | + |
| 5852 | + // Perform the easing function, defaults to swing |
| 5853 | + var specialEasing = this.options.specialEasing && this.options.specialEasing[this.prop]; |
| 5854 | + var defaultEasing = this.options.easing || (jQuery.easing.swing ? "swing" : "linear"); |
| 5855 | + this.pos = jQuery.easing[specialEasing || defaultEasing](this.state, n, 0, 1, this.options.duration); |
| 5856 | + this.now = this.start + ((this.end - this.start) * this.pos); |
| 5857 | + |
| 5858 | + // Perform the next step of the animation |
| 5859 | + this.update(); |
| 5860 | + } |
| 5861 | + |
| 5862 | + return true; |
| 5863 | + } |
| 5864 | +}; |
| 5865 | + |
| 5866 | +jQuery.extend( jQuery.fx, { |
| 5867 | + tick: function() { |
| 5868 | + var timers = jQuery.timers; |
| 5869 | + |
| 5870 | + for ( var i = 0; i < timers.length; i++ ) { |
| 5871 | + if ( !timers[i]() ) { |
| 5872 | + timers.splice(i--, 1); |
| 5873 | + } |
| 5874 | + } |
| 5875 | + |
| 5876 | + if ( !timers.length ) { |
| 5877 | + jQuery.fx.stop(); |
| 5878 | + } |
| 5879 | + }, |
| 5880 | + |
| 5881 | + stop: function() { |
| 5882 | + clearInterval( timerId ); |
| 5883 | + timerId = null; |
| 5884 | + }, |
| 5885 | + |
| 5886 | + speeds: { |
| 5887 | + slow: 600, |
| 5888 | + fast: 200, |
| 5889 | + // Default speed |
| 5890 | + _default: 400 |
| 5891 | + }, |
| 5892 | + |
| 5893 | + step: { |
| 5894 | + opacity: function( fx ) { |
| 5895 | + jQuery.style(fx.elem, "opacity", fx.now); |
| 5896 | + }, |
| 5897 | + |
| 5898 | + _default: function( fx ) { |
| 5899 | + if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) { |
| 5900 | + fx.elem.style[ fx.prop ] = (fx.prop === "width" || fx.prop === "height" ? Math.max(0, fx.now) : fx.now) + fx.unit; |
| 5901 | + } else { |
| 5902 | + fx.elem[ fx.prop ] = fx.now; |
| 5903 | + } |
| 5904 | + } |
| 5905 | + } |
| 5906 | +}); |
| 5907 | + |
| 5908 | +if ( jQuery.expr && jQuery.expr.filters ) { |
| 5909 | + jQuery.expr.filters.animated = function( elem ) { |
| 5910 | + return jQuery.grep(jQuery.timers, function( fn ) { |
| 5911 | + return elem === fn.elem; |
| 5912 | + }).length; |
| 5913 | + }; |
| 5914 | +} |
| 5915 | + |
| 5916 | +function genFx( type, num ) { |
| 5917 | + var obj = {}; |
| 5918 | + |
| 5919 | + jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function() { |
| 5920 | + obj[ this ] = type; |
| 5921 | + }); |
| 5922 | + |
| 5923 | + return obj; |
| 5924 | +} |
| 5925 | +if ( "getBoundingClientRect" in document.documentElement ) { |
| 5926 | + jQuery.fn.offset = function( options ) { |
| 5927 | + var elem = this[0]; |
| 5928 | + |
| 5929 | + if ( options ) { |
| 5930 | + return this.each(function( i ) { |
| 5931 | + jQuery.offset.setOffset( this, options, i ); |
| 5932 | + }); |
| 5933 | + } |
| 5934 | + |
| 5935 | + if ( !elem || !elem.ownerDocument ) { |
| 5936 | + return null; |
| 5937 | + } |
| 5938 | + |
| 5939 | + if ( elem === elem.ownerDocument.body ) { |
| 5940 | + return jQuery.offset.bodyOffset( elem ); |
| 5941 | + } |
| 5942 | + |
| 5943 | + var box = elem.getBoundingClientRect(), doc = elem.ownerDocument, body = doc.body, docElem = doc.documentElement, |
| 5944 | + clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0, |
| 5945 | + top = box.top + (self.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop ) - clientTop, |
| 5946 | + left = box.left + (self.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft) - clientLeft; |
| 5947 | + |
| 5948 | + return { top: top, left: left }; |
| 5949 | + }; |
| 5950 | + |
| 5951 | +} else { |
| 5952 | + jQuery.fn.offset = function( options ) { |
| 5953 | + var elem = this[0]; |
| 5954 | + |
| 5955 | + if ( options ) { |
| 5956 | + return this.each(function( i ) { |
| 5957 | + jQuery.offset.setOffset( this, options, i ); |
| 5958 | + }); |
| 5959 | + } |
| 5960 | + |
| 5961 | + if ( !elem || !elem.ownerDocument ) { |
| 5962 | + return null; |
| 5963 | + } |
| 5964 | + |
| 5965 | + if ( elem === elem.ownerDocument.body ) { |
| 5966 | + return jQuery.offset.bodyOffset( elem ); |
| 5967 | + } |
| 5968 | + |
| 5969 | + jQuery.offset.initialize(); |
| 5970 | + |
| 5971 | + var offsetParent = elem.offsetParent, prevOffsetParent = elem, |
| 5972 | + doc = elem.ownerDocument, computedStyle, docElem = doc.documentElement, |
| 5973 | + body = doc.body, defaultView = doc.defaultView, |
| 5974 | + prevComputedStyle = defaultView ? defaultView.getComputedStyle( elem, null ) : elem.currentStyle, |
| 5975 | + top = elem.offsetTop, left = elem.offsetLeft; |
| 5976 | + |
| 5977 | + while ( (elem = elem.parentNode) && elem !== body && elem !== docElem ) { |
| 5978 | + if ( jQuery.offset.supportsFixedPosition && prevComputedStyle.position === "fixed" ) { |
| 5979 | + break; |
| 5980 | + } |
| 5981 | + |
| 5982 | + computedStyle = defaultView ? defaultView.getComputedStyle(elem, null) : elem.currentStyle; |
| 5983 | + top -= elem.scrollTop; |
| 5984 | + left -= elem.scrollLeft; |
| 5985 | + |
| 5986 | + if ( elem === offsetParent ) { |
| 5987 | + top += elem.offsetTop; |
| 5988 | + left += elem.offsetLeft; |
| 5989 | + |
| 5990 | + if ( jQuery.offset.doesNotAddBorder && !(jQuery.offset.doesAddBorderForTableAndCells && /^t(able|d|h)$/i.test(elem.nodeName)) ) { |
| 5991 | + top += parseFloat( computedStyle.borderTopWidth ) || 0; |
| 5992 | + left += parseFloat( computedStyle.borderLeftWidth ) || 0; |
| 5993 | + } |
| 5994 | + |
| 5995 | + prevOffsetParent = offsetParent, offsetParent = elem.offsetParent; |
| 5996 | + } |
| 5997 | + |
| 5998 | + if ( jQuery.offset.subtractsBorderForOverflowNotVisible && computedStyle.overflow !== "visible" ) { |
| 5999 | + top += parseFloat( computedStyle.borderTopWidth ) || 0; |
| 6000 | + left += parseFloat( computedStyle.borderLeftWidth ) || 0; |
| 6001 | + } |
| 6002 | + |
| 6003 | + prevComputedStyle = computedStyle; |
| 6004 | + } |
| 6005 | + |
| 6006 | + if ( prevComputedStyle.position === "relative" || prevComputedStyle.position === "static" ) { |
| 6007 | + top += body.offsetTop; |
| 6008 | + left += body.offsetLeft; |
| 6009 | + } |
| 6010 | + |
| 6011 | + if ( jQuery.offset.supportsFixedPosition && prevComputedStyle.position === "fixed" ) { |
| 6012 | + top += Math.max( docElem.scrollTop, body.scrollTop ); |
| 6013 | + left += Math.max( docElem.scrollLeft, body.scrollLeft ); |
| 6014 | + } |
| 6015 | + |
| 6016 | + return { top: top, left: left }; |
| 6017 | + }; |
| 6018 | +} |
| 6019 | + |
| 6020 | +jQuery.offset = { |
| 6021 | + initialize: function() { |
| 6022 | + var body = document.body, container = document.createElement("div"), innerDiv, checkDiv, table, td, bodyMarginTop = parseFloat( jQuery.curCSS(body, "marginTop", true) ) || 0, |
| 6023 | + html = "<div style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;'><div></div></div><table style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;' cellpadding='0' cellspacing='0'><tr><td></td></tr></table>"; |
| 6024 | + |
| 6025 | + jQuery.extend( container.style, { position: "absolute", top: 0, left: 0, margin: 0, border: 0, width: "1px", height: "1px", visibility: "hidden" } ); |
| 6026 | + |
| 6027 | + container.innerHTML = html; |
| 6028 | + body.insertBefore( container, body.firstChild ); |
| 6029 | + innerDiv = container.firstChild; |
| 6030 | + checkDiv = innerDiv.firstChild; |
| 6031 | + td = innerDiv.nextSibling.firstChild.firstChild; |
| 6032 | + |
| 6033 | + this.doesNotAddBorder = (checkDiv.offsetTop !== 5); |
| 6034 | + this.doesAddBorderForTableAndCells = (td.offsetTop === 5); |
| 6035 | + |
| 6036 | + checkDiv.style.position = "fixed", checkDiv.style.top = "20px"; |
| 6037 | + // safari subtracts parent border width here which is 5px |
| 6038 | + this.supportsFixedPosition = (checkDiv.offsetTop === 20 || checkDiv.offsetTop === 15); |
| 6039 | + checkDiv.style.position = checkDiv.style.top = ""; |
| 6040 | + |
| 6041 | + innerDiv.style.overflow = "hidden", innerDiv.style.position = "relative"; |
| 6042 | + this.subtractsBorderForOverflowNotVisible = (checkDiv.offsetTop === -5); |
| 6043 | + |
| 6044 | + this.doesNotIncludeMarginInBodyOffset = (body.offsetTop !== bodyMarginTop); |
| 6045 | + |
| 6046 | + body.removeChild( container ); |
| 6047 | + body = container = innerDiv = checkDiv = table = td = null; |
| 6048 | + jQuery.offset.initialize = jQuery.noop; |
| 6049 | + }, |
| 6050 | + |
| 6051 | + bodyOffset: function( body ) { |
| 6052 | + var top = body.offsetTop, left = body.offsetLeft; |
| 6053 | + |
| 6054 | + jQuery.offset.initialize(); |
| 6055 | + |
| 6056 | + if ( jQuery.offset.doesNotIncludeMarginInBodyOffset ) { |
| 6057 | + top += parseFloat( jQuery.curCSS(body, "marginTop", true) ) || 0; |
| 6058 | + left += parseFloat( jQuery.curCSS(body, "marginLeft", true) ) || 0; |
| 6059 | + } |
| 6060 | + |
| 6061 | + return { top: top, left: left }; |
| 6062 | + }, |
| 6063 | + |
| 6064 | + setOffset: function( elem, options, i ) { |
| 6065 | + // set position first, in-case top/left are set even on static elem |
| 6066 | + if ( /static/.test( jQuery.curCSS( elem, "position" ) ) ) { |
| 6067 | + elem.style.position = "relative"; |
| 6068 | + } |
| 6069 | + var curElem = jQuery( elem ), |
| 6070 | + curOffset = curElem.offset(), |
| 6071 | + curTop = parseInt( jQuery.curCSS( elem, "top", true ), 10 ) || 0, |
| 6072 | + curLeft = parseInt( jQuery.curCSS( elem, "left", true ), 10 ) || 0; |
| 6073 | + |
| 6074 | + if ( jQuery.isFunction( options ) ) { |
| 6075 | + options = options.call( elem, i, curOffset ); |
| 6076 | + } |
| 6077 | + |
| 6078 | + var props = { |
| 6079 | + top: (options.top - curOffset.top) + curTop, |
| 6080 | + left: (options.left - curOffset.left) + curLeft |
| 6081 | + }; |
| 6082 | + |
| 6083 | + if ( "using" in options ) { |
| 6084 | + options.using.call( elem, props ); |
| 6085 | + } else { |
| 6086 | + curElem.css( props ); |
| 6087 | + } |
| 6088 | + } |
| 6089 | +}; |
| 6090 | + |
| 6091 | + |
| 6092 | +jQuery.fn.extend({ |
| 6093 | + position: function() { |
| 6094 | + if ( !this[0] ) { |
| 6095 | + return null; |
| 6096 | + } |
| 6097 | + |
| 6098 | + var elem = this[0], |
| 6099 | + |
| 6100 | + // Get *real* offsetParent |
| 6101 | + offsetParent = this.offsetParent(), |
| 6102 | + |
| 6103 | + // Get correct offsets |
| 6104 | + offset = this.offset(), |
| 6105 | + parentOffset = /^body|html$/i.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset(); |
| 6106 | + |
| 6107 | + // Subtract element margins |
| 6108 | + // note: when an element has margin: auto the offsetLeft and marginLeft |
| 6109 | + // are the same in Safari causing offset.left to incorrectly be 0 |
| 6110 | + offset.top -= parseFloat( jQuery.curCSS(elem, "marginTop", true) ) || 0; |
| 6111 | + offset.left -= parseFloat( jQuery.curCSS(elem, "marginLeft", true) ) || 0; |
| 6112 | + |
| 6113 | + // Add offsetParent borders |
| 6114 | + parentOffset.top += parseFloat( jQuery.curCSS(offsetParent[0], "borderTopWidth", true) ) || 0; |
| 6115 | + parentOffset.left += parseFloat( jQuery.curCSS(offsetParent[0], "borderLeftWidth", true) ) || 0; |
| 6116 | + |
| 6117 | + // Subtract the two offsets |
| 6118 | + return { |
| 6119 | + top: offset.top - parentOffset.top, |
| 6120 | + left: offset.left - parentOffset.left |
| 6121 | + }; |
| 6122 | + }, |
| 6123 | + |
| 6124 | + offsetParent: function() { |
| 6125 | + return this.map(function() { |
| 6126 | + var offsetParent = this.offsetParent || document.body; |
| 6127 | + while ( offsetParent && (!/^body|html$/i.test(offsetParent.nodeName) && jQuery.css(offsetParent, "position") === "static") ) { |
| 6128 | + offsetParent = offsetParent.offsetParent; |
| 6129 | + } |
| 6130 | + return offsetParent; |
| 6131 | + }); |
| 6132 | + } |
| 6133 | +}); |
| 6134 | + |
| 6135 | + |
| 6136 | +// Create scrollLeft and scrollTop methods |
| 6137 | +jQuery.each( ["Left", "Top"], function( i, name ) { |
| 6138 | + var method = "scroll" + name; |
| 6139 | + |
| 6140 | + jQuery.fn[ method ] = function(val) { |
| 6141 | + var elem = this[0], win; |
| 6142 | + |
| 6143 | + if ( !elem ) { |
| 6144 | + return null; |
| 6145 | + } |
| 6146 | + |
| 6147 | + if ( val !== undefined ) { |
| 6148 | + // Set the scroll offset |
| 6149 | + return this.each(function() { |
| 6150 | + win = getWindow( this ); |
| 6151 | + |
| 6152 | + if ( win ) { |
| 6153 | + win.scrollTo( |
| 6154 | + !i ? val : jQuery(win).scrollLeft(), |
| 6155 | + i ? val : jQuery(win).scrollTop() |
| 6156 | + ); |
| 6157 | + |
| 6158 | + } else { |
| 6159 | + this[ method ] = val; |
| 6160 | + } |
| 6161 | + }); |
| 6162 | + } else { |
| 6163 | + win = getWindow( elem ); |
| 6164 | + |
| 6165 | + // Return the scroll offset |
| 6166 | + return win ? ("pageXOffset" in win) ? win[ i ? "pageYOffset" : "pageXOffset" ] : |
| 6167 | + jQuery.support.boxModel && win.document.documentElement[ method ] || |
| 6168 | + win.document.body[ method ] : |
| 6169 | + elem[ method ]; |
| 6170 | + } |
| 6171 | + }; |
| 6172 | +}); |
| 6173 | + |
| 6174 | +function getWindow( elem ) { |
| 6175 | + return ("scrollTo" in elem && elem.document) ? |
| 6176 | + elem : |
| 6177 | + elem.nodeType === 9 ? |
| 6178 | + elem.defaultView || elem.parentWindow : |
| 6179 | + false; |
| 6180 | +} |
| 6181 | +// Create innerHeight, innerWidth, outerHeight and outerWidth methods |
| 6182 | +jQuery.each([ "Height", "Width" ], function( i, name ) { |
| 6183 | + |
| 6184 | + var type = name.toLowerCase(); |
| 6185 | + |
| 6186 | + // innerHeight and innerWidth |
| 6187 | + jQuery.fn["inner" + name] = function() { |
| 6188 | + return this[0] ? |
| 6189 | + jQuery.css( this[0], type, false, "padding" ) : |
| 6190 | + null; |
| 6191 | + }; |
| 6192 | + |
| 6193 | + // outerHeight and outerWidth |
| 6194 | + jQuery.fn["outer" + name] = function( margin ) { |
| 6195 | + return this[0] ? |
| 6196 | + jQuery.css( this[0], type, false, margin ? "margin" : "border" ) : |
| 6197 | + null; |
| 6198 | + }; |
| 6199 | + |
| 6200 | + jQuery.fn[ type ] = function( size ) { |
| 6201 | + // Get window width or height |
| 6202 | + var elem = this[0]; |
| 6203 | + if ( !elem ) { |
| 6204 | + return size == null ? null : this; |
| 6205 | + } |
| 6206 | + |
| 6207 | + if ( jQuery.isFunction( size ) ) { |
| 6208 | + return this.each(function( i ) { |
| 6209 | + var self = jQuery( this ); |
| 6210 | + self[ type ]( size.call( this, i, self[ type ]() ) ); |
| 6211 | + }); |
| 6212 | + } |
| 6213 | + |
| 6214 | + return ("scrollTo" in elem && elem.document) ? // does it walk and quack like a window? |
| 6215 | + // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode |
| 6216 | + elem.document.compatMode === "CSS1Compat" && elem.document.documentElement[ "client" + name ] || |
| 6217 | + elem.document.body[ "client" + name ] : |
| 6218 | + |
| 6219 | + // Get document width or height |
| 6220 | + (elem.nodeType === 9) ? // is it a document |
| 6221 | + // Either scroll[Width/Height] or offset[Width/Height], whichever is greater |
| 6222 | + Math.max( |
| 6223 | + elem.documentElement["client" + name], |
| 6224 | + elem.body["scroll" + name], elem.documentElement["scroll" + name], |
| 6225 | + elem.body["offset" + name], elem.documentElement["offset" + name] |
| 6226 | + ) : |
| 6227 | + |
| 6228 | + // Get or set width or height on the element |
| 6229 | + size === undefined ? |
| 6230 | + // Get width or height on the element |
| 6231 | + jQuery.css( elem, type ) : |
| 6232 | + |
| 6233 | + // Set the width or height on the element (default to pixels if value is unitless) |
| 6234 | + this.css( type, typeof size === "string" ? size : size + "px" ); |
| 6235 | + }; |
| 6236 | + |
| 6237 | +}); |
| 6238 | +// Expose jQuery to the global object |
| 6239 | +window.jQuery = window.$ = jQuery; |
| 6240 | + |
| 6241 | +})(window); |
Property changes on: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/lib/jquery-1.4.2.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 6242 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/demo.html |
— | — | @@ -0,0 +1,220 @@ |
| 2 | +<!DOCTYPE html> |
| 3 | +<html> |
| 4 | +<head> |
| 5 | + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 6 | + <title>MockJax Demo</title> |
| 7 | + <style type="text/css"> |
| 8 | + body { |
| 9 | + font-family: sans-serif; |
| 10 | + } |
| 11 | + dl dt { |
| 12 | + margin: 0; |
| 13 | + font-weight: bold; |
| 14 | + } |
| 15 | + dl dd { |
| 16 | + margin: 0 0 0.5em 0; |
| 17 | + } |
| 18 | + pre { |
| 19 | + padding: 1em; |
| 20 | + display: block; |
| 21 | + background: #EFEFEF; |
| 22 | + border: 1px dashed #656565; |
| 23 | + margin: 0 0 1em 0; |
| 24 | + } |
| 25 | + span.title { |
| 26 | + display: block; |
| 27 | + margin-top: 1em; |
| 28 | + font-size: 0.8em; |
| 29 | + } |
| 30 | + </style> |
| 31 | + <script src="lib/jquery-1.4.2.js"></script> |
| 32 | + <script src="lib/jquery.xmldom.js"></script> |
| 33 | + <script src="lib/json2.js"></script> |
| 34 | + <script src="jquery.mockjax.js"></script> |
| 35 | + <script type="text/javascript"> |
| 36 | + $('body').delegate('input', 'click', function() { |
| 37 | + var fn = $(this).attr('id'); |
| 38 | + if ( $.isFunction(window[fn]) ) { |
| 39 | + window[fn](); |
| 40 | + } |
| 41 | + }); |
| 42 | + $('body').delegate('pre', 'click', function() { |
| 43 | + $.mockjaxClear(); |
| 44 | + var script = $(this).html(); |
| 45 | + eval(script); |
| 46 | + }); |
| 47 | + </script> |
| 48 | +</head> |
| 49 | +<body> |
| 50 | + <p><a href="http://enterprisejquery.com/?p=106">Enterprise jQuery Blog Post about $.mockjax</a></p> |
| 51 | + <h2>What is jQuery.mockjax?</h2> |
| 52 | + <p>The Mockjax plugin for jQuery provides a decoupled non-invasive way to mock (or simulate) ajax requests throughout your application. It is possible to |
| 53 | + completely simulate the Ajax request/response cycle without any network traffic and without changing any production code. Below are a list of steps for making using |
| 54 | + of mockjax.</p> |
| 55 | + |
| 56 | + <ol> |
| 57 | + <li>Include jquery.mockjax.js jQuery Plugin</li> |
| 58 | + <li>Optionally include json2.js if not natively supported by your browser.</li> |
| 59 | + <li>Include jquery.xmldom.js if you're mocking XML inline.</li> |
| 60 | + <li>Include a file such as mockjax.js containing your mock definitions</li> |
| 61 | + </ol> |
| 62 | + |
| 63 | + <h2>Approaches to Mocking</h2> |
| 64 | + |
| 65 | + <p>There are a number of different approaches to mocking Ajax requests. Below is a list of request types and patterns |
| 66 | + supported by mockjax.</p> |
| 67 | + |
| 68 | + <dl> |
| 69 | + <dt>Mocking via Inline</dt> |
| 70 | + <dd>Mock response is included inline in the mock request definition. |
| 71 | + <span class="title">Simple Mock of JSON</span> |
| 72 | + <pre> |
| 73 | +$.mockjax({ |
| 74 | + url: '/test/inline', |
| 75 | + dataType: 'json', |
| 76 | + responseTime: 2500, |
| 77 | + responseText: { |
| 78 | + say: 'Hello world!' |
| 79 | + } |
| 80 | +}); |
| 81 | + |
| 82 | +// Normal ajax request in your application |
| 83 | +$.ajax({ |
| 84 | + url: '/test/inline', |
| 85 | + dataType: 'json', |
| 86 | + success: function(json) { |
| 87 | + alert('You said: ' + json.say); |
| 88 | + } |
| 89 | +}); |
| 90 | + </pre> |
| 91 | + </dd> |
| 92 | + |
| 93 | + <dt>Mocking via Proxy</dt> |
| 94 | + <dd>Mock response is contained in an external url, proxy attribute contains location of preferred response. |
| 95 | +<pre> |
| 96 | +$.mockjax({ |
| 97 | + url: '/some/webservice', |
| 98 | + dataType: 'json', |
| 99 | + proxy: 'test.json' |
| 100 | +}); |
| 101 | + |
| 102 | +// Normal ajax request in your application |
| 103 | +$.ajax({ |
| 104 | + url: '/some/webservice', |
| 105 | + dataType: 'json', |
| 106 | + success: function(json) { |
| 107 | + alert('You said: ' + json.say); |
| 108 | + } |
| 109 | +}); |
| 110 | +</pre> |
| 111 | + </dd> |
| 112 | + |
| 113 | + <dt>Mocking via Function</dt> |
| 114 | + <dd>There are two ways to mock via functions, the first provides the greatest flexability and allows for the |
| 115 | + developer to decide if they will intercept the request as a mock. In this situation, the developer should return |
| 116 | + a falsy value (false, undefined, or null) or an object literal containing the settings for this mock request. |
| 117 | +<pre> |
| 118 | +$.mockjax(function(settings) { |
| 119 | + if ( settings.dataType == 'json' ) { |
| 120 | + return { |
| 121 | + dataType: 'json', |
| 122 | + proxy: 'test.json' |
| 123 | + }; |
| 124 | + } |
| 125 | + return false; |
| 126 | +}); |
| 127 | + |
| 128 | +// Normal ajax request in your application |
| 129 | +$.ajax({ |
| 130 | + url: '/some/webservice', |
| 131 | + dataType: 'json', |
| 132 | + success: function(json) { |
| 133 | + alert('You said: ' + json.say); |
| 134 | + } |
| 135 | +}); |
| 136 | +</pre> |
| 137 | + <p>In the second form, a callback method is registered under the response attribute. The callback method is triggered |
| 138 | + right before the response is parsed. In the function body, the method has the opportunity to modify any attributes such |
| 139 | + as responseText or responseXML.</p> |
| 140 | +<pre> |
| 141 | +$.mockjax({ |
| 142 | + url: '/some/webservice', |
| 143 | + dataType: 'json', |
| 144 | + response: function(settings) { |
| 145 | + this.responseText = { say: 'random ' + Math.random() }; |
| 146 | + } |
| 147 | +}); |
| 148 | + |
| 149 | +// Normal ajax request in your application |
| 150 | +$.ajax({ |
| 151 | + url: '/some/webservice', |
| 152 | + dataType: 'json', |
| 153 | + success: function(json) { |
| 154 | + alert('You said: ' + json.say); |
| 155 | + } |
| 156 | +}); |
| 157 | +</pre> |
| 158 | + </dd> |
| 159 | + |
| 160 | + </dl> |
| 161 | + |
| 162 | + <h2>Mocking Various Data Types</h2> |
| 163 | + <p></p> |
| 164 | + |
| 165 | + <h3>Mocking JSON</h3> |
| 166 | + <pre> |
| 167 | + $.mockjax({ |
| 168 | + url: '/some/json', |
| 169 | + dataType: 'json', |
| 170 | + responseText: { |
| 171 | + say: "JSON Here" |
| 172 | + } |
| 173 | + }); |
| 174 | + |
| 175 | + // Normal ajax request in your application |
| 176 | + $.ajax({ |
| 177 | + url: '/some/json', |
| 178 | + dataType: 'json', |
| 179 | + success: function(json) { |
| 180 | + alert('You said: ' + json.say); |
| 181 | + } |
| 182 | + }); |
| 183 | + </pre> |
| 184 | + |
| 185 | + <h3>Mocking XML</h3> |
| 186 | + <pre> |
| 187 | + $.mockjax({ |
| 188 | + url: '/some/xml', |
| 189 | + dataType: 'xml', |
| 190 | + responseXML: '<document><say>Hello world XML</say></document>' |
| 191 | + }); |
| 192 | + |
| 193 | + // Normal ajax request in your application |
| 194 | + $.ajax({ |
| 195 | + url: '/some/xml', |
| 196 | + dataType: 'xml', |
| 197 | + success: function(xml) { |
| 198 | + alert('You said: ' + $(xml).find('document say').text() ); |
| 199 | + } |
| 200 | + }); |
| 201 | + </pre> |
| 202 | + |
| 203 | + <h3>Mocking HTML</h3> |
| 204 | + <pre> |
| 205 | + $.mockjax({ |
| 206 | + url: '/some/webservice', |
| 207 | + dataType: 'html', |
| 208 | + responseText: '<div>Hello there</div>' |
| 209 | + }); |
| 210 | + |
| 211 | + // Normal ajax request in your application |
| 212 | + $.ajax({ |
| 213 | + url: '/some/webservice', |
| 214 | + dataType: 'html', |
| 215 | + success: function(html) { |
| 216 | + alert('You said: ' + html); |
| 217 | + } |
| 218 | + }); |
| 219 | + </pre> |
| 220 | +</body> |
| 221 | +</html> |
Index: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/jquery.mockjax.min.js |
— | — | @@ -0,0 +1,22 @@ |
| 2 | +/*! |
| 3 | + * MockJax - Mock for Ajax requests |
| 4 | + * |
| 5 | + * Version: 1.3.1 |
| 6 | + * Released: 2010-08-11 |
| 7 | + * Source: http://github.com/appendto/jquery-mockjax |
| 8 | + * Plugin: mockjax |
| 9 | + * Author: Jonathan Sharp (http://jdsharp.com) |
| 10 | + * License: MIT,GPL |
| 11 | + * |
| 12 | + * Copyright (c) 2010 appendTo LLC. |
| 13 | + * Dual licensed under the MIT or GPL licenses. |
| 14 | + * http://appendto.com/open-source-licenses |
| 15 | + */ |
| 16 | +(function(c){var m=c.ajax,f=[];c.extend({ajax:function(j){var a=jQuery.extend(true,{},jQuery.ajaxSettings,j),n=false;c.each(f,function(g){if(f[g]){var b=null;if(c.isFunction(f[g]))b=f[g](a);else{b=f[g];if(c.isFunction(b.url.test))b.url.test(a.url)||(b=null);else{g=b.url.indexOf("*");if(b.url!="*"&&b.url!=a.url&&g==-1||g>-1&&b.url.substr(0,g)!=a.url.substr(0,g))b=null}if(b){if(b.data&&a.data){var l=false;(function d(h,k){c.each(h,function(i){if(k[i]===undefined)return l=false;else{l=true;if(typeof k[i]== |
| 17 | +"object")return d(h[i],k[i]);else return l=c.isFunction(h[i].test)?h[i].test(k[i]):h[i]==k[i]}})})(b.data,a.data);if(l==false)b=null}if(b&&b.type&&b.type!=a.type)b=null}}if(b){typeof console!=="undefined"&&console.log&&console.log("MOCK GET: "+a.url);n=true;if(a.dataType==="jsonp"){if(type==="GET")e.test(a.url)||(a.url+=(rquery.test(a.url)?"&":"?")+(a.jsonp||"callback")+"=?");else if(!a.data||!e.test(a.data))a.data=(a.data?a.data+"&":"")+(a.jsonp||"callback")+"=?";a.dataType="json"}var e=/=\?(&|$)/; |
| 18 | +if(a.dataType==="json"&&(a.data&&e.test(a.data)||e.test(a.url))){jsonp=a.jsonpCallback||"jsonp"+jsc++;if(a.data)a.data=(a.data+"").replace(e,"="+jsonp+"$1");a.url=a.url.replace(e,"="+jsonp+"$1");a.dataType="script";window[jsonp]=window[jsonp]||function(d){data=d;o();p();window[jsonp]=undefined;try{delete window[jsonp]}catch(h){}head&&head.removeChild(script)}}e=(e=/^(\w+:)?\/\/([^\/?#]+)/.exec(a.url))&&(e[1]&&e[1]!==location.protocol||e[2]!==location.host);if(a.dataType==="script"&&a.type==="GET"&& |
| 19 | +e){var q=j&&j.context||a,o=function(){if(a.success)a.success.call(q,b.response?b.response.toString():b.responseText||"",status,{});if(a.global){var d=[{},a];(a.context?jQuery(a.context):jQuery.event).trigger("ajaxSuccess",d)}},p=function(){a.complete&&a.complete.call(q,{},status);if(a.global){var d=[{},a];(a.context?jQuery(a.context):jQuery.event).trigger("ajaxComplete",d)}a.global&&!--jQuery.active&&jQuery.event.trigger("ajaxStop")};c.globalEval(b.responseText);o();p();return false}m.call(c,c.extend(true, |
| 20 | +{},j,{xhr:function(){b=c.extend({},c.mockjaxSettings,b);return{status:b.status,readyState:1,open:function(){},send:function(){var d=c.proxy(function(){this.status=b.status;this.readyState=4;c.isFunction(b.response)&&b.response();if(a.dataType=="json"&&typeof b.responseText=="object")this.responseText=JSON.stringify(b.responseText);else if(a.dataType=="xml")this.responseXML=c.xmlDOM&&typeof b.responseXML=="string"?c.xmlDOM(b.responseXML)[0]:b.responseXML;else this.responseText=b.responseText;this.onreadystatechange(b.isTimeout? |
| 21 | +"timeout":undefined)},this);if(b.proxy)m({global:false,url:b.proxy,type:b.type,data:b.data,dataType:a.dataType,complete:function(h){b.responseXML=h.responseXML;b.responseText=h.responseText;d()}});else if(a.async===false)d();else this.responseTimer=setTimeout(d,b.responseTime||50)},abort:function(){clearTimeout(this.responseTimer)},setRequestHeader:function(){},getResponseHeader:function(d){if(b.headers&&b.headers[d])return b.headers[d];else if(d=="Last-modified")return b.lastModified||(new Date).toString(); |
| 22 | +else if(d=="Etag")return b.etag||"";else if(d=="content-type")return b.contentType||"text/plain"}}}}));return false}}});if(!n)return m.apply(c,arguments)}});c.mockjaxSettings={status:200,responseTime:500,isTimeout:false,contentType:"text/plain",response:"",responseText:"",responseXML:"",proxy:"",lastModified:null,etag:"",headers:{etag:"IJF@H#@923uf8023hFO@I#H#","content-type":"text/plain"}};c.mockjax=function(j){var a=f.length;f[a]=j;return a};c.mockjaxClear=function(j){if(arguments.length==1)f[j]= |
| 23 | +null;else f=[]}})(jQuery); |
Property changes on: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/jquery.mockjax.min.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 24 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/test.json |
— | — | @@ -0,0 +1 @@ |
| 2 | +{ "say" : "I'm a json file!" } |
Index: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/mockjax.demo.js |
— | — | @@ -0,0 +1,33 @@ |
| 2 | + |
| 3 | +// Example of a getScript or dataType == 'script' |
| 4 | +$.mockjax({ |
| 5 | + url: 'example.com/foo', |
| 6 | + response: function() { |
| 7 | + // This method is executed when a script request comes in |
| 8 | + } |
| 9 | +}); |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +/* |
| 14 | + * This file contains the mock ajax requests |
| 15 | + */ |
| 16 | +$.mockjax({ |
| 17 | + url: '/rest/search/store', |
| 18 | + contentType: 'text/json', |
| 19 | + responseText: { |
| 20 | + status: 'success', |
| 21 | + data: { |
| 22 | + paging: { |
| 23 | + current: 1, |
| 24 | + total: 5 |
| 25 | + }, |
| 26 | + results: [ |
| 27 | + 'product-001', |
| 28 | + 'product-002', |
| 29 | + 'product-003', |
| 30 | + 'product-004' |
| 31 | + ] |
| 32 | + } |
| 33 | + } |
| 34 | +}); |
\ No newline at end of file |
Property changes on: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/mockjax.demo.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 35 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/test.js |
— | — | @@ -0,0 +1,54 @@ |
| 2 | +(function($) { |
| 3 | + $(function() { |
| 4 | + $.ajax({ |
| 5 | + url: 'test.json', |
| 6 | + success: function(data) { |
| 7 | + $('ul').append('<li>test.json: completed (' + data.test + ')</li>'); |
| 8 | + } |
| 9 | + }); |
| 10 | + |
| 11 | + $.mockjax({ |
| 12 | + url: 'test.json', |
| 13 | + contentType: 'text/json', |
| 14 | + responseText: { "test": "mock message" } |
| 15 | + }); |
| 16 | + |
| 17 | + $.ajax({ |
| 18 | + url: 'test.json', |
| 19 | + dataType: 'json', |
| 20 | + success: function(data) { |
| 21 | + $('ul').append('<li>test.json: completed (' + data.test + ')</li>'); |
| 22 | + }, |
| 23 | + error: function(xhr, status, error) { |
| 24 | + alert('error: ' + status + ' ' + error); |
| 25 | + }, |
| 26 | + complete: function() { |
| 27 | + } |
| 28 | + }); |
| 29 | + |
| 30 | + $.mockjax({ |
| 31 | + url: 'http://google.com', |
| 32 | + responseText: 'alert("Hello world");' |
| 33 | + }); |
| 34 | + |
| 35 | + $.mockjax({ |
| 36 | + url: 'http://another-cross-domain.com', |
| 37 | + responseText: function() { |
| 38 | + alert("Get script mock"); |
| 39 | + } |
| 40 | + }); |
| 41 | + |
| 42 | + $.ajax({ |
| 43 | + url: 'http://google.com', |
| 44 | + dataType: 'script', |
| 45 | + success: function(data) { |
| 46 | + $('ul').append('<li>script: completed (' + data.test + ')</li>'); |
| 47 | + }, |
| 48 | + error: function(xhr, status, error) { |
| 49 | + alert('error: ' + status + ' ' + error); |
| 50 | + }, |
| 51 | + complete: function() { |
| 52 | + } |
| 53 | + }); |
| 54 | + }); |
| 55 | +})(jQuery); |
Property changes on: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/appendto-jquery-mockjax/test.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 56 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/jasmine-0.11.1/jasmine.js |
— | — | @@ -0,0 +1,2343 @@ |
| 2 | +/** |
| 3 | + * Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework. |
| 4 | + * |
| 5 | + * @namespace |
| 6 | + */ |
| 7 | +var jasmine = {}; |
| 8 | + |
| 9 | +/** |
| 10 | + * @private |
| 11 | + */ |
| 12 | +jasmine.unimplementedMethod_ = function() { |
| 13 | + throw new Error("unimplemented method"); |
| 14 | +}; |
| 15 | + |
| 16 | +/** |
| 17 | + * Use <code>jasmine.undefined</code> instead of <code>undefined</code>, since <code>undefined</code> is just |
| 18 | + * a plain old variable and may be redefined by somebody else. |
| 19 | + * |
| 20 | + * @private |
| 21 | + */ |
| 22 | +jasmine.undefined = jasmine.___undefined___; |
| 23 | + |
| 24 | +/** |
| 25 | + * Default interval for event loop yields. Small values here may result in slow test running. Zero means no updates until all tests have completed. |
| 26 | + * |
| 27 | + */ |
| 28 | +jasmine.DEFAULT_UPDATE_INTERVAL = 250; |
| 29 | + |
| 30 | +jasmine.getGlobal = function() { |
| 31 | + function getGlobal() { |
| 32 | + return this; |
| 33 | + } |
| 34 | + |
| 35 | + return getGlobal(); |
| 36 | +}; |
| 37 | + |
| 38 | +/** |
| 39 | + * Allows for bound functions to be compared. Internal use only. |
| 40 | + * |
| 41 | + * @ignore |
| 42 | + * @private |
| 43 | + * @param base {Object} bound 'this' for the function |
| 44 | + * @param name {Function} function to find |
| 45 | + */ |
| 46 | +jasmine.bindOriginal_ = function(base, name) { |
| 47 | + var original = base[name]; |
| 48 | + if (original.apply) { |
| 49 | + return function() { |
| 50 | + return original.apply(base, arguments); |
| 51 | + }; |
| 52 | + } else { |
| 53 | + // IE support |
| 54 | + return jasmine.getGlobal()[name]; |
| 55 | + } |
| 56 | +}; |
| 57 | + |
| 58 | +jasmine.setTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'setTimeout'); |
| 59 | +jasmine.clearTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearTimeout'); |
| 60 | +jasmine.setInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'setInterval'); |
| 61 | +jasmine.clearInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearInterval'); |
| 62 | + |
| 63 | +jasmine.MessageResult = function(values) { |
| 64 | + this.type = 'log'; |
| 65 | + this.values = values; |
| 66 | + this.trace = new Error(); // todo: test better |
| 67 | +}; |
| 68 | + |
| 69 | +jasmine.MessageResult.prototype.toString = function() { |
| 70 | + var text = ""; |
| 71 | + for(var i = 0; i < this.values.length; i++) { |
| 72 | + if (i > 0) text += " "; |
| 73 | + if (jasmine.isString_(this.values[i])) { |
| 74 | + text += this.values[i]; |
| 75 | + } else { |
| 76 | + text += jasmine.pp(this.values[i]); |
| 77 | + } |
| 78 | + } |
| 79 | + return text; |
| 80 | +}; |
| 81 | + |
| 82 | +jasmine.ExpectationResult = function(params) { |
| 83 | + this.type = 'expect'; |
| 84 | + this.matcherName = params.matcherName; |
| 85 | + this.passed_ = params.passed; |
| 86 | + this.expected = params.expected; |
| 87 | + this.actual = params.actual; |
| 88 | + |
| 89 | + this.message = this.passed_ ? 'Passed.' : params.message; |
| 90 | + this.trace = this.passed_ ? '' : new Error(this.message); |
| 91 | +}; |
| 92 | + |
| 93 | +jasmine.ExpectationResult.prototype.toString = function () { |
| 94 | + return this.message; |
| 95 | +}; |
| 96 | + |
| 97 | +jasmine.ExpectationResult.prototype.passed = function () { |
| 98 | + return this.passed_; |
| 99 | +}; |
| 100 | + |
| 101 | +/** |
| 102 | + * Getter for the Jasmine environment. Ensures one gets created |
| 103 | + */ |
| 104 | +jasmine.getEnv = function() { |
| 105 | + return jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env(); |
| 106 | +}; |
| 107 | + |
| 108 | +/** |
| 109 | + * @ignore |
| 110 | + * @private |
| 111 | + * @param value |
| 112 | + * @returns {Boolean} |
| 113 | + */ |
| 114 | +jasmine.isArray_ = function(value) { |
| 115 | + return jasmine.isA_("Array", value); |
| 116 | +}; |
| 117 | + |
| 118 | +/** |
| 119 | + * @ignore |
| 120 | + * @private |
| 121 | + * @param value |
| 122 | + * @returns {Boolean} |
| 123 | + */ |
| 124 | +jasmine.isString_ = function(value) { |
| 125 | + return jasmine.isA_("String", value); |
| 126 | +}; |
| 127 | + |
| 128 | +/** |
| 129 | + * @ignore |
| 130 | + * @private |
| 131 | + * @param value |
| 132 | + * @returns {Boolean} |
| 133 | + */ |
| 134 | +jasmine.isNumber_ = function(value) { |
| 135 | + return jasmine.isA_("Number", value); |
| 136 | +}; |
| 137 | + |
| 138 | +/** |
| 139 | + * @ignore |
| 140 | + * @private |
| 141 | + * @param {String} typeName |
| 142 | + * @param value |
| 143 | + * @returns {Boolean} |
| 144 | + */ |
| 145 | +jasmine.isA_ = function(typeName, value) { |
| 146 | + return Object.prototype.toString.apply(value) === '[object ' + typeName + ']'; |
| 147 | +}; |
| 148 | + |
| 149 | +/** |
| 150 | + * Pretty printer for expecations. Takes any object and turns it into a human-readable string. |
| 151 | + * |
| 152 | + * @param value {Object} an object to be outputted |
| 153 | + * @returns {String} |
| 154 | + */ |
| 155 | +jasmine.pp = function(value) { |
| 156 | + var stringPrettyPrinter = new jasmine.StringPrettyPrinter(); |
| 157 | + stringPrettyPrinter.format(value); |
| 158 | + return stringPrettyPrinter.string; |
| 159 | +}; |
| 160 | + |
| 161 | +/** |
| 162 | + * Returns true if the object is a DOM Node. |
| 163 | + * |
| 164 | + * @param {Object} obj object to check |
| 165 | + * @returns {Boolean} |
| 166 | + */ |
| 167 | +jasmine.isDomNode = function(obj) { |
| 168 | + return obj['nodeType'] > 0; |
| 169 | +}; |
| 170 | + |
| 171 | +/** |
| 172 | + * Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter. |
| 173 | + * |
| 174 | + * @example |
| 175 | + * // don't care about which function is passed in, as long as it's a function |
| 176 | + * expect(mySpy).toHaveBeenCalledWith(jasmine.any(Function)); |
| 177 | + * |
| 178 | + * @param {Class} clazz |
| 179 | + * @returns matchable object of the type clazz |
| 180 | + */ |
| 181 | +jasmine.any = function(clazz) { |
| 182 | + return new jasmine.Matchers.Any(clazz); |
| 183 | +}; |
| 184 | + |
| 185 | +/** |
| 186 | + * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks. |
| 187 | + * |
| 188 | + * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine |
| 189 | + * expectation syntax. Spies can be checked if they were called or not and what the calling params were. |
| 190 | + * |
| 191 | + * A Spy has the following fields: wasCalled, callCount, mostRecentCall, and argsForCall (see docs). |
| 192 | + * |
| 193 | + * Spies are torn down at the end of every spec. |
| 194 | + * |
| 195 | + * Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj. |
| 196 | + * |
| 197 | + * @example |
| 198 | + * // a stub |
| 199 | + * var myStub = jasmine.createSpy('myStub'); // can be used anywhere |
| 200 | + * |
| 201 | + * // spy example |
| 202 | + * var foo = { |
| 203 | + * not: function(bool) { return !bool; } |
| 204 | + * } |
| 205 | + * |
| 206 | + * // actual foo.not will not be called, execution stops |
| 207 | + * spyOn(foo, 'not'); |
| 208 | + |
| 209 | + // foo.not spied upon, execution will continue to implementation |
| 210 | + * spyOn(foo, 'not').andCallThrough(); |
| 211 | + * |
| 212 | + * // fake example |
| 213 | + * var foo = { |
| 214 | + * not: function(bool) { return !bool; } |
| 215 | + * } |
| 216 | + * |
| 217 | + * // foo.not(val) will return val |
| 218 | + * spyOn(foo, 'not').andCallFake(function(value) {return value;}); |
| 219 | + * |
| 220 | + * // mock example |
| 221 | + * foo.not(7 == 7); |
| 222 | + * expect(foo.not).toHaveBeenCalled(); |
| 223 | + * expect(foo.not).toHaveBeenCalledWith(true); |
| 224 | + * |
| 225 | + * @constructor |
| 226 | + * @see spyOn, jasmine.createSpy, jasmine.createSpyObj |
| 227 | + * @param {String} name |
| 228 | + */ |
| 229 | +jasmine.Spy = function(name) { |
| 230 | + /** |
| 231 | + * The name of the spy, if provided. |
| 232 | + */ |
| 233 | + this.identity = name || 'unknown'; |
| 234 | + /** |
| 235 | + * Is this Object a spy? |
| 236 | + */ |
| 237 | + this.isSpy = true; |
| 238 | + /** |
| 239 | + * The actual function this spy stubs. |
| 240 | + */ |
| 241 | + this.plan = function() { |
| 242 | + }; |
| 243 | + /** |
| 244 | + * Tracking of the most recent call to the spy. |
| 245 | + * @example |
| 246 | + * var mySpy = jasmine.createSpy('foo'); |
| 247 | + * mySpy(1, 2); |
| 248 | + * mySpy.mostRecentCall.args = [1, 2]; |
| 249 | + */ |
| 250 | + this.mostRecentCall = {}; |
| 251 | + |
| 252 | + /** |
| 253 | + * Holds arguments for each call to the spy, indexed by call count |
| 254 | + * @example |
| 255 | + * var mySpy = jasmine.createSpy('foo'); |
| 256 | + * mySpy(1, 2); |
| 257 | + * mySpy(7, 8); |
| 258 | + * mySpy.mostRecentCall.args = [7, 8]; |
| 259 | + * mySpy.argsForCall[0] = [1, 2]; |
| 260 | + * mySpy.argsForCall[1] = [7, 8]; |
| 261 | + */ |
| 262 | + this.argsForCall = []; |
| 263 | + this.calls = []; |
| 264 | +}; |
| 265 | + |
| 266 | +/** |
| 267 | + * Tells a spy to call through to the actual implemenatation. |
| 268 | + * |
| 269 | + * @example |
| 270 | + * var foo = { |
| 271 | + * bar: function() { // do some stuff } |
| 272 | + * } |
| 273 | + * |
| 274 | + * // defining a spy on an existing property: foo.bar |
| 275 | + * spyOn(foo, 'bar').andCallThrough(); |
| 276 | + */ |
| 277 | +jasmine.Spy.prototype.andCallThrough = function() { |
| 278 | + this.plan = this.originalValue; |
| 279 | + return this; |
| 280 | +}; |
| 281 | + |
| 282 | +/** |
| 283 | + * For setting the return value of a spy. |
| 284 | + * |
| 285 | + * @example |
| 286 | + * // defining a spy from scratch: foo() returns 'baz' |
| 287 | + * var foo = jasmine.createSpy('spy on foo').andReturn('baz'); |
| 288 | + * |
| 289 | + * // defining a spy on an existing property: foo.bar() returns 'baz' |
| 290 | + * spyOn(foo, 'bar').andReturn('baz'); |
| 291 | + * |
| 292 | + * @param {Object} value |
| 293 | + */ |
| 294 | +jasmine.Spy.prototype.andReturn = function(value) { |
| 295 | + this.plan = function() { |
| 296 | + return value; |
| 297 | + }; |
| 298 | + return this; |
| 299 | +}; |
| 300 | + |
| 301 | +/** |
| 302 | + * For throwing an exception when a spy is called. |
| 303 | + * |
| 304 | + * @example |
| 305 | + * // defining a spy from scratch: foo() throws an exception w/ message 'ouch' |
| 306 | + * var foo = jasmine.createSpy('spy on foo').andThrow('baz'); |
| 307 | + * |
| 308 | + * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch' |
| 309 | + * spyOn(foo, 'bar').andThrow('baz'); |
| 310 | + * |
| 311 | + * @param {String} exceptionMsg |
| 312 | + */ |
| 313 | +jasmine.Spy.prototype.andThrow = function(exceptionMsg) { |
| 314 | + this.plan = function() { |
| 315 | + throw exceptionMsg; |
| 316 | + }; |
| 317 | + return this; |
| 318 | +}; |
| 319 | + |
| 320 | +/** |
| 321 | + * Calls an alternate implementation when a spy is called. |
| 322 | + * |
| 323 | + * @example |
| 324 | + * var baz = function() { |
| 325 | + * // do some stuff, return something |
| 326 | + * } |
| 327 | + * // defining a spy from scratch: foo() calls the function baz |
| 328 | + * var foo = jasmine.createSpy('spy on foo').andCall(baz); |
| 329 | + * |
| 330 | + * // defining a spy on an existing property: foo.bar() calls an anonymnous function |
| 331 | + * spyOn(foo, 'bar').andCall(function() { return 'baz';} ); |
| 332 | + * |
| 333 | + * @param {Function} fakeFunc |
| 334 | + */ |
| 335 | +jasmine.Spy.prototype.andCallFake = function(fakeFunc) { |
| 336 | + this.plan = fakeFunc; |
| 337 | + return this; |
| 338 | +}; |
| 339 | + |
| 340 | +/** |
| 341 | + * Resets all of a spy's the tracking variables so that it can be used again. |
| 342 | + * |
| 343 | + * @example |
| 344 | + * spyOn(foo, 'bar'); |
| 345 | + * |
| 346 | + * foo.bar(); |
| 347 | + * |
| 348 | + * expect(foo.bar.callCount).toEqual(1); |
| 349 | + * |
| 350 | + * foo.bar.reset(); |
| 351 | + * |
| 352 | + * expect(foo.bar.callCount).toEqual(0); |
| 353 | + */ |
| 354 | +jasmine.Spy.prototype.reset = function() { |
| 355 | + this.wasCalled = false; |
| 356 | + this.callCount = 0; |
| 357 | + this.argsForCall = []; |
| 358 | + this.calls = []; |
| 359 | + this.mostRecentCall = {}; |
| 360 | +}; |
| 361 | + |
| 362 | +jasmine.createSpy = function(name) { |
| 363 | + |
| 364 | + var spyObj = function() { |
| 365 | + spyObj.wasCalled = true; |
| 366 | + spyObj.callCount++; |
| 367 | + var args = jasmine.util.argsToArray(arguments); |
| 368 | + spyObj.mostRecentCall.object = this; |
| 369 | + spyObj.mostRecentCall.args = args; |
| 370 | + spyObj.argsForCall.push(args); |
| 371 | + spyObj.calls.push({object: this, args: args}); |
| 372 | + return spyObj.plan.apply(this, arguments); |
| 373 | + }; |
| 374 | + |
| 375 | + var spy = new jasmine.Spy(name); |
| 376 | + |
| 377 | + for (var prop in spy) { |
| 378 | + spyObj[prop] = spy[prop]; |
| 379 | + } |
| 380 | + |
| 381 | + spyObj.reset(); |
| 382 | + |
| 383 | + return spyObj; |
| 384 | +}; |
| 385 | + |
| 386 | +/** |
| 387 | + * Determines whether an object is a spy. |
| 388 | + * |
| 389 | + * @param {jasmine.Spy|Object} putativeSpy |
| 390 | + * @returns {Boolean} |
| 391 | + */ |
| 392 | +jasmine.isSpy = function(putativeSpy) { |
| 393 | + return putativeSpy && putativeSpy.isSpy; |
| 394 | +}; |
| 395 | + |
| 396 | +/** |
| 397 | + * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something |
| 398 | + * large in one call. |
| 399 | + * |
| 400 | + * @param {String} baseName name of spy class |
| 401 | + * @param {Array} methodNames array of names of methods to make spies |
| 402 | + */ |
| 403 | +jasmine.createSpyObj = function(baseName, methodNames) { |
| 404 | + if (!jasmine.isArray_(methodNames) || methodNames.length == 0) { |
| 405 | + throw new Error('createSpyObj requires a non-empty array of method names to create spies for'); |
| 406 | + } |
| 407 | + var obj = {}; |
| 408 | + for (var i = 0; i < methodNames.length; i++) { |
| 409 | + obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); |
| 410 | + } |
| 411 | + return obj; |
| 412 | +}; |
| 413 | + |
| 414 | +/** |
| 415 | + * All parameters are pretty-printed and concatenated together, then written to the current spec's output. |
| 416 | + * |
| 417 | + * Be careful not to leave calls to <code>jasmine.log</code> in production code. |
| 418 | + */ |
| 419 | +jasmine.log = function() { |
| 420 | + var spec = jasmine.getEnv().currentSpec; |
| 421 | + spec.log.apply(spec, arguments); |
| 422 | +}; |
| 423 | + |
| 424 | +/** |
| 425 | + * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy. |
| 426 | + * |
| 427 | + * @example |
| 428 | + * // spy example |
| 429 | + * var foo = { |
| 430 | + * not: function(bool) { return !bool; } |
| 431 | + * } |
| 432 | + * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops |
| 433 | + * |
| 434 | + * @see jasmine.createSpy |
| 435 | + * @param obj |
| 436 | + * @param methodName |
| 437 | + * @returns a Jasmine spy that can be chained with all spy methods |
| 438 | + */ |
| 439 | +var spyOn = function(obj, methodName) { |
| 440 | + return jasmine.getEnv().currentSpec.spyOn(obj, methodName); |
| 441 | +}; |
| 442 | + |
| 443 | +/** |
| 444 | + * Creates a Jasmine spec that will be added to the current suite. |
| 445 | + * |
| 446 | + * // TODO: pending tests |
| 447 | + * |
| 448 | + * @example |
| 449 | + * it('should be true', function() { |
| 450 | + * expect(true).toEqual(true); |
| 451 | + * }); |
| 452 | + * |
| 453 | + * @param {String} desc description of this specification |
| 454 | + * @param {Function} func defines the preconditions and expectations of the spec |
| 455 | + */ |
| 456 | +var it = function(desc, func) { |
| 457 | + return jasmine.getEnv().it(desc, func); |
| 458 | +}; |
| 459 | + |
| 460 | +/** |
| 461 | + * Creates a <em>disabled</em> Jasmine spec. |
| 462 | + * |
| 463 | + * A convenience method that allows existing specs to be disabled temporarily during development. |
| 464 | + * |
| 465 | + * @param {String} desc description of this specification |
| 466 | + * @param {Function} func defines the preconditions and expectations of the spec |
| 467 | + */ |
| 468 | +var xit = function(desc, func) { |
| 469 | + return jasmine.getEnv().xit(desc, func); |
| 470 | +}; |
| 471 | + |
| 472 | +/** |
| 473 | + * Starts a chain for a Jasmine expectation. |
| 474 | + * |
| 475 | + * It is passed an Object that is the actual value and should chain to one of the many |
| 476 | + * jasmine.Matchers functions. |
| 477 | + * |
| 478 | + * @param {Object} actual Actual value to test against and expected value |
| 479 | + */ |
| 480 | +var expect = function(actual) { |
| 481 | + return jasmine.getEnv().currentSpec.expect(actual); |
| 482 | +}; |
| 483 | + |
| 484 | +/** |
| 485 | + * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs. |
| 486 | + * |
| 487 | + * @param {Function} func Function that defines part of a jasmine spec. |
| 488 | + */ |
| 489 | +var runs = function(func) { |
| 490 | + jasmine.getEnv().currentSpec.runs(func); |
| 491 | +}; |
| 492 | + |
| 493 | +/** |
| 494 | + * Waits for a timeout before moving to the next runs()-defined block. |
| 495 | + * @param {Number} timeout |
| 496 | + */ |
| 497 | +var waits = function(timeout) { |
| 498 | + jasmine.getEnv().currentSpec.waits(timeout); |
| 499 | +}; |
| 500 | + |
| 501 | +/** |
| 502 | + * Waits for the latchFunction to return true before proceeding to the next runs()-defined block. |
| 503 | + * |
| 504 | + * @param {Number} timeout |
| 505 | + * @param {Function} latchFunction |
| 506 | + * @param {String} message |
| 507 | + */ |
| 508 | +var waitsFor = function(timeout, latchFunction, message) { |
| 509 | + jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message); |
| 510 | +}; |
| 511 | + |
| 512 | +/** |
| 513 | + * A function that is called before each spec in a suite. |
| 514 | + * |
| 515 | + * Used for spec setup, including validating assumptions. |
| 516 | + * |
| 517 | + * @param {Function} beforeEachFunction |
| 518 | + */ |
| 519 | +var beforeEach = function(beforeEachFunction) { |
| 520 | + jasmine.getEnv().beforeEach(beforeEachFunction); |
| 521 | +}; |
| 522 | + |
| 523 | +/** |
| 524 | + * A function that is called after each spec in a suite. |
| 525 | + * |
| 526 | + * Used for restoring any state that is hijacked during spec execution. |
| 527 | + * |
| 528 | + * @param {Function} afterEachFunction |
| 529 | + */ |
| 530 | +var afterEach = function(afterEachFunction) { |
| 531 | + jasmine.getEnv().afterEach(afterEachFunction); |
| 532 | +}; |
| 533 | + |
| 534 | +/** |
| 535 | + * Defines a suite of specifications. |
| 536 | + * |
| 537 | + * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared |
| 538 | + * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization |
| 539 | + * of setup in some tests. |
| 540 | + * |
| 541 | + * @example |
| 542 | + * // TODO: a simple suite |
| 543 | + * |
| 544 | + * // TODO: a simple suite with a nested describe block |
| 545 | + * |
| 546 | + * @param {String} description A string, usually the class under test. |
| 547 | + * @param {Function} specDefinitions function that defines several specs. |
| 548 | + */ |
| 549 | +var describe = function(description, specDefinitions) { |
| 550 | + return jasmine.getEnv().describe(description, specDefinitions); |
| 551 | +}; |
| 552 | + |
| 553 | +/** |
| 554 | + * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development. |
| 555 | + * |
| 556 | + * @param {String} description A string, usually the class under test. |
| 557 | + * @param {Function} specDefinitions function that defines several specs. |
| 558 | + */ |
| 559 | +var xdescribe = function(description, specDefinitions) { |
| 560 | + return jasmine.getEnv().xdescribe(description, specDefinitions); |
| 561 | +}; |
| 562 | + |
| 563 | + |
| 564 | +// Provide the XMLHttpRequest class for IE 5.x-6.x: |
| 565 | +jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() { |
| 566 | + try { |
| 567 | + return new ActiveXObject("Msxml2.XMLHTTP.6.0"); |
| 568 | + } catch(e) { |
| 569 | + } |
| 570 | + try { |
| 571 | + return new ActiveXObject("Msxml2.XMLHTTP.3.0"); |
| 572 | + } catch(e) { |
| 573 | + } |
| 574 | + try { |
| 575 | + return new ActiveXObject("Msxml2.XMLHTTP"); |
| 576 | + } catch(e) { |
| 577 | + } |
| 578 | + try { |
| 579 | + return new ActiveXObject("Microsoft.XMLHTTP"); |
| 580 | + } catch(e) { |
| 581 | + } |
| 582 | + throw new Error("This browser does not support XMLHttpRequest."); |
| 583 | +} : XMLHttpRequest; |
| 584 | +/** |
| 585 | + * @namespace |
| 586 | + */ |
| 587 | +jasmine.util = {}; |
| 588 | + |
| 589 | +/** |
| 590 | + * Declare that a child class inherit it's prototype from the parent class. |
| 591 | + * |
| 592 | + * @private |
| 593 | + * @param {Function} childClass |
| 594 | + * @param {Function} parentClass |
| 595 | + */ |
| 596 | +jasmine.util.inherit = function(childClass, parentClass) { |
| 597 | + /** |
| 598 | + * @private |
| 599 | + */ |
| 600 | + var subclass = function() { |
| 601 | + }; |
| 602 | + subclass.prototype = parentClass.prototype; |
| 603 | + childClass.prototype = new subclass; |
| 604 | +}; |
| 605 | + |
| 606 | +jasmine.util.formatException = function(e) { |
| 607 | + var lineNumber; |
| 608 | + if (e.line) { |
| 609 | + lineNumber = e.line; |
| 610 | + } |
| 611 | + else if (e.lineNumber) { |
| 612 | + lineNumber = e.lineNumber; |
| 613 | + } |
| 614 | + |
| 615 | + var file; |
| 616 | + |
| 617 | + if (e.sourceURL) { |
| 618 | + file = e.sourceURL; |
| 619 | + } |
| 620 | + else if (e.fileName) { |
| 621 | + file = e.fileName; |
| 622 | + } |
| 623 | + |
| 624 | + var message = (e.name && e.message) ? (e.name + ': ' + e.message) : e.toString(); |
| 625 | + |
| 626 | + if (file && lineNumber) { |
| 627 | + message += ' in ' + file + ' (line ' + lineNumber + ')'; |
| 628 | + } |
| 629 | + |
| 630 | + return message; |
| 631 | +}; |
| 632 | + |
| 633 | +jasmine.util.htmlEscape = function(str) { |
| 634 | + if (!str) return str; |
| 635 | + return str.replace(/&/g, '&') |
| 636 | + .replace(/</g, '<') |
| 637 | + .replace(/>/g, '>'); |
| 638 | +}; |
| 639 | + |
| 640 | +jasmine.util.argsToArray = function(args) { |
| 641 | + var arrayOfArgs = []; |
| 642 | + for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]); |
| 643 | + return arrayOfArgs; |
| 644 | +}; |
| 645 | + |
| 646 | +jasmine.util.extend = function(destination, source) { |
| 647 | + for (var property in source) destination[property] = source[property]; |
| 648 | + return destination; |
| 649 | +}; |
| 650 | + |
| 651 | +/** |
| 652 | + * Environment for Jasmine |
| 653 | + * |
| 654 | + * @constructor |
| 655 | + */ |
| 656 | +jasmine.Env = function() { |
| 657 | + this.currentSpec = null; |
| 658 | + this.currentSuite = null; |
| 659 | + this.currentRunner_ = new jasmine.Runner(this); |
| 660 | + |
| 661 | + this.reporter = new jasmine.MultiReporter(); |
| 662 | + |
| 663 | + this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL; |
| 664 | + this.lastUpdate = 0; |
| 665 | + this.specFilter = function() { |
| 666 | + return true; |
| 667 | + }; |
| 668 | + |
| 669 | + this.nextSpecId_ = 0; |
| 670 | + this.nextSuiteId_ = 0; |
| 671 | + this.equalityTesters_ = []; |
| 672 | + |
| 673 | + // wrap matchers |
| 674 | + this.matchersClass = function() { |
| 675 | + jasmine.Matchers.apply(this, arguments); |
| 676 | + }; |
| 677 | + jasmine.util.inherit(this.matchersClass, jasmine.Matchers); |
| 678 | + |
| 679 | + jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass); |
| 680 | +}; |
| 681 | + |
| 682 | + |
| 683 | +jasmine.Env.prototype.setTimeout = jasmine.setTimeout; |
| 684 | +jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; |
| 685 | +jasmine.Env.prototype.setInterval = jasmine.setInterval; |
| 686 | +jasmine.Env.prototype.clearInterval = jasmine.clearInterval; |
| 687 | + |
| 688 | +/** |
| 689 | + * @returns an object containing jasmine version build info, if set. |
| 690 | + */ |
| 691 | +jasmine.Env.prototype.version = function () { |
| 692 | + if (jasmine.version_) { |
| 693 | + return jasmine.version_; |
| 694 | + } else { |
| 695 | + throw new Error('Version not set'); |
| 696 | + } |
| 697 | +}; |
| 698 | + |
| 699 | +/** |
| 700 | + * @returns string containing jasmine version build info, if set. |
| 701 | + */ |
| 702 | +jasmine.Env.prototype.versionString = function() { |
| 703 | + if (jasmine.version_) { |
| 704 | + var version = this.version(); |
| 705 | + return version.major + "." + version.minor + "." + version.build + " revision " + version.revision; |
| 706 | + } else { |
| 707 | + return "version unknown"; |
| 708 | + } |
| 709 | +}; |
| 710 | + |
| 711 | +/** |
| 712 | + * @returns a sequential integer starting at 0 |
| 713 | + */ |
| 714 | +jasmine.Env.prototype.nextSpecId = function () { |
| 715 | + return this.nextSpecId_++; |
| 716 | +}; |
| 717 | + |
| 718 | +/** |
| 719 | + * @returns a sequential integer starting at 0 |
| 720 | + */ |
| 721 | +jasmine.Env.prototype.nextSuiteId = function () { |
| 722 | + return this.nextSuiteId_++; |
| 723 | +}; |
| 724 | + |
| 725 | +/** |
| 726 | + * Register a reporter to receive status updates from Jasmine. |
| 727 | + * @param {jasmine.Reporter} reporter An object which will receive status updates. |
| 728 | + */ |
| 729 | +jasmine.Env.prototype.addReporter = function(reporter) { |
| 730 | + this.reporter.addReporter(reporter); |
| 731 | +}; |
| 732 | + |
| 733 | +jasmine.Env.prototype.execute = function() { |
| 734 | + this.currentRunner_.execute(); |
| 735 | +}; |
| 736 | + |
| 737 | +jasmine.Env.prototype.describe = function(description, specDefinitions) { |
| 738 | + var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite); |
| 739 | + |
| 740 | + var parentSuite = this.currentSuite; |
| 741 | + if (parentSuite) { |
| 742 | + parentSuite.add(suite); |
| 743 | + } else { |
| 744 | + this.currentRunner_.add(suite); |
| 745 | + } |
| 746 | + |
| 747 | + this.currentSuite = suite; |
| 748 | + |
| 749 | + var declarationError = null; |
| 750 | + try { |
| 751 | + specDefinitions.call(suite); |
| 752 | + } catch(e) { |
| 753 | + declarationError = e; |
| 754 | + } |
| 755 | + |
| 756 | + this.currentSuite = parentSuite; |
| 757 | + |
| 758 | + if (declarationError) { |
| 759 | + this.it("encountered a declaration exception", function() { |
| 760 | + throw declarationError; |
| 761 | + }); |
| 762 | + } |
| 763 | + |
| 764 | + return suite; |
| 765 | +}; |
| 766 | + |
| 767 | +jasmine.Env.prototype.beforeEach = function(beforeEachFunction) { |
| 768 | + if (this.currentSuite) { |
| 769 | + this.currentSuite.beforeEach(beforeEachFunction); |
| 770 | + } else { |
| 771 | + this.currentRunner_.beforeEach(beforeEachFunction); |
| 772 | + } |
| 773 | +}; |
| 774 | + |
| 775 | +jasmine.Env.prototype.currentRunner = function () { |
| 776 | + return this.currentRunner_; |
| 777 | +}; |
| 778 | + |
| 779 | +jasmine.Env.prototype.afterEach = function(afterEachFunction) { |
| 780 | + if (this.currentSuite) { |
| 781 | + this.currentSuite.afterEach(afterEachFunction); |
| 782 | + } else { |
| 783 | + this.currentRunner_.afterEach(afterEachFunction); |
| 784 | + } |
| 785 | + |
| 786 | +}; |
| 787 | + |
| 788 | +jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) { |
| 789 | + return { |
| 790 | + execute: function() { |
| 791 | + } |
| 792 | + }; |
| 793 | +}; |
| 794 | + |
| 795 | +jasmine.Env.prototype.it = function(description, func) { |
| 796 | + var spec = new jasmine.Spec(this, this.currentSuite, description); |
| 797 | + this.currentSuite.add(spec); |
| 798 | + this.currentSpec = spec; |
| 799 | + |
| 800 | + if (func) { |
| 801 | + spec.runs(func); |
| 802 | + } |
| 803 | + |
| 804 | + return spec; |
| 805 | +}; |
| 806 | + |
| 807 | +jasmine.Env.prototype.xit = function(desc, func) { |
| 808 | + return { |
| 809 | + id: this.nextSpecId(), |
| 810 | + runs: function() { |
| 811 | + } |
| 812 | + }; |
| 813 | +}; |
| 814 | + |
| 815 | +jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) { |
| 816 | + if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) { |
| 817 | + return true; |
| 818 | + } |
| 819 | + |
| 820 | + a.__Jasmine_been_here_before__ = b; |
| 821 | + b.__Jasmine_been_here_before__ = a; |
| 822 | + |
| 823 | + var hasKey = function(obj, keyName) { |
| 824 | + return obj != null && obj[keyName] !== jasmine.undefined; |
| 825 | + }; |
| 826 | + |
| 827 | + for (var property in b) { |
| 828 | + if (!hasKey(a, property) && hasKey(b, property)) { |
| 829 | + mismatchKeys.push("expected has key '" + property + "', but missing from actual."); |
| 830 | + } |
| 831 | + } |
| 832 | + for (property in a) { |
| 833 | + if (!hasKey(b, property) && hasKey(a, property)) { |
| 834 | + mismatchKeys.push("expected missing key '" + property + "', but present in actual."); |
| 835 | + } |
| 836 | + } |
| 837 | + for (property in b) { |
| 838 | + if (property == '__Jasmine_been_here_before__') continue; |
| 839 | + if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) { |
| 840 | + mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual."); |
| 841 | + } |
| 842 | + } |
| 843 | + |
| 844 | + if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) { |
| 845 | + mismatchValues.push("arrays were not the same length"); |
| 846 | + } |
| 847 | + |
| 848 | + delete a.__Jasmine_been_here_before__; |
| 849 | + delete b.__Jasmine_been_here_before__; |
| 850 | + return (mismatchKeys.length == 0 && mismatchValues.length == 0); |
| 851 | +}; |
| 852 | + |
| 853 | +jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { |
| 854 | + mismatchKeys = mismatchKeys || []; |
| 855 | + mismatchValues = mismatchValues || []; |
| 856 | + |
| 857 | + for (var i = 0; i < this.equalityTesters_.length; i++) { |
| 858 | + var equalityTester = this.equalityTesters_[i]; |
| 859 | + var result = equalityTester(a, b, this, mismatchKeys, mismatchValues); |
| 860 | + if (result !== jasmine.undefined) return result; |
| 861 | + } |
| 862 | + |
| 863 | + if (a === b) return true; |
| 864 | + |
| 865 | + if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) { |
| 866 | + return (a == jasmine.undefined && b == jasmine.undefined); |
| 867 | + } |
| 868 | + |
| 869 | + if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { |
| 870 | + return a === b; |
| 871 | + } |
| 872 | + |
| 873 | + if (a instanceof Date && b instanceof Date) { |
| 874 | + return a.getTime() == b.getTime(); |
| 875 | + } |
| 876 | + |
| 877 | + if (a instanceof jasmine.Matchers.Any) { |
| 878 | + return a.matches(b); |
| 879 | + } |
| 880 | + |
| 881 | + if (b instanceof jasmine.Matchers.Any) { |
| 882 | + return b.matches(a); |
| 883 | + } |
| 884 | + |
| 885 | + if (jasmine.isString_(a) && jasmine.isString_(b)) { |
| 886 | + return (a == b); |
| 887 | + } |
| 888 | + |
| 889 | + if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) { |
| 890 | + return (a == b); |
| 891 | + } |
| 892 | + |
| 893 | + if (typeof a === "object" && typeof b === "object") { |
| 894 | + return this.compareObjects_(a, b, mismatchKeys, mismatchValues); |
| 895 | + } |
| 896 | + |
| 897 | + //Straight check |
| 898 | + return (a === b); |
| 899 | +}; |
| 900 | + |
| 901 | +jasmine.Env.prototype.contains_ = function(haystack, needle) { |
| 902 | + if (jasmine.isArray_(haystack)) { |
| 903 | + for (var i = 0; i < haystack.length; i++) { |
| 904 | + if (this.equals_(haystack[i], needle)) return true; |
| 905 | + } |
| 906 | + return false; |
| 907 | + } |
| 908 | + return haystack.indexOf(needle) >= 0; |
| 909 | +}; |
| 910 | + |
| 911 | +jasmine.Env.prototype.addEqualityTester = function(equalityTester) { |
| 912 | + this.equalityTesters_.push(equalityTester); |
| 913 | +}; |
| 914 | +/** No-op base class for Jasmine reporters. |
| 915 | + * |
| 916 | + * @constructor |
| 917 | + */ |
| 918 | +jasmine.Reporter = function() { |
| 919 | +}; |
| 920 | + |
| 921 | +//noinspection JSUnusedLocalSymbols |
| 922 | +jasmine.Reporter.prototype.reportRunnerStarting = function(runner) { |
| 923 | +}; |
| 924 | + |
| 925 | +//noinspection JSUnusedLocalSymbols |
| 926 | +jasmine.Reporter.prototype.reportRunnerResults = function(runner) { |
| 927 | +}; |
| 928 | + |
| 929 | +//noinspection JSUnusedLocalSymbols |
| 930 | +jasmine.Reporter.prototype.reportSuiteResults = function(suite) { |
| 931 | +}; |
| 932 | + |
| 933 | +//noinspection JSUnusedLocalSymbols |
| 934 | +jasmine.Reporter.prototype.reportSpecStarting = function(spec) { |
| 935 | +}; |
| 936 | + |
| 937 | +//noinspection JSUnusedLocalSymbols |
| 938 | +jasmine.Reporter.prototype.reportSpecResults = function(spec) { |
| 939 | +}; |
| 940 | + |
| 941 | +//noinspection JSUnusedLocalSymbols |
| 942 | +jasmine.Reporter.prototype.log = function(str) { |
| 943 | +}; |
| 944 | + |
| 945 | +/** |
| 946 | + * Blocks are functions with executable code that make up a spec. |
| 947 | + * |
| 948 | + * @constructor |
| 949 | + * @param {jasmine.Env} env |
| 950 | + * @param {Function} func |
| 951 | + * @param {jasmine.Spec} spec |
| 952 | + */ |
| 953 | +jasmine.Block = function(env, func, spec) { |
| 954 | + this.env = env; |
| 955 | + this.func = func; |
| 956 | + this.spec = spec; |
| 957 | +}; |
| 958 | + |
| 959 | +jasmine.Block.prototype.execute = function(onComplete) { |
| 960 | + try { |
| 961 | + this.func.apply(this.spec); |
| 962 | + } catch (e) { |
| 963 | + this.spec.fail(e); |
| 964 | + } |
| 965 | + onComplete(); |
| 966 | +}; |
| 967 | +/** JavaScript API reporter. |
| 968 | + * |
| 969 | + * @constructor |
| 970 | + */ |
| 971 | +jasmine.JsApiReporter = function() { |
| 972 | + this.started = false; |
| 973 | + this.finished = false; |
| 974 | + this.suites_ = []; |
| 975 | + this.results_ = {}; |
| 976 | +}; |
| 977 | + |
| 978 | +jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) { |
| 979 | + this.started = true; |
| 980 | + var suites = runner.topLevelSuites(); |
| 981 | + for (var i = 0; i < suites.length; i++) { |
| 982 | + var suite = suites[i]; |
| 983 | + this.suites_.push(this.summarize_(suite)); |
| 984 | + } |
| 985 | +}; |
| 986 | + |
| 987 | +jasmine.JsApiReporter.prototype.suites = function() { |
| 988 | + return this.suites_; |
| 989 | +}; |
| 990 | + |
| 991 | +jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { |
| 992 | + var isSuite = suiteOrSpec instanceof jasmine.Suite; |
| 993 | + var summary = { |
| 994 | + id: suiteOrSpec.id, |
| 995 | + name: suiteOrSpec.description, |
| 996 | + type: isSuite ? 'suite' : 'spec', |
| 997 | + children: [] |
| 998 | + }; |
| 999 | + |
| 1000 | + if (isSuite) { |
| 1001 | + var children = suiteOrSpec.children(); |
| 1002 | + for (var i = 0; i < children.length; i++) { |
| 1003 | + summary.children.push(this.summarize_(children[i])); |
| 1004 | + } |
| 1005 | + } |
| 1006 | + return summary; |
| 1007 | +}; |
| 1008 | + |
| 1009 | +jasmine.JsApiReporter.prototype.results = function() { |
| 1010 | + return this.results_; |
| 1011 | +}; |
| 1012 | + |
| 1013 | +jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) { |
| 1014 | + return this.results_[specId]; |
| 1015 | +}; |
| 1016 | + |
| 1017 | +//noinspection JSUnusedLocalSymbols |
| 1018 | +jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) { |
| 1019 | + this.finished = true; |
| 1020 | +}; |
| 1021 | + |
| 1022 | +//noinspection JSUnusedLocalSymbols |
| 1023 | +jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) { |
| 1024 | +}; |
| 1025 | + |
| 1026 | +//noinspection JSUnusedLocalSymbols |
| 1027 | +jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) { |
| 1028 | + this.results_[spec.id] = { |
| 1029 | + messages: spec.results().getItems(), |
| 1030 | + result: spec.results().failedCount > 0 ? "failed" : "passed" |
| 1031 | + }; |
| 1032 | +}; |
| 1033 | + |
| 1034 | +//noinspection JSUnusedLocalSymbols |
| 1035 | +jasmine.JsApiReporter.prototype.log = function(str) { |
| 1036 | +}; |
| 1037 | + |
| 1038 | +jasmine.JsApiReporter.prototype.resultsForSpecs = function(specIds){ |
| 1039 | + var results = {}; |
| 1040 | + for (var i = 0; i < specIds.length; i++) { |
| 1041 | + var specId = specIds[i]; |
| 1042 | + results[specId] = this.summarizeResult_(this.results_[specId]); |
| 1043 | + } |
| 1044 | + return results; |
| 1045 | +}; |
| 1046 | + |
| 1047 | +jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){ |
| 1048 | + var summaryMessages = []; |
| 1049 | + var messagesLength = result.messages.length; |
| 1050 | + for (var messageIndex = 0; messageIndex < messagesLength; messageIndex++) { |
| 1051 | + var resultMessage = result.messages[messageIndex]; |
| 1052 | + summaryMessages.push({ |
| 1053 | + text: resultMessage.type == 'log' ? resultMessage.toString() : jasmine.undefined, |
| 1054 | + passed: resultMessage.passed ? resultMessage.passed() : true, |
| 1055 | + type: resultMessage.type, |
| 1056 | + message: resultMessage.message, |
| 1057 | + trace: { |
| 1058 | + stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : jasmine.undefined |
| 1059 | + } |
| 1060 | + }); |
| 1061 | + } |
| 1062 | + |
| 1063 | + return { |
| 1064 | + result : result.result, |
| 1065 | + messages : summaryMessages |
| 1066 | + }; |
| 1067 | +}; |
| 1068 | + |
| 1069 | +/** |
| 1070 | + * @constructor |
| 1071 | + * @param {jasmine.Env} env |
| 1072 | + * @param actual |
| 1073 | + * @param {jasmine.Spec} spec |
| 1074 | + */ |
| 1075 | +jasmine.Matchers = function(env, actual, spec, opt_isNot) { |
| 1076 | + this.env = env; |
| 1077 | + this.actual = actual; |
| 1078 | + this.spec = spec; |
| 1079 | + this.isNot = opt_isNot || false; |
| 1080 | + this.reportWasCalled_ = false; |
| 1081 | +}; |
| 1082 | + |
| 1083 | +// todo: @deprecated as of Jasmine 0.11, remove soon [xw] |
| 1084 | +jasmine.Matchers.pp = function(str) { |
| 1085 | + throw new Error("jasmine.Matchers.pp() is no longer supported, please use jasmine.pp() instead!"); |
| 1086 | +}; |
| 1087 | + |
| 1088 | +// todo: @deprecated Deprecated as of Jasmine 0.10. Rewrite your custom matchers to return true or false. [xw] |
| 1089 | +jasmine.Matchers.prototype.report = function(result, failing_message, details) { |
| 1090 | + throw new Error("As of jasmine 0.11, custom matchers must be implemented differently -- please see jasmine docs"); |
| 1091 | +}; |
| 1092 | + |
| 1093 | +jasmine.Matchers.wrapInto_ = function(prototype, matchersClass) { |
| 1094 | + for (var methodName in prototype) { |
| 1095 | + if (methodName == 'report') continue; |
| 1096 | + var orig = prototype[methodName]; |
| 1097 | + matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig); |
| 1098 | + } |
| 1099 | +}; |
| 1100 | + |
| 1101 | +jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { |
| 1102 | + return function() { |
| 1103 | + var matcherArgs = jasmine.util.argsToArray(arguments); |
| 1104 | + var result = matcherFunction.apply(this, arguments); |
| 1105 | + |
| 1106 | + if (this.isNot) { |
| 1107 | + result = !result; |
| 1108 | + } |
| 1109 | + |
| 1110 | + if (this.reportWasCalled_) return result; |
| 1111 | + |
| 1112 | + var message; |
| 1113 | + if (!result) { |
| 1114 | + if (this.message) { |
| 1115 | + message = this.message.apply(this, arguments); |
| 1116 | + if (jasmine.isArray_(message)) { |
| 1117 | + message = message[this.isNot ? 1 : 0]; |
| 1118 | + } |
| 1119 | + } else { |
| 1120 | + var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); }); |
| 1121 | + message = "Expected " + jasmine.pp(this.actual) + (this.isNot ? " not " : " ") + englishyPredicate; |
| 1122 | + if (matcherArgs.length > 0) { |
| 1123 | + for (var i = 0; i < matcherArgs.length; i++) { |
| 1124 | + if (i > 0) message += ","; |
| 1125 | + message += " " + jasmine.pp(matcherArgs[i]); |
| 1126 | + } |
| 1127 | + } |
| 1128 | + message += "."; |
| 1129 | + } |
| 1130 | + } |
| 1131 | + var expectationResult = new jasmine.ExpectationResult({ |
| 1132 | + matcherName: matcherName, |
| 1133 | + passed: result, |
| 1134 | + expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0], |
| 1135 | + actual: this.actual, |
| 1136 | + message: message |
| 1137 | + }); |
| 1138 | + this.spec.addMatcherResult(expectationResult); |
| 1139 | + return result; |
| 1140 | + }; |
| 1141 | +}; |
| 1142 | + |
| 1143 | + |
| 1144 | + |
| 1145 | + |
| 1146 | +/** |
| 1147 | + * toBe: compares the actual to the expected using === |
| 1148 | + * @param expected |
| 1149 | + */ |
| 1150 | +jasmine.Matchers.prototype.toBe = function(expected) { |
| 1151 | + return this.actual === expected; |
| 1152 | +}; |
| 1153 | + |
| 1154 | +/** |
| 1155 | + * toNotBe: compares the actual to the expected using !== |
| 1156 | + * @param expected |
| 1157 | + */ |
| 1158 | +jasmine.Matchers.prototype.toNotBe = function(expected) { |
| 1159 | + return this.actual !== expected; |
| 1160 | +}; |
| 1161 | + |
| 1162 | +/** |
| 1163 | + * toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. |
| 1164 | + * |
| 1165 | + * @param expected |
| 1166 | + */ |
| 1167 | +jasmine.Matchers.prototype.toEqual = function(expected) { |
| 1168 | + return this.env.equals_(this.actual, expected); |
| 1169 | +}; |
| 1170 | + |
| 1171 | +/** |
| 1172 | + * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual |
| 1173 | + * @param expected |
| 1174 | + */ |
| 1175 | +jasmine.Matchers.prototype.toNotEqual = function(expected) { |
| 1176 | + return !this.env.equals_(this.actual, expected); |
| 1177 | +}; |
| 1178 | + |
| 1179 | +/** |
| 1180 | + * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes |
| 1181 | + * a pattern or a String. |
| 1182 | + * |
| 1183 | + * @param expected |
| 1184 | + */ |
| 1185 | +jasmine.Matchers.prototype.toMatch = function(expected) { |
| 1186 | + return new RegExp(expected).test(this.actual); |
| 1187 | +}; |
| 1188 | + |
| 1189 | +/** |
| 1190 | + * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch |
| 1191 | + * @param expected |
| 1192 | + */ |
| 1193 | +jasmine.Matchers.prototype.toNotMatch = function(expected) { |
| 1194 | + return !(new RegExp(expected).test(this.actual)); |
| 1195 | +}; |
| 1196 | + |
| 1197 | +/** |
| 1198 | + * Matcher that compares the actual to jasmine.undefined. |
| 1199 | + */ |
| 1200 | +jasmine.Matchers.prototype.toBeDefined = function() { |
| 1201 | + return (this.actual !== jasmine.undefined); |
| 1202 | +}; |
| 1203 | + |
| 1204 | +/** |
| 1205 | + * Matcher that compares the actual to jasmine.undefined. |
| 1206 | + */ |
| 1207 | +jasmine.Matchers.prototype.toBeUndefined = function() { |
| 1208 | + return (this.actual === jasmine.undefined); |
| 1209 | +}; |
| 1210 | + |
| 1211 | +/** |
| 1212 | + * Matcher that compares the actual to null. |
| 1213 | + */ |
| 1214 | +jasmine.Matchers.prototype.toBeNull = function() { |
| 1215 | + return (this.actual === null); |
| 1216 | +}; |
| 1217 | + |
| 1218 | +/** |
| 1219 | + * Matcher that boolean not-nots the actual. |
| 1220 | + */ |
| 1221 | +jasmine.Matchers.prototype.toBeTruthy = function() { |
| 1222 | + return !!this.actual; |
| 1223 | +}; |
| 1224 | + |
| 1225 | + |
| 1226 | +/** |
| 1227 | + * Matcher that boolean nots the actual. |
| 1228 | + */ |
| 1229 | +jasmine.Matchers.prototype.toBeFalsy = function() { |
| 1230 | + return !this.actual; |
| 1231 | +}; |
| 1232 | + |
| 1233 | + |
| 1234 | +/** @deprecated Use expect(xxx).toHaveBeenCalled() instead */ |
| 1235 | +jasmine.Matchers.prototype.wasCalled = function() { |
| 1236 | + return this.toHaveBeenCalled(); |
| 1237 | +}; |
| 1238 | + |
| 1239 | +/** |
| 1240 | + * Matcher that checks to see if the actual, a Jasmine spy, was called. |
| 1241 | + */ |
| 1242 | +jasmine.Matchers.prototype.toHaveBeenCalled = function() { |
| 1243 | + if (arguments.length > 0) { |
| 1244 | + throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith'); |
| 1245 | + } |
| 1246 | + |
| 1247 | + if (!jasmine.isSpy(this.actual)) { |
| 1248 | + throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); |
| 1249 | + } |
| 1250 | + |
| 1251 | + this.message = function() { |
| 1252 | + return "Expected spy " + this.actual.identity + " to have been called."; |
| 1253 | + }; |
| 1254 | + |
| 1255 | + return this.actual.wasCalled; |
| 1256 | +}; |
| 1257 | + |
| 1258 | +/** |
| 1259 | + * Matcher that checks to see if the actual, a Jasmine spy, was not called. |
| 1260 | + * |
| 1261 | + * @deprecated Use expect(xxx).not.toHaveBeenCalled() instead |
| 1262 | + */ |
| 1263 | +jasmine.Matchers.prototype.wasNotCalled = function() { |
| 1264 | + if (arguments.length > 0) { |
| 1265 | + throw new Error('wasNotCalled does not take arguments'); |
| 1266 | + } |
| 1267 | + |
| 1268 | + if (!jasmine.isSpy(this.actual)) { |
| 1269 | + throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); |
| 1270 | + } |
| 1271 | + |
| 1272 | + this.message = function() { |
| 1273 | + return "Expected spy " + this.actual.identity + " to not have been called."; |
| 1274 | + }; |
| 1275 | + |
| 1276 | + return !this.actual.wasCalled; |
| 1277 | +}; |
| 1278 | + |
| 1279 | +/** @deprecated Use expect(xxx).toHaveBeenCalledWith() instead */ |
| 1280 | +jasmine.Matchers.prototype.wasCalledWith = function() { |
| 1281 | + return this.toHaveBeenCalledWith.apply(this, arguments); |
| 1282 | +}; |
| 1283 | + |
| 1284 | +/** |
| 1285 | + * Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters. |
| 1286 | + * |
| 1287 | + * @example |
| 1288 | + * |
| 1289 | + */ |
| 1290 | +jasmine.Matchers.prototype.toHaveBeenCalledWith = function() { |
| 1291 | + var expectedArgs = jasmine.util.argsToArray(arguments); |
| 1292 | + if (!jasmine.isSpy(this.actual)) { |
| 1293 | + throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); |
| 1294 | + } |
| 1295 | + this.message = function() { |
| 1296 | + if (this.actual.callCount == 0) { |
| 1297 | + return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called."; |
| 1298 | + } else { |
| 1299 | + return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall); |
| 1300 | + } |
| 1301 | + }; |
| 1302 | + |
| 1303 | + return this.env.contains_(this.actual.argsForCall, expectedArgs); |
| 1304 | +}; |
| 1305 | + |
| 1306 | +/** @deprecated Use expect(xxx).not.toHaveBeenCalledWith() instead */ |
| 1307 | +jasmine.Matchers.prototype.wasNotCalledWith = function() { |
| 1308 | + var expectedArgs = jasmine.util.argsToArray(arguments); |
| 1309 | + if (!jasmine.isSpy(this.actual)) { |
| 1310 | + throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); |
| 1311 | + } |
| 1312 | + |
| 1313 | + this.message = function() { |
| 1314 | + return "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was"; |
| 1315 | + }; |
| 1316 | + |
| 1317 | + return !this.env.contains_(this.actual.argsForCall, expectedArgs); |
| 1318 | +}; |
| 1319 | + |
| 1320 | +/** |
| 1321 | + * Matcher that checks that the expected item is an element in the actual Array. |
| 1322 | + * |
| 1323 | + * @param {Object} expected |
| 1324 | + */ |
| 1325 | +jasmine.Matchers.prototype.toContain = function(expected) { |
| 1326 | + return this.env.contains_(this.actual, expected); |
| 1327 | +}; |
| 1328 | + |
| 1329 | +/** |
| 1330 | + * Matcher that checks that the expected item is NOT an element in the actual Array. |
| 1331 | + * |
| 1332 | + * @param {Object} expected |
| 1333 | + */ |
| 1334 | +jasmine.Matchers.prototype.toNotContain = function(expected) { |
| 1335 | + return !this.env.contains_(this.actual, expected); |
| 1336 | +}; |
| 1337 | + |
| 1338 | +jasmine.Matchers.prototype.toBeLessThan = function(expected) { |
| 1339 | + return this.actual < expected; |
| 1340 | +}; |
| 1341 | + |
| 1342 | +jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { |
| 1343 | + return this.actual > expected; |
| 1344 | +}; |
| 1345 | + |
| 1346 | +/** |
| 1347 | + * Matcher that checks that the expected exception was thrown by the actual. |
| 1348 | + * |
| 1349 | + * @param {String} expected |
| 1350 | + */ |
| 1351 | +jasmine.Matchers.prototype.toThrow = function(expected) { |
| 1352 | + var result = false; |
| 1353 | + var exception; |
| 1354 | + if (typeof this.actual != 'function') { |
| 1355 | + throw new Error('Actual is not a function'); |
| 1356 | + } |
| 1357 | + try { |
| 1358 | + this.actual(); |
| 1359 | + } catch (e) { |
| 1360 | + exception = e; |
| 1361 | + } |
| 1362 | + if (exception) { |
| 1363 | + result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected)); |
| 1364 | + } |
| 1365 | + |
| 1366 | + this.message = function() { |
| 1367 | + if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { |
| 1368 | + return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception].join(' '); |
| 1369 | + } else { |
| 1370 | + return "Expected function to throw an exception."; |
| 1371 | + } |
| 1372 | + }; |
| 1373 | + |
| 1374 | + return result; |
| 1375 | +}; |
| 1376 | + |
| 1377 | +jasmine.Matchers.Any = function(expectedClass) { |
| 1378 | + this.expectedClass = expectedClass; |
| 1379 | +}; |
| 1380 | + |
| 1381 | +jasmine.Matchers.Any.prototype.matches = function(other) { |
| 1382 | + if (this.expectedClass == String) { |
| 1383 | + return typeof other == 'string' || other instanceof String; |
| 1384 | + } |
| 1385 | + |
| 1386 | + if (this.expectedClass == Number) { |
| 1387 | + return typeof other == 'number' || other instanceof Number; |
| 1388 | + } |
| 1389 | + |
| 1390 | + if (this.expectedClass == Function) { |
| 1391 | + return typeof other == 'function' || other instanceof Function; |
| 1392 | + } |
| 1393 | + |
| 1394 | + if (this.expectedClass == Object) { |
| 1395 | + return typeof other == 'object'; |
| 1396 | + } |
| 1397 | + |
| 1398 | + return other instanceof this.expectedClass; |
| 1399 | +}; |
| 1400 | + |
| 1401 | +jasmine.Matchers.Any.prototype.toString = function() { |
| 1402 | + return '<jasmine.any(' + this.expectedClass + ')>'; |
| 1403 | +}; |
| 1404 | + |
| 1405 | +/** |
| 1406 | + * @constructor |
| 1407 | + */ |
| 1408 | +jasmine.MultiReporter = function() { |
| 1409 | + this.subReporters_ = []; |
| 1410 | +}; |
| 1411 | +jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter); |
| 1412 | + |
| 1413 | +jasmine.MultiReporter.prototype.addReporter = function(reporter) { |
| 1414 | + this.subReporters_.push(reporter); |
| 1415 | +}; |
| 1416 | + |
| 1417 | +(function() { |
| 1418 | + var functionNames = [ |
| 1419 | + "reportRunnerStarting", |
| 1420 | + "reportRunnerResults", |
| 1421 | + "reportSuiteResults", |
| 1422 | + "reportSpecStarting", |
| 1423 | + "reportSpecResults", |
| 1424 | + "log" |
| 1425 | + ]; |
| 1426 | + for (var i = 0; i < functionNames.length; i++) { |
| 1427 | + var functionName = functionNames[i]; |
| 1428 | + jasmine.MultiReporter.prototype[functionName] = (function(functionName) { |
| 1429 | + return function() { |
| 1430 | + for (var j = 0; j < this.subReporters_.length; j++) { |
| 1431 | + var subReporter = this.subReporters_[j]; |
| 1432 | + if (subReporter[functionName]) { |
| 1433 | + subReporter[functionName].apply(subReporter, arguments); |
| 1434 | + } |
| 1435 | + } |
| 1436 | + }; |
| 1437 | + })(functionName); |
| 1438 | + } |
| 1439 | +})(); |
| 1440 | +/** |
| 1441 | + * Holds results for a set of Jasmine spec. Allows for the results array to hold another jasmine.NestedResults |
| 1442 | + * |
| 1443 | + * @constructor |
| 1444 | + */ |
| 1445 | +jasmine.NestedResults = function() { |
| 1446 | + /** |
| 1447 | + * The total count of results |
| 1448 | + */ |
| 1449 | + this.totalCount = 0; |
| 1450 | + /** |
| 1451 | + * Number of passed results |
| 1452 | + */ |
| 1453 | + this.passedCount = 0; |
| 1454 | + /** |
| 1455 | + * Number of failed results |
| 1456 | + */ |
| 1457 | + this.failedCount = 0; |
| 1458 | + /** |
| 1459 | + * Was this suite/spec skipped? |
| 1460 | + */ |
| 1461 | + this.skipped = false; |
| 1462 | + /** |
| 1463 | + * @ignore |
| 1464 | + */ |
| 1465 | + this.items_ = []; |
| 1466 | +}; |
| 1467 | + |
| 1468 | +/** |
| 1469 | + * Roll up the result counts. |
| 1470 | + * |
| 1471 | + * @param result |
| 1472 | + */ |
| 1473 | +jasmine.NestedResults.prototype.rollupCounts = function(result) { |
| 1474 | + this.totalCount += result.totalCount; |
| 1475 | + this.passedCount += result.passedCount; |
| 1476 | + this.failedCount += result.failedCount; |
| 1477 | +}; |
| 1478 | + |
| 1479 | +/** |
| 1480 | + * Adds a log message. |
| 1481 | + * @param values Array of message parts which will be concatenated later. |
| 1482 | + */ |
| 1483 | +jasmine.NestedResults.prototype.log = function(values) { |
| 1484 | + this.items_.push(new jasmine.MessageResult(values)); |
| 1485 | +}; |
| 1486 | + |
| 1487 | +/** |
| 1488 | + * Getter for the results: message & results. |
| 1489 | + */ |
| 1490 | +jasmine.NestedResults.prototype.getItems = function() { |
| 1491 | + return this.items_; |
| 1492 | +}; |
| 1493 | + |
| 1494 | +/** |
| 1495 | + * Adds a result, tracking counts (total, passed, & failed) |
| 1496 | + * @param {jasmine.ExpectationResult|jasmine.NestedResults} result |
| 1497 | + */ |
| 1498 | +jasmine.NestedResults.prototype.addResult = function(result) { |
| 1499 | + if (result.type != 'log') { |
| 1500 | + if (result.items_) { |
| 1501 | + this.rollupCounts(result); |
| 1502 | + } else { |
| 1503 | + this.totalCount++; |
| 1504 | + if (result.passed()) { |
| 1505 | + this.passedCount++; |
| 1506 | + } else { |
| 1507 | + this.failedCount++; |
| 1508 | + } |
| 1509 | + } |
| 1510 | + } |
| 1511 | + this.items_.push(result); |
| 1512 | +}; |
| 1513 | + |
| 1514 | +/** |
| 1515 | + * @returns {Boolean} True if <b>everything</b> below passed |
| 1516 | + */ |
| 1517 | +jasmine.NestedResults.prototype.passed = function() { |
| 1518 | + return this.passedCount === this.totalCount; |
| 1519 | +}; |
| 1520 | +/** |
| 1521 | + * Base class for pretty printing for expectation results. |
| 1522 | + */ |
| 1523 | +jasmine.PrettyPrinter = function() { |
| 1524 | + this.ppNestLevel_ = 0; |
| 1525 | +}; |
| 1526 | + |
| 1527 | +/** |
| 1528 | + * Formats a value in a nice, human-readable string. |
| 1529 | + * |
| 1530 | + * @param value |
| 1531 | + */ |
| 1532 | +jasmine.PrettyPrinter.prototype.format = function(value) { |
| 1533 | + if (this.ppNestLevel_ > 40) { |
| 1534 | + throw new Error('jasmine.PrettyPrinter: format() nested too deeply!'); |
| 1535 | + } |
| 1536 | + |
| 1537 | + this.ppNestLevel_++; |
| 1538 | + try { |
| 1539 | + if (value === jasmine.undefined) { |
| 1540 | + this.emitScalar('undefined'); |
| 1541 | + } else if (value === null) { |
| 1542 | + this.emitScalar('null'); |
| 1543 | + } else if (value === jasmine.getGlobal()) { |
| 1544 | + this.emitScalar('<global>'); |
| 1545 | + } else if (value instanceof jasmine.Matchers.Any) { |
| 1546 | + this.emitScalar(value.toString()); |
| 1547 | + } else if (typeof value === 'string') { |
| 1548 | + this.emitString(value); |
| 1549 | + } else if (jasmine.isSpy(value)) { |
| 1550 | + this.emitScalar("spy on " + value.identity); |
| 1551 | + } else if (value instanceof RegExp) { |
| 1552 | + this.emitScalar(value.toString()); |
| 1553 | + } else if (typeof value === 'function') { |
| 1554 | + this.emitScalar('Function'); |
| 1555 | + } else if (typeof value.nodeType === 'number') { |
| 1556 | + this.emitScalar('HTMLNode'); |
| 1557 | + } else if (value instanceof Date) { |
| 1558 | + this.emitScalar('Date(' + value + ')'); |
| 1559 | + } else if (value.__Jasmine_been_here_before__) { |
| 1560 | + this.emitScalar('<circular reference: ' + (jasmine.isArray_(value) ? 'Array' : 'Object') + '>'); |
| 1561 | + } else if (jasmine.isArray_(value) || typeof value == 'object') { |
| 1562 | + value.__Jasmine_been_here_before__ = true; |
| 1563 | + if (jasmine.isArray_(value)) { |
| 1564 | + this.emitArray(value); |
| 1565 | + } else { |
| 1566 | + this.emitObject(value); |
| 1567 | + } |
| 1568 | + delete value.__Jasmine_been_here_before__; |
| 1569 | + } else { |
| 1570 | + this.emitScalar(value.toString()); |
| 1571 | + } |
| 1572 | + } finally { |
| 1573 | + this.ppNestLevel_--; |
| 1574 | + } |
| 1575 | +}; |
| 1576 | + |
| 1577 | +jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) { |
| 1578 | + for (var property in obj) { |
| 1579 | + if (property == '__Jasmine_been_here_before__') continue; |
| 1580 | + fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) != null) : false); |
| 1581 | + } |
| 1582 | +}; |
| 1583 | + |
| 1584 | +jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_; |
| 1585 | +jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_; |
| 1586 | +jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_; |
| 1587 | +jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_; |
| 1588 | + |
| 1589 | +jasmine.StringPrettyPrinter = function() { |
| 1590 | + jasmine.PrettyPrinter.call(this); |
| 1591 | + |
| 1592 | + this.string = ''; |
| 1593 | +}; |
| 1594 | +jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter); |
| 1595 | + |
| 1596 | +jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) { |
| 1597 | + this.append(value); |
| 1598 | +}; |
| 1599 | + |
| 1600 | +jasmine.StringPrettyPrinter.prototype.emitString = function(value) { |
| 1601 | + this.append("'" + value + "'"); |
| 1602 | +}; |
| 1603 | + |
| 1604 | +jasmine.StringPrettyPrinter.prototype.emitArray = function(array) { |
| 1605 | + this.append('[ '); |
| 1606 | + for (var i = 0; i < array.length; i++) { |
| 1607 | + if (i > 0) { |
| 1608 | + this.append(', '); |
| 1609 | + } |
| 1610 | + this.format(array[i]); |
| 1611 | + } |
| 1612 | + this.append(' ]'); |
| 1613 | +}; |
| 1614 | + |
| 1615 | +jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) { |
| 1616 | + var self = this; |
| 1617 | + this.append('{ '); |
| 1618 | + var first = true; |
| 1619 | + |
| 1620 | + this.iterateObject(obj, function(property, isGetter) { |
| 1621 | + if (first) { |
| 1622 | + first = false; |
| 1623 | + } else { |
| 1624 | + self.append(', '); |
| 1625 | + } |
| 1626 | + |
| 1627 | + self.append(property); |
| 1628 | + self.append(' : '); |
| 1629 | + if (isGetter) { |
| 1630 | + self.append('<getter>'); |
| 1631 | + } else { |
| 1632 | + self.format(obj[property]); |
| 1633 | + } |
| 1634 | + }); |
| 1635 | + |
| 1636 | + this.append(' }'); |
| 1637 | +}; |
| 1638 | + |
| 1639 | +jasmine.StringPrettyPrinter.prototype.append = function(value) { |
| 1640 | + this.string += value; |
| 1641 | +}; |
| 1642 | +jasmine.Queue = function(env) { |
| 1643 | + this.env = env; |
| 1644 | + this.blocks = []; |
| 1645 | + this.running = false; |
| 1646 | + this.index = 0; |
| 1647 | + this.offset = 0; |
| 1648 | +}; |
| 1649 | + |
| 1650 | +jasmine.Queue.prototype.addBefore = function(block) { |
| 1651 | + this.blocks.unshift(block); |
| 1652 | +}; |
| 1653 | + |
| 1654 | +jasmine.Queue.prototype.add = function(block) { |
| 1655 | + this.blocks.push(block); |
| 1656 | +}; |
| 1657 | + |
| 1658 | +jasmine.Queue.prototype.insertNext = function(block) { |
| 1659 | + this.blocks.splice((this.index + this.offset + 1), 0, block); |
| 1660 | + this.offset++; |
| 1661 | +}; |
| 1662 | + |
| 1663 | +jasmine.Queue.prototype.start = function(onComplete) { |
| 1664 | + this.running = true; |
| 1665 | + this.onComplete = onComplete; |
| 1666 | + this.next_(); |
| 1667 | +}; |
| 1668 | + |
| 1669 | +jasmine.Queue.prototype.isRunning = function() { |
| 1670 | + return this.running; |
| 1671 | +}; |
| 1672 | + |
| 1673 | +jasmine.Queue.LOOP_DONT_RECURSE = true; |
| 1674 | + |
| 1675 | +jasmine.Queue.prototype.next_ = function() { |
| 1676 | + var self = this; |
| 1677 | + var goAgain = true; |
| 1678 | + |
| 1679 | + while (goAgain) { |
| 1680 | + goAgain = false; |
| 1681 | + |
| 1682 | + if (self.index < self.blocks.length) { |
| 1683 | + var calledSynchronously = true; |
| 1684 | + var completedSynchronously = false; |
| 1685 | + |
| 1686 | + var onComplete = function () { |
| 1687 | + if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) { |
| 1688 | + completedSynchronously = true; |
| 1689 | + return; |
| 1690 | + } |
| 1691 | + |
| 1692 | + self.offset = 0; |
| 1693 | + self.index++; |
| 1694 | + |
| 1695 | + var now = new Date().getTime(); |
| 1696 | + if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { |
| 1697 | + self.env.lastUpdate = now; |
| 1698 | + self.env.setTimeout(function() { |
| 1699 | + self.next_(); |
| 1700 | + }, 0); |
| 1701 | + } else { |
| 1702 | + if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) { |
| 1703 | + goAgain = true; |
| 1704 | + } else { |
| 1705 | + self.next_(); |
| 1706 | + } |
| 1707 | + } |
| 1708 | + }; |
| 1709 | + self.blocks[self.index].execute(onComplete); |
| 1710 | + |
| 1711 | + calledSynchronously = false; |
| 1712 | + if (completedSynchronously) { |
| 1713 | + onComplete(); |
| 1714 | + } |
| 1715 | + |
| 1716 | + } else { |
| 1717 | + self.running = false; |
| 1718 | + if (self.onComplete) { |
| 1719 | + self.onComplete(); |
| 1720 | + } |
| 1721 | + } |
| 1722 | + } |
| 1723 | +}; |
| 1724 | + |
| 1725 | +jasmine.Queue.prototype.results = function() { |
| 1726 | + var results = new jasmine.NestedResults(); |
| 1727 | + for (var i = 0; i < this.blocks.length; i++) { |
| 1728 | + if (this.blocks[i].results) { |
| 1729 | + results.addResult(this.blocks[i].results()); |
| 1730 | + } |
| 1731 | + } |
| 1732 | + return results; |
| 1733 | +}; |
| 1734 | + |
| 1735 | + |
| 1736 | +/** |
| 1737 | + * Runner |
| 1738 | + * |
| 1739 | + * @constructor |
| 1740 | + * @param {jasmine.Env} env |
| 1741 | + */ |
| 1742 | +jasmine.Runner = function(env) { |
| 1743 | + var self = this; |
| 1744 | + self.env = env; |
| 1745 | + self.queue = new jasmine.Queue(env); |
| 1746 | + self.before_ = []; |
| 1747 | + self.after_ = []; |
| 1748 | + self.suites_ = []; |
| 1749 | +}; |
| 1750 | + |
| 1751 | +jasmine.Runner.prototype.execute = function() { |
| 1752 | + var self = this; |
| 1753 | + if (self.env.reporter.reportRunnerStarting) { |
| 1754 | + self.env.reporter.reportRunnerStarting(this); |
| 1755 | + } |
| 1756 | + self.queue.start(function () { |
| 1757 | + self.finishCallback(); |
| 1758 | + }); |
| 1759 | +}; |
| 1760 | + |
| 1761 | +jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) { |
| 1762 | + beforeEachFunction.typeName = 'beforeEach'; |
| 1763 | + this.before_.splice(0,0,beforeEachFunction); |
| 1764 | +}; |
| 1765 | + |
| 1766 | +jasmine.Runner.prototype.afterEach = function(afterEachFunction) { |
| 1767 | + afterEachFunction.typeName = 'afterEach'; |
| 1768 | + this.after_.splice(0,0,afterEachFunction); |
| 1769 | +}; |
| 1770 | + |
| 1771 | + |
| 1772 | +jasmine.Runner.prototype.finishCallback = function() { |
| 1773 | + this.env.reporter.reportRunnerResults(this); |
| 1774 | +}; |
| 1775 | + |
| 1776 | +jasmine.Runner.prototype.addSuite = function(suite) { |
| 1777 | + this.suites_.push(suite); |
| 1778 | +}; |
| 1779 | + |
| 1780 | +jasmine.Runner.prototype.add = function(block) { |
| 1781 | + if (block instanceof jasmine.Suite) { |
| 1782 | + this.addSuite(block); |
| 1783 | + } |
| 1784 | + this.queue.add(block); |
| 1785 | +}; |
| 1786 | + |
| 1787 | +jasmine.Runner.prototype.specs = function () { |
| 1788 | + var suites = this.suites(); |
| 1789 | + var specs = []; |
| 1790 | + for (var i = 0; i < suites.length; i++) { |
| 1791 | + specs = specs.concat(suites[i].specs()); |
| 1792 | + } |
| 1793 | + return specs; |
| 1794 | +}; |
| 1795 | + |
| 1796 | +jasmine.Runner.prototype.suites = function() { |
| 1797 | + return this.suites_; |
| 1798 | +}; |
| 1799 | + |
| 1800 | +jasmine.Runner.prototype.topLevelSuites = function() { |
| 1801 | + var topLevelSuites = []; |
| 1802 | + for (var i = 0; i < this.suites_.length; i++) { |
| 1803 | + if (!this.suites_[i].parentSuite) { |
| 1804 | + topLevelSuites.push(this.suites_[i]); |
| 1805 | + } |
| 1806 | + } |
| 1807 | + return topLevelSuites; |
| 1808 | +}; |
| 1809 | + |
| 1810 | +jasmine.Runner.prototype.results = function() { |
| 1811 | + return this.queue.results(); |
| 1812 | +}; |
| 1813 | +/** |
| 1814 | + * Internal representation of a Jasmine specification, or test. |
| 1815 | + * |
| 1816 | + * @constructor |
| 1817 | + * @param {jasmine.Env} env |
| 1818 | + * @param {jasmine.Suite} suite |
| 1819 | + * @param {String} description |
| 1820 | + */ |
| 1821 | +jasmine.Spec = function(env, suite, description) { |
| 1822 | + if (!env) { |
| 1823 | + throw new Error('jasmine.Env() required'); |
| 1824 | + } |
| 1825 | + if (!suite) { |
| 1826 | + throw new Error('jasmine.Suite() required'); |
| 1827 | + } |
| 1828 | + var spec = this; |
| 1829 | + spec.id = env.nextSpecId ? env.nextSpecId() : null; |
| 1830 | + spec.env = env; |
| 1831 | + spec.suite = suite; |
| 1832 | + spec.description = description; |
| 1833 | + spec.queue = new jasmine.Queue(env); |
| 1834 | + |
| 1835 | + spec.afterCallbacks = []; |
| 1836 | + spec.spies_ = []; |
| 1837 | + |
| 1838 | + spec.results_ = new jasmine.NestedResults(); |
| 1839 | + spec.results_.description = description; |
| 1840 | + spec.matchersClass = null; |
| 1841 | +}; |
| 1842 | + |
| 1843 | +jasmine.Spec.prototype.getFullName = function() { |
| 1844 | + return this.suite.getFullName() + ' ' + this.description + '.'; |
| 1845 | +}; |
| 1846 | + |
| 1847 | + |
| 1848 | +jasmine.Spec.prototype.results = function() { |
| 1849 | + return this.results_; |
| 1850 | +}; |
| 1851 | + |
| 1852 | +/** |
| 1853 | + * All parameters are pretty-printed and concatenated together, then written to the spec's output. |
| 1854 | + * |
| 1855 | + * Be careful not to leave calls to <code>jasmine.log</code> in production code. |
| 1856 | + */ |
| 1857 | +jasmine.Spec.prototype.log = function() { |
| 1858 | + return this.results_.log(arguments); |
| 1859 | +}; |
| 1860 | + |
| 1861 | +jasmine.Spec.prototype.runs = function (func) { |
| 1862 | + var block = new jasmine.Block(this.env, func, this); |
| 1863 | + this.addToQueue(block); |
| 1864 | + return this; |
| 1865 | +}; |
| 1866 | + |
| 1867 | +jasmine.Spec.prototype.addToQueue = function (block) { |
| 1868 | + if (this.queue.isRunning()) { |
| 1869 | + this.queue.insertNext(block); |
| 1870 | + } else { |
| 1871 | + this.queue.add(block); |
| 1872 | + } |
| 1873 | +}; |
| 1874 | + |
| 1875 | +/** |
| 1876 | + * @param {jasmine.ExpectationResult} result |
| 1877 | + */ |
| 1878 | +jasmine.Spec.prototype.addMatcherResult = function(result) { |
| 1879 | + this.results_.addResult(result); |
| 1880 | +}; |
| 1881 | + |
| 1882 | +jasmine.Spec.prototype.expect = function(actual) { |
| 1883 | + var positive = new (this.getMatchersClass_())(this.env, actual, this); |
| 1884 | + positive.not = new (this.getMatchersClass_())(this.env, actual, this, true); |
| 1885 | + return positive; |
| 1886 | +}; |
| 1887 | + |
| 1888 | +jasmine.Spec.prototype.waits = function(timeout) { |
| 1889 | + var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); |
| 1890 | + this.addToQueue(waitsFunc); |
| 1891 | + return this; |
| 1892 | +}; |
| 1893 | + |
| 1894 | +jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { |
| 1895 | + var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); |
| 1896 | + this.addToQueue(waitsForFunc); |
| 1897 | + return this; |
| 1898 | +}; |
| 1899 | + |
| 1900 | +jasmine.Spec.prototype.fail = function (e) { |
| 1901 | + var expectationResult = new jasmine.ExpectationResult({ |
| 1902 | + passed: false, |
| 1903 | + message: e ? jasmine.util.formatException(e) : 'Exception' |
| 1904 | + }); |
| 1905 | + this.results_.addResult(expectationResult); |
| 1906 | +}; |
| 1907 | + |
| 1908 | +jasmine.Spec.prototype.getMatchersClass_ = function() { |
| 1909 | + return this.matchersClass || this.env.matchersClass; |
| 1910 | +}; |
| 1911 | + |
| 1912 | +jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { |
| 1913 | + var parent = this.getMatchersClass_(); |
| 1914 | + var newMatchersClass = function() { |
| 1915 | + parent.apply(this, arguments); |
| 1916 | + }; |
| 1917 | + jasmine.util.inherit(newMatchersClass, parent); |
| 1918 | + jasmine.Matchers.wrapInto_(matchersPrototype, newMatchersClass); |
| 1919 | + this.matchersClass = newMatchersClass; |
| 1920 | +}; |
| 1921 | + |
| 1922 | +jasmine.Spec.prototype.finishCallback = function() { |
| 1923 | + this.env.reporter.reportSpecResults(this); |
| 1924 | +}; |
| 1925 | + |
| 1926 | +jasmine.Spec.prototype.finish = function(onComplete) { |
| 1927 | + this.removeAllSpies(); |
| 1928 | + this.finishCallback(); |
| 1929 | + if (onComplete) { |
| 1930 | + onComplete(); |
| 1931 | + } |
| 1932 | +}; |
| 1933 | + |
| 1934 | +jasmine.Spec.prototype.after = function(doAfter) { |
| 1935 | + if (this.queue.isRunning()) { |
| 1936 | + this.queue.add(new jasmine.Block(this.env, doAfter, this)); |
| 1937 | + } else { |
| 1938 | + this.afterCallbacks.unshift(doAfter); |
| 1939 | + } |
| 1940 | +}; |
| 1941 | + |
| 1942 | +jasmine.Spec.prototype.execute = function(onComplete) { |
| 1943 | + var spec = this; |
| 1944 | + if (!spec.env.specFilter(spec)) { |
| 1945 | + spec.results_.skipped = true; |
| 1946 | + spec.finish(onComplete); |
| 1947 | + return; |
| 1948 | + } |
| 1949 | + |
| 1950 | + this.env.reporter.reportSpecStarting(this); |
| 1951 | + |
| 1952 | + spec.env.currentSpec = spec; |
| 1953 | + |
| 1954 | + spec.addBeforesAndAftersToQueue(); |
| 1955 | + |
| 1956 | + spec.queue.start(function () { |
| 1957 | + spec.finish(onComplete); |
| 1958 | + }); |
| 1959 | +}; |
| 1960 | + |
| 1961 | +jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { |
| 1962 | + var runner = this.env.currentRunner(); |
| 1963 | + var i; |
| 1964 | + |
| 1965 | + for (var suite = this.suite; suite; suite = suite.parentSuite) { |
| 1966 | + for (i = 0; i < suite.before_.length; i++) { |
| 1967 | + this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); |
| 1968 | + } |
| 1969 | + } |
| 1970 | + for (i = 0; i < runner.before_.length; i++) { |
| 1971 | + this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); |
| 1972 | + } |
| 1973 | + for (i = 0; i < this.afterCallbacks.length; i++) { |
| 1974 | + this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); |
| 1975 | + } |
| 1976 | + for (suite = this.suite; suite; suite = suite.parentSuite) { |
| 1977 | + for (i = 0; i < suite.after_.length; i++) { |
| 1978 | + this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); |
| 1979 | + } |
| 1980 | + } |
| 1981 | + for (i = 0; i < runner.after_.length; i++) { |
| 1982 | + this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); |
| 1983 | + } |
| 1984 | +}; |
| 1985 | + |
| 1986 | +jasmine.Spec.prototype.explodes = function() { |
| 1987 | + throw 'explodes function should not have been called'; |
| 1988 | +}; |
| 1989 | + |
| 1990 | +jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { |
| 1991 | + if (obj == jasmine.undefined) { |
| 1992 | + throw "spyOn could not find an object to spy upon for " + methodName + "()"; |
| 1993 | + } |
| 1994 | + |
| 1995 | + if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) { |
| 1996 | + throw methodName + '() method does not exist'; |
| 1997 | + } |
| 1998 | + |
| 1999 | + if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { |
| 2000 | + throw new Error(methodName + ' has already been spied upon'); |
| 2001 | + } |
| 2002 | + |
| 2003 | + var spyObj = jasmine.createSpy(methodName); |
| 2004 | + |
| 2005 | + this.spies_.push(spyObj); |
| 2006 | + spyObj.baseObj = obj; |
| 2007 | + spyObj.methodName = methodName; |
| 2008 | + spyObj.originalValue = obj[methodName]; |
| 2009 | + |
| 2010 | + obj[methodName] = spyObj; |
| 2011 | + |
| 2012 | + return spyObj; |
| 2013 | +}; |
| 2014 | + |
| 2015 | +jasmine.Spec.prototype.removeAllSpies = function() { |
| 2016 | + for (var i = 0; i < this.spies_.length; i++) { |
| 2017 | + var spy = this.spies_[i]; |
| 2018 | + spy.baseObj[spy.methodName] = spy.originalValue; |
| 2019 | + } |
| 2020 | + this.spies_ = []; |
| 2021 | +}; |
| 2022 | + |
| 2023 | +/** |
| 2024 | + * Internal representation of a Jasmine suite. |
| 2025 | + * |
| 2026 | + * @constructor |
| 2027 | + * @param {jasmine.Env} env |
| 2028 | + * @param {String} description |
| 2029 | + * @param {Function} specDefinitions |
| 2030 | + * @param {jasmine.Suite} parentSuite |
| 2031 | + */ |
| 2032 | +jasmine.Suite = function(env, description, specDefinitions, parentSuite) { |
| 2033 | + var self = this; |
| 2034 | + self.id = env.nextSuiteId ? env.nextSuiteId() : null; |
| 2035 | + self.description = description; |
| 2036 | + self.queue = new jasmine.Queue(env); |
| 2037 | + self.parentSuite = parentSuite; |
| 2038 | + self.env = env; |
| 2039 | + self.before_ = []; |
| 2040 | + self.after_ = []; |
| 2041 | + self.children_ = []; |
| 2042 | + self.suites_ = []; |
| 2043 | + self.specs_ = []; |
| 2044 | +}; |
| 2045 | + |
| 2046 | +jasmine.Suite.prototype.getFullName = function() { |
| 2047 | + var fullName = this.description; |
| 2048 | + for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { |
| 2049 | + fullName = parentSuite.description + ' ' + fullName; |
| 2050 | + } |
| 2051 | + return fullName; |
| 2052 | +}; |
| 2053 | + |
| 2054 | +jasmine.Suite.prototype.finish = function(onComplete) { |
| 2055 | + this.env.reporter.reportSuiteResults(this); |
| 2056 | + this.finished = true; |
| 2057 | + if (typeof(onComplete) == 'function') { |
| 2058 | + onComplete(); |
| 2059 | + } |
| 2060 | +}; |
| 2061 | + |
| 2062 | +jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { |
| 2063 | + beforeEachFunction.typeName = 'beforeEach'; |
| 2064 | + this.before_.unshift(beforeEachFunction); |
| 2065 | +}; |
| 2066 | + |
| 2067 | +jasmine.Suite.prototype.afterEach = function(afterEachFunction) { |
| 2068 | + afterEachFunction.typeName = 'afterEach'; |
| 2069 | + this.after_.unshift(afterEachFunction); |
| 2070 | +}; |
| 2071 | + |
| 2072 | +jasmine.Suite.prototype.results = function() { |
| 2073 | + return this.queue.results(); |
| 2074 | +}; |
| 2075 | + |
| 2076 | +jasmine.Suite.prototype.add = function(suiteOrSpec) { |
| 2077 | + this.children_.push(suiteOrSpec); |
| 2078 | + if (suiteOrSpec instanceof jasmine.Suite) { |
| 2079 | + this.suites_.push(suiteOrSpec); |
| 2080 | + this.env.currentRunner().addSuite(suiteOrSpec); |
| 2081 | + } else { |
| 2082 | + this.specs_.push(suiteOrSpec); |
| 2083 | + } |
| 2084 | + this.queue.add(suiteOrSpec); |
| 2085 | +}; |
| 2086 | + |
| 2087 | +jasmine.Suite.prototype.specs = function() { |
| 2088 | + return this.specs_; |
| 2089 | +}; |
| 2090 | + |
| 2091 | +jasmine.Suite.prototype.suites = function() { |
| 2092 | + return this.suites_; |
| 2093 | +}; |
| 2094 | + |
| 2095 | +jasmine.Suite.prototype.children = function() { |
| 2096 | + return this.children_; |
| 2097 | +}; |
| 2098 | + |
| 2099 | +jasmine.Suite.prototype.execute = function(onComplete) { |
| 2100 | + var self = this; |
| 2101 | + this.queue.start(function () { |
| 2102 | + self.finish(onComplete); |
| 2103 | + }); |
| 2104 | +}; |
| 2105 | +jasmine.WaitsBlock = function(env, timeout, spec) { |
| 2106 | + this.timeout = timeout; |
| 2107 | + jasmine.Block.call(this, env, null, spec); |
| 2108 | +}; |
| 2109 | + |
| 2110 | +jasmine.util.inherit(jasmine.WaitsBlock, jasmine.Block); |
| 2111 | + |
| 2112 | +jasmine.WaitsBlock.prototype.execute = function (onComplete) { |
| 2113 | + this.env.reporter.log('>> Jasmine waiting for ' + this.timeout + ' ms...'); |
| 2114 | + this.env.setTimeout(function () { |
| 2115 | + onComplete(); |
| 2116 | + }, this.timeout); |
| 2117 | +}; |
| 2118 | +jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) { |
| 2119 | + this.timeout = timeout; |
| 2120 | + this.latchFunction = latchFunction; |
| 2121 | + this.message = message; |
| 2122 | + this.totalTimeSpentWaitingForLatch = 0; |
| 2123 | + jasmine.Block.call(this, env, null, spec); |
| 2124 | +}; |
| 2125 | + |
| 2126 | +jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block); |
| 2127 | + |
| 2128 | +jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100; |
| 2129 | + |
| 2130 | +jasmine.WaitsForBlock.prototype.execute = function (onComplete) { |
| 2131 | + var self = this; |
| 2132 | + self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen')); |
| 2133 | + var latchFunctionResult; |
| 2134 | + try { |
| 2135 | + latchFunctionResult = self.latchFunction.apply(self.spec); |
| 2136 | + } catch (e) { |
| 2137 | + self.spec.fail(e); |
| 2138 | + onComplete(); |
| 2139 | + return; |
| 2140 | + } |
| 2141 | + |
| 2142 | + if (latchFunctionResult) { |
| 2143 | + onComplete(); |
| 2144 | + } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) { |
| 2145 | + var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen'); |
| 2146 | + self.spec.fail({ |
| 2147 | + name: 'timeout', |
| 2148 | + message: message |
| 2149 | + }); |
| 2150 | + } else { |
| 2151 | + self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT; |
| 2152 | + self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT); |
| 2153 | + } |
| 2154 | +}; |
| 2155 | +// Mock setTimeout, clearTimeout |
| 2156 | +// Contributed by Pivotal Computer Systems, www.pivotalsf.com |
| 2157 | + |
| 2158 | +jasmine.FakeTimer = function() { |
| 2159 | + this.reset(); |
| 2160 | + |
| 2161 | + var self = this; |
| 2162 | + self.setTimeout = function(funcToCall, millis) { |
| 2163 | + self.timeoutsMade++; |
| 2164 | + self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); |
| 2165 | + return self.timeoutsMade; |
| 2166 | + }; |
| 2167 | + |
| 2168 | + self.setInterval = function(funcToCall, millis) { |
| 2169 | + self.timeoutsMade++; |
| 2170 | + self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); |
| 2171 | + return self.timeoutsMade; |
| 2172 | + }; |
| 2173 | + |
| 2174 | + self.clearTimeout = function(timeoutKey) { |
| 2175 | + self.scheduledFunctions[timeoutKey] = jasmine.undefined; |
| 2176 | + }; |
| 2177 | + |
| 2178 | + self.clearInterval = function(timeoutKey) { |
| 2179 | + self.scheduledFunctions[timeoutKey] = jasmine.undefined; |
| 2180 | + }; |
| 2181 | + |
| 2182 | +}; |
| 2183 | + |
| 2184 | +jasmine.FakeTimer.prototype.reset = function() { |
| 2185 | + this.timeoutsMade = 0; |
| 2186 | + this.scheduledFunctions = {}; |
| 2187 | + this.nowMillis = 0; |
| 2188 | +}; |
| 2189 | + |
| 2190 | +jasmine.FakeTimer.prototype.tick = function(millis) { |
| 2191 | + var oldMillis = this.nowMillis; |
| 2192 | + var newMillis = oldMillis + millis; |
| 2193 | + this.runFunctionsWithinRange(oldMillis, newMillis); |
| 2194 | + this.nowMillis = newMillis; |
| 2195 | +}; |
| 2196 | + |
| 2197 | +jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { |
| 2198 | + var scheduledFunc; |
| 2199 | + var funcsToRun = []; |
| 2200 | + for (var timeoutKey in this.scheduledFunctions) { |
| 2201 | + scheduledFunc = this.scheduledFunctions[timeoutKey]; |
| 2202 | + if (scheduledFunc != jasmine.undefined && |
| 2203 | + scheduledFunc.runAtMillis >= oldMillis && |
| 2204 | + scheduledFunc.runAtMillis <= nowMillis) { |
| 2205 | + funcsToRun.push(scheduledFunc); |
| 2206 | + this.scheduledFunctions[timeoutKey] = jasmine.undefined; |
| 2207 | + } |
| 2208 | + } |
| 2209 | + |
| 2210 | + if (funcsToRun.length > 0) { |
| 2211 | + funcsToRun.sort(function(a, b) { |
| 2212 | + return a.runAtMillis - b.runAtMillis; |
| 2213 | + }); |
| 2214 | + for (var i = 0; i < funcsToRun.length; ++i) { |
| 2215 | + try { |
| 2216 | + var funcToRun = funcsToRun[i]; |
| 2217 | + this.nowMillis = funcToRun.runAtMillis; |
| 2218 | + funcToRun.funcToCall(); |
| 2219 | + if (funcToRun.recurring) { |
| 2220 | + this.scheduleFunction(funcToRun.timeoutKey, |
| 2221 | + funcToRun.funcToCall, |
| 2222 | + funcToRun.millis, |
| 2223 | + true); |
| 2224 | + } |
| 2225 | + } catch(e) { |
| 2226 | + } |
| 2227 | + } |
| 2228 | + this.runFunctionsWithinRange(oldMillis, nowMillis); |
| 2229 | + } |
| 2230 | +}; |
| 2231 | + |
| 2232 | +jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { |
| 2233 | + this.scheduledFunctions[timeoutKey] = { |
| 2234 | + runAtMillis: this.nowMillis + millis, |
| 2235 | + funcToCall: funcToCall, |
| 2236 | + recurring: recurring, |
| 2237 | + timeoutKey: timeoutKey, |
| 2238 | + millis: millis |
| 2239 | + }; |
| 2240 | +}; |
| 2241 | + |
| 2242 | +/** |
| 2243 | + * @namespace |
| 2244 | + */ |
| 2245 | +jasmine.Clock = { |
| 2246 | + defaultFakeTimer: new jasmine.FakeTimer(), |
| 2247 | + |
| 2248 | + reset: function() { |
| 2249 | + jasmine.Clock.assertInstalled(); |
| 2250 | + jasmine.Clock.defaultFakeTimer.reset(); |
| 2251 | + }, |
| 2252 | + |
| 2253 | + tick: function(millis) { |
| 2254 | + jasmine.Clock.assertInstalled(); |
| 2255 | + jasmine.Clock.defaultFakeTimer.tick(millis); |
| 2256 | + }, |
| 2257 | + |
| 2258 | + runFunctionsWithinRange: function(oldMillis, nowMillis) { |
| 2259 | + jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); |
| 2260 | + }, |
| 2261 | + |
| 2262 | + scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { |
| 2263 | + jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); |
| 2264 | + }, |
| 2265 | + |
| 2266 | + useMock: function() { |
| 2267 | + if (!jasmine.Clock.isInstalled()) { |
| 2268 | + var spec = jasmine.getEnv().currentSpec; |
| 2269 | + spec.after(jasmine.Clock.uninstallMock); |
| 2270 | + |
| 2271 | + jasmine.Clock.installMock(); |
| 2272 | + } |
| 2273 | + }, |
| 2274 | + |
| 2275 | + installMock: function() { |
| 2276 | + jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; |
| 2277 | + }, |
| 2278 | + |
| 2279 | + uninstallMock: function() { |
| 2280 | + jasmine.Clock.assertInstalled(); |
| 2281 | + jasmine.Clock.installed = jasmine.Clock.real; |
| 2282 | + }, |
| 2283 | + |
| 2284 | + real: { |
| 2285 | + setTimeout: jasmine.getGlobal().setTimeout, |
| 2286 | + clearTimeout: jasmine.getGlobal().clearTimeout, |
| 2287 | + setInterval: jasmine.getGlobal().setInterval, |
| 2288 | + clearInterval: jasmine.getGlobal().clearInterval |
| 2289 | + }, |
| 2290 | + |
| 2291 | + assertInstalled: function() { |
| 2292 | + if (!jasmine.Clock.isInstalled()) { |
| 2293 | + throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); |
| 2294 | + } |
| 2295 | + }, |
| 2296 | + |
| 2297 | + isInstalled: function() { |
| 2298 | + return jasmine.Clock.installed == jasmine.Clock.defaultFakeTimer; |
| 2299 | + }, |
| 2300 | + |
| 2301 | + installed: null |
| 2302 | +}; |
| 2303 | +jasmine.Clock.installed = jasmine.Clock.real; |
| 2304 | + |
| 2305 | +//else for IE support |
| 2306 | +jasmine.getGlobal().setTimeout = function(funcToCall, millis) { |
| 2307 | + if (jasmine.Clock.installed.setTimeout.apply) { |
| 2308 | + return jasmine.Clock.installed.setTimeout.apply(this, arguments); |
| 2309 | + } else { |
| 2310 | + return jasmine.Clock.installed.setTimeout(funcToCall, millis); |
| 2311 | + } |
| 2312 | +}; |
| 2313 | + |
| 2314 | +jasmine.getGlobal().setInterval = function(funcToCall, millis) { |
| 2315 | + if (jasmine.Clock.installed.setInterval.apply) { |
| 2316 | + return jasmine.Clock.installed.setInterval.apply(this, arguments); |
| 2317 | + } else { |
| 2318 | + return jasmine.Clock.installed.setInterval(funcToCall, millis); |
| 2319 | + } |
| 2320 | +}; |
| 2321 | + |
| 2322 | +jasmine.getGlobal().clearTimeout = function(timeoutKey) { |
| 2323 | + if (jasmine.Clock.installed.clearTimeout.apply) { |
| 2324 | + return jasmine.Clock.installed.clearTimeout.apply(this, arguments); |
| 2325 | + } else { |
| 2326 | + return jasmine.Clock.installed.clearTimeout(timeoutKey); |
| 2327 | + } |
| 2328 | +}; |
| 2329 | + |
| 2330 | +jasmine.getGlobal().clearInterval = function(timeoutKey) { |
| 2331 | + if (jasmine.Clock.installed.clearTimeout.apply) { |
| 2332 | + return jasmine.Clock.installed.clearInterval.apply(this, arguments); |
| 2333 | + } else { |
| 2334 | + return jasmine.Clock.installed.clearInterval(timeoutKey); |
| 2335 | + } |
| 2336 | +}; |
| 2337 | + |
| 2338 | + |
| 2339 | +jasmine.version_= { |
| 2340 | + "major": 0, |
| 2341 | + "minor": 11, |
| 2342 | + "build": 1, |
| 2343 | + "revision": 1277514571 |
| 2344 | +}; |
Property changes on: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/jasmine-0.11.1/jasmine.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 2345 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/jasmine-0.11.1/jasmine-html.js |
— | — | @@ -0,0 +1,182 @@ |
| 2 | +jasmine.TrivialReporter = function(doc) { |
| 3 | + this.document = doc || document; |
| 4 | + this.suiteDivs = {}; |
| 5 | + this.logRunningSpecs = false; |
| 6 | +}; |
| 7 | + |
| 8 | +jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) { |
| 9 | + var el = document.createElement(type); |
| 10 | + |
| 11 | + for (var i = 2; i < arguments.length; i++) { |
| 12 | + var child = arguments[i]; |
| 13 | + |
| 14 | + if (typeof child === 'string') { |
| 15 | + el.appendChild(document.createTextNode(child)); |
| 16 | + } else { |
| 17 | + if (child) { el.appendChild(child); } |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + for (var attr in attrs) { |
| 22 | + if (attr == "className") { |
| 23 | + el[attr] = attrs[attr]; |
| 24 | + } else { |
| 25 | + el.setAttribute(attr, attrs[attr]); |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + return el; |
| 30 | +}; |
| 31 | + |
| 32 | +jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) { |
| 33 | + var showPassed, showSkipped; |
| 34 | + |
| 35 | + this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' }, |
| 36 | + this.createDom('div', { className: 'banner' }, |
| 37 | + this.createDom('div', { className: 'logo' }, |
| 38 | + "Jasmine", |
| 39 | + this.createDom('span', { className: 'version' }, runner.env.versionString())), |
| 40 | + this.createDom('div', { className: 'options' }, |
| 41 | + "Show ", |
| 42 | + showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }), |
| 43 | + this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "), |
| 44 | + showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }), |
| 45 | + this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped") |
| 46 | + ) |
| 47 | + ), |
| 48 | + |
| 49 | + this.runnerDiv = this.createDom('div', { className: 'runner running' }, |
| 50 | + this.createDom('a', { className: 'run_spec', href: '?' }, "run all"), |
| 51 | + this.runnerMessageSpan = this.createDom('span', {}, "Running..."), |
| 52 | + this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, "")) |
| 53 | + ); |
| 54 | + |
| 55 | + this.document.body.appendChild(this.outerDiv); |
| 56 | + |
| 57 | + var suites = runner.suites(); |
| 58 | + for (var i = 0; i < suites.length; i++) { |
| 59 | + var suite = suites[i]; |
| 60 | + var suiteDiv = this.createDom('div', { className: 'suite' }, |
| 61 | + this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"), |
| 62 | + this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description)); |
| 63 | + this.suiteDivs[suite.id] = suiteDiv; |
| 64 | + var parentDiv = this.outerDiv; |
| 65 | + if (suite.parentSuite) { |
| 66 | + parentDiv = this.suiteDivs[suite.parentSuite.id]; |
| 67 | + } |
| 68 | + parentDiv.appendChild(suiteDiv); |
| 69 | + } |
| 70 | + |
| 71 | + this.startedAt = new Date(); |
| 72 | + |
| 73 | + var self = this; |
| 74 | + showPassed.onchange = function(evt) { |
| 75 | + if (evt.target.checked) { |
| 76 | + self.outerDiv.className += ' show-passed'; |
| 77 | + } else { |
| 78 | + self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, ''); |
| 79 | + } |
| 80 | + }; |
| 81 | + |
| 82 | + showSkipped.onchange = function(evt) { |
| 83 | + if (evt.target.checked) { |
| 84 | + self.outerDiv.className += ' show-skipped'; |
| 85 | + } else { |
| 86 | + self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, ''); |
| 87 | + } |
| 88 | + }; |
| 89 | +}; |
| 90 | + |
| 91 | +jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) { |
| 92 | + var results = runner.results(); |
| 93 | + var className = (results.failedCount > 0) ? "runner failed" : "runner passed"; |
| 94 | + this.runnerDiv.setAttribute("class", className); |
| 95 | + //do it twice for IE |
| 96 | + this.runnerDiv.setAttribute("className", className); |
| 97 | + var specs = runner.specs(); |
| 98 | + var specCount = 0; |
| 99 | + for (var i = 0; i < specs.length; i++) { |
| 100 | + if (this.specFilter(specs[i])) { |
| 101 | + specCount++; |
| 102 | + } |
| 103 | + } |
| 104 | + var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s"); |
| 105 | + message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s"; |
| 106 | + this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild); |
| 107 | + |
| 108 | + this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString())); |
| 109 | +}; |
| 110 | + |
| 111 | +jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) { |
| 112 | + var results = suite.results(); |
| 113 | + var status = results.passed() ? 'passed' : 'failed'; |
| 114 | + if (results.totalCount == 0) { // todo: change this to check results.skipped |
| 115 | + status = 'skipped'; |
| 116 | + } |
| 117 | + this.suiteDivs[suite.id].className += " " + status; |
| 118 | +}; |
| 119 | + |
| 120 | +jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) { |
| 121 | + if (this.logRunningSpecs) { |
| 122 | + this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...'); |
| 123 | + } |
| 124 | +}; |
| 125 | + |
| 126 | +jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) { |
| 127 | + var results = spec.results(); |
| 128 | + var status = results.passed() ? 'passed' : 'failed'; |
| 129 | + if (results.skipped) { |
| 130 | + status = 'skipped'; |
| 131 | + } |
| 132 | + var specDiv = this.createDom('div', { className: 'spec ' + status }, |
| 133 | + this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"), |
| 134 | + this.createDom('a', { |
| 135 | + className: 'description', |
| 136 | + href: '?spec=' + encodeURIComponent(spec.getFullName()), |
| 137 | + title: spec.getFullName() |
| 138 | + }, spec.description)); |
| 139 | + |
| 140 | + |
| 141 | + var resultItems = results.getItems(); |
| 142 | + var messagesDiv = this.createDom('div', { className: 'messages' }); |
| 143 | + for (var i = 0; i < resultItems.length; i++) { |
| 144 | + var result = resultItems[i]; |
| 145 | + |
| 146 | + if (result.type == 'log') { |
| 147 | + messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString())); |
| 148 | + } else if (result.type == 'expect' && result.passed && !result.passed()) { |
| 149 | + messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message)); |
| 150 | + |
| 151 | + if (result.trace.stack) { |
| 152 | + messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack)); |
| 153 | + } |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + if (messagesDiv.childNodes.length > 0) { |
| 158 | + specDiv.appendChild(messagesDiv); |
| 159 | + } |
| 160 | + |
| 161 | + this.suiteDivs[spec.suite.id].appendChild(specDiv); |
| 162 | +}; |
| 163 | + |
| 164 | +jasmine.TrivialReporter.prototype.log = function() { |
| 165 | + var console = jasmine.getGlobal().console; |
| 166 | + if (console && console.log) console.log.apply(console, arguments); |
| 167 | +}; |
| 168 | + |
| 169 | +jasmine.TrivialReporter.prototype.getLocation = function() { |
| 170 | + return this.document.location; |
| 171 | +}; |
| 172 | + |
| 173 | +jasmine.TrivialReporter.prototype.specFilter = function(spec) { |
| 174 | + var paramMap = {}; |
| 175 | + var params = this.getLocation().search.substring(1).split('&'); |
| 176 | + for (var i = 0; i < params.length; i++) { |
| 177 | + var p = params[i].split('='); |
| 178 | + paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]); |
| 179 | + } |
| 180 | + |
| 181 | + if (!paramMap["spec"]) return true; |
| 182 | + return spec.getFullName().indexOf(paramMap["spec"]) == 0; |
| 183 | +}; |
Property changes on: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/jasmine-0.11.1/jasmine-html.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 184 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/jasmine-0.11.1/jasmine.css |
— | — | @@ -0,0 +1,166 @@ |
| 2 | +body { |
| 3 | + font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif; |
| 4 | +} |
| 5 | + |
| 6 | + |
| 7 | +.jasmine_reporter a:visited, .jasmine_reporter a { |
| 8 | + color: #303; |
| 9 | +} |
| 10 | + |
| 11 | +.jasmine_reporter a:hover, .jasmine_reporter a:active { |
| 12 | + color: blue; |
| 13 | +} |
| 14 | + |
| 15 | +.run_spec { |
| 16 | + float:right; |
| 17 | + padding-right: 5px; |
| 18 | + font-size: .8em; |
| 19 | + text-decoration: none; |
| 20 | +} |
| 21 | + |
| 22 | +.jasmine_reporter { |
| 23 | + margin: 0 5px; |
| 24 | +} |
| 25 | + |
| 26 | +.banner { |
| 27 | + color: #303; |
| 28 | + background-color: #fef; |
| 29 | + padding: 5px; |
| 30 | +} |
| 31 | + |
| 32 | +.logo { |
| 33 | + float: left; |
| 34 | + font-size: 1.1em; |
| 35 | + padding-left: 5px; |
| 36 | +} |
| 37 | + |
| 38 | +.logo .version { |
| 39 | + font-size: .6em; |
| 40 | + padding-left: 1em; |
| 41 | +} |
| 42 | + |
| 43 | +.runner.running { |
| 44 | + background-color: yellow; |
| 45 | +} |
| 46 | + |
| 47 | + |
| 48 | +.options { |
| 49 | + text-align: right; |
| 50 | + font-size: .8em; |
| 51 | +} |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +.suite { |
| 57 | + border: 1px outset gray; |
| 58 | + margin: 5px 0; |
| 59 | + padding-left: 1em; |
| 60 | +} |
| 61 | + |
| 62 | +.suite .suite { |
| 63 | + margin: 5px; |
| 64 | +} |
| 65 | + |
| 66 | +.suite.passed { |
| 67 | + background-color: #dfd; |
| 68 | +} |
| 69 | + |
| 70 | +.suite.failed { |
| 71 | + background-color: #fdd; |
| 72 | +} |
| 73 | + |
| 74 | +.spec { |
| 75 | + margin: 5px; |
| 76 | + padding-left: 1em; |
| 77 | + clear: both; |
| 78 | +} |
| 79 | + |
| 80 | +.spec.failed, .spec.passed, .spec.skipped { |
| 81 | + padding-bottom: 5px; |
| 82 | + border: 1px solid gray; |
| 83 | +} |
| 84 | + |
| 85 | +.spec.failed { |
| 86 | + background-color: #fbb; |
| 87 | + border-color: red; |
| 88 | +} |
| 89 | + |
| 90 | +.spec.passed { |
| 91 | + background-color: #bfb; |
| 92 | + border-color: green; |
| 93 | +} |
| 94 | + |
| 95 | +.spec.skipped { |
| 96 | + background-color: #bbb; |
| 97 | +} |
| 98 | + |
| 99 | +.messages { |
| 100 | + border-left: 1px dashed gray; |
| 101 | + padding-left: 1em; |
| 102 | + padding-right: 1em; |
| 103 | +} |
| 104 | + |
| 105 | +.passed { |
| 106 | + background-color: #cfc; |
| 107 | + display: none; |
| 108 | +} |
| 109 | + |
| 110 | +.failed { |
| 111 | + background-color: #fbb; |
| 112 | +} |
| 113 | + |
| 114 | +.skipped { |
| 115 | + color: #777; |
| 116 | + background-color: #eee; |
| 117 | + display: none; |
| 118 | +} |
| 119 | + |
| 120 | + |
| 121 | +/*.resultMessage {*/ |
| 122 | + /*white-space: pre;*/ |
| 123 | +/*}*/ |
| 124 | + |
| 125 | +.resultMessage span.result { |
| 126 | + display: block; |
| 127 | + line-height: 2em; |
| 128 | + color: black; |
| 129 | +} |
| 130 | + |
| 131 | +.resultMessage .mismatch { |
| 132 | + color: black; |
| 133 | +} |
| 134 | + |
| 135 | +.stackTrace { |
| 136 | + white-space: pre; |
| 137 | + font-size: .8em; |
| 138 | + margin-left: 10px; |
| 139 | + max-height: 5em; |
| 140 | + overflow: auto; |
| 141 | + border: 1px inset red; |
| 142 | + padding: 1em; |
| 143 | + background: #eef; |
| 144 | +} |
| 145 | + |
| 146 | +.finished-at { |
| 147 | + padding-left: 1em; |
| 148 | + font-size: .6em; |
| 149 | +} |
| 150 | + |
| 151 | +.show-passed .passed, |
| 152 | +.show-skipped .skipped { |
| 153 | + display: block; |
| 154 | +} |
| 155 | + |
| 156 | + |
| 157 | +#jasmine_content { |
| 158 | + position:fixed; |
| 159 | + right: 100%; |
| 160 | +} |
| 161 | + |
| 162 | +.runner { |
| 163 | + border: 1px solid gray; |
| 164 | + display: block; |
| 165 | + margin: 5px 0; |
| 166 | + padding: 2px 0 2px 10px; |
| 167 | +} |
Property changes on: branches/uploadwizard/extensions/UploadWizard/test/jasmine/lib/jasmine-0.11.1/jasmine.css |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 168 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/test/jasmine/SpecRunner.html |
— | — | @@ -0,0 +1,34 @@ |
| 2 | +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
| 3 | + "http://www.w3.org/TR/html4/loose.dtd"> |
| 4 | +<html> |
| 5 | +<head> |
| 6 | + <title>Jasmine Test Runner</title> |
| 7 | + <link rel="stylesheet" type="text/css" href="lib/jasmine-0.11.1/jasmine.css"> |
| 8 | + <script type="text/javascript" src="lib/jasmine-0.11.1/jasmine.js"></script> |
| 9 | + <script type="text/javascript" src="lib/jasmine-0.11.1/jasmine-html.js"></script> |
| 10 | + |
| 11 | + <!-- include source files here... --> |
| 12 | + <script type="text/javascript" src="../../../../skins/common/jquery-1.4.2.js"></script> |
| 13 | + <script type="text/javascript" src="lib/appendto-jquery-mockjax/jquery.mockjax.js"></script> |
| 14 | + |
| 15 | + <script type="text/javascript" src="../../resources/mw.js"></script> |
| 16 | + <script type="text/javascript" src="../../resources/mw.Utilities.js"></script> |
| 17 | + <script type="text/javascript" src="../../resources/mw.Uri.js"></script> |
| 18 | + <script type="text/javascript" src="../../resources/mw.Api.js"></script> |
| 19 | + <script type="text/javascript" src="../../resources/mw.Api.edit.js"></script> |
| 20 | + |
| 21 | + <!-- include spec files here... --> |
| 22 | + <script type="text/javascript" src="spec/mw.Uri.spec.js"</script> |
| 23 | + <script type="text/javascript" src="spec/mw.Api.spec.js"</script> |
| 24 | + <script type="text/javascript" src="spec/mw.Api.edit.spec.js"</script> |
| 25 | + |
| 26 | +</head> |
| 27 | +<body> |
| 28 | +<script type="text/javascript"> |
| 29 | + jasmine.getEnv().addReporter(new jasmine.TrivialReporter()); |
| 30 | + jasmine.getEnv().execute(); |
| 31 | +</script> |
| 32 | + |
| 33 | +</body> |
| 34 | +</html> |
| 35 | + |
Index: branches/uploadwizard/extensions/UploadWizard/test/jasmine/spec/mw.Api.edit.spec.js |
— | — | @@ -0,0 +1,138 @@ |
| 2 | +// this is a bit problematic -- we are using a "real" MediaWiki server rather than mocking it out. |
| 3 | +// jasmine has spies and such for mocking. |
| 4 | +// also, how are we going to configure this test? Perhaps we'll need to have a special SpecRunner text input for API url, etc. |
| 5 | + |
| 6 | +$j.mockjaxSettings = { |
| 7 | + responseTime: 0, // as fast as possible, for tests |
| 8 | + dataType: 'json' |
| 9 | +} |
| 10 | + |
| 11 | +describe( "mw.Api", function() { |
| 12 | + |
| 13 | + var API_DELAY = 250; // ms |
| 14 | + |
| 15 | + // typical globals made available |
| 16 | + // TODO this only works for me (NeilK) |
| 17 | + var wgScriptPath = '/w'; |
| 18 | + |
| 19 | + var pageUri = new mw.Uri( window.location ); |
| 20 | + |
| 21 | + var apiUrl = new mw.Uri( { |
| 22 | + protocol: pageUri.protocol, |
| 23 | + host: pageUri.host, |
| 24 | + path: wgScriptPath + '/api.php' |
| 25 | + } ); |
| 26 | + |
| 27 | + describe( "edit token", function() { |
| 28 | + |
| 29 | +/* |
| 30 | + var deleteToken; |
| 31 | + var deleteTokenGetter = function( t ) { |
| 32 | + deleteToken = t; |
| 33 | + }; |
| 34 | + |
| 35 | + |
| 36 | +*/ |
| 37 | + it( "should fetch a token with simple callback", function() { |
| 38 | + var api = new mw.Api( { url: apiUrl } ); |
| 39 | + runs( function() { |
| 40 | + this.token = undefined; |
| 41 | + var _this = this; |
| 42 | + api.getEditToken( |
| 43 | + function( t ) { |
| 44 | + _this.token = t; |
| 45 | + } |
| 46 | + ); |
| 47 | + } ); |
| 48 | + waits( API_DELAY ); |
| 49 | + runs( function() { |
| 50 | + expect( this.token ).toBeDefined(); |
| 51 | + expect( this.token ).toContain( '+\\' ); |
| 52 | + } ); |
| 53 | + } ); |
| 54 | + |
| 55 | + |
| 56 | + it( "should deal with network timeout", function() { |
| 57 | + runs( function() { |
| 58 | + this.token = undefined; |
| 59 | + var _this = this; |
| 60 | + var api = new mw.Api( { url: apiUrl } ); |
| 61 | + |
| 62 | + var ok = function( t ) { |
| 63 | + _this.token = t; |
| 64 | + }; |
| 65 | + |
| 66 | + var err = function( code, info ) { |
| 67 | + if ( code == 'http-timeout' ) { |
| 68 | + _this.timedOut = true; |
| 69 | + } |
| 70 | + }; |
| 71 | + |
| 72 | + this.mock = $j.mockjax( { |
| 73 | + // match every url |
| 74 | + url: '*', |
| 75 | + // with a timeout |
| 76 | + isTimeout: true |
| 77 | + } ); |
| 78 | + |
| 79 | + api.getEditToken( ok, err ); |
| 80 | + } ); |
| 81 | + |
| 82 | + // the mock should time out instantly, but in practice, some delay seems necessary ? |
| 83 | + waits( 100 ); |
| 84 | + |
| 85 | + runs( function() { |
| 86 | + expect( this.timedOut ).toBe( true ); |
| 87 | + $j.mockjaxClear( this.mock ); |
| 88 | + } ); |
| 89 | + |
| 90 | + } ); |
| 91 | + |
| 92 | + it( "should deal with server error", function() { |
| 93 | + runs( function() { |
| 94 | + this.token = undefined; |
| 95 | + var _this = this; |
| 96 | + var api = new mw.Api( { url: apiUrl } ); |
| 97 | + |
| 98 | + var ok = function( t ) { |
| 99 | + _this.token = t; |
| 100 | + }; |
| 101 | + |
| 102 | + var err = function( code, info ) { |
| 103 | + if ( code == 'http-error' && info && info.xhr && info.xhr.status == '500' ) { |
| 104 | + _this.error500 = true; |
| 105 | + } |
| 106 | + }; |
| 107 | + |
| 108 | + this.mock = $j.mockjax( { |
| 109 | + // match every url |
| 110 | + url: '*', |
| 111 | + // with a server error |
| 112 | + 'status': 500 |
| 113 | + } ); |
| 114 | + |
| 115 | + api.getEditToken( ok, err ); |
| 116 | + } ); |
| 117 | + |
| 118 | + waits( 100 ); |
| 119 | + |
| 120 | + runs( function() { |
| 121 | + expect( this.error500 ).toBe( true ); |
| 122 | + $j.mockjaxClear( this.mock ); |
| 123 | + } ); |
| 124 | + } ); |
| 125 | + |
| 126 | + |
| 127 | +/* |
| 128 | + it ( "should be able to create a page with an edit token", function() { |
| 129 | + var titles = [ 'Foo' ]; |
| 130 | + api.getPageEditToken( titles, tokenGetter ); |
| 131 | + api.editPage( titles ); |
| 132 | + api.getDeleteToken( deleteTokenGetter ); |
| 133 | + } ); |
| 134 | +*/ |
| 135 | + |
| 136 | + } ); |
| 137 | + |
| 138 | +} ); |
| 139 | + |
Property changes on: branches/uploadwizard/extensions/UploadWizard/test/jasmine/spec/mw.Api.edit.spec.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 140 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/test/jasmine/spec/mw.Uri.spec.js |
— | — | @@ -0,0 +1,246 @@ |
| 2 | +describe( "mw.Uri", function() { |
| 3 | + |
| 4 | + describe( "should work well in loose and strict mode", function() { |
| 5 | + |
| 6 | + function basicTests( strict ) { |
| 7 | + |
| 8 | + describe( "should parse a simple HTTP URI correctly", function() { |
| 9 | + |
| 10 | + var uriString = 'http://www.ietf.org/rfc/rfc2396.txt'; |
| 11 | + var uri; |
| 12 | + if ( strict ) { |
| 13 | + uri = new mw.Uri( uriString, strict ); |
| 14 | + } else { |
| 15 | + uri = new mw.Uri( uriString ); |
| 16 | + } |
| 17 | + |
| 18 | + it( "should have basic object properties", function() { |
| 19 | + expect( uri.protocol ).toEqual( 'http' ); |
| 20 | + expect( uri.host ).toEqual( 'www.ietf.org' ); |
| 21 | + expect( uri.port ).not.toBeDefined(); |
| 22 | + expect( uri.path ).toEqual( '/rfc/rfc2396.txt' ); |
| 23 | + expect( uri.query ).toEqual( {} ); |
| 24 | + expect( uri.fragment ).not.toBeDefined(); |
| 25 | + } ); |
| 26 | + |
| 27 | + describe( "should construct composite components of URI on request", function() { |
| 28 | + it( "should have empty userinfo", function() { |
| 29 | + expect( uri.getUserInfo() ).toEqual( '' ); |
| 30 | + } ); |
| 31 | + |
| 32 | + it( "should have authority equal to host", function() { |
| 33 | + expect( uri.getAuthority() ).toEqual( 'www.ietf.org' ); |
| 34 | + } ); |
| 35 | + |
| 36 | + it( "should have hostport equal to host", function() { |
| 37 | + expect( uri.getHostPort() ).toEqual( 'www.ietf.org' ); |
| 38 | + } ); |
| 39 | + |
| 40 | + it( "should have empty string as query string", function() { |
| 41 | + expect( uri.getQueryString() ).toEqual( '' ); |
| 42 | + } ); |
| 43 | + |
| 44 | + it( "should have path as relative path", function() { |
| 45 | + expect( uri.getRelativePath() ).toEqual( '/rfc/rfc2396.txt' ); |
| 46 | + } ); |
| 47 | + |
| 48 | + it( "should return a uri string equivalent to original", function() { |
| 49 | + expect( uri.toString() ).toEqual( uriString ); |
| 50 | + } ); |
| 51 | + } ); |
| 52 | + } ); |
| 53 | + } |
| 54 | + |
| 55 | + describe( "should work in loose mode", function() { |
| 56 | + basicTests( false ); |
| 57 | + } ); |
| 58 | + |
| 59 | + describe( "should work in strict mode", function() { |
| 60 | + basicTests( true ); |
| 61 | + } ); |
| 62 | + |
| 63 | + } ); |
| 64 | + |
| 65 | + it( "should parse a simple ftp URI correctly with user and password", function() { |
| 66 | + var uri = new mw.Uri( 'ftp://usr:pwd@192.0.2.16/' ); |
| 67 | + expect( uri.protocol ).toEqual( 'ftp' ); |
| 68 | + expect( uri.user ).toEqual( 'usr' ); |
| 69 | + expect( uri.password ).toEqual( 'pwd' ); |
| 70 | + expect( uri.host ).toEqual( '192.0.2.16' ); |
| 71 | + expect( uri.port ).not.toBeDefined(); |
| 72 | + expect( uri.path ).toEqual( '/' ); |
| 73 | + expect( uri.query ).toEqual( {} ); |
| 74 | + expect( uri.fragment ).not.toBeDefined(); |
| 75 | + } ); |
| 76 | + |
| 77 | + it( "should parse a simple querystring", function() { |
| 78 | + var uri = new mw.Uri( 'http://www.google.com/?q=uri' ); |
| 79 | + expect( uri.protocol ).toEqual( 'http' ); |
| 80 | + expect( uri.host ).toEqual( 'www.google.com' ); |
| 81 | + expect( uri.port ).not.toBeDefined(); |
| 82 | + expect( uri.path ).toEqual( '/' ); |
| 83 | + expect( uri.query ).toBeDefined(); |
| 84 | + expect( uri.query ).toEqual( { q: 'uri' } ); |
| 85 | + expect( uri.fragment ).not.toBeDefined(); |
| 86 | + expect( uri.getQueryString() ).toEqual( 'q=uri' ); |
| 87 | + } ); |
| 88 | + |
| 89 | + describe( "should deal with an all-dressed URI with everything", function() { |
| 90 | + var uri = new mw.Uri( 'http://auth@www.test.com:81/dir/dir.2/index.htm?q1=0&&test1&test2=value+%28escaped%29#top' ); |
| 91 | + |
| 92 | + it( "should have basic object properties", function() { |
| 93 | + expect( uri.protocol ).toEqual( 'http' ); |
| 94 | + expect( uri.user ).toEqual( 'auth' ); |
| 95 | + expect( uri.password ).not.toBeDefined(); |
| 96 | + expect( uri.host ).toEqual( 'www.test.com' ); |
| 97 | + expect( uri.port ).toEqual( '81' ); |
| 98 | + expect( uri.path ).toEqual( '/dir/dir.2/index.htm' ); |
| 99 | + expect( uri.query ).toEqual( { q1: '0', test1: '', test2: 'value (escaped)' } ); |
| 100 | + expect( uri.fragment ).toEqual( 'top' ); |
| 101 | + } ); |
| 102 | + |
| 103 | + describe( "should construct composite components of URI on request", function() { |
| 104 | + it( "should have userinfo", function() { |
| 105 | + expect( uri.getUserInfo() ).toEqual( 'auth' ); |
| 106 | + } ); |
| 107 | + |
| 108 | + it( "should have authority equal to auth@hostport", function() { |
| 109 | + expect( uri.getAuthority() ).toEqual( 'auth@www.test.com:81' ); |
| 110 | + } ); |
| 111 | + |
| 112 | + it( "should have hostport equal to host:port", function() { |
| 113 | + expect( uri.getHostPort() ).toEqual( 'www.test.com:81' ); |
| 114 | + } ); |
| 115 | + |
| 116 | + it( "should have query string which contains all components", function() { |
| 117 | + var queryString = uri.getQueryString(); |
| 118 | + expect( queryString ).toContain( 'q1=0' ); |
| 119 | + expect( queryString ).toContain( 'test1=' ); |
| 120 | + expect( queryString ).toContain( 'test2=value+%28escaped%29' ); |
| 121 | + } ); |
| 122 | + |
| 123 | + it( "should have path as relative path", function() { |
| 124 | + expect( uri.getRelativePath() ).toContain( uri.path ); |
| 125 | + expect( uri.getRelativePath() ).toContain( uri.getQueryString() ); |
| 126 | + expect( uri.getRelativePath() ).toContain( uri.fragment ); |
| 127 | + } ); |
| 128 | + |
| 129 | + } ); |
| 130 | + } ); |
| 131 | + |
| 132 | + describe( "should be able to clone itself", function() { |
| 133 | + var original = new mw.Uri( 'http://en.wiki.local/w/api.php?action=query&foo=bar' ); |
| 134 | + var clone = original.clone(); |
| 135 | + |
| 136 | + it( "should make clones equivalent", function() { |
| 137 | + expect( original ).toEqual( clone ); |
| 138 | + expect( original.toString() ).toEqual( clone.toString() ); |
| 139 | + } ); |
| 140 | + |
| 141 | + it( "should be able to manipulate clones independently", function() { |
| 142 | + // but they are still different objects |
| 143 | + expect( original ).not.toBe( clone ); |
| 144 | + // and can diverge |
| 145 | + clone.host = 'fr.wiki.local'; |
| 146 | + expect( original.host ).not.toEqual( clone.host ); |
| 147 | + expect( original.toString() ).not.toEqual( clone.toString() ); |
| 148 | + } ); |
| 149 | + } ); |
| 150 | + |
| 151 | + describe( "should be able to construct URL from object", function() { |
| 152 | + it ( "should construct given basic arguments", function() { |
| 153 | + var uri = new mw.Uri( { protocol: 'http', host: 'www.foo.local', path: '/this' } ); |
| 154 | + expect( uri.toString() ).toEqual( 'http://www.foo.local/this' ); |
| 155 | + } ); |
| 156 | + |
| 157 | + it ( "should construct given basic arguments", function() { |
| 158 | + var uri = new mw.Uri( { |
| 159 | + protocol: 'http', |
| 160 | + host: 'www.foo.local', |
| 161 | + path: '/this', |
| 162 | + query: { hi: 'there' }, |
| 163 | + fragment: 'blah' |
| 164 | + } ); |
| 165 | + expect( uri.toString() ).toEqual( 'http://www.foo.local/this?hi=there#blah' ); |
| 166 | + } ); |
| 167 | + |
| 168 | + it ( "should fail to construct without required properties", function() { |
| 169 | + expect( function() { |
| 170 | + var uri = new mw.Uri( { protocol: 'http', host: 'www.foo.local' } ); |
| 171 | + } ).toThrow( "bad constructor arguments" ); |
| 172 | + } ); |
| 173 | + } ); |
| 174 | + |
| 175 | + describe( "should be able to manipulate properties", function() { |
| 176 | + var uri; |
| 177 | + |
| 178 | + beforeEach( function() { |
| 179 | + uri = new mw.Uri( 'http://en.wiki.local/w/api.php' ); |
| 180 | + } ); |
| 181 | + |
| 182 | + it( "can add a fragment", function() { |
| 183 | + uri.fragment = 'frag'; |
| 184 | + expect( uri.toString() ).toEqual( 'http://en.wiki.local/w/api.php#frag' ); |
| 185 | + } ); |
| 186 | + |
| 187 | + it( "can change host and port", function() { |
| 188 | + uri.host = 'fr.wiki.local'; |
| 189 | + uri.port = '8080'; |
| 190 | + expect( uri.toString() ).toEqual( 'http://fr.wiki.local:8080/w/api.php' ); |
| 191 | + } ); |
| 192 | + |
| 193 | + it ( "can add query arguments", function() { |
| 194 | + uri.query.foo = 'bar'; |
| 195 | + expect( uri.toString() ).toEqual( 'http://en.wiki.local/w/api.php?foo=bar' ); |
| 196 | + } ); |
| 197 | + |
| 198 | + it ( "can extend query arguments", function() { |
| 199 | + uri.query.foo = 'bar'; |
| 200 | + expect( uri.toString() ).toEqual( 'http://en.wiki.local/w/api.php?foo=bar' ); |
| 201 | + uri.extend( { foo: 'quux', pif: 'paf' } ); |
| 202 | + expect( uri.toString() ).toContain( 'foo=quux' ) |
| 203 | + expect( uri.toString() ).not.toContain( 'foo=bar' ) |
| 204 | + expect( uri.toString() ).toContain( 'pif=paf' ) |
| 205 | + } ); |
| 206 | + |
| 207 | + it ( "can remove query arguments", function() { |
| 208 | + uri.query.foo = 'bar'; |
| 209 | + expect( uri.toString() ).toEqual( 'http://en.wiki.local/w/api.php?foo=bar' ); |
| 210 | + delete( uri.query.foo ); |
| 211 | + expect( uri.toString() ).toEqual( 'http://en.wiki.local/w/api.php' ); |
| 212 | + } ); |
| 213 | + |
| 214 | + } ); |
| 215 | + |
| 216 | + it( "should throw error on no arguments to constructor", function() { |
| 217 | + expect( function() { |
| 218 | + uri = new mw.Uri(); |
| 219 | + } ).toThrow( "bad constructor arguments" ); |
| 220 | + } ); |
| 221 | + |
| 222 | + it( "should throw error on empty string as argument to constructor", function() { |
| 223 | + expect( function() { |
| 224 | + uri = new mw.Uri( '' ); |
| 225 | + } ).toThrow( "bad constructor arguments" ); |
| 226 | + } ); |
| 227 | + |
| 228 | + it( "should throw error on non-URI as argument to constructor", function() { |
| 229 | + expect( function() { |
| 230 | + uri = new mw.Uri( 'glaswegian penguins' ); |
| 231 | + } ).toThrow( "bad constructor arguments" ); |
| 232 | + } ); |
| 233 | + |
| 234 | + it( "should throw error on improper URI as argument to constructor", function() { |
| 235 | + expect( function() { |
| 236 | + uri = new mw.Uri( 'http:/foo.com' ); |
| 237 | + } ).toThrow( "bad constructor arguments" ); |
| 238 | + } ); |
| 239 | + |
| 240 | + it( "should throw error on URI without protocol as argument to constructor", function() { |
| 241 | + expect( function() { |
| 242 | + uri = new mw.Uri( 'foo.com/bar/baz' ); |
| 243 | + } ).toThrow( "bad constructor arguments" ); |
| 244 | + } ); |
| 245 | + |
| 246 | + |
| 247 | +} ); |
Property changes on: branches/uploadwizard/extensions/UploadWizard/test/jasmine/spec/mw.Uri.spec.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 248 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/test/php/scripts/generateRandomImages.php |
— | — | @@ -0,0 +1,173 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/* Because MediaWiki tests the uniqueness of media upload content, and filenames, it is sometimes useful to generate |
| 5 | + files that are guaranteed (or at least very likely) to be unique in both those ways. |
| 6 | + This generates a number of filenames with random names and random content (colored circles) */ |
| 7 | + |
| 8 | + |
| 9 | +$defaults = array( |
| 10 | + 'dict' => "/usr/share/dict/words", |
| 11 | + 'number' => 10, |
| 12 | + 'minWidth' => 400, |
| 13 | + 'maxWidth' => 800, |
| 14 | + 'minHeight' => 400, |
| 15 | + 'maxHeight' => 800, |
| 16 | + 'format' => 'jpg' |
| 17 | +); |
| 18 | + |
| 19 | +writeRandomImages( getOptions( $defaults ) ); |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +/** |
| 25 | + * Override defaults with command-line options |
| 26 | + * |
| 27 | + * @param {Array} key-value default values |
| 28 | + * @return {Array} defaults with CLI overrides |
| 29 | + */ |
| 30 | +function getOptions( $defaults ) { |
| 31 | + |
| 32 | + // all options are optional, so append '::' to spec |
| 33 | + $getoptSpec = array_map( function($s) { return $s . "::"; }, array_keys( $defaults ) ); |
| 34 | + $cliOptions = getopt( null, $getoptSpec ); |
| 35 | + |
| 36 | + $options = array(); |
| 37 | + foreach ( $defaults as $key => $value ) { |
| 38 | + $options[$key] = array_key_exists( $key, $cliOptions ) ? $cliOptions[$key] : $defaults[$key]; |
| 39 | + } |
| 40 | + |
| 41 | + return $options; |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +/** |
| 47 | + * writes random images with random files to disk in current working directory |
| 48 | + * |
| 49 | + * @param {Array} key-value options |
| 50 | + */ |
| 51 | +function writeRandomImages( $options ) { |
| 52 | + global $dictionary; |
| 53 | + |
| 54 | + // each filename uses two words from the dictionary |
| 55 | + $wordsDesired = $options['number'] * 2; |
| 56 | + |
| 57 | + foreach( getPairs( getRandomLines( $wordsDesired, $options['dict'] ) ) as $pair ) { |
| 58 | + $filename = $pair[0] . '_' . $pair[1] . '.' . $options['format']; |
| 59 | + |
| 60 | + // strip all whitespace (in case we somehow have inner whitespace) |
| 61 | + $filename = preg_replace( '/\s+/', '', $filename ); |
| 62 | + |
| 63 | + $image = getRandomImage( $options['minWidth'], $options['maxWidth'], $options['minHeight'], $options['maxHeight'] ); |
| 64 | + $image->setImageFormat( $options['format'] ); |
| 65 | + $image->writeImage( $filename ); |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | + |
| 70 | +/** |
| 71 | + * Generate an image consisting of randomly colored and sized circles |
| 72 | + * @return {Image} |
| 73 | + */ |
| 74 | +function getRandomImage($minWidth, $maxWidth, $minHeight, $maxHeight) { |
| 75 | + global $options; |
| 76 | + |
| 77 | + $imageWidth = mt_rand( $minWidth, $maxWidth ); |
| 78 | + $imageHeight = mt_rand( $minHeight, $maxHeight ); |
| 79 | + |
| 80 | + $image = new Imagick(); |
| 81 | + $image->newImage( $imageWidth, $imageHeight, new ImagickPixel( getRandomColor() ) ); |
| 82 | + |
| 83 | + |
| 84 | + $diagonalLength = sqrt( pow( $imageWidth, 2 ) + pow( $imageHeight, 2 ) ); |
| 85 | + |
| 86 | + for ( $i = 0; $i <= 5; $i++ ) { |
| 87 | + $radius = mt_rand( 0, $diagonalLength / 4 ); |
| 88 | + $originX = mt_rand( -1 * $radius, $imageWidth + $radius ); |
| 89 | + $originY = mt_rand( -1 * $radius, $imageHeight + $radius ); |
| 90 | + $perimeterX = $originX + $radius; |
| 91 | + $perimeterY = $originY + $radius; |
| 92 | + |
| 93 | + $draw = new ImagickDraw(); |
| 94 | + $draw->setFillColor( getRandomColor() ); |
| 95 | + $draw->circle( $originX, $originY, $perimeterX, $perimeterY ); |
| 96 | + $image->drawImage( $draw ); |
| 97 | + |
| 98 | + } |
| 99 | + |
| 100 | + return $image; |
| 101 | +} |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | +/** |
| 106 | + * Generate a string of random colors for ImageMagick, like "rgb(12, 37, 98)" |
| 107 | + * |
| 108 | + * @return {String} |
| 109 | + */ |
| 110 | +function getRandomColor() { |
| 111 | + $components = array(); |
| 112 | + for ($i = 0; $i <= 2; $i++ ) { |
| 113 | + $components[] = mt_rand( 0, 255 ); |
| 114 | + } |
| 115 | + return 'rgb(' . join(', ', $components) . ')'; |
| 116 | +} |
| 117 | + |
| 118 | +/** |
| 119 | + * Turn an array into an array of pairs. |
| 120 | + * |
| 121 | + * @param {Array} an array |
| 122 | + * @return {Array} of two-element arrays |
| 123 | + */ |
| 124 | +function getPairs( $arr ) { |
| 125 | + // construct pairs of words |
| 126 | + $pairs = array(); |
| 127 | + $count = count( $arr ); |
| 128 | + for( $i = 0; $i < $count; $i += 2 ) { |
| 129 | + $pairs[] = array( $arr[$i], $arr[$i+1] ); |
| 130 | + } |
| 131 | + return $pairs; |
| 132 | +} |
| 133 | + |
| 134 | +/** |
| 135 | + * Return N random lines from a file |
| 136 | + * |
| 137 | + * Will die if the file could not be read or if it had fewer lines than requested. |
| 138 | + * |
| 139 | + * @param {Integer} number of lines desired |
| 140 | + * @string {String} path to file |
| 141 | + * @return {Array} of exactly n elements, drawn randomly from lines the file |
| 142 | + */ |
| 143 | +function getRandomLines( $number_desired, $filepath ) { |
| 144 | + $lines = array(); |
| 145 | + for ( $i = 0; $i < $number_desired; $i++ ) { |
| 146 | + $lines[] = null; |
| 147 | + } |
| 148 | + |
| 149 | + /* |
| 150 | + * This algorithm obtains N random lines from a file in one single pass. It does this by replacing elements of |
| 151 | + * a fixed-size array of lines, less and less frequently as it reads the file. |
| 152 | + */ |
| 153 | + $fh = fopen( $filepath, "r" ) or die( "couldn't open $filepath" ) ; |
| 154 | + $line_number = 0; |
| 155 | + $max_index = $number_desired - 1; |
| 156 | + while( !feof( $fh ) ) { |
| 157 | + $line = fgets( $fh ); |
| 158 | + if ( $line !== false ) { |
| 159 | + $line_number++; |
| 160 | + $line = trim( $line ); |
| 161 | + if ( mt_rand( 0, $line_number ) <= $max_index ) { |
| 162 | + $lines[ mt_rand( 0, $max_index ) ] = $line; |
| 163 | + } |
| 164 | + } |
| 165 | + } |
| 166 | + fclose( $fh ); |
| 167 | + if ( $line_number < $number_desired ) { |
| 168 | + die( "not enough lines in $filepath" ); |
| 169 | + } |
| 170 | + |
| 171 | + return $lines; |
| 172 | +} |
| 173 | + |
| 174 | +?> |
Property changes on: branches/uploadwizard/extensions/UploadWizard/test/php/scripts/generateRandomImages.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 175 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/UploadWizardMessages.php |
— | — | @@ -0,0 +1,73 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * UploadWizardMessages |
| 5 | + * |
| 6 | + * Simple class to take messages from a modules' i18n.php and dump them into Javascript. |
| 7 | + * |
| 8 | + * @file |
| 9 | + * @ingroup Upload |
| 10 | + */ |
| 11 | + |
| 12 | +/* This class is temporary. |
| 13 | + |
| 14 | + With the rejection of JS2 and reassignment of Michael Dale, there seems to be no currently supported |
| 15 | + resource loader (July 2010), but UploadWizard already relies on things like |
| 16 | + pluralization in messages which were only available in JS2. Also we have problems with how JS2 loads |
| 17 | + things in IE6; there are bugs which neither I nor Trevor Parscal can figure out. So, we are temporarily |
| 18 | + falling back to a simpler method of loading messages, which will hopefully |
| 19 | + be superseded by the new loader Roan Kattouw & Trevor Parscal are writing. |
| 20 | + |
| 21 | +*/ |
| 22 | + |
| 23 | +class UploadWizardMessages { |
| 24 | + |
| 25 | + /** |
| 26 | + * getMessagesJs generates a javascript addMessages() calls for a given module and language |
| 27 | + * |
| 28 | + * @param String $moduleName the name of the module |
| 29 | + * @param String $langCode Name of scriptText module ( that hosts messages ) |
| 30 | + * @return string |
| 31 | + */ |
| 32 | + |
| 33 | + |
| 34 | + public static function getMessagesJs( $moduleName, $language ) { |
| 35 | + global $wgOut; |
| 36 | + |
| 37 | + // TODO this should be cached. Perhaps with Localisation Cache. |
| 38 | + global $wgExtensionMessagesFiles; |
| 39 | + |
| 40 | + // Empty out messages in the current scope |
| 41 | + $messages = array(); |
| 42 | + require( $wgExtensionMessagesFiles[ $moduleName ] ); |
| 43 | + |
| 44 | + // iterate over the default messages, and get this wiki's current messages |
| 45 | + // presumably this will include local overrides in MediaWiki: space |
| 46 | + $messagesForJs = array(); |
| 47 | + |
| 48 | + // 'en' is the default language, so it will be the most complete |
| 49 | + foreach ( array_keys( $messages['en'] ) as $key ) { |
| 50 | + $messagesForJs[ $key ] = wfMsgGetKey( $key, /*DB*/true, $language, /*Transform*/false ); |
| 51 | + } |
| 52 | + |
| 53 | + $json = new Services_JSON(); |
| 54 | + $messagesJson = $json->encode( $messagesForJs ); |
| 55 | + return 'mw.addMessages(' . $messagesJson . ');'; |
| 56 | + } |
| 57 | + |
| 58 | + |
| 59 | + static function getNormalizedLangCode( $langCode ) { |
| 60 | + global $wgLang; |
| 61 | + // Check the langCode |
| 62 | + if( !$langCode) { |
| 63 | + if ( $wgLang ) { |
| 64 | + $langCode = $wgLang->getCode(); |
| 65 | + } else { |
| 66 | + $langCode = 'en'; // desperation |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + } |
| 71 | + |
| 72 | +} |
| 73 | + |
| 74 | +?> |
Property changes on: branches/uploadwizard/extensions/UploadWizard/UploadWizardMessages.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 75 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/UploadWizard.i18n.php |
— | — | @@ -35,6 +35,7 @@ |
36 | 36 | 'mwe-upwiz-add-file-0' => 'Click here to upload a file', |
37 | 37 | 'mwe-upwiz-browse' => 'Browse...', |
38 | 38 | 'mwe-upwiz-transported' => 'OK', |
| 39 | + 'mwe-upwiz-failed' => 'Failed', |
39 | 40 | 'mwe-upwiz-click-here' => 'Click here to select a file', |
40 | 41 | 'mwe-upwiz-uploading' => 'uploading...', |
41 | 42 | 'mwe-upwiz-editing' => 'editing...', |
— | — | @@ -150,6 +151,12 @@ |
151 | 152 | 'mwe-upwiz-error-bad-chars' => 'This field contains symbols that are not allowed. |
152 | 153 | Please do not use wikitext or HTML here.', |
153 | 154 | 'mwe-upwiz-error-date' => 'Please enter a valid date in YYYY-MM-DD format, or pick a date from the popup calendar.', |
| 155 | + |
| 156 | + /* API error messages */ |
| 157 | + 'mwe-api-error-token-missing' => 'The server did not return a token.', |
| 158 | + 'mwe-api-error-http-timeout' => 'The server didn\'t return a response in time.', |
| 159 | + 'mwe-api-error-http-error' => 'We couldn\'t communicate properly with the server.', |
| 160 | + |
154 | 161 | /* LICENSES */ |
155 | 162 | /* surprisingly we don't seem to have strings for these yet */ |
156 | 163 | 'mwe-upwiz-license-cc-by-sa-3.0' => 'Creative Commons Attribution ShareAlike 3.0', |
— | — | @@ -161,6 +168,7 @@ |
162 | 169 | 'mwe-upwiz-categories' => 'Categories', |
163 | 170 | 'mwe-upwiz-categories-add' => 'Add', |
164 | 171 | 'mwe-upwiz-category-remove' => 'Remove this category' |
| 172 | + |
165 | 173 | ); |
166 | 174 | |
167 | 175 | /** Message documentation (Message documentation) |
Index: branches/uploadwizard/extensions/UploadWizard/resources/jquery/jquery.autocomplete.js |
— | — | @@ -0,0 +1,528 @@ |
| 2 | +(function($){ |
| 3 | + |
| 4 | +jQuery.autocomplete = function(input, options) { |
| 5 | + // Create a link to self |
| 6 | + var me = this; |
| 7 | + |
| 8 | + // Create jQuery object for input element |
| 9 | + var $input = $(input).attr("autocomplete", "off"); |
| 10 | + |
| 11 | + // Apply inputClass if necessary |
| 12 | + if (options.inputClass) $input.addClass(options.inputClass); |
| 13 | + |
| 14 | + // Create results |
| 15 | + if(!options.resultElem){ |
| 16 | + var results = document.createElement("div"); |
| 17 | + // Create jQuery object for results |
| 18 | + var $results = $(results); |
| 19 | + // Add to body element |
| 20 | + $("body").append(results); |
| 21 | + $results.hide().addClass(options.resultsClass).css("position", "absolute"); |
| 22 | + if( options.width > 0 ) $results.css("width", options.width); |
| 23 | + }else{ |
| 24 | + var results = $j(options.resultElem).get(0); |
| 25 | + var $results = $j(options.resultElem); |
| 26 | + $results.hide(); |
| 27 | + } |
| 28 | + |
| 29 | + |
| 30 | + input.autocompleter = me; |
| 31 | + |
| 32 | + var timeout = null; |
| 33 | + var prev = ""; |
| 34 | + var active = -1; |
| 35 | + var cache = {}; |
| 36 | + var keyb = false; |
| 37 | + var hasFocus = false; |
| 38 | + var lastKeyPressCode = null; |
| 39 | + |
| 40 | + // flush cache |
| 41 | + function flushCache(){ |
| 42 | + cache = {}; |
| 43 | + cache.data = {}; |
| 44 | + cache.length = 0; |
| 45 | + }; |
| 46 | + |
| 47 | + // flush cache |
| 48 | + flushCache(); |
| 49 | + |
| 50 | + // if there is a data array supplied |
| 51 | + if( options.data != null ){ |
| 52 | + var sFirstChar = "", stMatchSets = {}, row = []; |
| 53 | + |
| 54 | + // no url was specified, we need to adjust the cache length to make sure it fits the local data store |
| 55 | + if( typeof options.url != "string" ) options.cacheLength = 1; |
| 56 | + |
| 57 | + // loop through the array and create a lookup structure |
| 58 | + for( var i=0; i < options.data.length; i++ ){ |
| 59 | + // if row is a string, make an array otherwise just reference the array |
| 60 | + row = ((typeof options.data[i] == "string") ? [options.data[i]] : options.data[i]); |
| 61 | + |
| 62 | + // if the length is zero, don't add to list |
| 63 | + if( row[0].length > 0 ){ |
| 64 | + // get the first character |
| 65 | + sFirstChar = row[0].substring(0, 1).toLowerCase(); |
| 66 | + // if no lookup array for this character exists, look it up now |
| 67 | + if( !stMatchSets[sFirstChar] ) stMatchSets[sFirstChar] = []; |
| 68 | + // if the match is a string |
| 69 | + stMatchSets[sFirstChar].push(row); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + // add the data items to the cache |
| 74 | + for( var k in stMatchSets ){ |
| 75 | + // increase the cache size |
| 76 | + options.cacheLength++; |
| 77 | + // add to the cache |
| 78 | + addToCache(k, stMatchSets[k]); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + $input |
| 83 | + .keydown(function(e) { |
| 84 | + // track last key pressed |
| 85 | + lastKeyPressCode = e.keyCode; |
| 86 | + switch(e.keyCode) { |
| 87 | + case 38: // up |
| 88 | + e.preventDefault(); |
| 89 | + moveSelect(-1); |
| 90 | + break; |
| 91 | + case 40: // down |
| 92 | + e.preventDefault(); |
| 93 | + moveSelect(1); |
| 94 | + break; |
| 95 | + case 9: // tab |
| 96 | + case 13: // return |
| 97 | + if( selectCurrent() ){ |
| 98 | + // make sure to blur off the current field |
| 99 | + $input.get(0).blur(); |
| 100 | + e.preventDefault(); |
| 101 | + } |
| 102 | + break; |
| 103 | + default: |
| 104 | + active = -1; |
| 105 | + if (timeout) clearTimeout(timeout); |
| 106 | + timeout = setTimeout(function(){onChange();}, options.delay); |
| 107 | + break; |
| 108 | + } |
| 109 | + }) |
| 110 | + .focus(function(){ |
| 111 | + // track whether the field has focus, we shouldn't process any results if the field no longer has focus |
| 112 | + hasFocus = true; |
| 113 | + }) |
| 114 | + .blur(function() { |
| 115 | + // track whether the field has focus |
| 116 | + hasFocus = false; |
| 117 | + hideResults(); |
| 118 | + }); |
| 119 | + |
| 120 | + hideResultsNow(); |
| 121 | + |
| 122 | + function onChange() { |
| 123 | + // ignore if the following keys are pressed: [del] [shift] [capslock] |
| 124 | + if( lastKeyPressCode == 46 || (lastKeyPressCode > 8 && lastKeyPressCode < 32) ) return $results.hide(); |
| 125 | + var v = $input.val(); |
| 126 | + if (v == prev) return; |
| 127 | + prev = v; |
| 128 | + if (v.length >= options.minChars) { |
| 129 | + $input.addClass(options.loadingClass); |
| 130 | + requestData(v); |
| 131 | + } else { |
| 132 | + $input.removeClass(options.loadingClass); |
| 133 | + $results.hide(); |
| 134 | + } |
| 135 | + }; |
| 136 | + |
| 137 | + function moveSelect(step) { |
| 138 | + var lis = $("li", results); |
| 139 | + if (!lis) return; |
| 140 | + |
| 141 | + active += step; |
| 142 | + |
| 143 | + if (active < 0) { |
| 144 | + active = 0; |
| 145 | + } else if (active >= lis.size()) { |
| 146 | + active = lis.size() - 1; |
| 147 | + } |
| 148 | + |
| 149 | + lis.removeClass("ac_over"); |
| 150 | + |
| 151 | + $(lis[active]).addClass("ac_over"); |
| 152 | + |
| 153 | + // Weird behaviour in IE |
| 154 | + // if (lis[active] && lis[active].scrollIntoView) { |
| 155 | + // lis[active].scrollIntoView(false); |
| 156 | + // } |
| 157 | + |
| 158 | + }; |
| 159 | + function selectCurrent() { |
| 160 | + var li = $("li.ac_over", results)[0]; |
| 161 | + if (!li) { |
| 162 | + var $li = $("li", results); |
| 163 | + if (options.selectOnly) { |
| 164 | + if ($li.length == 1) li = $li[0]; |
| 165 | + } else if (options.selectFirst) { |
| 166 | + li = $li[0]; |
| 167 | + } |
| 168 | + } |
| 169 | + if (li) { |
| 170 | + selectItem(li); |
| 171 | + return true; |
| 172 | + } else { |
| 173 | + return false; |
| 174 | + } |
| 175 | + }; |
| 176 | + |
| 177 | + function selectItem(li) { |
| 178 | + if (!li) { |
| 179 | + li = document.createElement("li"); |
| 180 | + li.extra = []; |
| 181 | + li.selectValue = ""; |
| 182 | + } |
| 183 | + var v = $.trim(li.selectValue ? li.selectValue : li.innerHTML); |
| 184 | + input.lastSelected = v; |
| 185 | + prev = v; |
| 186 | + $results.html(""); |
| 187 | + $input.val(v); |
| 188 | + hideResultsNow(); |
| 189 | + if (options.onItemSelect) setTimeout(function() { options.onItemSelect(li) }, 1); |
| 190 | + }; |
| 191 | + |
| 192 | + // selects a portion of the input string |
| 193 | + function createSelection(start, end){ |
| 194 | + // get a reference to the input element |
| 195 | + var field = $input.get(0); |
| 196 | + if( field.createTextRange ){ |
| 197 | + var selRange = field.createTextRange(); |
| 198 | + selRange.collapse(true); |
| 199 | + selRange.moveStart("character", start); |
| 200 | + selRange.moveEnd("character", end); |
| 201 | + selRange.select(); |
| 202 | + } else if( field.setSelectionRange ){ |
| 203 | + field.setSelectionRange(start, end); |
| 204 | + } else { |
| 205 | + if( field.selectionStart ){ |
| 206 | + field.selectionStart = start; |
| 207 | + field.selectionEnd = end; |
| 208 | + } |
| 209 | + } |
| 210 | + field.focus(); |
| 211 | + }; |
| 212 | + |
| 213 | + // fills in the input box w/the first match (assumed to be the best match) |
| 214 | + function autoFill(sValue){ |
| 215 | + // if the last user key pressed was backspace, don't autofill |
| 216 | + if( lastKeyPressCode != 8 ){ |
| 217 | + // fill in the value (keep the case the user has typed) |
| 218 | + $input.val($input.val() + sValue.substring(prev.length)); |
| 219 | + // select the portion of the value not typed by the user (so the next character will erase) |
| 220 | + createSelection(prev.length, sValue.length); |
| 221 | + } |
| 222 | + }; |
| 223 | + |
| 224 | + function showResults() { |
| 225 | + // get the position of the input field right now (in case the DOM is shifted) |
| 226 | + var pos = findPos(input); |
| 227 | + // either use the specified width, or autocalculate based on form element |
| 228 | + var iWidth = (options.width > 0) ? options.width : $input.width(); |
| 229 | + // reposition |
| 230 | + if(!options.resultElem){ |
| 231 | + $results.css({ |
| 232 | + width: parseInt(iWidth) + "px", |
| 233 | + top: (pos.y + input.offsetHeight) + "px", |
| 234 | + left: pos.x + "px" |
| 235 | + }).show(); |
| 236 | + }else{ |
| 237 | + $results.show(); |
| 238 | + } |
| 239 | + if(options.resultContainer){ |
| 240 | + $(options.resultContainer).css({top: (pos.y + input.offsetHeight) + "px", |
| 241 | + left: (pos.x- parseInt(iWidth)) + "px"}).show(); |
| 242 | + } |
| 243 | + }; |
| 244 | + |
| 245 | + function hideResults() { |
| 246 | + if (timeout) clearTimeout(timeout); |
| 247 | + timeout = setTimeout(hideResultsNow, 200); |
| 248 | + }; |
| 249 | + |
| 250 | + function hideResultsNow() { |
| 251 | + if (timeout) clearTimeout(timeout); |
| 252 | + $input.removeClass(options.loadingClass); |
| 253 | + if ($results.is(":visible")) { |
| 254 | + $results.hide(); |
| 255 | + } |
| 256 | + if(options.resultContainer){ |
| 257 | + $(options.resultContainer).hide(); |
| 258 | + } |
| 259 | + if (options.mustMatch) { |
| 260 | + var v = $input.val(); |
| 261 | + if (v != input.lastSelected) { |
| 262 | + selectItem(null); |
| 263 | + } |
| 264 | + } |
| 265 | + }; |
| 266 | + |
| 267 | + function receiveData(q, data) { |
| 268 | + if (data) { |
| 269 | + $input.removeClass(options.loadingClass); |
| 270 | + results.innerHTML = ""; |
| 271 | + |
| 272 | + // if the field no longer has focus or if there are no matches, do not display the drop down |
| 273 | + if( !hasFocus || data.length == 0 ) return hideResultsNow(); |
| 274 | + |
| 275 | + //messes with layout & ie7 does not have this problem |
| 276 | + /*if ($.browser.msie) { |
| 277 | + // we put a styled iframe behind the calendar so HTML SELECT elements don't show through |
| 278 | + $results.append(document.createElement('iframe')); |
| 279 | + }*/ |
| 280 | + results.appendChild(dataToDom(data)); |
| 281 | + // autofill in the complete box w/the first match as long as the user hasn't entered in more data |
| 282 | + if( options.autoFill && ($input.val().toLowerCase() == q.toLowerCase()) ) autoFill(data[0][0]); |
| 283 | + showResults(); |
| 284 | + } else { |
| 285 | + hideResultsNow(); |
| 286 | + } |
| 287 | + }; |
| 288 | + |
| 289 | + function parseData(data) { |
| 290 | + if (!data) return null; |
| 291 | + var parsed = []; |
| 292 | + var rows = data.split(options.lineSeparator); |
| 293 | + for (var i=0; i < rows.length; i++) { |
| 294 | + var row = $.trim(rows[i]); |
| 295 | + if (row) { |
| 296 | + parsed[parsed.length] = row.split(options.cellSeparator); |
| 297 | + } |
| 298 | + } |
| 299 | + return parsed; |
| 300 | + }; |
| 301 | + |
| 302 | + function dataToDom(data) { |
| 303 | + var ul = document.createElement("ul"); |
| 304 | + if(options.ul_class)$(ul).addClass(options.ul_class); |
| 305 | + |
| 306 | + var num = data.length; |
| 307 | + |
| 308 | + // limited results to a max number |
| 309 | + if( (options.maxItemsToShow > 0) && (options.maxItemsToShow < num) ) num = options.maxItemsToShow; |
| 310 | + |
| 311 | + for (var i=0; i < num; i++) { |
| 312 | + var row = data[i]; |
| 313 | + if (!row) continue; |
| 314 | + var li = document.createElement("li"); |
| 315 | + if (options.formatItem) { |
| 316 | + li.innerHTML = options.formatItem(row, i, num); |
| 317 | + li.selectValue = row[0]; |
| 318 | + } else { |
| 319 | + li.innerHTML = row[0]; |
| 320 | + li.selectValue = row[0]; |
| 321 | + } |
| 322 | + var extra = null; |
| 323 | + if (row.length > 1) { |
| 324 | + extra = []; |
| 325 | + for (var j=1; j < row.length; j++) { |
| 326 | + extra[extra.length] = row[j]; |
| 327 | + } |
| 328 | + } |
| 329 | + li.extra = extra; |
| 330 | + ul.appendChild(li); |
| 331 | + $(li).hover( |
| 332 | + function() { $("li", ul).removeClass("ac_over"); $(this).addClass("ac_over"); active = $("li", ul).indexOf($(this).get(0)); }, |
| 333 | + function() { $(this).removeClass("ac_over"); } |
| 334 | + ).click(function(e) { e.preventDefault(); e.stopPropagation(); selectItem(this) }); |
| 335 | + } |
| 336 | + return ul; |
| 337 | + }; |
| 338 | + |
| 339 | + function requestData(q) { |
| 340 | + if (!options.matchCase) q = q.toLowerCase(); |
| 341 | + var data = options.cacheLength ? loadFromCache(q) : null; |
| 342 | + // recieve the cached data |
| 343 | + if (data) { |
| 344 | + receiveData(q, data); |
| 345 | + // if an AJAX url has been supplied, try loading the data now |
| 346 | + } else if( (typeof options.url == "string") && (options.url.length > 0) ){ |
| 347 | + $.get(makeUrl(q), function(data) { |
| 348 | + data = parseData(data); |
| 349 | + addToCache(q, data); |
| 350 | + receiveData(q, data); |
| 351 | + }); |
| 352 | + // if there's been no data found, remove the loading class |
| 353 | + } else { |
| 354 | + $input.removeClass(options.loadingClass); |
| 355 | + } |
| 356 | + }; |
| 357 | + |
| 358 | + function makeUrl(q) { |
| 359 | + var url = options.url + "?"+options.paramName+'='+ encodeURI(q); |
| 360 | + for (var i in options.extraParams) { |
| 361 | + url += "&" + i + "=" + encodeURI(options.extraParams[i]); |
| 362 | + } |
| 363 | + return url; |
| 364 | + }; |
| 365 | + |
| 366 | + function loadFromCache(q) { |
| 367 | + if (!q) return null; |
| 368 | + if (typeof cache.data[q]!='undefined'){ |
| 369 | + return cache.data[q]; |
| 370 | + } |
| 371 | + if (options.matchSubset) { |
| 372 | + for (var i = q.length - 1; i >= options.minChars; i--) { |
| 373 | + var qs = q.substr(0, i); |
| 374 | + var c = cache.data[qs]; |
| 375 | + if (c) { |
| 376 | + var csub = []; |
| 377 | + for (var j = 0; j < c.length; j++) { |
| 378 | + var x = c[j]; |
| 379 | + var x0 = x[0]; |
| 380 | + if (matchSubset(x0, q)) { |
| 381 | + csub[csub.length] = x; |
| 382 | + } |
| 383 | + } |
| 384 | + return csub; |
| 385 | + } |
| 386 | + } |
| 387 | + } |
| 388 | + return null; |
| 389 | + }; |
| 390 | + |
| 391 | + function matchSubset(s, sub) { |
| 392 | + if (!options.matchCase) s = s.toLowerCase(); |
| 393 | + var i = s.indexOf(sub); |
| 394 | + if (i == -1) return false; |
| 395 | + return i == 0 || options.matchContains; |
| 396 | + }; |
| 397 | + |
| 398 | + this.flushCache = function() { |
| 399 | + flushCache(); |
| 400 | + }; |
| 401 | + |
| 402 | + this.setExtraParams = function(p) { |
| 403 | + options.extraParams = p; |
| 404 | + }; |
| 405 | + |
| 406 | + this.findValue = function(){ |
| 407 | + var q = $input.val(); |
| 408 | + |
| 409 | + if (!options.matchCase) q = q.toLowerCase(); |
| 410 | + var data = options.cacheLength ? loadFromCache(q) : null; |
| 411 | + if (data) { |
| 412 | + findValueCallback(q, data); |
| 413 | + } else if( (typeof options.url == "string") && (options.url.length > 0) ){ |
| 414 | + $.get(makeUrl(q), function(data) { |
| 415 | + data = parseData(data) |
| 416 | + addToCache(q, data); |
| 417 | + findValueCallback(q, data); |
| 418 | + }); |
| 419 | + } else { |
| 420 | + // no matches |
| 421 | + findValueCallback(q, null); |
| 422 | + } |
| 423 | + } |
| 424 | + |
| 425 | + function findValueCallback(q, data){ |
| 426 | + if (data) $input.removeClass(options.loadingClass); |
| 427 | + |
| 428 | + var num = (data) ? data.length : 0; |
| 429 | + var li = null; |
| 430 | + |
| 431 | + for (var i=0; i < num; i++) { |
| 432 | + var row = data[i]; |
| 433 | + |
| 434 | + if( row[0].toLowerCase() == q.toLowerCase() ){ |
| 435 | + li = document.createElement("li"); |
| 436 | + if (options.formatItem) { |
| 437 | + li.innerHTML = options.formatItem(row, i, num); |
| 438 | + li.selectValue = row[0]; |
| 439 | + } else { |
| 440 | + li.innerHTML = row[0]; |
| 441 | + li.selectValue = row[0]; |
| 442 | + } |
| 443 | + var extra = null; |
| 444 | + if( row.length > 1 ){ |
| 445 | + extra = []; |
| 446 | + for (var j=1; j < row.length; j++) { |
| 447 | + extra[extra.length] = row[j]; |
| 448 | + } |
| 449 | + } |
| 450 | + li.extra = extra; |
| 451 | + } |
| 452 | + } |
| 453 | + |
| 454 | + if( options.onFindValue ) setTimeout(function() { options.onFindValue(li) }, 1); |
| 455 | + } |
| 456 | + |
| 457 | + function addToCache(q, data) { |
| 458 | + if (!data || !q || !options.cacheLength) return; |
| 459 | + if (!cache.length || cache.length > options.cacheLength) { |
| 460 | + flushCache(); |
| 461 | + cache.length++; |
| 462 | + } else if (!cache[q]) { |
| 463 | + cache.length++; |
| 464 | + } |
| 465 | + cache.data[q] = data; |
| 466 | + }; |
| 467 | + |
| 468 | + function findPos(obj) { |
| 469 | + var curleft = obj.offsetLeft || 0; |
| 470 | + var curtop = obj.offsetTop || 0; |
| 471 | + while (obj = obj.offsetParent) { |
| 472 | + curleft += obj.offsetLeft |
| 473 | + curtop += obj.offsetTop |
| 474 | + } |
| 475 | + return {x:curleft,y:curtop}; |
| 476 | + } |
| 477 | +} |
| 478 | +})(jQuery); |
| 479 | + |
| 480 | +jQuery.fn.autocomplete = function(url, options, data) { |
| 481 | + // Make sure options exists |
| 482 | + options = options || {}; |
| 483 | + // Set url as option |
| 484 | + options.url = url; |
| 485 | + // set some bulk local data |
| 486 | + options.data = ((typeof data == "object") && (data.constructor == Array)) ? data : null; |
| 487 | + |
| 488 | + // Set default values for required options |
| 489 | + options.resultElem = options.resultElem || null; |
| 490 | + options.paramName = options.paramName || 'q'; |
| 491 | + |
| 492 | + options.inputClass = options.inputClass || "ac_input"; |
| 493 | + options.resultsClass = options.resultsClass || "ac_results"; |
| 494 | + options.lineSeparator = options.lineSeparator || "\n"; |
| 495 | + options.cellSeparator = options.cellSeparator || "|"; |
| 496 | + options.minChars = options.minChars || 1; |
| 497 | + options.delay = options.delay || 400; |
| 498 | + options.matchCase = options.matchCase || 0; |
| 499 | + options.matchSubset = options.matchSubset || 1; |
| 500 | + options.matchContains = options.matchContains || 0; |
| 501 | + options.cacheLength = options.cacheLength || 1; |
| 502 | + options.mustMatch = options.mustMatch || 0; |
| 503 | + options.extraParams = options.extraParams || {}; |
| 504 | + options.loadingClass = options.loadingClass || "ac_loading"; |
| 505 | + options.selectFirst = options.selectFirst || false; |
| 506 | + options.selectOnly = options.selectOnly || false; |
| 507 | + options.maxItemsToShow = options.maxItemsToShow || -1; |
| 508 | + options.autoFill = options.autoFill || false; |
| 509 | + options.width = parseInt(options.width, 10) || 0; |
| 510 | + |
| 511 | + this.each(function() { |
| 512 | + var input = this; |
| 513 | + new jQuery.autocomplete(input, options); |
| 514 | + }); |
| 515 | + |
| 516 | + // Don't break the chain |
| 517 | + return this; |
| 518 | +} |
| 519 | + |
| 520 | +jQuery.fn.autocompleteArray = function(data, options) { |
| 521 | + return this.autocomplete(null, options, data); |
| 522 | +} |
| 523 | + |
| 524 | +jQuery.fn.indexOf = function(e){ |
| 525 | + for( var i=0; i<this.length; i++ ){ |
| 526 | + if( this[i] == e ) return i; |
| 527 | + } |
| 528 | + return -1; |
| 529 | +}; |
Property changes on: branches/uploadwizard/extensions/UploadWizard/resources/jquery/jquery.autocomplete.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 530 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/resources/jquery/jquery.autoSuggest.js |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * the fly. It supports keybord navigation (UP + DOWN + RETURN), as well |
13 | 13 | * as multiple AutoSuggest fields on the same page. |
14 | 14 | * |
15 | | - * Inspied by the Autocomplete plugin by: J�rn Zaefferer |
| 15 | + * Inspied by the Autocomplete plugin by: Jörn Zaefferer |
16 | 16 | * and the Facelist plugin by: Ian Tearle (iantearle.com) |
17 | 17 | * |
18 | 18 | * This AutoSuggest jQuery plug-in is dual licensed under the MIT and GPL licenses: |
Index: branches/uploadwizard/extensions/UploadWizard/resources/jquery/jquery.datePicker.js |
— | — | @@ -0,0 +1,1525 @@ |
| 2 | +/** |
| 3 | + * Copyright (c) 2007 Kelvin Luck (http://www.kelvinluck.com/) |
| 4 | + * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) |
| 5 | + * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. |
| 6 | + * |
| 7 | + * $Id: jquery.datePicker.js 3739 2007-10-25 13:55:30Z kelvin.luck $ |
| 8 | + **/ |
| 9 | + |
| 10 | +(function($){ |
| 11 | + |
| 12 | + $.fn.extend({ |
| 13 | +/** |
| 14 | + * Render a calendar table into any matched elements. |
| 15 | + * |
| 16 | + * @param Object s (optional) Customize your calendars. |
| 17 | + * @option Number month The month to render (NOTE that months are zero based). Default is today's month. |
| 18 | + * @option Number year The year to render. Default is today's year. |
| 19 | + * @option Function renderCallback A reference to a function that is called as each cell is rendered and which can add classes and event listeners to the created nodes. Default is no callback. |
| 20 | + * @option Number showHeader Whether or not to show the header row, possible values are: $.dpConst.SHOW_HEADER_NONE (no header), $.dpConst.SHOW_HEADER_SHORT (first letter of each day) and $.dpConst.SHOW_HEADER_LONG (full name of each day). Default is $.dpConst.SHOW_HEADER_SHORT. |
| 21 | + * @option String hoverClass The class to attach to each cell when you hover over it (to allow you to use hover effects in IE6 which doesn't support the :hover pseudo-class on elements other than links). Default is dp-hover. Pass false if you don't want a hover class. |
| 22 | + * @type jQuery |
| 23 | + * @name renderCalendar |
| 24 | + * @cat plugins/datePicker |
| 25 | + * @author Kelvin Luck (http://www.kelvinluck.com/) |
| 26 | + * |
| 27 | + * @example $('#calendar-me').renderCalendar({month:0, year:2007}); |
| 28 | + * @desc Renders a calendar displaying January 2007 into the element with an id of calendar-me. |
| 29 | + * |
| 30 | + * @example |
| 31 | + * var testCallback = function($td, thisDate, month, year) |
| 32 | + * { |
| 33 | + * if ($td.is('.current-month') && thisDate.getDay() == 4) { |
| 34 | + * var d = thisDate.getDate(); |
| 35 | + * $td.bind( |
| 36 | + * 'click', |
| 37 | + * function() |
| 38 | + * { |
| 39 | + * alert('You clicked on ' + d + '/' + (Number(month)+1) + '/' + year); |
| 40 | + * } |
| 41 | + * ).addClass('thursday'); |
| 42 | + * } else if (thisDate.getDay() == 5) { |
| 43 | + * $td.html('Friday the ' + $td.html() + 'th'); |
| 44 | + * } |
| 45 | + * } |
| 46 | + * $('#calendar-me').renderCalendar({month:0, year:2007, renderCallback:testCallback}); |
| 47 | + * |
| 48 | + * @desc Renders a calendar displaying January 2007 into the element with an id of calendar-me. Every Thursday in the current month has a class of "thursday" applied to it, is clickable and shows an alert when clicked. Every Friday on the calendar has the number inside replaced with text. |
| 49 | + **/ |
| 50 | + renderCalendar : function(s) |
| 51 | + { |
| 52 | + var dc = function(a) |
| 53 | + { |
| 54 | + return document.createElement(a); |
| 55 | + }; |
| 56 | + |
| 57 | + s = $.extend( |
| 58 | + { |
| 59 | + month : null, |
| 60 | + year : null, |
| 61 | + renderCallback : null, |
| 62 | + showHeader : $.dpConst.SHOW_HEADER_SHORT, |
| 63 | + dpController : null, |
| 64 | + hoverClass : 'dp-hover' |
| 65 | + } |
| 66 | + , s |
| 67 | + ); |
| 68 | + |
| 69 | + if (s.showHeader != $.dpConst.SHOW_HEADER_NONE) { |
| 70 | + var headRow = $(dc('tr')); |
| 71 | + for (var i=Date.firstDayOfWeek; i<Date.firstDayOfWeek+7; i++) { |
| 72 | + var weekday = i%7; |
| 73 | + var day = Date.dayNames[weekday]; |
| 74 | + headRow.append( |
| 75 | + jQuery(dc('th')).attr({'scope':'col', 'abbr':day, 'title':day, 'class':(weekday == 0 || weekday == 6 ? 'weekend' : 'weekday')}).html(s.showHeader == $.dpConst.SHOW_HEADER_SHORT ? day.substr(0, 1) : day) |
| 76 | + ); |
| 77 | + } |
| 78 | + }; |
| 79 | + |
| 80 | + var calendarTable = $(dc('table')) |
| 81 | + .attr( |
| 82 | + { |
| 83 | + 'cellspacing':2, |
| 84 | + 'className':'jCalendar' |
| 85 | + } |
| 86 | + ) |
| 87 | + .append( |
| 88 | + (s.showHeader != $.dpConst.SHOW_HEADER_NONE ? |
| 89 | + $(dc('thead')) |
| 90 | + .append(headRow) |
| 91 | + : |
| 92 | + dc('thead') |
| 93 | + ) |
| 94 | + ); |
| 95 | + var tbody = $(dc('tbody')); |
| 96 | + |
| 97 | + var today = (new Date()).zeroTime(); |
| 98 | + |
| 99 | + var month = s.month == undefined ? today.getMonth() : s.month; |
| 100 | + var year = s.year || today.getFullYear(); |
| 101 | + |
| 102 | + var currentDate = new Date(year, month, 1); |
| 103 | + |
| 104 | + |
| 105 | + var firstDayOffset = Date.firstDayOfWeek - currentDate.getDay() + 1; |
| 106 | + if (firstDayOffset > 1) firstDayOffset -= 7; |
| 107 | + var weeksToDraw = Math.ceil(( (-1*firstDayOffset+1) + currentDate.getDaysInMonth() ) /7); |
| 108 | + currentDate.addDays(firstDayOffset-1); |
| 109 | + |
| 110 | + var doHover = function() |
| 111 | + { |
| 112 | + if (s.hoverClass) { |
| 113 | + $(this).addClass(s.hoverClass); |
| 114 | + } |
| 115 | + }; |
| 116 | + var unHover = function() |
| 117 | + { |
| 118 | + if (s.hoverClass) { |
| 119 | + $(this).removeClass(s.hoverClass); |
| 120 | + } |
| 121 | + }; |
| 122 | + |
| 123 | + var w = 0; |
| 124 | + while (w++<weeksToDraw) { |
| 125 | + var r = jQuery(dc('tr')); |
| 126 | + for (var i=0; i<7; i++) { |
| 127 | + var thisMonth = currentDate.getMonth() == month; |
| 128 | + var d = $(dc('td')) |
| 129 | + .text(currentDate.getDate() + '') |
| 130 | + .attr('className', (thisMonth ? 'current-month ' : 'other-month ') + |
| 131 | + (currentDate.isWeekend() ? 'weekend ' : 'weekday ') + |
| 132 | + (thisMonth && currentDate.getTime() == today.getTime() ? 'today ' : '') |
| 133 | + ) |
| 134 | + .hover(doHover, unHover) |
| 135 | + ; |
| 136 | + if (s.renderCallback) { |
| 137 | + s.renderCallback(d, currentDate, month, year); |
| 138 | + } |
| 139 | + r.append(d); |
| 140 | + currentDate.addDays(1); |
| 141 | + } |
| 142 | + tbody.append(r); |
| 143 | + } |
| 144 | + calendarTable.append(tbody); |
| 145 | + |
| 146 | + return this.each( |
| 147 | + function() |
| 148 | + { |
| 149 | + $(this).empty().append(calendarTable); |
| 150 | + } |
| 151 | + ); |
| 152 | + }, |
| 153 | +/** |
| 154 | + * Create a datePicker associated with each of the matched elements. |
| 155 | + * |
| 156 | + * The matched element will receive a few custom events with the following signatures: |
| 157 | + * |
| 158 | + * dateSelected(event, date, $td, status) |
| 159 | + * Triggered when a date is selected. event is a reference to the event, date is the Date selected, $td is a jquery object wrapped around the TD that was clicked on and status is whether the date was selected (true) or deselected (false) |
| 160 | + * |
| 161 | + * dpClosed(event, selected) |
| 162 | + * Triggered when the date picker is closed. event is a reference to the event and selected is an Array containing Date objects. |
| 163 | + * |
| 164 | + * dpMonthChanged(event, displayedMonth, displayedYear) |
| 165 | + * Triggered when the month of the popped up calendar is changed. event is a reference to the event, displayedMonth is the number of the month now displayed (zero based) and displayedYear is the year of the month. |
| 166 | + * |
| 167 | + * dpDisplayed(event, $datePickerDiv) |
| 168 | + * Triggered when the date picker is created. $datePickerDiv is the div containing the date picker. Use this event to add custom content/ listeners to the popped up date picker. |
| 169 | + * |
| 170 | + * @param Object s (optional) Customize your date pickers. |
| 171 | + * @option Number month The month to render when the date picker is opened (NOTE that months are zero based). Default is today's month. |
| 172 | + * @option Number year The year to render when the date picker is opened. Default is today's year. |
| 173 | + * @option String startDate The first date date can be selected. |
| 174 | + * @option String endDate The last date that can be selected. |
| 175 | + * @option Boolean inline Whether to create the datePicker as inline (e.g. always on the page) or as a model popup. Default is false (== modal popup) |
| 176 | + * @option Boolean createButton Whether to create a .dp-choose-date anchor directly after the matched element which when clicked will trigger the showing of the date picker. Default is true. |
| 177 | + * @option Boolean showYearNavigation Whether to display buttons which allow the user to navigate through the months a year at a time. Default is true. |
| 178 | + * @option Boolean closeOnSelect Whether to close the date picker when a date is selected. Default is true. |
| 179 | + * @option Boolean displayClose Whether to create a "Close" button within the date picker popup. Default is false. |
| 180 | + * @option Boolean selectMultiple Whether a user should be able to select multiple dates with this date picker. Default is false. |
| 181 | + * @option Boolean clickInput If the matched element is an input type="text" and this option is true then clicking on the input will cause the date picker to appear. |
| 182 | + * @option Number verticalPosition The vertical alignment of the popped up date picker to the matched element. One of $.dpConst.POS_TOP and $.dpConst.POS_BOTTOM. Default is $.dpConst.POS_TOP. |
| 183 | + * @option Number horizontalPosition The horizontal alignment of the popped up date picker to the matched element. One of $.dpConst.POS_LEFT and $.dpConst.POS_RIGHT. |
| 184 | + * @option Number verticalOffset The number of pixels offset from the defined verticalPosition of this date picker that it should pop up in. Default in 0. |
| 185 | + * @option Number horizontalOffset The number of pixels offset from the defined horizontalPosition of this date picker that it should pop up in. Default in 0. |
| 186 | + * @option (Function|Array) renderCallback A reference to a function (or an array of separate functions) that is called as each cell is rendered and which can add classes and event listeners to the created nodes. Each callback function will receive four arguments; a jquery object wrapping the created TD, a Date object containing the date this TD represents, a number giving the currently rendered month and a number giving the currently rendered year. Default is no callback. |
| 187 | + * @option String hoverClass The class to attach to each cell when you hover over it (to allow you to use hover effects in IE6 which doesn't support the :hover pseudo-class on elements other than links). Default is dp-hover. Pass false if you don't want a hover class. |
| 188 | + * @type jQuery |
| 189 | + * @name datePicker |
| 190 | + * @cat plugins/datePicker |
| 191 | + * @author Kelvin Luck (http://www.kelvinluck.com/) |
| 192 | + * |
| 193 | + * @example $('input.date-picker').datePicker(); |
| 194 | + * @desc Creates a date picker button next to all matched input elements. When the button is clicked on the value of the selected date will be placed in the corresponding input (formatted according to Date.format). |
| 195 | + * |
| 196 | + * @example demo/index.html |
| 197 | + * @desc See the projects homepage for many more complex examples... |
| 198 | + **/ |
| 199 | + datePicker : function(s) |
| 200 | + { |
| 201 | + if (!$.event._dpCache) $.event._dpCache = []; |
| 202 | + |
| 203 | + // initialise the date picker controller with the relevant settings... |
| 204 | + s = $.extend( |
| 205 | + { |
| 206 | + month : undefined, |
| 207 | + year : undefined, |
| 208 | + startDate : undefined, |
| 209 | + endDate : undefined, |
| 210 | + inline : false, |
| 211 | + renderCallback : [], |
| 212 | + createButton : true, |
| 213 | + showYearNavigation : true, |
| 214 | + closeOnSelect : true, |
| 215 | + displayClose : false, |
| 216 | + selectMultiple : false, |
| 217 | + clickInput : false, |
| 218 | + verticalPosition : $.dpConst.POS_TOP, |
| 219 | + horizontalPosition : $.dpConst.POS_LEFT, |
| 220 | + verticalOffset : 0, |
| 221 | + horizontalOffset : 0, |
| 222 | + hoverClass : 'dp-hover' |
| 223 | + } |
| 224 | + , s |
| 225 | + ); |
| 226 | + |
| 227 | + return this.each( |
| 228 | + function() |
| 229 | + { |
| 230 | + var $this = $(this); |
| 231 | + var alreadyExists = true; |
| 232 | + |
| 233 | + if (!this._dpId) { |
| 234 | + this._dpId = $.event.guid++; |
| 235 | + $.event._dpCache[this._dpId] = new DatePicker(this); |
| 236 | + alreadyExists = false; |
| 237 | + } |
| 238 | + |
| 239 | + if (s.inline) { |
| 240 | + s.createButton = false; |
| 241 | + s.displayClose = false; |
| 242 | + s.closeOnSelect = false; |
| 243 | + $this.empty(); |
| 244 | + } |
| 245 | + |
| 246 | + var controller = $.event._dpCache[this._dpId]; |
| 247 | + |
| 248 | + controller.init(s); |
| 249 | + |
| 250 | + if (!alreadyExists && s.createButton) { |
| 251 | + // create it! |
| 252 | + controller.button = $('<a href="#" class="dp-choose-date" title="' + $.dpText.TEXT_CHOOSE_DATE + '">' + $.dpText.TEXT_CHOOSE_DATE + '</a>') |
| 253 | + .bind( |
| 254 | + 'click', |
| 255 | + function() |
| 256 | + { |
| 257 | + $this.dpDisplay(this); |
| 258 | + this.blur(); |
| 259 | + return false; |
| 260 | + } |
| 261 | + ); |
| 262 | + $this.after(controller.button); |
| 263 | + } |
| 264 | + |
| 265 | + if (!alreadyExists && $this.is(':text')) { |
| 266 | + $this |
| 267 | + .bind( |
| 268 | + 'dateSelected', |
| 269 | + function(e, selectedDate, $td) |
| 270 | + { |
| 271 | + this.value = selectedDate.asString(); |
| 272 | + } |
| 273 | + ).bind( |
| 274 | + 'change', |
| 275 | + function() |
| 276 | + { |
| 277 | + var d = Date.fromString(this.value); |
| 278 | + if (d) { |
| 279 | + controller.setSelected(d, true, true); |
| 280 | + } |
| 281 | + } |
| 282 | + ); |
| 283 | + if (s.clickInput) { |
| 284 | + $this.bind( |
| 285 | + 'click', |
| 286 | + function() |
| 287 | + { |
| 288 | + $this.dpDisplay(); |
| 289 | + } |
| 290 | + ); |
| 291 | + } |
| 292 | + var d = Date.fromString(this.value); |
| 293 | + if (this.value != '' && d) { |
| 294 | + controller.setSelected(d, true, true); |
| 295 | + } |
| 296 | + } |
| 297 | + |
| 298 | + $this.addClass('dp-applied'); |
| 299 | + |
| 300 | + } |
| 301 | + ) |
| 302 | + }, |
| 303 | +/** |
| 304 | + * Disables or enables this date picker |
| 305 | + * |
| 306 | + * @param Boolean s Whether to disable (true) or enable (false) this datePicker |
| 307 | + * @type jQuery |
| 308 | + * @name dpSetDisabled |
| 309 | + * @cat plugins/datePicker |
| 310 | + * @author Kelvin Luck (http://www.kelvinluck.com/) |
| 311 | + * |
| 312 | + * @example $('.date-picker').datePicker(); |
| 313 | + * $('.date-picker').dpSetDisabled(true); |
| 314 | + * @desc Prevents this date picker from displaying and adds a class of dp-disabled to it (and it's associated button if it has one) for styling purposes. If the matched element is an input field then it will also set the disabled attribute to stop people directly editing the field. |
| 315 | + **/ |
| 316 | + dpSetDisabled : function(s) |
| 317 | + { |
| 318 | + return _w.call(this, 'setDisabled', s); |
| 319 | + }, |
| 320 | +/** |
| 321 | + * Updates the first selectable date for any date pickers on any matched elements. |
| 322 | + * |
| 323 | + * @param String d A string representing the first selectable date (formatted according to Date.format). |
| 324 | + * @type jQuery |
| 325 | + * @name dpSetStartDate |
| 326 | + * @cat plugins/datePicker |
| 327 | + * @author Kelvin Luck (http://www.kelvinluck.com/) |
| 328 | + * |
| 329 | + * @example $('.date-picker').datePicker(); |
| 330 | + * $('.date-picker').dpSetStartDate('01/01/2000'); |
| 331 | + * @desc Creates a date picker associated with all elements with a class of "date-picker" then sets the first selectable date for each of these to the first day of the millenium. |
| 332 | + **/ |
| 333 | + dpSetStartDate : function(d) |
| 334 | + { |
| 335 | + return _w.call(this, 'setStartDate', d); |
| 336 | + }, |
| 337 | +/** |
| 338 | + * Updates the last selectable date for any date pickers on any matched elements. |
| 339 | + * |
| 340 | + * @param String d A string representing the last selectable date (formatted according to Date.format). |
| 341 | + * @type jQuery |
| 342 | + * @name dpSetEndDate |
| 343 | + * @cat plugins/datePicker |
| 344 | + * @author Kelvin Luck (http://www.kelvinluck.com/) |
| 345 | + * |
| 346 | + * @example $('.date-picker').datePicker(); |
| 347 | + * $('.date-picker').dpSetEndDate('01/01/2010'); |
| 348 | + * @desc Creates a date picker associated with all elements with a class of "date-picker" then sets the last selectable date for each of these to the first Janurary 2010. |
| 349 | + **/ |
| 350 | + dpSetEndDate : function(d) |
| 351 | + { |
| 352 | + return _w.call(this, 'setEndDate', d); |
| 353 | + }, |
| 354 | +/** |
| 355 | + * Gets a list of Dates currently selected by this datePicker. This will be an empty array if no dates are currently selected or NULL if there is no datePicker associated with the matched element. |
| 356 | + * |
| 357 | + * @type Array |
| 358 | + * @name dpGetSelected |
| 359 | + * @cat plugins/datePicker |
| 360 | + * @author Kelvin Luck (http://www.kelvinluck.com/) |
| 361 | + * |
| 362 | + * @example $('.date-picker').datePicker(); |
| 363 | + * alert($('.date-picker').dpGetSelected()); |
| 364 | + * @desc Will alert an empty array (as nothing is selected yet) |
| 365 | + **/ |
| 366 | + dpGetSelected : function() |
| 367 | + { |
| 368 | + var c = _getController(this[0]); |
| 369 | + if (c) { |
| 370 | + return c.getSelected(); |
| 371 | + } |
| 372 | + return null; |
| 373 | + }, |
| 374 | +/** |
| 375 | + * Selects or deselects a date on any matched element's date pickers. Deselcting is only useful on date pickers where selectMultiple==true. Selecting will only work if the passed date is within the startDate and endDate boundries for a given date picker. |
| 376 | + * |
| 377 | + * @param String d A string representing the date you want to select (formatted according to Date.format). |
| 378 | + * @param Boolean v Whether you want to select (true) or deselect (false) this date. Optional - default = true. |
| 379 | + * @param Boolean m Whether you want the date picker to open up on the month of this date when it is next opened. Optional - default = true. |
| 380 | + * @type jQuery |
| 381 | + * @name dpSetSelected |
| 382 | + * @cat plugins/datePicker |
| 383 | + * @author Kelvin Luck (http://www.kelvinluck.com/) |
| 384 | + * |
| 385 | + * @example $('.date-picker').datePicker(); |
| 386 | + * $('.date-picker').dpSetSelected('01/01/2010'); |
| 387 | + * @desc Creates a date picker associated with all elements with a class of "date-picker" then sets the selected date on these date pickers to the first Janurary 2010. When the date picker is next opened it will display Janurary 2010. |
| 388 | + **/ |
| 389 | + dpSetSelected : function(d, v, m) |
| 390 | + { |
| 391 | + if (v == undefined) v=true; |
| 392 | + if (m == undefined) m=true; |
| 393 | + return _w.call(this, 'setSelected', Date.fromString(d), v, m); |
| 394 | + }, |
| 395 | +/** |
| 396 | + * Sets the month that will be displayed when the date picker is next opened. If the passed month is before startDate then the month containing startDate will be displayed instead. If the passed month is after endDate then the month containing the endDate will be displayed instead. |
| 397 | + * |
| 398 | + * @param Number m The month you want the date picker to display. Optional - defaults to the currently displayed month. |
| 399 | + * @param Number y The year you want the date picker to display. Optional - defaults to the currently displayed year. |
| 400 | + * @type jQuery |
| 401 | + * @name dpSetDisplayedMonth |
| 402 | + * @cat plugins/datePicker |
| 403 | + * @author Kelvin Luck (http://www.kelvinluck.com/) |
| 404 | + * |
| 405 | + * @example $('.date-picker').datePicker(); |
| 406 | + * $('.date-picker').dpSetDisplayedMonth(10, 2008); |
| 407 | + * @desc Creates a date picker associated with all elements with a class of "date-picker" then sets the selected date on these date pickers to the first Janurary 2010. When the date picker is next opened it will display Janurary 2010. |
| 408 | + **/ |
| 409 | + dpSetDisplayedMonth : function(m, y) |
| 410 | + { |
| 411 | + return _w.call(this, 'setDisplayedMonth', Number(m), Number(y)); |
| 412 | + }, |
| 413 | +/** |
| 414 | + * Displays the date picker associated with the matched elements. Since only one date picker can be displayed at once then the date picker associated with the last matched element will be the one that is displayed. |
| 415 | + * |
| 416 | + * @param HTMLElement e An element that you want the date picker to pop up relative in position to. Optional - default behaviour is to pop up next to the element associated with this date picker. |
| 417 | + * @type jQuery |
| 418 | + * @name dpDisplay |
| 419 | + * @cat plugins/datePicker |
| 420 | + * @author Kelvin Luck (http://www.kelvinluck.com/) |
| 421 | + * |
| 422 | + * @example $('#date-picker').datePicker(); |
| 423 | + * $('#date-picker').dpDisplay(); |
| 424 | + * @desc Creates a date picker associated with the element with an id of date-picker and then causes it to pop up. |
| 425 | + **/ |
| 426 | + dpDisplay : function(e) |
| 427 | + { |
| 428 | + return _w.call(this, 'display', e); |
| 429 | + }, |
| 430 | +/** |
| 431 | + * Sets a function or array of functions that is called when each TD of the date picker popup is rendered to the page |
| 432 | + * |
| 433 | + * @param (Function|Array) a A function or an array of functions that are called when each td is rendered. Each function will receive four arguments; a jquery object wrapping the created TD, a Date object containing the date this TD represents, a number giving the currently rendered month and a number giving the currently rendered year. |
| 434 | + * @type jQuery |
| 435 | + * @name dpSetRenderCallback |
| 436 | + * @cat plugins/datePicker |
| 437 | + * @author Kelvin Luck (http://www.kelvinluck.com/) |
| 438 | + * |
| 439 | + * @example $('#date-picker').datePicker(); |
| 440 | + * $('#date-picker').dpSetRenderCallback(function($td, thisDate, month, year) |
| 441 | + * { |
| 442 | + * // do stuff as each td is rendered dependant on the date in the td and the displayed month and year |
| 443 | + * }); |
| 444 | + * @desc Creates a date picker associated with the element with an id of date-picker and then creates a function which is called as each td is rendered when this date picker is displayed. |
| 445 | + **/ |
| 446 | + dpSetRenderCallback : function(a) |
| 447 | + { |
| 448 | + return _w.call(this, 'setRenderCallback', a); |
| 449 | + }, |
| 450 | +/** |
| 451 | + * Sets the position that the datePicker will pop up (relative to it's associated element) |
| 452 | + * |
| 453 | + * @param Number v The vertical alignment of the created date picker to it's associated element. Possible values are $.dpConst.POS_TOP and $.dpConst.POS_BOTTOM |
| 454 | + * @param Number h The horizontal alignment of the created date picker to it's associated element. Possible values are $.dpConst.POS_LEFT and $.dpConst.POS_RIGHT |
| 455 | + * @type jQuery |
| 456 | + * @name dpSetPosition |
| 457 | + * @cat plugins/datePicker |
| 458 | + * @author Kelvin Luck (http://www.kelvinluck.com/) |
| 459 | + * |
| 460 | + * @example $('#date-picker').datePicker(); |
| 461 | + * $('#date-picker').dpSetPosition($.dpConst.POS_BOTTOM, $.dpConst.POS_RIGHT); |
| 462 | + * @desc Creates a date picker associated with the element with an id of date-picker and makes it so that when this date picker pops up it will be bottom and right aligned to the #date-picker element. |
| 463 | + **/ |
| 464 | + dpSetPosition : function(v, h) |
| 465 | + { |
| 466 | + return _w.call(this, 'setPosition', v, h); |
| 467 | + }, |
| 468 | +/** |
| 469 | + * Sets the offset that the popped up date picker will have from it's default position relative to it's associated element (as set by dpSetPosition) |
| 470 | + * |
| 471 | + * @param Number v The vertical offset of the created date picker. |
| 472 | + * @param Number h The horizontal offset of the created date picker. |
| 473 | + * @type jQuery |
| 474 | + * @name dpSetOffset |
| 475 | + * @cat plugins/datePicker |
| 476 | + * @author Kelvin Luck (http://www.kelvinluck.com/) |
| 477 | + * |
| 478 | + * @example $('#date-picker').datePicker(); |
| 479 | + * $('#date-picker').dpSetOffset(-20, 200); |
| 480 | + * @desc Creates a date picker associated with the element with an id of date-picker and makes it so that when this date picker pops up it will be 20 pixels above and 200 pixels to the right of it's default position. |
| 481 | + **/ |
| 482 | + dpSetOffset : function(v, h) |
| 483 | + { |
| 484 | + return _w.call(this, 'setOffset', v, h); |
| 485 | + }, |
| 486 | +/** |
| 487 | + * Closes the open date picker associated with this element. |
| 488 | + * |
| 489 | + * @type jQuery |
| 490 | + * @name dpClose |
| 491 | + * @cat plugins/datePicker |
| 492 | + * @author Kelvin Luck (http://www.kelvinluck.com/) |
| 493 | + * |
| 494 | + * @example $('.date-pick') |
| 495 | + * .datePicker() |
| 496 | + * .bind( |
| 497 | + * 'focus', |
| 498 | + * function() |
| 499 | + * { |
| 500 | + * $(this).dpDisplay(); |
| 501 | + * } |
| 502 | + * ).bind( |
| 503 | + * 'blur', |
| 504 | + * function() |
| 505 | + * { |
| 506 | + * $(this).dpClose(); |
| 507 | + * } |
| 508 | + * ); |
| 509 | + * @desc Creates a date picker and makes it appear when the relevant element is focused and disappear when it is blurred. |
| 510 | + **/ |
| 511 | + dpClose : function() |
| 512 | + { |
| 513 | + return _w.call(this, '_closeCalendar', false, this[0]); |
| 514 | + }, |
| 515 | + // private function called on unload to clean up any expandos etc and prevent memory links... |
| 516 | + _dpDestroy : function() |
| 517 | + { |
| 518 | + // TODO - implement this? |
| 519 | + } |
| 520 | + }); |
| 521 | + |
| 522 | + // private internal function to cut down on the amount of code needed where we forward |
| 523 | + // dp* methods on the jQuery object on to the relevant DatePicker controllers... |
| 524 | + var _w = function(f, a1, a2, a3) |
| 525 | + { |
| 526 | + return this.each( |
| 527 | + function() |
| 528 | + { |
| 529 | + var c = _getController(this); |
| 530 | + if (c) { |
| 531 | + c[f](a1, a2, a3); |
| 532 | + } |
| 533 | + } |
| 534 | + ); |
| 535 | + }; |
| 536 | + |
| 537 | + function DatePicker(ele) |
| 538 | + { |
| 539 | + this.ele = ele; |
| 540 | + |
| 541 | + // initial values... |
| 542 | + this.displayedMonth = null; |
| 543 | + this.displayedYear = null; |
| 544 | + this.startDate = null; |
| 545 | + this.endDate = null; |
| 546 | + this.showYearNavigation = null; |
| 547 | + this.closeOnSelect = null; |
| 548 | + this.displayClose = null; |
| 549 | + this.selectMultiple = null; |
| 550 | + this.verticalPosition = null; |
| 551 | + this.horizontalPosition = null; |
| 552 | + this.verticalOffset = null; |
| 553 | + this.horizontalOffset = null; |
| 554 | + this.button = null; |
| 555 | + this.renderCallback = []; |
| 556 | + this.selectedDates = {}; |
| 557 | + this.inline = null; |
| 558 | + this.context = '#dp-popup'; |
| 559 | + }; |
| 560 | + $.extend( |
| 561 | + DatePicker.prototype, |
| 562 | + { |
| 563 | + init : function(s) |
| 564 | + { |
| 565 | + this.setStartDate(s.startDate); |
| 566 | + this.setEndDate(s.endDate); |
| 567 | + this.setDisplayedMonth(Number(s.month), Number(s.year)); |
| 568 | + this.setRenderCallback(s.renderCallback); |
| 569 | + this.showYearNavigation = s.showYearNavigation; |
| 570 | + this.closeOnSelect = s.closeOnSelect; |
| 571 | + this.displayClose = s.displayClose; |
| 572 | + this.selectMultiple = s.selectMultiple; |
| 573 | + this.verticalPosition = s.verticalPosition; |
| 574 | + this.horizontalPosition = s.horizontalPosition; |
| 575 | + this.hoverClass = s.hoverClass; |
| 576 | + this.setOffset(s.verticalOffset, s.horizontalOffset); |
| 577 | + this.inline = s.inline; |
| 578 | + if (this.inline) { |
| 579 | + this.context = this.ele; |
| 580 | + this.display(); |
| 581 | + } |
| 582 | + }, |
| 583 | + setStartDate : function(d) |
| 584 | + { |
| 585 | + if (d) { |
| 586 | + this.startDate = Date.fromString(d); |
| 587 | + } |
| 588 | + if (!this.startDate) { |
| 589 | + this.startDate = (new Date()).zeroTime(); |
| 590 | + } |
| 591 | + this.setDisplayedMonth(this.displayedMonth, this.displayedYear); |
| 592 | + }, |
| 593 | + setEndDate : function(d) |
| 594 | + { |
| 595 | + if (d) { |
| 596 | + this.endDate = Date.fromString(d); |
| 597 | + } |
| 598 | + if (!this.endDate) { |
| 599 | + this.endDate = (new Date('12/31/2999')); // using the JS Date.parse function which expects mm/dd/yyyy |
| 600 | + } |
| 601 | + if (this.endDate.getTime() < this.startDate.getTime()) { |
| 602 | + this.endDate = this.startDate; |
| 603 | + } |
| 604 | + this.setDisplayedMonth(this.displayedMonth, this.displayedYear); |
| 605 | + }, |
| 606 | + setPosition : function(v, h) |
| 607 | + { |
| 608 | + this.verticalPosition = v; |
| 609 | + this.horizontalPosition = h; |
| 610 | + }, |
| 611 | + setOffset : function(v, h) |
| 612 | + { |
| 613 | + this.verticalOffset = parseInt(v) || 0; |
| 614 | + this.horizontalOffset = parseInt(h) || 0; |
| 615 | + }, |
| 616 | + setDisabled : function(s) |
| 617 | + { |
| 618 | + $e = $(this.ele); |
| 619 | + $e[s ? 'addClass' : 'removeClass']('dp-disabled'); |
| 620 | + if (this.button) { |
| 621 | + $but = $(this.button); |
| 622 | + $but[s ? 'addClass' : 'removeClass']('dp-disabled'); |
| 623 | + $but.attr('title', s ? '' : $.dpText.TEXT_CHOOSE_DATE); |
| 624 | + } |
| 625 | + if ($e.is(':text')) { |
| 626 | + $e.attr('disabled', s ? 'disabled' : ''); |
| 627 | + } |
| 628 | + }, |
| 629 | + setDisplayedMonth : function(m, y) |
| 630 | + { |
| 631 | + if (this.startDate == undefined || this.endDate == undefined) { |
| 632 | + return; |
| 633 | + } |
| 634 | + var s = new Date(this.startDate.getTime()); |
| 635 | + s.setDate(1); |
| 636 | + var e = new Date(this.endDate.getTime()); |
| 637 | + e.setDate(1); |
| 638 | + |
| 639 | + var t; |
| 640 | + if ((!m && !y) || (isNaN(m) && isNaN(y))) { |
| 641 | + // no month or year passed - default to current month |
| 642 | + t = new Date().zeroTime(); |
| 643 | + t.setDate(1); |
| 644 | + } else if (isNaN(m)) { |
| 645 | + // just year passed in - presume we want the displayedMonth |
| 646 | + t = new Date(y, this.displayedMonth, 1); |
| 647 | + } else if (isNaN(y)) { |
| 648 | + // just month passed in - presume we want the displayedYear |
| 649 | + t = new Date(this.displayedYear, m, 1); |
| 650 | + } else { |
| 651 | + // year and month passed in - that's the date we want! |
| 652 | + t = new Date(y, m, 1) |
| 653 | + } |
| 654 | + |
| 655 | + // check if the desired date is within the range of our defined startDate and endDate |
| 656 | + if (t.getTime() < s.getTime()) { |
| 657 | + t = s; |
| 658 | + } else if (t.getTime() > e.getTime()) { |
| 659 | + t = e; |
| 660 | + } |
| 661 | + this.displayedMonth = t.getMonth(); |
| 662 | + this.displayedYear = t.getFullYear(); |
| 663 | + }, |
| 664 | + setSelected : function(d, v, moveToMonth) |
| 665 | + { |
| 666 | + if (this.selectMultiple == false) { |
| 667 | + this.selectedDates = {}; |
| 668 | + $('td.selected', this.context).removeClass('selected'); |
| 669 | + } |
| 670 | + if (moveToMonth) { |
| 671 | + this.setDisplayedMonth(d.getMonth(), d.getFullYear()); |
| 672 | + } |
| 673 | + this.selectedDates[d.toString()] = v; |
| 674 | + }, |
| 675 | + isSelected : function(d) |
| 676 | + { |
| 677 | + return this.selectedDates[d.toString()]; |
| 678 | + }, |
| 679 | + getSelected : function() |
| 680 | + { |
| 681 | + var r = []; |
| 682 | + for(s in this.selectedDates) { |
| 683 | + if (this.selectedDates[s] == true) { |
| 684 | + r.push(Date.parse(s)); |
| 685 | + } |
| 686 | + } |
| 687 | + return r; |
| 688 | + }, |
| 689 | + display : function(eleAlignTo) |
| 690 | + { |
| 691 | + if ($(this.ele).is('.dp-disabled')) return; |
| 692 | + |
| 693 | + eleAlignTo = eleAlignTo || this.ele; |
| 694 | + var c = this; |
| 695 | + var $ele = $(eleAlignTo); |
| 696 | + var eleOffset = $ele.offset(); |
| 697 | + |
| 698 | + var $createIn; |
| 699 | + var attrs; |
| 700 | + var attrsCalendarHolder; |
| 701 | + var cssRules; |
| 702 | + |
| 703 | + if (c.inline) { |
| 704 | + $createIn = $(this.ele); |
| 705 | + attrs = { |
| 706 | + 'id' : 'calendar-' + this.ele._dpId, |
| 707 | + 'className' : 'dp-popup dp-popup-inline' |
| 708 | + }; |
| 709 | + cssRules = { |
| 710 | + }; |
| 711 | + } else { |
| 712 | + $createIn = $('body'); |
| 713 | + attrs = { |
| 714 | + 'id' : 'dp-popup', |
| 715 | + 'className' : 'dp-popup' |
| 716 | + }; |
| 717 | + cssRules = { |
| 718 | + 'top' : eleOffset.top + c.verticalOffset, |
| 719 | + 'left' : eleOffset.left + c.horizontalOffset |
| 720 | + }; |
| 721 | + |
| 722 | + var _checkMouse = function(e) |
| 723 | + { |
| 724 | + var el = e.target; |
| 725 | + var cal = $('#dp-popup')[0]; |
| 726 | + |
| 727 | + while (true){ |
| 728 | + if (el == cal) { |
| 729 | + return true; |
| 730 | + } else if (el == document) { |
| 731 | + c._closeCalendar(); |
| 732 | + return false; |
| 733 | + } else { |
| 734 | + el = $(el).parent()[0]; |
| 735 | + } |
| 736 | + } |
| 737 | + }; |
| 738 | + this._checkMouse = _checkMouse; |
| 739 | + |
| 740 | + this._closeCalendar(true); |
| 741 | + } |
| 742 | + |
| 743 | + |
| 744 | + $createIn |
| 745 | + .append( |
| 746 | + $('<div></div>') |
| 747 | + .attr(attrs) |
| 748 | + .css(cssRules) |
| 749 | + .append( |
| 750 | + $('<h2></h2>'), |
| 751 | + $('<div class="dp-nav-prev"></div>') |
| 752 | + .append( |
| 753 | + $('<a class="dp-nav-prev-year" href="#" title="' + $.dpText.TEXT_PREV_YEAR + '"><<</a>') |
| 754 | + .bind( |
| 755 | + 'click', |
| 756 | + function() |
| 757 | + { |
| 758 | + return c._displayNewMonth.call(c, this, 0, -1); |
| 759 | + } |
| 760 | + ), |
| 761 | + $('<a class="dp-nav-prev-month" href="#" title="' + $.dpText.TEXT_PREV_MONTH + '"><</a>') |
| 762 | + .bind( |
| 763 | + 'click', |
| 764 | + function() |
| 765 | + { |
| 766 | + return c._displayNewMonth.call(c, this, -1, 0); |
| 767 | + } |
| 768 | + ) |
| 769 | + ), |
| 770 | + $('<div class="dp-nav-next"></div>') |
| 771 | + .append( |
| 772 | + $('<a class="dp-nav-next-year" href="#" title="' + $.dpText.TEXT_NEXT_YEAR + '">>></a>') |
| 773 | + .bind( |
| 774 | + 'click', |
| 775 | + function() |
| 776 | + { |
| 777 | + return c._displayNewMonth.call(c, this, 0, 1); |
| 778 | + } |
| 779 | + ), |
| 780 | + $('<a class="dp-nav-next-month" href="#" title="' + $.dpText.TEXT_NEXT_MONTH + '">></a>') |
| 781 | + .bind( |
| 782 | + 'click', |
| 783 | + function() |
| 784 | + { |
| 785 | + return c._displayNewMonth.call(c, this, 1, 0); |
| 786 | + } |
| 787 | + ) |
| 788 | + ), |
| 789 | + $('<div></div>') |
| 790 | + .attr('className', 'dp-calendar') |
| 791 | + ) |
| 792 | + .bgIframe() |
| 793 | + ); |
| 794 | + |
| 795 | + var $pop = this.inline ? $('.dp-popup', this.context) : $('#dp-popup'); |
| 796 | + |
| 797 | + if (this.showYearNavigation == false) { |
| 798 | + $('.dp-nav-prev-year, .dp-nav-next-year', c.context).css('display', 'none'); |
| 799 | + } |
| 800 | + if (this.displayClose) { |
| 801 | + $pop.append( |
| 802 | + $('<a href="#" id="dp-close">' + $.dpText.TEXT_CLOSE + '</a>') |
| 803 | + .bind( |
| 804 | + 'click', |
| 805 | + function() |
| 806 | + { |
| 807 | + c._closeCalendar(); |
| 808 | + return false; |
| 809 | + } |
| 810 | + ) |
| 811 | + ); |
| 812 | + } |
| 813 | + c._renderCalendar(); |
| 814 | + |
| 815 | + $(this.ele).trigger('dpDisplayed', $pop); |
| 816 | + |
| 817 | + if (!c.inline) { |
| 818 | + if (this.verticalPosition == $.dpConst.POS_BOTTOM) { |
| 819 | + $pop.css('top', eleOffset.top + $ele.height() - $pop.height() + c.verticalOffset); |
| 820 | + } |
| 821 | + if (this.horizontalPosition == $.dpConst.POS_RIGHT) { |
| 822 | + $pop.css('left', eleOffset.left + $ele.width() - $pop.width() + c.horizontalOffset); |
| 823 | + } |
| 824 | + $(document).bind('mousedown', this._checkMouse); |
| 825 | + } |
| 826 | + }, |
| 827 | + setRenderCallback : function(a) |
| 828 | + { |
| 829 | + if (a && typeof(a) == 'function') { |
| 830 | + a = [a]; |
| 831 | + } |
| 832 | + this.renderCallback = this.renderCallback.concat(a); |
| 833 | + }, |
| 834 | + cellRender : function ($td, thisDate, month, year) { |
| 835 | + var c = this.dpController; |
| 836 | + var d = new Date(thisDate.getTime()); |
| 837 | + |
| 838 | + // add our click handlers to deal with it when the days are clicked... |
| 839 | + |
| 840 | + $td.bind( |
| 841 | + 'click', |
| 842 | + function() |
| 843 | + { |
| 844 | + var $this = $(this); |
| 845 | + if (!$this.is('.disabled')) { |
| 846 | + c.setSelected(d, !$this.is('.selected') || !c.selectMultiple); |
| 847 | + var s = c.isSelected(d); |
| 848 | + $(c.ele).trigger('dateSelected', [d, $td, s]); |
| 849 | + $(c.ele).trigger('change'); |
| 850 | + if (c.closeOnSelect) { |
| 851 | + c._closeCalendar(); |
| 852 | + } else { |
| 853 | + $this[s ? 'addClass' : 'removeClass']('selected'); |
| 854 | + } |
| 855 | + } |
| 856 | + } |
| 857 | + ); |
| 858 | + |
| 859 | + if (c.isSelected(d)) { |
| 860 | + $td.addClass('selected'); |
| 861 | + } |
| 862 | + |
| 863 | + // call any extra renderCallbacks that were passed in |
| 864 | + for (var i=0; i<c.renderCallback.length; i++) { |
| 865 | + c.renderCallback[i].apply(this, arguments); |
| 866 | + } |
| 867 | + |
| 868 | + |
| 869 | + }, |
| 870 | + // ele is the clicked button - only proceed if it doesn't have the class disabled... |
| 871 | + // m and y are -1, 0 or 1 depending which direction we want to go in... |
| 872 | + _displayNewMonth : function(ele, m, y) |
| 873 | + { |
| 874 | + if (!$(ele).is('.disabled')) { |
| 875 | + this.setDisplayedMonth(this.displayedMonth + m, this.displayedYear + y); |
| 876 | + this._clearCalendar(); |
| 877 | + this._renderCalendar(); |
| 878 | + $(this.ele).trigger('dpMonthChanged', [this.displayedMonth, this.displayedYear]); |
| 879 | + } |
| 880 | + ele.blur(); |
| 881 | + return false; |
| 882 | + }, |
| 883 | + _renderCalendar : function() |
| 884 | + { |
| 885 | + // set the title... |
| 886 | + $('h2', this.context).html(Date.monthNames[this.displayedMonth] + ' ' + this.displayedYear); |
| 887 | + |
| 888 | + // render the calendar... |
| 889 | + $('.dp-calendar', this.context).renderCalendar( |
| 890 | + { |
| 891 | + month : this.displayedMonth, |
| 892 | + year : this.displayedYear, |
| 893 | + renderCallback : this.cellRender, |
| 894 | + dpController : this, |
| 895 | + hoverClass : this.hoverClass |
| 896 | + } |
| 897 | + ); |
| 898 | + |
| 899 | + // update the status of the control buttons and disable dates before startDate or after endDate... |
| 900 | + // TODO: When should the year buttons be disabled? When you can't go forward a whole year from where you are or is that annoying? |
| 901 | + if (this.displayedYear == this.startDate.getFullYear() && this.displayedMonth == this.startDate.getMonth()) { |
| 902 | + $('.dp-nav-prev-year', this.context).addClass('disabled'); |
| 903 | + $('.dp-nav-prev-month', this.context).addClass('disabled'); |
| 904 | + $('.dp-calendar td.other-month', this.context).each( |
| 905 | + function() |
| 906 | + { |
| 907 | + var $this = $(this); |
| 908 | + if (Number($this.text()) > 20) { |
| 909 | + $this.addClass('disabled'); |
| 910 | + } |
| 911 | + } |
| 912 | + ); |
| 913 | + var d = this.startDate.getDate(); |
| 914 | + $('.dp-calendar td.current-month', this.context).each( |
| 915 | + function() |
| 916 | + { |
| 917 | + var $this = $(this); |
| 918 | + if (Number($this.text()) < d) { |
| 919 | + $this.addClass('disabled'); |
| 920 | + } |
| 921 | + } |
| 922 | + ); |
| 923 | + } else { |
| 924 | + $('.dp-nav-prev-year', this.context).removeClass('disabled'); |
| 925 | + $('.dp-nav-prev-month', this.context).removeClass('disabled'); |
| 926 | + var d = this.startDate.getDate(); |
| 927 | + if (d > 20) { |
| 928 | + // check if the startDate is last month as we might need to add some disabled classes... |
| 929 | + var sd = new Date(this.startDate.getTime()); |
| 930 | + sd.addMonths(1); |
| 931 | + if (this.displayedYear == sd.getFullYear() && this.displayedMonth == sd.getMonth()) { |
| 932 | + $('dp-calendar td.other-month', this.context).each( |
| 933 | + function() |
| 934 | + { |
| 935 | + var $this = $(this); |
| 936 | + if (Number($this.text()) < d) { |
| 937 | + $this.addClass('disabled'); |
| 938 | + } |
| 939 | + } |
| 940 | + ); |
| 941 | + } |
| 942 | + } |
| 943 | + } |
| 944 | + if (this.displayedYear == this.endDate.getFullYear() && this.displayedMonth == this.endDate.getMonth()) { |
| 945 | + $('.dp-nav-next-year', this.context).addClass('disabled'); |
| 946 | + $('.dp-nav-next-month', this.context).addClass('disabled'); |
| 947 | + $('.dp-calendar td.other-month', this.context).each( |
| 948 | + function() |
| 949 | + { |
| 950 | + var $this = $(this); |
| 951 | + if (Number($this.text()) < 14) { |
| 952 | + $this.addClass('disabled'); |
| 953 | + } |
| 954 | + } |
| 955 | + ); |
| 956 | + var d = this.endDate.getDate(); |
| 957 | + $('.dp-calendar td.current-month', this.context).each( |
| 958 | + function() |
| 959 | + { |
| 960 | + var $this = $(this); |
| 961 | + if (Number($this.text()) > d) { |
| 962 | + $this.addClass('disabled'); |
| 963 | + } |
| 964 | + } |
| 965 | + ); |
| 966 | + } else { |
| 967 | + $('.dp-nav-next-year', this.context).removeClass('disabled'); |
| 968 | + $('.dp-nav-next-month', this.context).removeClass('disabled'); |
| 969 | + var d = this.endDate.getDate(); |
| 970 | + if (d < 13) { |
| 971 | + // check if the endDate is next month as we might need to add some disabled classes... |
| 972 | + var ed = new Date(this.endDate.getTime()); |
| 973 | + ed.addMonths(-1); |
| 974 | + if (this.displayedYear == ed.getFullYear() && this.displayedMonth == ed.getMonth()) { |
| 975 | + $('.dp-calendar td.other-month', this.context).each( |
| 976 | + function() |
| 977 | + { |
| 978 | + var $this = $(this); |
| 979 | + if (Number($this.text()) > d) { |
| 980 | + $this.addClass('disabled'); |
| 981 | + } |
| 982 | + } |
| 983 | + ); |
| 984 | + } |
| 985 | + } |
| 986 | + } |
| 987 | + }, |
| 988 | + _closeCalendar : function(programatic, ele) |
| 989 | + { |
| 990 | + if (!ele || ele == this.ele) |
| 991 | + { |
| 992 | + $(document).unbind('mousedown', this._checkMouse); |
| 993 | + this._clearCalendar(); |
| 994 | + $('#dp-popup a').unbind(); |
| 995 | + $('#dp-popup').empty().remove(); |
| 996 | + if (!programatic) { |
| 997 | + $(this.ele).trigger('dpClosed', [this.getSelected()]); |
| 998 | + } |
| 999 | + } |
| 1000 | + }, |
| 1001 | + // empties the current dp-calendar div and makes sure that all events are unbound |
| 1002 | + // and expandos removed to avoid memory leaks... |
| 1003 | + _clearCalendar : function() |
| 1004 | + { |
| 1005 | + // TODO. |
| 1006 | + $('.dp-calendar td', this.context).unbind(); |
| 1007 | + $('.dp-calendar', this.context).empty(); |
| 1008 | + } |
| 1009 | + } |
| 1010 | + ); |
| 1011 | + |
| 1012 | + // static constants |
| 1013 | + $.dpConst = { |
| 1014 | + SHOW_HEADER_NONE : 0, |
| 1015 | + SHOW_HEADER_SHORT : 1, |
| 1016 | + SHOW_HEADER_LONG : 2, |
| 1017 | + POS_TOP : 0, |
| 1018 | + POS_BOTTOM : 1, |
| 1019 | + POS_LEFT : 0, |
| 1020 | + POS_RIGHT : 1 |
| 1021 | + }; |
| 1022 | + // localisable text |
| 1023 | + $.dpText = { |
| 1024 | + TEXT_PREV_YEAR : 'Previous year', |
| 1025 | + TEXT_PREV_MONTH : 'Previous month', |
| 1026 | + TEXT_NEXT_YEAR : 'Next year', |
| 1027 | + TEXT_NEXT_MONTH : 'Next month', |
| 1028 | + TEXT_CLOSE : 'Close', |
| 1029 | + TEXT_CHOOSE_DATE : 'Choose date' |
| 1030 | + }; |
| 1031 | + // version |
| 1032 | + $.dpVersion = '$Id: jquery.datePicker.js 3739 2007-10-25 13:55:30Z kelvin.luck $'; |
| 1033 | + |
| 1034 | + function _getController(ele) |
| 1035 | + { |
| 1036 | + if (ele._dpId) return $.event._dpCache[ele._dpId]; |
| 1037 | + return false; |
| 1038 | + }; |
| 1039 | + |
| 1040 | + // make it so that no error is thrown if bgIframe plugin isn't included (allows you to use conditional |
| 1041 | + // comments to only include bgIframe where it is needed in IE without breaking this plugin). |
| 1042 | + if ($.fn.bgIframe == undefined) { |
| 1043 | + $.fn.bgIframe = function() {return this; }; |
| 1044 | + }; |
| 1045 | + |
| 1046 | + |
| 1047 | + // clean-up |
| 1048 | + $(window) |
| 1049 | + .bind('unload', function() { |
| 1050 | + var els = $.event._dpCache || []; |
| 1051 | + for (var i in els) { |
| 1052 | + $(els[i].ele)._dpDestroy(); |
| 1053 | + } |
| 1054 | + }); |
| 1055 | + |
| 1056 | + |
| 1057 | +})(jQuery); |
| 1058 | + |
| 1059 | + |
| 1060 | +/* |
| 1061 | + * Date prototype extensions. Doesn't depend on any |
| 1062 | + * other code. Doens't overwrite existing methods. |
| 1063 | + * |
| 1064 | + * Adds dayNames, abbrDayNames, monthNames and abbrMonthNames static properties and isLeapYear, |
| 1065 | + * isWeekend, isWeekDay, getDaysInMonth, getDayName, getMonthName, getDayOfYear, getWeekOfYear, |
| 1066 | + * setDayOfYear, addYears, addMonths, addDays, addHours, addMinutes, addSeconds methods |
| 1067 | + * |
| 1068 | + * Copyright (c) 2006 Jörn Zaefferer and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net) |
| 1069 | + * |
| 1070 | + * Additional methods and properties added by Kelvin Luck: firstDayOfWeek, dateFormat, zeroTime, asString, fromString - |
| 1071 | + * I've added my name to these methods so you know who to blame if they are broken! |
| 1072 | + * |
| 1073 | + * Dual licensed under the MIT and GPL licenses: |
| 1074 | + * http://www.opensource.org/licenses/mit-license.php |
| 1075 | + * http://www.gnu.org/licenses/gpl.html |
| 1076 | + * |
| 1077 | + */ |
| 1078 | + |
| 1079 | +/** |
| 1080 | + * An Array of day names starting with Sunday. |
| 1081 | + * |
| 1082 | + * @example dayNames[0] |
| 1083 | + * @result 'Sunday' |
| 1084 | + * |
| 1085 | + * @name dayNames |
| 1086 | + * @type Array |
| 1087 | + * @cat Plugins/Methods/Date |
| 1088 | + */ |
| 1089 | +Date.dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; |
| 1090 | + |
| 1091 | +/** |
| 1092 | + * An Array of abbreviated day names starting with Sun. |
| 1093 | + * |
| 1094 | + * @example abbrDayNames[0] |
| 1095 | + * @result 'Sun' |
| 1096 | + * |
| 1097 | + * @name abbrDayNames |
| 1098 | + * @type Array |
| 1099 | + * @cat Plugins/Methods/Date |
| 1100 | + */ |
| 1101 | +Date.abbrDayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; |
| 1102 | + |
| 1103 | +/** |
| 1104 | + * An Array of month names starting with Janurary. |
| 1105 | + * |
| 1106 | + * @example monthNames[0] |
| 1107 | + * @result 'January' |
| 1108 | + * |
| 1109 | + * @name monthNames |
| 1110 | + * @type Array |
| 1111 | + * @cat Plugins/Methods/Date |
| 1112 | + */ |
| 1113 | +Date.monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; |
| 1114 | + |
| 1115 | +/** |
| 1116 | + * An Array of abbreviated month names starting with Jan. |
| 1117 | + * |
| 1118 | + * @example abbrMonthNames[0] |
| 1119 | + * @result 'Jan' |
| 1120 | + * |
| 1121 | + * @name monthNames |
| 1122 | + * @type Array |
| 1123 | + * @cat Plugins/Methods/Date |
| 1124 | + */ |
| 1125 | +Date.abbrMonthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; |
| 1126 | + |
| 1127 | +/** |
| 1128 | + * The first day of the week for this locale. |
| 1129 | + * |
| 1130 | + * @name firstDayOfWeek |
| 1131 | + * @type Number |
| 1132 | + * @cat Plugins/Methods/Date |
| 1133 | + * @author Kelvin Luck |
| 1134 | + */ |
| 1135 | +Date.firstDayOfWeek = 1; |
| 1136 | + |
| 1137 | +/** |
| 1138 | + * The format that string dates should be represented as (e.g. 'dd/mm/yyyy' for UK, 'mm/dd/yyyy' for US, 'yyyy-mm-dd' for Unicode etc). |
| 1139 | + * |
| 1140 | + * @name format |
| 1141 | + * @type String |
| 1142 | + * @cat Plugins/Methods/Date |
| 1143 | + * @author Kelvin Luck |
| 1144 | + */ |
| 1145 | +Date.format = 'dd/mm/yyyy'; |
| 1146 | +//Date.format = 'mm/dd/yyyy'; |
| 1147 | +//Date.format = 'yyyy-mm-dd'; |
| 1148 | +//Date.format = 'dd mmm yy'; |
| 1149 | + |
| 1150 | +/** |
| 1151 | + * The first two numbers in the century to be used when decoding a two digit year. Since a two digit year is ambiguous (and date.setYear |
| 1152 | + * only works with numbers < 99 and so doesn't allow you to set years after 2000) we need to use this to disambiguate the two digit year codes. |
| 1153 | + * |
| 1154 | + * @name format |
| 1155 | + * @type String |
| 1156 | + * @cat Plugins/Methods/Date |
| 1157 | + * @author Kelvin Luck |
| 1158 | + */ |
| 1159 | +Date.fullYearStart = '20'; |
| 1160 | + |
| 1161 | +(function() { |
| 1162 | + |
| 1163 | + /** |
| 1164 | + * Adds a given method under the given name |
| 1165 | + * to the Date prototype if it doesn't |
| 1166 | + * currently exist. |
| 1167 | + * |
| 1168 | + * @private |
| 1169 | + */ |
| 1170 | + function add(name, method) { |
| 1171 | + if( !Date.prototype[name] ) { |
| 1172 | + Date.prototype[name] = method; |
| 1173 | + } |
| 1174 | + }; |
| 1175 | + |
| 1176 | + /** |
| 1177 | + * Checks if the year is a leap year. |
| 1178 | + * |
| 1179 | + * @example var dtm = new Date("01/12/2008"); |
| 1180 | + * dtm.isLeapYear(); |
| 1181 | + * @result true |
| 1182 | + * |
| 1183 | + * @name isLeapYear |
| 1184 | + * @type Boolean |
| 1185 | + * @cat Plugins/Methods/Date |
| 1186 | + */ |
| 1187 | + add("isLeapYear", function() { |
| 1188 | + var y = this.getFullYear(); |
| 1189 | + return (y%4==0 && y%100!=0) || y%400==0; |
| 1190 | + }); |
| 1191 | + |
| 1192 | + /** |
| 1193 | + * Checks if the day is a weekend day (Sat or Sun). |
| 1194 | + * |
| 1195 | + * @example var dtm = new Date("01/12/2008"); |
| 1196 | + * dtm.isWeekend(); |
| 1197 | + * @result false |
| 1198 | + * |
| 1199 | + * @name isWeekend |
| 1200 | + * @type Boolean |
| 1201 | + * @cat Plugins/Methods/Date |
| 1202 | + */ |
| 1203 | + add("isWeekend", function() { |
| 1204 | + return this.getDay()==0 || this.getDay()==6; |
| 1205 | + }); |
| 1206 | + |
| 1207 | + /** |
| 1208 | + * Check if the day is a day of the week (Mon-Fri) |
| 1209 | + * |
| 1210 | + * @example var dtm = new Date("01/12/2008"); |
| 1211 | + * dtm.isWeekDay(); |
| 1212 | + * @result false |
| 1213 | + * |
| 1214 | + * @name isWeekDay |
| 1215 | + * @type Boolean |
| 1216 | + * @cat Plugins/Methods/Date |
| 1217 | + */ |
| 1218 | + add("isWeekDay", function() { |
| 1219 | + return !this.isWeekend(); |
| 1220 | + }); |
| 1221 | + |
| 1222 | + /** |
| 1223 | + * Gets the number of days in the month. |
| 1224 | + * |
| 1225 | + * @example var dtm = new Date("01/12/2008"); |
| 1226 | + * dtm.getDaysInMonth(); |
| 1227 | + * @result 31 |
| 1228 | + * |
| 1229 | + * @name getDaysInMonth |
| 1230 | + * @type Number |
| 1231 | + * @cat Plugins/Methods/Date |
| 1232 | + */ |
| 1233 | + add("getDaysInMonth", function() { |
| 1234 | + return [31,(this.isLeapYear() ? 29:28),31,30,31,30,31,31,30,31,30,31][this.getMonth()]; |
| 1235 | + }); |
| 1236 | + |
| 1237 | + /** |
| 1238 | + * Gets the name of the day. |
| 1239 | + * |
| 1240 | + * @example var dtm = new Date("01/12/2008"); |
| 1241 | + * dtm.getDayName(); |
| 1242 | + * @result 'Saturday' |
| 1243 | + * |
| 1244 | + * @example var dtm = new Date("01/12/2008"); |
| 1245 | + * dtm.getDayName(true); |
| 1246 | + * @result 'Sat' |
| 1247 | + * |
| 1248 | + * @param abbreviated Boolean When set to true the name will be abbreviated. |
| 1249 | + * @name getDayName |
| 1250 | + * @type String |
| 1251 | + * @cat Plugins/Methods/Date |
| 1252 | + */ |
| 1253 | + add("getDayName", function(abbreviated) { |
| 1254 | + return abbreviated ? Date.abbrDayNames[this.getDay()] : Date.dayNames[this.getDay()]; |
| 1255 | + }); |
| 1256 | + |
| 1257 | + /** |
| 1258 | + * Gets the name of the month. |
| 1259 | + * |
| 1260 | + * @example var dtm = new Date("01/12/2008"); |
| 1261 | + * dtm.getMonthName(); |
| 1262 | + * @result 'Janurary' |
| 1263 | + * |
| 1264 | + * @example var dtm = new Date("01/12/2008"); |
| 1265 | + * dtm.getMonthName(true); |
| 1266 | + * @result 'Jan' |
| 1267 | + * |
| 1268 | + * @param abbreviated Boolean When set to true the name will be abbreviated. |
| 1269 | + * @name getDayName |
| 1270 | + * @type String |
| 1271 | + * @cat Plugins/Methods/Date |
| 1272 | + */ |
| 1273 | + add("getMonthName", function(abbreviated) { |
| 1274 | + return abbreviated ? Date.abbrMonthNames[this.getMonth()] : Date.monthNames[this.getMonth()]; |
| 1275 | + }); |
| 1276 | + |
| 1277 | + /** |
| 1278 | + * Get the number of the day of the year. |
| 1279 | + * |
| 1280 | + * @example var dtm = new Date("01/12/2008"); |
| 1281 | + * dtm.getDayOfYear(); |
| 1282 | + * @result 11 |
| 1283 | + * |
| 1284 | + * @name getDayOfYear |
| 1285 | + * @type Number |
| 1286 | + * @cat Plugins/Methods/Date |
| 1287 | + */ |
| 1288 | + add("getDayOfYear", function() { |
| 1289 | + var tmpdtm = new Date("1/1/" + this.getFullYear()); |
| 1290 | + return Math.floor((this.getTime() - tmpdtm.getTime()) / 86400000); |
| 1291 | + }); |
| 1292 | + |
| 1293 | + /** |
| 1294 | + * Get the number of the week of the year. |
| 1295 | + * |
| 1296 | + * @example var dtm = new Date("01/12/2008"); |
| 1297 | + * dtm.getWeekOfYear(); |
| 1298 | + * @result 2 |
| 1299 | + * |
| 1300 | + * @name getWeekOfYear |
| 1301 | + * @type Number |
| 1302 | + * @cat Plugins/Methods/Date |
| 1303 | + */ |
| 1304 | + add("getWeekOfYear", function() { |
| 1305 | + return Math.ceil(this.getDayOfYear() / 7); |
| 1306 | + }); |
| 1307 | + |
| 1308 | + /** |
| 1309 | + * Set the day of the year. |
| 1310 | + * |
| 1311 | + * @example var dtm = new Date("01/12/2008"); |
| 1312 | + * dtm.setDayOfYear(1); |
| 1313 | + * dtm.toString(); |
| 1314 | + * @result 'Tue Jan 01 2008 00:00:00' |
| 1315 | + * |
| 1316 | + * @name setDayOfYear |
| 1317 | + * @type Date |
| 1318 | + * @cat Plugins/Methods/Date |
| 1319 | + */ |
| 1320 | + add("setDayOfYear", function(day) { |
| 1321 | + this.setMonth(0); |
| 1322 | + this.setDate(day); |
| 1323 | + return this; |
| 1324 | + }); |
| 1325 | + |
| 1326 | + /** |
| 1327 | + * Add a number of years to the date object. |
| 1328 | + * |
| 1329 | + * @example var dtm = new Date("01/12/2008"); |
| 1330 | + * dtm.addYears(1); |
| 1331 | + * dtm.toString(); |
| 1332 | + * @result 'Mon Jan 12 2009 00:00:00' |
| 1333 | + * |
| 1334 | + * @name addYears |
| 1335 | + * @type Date |
| 1336 | + * @cat Plugins/Methods/Date |
| 1337 | + */ |
| 1338 | + add("addYears", function(num) { |
| 1339 | + this.setFullYear(this.getFullYear() + num); |
| 1340 | + return this; |
| 1341 | + }); |
| 1342 | + |
| 1343 | + /** |
| 1344 | + * Add a number of months to the date object. |
| 1345 | + * |
| 1346 | + * @example var dtm = new Date("01/12/2008"); |
| 1347 | + * dtm.addMonths(1); |
| 1348 | + * dtm.toString(); |
| 1349 | + * @result 'Tue Feb 12 2008 00:00:00' |
| 1350 | + * |
| 1351 | + * @name addMonths |
| 1352 | + * @type Date |
| 1353 | + * @cat Plugins/Methods/Date |
| 1354 | + */ |
| 1355 | + add("addMonths", function(num) { |
| 1356 | + var tmpdtm = this.getDate(); |
| 1357 | + |
| 1358 | + this.setMonth(this.getMonth() + num); |
| 1359 | + |
| 1360 | + if (tmpdtm > this.getDate()) |
| 1361 | + this.addDays(-this.getDate()); |
| 1362 | + |
| 1363 | + return this; |
| 1364 | + }); |
| 1365 | + |
| 1366 | + /** |
| 1367 | + * Add a number of days to the date object. |
| 1368 | + * |
| 1369 | + * @example var dtm = new Date("01/12/2008"); |
| 1370 | + * dtm.addDays(1); |
| 1371 | + * dtm.toString(); |
| 1372 | + * @result 'Sun Jan 13 2008 00:00:00' |
| 1373 | + * |
| 1374 | + * @name addDays |
| 1375 | + * @type Date |
| 1376 | + * @cat Plugins/Methods/Date |
| 1377 | + */ |
| 1378 | + add("addDays", function(num) { |
| 1379 | + this.setDate(this.getDate() + num); |
| 1380 | + return this; |
| 1381 | + }); |
| 1382 | + |
| 1383 | + /** |
| 1384 | + * Add a number of hours to the date object. |
| 1385 | + * |
| 1386 | + * @example var dtm = new Date("01/12/2008"); |
| 1387 | + * dtm.addHours(24); |
| 1388 | + * dtm.toString(); |
| 1389 | + * @result 'Sun Jan 13 2008 00:00:00' |
| 1390 | + * |
| 1391 | + * @name addHours |
| 1392 | + * @type Date |
| 1393 | + * @cat Plugins/Methods/Date |
| 1394 | + */ |
| 1395 | + add("addHours", function(num) { |
| 1396 | + this.setHours(this.getHours() + num); |
| 1397 | + return this; |
| 1398 | + }); |
| 1399 | + |
| 1400 | + /** |
| 1401 | + * Add a number of minutes to the date object. |
| 1402 | + * |
| 1403 | + * @example var dtm = new Date("01/12/2008"); |
| 1404 | + * dtm.addMinutes(60); |
| 1405 | + * dtm.toString(); |
| 1406 | + * @result 'Sat Jan 12 2008 01:00:00' |
| 1407 | + * |
| 1408 | + * @name addMinutes |
| 1409 | + * @type Date |
| 1410 | + * @cat Plugins/Methods/Date |
| 1411 | + */ |
| 1412 | + add("addMinutes", function(num) { |
| 1413 | + this.setMinutes(this.getMinutes() + num); |
| 1414 | + return this; |
| 1415 | + }); |
| 1416 | + |
| 1417 | + /** |
| 1418 | + * Add a number of seconds to the date object. |
| 1419 | + * |
| 1420 | + * @example var dtm = new Date("01/12/2008"); |
| 1421 | + * dtm.addSeconds(60); |
| 1422 | + * dtm.toString(); |
| 1423 | + * @result 'Sat Jan 12 2008 00:01:00' |
| 1424 | + * |
| 1425 | + * @name addSeconds |
| 1426 | + * @type Date |
| 1427 | + * @cat Plugins/Methods/Date |
| 1428 | + */ |
| 1429 | + add("addSeconds", function(num) { |
| 1430 | + this.setSeconds(this.getSeconds() + num); |
| 1431 | + return this; |
| 1432 | + }); |
| 1433 | + |
| 1434 | + /** |
| 1435 | + * Sets the time component of this Date to zero for cleaner, easier comparison of dates where time is not relevant. |
| 1436 | + * |
| 1437 | + * @example var dtm = new Date(); |
| 1438 | + * dtm.zeroTime(); |
| 1439 | + * dtm.toString(); |
| 1440 | + * @result 'Sat Jan 12 2008 00:01:00' |
| 1441 | + * |
| 1442 | + * @name zeroTime |
| 1443 | + * @type Date |
| 1444 | + * @cat Plugins/Methods/Date |
| 1445 | + * @author Kelvin Luck |
| 1446 | + */ |
| 1447 | + add("zeroTime", function() { |
| 1448 | + this.setMilliseconds(0); |
| 1449 | + this.setSeconds(0); |
| 1450 | + this.setMinutes(0); |
| 1451 | + this.setHours(0); |
| 1452 | + return this; |
| 1453 | + }); |
| 1454 | + |
| 1455 | + /** |
| 1456 | + * Returns a string representation of the date object according to Date.format. |
| 1457 | + * (Date.toString may be used in other places so I purposefully didn't overwrite it) |
| 1458 | + * |
| 1459 | + * @example var dtm = new Date("01/12/2008"); |
| 1460 | + * dtm.asString(); |
| 1461 | + * @result '12/01/2008' // (where Date.format == 'dd/mm/yyyy' |
| 1462 | + * |
| 1463 | + * @name asString |
| 1464 | + * @type Date |
| 1465 | + * @cat Plugins/Methods/Date |
| 1466 | + * @author Kelvin Luck |
| 1467 | + */ |
| 1468 | + add("asString", function() { |
| 1469 | + var r = Date.format; |
| 1470 | + return r |
| 1471 | + .split('yyyy').join(this.getFullYear()) |
| 1472 | + .split('yy').join((this.getFullYear() + '').substring(2)) |
| 1473 | + .split('mmm').join(this.getMonthName(true)) |
| 1474 | + .split('mm').join(_zeroPad(this.getMonth()+1)) |
| 1475 | + .split('dd').join(_zeroPad(this.getDate())); |
| 1476 | + }); |
| 1477 | + |
| 1478 | + /** |
| 1479 | + * Returns a new date object created from the passed String according to Date.format or false if the attempt to do this results in an invalid date object |
| 1480 | + * (We can't simple use Date.parse as it's not aware of locale and I chose not to overwrite it incase it's functionality is being relied on elsewhere) |
| 1481 | + * |
| 1482 | + * @example var dtm = Date.fromString("12/01/2008"); |
| 1483 | + * dtm.toString(); |
| 1484 | + * @result 'Sat Jan 12 2008 00:00:00' // (where Date.format == 'dd/mm/yyyy' |
| 1485 | + * |
| 1486 | + * @name fromString |
| 1487 | + * @type Date |
| 1488 | + * @cat Plugins/Methods/Date |
| 1489 | + * @author Kelvin Luck |
| 1490 | + */ |
| 1491 | + Date.fromString = function(s) |
| 1492 | + { |
| 1493 | + var f = Date.format; |
| 1494 | + var d = new Date('01/01/1977'); |
| 1495 | + var iY = f.indexOf('yyyy'); |
| 1496 | + if (iY > -1) { |
| 1497 | + d.setFullYear(Number(s.substr(iY, 4))); |
| 1498 | + } else { |
| 1499 | + // TODO - this doesn't work very well - are there any rules for what is meant by a two digit year? |
| 1500 | + d.setFullYear(Number(Date.fullYearStart + s.substr(f.indexOf('yy'), 2))); |
| 1501 | + } |
| 1502 | + var iM = f.indexOf('mmm'); |
| 1503 | + if (iM > -1) { |
| 1504 | + var mStr = s.substr(iM, 3); |
| 1505 | + for (var i=0; i<Date.abbrMonthNames.length; i++) { |
| 1506 | + if (Date.abbrMonthNames[i] == mStr) break; |
| 1507 | + } |
| 1508 | + d.setMonth(i); |
| 1509 | + } else { |
| 1510 | + d.setMonth(Number(s.substr(f.indexOf('mm'), 2)) - 1); |
| 1511 | + } |
| 1512 | + d.setDate(Number(s.substr(f.indexOf('dd'), 2))); |
| 1513 | + if (isNaN(d.getTime())) { |
| 1514 | + return false; |
| 1515 | + } |
| 1516 | + return d; |
| 1517 | + }; |
| 1518 | + |
| 1519 | + // utility method |
| 1520 | + var _zeroPad = function(num) { |
| 1521 | + var s = '0'+num; |
| 1522 | + return s.substring(s.length-2) |
| 1523 | + //return ('0'+num).substring(-2); // doesn't work on IE :( |
| 1524 | + }; |
| 1525 | + |
| 1526 | +})(); |
Property changes on: branches/uploadwizard/extensions/UploadWizard/resources/jquery/jquery.datePicker.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 1527 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/resources/jquery/jquery.tipsyPlus.js |
— | — | @@ -0,0 +1,49 @@ |
| 2 | +( function( $j ) { |
| 3 | + $j.fn.tipsyPlus = function( optionsArg ) { |
| 4 | + // use extend! |
| 5 | + var titleOption = 'title'; |
| 6 | + var htmlOption = false; |
| 7 | + |
| 8 | + var options = $j.extend( |
| 9 | + { type: 'help', shadow: true }, |
| 10 | + optionsArg |
| 11 | + ); |
| 12 | + |
| 13 | + var el = this; |
| 14 | + |
| 15 | + if (options.plus) { |
| 16 | + htmlOption = true; |
| 17 | + titleOption = function() { |
| 18 | + return $j( '<span />' ).append( |
| 19 | + $j( this ).attr( 'original-title' ), |
| 20 | + $j( '<a class="mwe-upwiz-tooltip-link"/>' ) |
| 21 | + .attr( 'href', '#' ) |
| 22 | + .append( gM( 'mwe-upwiz-tooltip-more-info' ) ) |
| 23 | + .mouseenter( function() { |
| 24 | + el.data('tipsy').sticky = true; |
| 25 | + } ) |
| 26 | + .mouseleave( function() { |
| 27 | + el.data('tipsy').sticky = false; |
| 28 | + } ) |
| 29 | + .click( function() { |
| 30 | + // show the wiki page with more |
| 31 | + alert( options.plus ); |
| 32 | + // pass this in as a closure to be called on dismiss |
| 33 | + el.focus(); |
| 34 | + el.data('tipsy').sticky = false; |
| 35 | + } ) |
| 36 | + ); |
| 37 | + }; |
| 38 | + } |
| 39 | + |
| 40 | + return this.tipsy( { |
| 41 | + gravity: 'w', |
| 42 | + trigger: 'focus', |
| 43 | + title: titleOption, |
| 44 | + html: htmlOption, |
| 45 | + type: options.type, |
| 46 | + shadow: options.shadow |
| 47 | + } ); |
| 48 | + }; |
| 49 | +} )( jQuery ); |
| 50 | + |
Property changes on: branches/uploadwizard/extensions/UploadWizard/resources/jquery/jquery.tipsyPlus.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 51 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/resources/jquery/jquery.autocomplete.css |
— | — | @@ -0,0 +1,46 @@ |
| 2 | +.ac_results { |
| 3 | + padding: 0px; |
| 4 | + border: 1px solid WindowFrame; |
| 5 | + background-color: Window; |
| 6 | + overflow: hidden; |
| 7 | +} |
| 8 | + |
| 9 | +.ac_results ul { |
| 10 | + width: 100%; |
| 11 | + list-style-position: outside; |
| 12 | + list-style: none; |
| 13 | + padding: 0; |
| 14 | + margin: 0; |
| 15 | +} |
| 16 | + |
| 17 | +.ac_results iframe { |
| 18 | + display:none;/*sorry for IE5*/ |
| 19 | + display/**/:block;/*sorry for IE5*/ |
| 20 | + position:absolute; |
| 21 | + top:0; |
| 22 | + left:0; |
| 23 | + z-index:-1; |
| 24 | + filter:mask(); |
| 25 | + width:3000px; |
| 26 | + height:3000px; |
| 27 | +} |
| 28 | + |
| 29 | +.ac_results li { |
| 30 | + margin: 0px; |
| 31 | + padding: 2px 5px; |
| 32 | + cursor: pointer; |
| 33 | + display: block; |
| 34 | + width: 100%; |
| 35 | + font: menu; |
| 36 | + font-size: 12px; |
| 37 | + overflow: hidden; |
| 38 | +} |
| 39 | + |
| 40 | +.ac_loading { |
| 41 | + background : Window url('./indicator.gif') right center no-repeat; |
| 42 | +} |
| 43 | + |
| 44 | +.ac_over { |
| 45 | + background-color: Highlight; |
| 46 | + color: HighlightText; |
| 47 | +} |
Property changes on: branches/uploadwizard/extensions/UploadWizard/resources/jquery/jquery.autocomplete.css |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 48 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/resources/jquery/jquery.spinner.js |
— | — | @@ -0,0 +1,40 @@ |
| 2 | +( function( $ ) { |
| 3 | + /** |
| 4 | + * Set a given selector html to the loading spinner: |
| 5 | + */ |
| 6 | + $.fn.loadingSpinner = function( ) { |
| 7 | + if ( this ) { |
| 8 | + $j( this ).html( |
| 9 | + $j( '<div />' ) |
| 10 | + .addClass( "loadingSpinner" ) |
| 11 | + ); |
| 12 | + } |
| 13 | + return this; |
| 14 | + } |
| 15 | + /** |
| 16 | + * Add an absolute overlay spinner useful for cases where the |
| 17 | + * element does not display child elements, ( images, video ) |
| 18 | + */ |
| 19 | + $.fn.getAbsoluteOverlaySpinner = function(){ |
| 20 | + var pos = $j( this ).offset(); |
| 21 | + var posLeft = ( $j( this ).width() ) ? |
| 22 | + parseInt( pos.left + ( .4 * $j( this ).width() ) ) : |
| 23 | + pos.left + 30; |
| 24 | + |
| 25 | + var posTop = ( $j( this ).height() ) ? |
| 26 | + parseInt( pos.top + ( .4 * $j( this ).height() ) ) : |
| 27 | + pos.top + 30; |
| 28 | + |
| 29 | + var $spinner = $j('<div />') |
| 30 | + .loadingSpinner() |
| 31 | + .css({ |
| 32 | + 'width' : 32, |
| 33 | + 'height' : 32, |
| 34 | + 'position': 'absolute', |
| 35 | + 'top' : posTop + 'px', |
| 36 | + 'left' : posLeft + 'px' |
| 37 | + }); |
| 38 | + $j('body').append( $spinner ); |
| 39 | + return $spinner; |
| 40 | + } |
| 41 | +} )( jQuery ); |
Property changes on: branches/uploadwizard/extensions/UploadWizard/resources/jquery/jquery.spinner.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 42 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/resources/mw.ApiMisc.js |
— | — | @@ -0,0 +1,164 @@ |
| 2 | + /** |
| 3 | + * |
| 4 | + * Helper function to get revision text for a given title |
| 5 | + * |
| 6 | + * Assumes "follow redirects" |
| 7 | + * |
| 8 | + * $j.getTextFromTitle( [apiUrl], title, callback ) |
| 9 | + * |
| 10 | + * @param {String} url or title key |
| 11 | + * @parma {Mixed} title or callback function |
| 12 | + * @param {Function} callback Function or NULL |
| 13 | + * |
| 14 | + * @return callback is called with: |
| 15 | + * {Boolean} false if no page found |
| 16 | + * {String} text of wiki page |
| 17 | + */ |
| 18 | + getTextFromTitle: function( title, callback ) { |
| 19 | + var request = { |
| 20 | + // Normalize the File NS (ie sometimes its present in apiTitleKey other times not |
| 21 | + 'titles' : title, |
| 22 | + 'prop' : 'revisions', |
| 23 | + 'rvprop' : 'content' |
| 24 | + }; |
| 25 | + |
| 26 | + this.get( request, function( response ) { |
| 27 | + if( !response || !response.query || !response.query.pages ) { |
| 28 | + callback( false ); |
| 29 | + } |
| 30 | + var pages = response.query.pages; |
| 31 | + for(var i in pages) { |
| 32 | + page = pages[ i ]; |
| 33 | + if( page[ 'revisions' ] && page[ 'revisions' ][0]['*'] ) { |
| 34 | + callback( page[ 'revisions' ][0]['*'] ); |
| 35 | + } |
| 36 | + } |
| 37 | + } ); |
| 38 | + }, |
| 39 | + |
| 40 | +/* |
| 41 | + // Stub feature apiUserNameCache to avoid multiple calls |
| 42 | + // ( a more general api framework should be developed ) |
| 43 | + apiUserNameCache: {}, |
| 44 | + |
| 45 | + /** |
| 46 | + * Api helper to grab the username |
| 47 | + * @param {Function} callback Function to callback with username or false if not found |
| 48 | + * @param {Boolean} fresh A fresh check is issued. |
| 49 | + */ |
| 50 | + getUserName: function( callback, fresh ){ |
| 51 | + |
| 52 | + /* |
| 53 | + // If apiUrl is local check wgUserName global |
| 54 | + // before issuing the api request. |
| 55 | + if( mw.isLocalDomain( apiUrl ) ){ |
| 56 | + if( typeof wgUserName != 'undefined' && wgUserName !== null ) { |
| 57 | + callback( wgUserName ) |
| 58 | + // In case someone called this function without a callback |
| 59 | + return wgUserName; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + */ |
| 64 | + |
| 65 | + if( ! fresh && apiUserNameCache[ apiUrl ] ) { |
| 66 | + callback( apiUserNameCache[ apiUrl ] ); |
| 67 | + return ; |
| 68 | + } |
| 69 | + |
| 70 | + // Setup the api request |
| 71 | + var parameters = { |
| 72 | + 'action':'query', |
| 73 | + 'meta':'userinfo' |
| 74 | + } |
| 75 | + |
| 76 | + // Do request |
| 77 | + this.get( request, function( data ) { |
| 78 | + if( !data || !data.query || !data.query.userinfo || !data.query.userinfo.name ){ |
| 79 | + // Could not get user name user is not-logged in |
| 80 | + mw.log( " No userName in response " ); |
| 81 | + callback( false ); |
| 82 | + return ; |
| 83 | + } |
| 84 | + // Check for "not logged in" id == 0 |
| 85 | + if( data.query.userinfo.id == 0 ){ |
| 86 | + callback( false ); |
| 87 | + return ; |
| 88 | + } |
| 89 | + /* apiUserNameCache[ apiUrl ] = data.query.userinfo.name; */ |
| 90 | + // Else return the username: |
| 91 | + callback( data.query.userinfo.name ); |
| 92 | + }, function(){ |
| 93 | + // Timeout also results in callback( false ) ( no user found) |
| 94 | + callback( false ); |
| 95 | + } ); |
| 96 | + } |
| 97 | +*/ |
| 98 | + |
| 99 | + /** |
| 100 | + * Issues the wikitext parse call |
| 101 | + * |
| 102 | + * @param {String} wikitext Wiki Text to be parsed by mediaWiki api call |
| 103 | + * @param {String} title Context title of the content to be parsed |
| 104 | + * @param {Function} callback Function called with api parser output |
| 105 | + */ |
| 106 | + parseWikiText: function( wikitext, title, callback ) { |
| 107 | + mw.log("mw.parseWikiText text length: " + wikitext.length + ' title context: ' + title ); |
| 108 | + // TODO mw.load? ajax? why? |
| 109 | + mw.load( 'JSON', function(){ |
| 110 | + $j.ajax( { |
| 111 | + type: 'POST', |
| 112 | + url: this.url, |
| 113 | + // Give the wiki 60 seconds to parse the wiki-text |
| 114 | + timeout : 60000, |
| 115 | + data: { |
| 116 | + 'action': 'parse', |
| 117 | + 'format': 'json', |
| 118 | + 'title' : title, |
| 119 | + 'text': wikitext |
| 120 | + }, |
| 121 | + dataType: 'text', |
| 122 | + success: function( data ) { |
| 123 | + var jsonData = JSON.parse( data ) ; |
| 124 | + // xxx should handle other failures |
| 125 | + callback( jsonData.parse.text['*'] ); |
| 126 | + }, |
| 127 | + error: function( XMLHttpRequest, textStatus, errorThrown ){ |
| 128 | + // xxx should better handle failures |
| 129 | + mw.log( "Error: mw.parseWikiText:" + textStatus ); |
| 130 | + callback( "Error: failed to parse wikitext " ); |
| 131 | + } |
| 132 | + } ); |
| 133 | + } ); |
| 134 | + }, |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | + // Api actions that must be submitted in a POST, and need an api proxy for cross domain calls |
| 139 | + // TODO protecting app code from knowing it's supposed to POST or not is a dubious benefit. :( |
| 140 | + apiPostActions: [ 'login', 'purge', 'rollback', 'delete', 'undelete', |
| 141 | + 'protect', 'block', 'unblock', 'move', 'edit', 'upload', 'emailuser', |
| 142 | + 'import', 'userrights' ], |
| 143 | + |
| 144 | + |
| 145 | + /** |
| 146 | + * Checks if a mw request data requires a post request or not |
| 147 | + * @param {Object} |
| 148 | + * @return {Boolean} |
| 149 | + * true if the request requires a post request |
| 150 | + * false if the request does not |
| 151 | + */ |
| 152 | + mw.checkRequestPost = function ( data ) { |
| 153 | + if( $j.inArray( data['action'], this.apiPostActions ) != -1 ) { |
| 154 | + return true; |
| 155 | + } |
| 156 | + if( data['prop'] == 'info' && data['intoken'] ) { |
| 157 | + return true; |
| 158 | + } |
| 159 | + if( data['meta'] == 'userinfo' ) { |
| 160 | + return true; |
| 161 | + } |
| 162 | + return false; |
| 163 | + } |
| 164 | + |
| 165 | + |
Property changes on: branches/uploadwizard/extensions/UploadWizard/resources/mw.ApiMisc.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 166 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/resources/mw.UtilitiesTime.js |
— | — | @@ -1,90 +1,96 @@ |
2 | 2 | /** |
3 | | - * Given a float number of seconds, returns npt format response. ( ignore |
4 | | - * days for now ) |
5 | | - * |
6 | | - * @param {Float} |
7 | | - * sec Seconds |
8 | | - * @param {Boolean} |
9 | | - * show_ms If milliseconds should be displayed. |
10 | | - * @return {Float} String npt format |
| 3 | + * dependencies: [ mw ] |
11 | 4 | */ |
12 | | -mw.seconds2npt = function( sec, show_ms ) { |
13 | | - if ( isNaN( sec ) ) { |
14 | | - mw.log("Warning: trying to get npt time on NaN:" + sec); |
15 | | - return '0:00:00'; |
16 | | - } |
17 | | - |
18 | | - var tm = mw.seconds2Measurements( sec ) |
| 5 | +( function( mw ) { |
| 6 | + |
| 7 | + /** |
| 8 | + * Given a float number of seconds, returns npt format response. ( ignore |
| 9 | + * days for now ) |
| 10 | + * |
| 11 | + * @param {Float} |
| 12 | + * sec Seconds |
| 13 | + * @param {Boolean} |
| 14 | + * show_ms If milliseconds should be displayed. |
| 15 | + * @return {Float} String npt format |
| 16 | + */ |
| 17 | + mw.seconds2npt = function( sec, show_ms ) { |
| 18 | + if ( isNaN( sec ) ) { |
| 19 | + mw.log("Warning: trying to get npt time on NaN:" + sec); |
| 20 | + return '0:00:00'; |
| 21 | + } |
| 22 | + |
| 23 | + var tm = mw.seconds2Measurements( sec ) |
| 24 | + |
| 25 | + // Round the number of seconds to the required number of significant |
| 26 | + // digits |
| 27 | + if ( show_ms ) { |
| 28 | + tm.seconds = Math.round( tm.seconds * 1000 ) / 1000; |
| 29 | + } else { |
| 30 | + tm.seconds = Math.round( tm.seconds ); |
| 31 | + } |
| 32 | + if ( tm.seconds < 10 ){ |
| 33 | + tm.seconds = '0' + tm.seconds; |
| 34 | + } |
| 35 | + if( tm.hours == 0 ){ |
| 36 | + hoursStr = '' |
| 37 | + } else { |
| 38 | + if ( tm.minutes < 10 ) |
| 39 | + tm.minutes = '0' + tm.minutes; |
19 | 40 | |
20 | | - // Round the number of seconds to the required number of significant |
21 | | - // digits |
22 | | - if ( show_ms ) { |
23 | | - tm.seconds = Math.round( tm.seconds * 1000 ) / 1000; |
24 | | - } else { |
25 | | - tm.seconds = Math.round( tm.seconds ); |
| 41 | + hoursStr = tm.hours + ":"; |
| 42 | + } |
| 43 | + return hoursStr + tm.minutes + ":" + tm.seconds; |
26 | 44 | } |
27 | | - if ( tm.seconds < 10 ){ |
28 | | - tm.seconds = '0' + tm.seconds; |
| 45 | + |
| 46 | + /** |
| 47 | + * Given seconds return array with 'days', 'hours', 'min', 'seconds' |
| 48 | + * |
| 49 | + * @param {float} |
| 50 | + * sec Seconds to be converted into time measurements |
| 51 | + */ |
| 52 | + mw.seconds2Measurements = function ( sec ){ |
| 53 | + var tm = {}; |
| 54 | + tm.days = Math.floor( sec / ( 3600 * 24 ) ) |
| 55 | + tm.hours = Math.floor( sec / 3600 ); |
| 56 | + tm.minutes = Math.floor( ( sec / 60 ) % 60 ); |
| 57 | + tm.seconds = sec % 60; |
| 58 | + return tm; |
29 | 59 | } |
30 | | - if( tm.hours == 0 ){ |
31 | | - hoursStr = '' |
32 | | - } else { |
33 | | - if ( tm.minutes < 10 ) |
34 | | - tm.minutes = '0' + tm.minutes; |
35 | | - |
36 | | - hoursStr = tm.hours + ":"; |
37 | | - } |
38 | | - return hoursStr + tm.minutes + ":" + tm.seconds; |
39 | | -} |
40 | 60 | |
41 | | -/** |
42 | | - * Given seconds return array with 'days', 'hours', 'min', 'seconds' |
43 | | - * |
44 | | - * @param {float} |
45 | | - * sec Seconds to be converted into time measurements |
46 | | - */ |
47 | | -mw.seconds2Measurements = function ( sec ){ |
48 | | - var tm = {}; |
49 | | - tm.days = Math.floor( sec / ( 3600 * 24 ) ) |
50 | | - tm.hours = Math.floor( sec / 3600 ); |
51 | | - tm.minutes = Math.floor( ( sec / 60 ) % 60 ); |
52 | | - tm.seconds = sec % 60; |
53 | | - return tm; |
54 | | -} |
| 61 | + /** |
| 62 | + * Take hh:mm:ss,ms or hh:mm:ss.ms input, return the number of seconds |
| 63 | + * |
| 64 | + * @param {String} |
| 65 | + * npt_str NPT time string |
| 66 | + * @return {Float} Number of seconds |
| 67 | + */ |
| 68 | + mw.npt2seconds = function ( npt_str ) { |
| 69 | + if ( !npt_str ) { |
| 70 | + // mw.log('npt2seconds:not valid ntp:'+ntp); |
| 71 | + return false; |
| 72 | + } |
| 73 | + // Strip {npt:}01:02:20 or 32{s} from time if present |
| 74 | + npt_str = npt_str.replace( /npt:|s/g, '' ); |
55 | 75 | |
56 | | -/** |
57 | | - * Take hh:mm:ss,ms or hh:mm:ss.ms input, return the number of seconds |
58 | | - * |
59 | | - * @param {String} |
60 | | - * npt_str NPT time string |
61 | | - * @return {Float} Number of seconds |
62 | | - */ |
63 | | -mw.npt2seconds = function ( npt_str ) { |
64 | | - if ( !npt_str ) { |
65 | | - // mw.log('npt2seconds:not valid ntp:'+ntp); |
66 | | - return false; |
67 | | - } |
68 | | - // Strip {npt:}01:02:20 or 32{s} from time if present |
69 | | - npt_str = npt_str.replace( /npt:|s/g, '' ); |
| 76 | + var hour = 0; |
| 77 | + var min = 0; |
| 78 | + var sec = 0; |
70 | 79 | |
71 | | - var hour = 0; |
72 | | - var min = 0; |
73 | | - var sec = 0; |
| 80 | + times = npt_str.split( ':' ); |
| 81 | + if ( times.length == 3 ) { |
| 82 | + sec = times[2]; |
| 83 | + min = times[1]; |
| 84 | + hour = times[0]; |
| 85 | + } else if ( times.length == 2 ) { |
| 86 | + sec = times[1]; |
| 87 | + min = times[0]; |
| 88 | + } else { |
| 89 | + sec = times[0]; |
| 90 | + } |
| 91 | + // Sometimes a comma is used instead of period for ms |
| 92 | + sec = sec.replace( /,\s?/, '.' ); |
| 93 | + // Return seconds float |
| 94 | + return parseInt( hour * 3600 ) + parseInt( min * 60 ) + parseFloat( sec ); |
| 95 | + } |
74 | 96 | |
75 | | - times = npt_str.split( ':' ); |
76 | | - if ( times.length == 3 ) { |
77 | | - sec = times[2]; |
78 | | - min = times[1]; |
79 | | - hour = times[0]; |
80 | | - } else if ( times.length == 2 ) { |
81 | | - sec = times[1]; |
82 | | - min = times[0]; |
83 | | - } else { |
84 | | - sec = times[0]; |
85 | | - } |
86 | | - // Sometimes a comma is used instead of period for ms |
87 | | - sec = sec.replace( /,\s?/, '.' ); |
88 | | - // Return seconds float |
89 | | - return parseInt( hour * 3600 ) + parseInt( min * 60 ) + parseFloat( sec ); |
90 | | -} |
91 | | - |
| 97 | +} )( window.mw ); |
Index: branches/uploadwizard/extensions/UploadWizard/resources/mw.Api.edit.js |
— | — | @@ -0,0 +1,50 @@ |
| 2 | +// library to assist with edits |
| 3 | + |
| 4 | +// dependencies: [ mw.Api, jQuery ] |
| 5 | + |
| 6 | +( function( mw, $ ) { |
| 7 | + $.extend( mw.Api.prototype, { |
| 8 | + /** |
| 9 | + * Api helper to grab an edit token |
| 10 | + * |
| 11 | + * token callback has signature ( String token ) |
| 12 | + * error callback has signature ( String code, Object results, XmlHttpRequest xhr, Exception exception ) |
| 13 | + * Note that xhr and exception are only available for 'http_*' errors |
| 14 | + * code may be any http_* error code (see mw.Api), or 'token_missing' |
| 15 | + * |
| 16 | + * @param {Function} received token callback |
| 17 | + * @param {Function} error callback |
| 18 | + */ |
| 19 | + getEditToken: function( tokenCallback, err ) { |
| 20 | + |
| 21 | + var parameters = { |
| 22 | + 'prop': 'info', |
| 23 | + 'intoken': 'edit', |
| 24 | + /* we need some kind of dummy page to get a token from. This will return a response |
| 25 | + complaining that the page is missing, but we should also get an edit token */ |
| 26 | + 'titles': 'DummyPageForEditToken' |
| 27 | + }; |
| 28 | + |
| 29 | + var ok = function( data ) { |
| 30 | + var token; |
| 31 | + $.each( data.query.pages, function( i, page ) { |
| 32 | + if ( page['edittoken'] ) { |
| 33 | + token = page['edittoken']; |
| 34 | + return false; |
| 35 | + } |
| 36 | + } ); |
| 37 | + if ( mw.isDefined( token ) ) { |
| 38 | + tokenCallback( token ); |
| 39 | + } else { |
| 40 | + err( 'token-missing', data ); |
| 41 | + } |
| 42 | + }; |
| 43 | + |
| 44 | + var ajaxOptions = { 'ok': ok, 'err': err }; |
| 45 | + |
| 46 | + this.get( parameters, ajaxOptions ); |
| 47 | + } |
| 48 | + |
| 49 | + } ); |
| 50 | + |
| 51 | +}) ( window.mw, jQuery ); |
Property changes on: branches/uploadwizard/extensions/UploadWizard/resources/mw.Api.edit.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 52 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/resources/uploadWizard.css |
— | — | @@ -218,6 +218,12 @@ |
219 | 219 | color: #009900; |
220 | 220 | } |
221 | 221 | |
| 222 | +.mwe-upwiz-status-failed { |
| 223 | + background: url(16px-Gnome-process-stop.svg.png) no-repeat left center; |
| 224 | + font-weight: bold; |
| 225 | + color: #CC0000; |
| 226 | +} |
| 227 | + |
222 | 228 | .mwe-upwiz-progress { |
223 | 229 | margin-top: 15px; |
224 | 230 | } |
Index: branches/uploadwizard/extensions/UploadWizard/resources/mw.Uri.js |
— | — | @@ -0,0 +1,252 @@ |
| 2 | +/** |
| 3 | + * Library for simple URI parsing and manipulation. Requires jQuery. |
| 4 | + * |
| 5 | + * Do not expect full RFC 3986 compliance. Intended to be minimal, but featureful. |
| 6 | + * The use cases we have in mind are constructing 'next page' or 'previous page' URLs, |
| 7 | + * detecting whether we need to use cross-domain proxies for an API, constructing simple |
| 8 | + * URL-based API calls, etc. |
| 9 | + * |
| 10 | + * Intended to compress very well if you use a JS-parsing minifier. |
| 11 | + * |
| 12 | + * Dependencies: mw, mw.Utilities, jQuery |
| 13 | + * |
| 14 | + * Example: |
| 15 | + * |
| 16 | + * var uri = new mw.Uri( 'http://foo.com/mysite/mypage.php?quux=2' ); |
| 17 | + * |
| 18 | + * if ( uri.host == 'foo.com' ) { |
| 19 | + * uri.host = 'www.foo.com'; |
| 20 | + * uri.extend( { bar: 1 } ); |
| 21 | + * |
| 22 | + * $( 'a#id1' ).setAttr( 'href', uri ); |
| 23 | + * // anchor with id 'id1' now links to http://www.foo.com/mysite/mypage.php?bar=1&quux=2 |
| 24 | + * |
| 25 | + * $( 'a#id2' ).setAttr( 'href', uri.clone().extend( { bar: 3, pif: 'paf' } ) ); |
| 26 | + * // anchor with id 'id2' now links to http://www.foo.com/mysite/mypage.php?bar=3&quux=2&pif=paf |
| 27 | + * } |
| 28 | + * |
| 29 | + * Parsing here is regex based, so may not work on all URIs, but is good enough for most. |
| 30 | + * |
| 31 | + * Given a URI like |
| 32 | + * 'http://usr:pwd@www.test.com:81/dir/dir.2/index.htm?q1=0&&test1&test2=value+%28escaped%29#top': |
| 33 | + * The returned object will have the following properties: |
| 34 | + * |
| 35 | + * protocol 'http' |
| 36 | + * user 'usr' |
| 37 | + * password 'pwd' |
| 38 | + * host 'www.test.com' |
| 39 | + * port '81' |
| 40 | + * path '/dir/dir.2/index.htm' |
| 41 | + * query { q1: 0, test1: '', test2: 'value (escaped)' } |
| 42 | + * fragment 'top' |
| 43 | + * |
| 44 | + * n.b. 'password' is not technically allowed for HTTP URIs, but it is possible with other sorts of URIs. |
| 45 | + * |
| 46 | + * You can modify the properties directly. Then use the toString() method to extract the full URI string again. |
| 47 | + * |
| 48 | + * parsing based on parseUri 1.2.2 (c) Steven Levithan <stevenlevithan.com> MIT License |
| 49 | + * http://stevenlevithan.com/demo/parseuri/js/ |
| 50 | + * |
| 51 | + */ |
| 52 | + |
| 53 | +( function( mw, $ ) { |
| 54 | + /** |
| 55 | + * Constructs URI object. Throws error if arguments are illegal/impossible, or otherwise don't parse. |
| 56 | + * @constructor |
| 57 | + * @param {!Object|Location|String} URI string, or a Location object (obtained from window.location in some browsers) or an Object with appropriate properties (especially another URI object to clone). Object must have non-blank 'protocol', 'host', and 'path' properties. |
| 58 | + * @param {Boolean} strict mode (when parsing a string) |
| 59 | + */ |
| 60 | + mw.Uri = function( uri, strictMode ) { |
| 61 | + strictMode = !!strictMode; |
| 62 | + if ( mw.isFull( uri ) ) { |
| 63 | + if ( typeof uri === 'string' ) { |
| 64 | + this._parse( uri, strictMode ); |
| 65 | + } else if ( uri instanceof Location ) { |
| 66 | + this._parse( uri.href, strictMode ); |
| 67 | + } else if ( typeof uri === 'object' ) { |
| 68 | + var _this = this; |
| 69 | + $.each( this._properties, function( i, property ) { |
| 70 | + _this[property] = uri[property]; |
| 71 | + } ); |
| 72 | + if ( ! mw.isDefined( this.query ) ) { |
| 73 | + this.query = {}; |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + if ( !( this.protocol && this.host && this.path ) ) { |
| 78 | + throw new Error( "bad constructor arguments" ); |
| 79 | + } |
| 80 | + }; |
| 81 | + |
| 82 | + mw.Uri.prototype = { |
| 83 | + |
| 84 | + /** |
| 85 | + * Standard encodeURIComponent, with extra stuff to make all browsers work similarly and more compliant with RFC 3986 |
| 86 | + * @param {String} string |
| 87 | + * @return {String} encoded for URI |
| 88 | + */ |
| 89 | + encode: function( component ) { |
| 90 | + return encodeURIComponent( component ) |
| 91 | + .replace( /!/g, '%21') |
| 92 | + .replace( /'/g, '%27') |
| 93 | + .replace( /\(/g, '%28') |
| 94 | + .replace( /\)/g, '%29') |
| 95 | + .replace( /\*/g, '%2A') |
| 96 | + .replace( /%20/g, '+' ); |
| 97 | + }, |
| 98 | + |
| 99 | + /** |
| 100 | + * Standard decodeURIComponent, with '+' to space |
| 101 | + * @param {String} string encoded for URI |
| 102 | + * @return {String} decoded string |
| 103 | + */ |
| 104 | + decode: function( component ) { |
| 105 | + return decodeURIComponent( component ).replace( /\+/g, ' ' ); |
| 106 | + }, |
| 107 | + |
| 108 | + // regular expressions to parse many common URIs. |
| 109 | + // @private |
| 110 | + _parser: { |
| 111 | + strict: /^(?:([^:\/?#]+):)?(?:\/\/(?:(?:([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)?((?:[^?#\/]*\/)*[^?#]*)(?:\?([^#]*))?(?:#(.*))?/, |
| 112 | + loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?(?:(?:([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?((?:\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?[^?#\/]*)(?:\?([^#]*))?(?:#(.*))?/ |
| 113 | + }, |
| 114 | + |
| 115 | + /* the order here matches the order of captured matches in the above parser regexes */ |
| 116 | + // @private |
| 117 | + _properties: [ |
| 118 | + "protocol", // http |
| 119 | + "user", // usr |
| 120 | + "password", // pwd |
| 121 | + "host", // www.test.com |
| 122 | + "port", // 81 |
| 123 | + "path", // /dir/dir.2/index.htm |
| 124 | + "query", // q1=0&&test1&test2=value (will become { q1: 0, test1: '', test2: 'value' } ) |
| 125 | + "fragment" // top |
| 126 | + ], |
| 127 | + |
| 128 | + /** |
| 129 | + * Parse a string and set our properties accordingly. |
| 130 | + * @param {String} URI |
| 131 | + * @param {Boolean} strictness |
| 132 | + * @return {Boolean} success |
| 133 | + */ |
| 134 | + _parse: function( str, strictMode ) { |
| 135 | + var matches = this._parser[ strictMode ? "strict" : "loose" ].exec( str ); |
| 136 | + var uri = this; |
| 137 | + $.each( uri._properties, function( i, property ) { |
| 138 | + uri[ property ] = matches[ i+1 ]; |
| 139 | + } ); |
| 140 | + |
| 141 | + // uri.query starts out as the query string; we will parse it into key-val pairs then make |
| 142 | + // that object the "query" property. |
| 143 | + // we overwrite query in uri way to make cloning easier, it can use the same list of properties. |
| 144 | + var query = {}; |
| 145 | + // using replace to iterate over a string |
| 146 | + // JS 1.3 - function as parameter to replace |
| 147 | + // Note: uri does not work with repeated parameter names (e.g. foo=1&foo=2 ) |
| 148 | + if ( uri.query ) { |
| 149 | + uri.query.replace( /(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) { |
| 150 | + if ( $1 ) { |
| 151 | + query[ uri.decode( $1 ) ] = uri.decode( $2 ); |
| 152 | + } |
| 153 | + } ); |
| 154 | + } |
| 155 | + this.query = query; |
| 156 | + }, |
| 157 | + |
| 158 | + /** |
| 159 | + * Returns user and password portion of a URI. |
| 160 | + * @return {String} |
| 161 | + */ |
| 162 | + getUserInfo: function() { |
| 163 | + var userInfo = ''; |
| 164 | + if ( mw.isFull( this.user ) ) { |
| 165 | + userInfo += this.encode( this.user ); |
| 166 | + if ( mw.isFull( this.password ) ) { |
| 167 | + userInfo += ':' + this.encode( this.password ); |
| 168 | + } |
| 169 | + } |
| 170 | + return userInfo; |
| 171 | + }, |
| 172 | + |
| 173 | + /** |
| 174 | + * Gets host and port portion of a URI. |
| 175 | + * @return {String} |
| 176 | + */ |
| 177 | + getHostPort: function() { |
| 178 | + return this.host |
| 179 | + + ( mw.isFull( this.port ) ? ':' + this.port |
| 180 | + : '' |
| 181 | + ); |
| 182 | + }, |
| 183 | + |
| 184 | + /** |
| 185 | + * Returns the userInfo and host and port portion of the URI. |
| 186 | + * In most real-world URLs, this is simply the hostname, but it is more general. |
| 187 | + * @return {String} |
| 188 | + */ |
| 189 | + getAuthority: function() { |
| 190 | + var userInfo = this.getUserInfo(); |
| 191 | + return ( mw.isFull( userInfo ) ? userInfo + '@' |
| 192 | + : '' |
| 193 | + ) |
| 194 | + + this.getHostPort(); |
| 195 | + }, |
| 196 | + |
| 197 | + /** |
| 198 | + * Returns the query arguments of the URL, encoded into a string |
| 199 | + * Does not preserve the order of arguments passed into the URI. Does handle escaping. |
| 200 | + * @return {String} |
| 201 | + */ |
| 202 | + getQueryString: function() { |
| 203 | + var pairs = []; |
| 204 | + var _this = this; |
| 205 | + $.each( this.query, function( key, value ) { |
| 206 | + pairs.push( _this.encode( key ) + '=' + _this.encode( value ) ); |
| 207 | + } ); |
| 208 | + return pairs.join( '&' ); |
| 209 | + }, |
| 210 | + |
| 211 | + /** |
| 212 | + * Returns everything after the authority section of the URI |
| 213 | + * @return {String} |
| 214 | + */ |
| 215 | + getRelativePath: function() { |
| 216 | + var queryString = this.getQueryString(); |
| 217 | + return this.path |
| 218 | + + ( mw.isFull( queryString ) ? '?' + queryString |
| 219 | + : '' |
| 220 | + ) |
| 221 | + + ( mw.isFull( this.fragment ) ? '#' + this.encode( this.fragment ) |
| 222 | + : '' |
| 223 | + ); |
| 224 | + }, |
| 225 | + |
| 226 | + /** |
| 227 | + * Gets the entire URI string. May not be precisely the same as input due to order of query arguments. |
| 228 | + * @return {String} the URI string |
| 229 | + */ |
| 230 | + toString: function() { |
| 231 | + return this.protocol + '://' + this.getAuthority() + this.getRelativePath(); |
| 232 | + }, |
| 233 | + |
| 234 | + /** |
| 235 | + * Clone this URI |
| 236 | + * @return {Object} new URI object with same properties |
| 237 | + */ |
| 238 | + clone: function() { |
| 239 | + return new mw.Uri( this ); |
| 240 | + }, |
| 241 | + |
| 242 | + /** |
| 243 | + * Extend the query -- supply query parameters to override or add to ours |
| 244 | + * @param {Object} query parameters in key-val form to override or add |
| 245 | + * @return {Object} this URI object |
| 246 | + */ |
| 247 | + extend: function( parameters ) { |
| 248 | + $.extend( this.query, parameters ); |
| 249 | + return this; |
| 250 | + } |
| 251 | + }; |
| 252 | + |
| 253 | +} )( window.mw, jQuery ); |
Property changes on: branches/uploadwizard/extensions/UploadWizard/resources/mw.Uri.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 254 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/resources/mw.js |
— | — | @@ -0,0 +1,5 @@ |
| 2 | +// dependencies: [] |
| 3 | + |
| 4 | +if ( typeof window.mw === 'undefined' ) { |
| 5 | + window.mw = {}; |
| 6 | +} |
Property changes on: branches/uploadwizard/extensions/UploadWizard/resources/mw.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 7 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/resources/apiTokenMisc.js |
— | — | @@ -0,0 +1,61 @@ |
| 2 | +/* mistaken attempt to add tokens to all posts. |
| 3 | + there are way too many ways of getting tokens to generalize this. |
| 4 | + for uploading we are using forms (not constructing our own multiparts, for the most part) so we should obtain a reasonably fresh |
| 5 | + token for each upload instead. |
| 6 | + however this could make sense with editing |
| 7 | + */ |
| 8 | + |
| 9 | + // All POST actions need an edit token. TODO confirm this |
| 10 | + // Edit tokens expire at a time unpredictable to the client. |
| 11 | + // It is not desirable to fetch a new token before every POST. |
| 12 | + // So: we will have to obtain one if we don't have one already or encounter |
| 13 | + // a 'badtoken' error. Logic here is a bit convoluted but it's the best I can do. |
| 14 | + |
| 15 | + // A token may be cached already in the api. If we have one, use it; if not, get one and |
| 16 | + // then do the same post we were going to do. |
| 17 | + if ( this.token ) { |
| 18 | + // we have an API token, but it might be expired. |
| 19 | + // So, in the parameters of the post call, use an error handler to deal with bad tokens |
| 20 | + // that tries the post again with a brand new token. |
| 21 | + if ( ! ajaxOptions.apiError.badtoken ) { |
| 22 | + var api = this; |
| 23 | + ajaxOptions.apiError.badtoken = function() { |
| 24 | + // don't infinite loop |
| 25 | + delete ajaxOptions.apiError.badtoken; |
| 26 | + api._postWithNewToken( parameters, ajaxOptions ); |
| 27 | + }; |
| 28 | + } |
| 29 | + this._post( parameters, ajaxOptions ); |
| 30 | + } else { |
| 31 | + this._postWithNewToken( parameters, ajaxOptions ); |
| 32 | + } |
| 33 | + /** |
| 34 | + * Post API request using the token that exists already in the API (standard case) |
| 35 | + * |
| 36 | + * @param {Object} request parameters |
| 37 | + * @param {Object} ajax properties |
| 38 | + */ |
| 39 | + _post: function( parameters, ajaxOptions ) { |
| 40 | + parameters['token'] = this.token; |
| 41 | + this.ajax( parameters, ajaxOptions ); |
| 42 | + }, |
| 43 | + |
| 44 | + /** |
| 45 | + * Get a new token, cache it in the API, and then do a post |
| 46 | + * |
| 47 | + * @param {Object} request parameters |
| 48 | + * @param {Object} ajax properties |
| 49 | + */ |
| 50 | + _postWithNewToken: function( parameters, ajaxOptions ) { |
| 51 | + var api = this; |
| 52 | + this.getToken( function( token ) { |
| 53 | + if ( token === false ) { |
| 54 | + // XXX getting the token failed |
| 55 | + } else { |
| 56 | + api.token = token; |
| 57 | + api._post( parameters, ajaxOptions ); |
| 58 | + } |
| 59 | + } ); |
| 60 | + }, |
| 61 | + |
| 62 | + |
Property changes on: branches/uploadwizard/extensions/UploadWizard/resources/apiTokenMisc.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 63 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/resources/mw.UploadWizard.js |
— | — | @@ -1,3 +1,4 @@ |
| 2 | + |
2 | 3 | /** |
3 | 4 | * Sort of an abstract class for deeds |
4 | 5 | */ |
— | — | @@ -107,7 +108,7 @@ |
108 | 109 | } |
109 | 110 | } |
110 | 111 | } ); |
111 | | - mw.log( 'hasdata:' + hasData + ' endstatecount:' + endStateCount ); |
| 112 | + //mw.log( 'hasdata:' + hasData + ' endstatecount:' + endStateCount ); |
112 | 113 | // sometimes, the first data we have just tells us that it's over. So only show the bar |
113 | 114 | // if we have good data AND the fraction is less than 1. |
114 | 115 | if ( hasData && fraction < 1.0 ) { |
— | — | @@ -352,11 +353,12 @@ |
353 | 354 | * Represents the upload -- in its local and remote state. (Possibly those could be separate objects too...) |
354 | 355 | * This is our 'model' object if we are thinking MVC. Needs to be better factored, lots of feature envy with the UploadWizard |
355 | 356 | * states: |
356 | | - * 'new' 'transporting' 'transported' 'details' 'submitting-details' 'complete' |
| 357 | + * 'new' 'transporting' 'transported' 'details' 'submitting-details' 'complete' 'failed' |
357 | 358 | * should fork this into two -- local and remote, e.g. filename |
358 | 359 | */ |
359 | | -mw.UploadWizardUpload = function( filesDiv ) { |
| 360 | +mw.UploadWizardUpload = function( api, filesDiv ) { |
360 | 361 | var _this = this; |
| 362 | + _this.api = api; |
361 | 363 | _this.state = 'new'; |
362 | 364 | _this.transportWeight = 1; // default |
363 | 365 | _this.detailsWeight = 1; // default |
— | — | @@ -367,6 +369,9 @@ |
368 | 370 | _this.originalFilename = undefined; |
369 | 371 | _this.mimetype = undefined; |
370 | 372 | _this.extension = undefined; |
| 373 | + |
| 374 | + // XXX |
| 375 | + // this is sure starting to look like we should compose of UI, handler. |
371 | 376 | |
372 | 377 | // details |
373 | 378 | _this.ui = new mw.UploadWizardUploadInterface( _this, filesDiv ); |
— | — | @@ -374,7 +379,7 @@ |
375 | 380 | // handler -- usually ApiUploadHandler |
376 | 381 | // _this.handler = new ( mw.UploadWizard.config[ 'uploadHandlerClass' ] )( _this ); |
377 | 382 | // _this.handler = new mw.MockUploadHandler( _this ); |
378 | | - _this.handler = new mw.ApiUploadHandler( _this ); |
| 383 | + _this.handler = new mw.ApiUploadHandler( _this, api ); |
379 | 384 | }; |
380 | 385 | |
381 | 386 | mw.UploadWizardUpload.prototype = { |
— | — | @@ -390,7 +395,7 @@ |
391 | 396 | start: function() { |
392 | 397 | var _this = this; |
393 | 398 | _this.setTransportProgress(0.0); |
394 | | - _this.ui.start(); |
| 399 | + //_this.ui.start(); |
395 | 400 | _this.handler.start(); |
396 | 401 | }, |
397 | 402 | |
— | — | @@ -407,6 +412,7 @@ |
408 | 413 | // we signal to the wizard to update itself, which has to delete the final vestige of |
409 | 414 | // this upload (the ui.div). We have to do this silly dance because we |
410 | 415 | // trigger through the div. Triggering through objects doesn't always work. |
| 416 | + // TODO fix -- this now works in jquery 1.4.2 |
411 | 417 | $j( this.ui.div ).trigger( 'removeUploadEvent' ); |
412 | 418 | }, |
413 | 419 | |
— | — | @@ -424,8 +430,19 @@ |
425 | 431 | }, |
426 | 432 | |
427 | 433 | /** |
| 434 | + * Stop the upload -- we have failed for some reason |
| 435 | + */ |
| 436 | + setFailed: function( code ) { |
| 437 | + /* stop the upload progress */ |
| 438 | + this.state = 'failed'; |
| 439 | + this.transportProgress = 0; |
| 440 | + this.ui.showFailed( code ); |
| 441 | + }, |
| 442 | + |
| 443 | + /** |
428 | 444 | * To be executed when an individual upload finishes. Processes the result and updates step 2's details |
429 | 445 | * @param result the API result in parsed JSON form |
| 446 | + * XXX needs refactor --- new api needs error handler instead |
430 | 447 | */ |
431 | 448 | setTransported: function( result ) { |
432 | 449 | var _this = this; |
— | — | @@ -448,10 +465,14 @@ |
449 | 466 | |
450 | 467 | // and other errors that result in a stash |
451 | 468 | } else { |
452 | | - alert("failure!"); |
453 | | - // we may want to tag or otherwise queue it as an upload to retry |
| 469 | + if ( result.error ) { |
| 470 | + alert( "error : " + result.error.code + " : " + result.error.info ); |
| 471 | + } |
| 472 | + this.ui.showFailed(); |
| 473 | + alert("huh?"); |
| 474 | + // TODO now we should tag the upload as failed |
| 475 | + // if can recover, should maybe allow re-uploading. |
454 | 476 | } |
455 | | - |
456 | 477 | |
457 | 478 | }, |
458 | 479 | |
— | — | @@ -479,6 +500,7 @@ |
480 | 501 | var _this = this; |
481 | 502 | |
482 | 503 | _this.filename = result.upload.filename; |
| 504 | + // XXX global? |
483 | 505 | _this.title = wgFormattedNamespaces[wgNamespaceIds['file']] + ':' + _this.filename; |
484 | 506 | |
485 | 507 | _this.extractImageInfo( result.upload.imageinfo ); |
— | — | @@ -537,8 +559,6 @@ |
538 | 560 | return; |
539 | 561 | } |
540 | 562 | |
541 | | - var apiUrl = mw.UploadWizard.config.apiUrl; |
542 | | - |
543 | 563 | var params = { |
544 | 564 | 'titles': _this.title, |
545 | 565 | 'prop': 'imageinfo', |
— | — | @@ -546,7 +566,8 @@ |
547 | 567 | 'iiprop': 'url' |
548 | 568 | }; |
549 | 569 | |
550 | | - mw.getJSON( apiUrl, params, function( data ) { |
| 570 | + debugger; |
| 571 | + this.api.get( params, function( data ) { |
551 | 572 | if ( !data || !data.query || !data.query.pages ) { |
552 | 573 | mw.log(" No data? "); |
553 | 574 | // XXX do something about the thumbnail spinner, maybe call the callback with a broken image. |
— | — | @@ -609,8 +630,6 @@ |
610 | 631 | $j( selector ).loadingSpinner(); |
611 | 632 | _this.getThumbnail( width, callback ); |
612 | 633 | } |
613 | | - |
614 | | - |
615 | 634 | |
616 | 635 | }; |
617 | 636 | |
— | — | @@ -717,16 +736,16 @@ |
718 | 737 | /** |
719 | 738 | * |
720 | 739 | */ |
721 | | - showIndicatorMessage: function( classToRemove, classToAdd, msgKey ) { |
| 740 | + showIndicatorMessage: function( statusClass, msgKey ) { |
722 | 741 | var _this = this; |
723 | 742 | var $indicator = $j( _this.div ).find( '.mwe-upwiz-file-indicator' ); |
724 | | - if ( classToRemove ) { |
725 | | - $indicator.removeClass( classToRemove ); |
726 | | - } |
727 | | - if ( classToAdd ) { |
728 | | - $indicator.addClass( classToAdd ); |
729 | | - } |
730 | | - $indicator.html( gM( msgKey ) ); |
| 743 | + $j.each( $indicator.attr( 'class' ).split( /\s+/ ), function( i, className ) { |
| 744 | + if ( className.match( /^mwe-upwiz-status/ ) ) { |
| 745 | + $indicator.removeClass( className ); |
| 746 | + } |
| 747 | + } ); |
| 748 | + $indicator.addClass( 'mwe-upwiz-status-' + statusClass ) |
| 749 | + .html( gM( msgKey ) ); |
731 | 750 | $j( _this.div ).find( '.mwe-upwiz-visible-file-filename' ) |
732 | 751 | .css( 'margin-right', ( $indicator.outerWidth() + 24 ).toString() + 'px' ); |
733 | 752 | $indicator.css( 'visibility', 'visible' ); |
— | — | @@ -737,17 +756,25 @@ |
738 | 757 | * @param fraction The fraction of progress. Float between 0 and 1 |
739 | 758 | */ |
740 | 759 | showTransportProgress: function() { |
741 | | - this.showIndicatorMessage( null, 'mwe-upwiz-status-progress', 'mwe-upwiz-uploading' ); |
| 760 | + this.showIndicatorMessage( 'progress', 'mwe-upwiz-uploading' ); |
742 | 761 | // update individual progress bar with fraction? |
743 | 762 | }, |
744 | 763 | |
745 | 764 | /** |
746 | | - * Execute when this upload is transported; cleans up interface. |
| 765 | + * Show that upload is transported |
747 | 766 | */ |
748 | 767 | showTransported: function() { |
749 | | - this.showIndicatorMessage( 'mwe-upwiz-status-progress', 'mwe-upwiz-status-completed', 'mwe-upwiz-transported' ); |
| 768 | + this.showIndicatorMessage( 'completed', 'mwe-upwiz-transported' ); |
750 | 769 | }, |
751 | 770 | |
| 771 | + /** |
| 772 | + * Show that transport has failed |
| 773 | + */ |
| 774 | + showFailed: function( code ) { |
| 775 | + this.showIndicatorMessage( 'failed', 'mwe-upwiz-failed' ); |
| 776 | + //add a "retry" button, too? |
| 777 | + }, |
| 778 | + |
752 | 779 | /** |
753 | 780 | * Run this when the value of the file input has changed. Check the file for various forms of goodness. |
754 | 781 | * If okay, then update the visible filename (due to CSS trickery the real file input is invisible) |
— | — | @@ -1813,7 +1840,6 @@ |
1814 | 1841 | action: 'edit', |
1815 | 1842 | // XXX this is problematic, if the upload wizard is idle for a long time the token expires. |
1816 | 1843 | // should obtain token just before uploading |
1817 | | - token: mw.UploadWizard.config[ 'token' ], |
1818 | 1844 | title: _this.upload.title, |
1819 | 1845 | // section: 0, ?? causing issues? |
1820 | 1846 | text: wikiText, |
— | — | @@ -1841,7 +1867,7 @@ |
1842 | 1868 | }; |
1843 | 1869 | |
1844 | 1870 | _this.upload.state = 'submitting-details'; |
1845 | | - mw.getJSON( params, callback ); |
| 1871 | + _this.api.post( params, callback ); |
1846 | 1872 | }, |
1847 | 1873 | |
1848 | 1874 | /** |
— | — | @@ -1866,11 +1892,9 @@ |
1867 | 1893 | reason: "User edited page with " + mw.UploadWizard.userAgent, |
1868 | 1894 | movetalk: '', |
1869 | 1895 | noredirect: '', // presume it's too new |
1870 | | - token: mw.UploadWizard.config[ 'token' ] |
1871 | 1896 | }; |
1872 | 1897 | mw.log(params); |
1873 | | - // despite the name, getJSON magically changes this into a POST request (it has a list of methods and what they require). |
1874 | | - mw.getJSON( params, function( data ) { |
| 1898 | + _this.api.post( params, function( data ) { |
1875 | 1899 | // handle errors later |
1876 | 1900 | // possible error data: { code = 'missingtitle' } -- orig filename not there |
1877 | 1901 | // and many more |
— | — | @@ -1902,7 +1926,7 @@ |
1903 | 1927 | 'iiprop': 'timestamp|url|user|size|sha1|mime|metadata' |
1904 | 1928 | }; |
1905 | 1929 | // XXX timeout callback? |
1906 | | - mw.getJSON( params, function( data ) { |
| 1930 | + this.api.get( params, function( data ) { |
1907 | 1931 | if ( data && data.query && data.query.pages ) { |
1908 | 1932 | if ( ! data.query.pages[-1] ) { |
1909 | 1933 | for ( var page_id in data.query.pages ) { |
— | — | @@ -1939,6 +1963,7 @@ |
1940 | 1964 | mw.UploadWizard = function( config ) { |
1941 | 1965 | |
1942 | 1966 | this.uploads = []; |
| 1967 | + this.api = new mw.Api( { url: config.apiUrl } ); |
1943 | 1968 | |
1944 | 1969 | // making a sort of global for now, should be done by passing in config or fragments of config when needed |
1945 | 1970 | // elsewhere |
— | — | @@ -1950,6 +1975,7 @@ |
1951 | 1976 | |
1952 | 1977 | }; |
1953 | 1978 | |
| 1979 | +mw.UploadWizard.DEBUG = true; |
1954 | 1980 | |
1955 | 1981 | mw.UploadWizard.userAgent = "UploadWizard (alpha)"; |
1956 | 1982 | |
— | — | @@ -2260,7 +2286,7 @@ |
2261 | 2287 | return false; |
2262 | 2288 | } |
2263 | 2289 | |
2264 | | - var upload = new mw.UploadWizardUpload( _this, '#mwe-upwiz-files' ); |
| 2290 | + var upload = new mw.UploadWizardUpload( _this.api, '#mwe-upwiz-files' ); |
2265 | 2291 | _this.uploadToAdd = upload; |
2266 | 2292 | |
2267 | 2293 | upload.ui.moveFileInputToCover( '#mwe-upwiz-add-file' ); |
— | — | @@ -3168,54 +3194,6 @@ |
3169 | 3195 | |
3170 | 3196 | ( function( $j ) { |
3171 | 3197 | |
3172 | | - $j.fn.tipsyPlus = function( optionsArg ) { |
3173 | | - // use extend! |
3174 | | - var titleOption = 'title'; |
3175 | | - var htmlOption = false; |
3176 | | - |
3177 | | - var options = $j.extend( |
3178 | | - { type: 'help', shadow: true }, |
3179 | | - optionsArg |
3180 | | - ); |
3181 | | - |
3182 | | - var el = this; |
3183 | | - |
3184 | | - if (options.plus) { |
3185 | | - htmlOption = true; |
3186 | | - titleOption = function() { |
3187 | | - return $j( '<span />' ).append( |
3188 | | - $j( this ).attr( 'original-title' ), |
3189 | | - $j( '<a class="mwe-upwiz-tooltip-link"/>' ) |
3190 | | - .attr( 'href', '#' ) |
3191 | | - .append( gM( 'mwe-upwiz-tooltip-more-info' ) ) |
3192 | | - .mouseenter( function() { |
3193 | | - el.data('tipsy').sticky = true; |
3194 | | - } ) |
3195 | | - .mouseleave( function() { |
3196 | | - el.data('tipsy').sticky = false; |
3197 | | - } ) |
3198 | | - .click( function() { |
3199 | | - // show the wiki page with more |
3200 | | - alert( options.plus ); |
3201 | | - // pass this in as a closure to be called on dismiss |
3202 | | - el.focus(); |
3203 | | - el.data('tipsy').sticky = false; |
3204 | | - } ) |
3205 | | - ); |
3206 | | - }; |
3207 | | - } |
3208 | | - |
3209 | | - return this.tipsy( { |
3210 | | - gravity: 'w', |
3211 | | - trigger: 'focus', |
3212 | | - title: titleOption, |
3213 | | - html: htmlOption, |
3214 | | - type: options.type, |
3215 | | - shadow: options.shadow |
3216 | | - } ); |
3217 | | - |
3218 | | - }; |
3219 | | - |
3220 | 3198 | /** |
3221 | 3199 | * Create 'remove' control, an X which highlights in some standardized way. |
3222 | 3200 | */ |
— | — | @@ -3287,17 +3265,7 @@ |
3288 | 3266 | return this.prepend( $j( '<span/>' ).append( '*' ).addClass( 'mwe-upwiz-required-marker' ) ); |
3289 | 3267 | }; |
3290 | 3268 | |
3291 | | - /** |
3292 | | - * Upper-case the first letter of a string. XXX move to common library |
3293 | | - * @param string |
3294 | | - * @return string with first letter uppercased. |
3295 | | - */ |
3296 | | - mw.ucfirst = function( s ) { |
3297 | | - return s.substring(0,1).toUpperCase() + s.substr(1); |
3298 | | - }; |
3299 | 3269 | |
3300 | | - |
3301 | | - |
3302 | 3270 | /** |
3303 | 3271 | * jQuery extension. Makes a textarea automatically grow if you enter overflow |
3304 | 3272 | * (This feature was in the old Commons interface with a confusing arrow icon; it's nicer to make it automatic.) |
Index: branches/uploadwizard/extensions/UploadWizard/resources/mw.DestinationChecker.js |
— | — | @@ -125,6 +125,7 @@ |
126 | 126 | _this.spinner( true ); |
127 | 127 | |
128 | 128 | // Setup the request -- will return thumbnail data if it finds one |
| 129 | + // XXX do not use iiurlwidth as it will create a thumbnail |
129 | 130 | var request = { |
130 | 131 | 'titles': 'File:' + name, |
131 | 132 | 'prop': 'imageinfo', |
Index: branches/uploadwizard/extensions/UploadWizard/resources/mw.Api.js |
— | — | @@ -0,0 +1,154 @@ |
| 2 | +/* mw.Api objects represent the API of a particular MediaWiki server. */ |
| 3 | + |
| 4 | +// dependencies: [ mw ] |
| 5 | + |
| 6 | +( function( mw, $j ) { |
| 7 | + |
| 8 | + /** |
| 9 | + * Represents the API of a particular MediaWiki server. |
| 10 | + * |
| 11 | + * Required options: |
| 12 | + * url - complete URL to API endpoint. Usually equivalent to wgServer + wgScriptPath + '/api.php' |
| 13 | + * |
| 14 | + * Other options: |
| 15 | + * can override the parameter defaults and ajax default options. |
| 16 | + * XXX document! |
| 17 | + * |
| 18 | + * ajax options can also be overriden on every get() or post() |
| 19 | + * |
| 20 | + * @param options {Mixed} can take many options, but must include at minimum the API url. |
| 21 | + */ |
| 22 | + mw.Api = function( options ) { |
| 23 | + |
| 24 | + // make sure we at least have a URL endpoint for the API |
| 25 | + if ( ! mw.isDefined( options.url ) ) { |
| 26 | + throw new Error( 'Configuration error - needs url property' ); |
| 27 | + }; |
| 28 | + |
| 29 | + this.url = options.url; |
| 30 | + |
| 31 | + // deal with cases where we need an API proxy |
| 32 | + var apiUri = new mw.Uri( this.url ); |
| 33 | + var scriptUri = new mw.Uri( window.location ); |
| 34 | + if ( apiUri.host !== scriptUri.host ) { |
| 35 | + /* Ask mdale, his proxy was not being developed on wikimedia svn... somewhere on Kaltura servers */ |
| 36 | + throw new Error( "unimplemented -- API proxy required."); |
| 37 | + } |
| 38 | + |
| 39 | + var _this = this; |
| 40 | + |
| 41 | + /* We allow people to omit these default parameters from API requests */ |
| 42 | + // there is very customizable error handling here, on a per-call basis |
| 43 | + // wondering, would it be simpler to make it easy to clone the api object, change error handling, and use that instead? |
| 44 | + this.defaults = { |
| 45 | + parameters: { |
| 46 | + action: 'query', |
| 47 | + format: 'json' |
| 48 | + }, |
| 49 | + |
| 50 | + ajax: { |
| 51 | + // force toString if we got a mw.Uri object |
| 52 | + url: new String( this.url ), |
| 53 | + |
| 54 | + /* default function for success and no API error */ |
| 55 | + ok: function() {}, |
| 56 | + |
| 57 | + // caller can supply handlers for http transport error or api errors |
| 58 | + err: function( code, result ) { |
| 59 | + var errorMsg = "API error: " + type + " : " + code; |
| 60 | + mw.log( errorMsg ); |
| 61 | + }, |
| 62 | + |
| 63 | + timeout: 30000, /* 30 seconds */ |
| 64 | + |
| 65 | + dataType: 'json' |
| 66 | + |
| 67 | + } |
| 68 | + }; |
| 69 | + |
| 70 | + |
| 71 | + if ( options.parameters ) { |
| 72 | + $j.extend( this.defaults.parameters, options.parameters ); |
| 73 | + } |
| 74 | + |
| 75 | + if ( options.ajax ) { |
| 76 | + $j.extend( this.defaults.ajax, options.ajax ); |
| 77 | + } |
| 78 | + }; |
| 79 | + |
| 80 | + mw.Api.prototype = { |
| 81 | + |
| 82 | + /** |
| 83 | + * For api queries, in simple cases the caller just passes a success callback. |
| 84 | + * In complex cases they pass an object with a success property as callback and probably other options. |
| 85 | + * Normalize the argument so that it's always the latter case. |
| 86 | + * |
| 87 | + * @param {Object|Function} ajax properties, or just a success function |
| 88 | + * @return Function |
| 89 | + */ |
| 90 | + normalizeAjaxOptions: function( arg ) { |
| 91 | + if ( typeof arg === 'function' ) { |
| 92 | + var ok = arg; |
| 93 | + arg = { 'ok': ok }; |
| 94 | + } |
| 95 | + if (! arg.ok ) { |
| 96 | + throw Error( "ajax options must include ok callback" ); |
| 97 | + } |
| 98 | + return arg; |
| 99 | + }, |
| 100 | + |
| 101 | + /** |
| 102 | + * Perform API get request |
| 103 | + * |
| 104 | + * @param {Object} request parameters |
| 105 | + * @param {Object|Function} ajax properties, or just a success function |
| 106 | + */ |
| 107 | + get: function( parameters, ajaxOptions ) { |
| 108 | + ajaxOptions.type = 'get'; |
| 109 | + this.ajax( parameters, ajaxOptions ); |
| 110 | + }, |
| 111 | + |
| 112 | + /** |
| 113 | + * Perform API post request |
| 114 | + * TODO post actions for nonlocal will need proxy |
| 115 | + * |
| 116 | + * @param {Object} request parameters |
| 117 | + * @param {Object|Function} ajax properties, or just a success function |
| 118 | + */ |
| 119 | + post: function( parameters, ajaxOptions ) { |
| 120 | + ajaxOptions.type = 'post'; |
| 121 | + this.ajax( parameters, ajaxOptions ); |
| 122 | + }, |
| 123 | + |
| 124 | + /** |
| 125 | + * Perform the API call. |
| 126 | + * |
| 127 | + * @param {Object} request parameters |
| 128 | + * @param {Object} ajax properties |
| 129 | + */ |
| 130 | + ajax: function( parameters, ajaxOptions ) { |
| 131 | + ajaxOptions = this.normalizeAjaxOptions( ajaxOptions ); |
| 132 | + parameters = $j.extend( {}, this.defaults.parameters, parameters ); |
| 133 | + ajaxOptions = $j.extend( {}, this.defaults.ajax, ajaxOptions ); |
| 134 | + ajaxOptions.data = parameters; |
| 135 | + |
| 136 | + ajaxOptions.error = function( xhr, textStatus, exception ) { |
| 137 | + ajaxOptions.err( 'http-' + textStatus, { xhr: xhr, exception: exception } ); |
| 138 | + }; |
| 139 | + |
| 140 | + /* success just means 200 OK; also check for API errors */ |
| 141 | + ajaxOptions.success = function( result ) { |
| 142 | + if ( result.error ) { |
| 143 | + ajaxOptions.err( result.error.code, result ); |
| 144 | + } else { |
| 145 | + ajaxOptions.ok( result ); |
| 146 | + } |
| 147 | + }; |
| 148 | + |
| 149 | + $j.ajax( ajaxOptions ); |
| 150 | + |
| 151 | + }, |
| 152 | + |
| 153 | + } |
| 154 | + |
| 155 | +}) ( window.mw, jQuery ); |
Property changes on: branches/uploadwizard/extensions/UploadWizard/resources/mw.Api.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 156 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/resources/mw.ApiProxy.js |
— | — | @@ -0,0 +1,36 @@ |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +/* |
| 7 | + |
| 8 | +apiproxy stuff -- we will do this in a different way |
| 9 | + if( mw.checkRequestPost( parameters ) ) { |
| 10 | + |
| 11 | + // Check if we need to setup a proxy |
| 12 | + if( ! mw.isLocalDomain( url ) ) { |
| 13 | + |
| 14 | + // Load the proxy and issue the parameters |
| 15 | + mw.load( 'ApiProxy', function( ) { |
| 16 | + mw.ApiProxy.doRequest( url, parameters, callback, timeoutCallback); |
| 17 | + } ); |
| 18 | + |
| 19 | + } else { |
| 20 | + |
| 21 | + } |
| 22 | + return ; |
| 23 | + } |
| 24 | + |
| 25 | + // If cross domain setup a callback: |
| 26 | + if( ! mw.isLocalDomain( url ) ) { |
| 27 | + if( url.indexOf( 'callback=' ) == -1 || parameters[ 'callback' ] == -1 ) { |
| 28 | + // jQuery specific jsonp format: ( second ? is replaced with the callback ) |
| 29 | + url += ( url.indexOf('?') == -1 ) ? '?callback=?' : '&callback=?'; |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + // Pass off the jQuery getJSON parameters: |
| 34 | + $j.getJSON( this.url, parameters, myCallback ); |
| 35 | + } |
| 36 | + |
| 37 | +*/ |
Property changes on: branches/uploadwizard/extensions/UploadWizard/resources/mw.ApiProxy.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 38 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/resources/mw.Utilities.js |
— | — | @@ -1,26 +1,62 @@ |
2 | | -/** |
3 | | -* Check if an object is empty or if its an empty string. |
4 | | -* |
5 | | -* @param {Object} object Object to be checked |
6 | | -*/ |
7 | | -mw.isEmpty = function( object ) { |
8 | | - if( typeof object == 'string' ) { |
9 | | - if( object == '' ) return true; |
10 | | - // Non empty string: |
11 | | - return false; |
12 | | - } |
| 2 | +// dependencies: mw |
13 | 3 | |
14 | | - // If an array check length: |
15 | | - if( Object.prototype.toString.call( object ) === "[object Array]" |
16 | | - && object.length == 0 ) { |
| 4 | +( function( mw ) { |
| 5 | + |
| 6 | + /** |
| 7 | + * Check if an object is empty or if its an empty string. |
| 8 | + * |
| 9 | + * @param {Object} object Object to be checked |
| 10 | + * @return {Boolean} |
| 11 | + */ |
| 12 | + mw.isEmpty = function( obj ) { |
| 13 | + if( typeof obj == 'string' ) { |
| 14 | + if( obj == '' ) return true; |
| 15 | + // Non empty string: |
| 16 | + return false; |
| 17 | + } |
| 18 | + |
| 19 | + // If an array check length: |
| 20 | + if( Object.prototype.toString.call( obj ) === "[object Array]" |
| 21 | + && obj.length == 0 ) { |
| 22 | + return true; |
| 23 | + } |
| 24 | + |
| 25 | + // Else check as an obj: |
| 26 | + for( var i in obj ) { return false; } |
| 27 | + |
| 28 | + // Else obj is empty: |
17 | 29 | return true; |
18 | | - } |
| 30 | + }; |
19 | 31 | |
20 | | - // Else check as an object: |
21 | | - for( var i in object ) { return false; } |
| 32 | + /** |
| 33 | + * Opposite of mw.isEmpty |
| 34 | + * |
| 35 | + * @param {Object} object Object to be checked |
| 36 | + * @return {Boolean} |
| 37 | + */ |
| 38 | + mw.isFull = function( obj ) { |
| 39 | + return ! mw.isEmpty( obj ); |
| 40 | + }; |
22 | 41 | |
23 | | - // Else object is empty: |
24 | | - return true; |
25 | | -} |
| 42 | + /** |
| 43 | + * Check if something is defined |
| 44 | + * (inlineable?) |
| 45 | + * @param {Object} |
| 46 | + * @return boolean |
| 47 | + */ |
| 48 | + mw.isDefined = function( obj ) { |
| 49 | + return typeof obj !== 'undefined'; |
| 50 | + }; |
26 | 51 | |
27 | 52 | |
| 53 | + /** |
| 54 | + * Upper-case the first letter of a string. |
| 55 | + * @param string |
| 56 | + * @return string with first letter uppercased. |
| 57 | + */ |
| 58 | + mw.ucfirst = function( s ) { |
| 59 | + return s.substring(0,1).toUpperCase() + s.substr(1); |
| 60 | + }; |
| 61 | + |
| 62 | + |
| 63 | +} )( window.mw ); |
Index: branches/uploadwizard/extensions/UploadWizard/resources/mw.ApiUploadHandler.js |
— | — | @@ -10,16 +10,17 @@ |
11 | 11 | * Represents an object which configures a form to upload its files via an iframe talking to the MediaWiki API. |
12 | 12 | * @param an UploadInterface object, which contains a .form property which points to a real HTML form in the DOM |
13 | 13 | */ |
14 | | -mw.ApiUploadHandler = function( upload ) { |
| 14 | +mw.ApiUploadHandler = function( upload, api ) { |
| 15 | + this.upload = upload; |
| 16 | + this.api = api; |
| 17 | + this.$form = $j( this.upload.ui.form ); |
| 18 | + this.configureForm(); |
| 19 | + |
| 20 | + // the Iframe transport is hardcoded for now because it works everywhere |
| 21 | + // can also use Xhr Binary depending on browser |
15 | 22 | var _this = this; |
16 | | - _this.upload = upload; |
17 | | - |
18 | | - _this.configureForm(); |
19 | | - |
20 | | - // hardcoded for now |
21 | | - // can also use Xhr Binary depending on config |
22 | | - _this.transport = new mw.IframeTransport( |
23 | | - _this.upload.ui.form, |
| 23 | + this.transport = new mw.IframeTransport( |
| 24 | + this.$form, |
24 | 25 | function( fraction ){ _this.upload.setTransportProgress( fraction ); }, |
25 | 26 | function( result ) { _this.upload.setTransported( result ); } |
26 | 27 | ); |
— | — | @@ -33,7 +34,6 @@ |
34 | 35 | * @param callback |
35 | 36 | */ |
36 | 37 | configureForm: function() { |
37 | | - var apiUrl = mw.UploadWizard.config[ 'apiUrl' ]; // XXX or? throw new Error( "configuration", "no API url" ); |
38 | 38 | if ( ! ( mw.UploadWizard.config[ 'token' ] ) ) { |
39 | 39 | throw new Error( "configuration", "no edit token" ); |
40 | 40 | } |
— | — | @@ -43,44 +43,59 @@ |
44 | 44 | |
45 | 45 | // Set the form action |
46 | 46 | try { |
47 | | - $j( _this.upload.ui.form ) |
48 | | - .attr( 'action', apiUrl ) |
49 | | - .attr( 'method', 'POST' ) |
50 | | - .attr( 'enctype', 'multipart/form-data' ); |
| 47 | + this.$form.attr( { |
| 48 | + action: _this.api.url, |
| 49 | + method: 'POST', |
| 50 | + enctype: 'multipart/form-data' |
| 51 | + } ); |
51 | 52 | } catch ( e ) { |
52 | 53 | alert( "oops, form modification didn't work in ApiUploadHandler" ); |
53 | 54 | mw.log( "IE for some reason error's out when you change the action" ); |
54 | 55 | // well, if IE fucks this up perhaps we should do something to make sure it writes correctly |
55 | 56 | // from the outset? |
56 | 57 | } |
57 | | - |
58 | | - _this.addFormInputIfMissing( 'token', mw.UploadWizard.config[ 'token' ]); |
| 58 | + |
| 59 | + // XXX TODO - different action, like upload-stash-only or something |
59 | 60 | _this.addFormInputIfMissing( 'action', 'upload' ); |
| 61 | + |
| 62 | + // XXX TODO - remove; if we are uploading to stash only, a comment should not be required - yet. |
| 63 | + _this.addFormInputIfMissing( 'comment', 'DUMMY TEXT' ); |
| 64 | + |
| 65 | + _this.addFormInputIfMissing( 'stash', 1 ); |
| 66 | + |
| 67 | + // we use JSON in HTML because according to mdale, some browsers cannot handle just JSON |
60 | 68 | _this.addFormInputIfMissing( 'format', 'jsonfm' ); |
61 | 69 | |
62 | 70 | // XXX only for testing, so it stops complaining about dupes |
63 | | - if ( mw.UploadWizard.config[ 'debug' ]) { |
| 71 | + if ( mw.UploadWizard.DEBUG ) { |
64 | 72 | _this.addFormInputIfMissing( 'ignorewarnings', '1' ); |
65 | 73 | } |
66 | 74 | }, |
67 | 75 | |
| 76 | + /** |
| 77 | + * Modify our form to have a fresh edit token. |
| 78 | + * If successful, return true to a callback. |
| 79 | + * @param callback to return true on success |
| 80 | + */ |
| 81 | + configureEditToken: function( callerOk, err ) { |
| 82 | + var _this = this; |
| 83 | + |
| 84 | + var ok = function( token ) { |
| 85 | + _this.addFormInputIfMissing( 'token', token ); |
| 86 | + callerOk(); |
| 87 | + }; |
| 88 | + |
| 89 | + _this.api.getEditToken( ok, err ); |
| 90 | + }, |
| 91 | + |
68 | 92 | /** |
69 | 93 | * Add a hidden input to a form if it was not already there. |
70 | 94 | * @param name the name of the input |
71 | 95 | * @param value the value of the input |
72 | 96 | */ |
73 | 97 | addFormInputIfMissing: function( name, value ) { |
74 | | - var _this = this; |
75 | | - var $jForm = $j( _this.upload.ui.form ); |
76 | | - if ( $jForm.find( "[name='" + name + "']" ).length === 0 ) { |
77 | | - $jForm.append( |
78 | | - $j( '<input />' ) |
79 | | - .attr( { |
80 | | - 'type': "hidden", |
81 | | - 'name' : name, |
82 | | - 'value' : value |
83 | | - } ) |
84 | | - ); |
| 98 | + if ( this.$form.find( "[name='" + name + "']" ).length === 0 ) { |
| 99 | + this.$form.append( $j( '<input />' ) .attr( { 'type': "hidden", 'name': name, 'value': value } )); |
85 | 100 | } |
86 | 101 | }, |
87 | 102 | |
— | — | @@ -89,10 +104,16 @@ |
90 | 105 | */ |
91 | 106 | start: function() { |
92 | 107 | var _this = this; |
93 | | - mw.log( "api: upload start!" ); |
94 | | - _this.beginTime = ( new Date() ).getTime(); |
95 | | - _this.upload.ui.busy(); |
96 | | - $j( this.upload.ui.form ).submit(); |
| 108 | + var ok = function() { |
| 109 | + mw.log( "api: upload start!" ); |
| 110 | + _this.beginTime = ( new Date() ).getTime(); |
| 111 | + _this.upload.ui.busy(); |
| 112 | + _this.$form.submit(); |
| 113 | + }; |
| 114 | + var err = function( code, info ) { |
| 115 | + _this.upload.setFailed( code, info ); |
| 116 | + }; |
| 117 | + this.configureEditToken( ok, err ); |
97 | 118 | } |
98 | 119 | }; |
99 | 120 | |
Index: branches/uploadwizard/extensions/UploadWizard/resources/mw.IframeTransport.js |
— | — | @@ -1,36 +1,37 @@ |
2 | 2 | /** |
3 | 3 | * Represents a "transport" for files to upload; in this case an iframe. |
| 4 | + * XXX dubious whether this is really separated from "ApiUploadHandler", which does a lot of form config. |
| 5 | + * |
4 | 6 | * The iframe is made to be the target of a form so that the existing page does not reload, even though it's a POST. |
5 | | - * @param form an HTML form |
| 7 | + * @param form jQuery selector for HTML form |
6 | 8 | * @param progressCb callback to execute when we've started. (does not do float here because iframes can't |
7 | 9 | * monitor fractional progress). |
8 | 10 | * @param transportedCb callback to execute when we've finished the upload |
9 | 11 | */ |
10 | | -mw.IframeTransport = function( form, progressCb, transportedCb ) { |
11 | | - var _this = this; |
| 12 | +mw.IframeTransport = function( $form, progressCb, transportedCb ) { |
| 13 | + this.$form = $form; |
| 14 | + this.progressCb = progressCb; |
| 15 | + this.transportedCb = transportedCb; |
12 | 16 | |
13 | | - _this.form = form; |
14 | | - _this.progressCb = progressCb; |
15 | | - _this.transportedCb = transportedCb; |
16 | | - |
17 | | - _this.iframeId = 'f_' + ( $j( 'iframe' ).length + 1 ); |
| 17 | + this.iframeId = 'f_' + ( $j( 'iframe' ).length + 1 ); |
18 | 18 | |
19 | 19 | //IE only works if you "create element with the name" ( not jquery style ) |
20 | 20 | var iframe; |
21 | 21 | try { |
22 | | - iframe = document.createElement( '<iframe name="' + _this.iframeId + '">' ); |
| 22 | + iframe = document.createElement( '<iframe name="' + this.iframeId + '">' ); |
23 | 23 | } catch ( ex ) { |
24 | 24 | iframe = document.createElement( 'iframe' ); |
25 | | - } |
| 25 | + } |
| 26 | + this.$iframe = $j( iframe ); |
26 | 27 | |
27 | 28 | // we configure form on load, because the first time it loads, it's blank |
28 | 29 | // then we configure it to deal with an API submission |
29 | | - $j( iframe ) |
30 | | - .attr( { 'src' : 'javascript:false;', |
31 | | - 'id' : _this.iframeId, |
32 | | - 'name' : _this.iframeId } ) |
33 | | - .load( function() { _this.configureForm(); } ) |
34 | | - .css( 'display', 'none' ); |
| 30 | + var _this = this; |
| 31 | + this.$iframe.attr( { 'src' : 'javascript:false;', |
| 32 | + 'id' : this.iframeId, |
| 33 | + 'name' : this.iframeId } ) |
| 34 | + .load( function() { _this.configureForm(); } ) |
| 35 | + .css( 'display', 'none' ); |
35 | 36 | |
36 | 37 | $j( "body" ).append( iframe ); |
37 | 38 | }; |
— | — | @@ -42,20 +43,19 @@ |
43 | 44 | */ |
44 | 45 | configureForm: function() { |
45 | 46 | mw.log( "configuring form for iframe transport" ); |
46 | | - var _this = this; |
47 | 47 | // Set the form target to the iframe |
48 | | - var $jForm = $j( _this.form ); |
49 | | - $jForm.attr( 'target', _this.iframeId ); |
| 48 | + this.$form.attr( 'target', this.iframeId ); |
50 | 49 | |
51 | 50 | // attach an additional handler to the form, so, when submitted, it starts showing the progress |
52 | 51 | // XXX this is lame .. there should be a generic way to indicate busy status... |
53 | | - $jForm.submit( function() { |
| 52 | + this.$form.submit( function() { |
54 | 53 | mw.log( "submitting to iframe..." ); |
55 | 54 | return true; |
56 | 55 | } ); |
57 | 56 | |
58 | 57 | // Set up the completion callback |
59 | | - $j( '#' + _this.iframeId ).load( function() { |
| 58 | + var _this = this; |
| 59 | + $j( '#' + this.iframeId ).load( function() { |
60 | 60 | mw.log( "received result in iframe" ); |
61 | 61 | _this.progressCb( 1.0 ); |
62 | 62 | _this.processIframeResult( $j( this ).get( 0 ) ); |
— | — | @@ -88,7 +88,9 @@ |
89 | 89 | response = doc.XMLDocument; |
90 | 90 | } else if ( doc.body ) { |
91 | 91 | // Get the json string |
92 | | - // XXX wait... why are we grepping it out of an HTML doc? We requested jsonfm, why? |
| 92 | + // We're actually searching through an HTML doc here -- |
| 93 | + // according to mdale we need to do this |
| 94 | + // because IE does not load JSON properly in an iframe |
93 | 95 | json = $j( doc.body ).find( 'pre' ).text(); |
94 | 96 | mw.log( 'iframe:json::' + json ); |
95 | 97 | if ( json ) { |
Index: branches/uploadwizard/extensions/UploadWizard/resources/mw.Log.js |
— | — | @@ -1,50 +1,62 @@ |
2 | | -// placeholders for stuff we used to get from mwEmbed |
| 2 | +// dependencies: [ mw ] |
3 | 3 | |
4 | | -/** |
5 | | -* Log a string msg to the console |
6 | | -* |
7 | | -* all mw.log statements will be removed on minification so |
8 | | -* lots of mw.log calls will not impact performance in non debug mode |
9 | | -* |
10 | | -* @param {String} string String to output to console |
11 | | -*/ |
12 | | -mw.log = function( string ) { |
| 4 | +( function( mw, $j ) { |
13 | 5 | |
14 | | - // Add any prepend debug strings if necessary |
15 | | - if ( mw.log.preAppendLog ) { |
16 | | - string = mw.log.preAppendLog + string; |
| 6 | + // XXX we need to solve this with resource loader |
| 7 | + var dependencies = { "mw": mw }; |
| 8 | + for ( var d in dependencies ) { |
| 9 | + if ( typeof dependencies[d] === 'undefined' ) { |
| 10 | + alert( "missing dependency: " + d ); |
| 11 | + } |
17 | 12 | } |
18 | 13 | |
19 | | - if ( window.console ) { |
20 | | - window.console.log( string ); |
21 | | - } else { |
| 14 | + /** |
| 15 | + * Log a string msg to the console |
| 16 | + * |
| 17 | + * all mw.log statements will be removed on minification so |
| 18 | + * lots of mw.log calls will not impact performance in non debug mode |
| 19 | + * |
| 20 | + * @param {String} string String to output to console |
| 21 | + */ |
| 22 | + mw.log = function( string ) { |
22 | 23 | |
23 | | - /** |
24 | | - * Old IE and non-Firebug debug: ( commented out for now ) |
25 | | - */ |
26 | | - var log_elm = document.getElementById('mv_js_log'); |
27 | | - if(!log_elm) { |
28 | | - var body = document.getElementsByTagName("body")[0]; |
29 | | - if (body) { |
30 | | - body.innerHTML = document.getElementsByTagName("body")[0].innerHTML + |
31 | | - '<div style="position:absolute;z-index:500;bottom:0px;left:0px;right:0px;height:100px;">'+ |
32 | | - '<textarea id="mv_js_log" cols="120" rows="4"></textarea>'+ |
33 | | - '</div>'; |
34 | | - log_elm = document.getElementById('mv_js_log'); |
35 | | - } else { |
36 | | - mw.logBuffered += string + "\n"; |
37 | | - } |
| 24 | + // Add any prepend debug strings if necessary |
| 25 | + if ( mw.log.preAppendLog ) { |
| 26 | + string = mw.log.preAppendLog + string; |
38 | 27 | } |
39 | | - if(log_elm) { |
40 | | - if (mw.logBuffered.length) { |
41 | | - log_elm.value += mw.logBuffered; |
42 | | - mw.logBuffered = ""; |
| 28 | + |
| 29 | + if ( window.console ) { |
| 30 | + window.console.log( string ); |
| 31 | + } else { |
| 32 | + |
| 33 | + /** |
| 34 | + * Old IE and non-Firebug debug: ( commented out for now ) |
| 35 | + */ |
| 36 | + var log_elm = document.getElementById('mv_js_log'); |
| 37 | + if(!log_elm) { |
| 38 | + var body = document.getElementsByTagName("body")[0]; |
| 39 | + if (body) { |
| 40 | + body.innerHTML = document.getElementsByTagName("body")[0].innerHTML + |
| 41 | + '<div style="position:absolute;z-index:500;bottom:0px;left:0px;right:0px;height:100px;">'+ |
| 42 | + '<textarea id="mv_js_log" cols="120" rows="4"></textarea>'+ |
| 43 | + '</div>'; |
| 44 | + log_elm = document.getElementById('mv_js_log'); |
| 45 | + } else { |
| 46 | + mw.logBuffered += string + "\n"; |
| 47 | + } |
43 | 48 | } |
44 | | - log_elm.value+=string+"\n"; |
| 49 | + if(log_elm) { |
| 50 | + if (mw.logBuffered.length) { |
| 51 | + log_elm.value += mw.logBuffered; |
| 52 | + mw.logBuffered = ""; |
| 53 | + } |
| 54 | + log_elm.value+=string+"\n"; |
| 55 | + } |
| 56 | + |
45 | 57 | } |
46 | | - |
47 | 58 | } |
48 | | -} |
49 | 59 | |
50 | | -mw.logBuffered = ""; |
| 60 | + mw.logBuffered = ""; |
51 | 61 | |
| 62 | +} )( window.mw ); |
| 63 | + |
Index: branches/uploadwizard/extensions/UploadWizard/UploadWizard.php |
— | — | @@ -29,6 +29,7 @@ |
30 | 30 | ); |
31 | 31 | |
32 | 32 | |
| 33 | + |
33 | 34 | $dir = dirname(__FILE__) . '/'; |
34 | 35 | |
35 | 36 | $wgExtensionMessagesFiles['UploadWizard'] = $dir . 'UploadWizard.i18n.php'; |
— | — | @@ -36,6 +37,7 @@ |
37 | 38 | |
38 | 39 | # Require modules, includeing the special page |
39 | 40 | $wgAutoloadLocalClasses[ 'SpecialUploadWizard' ] = $dir . 'SpecialUploadWizard.php'; |
| 41 | +$wgAutoloadLocalClasses[ 'SessionStash' ] = $dir . 'SessionStash.php'; |
40 | 42 | $wgAutoloadLocalClasses[ 'UploadWizardMessages' ] = $dir . 'UploadWizardMessages.php'; |
41 | 43 | |
42 | 44 | # Let the special page be a special center of unique specialness |
— | — | @@ -48,3 +50,5 @@ |
49 | 51 | // Set up the javascript path for the loader and localization file. |
50 | 52 | $wgExtensionJavascriptModules[ 'UploadWizard' ] = 'extensions/UploadWizard'; |
51 | 53 | |
| 54 | + |
| 55 | + |
Index: branches/uploadwizard/extensions/UploadWizard/SessionStash.php |
— | — | @@ -0,0 +1,293 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class SessionStash { |
| 5 | + // repository that this uses to store temp files |
| 6 | + protected $repo; |
| 7 | + |
| 8 | + // array of initialized objects obtained from session (lazily initialized upon getFile()) |
| 9 | + private $files = array(); |
| 10 | + |
| 11 | + const SESSION_VERSION = 2; |
| 12 | + const SESSION_KEYNAME = 'wsUploadData'; |
| 13 | + const SESSION_THUMB_KEYNAME = 'wsUploadDataThumb'; |
| 14 | + |
| 15 | + /** |
| 16 | + * Represents the session which contain temporarily stored files. |
| 17 | + * Designed to be compatible with the session stashing code in UploadBase (should replace eventually) |
| 18 | + * @param {FileRepo} optional -- repo in which to store files. Will choose LocalRepo if not supplied. |
| 19 | + */ |
| 20 | + public function __construct( $repo=null ) { |
| 21 | + |
| 22 | + if ( is_null( $repo ) ) { |
| 23 | + $repo = RepoGroup::singleton()->getLocalRepo(); |
| 24 | + } |
| 25 | + $this->repo = $repo; |
| 26 | + |
| 27 | + if ( ! isset( $_SESSION ) ) { |
| 28 | + throw new MWException( 'session not available' ); |
| 29 | + } |
| 30 | + |
| 31 | + if ( ! array_key_exists( self::SESSION_KEYNAME, $_SESSION ) ) { |
| 32 | + $_SESSION[self::SESSION_KEYNAME] = array(); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + public function getBaseUrl() { |
| 37 | + // XXX do this better |
| 38 | + return '/wiki/Special:SessionStash'; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Get a file from the stash. |
| 43 | + * May throw exception if session data cannot be parsed due to schema change. |
| 44 | + * @param {Integer} key |
| 45 | + * @return {null|SessionStashItem} null if no such item, or the item |
| 46 | + */ |
| 47 | + public function getFile( $key ) { |
| 48 | + if ( !array_key_exists( $key, $this->files ) ) { |
| 49 | + $stashData = $_SESSION[self::SESSION_KEYNAME][$key]; |
| 50 | + |
| 51 | + if ($stashData['version'] !== self::SESSION_VERSION ) { |
| 52 | + throw new MWException( 'session item schema does not match current software' ); |
| 53 | + } |
| 54 | + |
| 55 | + // The path is flattened in with the other random props so we have to dig it out. |
| 56 | + $data = array(); |
| 57 | + foreach( $stashData as $stashKey => $stashVal ) { |
| 58 | + if ( $stashKey === 'mTempPath' ) { |
| 59 | + $path = $stashVal; |
| 60 | + } else { |
| 61 | + $data[ $stashKey ] = $stashVal; |
| 62 | + } |
| 63 | + } |
| 64 | + $this->files[$key] = new SessionStashFile( $this, $this->repo, $path, $key, $data ); |
| 65 | + } |
| 66 | + return $this->files[$key]; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Stash a file in a temp directory and record that we did this in the session, along with other parameters. |
| 71 | + * @param {String} name - this is used for directory hashing when storing. Otherwise not important |
| 72 | + * @param {String} path - path to file you want stashed |
| 73 | + * @param {Array} data - other data you want added to the session. Do not use 'mTempPath', 'mFileProps', 'mFileSize', or version as keys here |
| 74 | + * @return {SessionStashItem} item |
| 75 | + */ |
| 76 | + public function stashFile( $key, $path, $data=array() ) { |
| 77 | + if ( !$key ) { |
| 78 | + $key = mt_rand( 0, 0x7fffffff ); |
| 79 | + } |
| 80 | + |
| 81 | + // if not already in a temporary area, put it there |
| 82 | + $status = $this->repo->storeTemp( basename($path), $path ); |
| 83 | + if( !$status->isOK() ) { |
| 84 | + return false; |
| 85 | + } |
| 86 | + $stashPath = $status->value; |
| 87 | + |
| 88 | + |
| 89 | + // get props |
| 90 | + $fileProps = File::getPropsFromPath( $path ); |
| 91 | + $fileSize = $fileProps['size']; |
| 92 | + |
| 93 | + // standard info we always store. |
| 94 | + // 'mTempPath', 'mFileSize', and 'mFileProps' are arbitrary names |
| 95 | + // chosen for compatibility with UploadBase's way of doing this. |
| 96 | + $stashData = array( |
| 97 | + 'mTempPath' => $stashPath, |
| 98 | + 'mFileSize' => $fileSize, |
| 99 | + 'mFileProps' => $fileProps, |
| 100 | + 'version' => self::SESSION_VERSION |
| 101 | + ); |
| 102 | + |
| 103 | + // put extended info into the session (this changes from application to application). |
| 104 | + // UploadWizard wants different things than say FirefoggChunkedUpload. |
| 105 | + foreach ($data as $stashKey => $stashValue) { |
| 106 | + if ( !array_key_exists( $stashKey, $data ) ) { |
| 107 | + $stashData[$stashKey] = $stashValue; |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + $_SESSION[self::SESSION_KEYNAME][$key] = $stashData; |
| 112 | + |
| 113 | + wfDebug( "SESSION\n=====\n " . print_r( $_SESSION, 1 ) . "\n" ); |
| 114 | + |
| 115 | + return $this->getFile( $key ); |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +class SessionStashFile extends UnregisteredLocalFile { |
| 120 | + public $sessionStash; |
| 121 | + public $sessionKey; |
| 122 | + public $sessionData; |
| 123 | + private $urlName; |
| 124 | + |
| 125 | + /** |
| 126 | + * A LocalFile wrapper around a file that has been temporarily stashed, so we can do things like create thumbnails for it |
| 127 | + * Arguably UnregisteredLocalFile should be handling its own file repo but that class is a bit retarded currently |
| 128 | + * @param {FileRepo} repository where we should find the path |
| 129 | + * @param {String} path to file |
| 130 | + */ |
| 131 | + public function __construct( $stash, $repo, $path, $key, $data ) { |
| 132 | + $this->sessionStash = $stash; |
| 133 | + $this->sessionKey = $key; |
| 134 | + $this->sessionData = $data; |
| 135 | + if ( $repo->isVirtualUrl( $path ) ) { |
| 136 | + $path = $repo->resolveVirtualUrl( $path ); |
| 137 | + } |
| 138 | + parent::__construct( false, $repo, $path, false ); |
| 139 | + |
| 140 | + // we will be initializing from some tmpnam files that don't have extensions. |
| 141 | + // most of MediaWiki assumes all uploaded files have good extensions. So, we fix this. |
| 142 | + $this->name = basename( $this->path ); |
| 143 | + $this->setExtension(); |
| 144 | + |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * A method needed by the file transforming and scaling routines in File.php |
| 149 | + * We do not necessarily care about doing the description at this point |
| 150 | + * @return {String} the empty string |
| 151 | + */ |
| 152 | + public function getDescriptionUrl() { |
| 153 | + return ''; |
| 154 | + } |
| 155 | + |
| 156 | + /** |
| 157 | + * Find or guess extension -- ensuring that our extension matches our mime type. |
| 158 | + * Since these files are constructed from php tempnames they may not start off |
| 159 | + * with an extension |
| 160 | + */ |
| 161 | + public function setExtension() { |
| 162 | + // Does this have an extension? |
| 163 | + $n = strrpos( $this->path, '.' ); |
| 164 | + if ( $n !== false ) { |
| 165 | + $extension = $n ? substr( $this->path, $n + 1 ) : ''; |
| 166 | + } else { |
| 167 | + // If not, assume that it should be related to the mime type of the original file. |
| 168 | + // |
| 169 | + // This entire thing is backwards -- we *should* just create an extension based on |
| 170 | + // the mime type of the transformed file, *after* transformation. But File.php demands |
| 171 | + // to know the name of the transformed file before creating it. |
| 172 | + $mimeType = $this->getMimeType(); |
| 173 | + $extensions = explode( ' ', MimeMagic::singleton()->getExtensionsForType( $mimeType ) ); |
| 174 | + if ( count( $extensions ) ) { |
| 175 | + $extension = $extensions[0]; |
| 176 | + } |
| 177 | + } |
| 178 | + |
| 179 | + if ( is_null( $extension ) ) { |
| 180 | + throw 'cannot determine extension'; |
| 181 | + } |
| 182 | + |
| 183 | + return parent::normalizeExtension( $extension ); |
| 184 | + } |
| 185 | + |
| 186 | + /** |
| 187 | + * Get the path for the thumbnail (actually any transformation of this file) |
| 188 | + * The actual argument is the result of thumbName although we seem to have |
| 189 | + * buggy code elsewhere that expects a boolean 'suffix' |
| 190 | + * |
| 191 | + * @param {String|false} name of thumbnail (e.g. "120px-123456.jpg" ), or false to just get the path |
| 192 | + * @param {String} path thumbnail should take on filesystem, or containing directory if thumbname is false |
| 193 | + */ |
| 194 | + public function getThumbPath( $thumbName=false ) { |
| 195 | + $path = dirname( $this->path ); |
| 196 | + if ( $thumbName !== false ) { |
| 197 | + $path .= "/$thumbName"; |
| 198 | + } |
| 199 | + return $path; |
| 200 | + } |
| 201 | + |
| 202 | + /** |
| 203 | + * Return the file/url base name of a thumbnail with the specified parameters |
| 204 | + * |
| 205 | + * @param {Array} $params: handler-specific parameters |
| 206 | + * @return {String} base name for URL, like '120px-12345.jpg' |
| 207 | + */ |
| 208 | + function thumbName( $params ) { |
| 209 | + if ( !$this->getHandler() ) { |
| 210 | + return null; |
| 211 | + } |
| 212 | + $extension = $this->getExtension(); |
| 213 | + list( $thumbExt, $thumbMime ) = $this->handler->getThumbType( $extension, $this->getMimeType(), $params ); |
| 214 | + $thumbName = $this->handler->makeParamString( $params ) . '-' . $this->getUrlName(); |
| 215 | + if ( $thumbExt != $extension ) { |
| 216 | + $thumbName .= ".$thumbExt"; |
| 217 | + } |
| 218 | + return $thumbName; |
| 219 | + } |
| 220 | + |
| 221 | + /** |
| 222 | + * Get a URL to access the thumbnail |
| 223 | + * This is required because the model of how files work requires that |
| 224 | + * the thumbnail urls be predictable. However, in our model the URL is not based on the filename |
| 225 | + * (that's hidden in the session) |
| 226 | + * |
| 227 | + * @param {String} basename of thumbnail file -- however, we don't want to use the file exactly |
| 228 | + * @return {String} URL to access thumbnail, or URL with partial path |
| 229 | + */ |
| 230 | + public function getThumbUrl( $thumbName=false ) { |
| 231 | + $path = $this->sessionStash->getBaseUrl(); |
| 232 | + $extension = $this->getExtension(); |
| 233 | + if ( $thumbName !== false ) { |
| 234 | + $path .= '/' . rawurlencode( $thumbName ); |
| 235 | + } |
| 236 | + return $path; |
| 237 | + } |
| 238 | + |
| 239 | + /** |
| 240 | + * The basename for the URL, which we want to not be related to the filename. |
| 241 | + * Will also be used as the lookup key for a thumbnail file. |
| 242 | + * @param {Array} optional transformation parameters |
| 243 | + * @return {String} base url name, like '120px-123456.jpg' |
| 244 | + */ |
| 245 | + public function getUrlName() { |
| 246 | + if ( ! $this->urlName ) { |
| 247 | + $this->urlName = $this->sessionKey . '.' . $this->getExtension(); |
| 248 | + } |
| 249 | + return $this->urlName; |
| 250 | + } |
| 251 | + |
| 252 | + /** |
| 253 | + * Return the URL of the file, if for some reason we wanted to download it |
| 254 | + * We tend not to do this for the original file, but we do want thumb icons |
| 255 | + */ |
| 256 | + public function getUrl() { |
| 257 | + if ( !isset( $this->url ) ) { |
| 258 | + $this->url = $this->sessionStash->getBaseUrl() . '/' . $this->getUrlName(); |
| 259 | + } |
| 260 | + return $this->url; |
| 261 | + } |
| 262 | + |
| 263 | + /** |
| 264 | + * Override transform to replace the url with a SessionStash url |
| 265 | + * @param {Array} parameters suitable for File::transform() |
| 266 | + * @param {Bitmask} flags suitable for File::transform() |
| 267 | + * @return {ThumbnailImage} with modified url |
| 268 | + */ |
| 269 | + public function transform( $params, $flags=0 ) { |
| 270 | + |
| 271 | + // force it to get a thumbnail right away |
| 272 | + $flags &= self::RENDER_NOW; |
| 273 | + |
| 274 | + // returns a ThumbnailImage object containing the url and path. Note. NOT A FILE OBJECT. |
| 275 | + $thumb = parent::transform( $params, $flags ); |
| 276 | + |
| 277 | + $key = $this->thumbName($params); |
| 278 | + // remove extension, so it's stored under '120px-123456' |
| 279 | + // this makes it uniform with the other session key for the original, '123456' |
| 280 | + $n = strrpos( $key, '.' ); |
| 281 | + if ( $n !== false ) { |
| 282 | + $key = substr( $key, 0, $n ); |
| 283 | + } |
| 284 | + |
| 285 | + $stashedThumbFile = $this->sessionStash->stashFile( $key, $thumb->path ); |
| 286 | + $thumb->url = $this->sessionStash->getBaseUrl() . '/' . $key . "." . $stashedThumbFile->extension; |
| 287 | + |
| 288 | + return $thumb; |
| 289 | + |
| 290 | + } |
| 291 | + |
| 292 | +} |
| 293 | + |
| 294 | +?> |
Property changes on: branches/uploadwizard/extensions/UploadWizard/SessionStash.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 295 | + native |
Index: branches/uploadwizard/extensions/UploadWizard/SpecialUploadWizard.php |
— | — | @@ -11,6 +11,7 @@ |
12 | 12 | |
13 | 13 | class SpecialUploadWizard extends SpecialPage { |
14 | 14 | |
| 15 | + |
15 | 16 | // $request is the request (usually wgRequest) |
16 | 17 | // $par is everything in the URL after Special:UploadWizard. Not sure what we can use it for |
17 | 18 | public function __construct( $request=null, $par=null ) { |
— | — | @@ -50,7 +51,10 @@ |
51 | 52 | $this->outputHeader(); |
52 | 53 | |
53 | 54 | /* Doing resource loading the old-fashioned way for now until there's some kind of script-loading |
54 | | - strategy that everyone agrees on, or is available generally */ |
| 55 | + strategy that everyone agrees on, or is available generally |
| 56 | + Essentially this list of scripts has to be topologically-sorted by hand, that is, the depended-upon stuff |
| 57 | + comes first. There can be no circular dependencies. |
| 58 | + */ |
55 | 59 | $scripts = array( |
56 | 60 | // jquery is already loaded by vector. |
57 | 61 | // "resources/jquery-1.4.2.js", |
— | — | @@ -62,18 +66,24 @@ |
63 | 67 | |
64 | 68 | // interface helping stuff |
65 | 69 | "resources/jquery/jquery.tipsy.js", |
| 70 | + "resources/jquery/jquery.tipsyPlus.js", |
66 | 71 | "resources/jquery/jquery.morphCrossfade.js", |
67 | 72 | "resources/jquery/jquery.validate.js", |
68 | 73 | "resources/jquery/jquery.arrowSteps.js", |
69 | 74 | "resources/jquery/jquery.mwCoolCats.js", |
70 | 75 | "resources/jquery/jquery.autocomplete.js", |
| 76 | + "resources/jquery/jquery.spinner.js", |
71 | 77 | |
72 | 78 | // our application... |
73 | 79 | |
74 | | - // miscellaneous utilities |
| 80 | + // miscellaneous utilities |
| 81 | + "resources/mw.js", |
| 82 | + "resources/mw.Log.js", |
75 | 83 | "resources/mw.Utilities.js", |
76 | 84 | "resources/mw.UtilitiesTime.js", |
77 | | - "resources/mw.Log.js", |
| 85 | + "resources/mw.Uri.js", |
| 86 | + "resources/mw.Api.js", |
| 87 | + "resources/mw.Api.edit.js", |
78 | 88 | // "resources/mw.MockUploadHandler.js", |
79 | 89 | |
80 | 90 | // message parsing and such |
— | — | @@ -86,6 +96,7 @@ |
87 | 97 | "resources/mw.IframeTransport.js", |
88 | 98 | "resources/mw.ApiUploadHandler.js", |
89 | 99 | "resources/mw.DestinationChecker.js", |
| 100 | + |
90 | 101 | // the thing that does most of it |
91 | 102 | "resources/mw.UploadWizard.js", |
92 | 103 | |
— | — | @@ -122,6 +133,7 @@ |
123 | 134 | |
124 | 135 | // where the uploadwizard will go |
125 | 136 | // TODO import more from UploadWizard itself. |
| 137 | + // "createInterface" call? |
126 | 138 | $wgOut->addHTML( |
127 | 139 | '<div id="upload-licensing" class="upload-section" style="display: none;">Licensing tutorial</div>' |
128 | 140 | . '<div id="upload-wizard" class="upload-section"><div class="loadingSpinner"></div></div>' |
— | — | @@ -234,13 +246,4 @@ |
235 | 247 | |
236 | 248 | } |
237 | 249 | |
238 | | -/* |
239 | | -// XXX UploadWizard extension, do this in the normal SpecialPage way once JS2 issue resolved |
240 | | -function wfSpecialUploadWizard( $par ) { |
241 | | - global $wgRequest; |
242 | | - // can we obtain $request from here? |
243 | | - // $this->loadRequest( is_null( $request ) ? $wgRequest : $request ); |
244 | | - $o = new SpecialUploadWizard( $wgRequest, $par ); |
245 | | - $o->execute(); |
246 | | -} |
247 | | -*/ |
| 250 | + |
Index: branches/uploadwizard/extensions/UploadWizard/UploadWizardPage.js |
— | — | @@ -83,5 +83,9 @@ |
84 | 84 | } |
85 | 85 | |
86 | 86 | $j( document ).ready( function() { |
| 87 | + // sets up plural and so on. Seems like a bad design to have to do this, though. |
| 88 | + mw.Language.magicSetup(); |
| 89 | + |
| 90 | + // show page. |
87 | 91 | mw.UploadWizardPage(); |
88 | 92 | } ); |