jquery.ui.effect.js 31KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  1. /*!
  2. * jQuery UI Effects v1.9 stable
  3. * http://jqueryui.com
  4. *
  5. * Copyright 2012 jQuery Foundation and other contributors
  6. * Released under the MIT license.
  7. * http://jquery.org/license
  8. *
  9. * http://api.jqueryui.com/category/effects-core/
  10. */
  11. ;(jQuery.effects || (function($, undefined) {
  12. var backCompat = $.uiBackCompat !== false,
  13. // prefix used for storing data on .data()
  14. dataSpace = "ui-effects-";
  15. $.effects = {
  16. effect: {}
  17. };
  18. /*!
  19. * jQuery Color Animations v2.1.1
  20. * https://github.com/jquery/jquery-color
  21. *
  22. * Copyright 2012 jQuery Foundation and other contributors
  23. * Released under the MIT license.
  24. * http://jquery.org/license
  25. *
  26. * Date: Sun Oct 28 15:08:06 2012 -0400
  27. */
  28. (function( jQuery, undefined ) {
  29. var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor",
  30. // plusequals test for += 100 -= 100
  31. rplusequals = /^([\-+])=\s*(\d+\.?\d*)/,
  32. // a set of RE's that can match strings and generate color tuples.
  33. stringParsers = [{
  34. re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
  35. parse: function( execResult ) {
  36. return [
  37. execResult[ 1 ],
  38. execResult[ 2 ],
  39. execResult[ 3 ],
  40. execResult[ 4 ]
  41. ];
  42. }
  43. }, {
  44. re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
  45. parse: function( execResult ) {
  46. return [
  47. execResult[ 1 ] * 2.55,
  48. execResult[ 2 ] * 2.55,
  49. execResult[ 3 ] * 2.55,
  50. execResult[ 4 ]
  51. ];
  52. }
  53. }, {
  54. // this regex ignores A-F because it's compared against an already lowercased string
  55. re: /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/,
  56. parse: function( execResult ) {
  57. return [
  58. parseInt( execResult[ 1 ], 16 ),
  59. parseInt( execResult[ 2 ], 16 ),
  60. parseInt( execResult[ 3 ], 16 )
  61. ];
  62. }
  63. }, {
  64. // this regex ignores A-F because it's compared against an already lowercased string
  65. re: /#([a-f0-9])([a-f0-9])([a-f0-9])/,
  66. parse: function( execResult ) {
  67. return [
  68. parseInt( execResult[ 1 ] + execResult[ 1 ], 16 ),
  69. parseInt( execResult[ 2 ] + execResult[ 2 ], 16 ),
  70. parseInt( execResult[ 3 ] + execResult[ 3 ], 16 )
  71. ];
  72. }
  73. }, {
  74. re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,
  75. space: "hsla",
  76. parse: function( execResult ) {
  77. return [
  78. execResult[ 1 ],
  79. execResult[ 2 ] / 100,
  80. execResult[ 3 ] / 100,
  81. execResult[ 4 ]
  82. ];
  83. }
  84. }],
  85. // jQuery.Color( )
  86. color = jQuery.Color = function( color, green, blue, alpha ) {
  87. return new jQuery.Color.fn.parse( color, green, blue, alpha );
  88. },
  89. spaces = {
  90. rgba: {
  91. props: {
  92. red: {
  93. idx: 0,
  94. type: "byte"
  95. },
  96. green: {
  97. idx: 1,
  98. type: "byte"
  99. },
  100. blue: {
  101. idx: 2,
  102. type: "byte"
  103. }
  104. }
  105. },
  106. hsla: {
  107. props: {
  108. hue: {
  109. idx: 0,
  110. type: "degrees"
  111. },
  112. saturation: {
  113. idx: 1,
  114. type: "percent"
  115. },
  116. lightness: {
  117. idx: 2,
  118. type: "percent"
  119. }
  120. }
  121. }
  122. },
  123. propTypes = {
  124. "byte": {
  125. floor: true,
  126. max: 255
  127. },
  128. "percent": {
  129. max: 1
  130. },
  131. "degrees": {
  132. mod: 360,
  133. floor: true
  134. }
  135. },
  136. support = color.support = {},
  137. // element for support tests
  138. supportElem = jQuery( "<p>" )[ 0 ],
  139. // colors = jQuery.Color.names
  140. colors,
  141. // local aliases of functions called often
  142. each = jQuery.each;
  143. // determine rgba support immediately
  144. supportElem.style.cssText = "background-color:rgba(1,1,1,.5)";
  145. support.rgba = supportElem.style.backgroundColor.indexOf( "rgba" ) > -1;
  146. // define cache name and alpha properties
  147. // for rgba and hsla spaces
  148. each( spaces, function( spaceName, space ) {
  149. space.cache = "_" + spaceName;
  150. space.props.alpha = {
  151. idx: 3,
  152. type: "percent",
  153. def: 1
  154. };
  155. });
  156. function clamp( value, prop, allowEmpty ) {
  157. var type = propTypes[ prop.type ] || {};
  158. if ( value == null ) {
  159. return (allowEmpty || !prop.def) ? null : prop.def;
  160. }
  161. // ~~ is an short way of doing floor for positive numbers
  162. value = type.floor ? ~~value : parseFloat( value );
  163. // IE will pass in empty strings as value for alpha,
  164. // which will hit this case
  165. if ( isNaN( value ) ) {
  166. return prop.def;
  167. }
  168. if ( type.mod ) {
  169. // we add mod before modding to make sure that negatives values
  170. // get converted properly: -10 -> 350
  171. return (value + type.mod) % type.mod;
  172. }
  173. // for now all property types without mod have min and max
  174. return 0 > value ? 0 : type.max < value ? type.max : value;
  175. }
  176. function stringParse( string ) {
  177. var inst = color(),
  178. rgba = inst._rgba = [];
  179. string = string.toLowerCase();
  180. each( stringParsers, function( i, parser ) {
  181. var parsed,
  182. match = parser.re.exec( string ),
  183. values = match && parser.parse( match ),
  184. spaceName = parser.space || "rgba";
  185. if ( values ) {
  186. parsed = inst[ spaceName ]( values );
  187. // if this was an rgba parse the assignment might happen twice
  188. // oh well....
  189. inst[ spaces[ spaceName ].cache ] = parsed[ spaces[ spaceName ].cache ];
  190. rgba = inst._rgba = parsed._rgba;
  191. // exit each( stringParsers ) here because we matched
  192. return false;
  193. }
  194. });
  195. // Found a stringParser that handled it
  196. if ( rgba.length ) {
  197. // if this came from a parsed string, force "transparent" when alpha is 0
  198. // chrome, (and maybe others) return "transparent" as rgba(0,0,0,0)
  199. if ( rgba.join() === "0,0,0,0" ) {
  200. jQuery.extend( rgba, colors.transparent );
  201. }
  202. return inst;
  203. }
  204. // named colors
  205. return colors[ string ];
  206. }
  207. color.fn = jQuery.extend( color.prototype, {
  208. parse: function( red, green, blue, alpha ) {
  209. if ( red === undefined ) {
  210. this._rgba = [ null, null, null, null ];
  211. return this;
  212. }
  213. if ( red.jquery || red.nodeType ) {
  214. red = jQuery( red ).css( green );
  215. green = undefined;
  216. }
  217. var inst = this,
  218. type = jQuery.type( red ),
  219. rgba = this._rgba = [];
  220. // more than 1 argument specified - assume ( red, green, blue, alpha )
  221. if ( green !== undefined ) {
  222. red = [ red, green, blue, alpha ];
  223. type = "array";
  224. }
  225. if ( type === "string" ) {
  226. return this.parse( stringParse( red ) || colors._default );
  227. }
  228. if ( type === "array" ) {
  229. each( spaces.rgba.props, function( key, prop ) {
  230. rgba[ prop.idx ] = clamp( red[ prop.idx ], prop );
  231. });
  232. return this;
  233. }
  234. if ( type === "object" ) {
  235. if ( red instanceof color ) {
  236. each( spaces, function( spaceName, space ) {
  237. if ( red[ space.cache ] ) {
  238. inst[ space.cache ] = red[ space.cache ].slice();
  239. }
  240. });
  241. } else {
  242. each( spaces, function( spaceName, space ) {
  243. var cache = space.cache;
  244. each( space.props, function( key, prop ) {
  245. // if the cache doesn't exist, and we know how to convert
  246. if ( !inst[ cache ] && space.to ) {
  247. // if the value was null, we don't need to copy it
  248. // if the key was alpha, we don't need to copy it either
  249. if ( key === "alpha" || red[ key ] == null ) {
  250. return;
  251. }
  252. inst[ cache ] = space.to( inst._rgba );
  253. }
  254. // this is the only case where we allow nulls for ALL properties.
  255. // call clamp with alwaysAllowEmpty
  256. inst[ cache ][ prop.idx ] = clamp( red[ key ], prop, true );
  257. });
  258. // everything defined but alpha?
  259. if ( inst[ cache ] && jQuery.inArray( null, inst[ cache ].slice( 0, 3 ) ) < 0 ) {
  260. // use the default of 1
  261. inst[ cache ][ 3 ] = 1;
  262. if ( space.from ) {
  263. inst._rgba = space.from( inst[ cache ] );
  264. }
  265. }
  266. });
  267. }
  268. return this;
  269. }
  270. },
  271. is: function( compare ) {
  272. var is = color( compare ),
  273. same = true,
  274. inst = this;
  275. each( spaces, function( _, space ) {
  276. var localCache,
  277. isCache = is[ space.cache ];
  278. if (isCache) {
  279. localCache = inst[ space.cache ] || space.to && space.to( inst._rgba ) || [];
  280. each( space.props, function( _, prop ) {
  281. if ( isCache[ prop.idx ] != null ) {
  282. same = ( isCache[ prop.idx ] === localCache[ prop.idx ] );
  283. return same;
  284. }
  285. });
  286. }
  287. return same;
  288. });
  289. return same;
  290. },
  291. _space: function() {
  292. var used = [],
  293. inst = this;
  294. each( spaces, function( spaceName, space ) {
  295. if ( inst[ space.cache ] ) {
  296. used.push( spaceName );
  297. }
  298. });
  299. return used.pop();
  300. },
  301. transition: function( other, distance ) {
  302. var end = color( other ),
  303. spaceName = end._space(),
  304. space = spaces[ spaceName ],
  305. startColor = this.alpha() === 0 ? color( "transparent" ) : this,
  306. start = startColor[ space.cache ] || space.to( startColor._rgba ),
  307. result = start.slice();
  308. end = end[ space.cache ];
  309. each( space.props, function( key, prop ) {
  310. var index = prop.idx,
  311. startValue = start[ index ],
  312. endValue = end[ index ],
  313. type = propTypes[ prop.type ] || {};
  314. // if null, don't override start value
  315. if ( endValue === null ) {
  316. return;
  317. }
  318. // if null - use end
  319. if ( startValue === null ) {
  320. result[ index ] = endValue;
  321. } else {
  322. if ( type.mod ) {
  323. if ( endValue - startValue > type.mod / 2 ) {
  324. startValue += type.mod;
  325. } else if ( startValue - endValue > type.mod / 2 ) {
  326. startValue -= type.mod;
  327. }
  328. }
  329. result[ index ] = clamp( ( endValue - startValue ) * distance + startValue, prop );
  330. }
  331. });
  332. return this[ spaceName ]( result );
  333. },
  334. blend: function( opaque ) {
  335. // if we are already opaque - return ourself
  336. if ( this._rgba[ 3 ] === 1 ) {
  337. return this;
  338. }
  339. var rgb = this._rgba.slice(),
  340. a = rgb.pop(),
  341. blend = color( opaque )._rgba;
  342. return color( jQuery.map( rgb, function( v, i ) {
  343. return ( 1 - a ) * blend[ i ] + a * v;
  344. }));
  345. },
  346. toRgbaString: function() {
  347. var prefix = "rgba(",
  348. rgba = jQuery.map( this._rgba, function( v, i ) {
  349. return v == null ? ( i > 2 ? 1 : 0 ) : v;
  350. });
  351. if ( rgba[ 3 ] === 1 ) {
  352. rgba.pop();
  353. prefix = "rgb(";
  354. }
  355. return prefix + rgba.join() + ")";
  356. },
  357. toHslaString: function() {
  358. var prefix = "hsla(",
  359. hsla = jQuery.map( this.hsla(), function( v, i ) {
  360. if ( v == null ) {
  361. v = i > 2 ? 1 : 0;
  362. }
  363. // catch 1 and 2
  364. if ( i && i < 3 ) {
  365. v = Math.round( v * 100 ) + "%";
  366. }
  367. return v;
  368. });
  369. if ( hsla[ 3 ] === 1 ) {
  370. hsla.pop();
  371. prefix = "hsl(";
  372. }
  373. return prefix + hsla.join() + ")";
  374. },
  375. toHexString: function( includeAlpha ) {
  376. var rgba = this._rgba.slice(),
  377. alpha = rgba.pop();
  378. if ( includeAlpha ) {
  379. rgba.push( ~~( alpha * 255 ) );
  380. }
  381. return "#" + jQuery.map( rgba, function( v ) {
  382. // default to 0 when nulls exist
  383. v = ( v || 0 ).toString( 16 );
  384. return v.length === 1 ? "0" + v : v;
  385. }).join("");
  386. },
  387. toString: function() {
  388. return this._rgba[ 3 ] === 0 ? "transparent" : this.toRgbaString();
  389. }
  390. });
  391. color.fn.parse.prototype = color.fn;
  392. // hsla conversions adapted from:
  393. // https://code.google.com/p/maashaack/source/browse/packages/graphics/trunk/src/graphics/colors/HUE2RGB.as?r=5021
  394. function hue2rgb( p, q, h ) {
  395. h = ( h + 1 ) % 1;
  396. if ( h * 6 < 1 ) {
  397. return p + (q - p) * h * 6;
  398. }
  399. if ( h * 2 < 1) {
  400. return q;
  401. }
  402. if ( h * 3 < 2 ) {
  403. return p + (q - p) * ((2/3) - h) * 6;
  404. }
  405. return p;
  406. }
  407. spaces.hsla.to = function ( rgba ) {
  408. if ( rgba[ 0 ] == null || rgba[ 1 ] == null || rgba[ 2 ] == null ) {
  409. return [ null, null, null, rgba[ 3 ] ];
  410. }
  411. var r = rgba[ 0 ] / 255,
  412. g = rgba[ 1 ] / 255,
  413. b = rgba[ 2 ] / 255,
  414. a = rgba[ 3 ],
  415. max = Math.max( r, g, b ),
  416. min = Math.min( r, g, b ),
  417. diff = max - min,
  418. add = max + min,
  419. l = add * 0.5,
  420. h, s;
  421. if ( min === max ) {
  422. h = 0;
  423. } else if ( r === max ) {
  424. h = ( 60 * ( g - b ) / diff ) + 360;
  425. } else if ( g === max ) {
  426. h = ( 60 * ( b - r ) / diff ) + 120;
  427. } else {
  428. h = ( 60 * ( r - g ) / diff ) + 240;
  429. }
  430. // chroma (diff) == 0 means greyscale which, by definition, saturation = 0%
  431. // otherwise, saturation is based on the ratio of chroma (diff) to lightness (add)
  432. if ( diff === 0 ) {
  433. s = 0;
  434. } else if ( l <= 0.5 ) {
  435. s = diff / add;
  436. } else {
  437. s = diff / ( 2 - add );
  438. }
  439. return [ Math.round(h) % 360, s, l, a == null ? 1 : a ];
  440. };
  441. spaces.hsla.from = function ( hsla ) {
  442. if ( hsla[ 0 ] == null || hsla[ 1 ] == null || hsla[ 2 ] == null ) {
  443. return [ null, null, null, hsla[ 3 ] ];
  444. }
  445. var h = hsla[ 0 ] / 360,
  446. s = hsla[ 1 ],
  447. l = hsla[ 2 ],
  448. a = hsla[ 3 ],
  449. q = l <= 0.5 ? l * ( 1 + s ) : l + s - l * s,
  450. p = 2 * l - q;
  451. return [
  452. Math.round( hue2rgb( p, q, h + ( 1 / 3 ) ) * 255 ),
  453. Math.round( hue2rgb( p, q, h ) * 255 ),
  454. Math.round( hue2rgb( p, q, h - ( 1 / 3 ) ) * 255 ),
  455. a
  456. ];
  457. };
  458. each( spaces, function( spaceName, space ) {
  459. var props = space.props,
  460. cache = space.cache,
  461. to = space.to,
  462. from = space.from;
  463. // makes rgba() and hsla()
  464. color.fn[ spaceName ] = function( value ) {
  465. // generate a cache for this space if it doesn't exist
  466. if ( to && !this[ cache ] ) {
  467. this[ cache ] = to( this._rgba );
  468. }
  469. if ( value === undefined ) {
  470. return this[ cache ].slice();
  471. }
  472. var ret,
  473. type = jQuery.type( value ),
  474. arr = ( type === "array" || type === "object" ) ? value : arguments,
  475. local = this[ cache ].slice();
  476. each( props, function( key, prop ) {
  477. var val = arr[ type === "object" ? key : prop.idx ];
  478. if ( val == null ) {
  479. val = local[ prop.idx ];
  480. }
  481. local[ prop.idx ] = clamp( val, prop );
  482. });
  483. if ( from ) {
  484. ret = color( from( local ) );
  485. ret[ cache ] = local;
  486. return ret;
  487. } else {
  488. return color( local );
  489. }
  490. };
  491. // makes red() green() blue() alpha() hue() saturation() lightness()
  492. each( props, function( key, prop ) {
  493. // alpha is included in more than one space
  494. if ( color.fn[ key ] ) {
  495. return;
  496. }
  497. color.fn[ key ] = function( value ) {
  498. var vtype = jQuery.type( value ),
  499. fn = ( key === "alpha" ? ( this._hsla ? "hsla" : "rgba" ) : spaceName ),
  500. local = this[ fn ](),
  501. cur = local[ prop.idx ],
  502. match;
  503. if ( vtype === "undefined" ) {
  504. return cur;
  505. }
  506. if ( vtype === "function" ) {
  507. value = value.call( this, cur );
  508. vtype = jQuery.type( value );
  509. }
  510. if ( value == null && prop.empty ) {
  511. return this;
  512. }
  513. if ( vtype === "string" ) {
  514. match = rplusequals.exec( value );
  515. if ( match ) {
  516. value = cur + parseFloat( match[ 2 ] ) * ( match[ 1 ] === "+" ? 1 : -1 );
  517. }
  518. }
  519. local[ prop.idx ] = value;
  520. return this[ fn ]( local );
  521. };
  522. });
  523. });
  524. // add cssHook and .fx.step function for each named hook.
  525. // accept a space separated string of properties
  526. color.hook = function( hook ) {
  527. var hooks = hook.split( " " );
  528. each( hooks, function( i, hook ) {
  529. jQuery.cssHooks[ hook ] = {
  530. set: function( elem, value ) {
  531. var parsed, curElem,
  532. backgroundColor = "";
  533. if ( jQuery.type( value ) !== "string" || ( parsed = stringParse( value ) ) ) {
  534. value = color( parsed || value );
  535. if ( !support.rgba && value._rgba[ 3 ] !== 1 ) {
  536. curElem = hook === "backgroundColor" ? elem.parentNode : elem;
  537. while (
  538. (backgroundColor === "" || backgroundColor === "transparent") &&
  539. curElem && curElem.style
  540. ) {
  541. try {
  542. backgroundColor = jQuery.css( curElem, "backgroundColor" );
  543. curElem = curElem.parentNode;
  544. } catch ( e ) {
  545. }
  546. }
  547. value = value.blend( backgroundColor && backgroundColor !== "transparent" ?
  548. backgroundColor :
  549. "_default" );
  550. }
  551. value = value.toRgbaString();
  552. }
  553. try {
  554. elem.style[ hook ] = value;
  555. } catch( e ) {
  556. // wrapped to prevent IE from throwing errors on "invalid" values like 'auto' or 'inherit'
  557. }
  558. }
  559. };
  560. jQuery.fx.step[ hook ] = function( fx ) {
  561. if ( !fx.colorInit ) {
  562. fx.start = color( fx.elem, hook );
  563. fx.end = color( fx.end );
  564. fx.colorInit = true;
  565. }
  566. jQuery.cssHooks[ hook ].set( fx.elem, fx.start.transition( fx.end, fx.pos ) );
  567. };
  568. });
  569. };
  570. color.hook( stepHooks );
  571. jQuery.cssHooks.borderColor = {
  572. expand: function( value ) {
  573. var expanded = {};
  574. each( [ "Top", "Right", "Bottom", "Left" ], function( i, part ) {
  575. expanded[ "border" + part + "Color" ] = value;
  576. });
  577. return expanded;
  578. }
  579. };
  580. // Basic color names only.
  581. // Usage of any of the other color names requires adding yourself or including
  582. // jquery.color.svg-names.js.
  583. colors = jQuery.Color.names = {
  584. // 4.1. Basic color keywords
  585. aqua: "#00ffff",
  586. black: "#000000",
  587. blue: "#0000ff",
  588. fuchsia: "#ff00ff",
  589. gray: "#808080",
  590. green: "#008000",
  591. lime: "#00ff00",
  592. maroon: "#800000",
  593. navy: "#000080",
  594. olive: "#808000",
  595. purple: "#800080",
  596. red: "#ff0000",
  597. silver: "#c0c0c0",
  598. teal: "#008080",
  599. white: "#ffffff",
  600. yellow: "#ffff00",
  601. // 4.2.3. "transparent" color keyword
  602. transparent: [ null, null, null, 0 ],
  603. _default: "#ffffff"
  604. };
  605. })( jQuery );
  606. /******************************************************************************/
  607. /****************************** CLASS ANIMATIONS ******************************/
  608. /******************************************************************************/
  609. (function() {
  610. var classAnimationActions = [ "add", "remove", "toggle" ],
  611. shorthandStyles = {
  612. border: 1,
  613. borderBottom: 1,
  614. borderColor: 1,
  615. borderLeft: 1,
  616. borderRight: 1,
  617. borderTop: 1,
  618. borderWidth: 1,
  619. margin: 1,
  620. padding: 1
  621. };
  622. $.each([ "borderLeftStyle", "borderRightStyle", "borderBottomStyle", "borderTopStyle" ], function( _, prop ) {
  623. $.fx.step[ prop ] = function( fx ) {
  624. if ( fx.end !== "none" && !fx.setAttr || fx.pos === 1 && !fx.setAttr ) {
  625. jQuery.style( fx.elem, prop, fx.end );
  626. fx.setAttr = true;
  627. }
  628. };
  629. });
  630. function getElementStyles() {
  631. var style = this.ownerDocument.defaultView ?
  632. this.ownerDocument.defaultView.getComputedStyle( this, null ) :
  633. this.currentStyle,
  634. newStyle = {},
  635. key,
  636. len;
  637. // webkit enumerates style porperties
  638. if ( style && style.length && style[ 0 ] && style[ style[ 0 ] ] ) {
  639. len = style.length;
  640. while ( len-- ) {
  641. key = style[ len ];
  642. if ( typeof style[ key ] === "string" ) {
  643. newStyle[ $.camelCase( key ) ] = style[ key ];
  644. }
  645. }
  646. } else {
  647. for ( key in style ) {
  648. if ( typeof style[ key ] === "string" ) {
  649. newStyle[ key ] = style[ key ];
  650. }
  651. }
  652. }
  653. return newStyle;
  654. }
  655. function styleDifference( oldStyle, newStyle ) {
  656. var diff = {},
  657. name, value;
  658. for ( name in newStyle ) {
  659. value = newStyle[ name ];
  660. if ( oldStyle[ name ] !== value ) {
  661. if ( !shorthandStyles[ name ] ) {
  662. if ( $.fx.step[ name ] || !isNaN( parseFloat( value ) ) ) {
  663. diff[ name ] = value;
  664. }
  665. }
  666. }
  667. }
  668. return diff;
  669. }
  670. $.effects.animateClass = function( value, duration, easing, callback ) {
  671. var o = $.speed( duration, easing, callback );
  672. return this.queue( function() {
  673. var animated = $( this ),
  674. baseClass = animated.attr( "class" ) || "",
  675. applyClassChange,
  676. allAnimations = o.children ? animated.find( "*" ).andSelf() : animated;
  677. // map the animated objects to store the original styles.
  678. allAnimations = allAnimations.map(function() {
  679. var el = $( this );
  680. return {
  681. el: el,
  682. start: getElementStyles.call( this )
  683. };
  684. });
  685. // apply class change
  686. applyClassChange = function() {
  687. $.each( classAnimationActions, function(i, action) {
  688. if ( value[ action ] ) {
  689. animated[ action + "Class" ]( value[ action ] );
  690. }
  691. });
  692. };
  693. applyClassChange();
  694. // map all animated objects again - calculate new styles and diff
  695. allAnimations = allAnimations.map(function() {
  696. this.end = getElementStyles.call( this.el[ 0 ] );
  697. this.diff = styleDifference( this.start, this.end );
  698. return this;
  699. });
  700. // apply original class
  701. animated.attr( "class", baseClass );
  702. // map all animated objects again - this time collecting a promise
  703. allAnimations = allAnimations.map(function() {
  704. var styleInfo = this,
  705. dfd = $.Deferred(),
  706. opts = jQuery.extend({}, o, {
  707. queue: false,
  708. complete: function() {
  709. dfd.resolve( styleInfo );
  710. }
  711. });
  712. this.el.animate( this.diff, opts );
  713. return dfd.promise();
  714. });
  715. // once all animations have completed:
  716. $.when.apply( $, allAnimations.get() ).done(function() {
  717. // set the final class
  718. applyClassChange();
  719. // for each animated element,
  720. // clear all css properties that were animated
  721. $.each( arguments, function() {
  722. var el = this.el;
  723. $.each( this.diff, function(key) {
  724. el.css( key, '' );
  725. });
  726. });
  727. // this is guarnteed to be there if you use jQuery.speed()
  728. // it also handles dequeuing the next anim...
  729. o.complete.call( animated[ 0 ] );
  730. });
  731. });
  732. };
  733. $.fn.extend({
  734. _addClass: $.fn.addClass,
  735. addClass: function( classNames, speed, easing, callback ) {
  736. return speed ?
  737. $.effects.animateClass.call( this,
  738. { add: classNames }, speed, easing, callback ) :
  739. this._addClass( classNames );
  740. },
  741. _removeClass: $.fn.removeClass,
  742. removeClass: function( classNames, speed, easing, callback ) {
  743. return speed ?
  744. $.effects.animateClass.call( this,
  745. { remove: classNames }, speed, easing, callback ) :
  746. this._removeClass( classNames );
  747. },
  748. _toggleClass: $.fn.toggleClass,
  749. toggleClass: function( classNames, force, speed, easing, callback ) {
  750. if ( typeof force === "boolean" || force === undefined ) {
  751. if ( !speed ) {
  752. // without speed parameter
  753. return this._toggleClass( classNames, force );
  754. } else {
  755. return $.effects.animateClass.call( this,
  756. (force ? { add: classNames } : { remove: classNames }),
  757. speed, easing, callback );
  758. }
  759. } else {
  760. // without force parameter
  761. return $.effects.animateClass.call( this,
  762. { toggle: classNames }, force, speed, easing );
  763. }
  764. },
  765. switchClass: function( remove, add, speed, easing, callback) {
  766. return $.effects.animateClass.call( this, {
  767. add: add,
  768. remove: remove
  769. }, speed, easing, callback );
  770. }
  771. });
  772. })();
  773. /******************************************************************************/
  774. /*********************************** EFFECTS **********************************/
  775. /******************************************************************************/
  776. (function() {
  777. $.extend( $.effects, {
  778. version: "@VERSION",
  779. // Saves a set of properties in a data storage
  780. save: function( element, set ) {
  781. for( var i=0; i < set.length; i++ ) {
  782. if ( set[ i ] !== null ) {
  783. element.data( dataSpace + set[ i ], element[ 0 ].style[ set[ i ] ] );
  784. }
  785. }
  786. },
  787. // Restores a set of previously saved properties from a data storage
  788. restore: function( element, set ) {
  789. var val, i;
  790. for( i=0; i < set.length; i++ ) {
  791. if ( set[ i ] !== null ) {
  792. val = element.data( dataSpace + set[ i ] );
  793. // support: jQuery 1.6.2
  794. // http://bugs.jquery.com/ticket/9917
  795. // jQuery 1.6.2 incorrectly returns undefined for any falsy value.
  796. // We can't differentiate between "" and 0 here, so we just assume
  797. // empty string since it's likely to be a more common value...
  798. if ( val === undefined ) {
  799. val = "";
  800. }
  801. element.css( set[ i ], val );
  802. }
  803. }
  804. },
  805. setMode: function( el, mode ) {
  806. if (mode === "toggle") {
  807. mode = el.is( ":hidden" ) ? "show" : "hide";
  808. }
  809. return mode;
  810. },
  811. // Translates a [top,left] array into a baseline value
  812. // this should be a little more flexible in the future to handle a string & hash
  813. getBaseline: function( origin, original ) {
  814. var y, x;
  815. switch ( origin[ 0 ] ) {
  816. case "top": y = 0; break;
  817. case "middle": y = 0.5; break;
  818. case "bottom": y = 1; break;
  819. default: y = origin[ 0 ] / original.height;
  820. }
  821. switch ( origin[ 1 ] ) {
  822. case "left": x = 0; break;
  823. case "center": x = 0.5; break;
  824. case "right": x = 1; break;
  825. default: x = origin[ 1 ] / original.width;
  826. }
  827. return {
  828. x: x,
  829. y: y
  830. };
  831. },
  832. // Wraps the element around a wrapper that copies position properties
  833. createWrapper: function( element ) {
  834. // if the element is already wrapped, return it
  835. if ( element.parent().is( ".ui-effects-wrapper" )) {
  836. return element.parent();
  837. }
  838. // wrap the element
  839. var props = {
  840. width: element.outerWidth(true),
  841. height: element.outerHeight(true),
  842. "float": element.css( "float" )
  843. },
  844. wrapper = $( "<div></div>" )
  845. .addClass( "ui-effects-wrapper" )
  846. .css({
  847. fontSize: "100%",
  848. background: "transparent",
  849. border: "none",
  850. margin: 0,
  851. padding: 0
  852. }),
  853. // Store the size in case width/height are defined in % - Fixes #5245
  854. size = {
  855. width: element.width(),
  856. height: element.height()
  857. },
  858. active = document.activeElement;
  859. // support: Firefox
  860. // Firefox incorrectly exposes anonymous content
  861. // https://bugzilla.mozilla.org/show_bug.cgi?id=561664
  862. try {
  863. active.id;
  864. } catch( e ) {
  865. active = document.body;
  866. }
  867. element.wrap( wrapper );
  868. // Fixes #7595 - Elements lose focus when wrapped.
  869. if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
  870. $( active ).focus();
  871. }
  872. wrapper = element.parent(); //Hotfix for jQuery 1.4 since some change in wrap() seems to actually lose the reference to the wrapped element
  873. // transfer positioning properties to the wrapper
  874. if ( element.css( "position" ) === "static" ) {
  875. wrapper.css({ position: "relative" });
  876. element.css({ position: "relative" });
  877. } else {
  878. $.extend( props, {
  879. position: element.css( "position" ),
  880. zIndex: element.css( "z-index" )
  881. });
  882. $.each([ "top", "left", "bottom", "right" ], function(i, pos) {
  883. props[ pos ] = element.css( pos );
  884. if ( isNaN( parseInt( props[ pos ], 10 ) ) ) {
  885. props[ pos ] = "auto";
  886. }
  887. });
  888. element.css({
  889. position: "relative",
  890. top: 0,
  891. left: 0,
  892. right: "auto",
  893. bottom: "auto"
  894. });
  895. }
  896. element.css(size);
  897. return wrapper.css( props ).show();
  898. },
  899. removeWrapper: function( element ) {
  900. var active = document.activeElement;
  901. if ( element.parent().is( ".ui-effects-wrapper" ) ) {
  902. element.parent().replaceWith( element );
  903. // Fixes #7595 - Elements lose focus when wrapped.
  904. if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
  905. $( active ).focus();
  906. }
  907. }
  908. return element;
  909. },
  910. setTransition: function( element, list, factor, value ) {
  911. value = value || {};
  912. $.each( list, function( i, x ) {
  913. var unit = element.cssUnit( x );
  914. if ( unit[ 0 ] > 0 ) {
  915. value[ x ] = unit[ 0 ] * factor + unit[ 1 ];
  916. }
  917. });
  918. return value;
  919. }
  920. });
  921. // return an effect options object for the given parameters:
  922. function _normalizeArguments( effect, options, speed, callback ) {
  923. // allow passing all options as the first parameter
  924. if ( $.isPlainObject( effect ) ) {
  925. options = effect;
  926. effect = effect.effect;
  927. }
  928. // convert to an object
  929. effect = { effect: effect };
  930. // catch (effect, null, ...)
  931. if ( options == null ) {
  932. options = {};
  933. }
  934. // catch (effect, callback)
  935. if ( $.isFunction( options ) ) {
  936. callback = options;
  937. speed = null;
  938. options = {};
  939. }
  940. // catch (effect, speed, ?)
  941. if ( typeof options === "number" || $.fx.speeds[ options ] ) {
  942. callback = speed;
  943. speed = options;
  944. options = {};
  945. }
  946. // catch (effect, options, callback)
  947. if ( $.isFunction( speed ) ) {
  948. callback = speed;
  949. speed = null;
  950. }
  951. // add options to effect
  952. if ( options ) {
  953. $.extend( effect, options );
  954. }
  955. speed = speed || options.duration;
  956. effect.duration = $.fx.off ? 0 :
  957. typeof speed === "number" ? speed :
  958. speed in $.fx.speeds ? $.fx.speeds[ speed ] :
  959. $.fx.speeds._default;
  960. effect.complete = callback || options.complete;
  961. return effect;
  962. }
  963. function standardSpeed( speed ) {
  964. // valid standard speeds
  965. if ( !speed || typeof speed === "number" || $.fx.speeds[ speed ] ) {
  966. return true;
  967. }
  968. // invalid strings - treat as "normal" speed
  969. if ( typeof speed === "string" && !$.effects.effect[ speed ] ) {
  970. // TODO: remove in 2.0 (#7115)
  971. if ( backCompat && $.effects[ speed ] ) {
  972. return false;
  973. }
  974. return true;
  975. }
  976. return false;
  977. }
  978. $.fn.extend({
  979. effect: function( /* effect, options, speed, callback */ ) {
  980. var args = _normalizeArguments.apply( this, arguments ),
  981. mode = args.mode,
  982. queue = args.queue,
  983. effectMethod = $.effects.effect[ args.effect ],
  984. // DEPRECATED: remove in 2.0 (#7115)
  985. oldEffectMethod = !effectMethod && backCompat && $.effects[ args.effect ];
  986. if ( $.fx.off || !( effectMethod || oldEffectMethod ) ) {
  987. // delegate to the original method (e.g., .show()) if possible
  988. if ( mode ) {
  989. return this[ mode ]( args.duration, args.complete );
  990. } else {
  991. return this.each( function() {
  992. if ( args.complete ) {
  993. args.complete.call( this );
  994. }
  995. });
  996. }
  997. }
  998. function run( next ) {
  999. var elem = $( this ),
  1000. complete = args.complete,
  1001. mode = args.mode;
  1002. function done() {
  1003. if ( $.isFunction( complete ) ) {
  1004. complete.call( elem[0] );
  1005. }
  1006. if ( $.isFunction( next ) ) {
  1007. next();
  1008. }
  1009. }
  1010. // if the element is hiddden and mode is hide,
  1011. // or element is visible and mode is show
  1012. if ( elem.is( ":hidden" ) ? mode === "hide" : mode === "show" ) {
  1013. done();
  1014. } else {
  1015. effectMethod.call( elem[0], args, done );
  1016. }
  1017. }
  1018. // TODO: remove this check in 2.0, effectMethod will always be true
  1019. if ( effectMethod ) {
  1020. return queue === false ? this.each( run ) : this.queue( queue || "fx", run );
  1021. } else {
  1022. // DEPRECATED: remove in 2.0 (#7115)
  1023. return oldEffectMethod.call(this, {
  1024. options: args,
  1025. duration: args.duration,
  1026. callback: args.complete,
  1027. mode: args.mode
  1028. });
  1029. }
  1030. },
  1031. _show: $.fn.show,
  1032. show: function( speed ) {
  1033. if ( standardSpeed( speed ) ) {
  1034. return this._show.apply( this, arguments );
  1035. } else {
  1036. var args = _normalizeArguments.apply( this, arguments );
  1037. args.mode = "show";
  1038. return this.effect.call( this, args );
  1039. }
  1040. },
  1041. _hide: $.fn.hide,
  1042. hide: function( speed ) {
  1043. if ( standardSpeed( speed ) ) {
  1044. return this._hide.apply( this, arguments );
  1045. } else {
  1046. var args = _normalizeArguments.apply( this, arguments );
  1047. args.mode = "hide";
  1048. return this.effect.call( this, args );
  1049. }
  1050. },
  1051. // jQuery core overloads toggle and creates _toggle
  1052. __toggle: $.fn.toggle,
  1053. toggle: function( speed ) {
  1054. if ( standardSpeed( speed ) || typeof speed === "boolean" || $.isFunction( speed ) ) {
  1055. return this.__toggle.apply( this, arguments );
  1056. } else {
  1057. var args = _normalizeArguments.apply( this, arguments );
  1058. args.mode = "toggle";
  1059. return this.effect.call( this, args );
  1060. }
  1061. },
  1062. // helper functions
  1063. cssUnit: function(key) {
  1064. var style = this.css( key ),
  1065. val = [];
  1066. $.each( [ "em", "px", "%", "pt" ], function( i, unit ) {
  1067. if ( style.indexOf( unit ) > 0 ) {
  1068. val = [ parseFloat( style ), unit ];
  1069. }
  1070. });
  1071. return val;
  1072. }
  1073. });
  1074. })();
  1075. /******************************************************************************/
  1076. /*********************************** EASING ***********************************/
  1077. /******************************************************************************/
  1078. (function() {
  1079. // based on easing equations from Robert Penner (http://www.robertpenner.com/easing)
  1080. var baseEasings = {};
  1081. $.each( [ "Quad", "Cubic", "Quart", "Quint", "Expo" ], function( i, name ) {
  1082. baseEasings[ name ] = function( p ) {
  1083. return Math.pow( p, i + 2 );
  1084. };
  1085. });
  1086. $.extend( baseEasings, {
  1087. Sine: function ( p ) {
  1088. return 1 - Math.cos( p * Math.PI / 2 );
  1089. },
  1090. Circ: function ( p ) {
  1091. return 1 - Math.sqrt( 1 - p * p );
  1092. },
  1093. Elastic: function( p ) {
  1094. return p === 0 || p === 1 ? p :
  1095. -Math.pow( 2, 8 * (p - 1) ) * Math.sin( ( (p - 1) * 80 - 7.5 ) * Math.PI / 15 );
  1096. },
  1097. Back: function( p ) {
  1098. return p * p * ( 3 * p - 2 );
  1099. },
  1100. Bounce: function ( p ) {
  1101. var pow2,
  1102. bounce = 4;
  1103. while ( p < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {}
  1104. return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - p, 2 );
  1105. }
  1106. });
  1107. $.each( baseEasings, function( name, easeIn ) {
  1108. $.easing[ "easeIn" + name ] = easeIn;
  1109. $.easing[ "easeOut" + name ] = function( p ) {
  1110. return 1 - easeIn( 1 - p );
  1111. };
  1112. $.easing[ "easeInOut" + name ] = function( p ) {
  1113. return p < 0.5 ?
  1114. easeIn( p * 2 ) / 2 :
  1115. 1 - easeIn( p * -2 + 2 ) / 2;
  1116. };
  1117. });
  1118. })();
  1119. })(jQuery));