jquery-ui-1.10.1.custom.js 160 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738
  1. /*! jQuery UI - v1.10.1 - 2013-02-26
  2. * http://jqueryui.com
  3. * Includes: jquery.ui.core.js, jquery.ui.widget.js, jquery.ui.mouse.js, jquery.ui.position.js, jquery.ui.draggable.js, jquery.ui.resizable.js, jquery.ui.autocomplete.js, jquery.ui.button.js, jquery.ui.dialog.js, jquery.ui.menu.js
  4. * Copyright (c) 2013 jQuery Foundation and other contributors Licensed MIT */
  5. (function( $, undefined ) {
  6. var uuid = 0,
  7. runiqueId = /^ui-id-\d+$/;
  8. // prevent duplicate loading
  9. // this is only a problem because we proxy existing functions
  10. // and we don't want to double proxy them
  11. $.ui = $.ui || {};
  12. if ( $.ui.version ) {
  13. return;
  14. }
  15. $.extend( $.ui, {
  16. version: "1.10.1",
  17. keyCode: {
  18. BACKSPACE: 8,
  19. COMMA: 188,
  20. DELETE: 46,
  21. DOWN: 40,
  22. END: 35,
  23. ENTER: 13,
  24. ESCAPE: 27,
  25. HOME: 36,
  26. LEFT: 37,
  27. NUMPAD_ADD: 107,
  28. NUMPAD_DECIMAL: 110,
  29. NUMPAD_DIVIDE: 111,
  30. NUMPAD_ENTER: 108,
  31. NUMPAD_MULTIPLY: 106,
  32. NUMPAD_SUBTRACT: 109,
  33. PAGE_DOWN: 34,
  34. PAGE_UP: 33,
  35. PERIOD: 190,
  36. RIGHT: 39,
  37. SPACE: 32,
  38. TAB: 9,
  39. UP: 38
  40. }
  41. });
  42. // plugins
  43. $.fn.extend({
  44. _focus: $.fn.focus,
  45. focus: function( delay, fn ) {
  46. return typeof delay === "number" ?
  47. this.each(function() {
  48. var elem = this;
  49. setTimeout(function() {
  50. $( elem ).focus();
  51. if ( fn ) {
  52. fn.call( elem );
  53. }
  54. }, delay );
  55. }) :
  56. this._focus.apply( this, arguments );
  57. },
  58. scrollParent: function() {
  59. var scrollParent;
  60. if (($.ui.ie && (/(static|relative)/).test(this.css("position"))) || (/absolute/).test(this.css("position"))) {
  61. scrollParent = this.parents().filter(function() {
  62. return (/(relative|absolute|fixed)/).test($.css(this,"position")) && (/(auto|scroll)/).test($.css(this,"overflow")+$.css(this,"overflow-y")+$.css(this,"overflow-x"));
  63. }).eq(0);
  64. } else {
  65. scrollParent = this.parents().filter(function() {
  66. return (/(auto|scroll)/).test($.css(this,"overflow")+$.css(this,"overflow-y")+$.css(this,"overflow-x"));
  67. }).eq(0);
  68. }
  69. return (/fixed/).test(this.css("position")) || !scrollParent.length ? $(document) : scrollParent;
  70. },
  71. zIndex: function( zIndex ) {
  72. if ( zIndex !== undefined ) {
  73. return this.css( "zIndex", zIndex );
  74. }
  75. if ( this.length ) {
  76. var elem = $( this[ 0 ] ), position, value;
  77. while ( elem.length && elem[ 0 ] !== document ) {
  78. // Ignore z-index if position is set to a value where z-index is ignored by the browser
  79. // This makes behavior of this function consistent across browsers
  80. // WebKit always returns auto if the element is positioned
  81. position = elem.css( "position" );
  82. if ( position === "absolute" || position === "relative" || position === "fixed" ) {
  83. // IE returns 0 when zIndex is not specified
  84. // other browsers return a string
  85. // we ignore the case of nested elements with an explicit value of 0
  86. // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
  87. value = parseInt( elem.css( "zIndex" ), 10 );
  88. if ( !isNaN( value ) && value !== 0 ) {
  89. return value;
  90. }
  91. }
  92. elem = elem.parent();
  93. }
  94. }
  95. return 0;
  96. },
  97. uniqueId: function() {
  98. return this.each(function() {
  99. if ( !this.id ) {
  100. this.id = "ui-id-" + (++uuid);
  101. }
  102. });
  103. },
  104. removeUniqueId: function() {
  105. return this.each(function() {
  106. if ( runiqueId.test( this.id ) ) {
  107. $( this ).removeAttr( "id" );
  108. }
  109. });
  110. }
  111. });
  112. // selectors
  113. function focusable( element, isTabIndexNotNaN ) {
  114. var map, mapName, img,
  115. nodeName = element.nodeName.toLowerCase();
  116. if ( "area" === nodeName ) {
  117. map = element.parentNode;
  118. mapName = map.name;
  119. if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
  120. return false;
  121. }
  122. img = $( "img[usemap=#" + mapName + "]" )[0];
  123. return !!img && visible( img );
  124. }
  125. return ( /input|select|textarea|button|object/.test( nodeName ) ?
  126. !element.disabled :
  127. "a" === nodeName ?
  128. element.href || isTabIndexNotNaN :
  129. isTabIndexNotNaN) &&
  130. // the element and all of its ancestors must be visible
  131. visible( element );
  132. }
  133. function visible( element ) {
  134. return $.expr.filters.visible( element ) &&
  135. !$( element ).parents().addBack().filter(function() {
  136. return $.css( this, "visibility" ) === "hidden";
  137. }).length;
  138. }
  139. $.extend( $.expr[ ":" ], {
  140. data: $.expr.createPseudo ?
  141. $.expr.createPseudo(function( dataName ) {
  142. return function( elem ) {
  143. return !!$.data( elem, dataName );
  144. };
  145. }) :
  146. // support: jQuery <1.8
  147. function( elem, i, match ) {
  148. return !!$.data( elem, match[ 3 ] );
  149. },
  150. focusable: function( element ) {
  151. return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
  152. },
  153. tabbable: function( element ) {
  154. var tabIndex = $.attr( element, "tabindex" ),
  155. isTabIndexNaN = isNaN( tabIndex );
  156. return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
  157. }
  158. });
  159. // support: jQuery <1.8
  160. if ( !$( "<a>" ).outerWidth( 1 ).jquery ) {
  161. $.each( [ "Width", "Height" ], function( i, name ) {
  162. var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
  163. type = name.toLowerCase(),
  164. orig = {
  165. innerWidth: $.fn.innerWidth,
  166. innerHeight: $.fn.innerHeight,
  167. outerWidth: $.fn.outerWidth,
  168. outerHeight: $.fn.outerHeight
  169. };
  170. function reduce( elem, size, border, margin ) {
  171. $.each( side, function() {
  172. size -= parseFloat( $.css( elem, "padding" + this ) ) || 0;
  173. if ( border ) {
  174. size -= parseFloat( $.css( elem, "border" + this + "Width" ) ) || 0;
  175. }
  176. if ( margin ) {
  177. size -= parseFloat( $.css( elem, "margin" + this ) ) || 0;
  178. }
  179. });
  180. return size;
  181. }
  182. $.fn[ "inner" + name ] = function( size ) {
  183. if ( size === undefined ) {
  184. return orig[ "inner" + name ].call( this );
  185. }
  186. return this.each(function() {
  187. $( this ).css( type, reduce( this, size ) + "px" );
  188. });
  189. };
  190. $.fn[ "outer" + name] = function( size, margin ) {
  191. if ( typeof size !== "number" ) {
  192. return orig[ "outer" + name ].call( this, size );
  193. }
  194. return this.each(function() {
  195. $( this).css( type, reduce( this, size, true, margin ) + "px" );
  196. });
  197. };
  198. });
  199. }
  200. // support: jQuery <1.8
  201. if ( !$.fn.addBack ) {
  202. $.fn.addBack = function( selector ) {
  203. return this.add( selector == null ?
  204. this.prevObject : this.prevObject.filter( selector )
  205. );
  206. };
  207. }
  208. // support: jQuery 1.6.1, 1.6.2 (http://bugs.jquery.com/ticket/9413)
  209. if ( $( "<a>" ).data( "a-b", "a" ).removeData( "a-b" ).data( "a-b" ) ) {
  210. $.fn.removeData = (function( removeData ) {
  211. return function( key ) {
  212. if ( arguments.length ) {
  213. return removeData.call( this, $.camelCase( key ) );
  214. } else {
  215. return removeData.call( this );
  216. }
  217. };
  218. })( $.fn.removeData );
  219. }
  220. // deprecated
  221. $.ui.ie = !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() );
  222. $.support.selectstart = "onselectstart" in document.createElement( "div" );
  223. $.fn.extend({
  224. disableSelection: function() {
  225. return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
  226. ".ui-disableSelection", function( event ) {
  227. event.preventDefault();
  228. });
  229. },
  230. enableSelection: function() {
  231. return this.unbind( ".ui-disableSelection" );
  232. }
  233. });
  234. $.extend( $.ui, {
  235. // $.ui.plugin is deprecated. Use the proxy pattern instead.
  236. plugin: {
  237. add: function( module, option, set ) {
  238. var i,
  239. proto = $.ui[ module ].prototype;
  240. for ( i in set ) {
  241. proto.plugins[ i ] = proto.plugins[ i ] || [];
  242. proto.plugins[ i ].push( [ option, set[ i ] ] );
  243. }
  244. },
  245. call: function( instance, name, args ) {
  246. var i,
  247. set = instance.plugins[ name ];
  248. if ( !set || !instance.element[ 0 ].parentNode || instance.element[ 0 ].parentNode.nodeType === 11 ) {
  249. return;
  250. }
  251. for ( i = 0; i < set.length; i++ ) {
  252. if ( instance.options[ set[ i ][ 0 ] ] ) {
  253. set[ i ][ 1 ].apply( instance.element, args );
  254. }
  255. }
  256. }
  257. },
  258. // only used by resizable
  259. hasScroll: function( el, a ) {
  260. //If overflow is hidden, the element might have extra content, but the user wants to hide it
  261. if ( $( el ).css( "overflow" ) === "hidden") {
  262. return false;
  263. }
  264. var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
  265. has = false;
  266. if ( el[ scroll ] > 0 ) {
  267. return true;
  268. }
  269. // TODO: determine which cases actually cause this to happen
  270. // if the element doesn't have the scroll set, see if it's possible to
  271. // set the scroll
  272. el[ scroll ] = 1;
  273. has = ( el[ scroll ] > 0 );
  274. el[ scroll ] = 0;
  275. return has;
  276. }
  277. });
  278. })( jQuery );
  279. (function( $, undefined ) {
  280. var uuid = 0,
  281. slice = Array.prototype.slice,
  282. _cleanData = $.cleanData;
  283. $.cleanData = function( elems ) {
  284. for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
  285. try {
  286. $( elem ).triggerHandler( "remove" );
  287. // http://bugs.jquery.com/ticket/8235
  288. } catch( e ) {}
  289. }
  290. _cleanData( elems );
  291. };
  292. $.widget = function( name, base, prototype ) {
  293. var fullName, existingConstructor, constructor, basePrototype,
  294. // proxiedPrototype allows the provided prototype to remain unmodified
  295. // so that it can be used as a mixin for multiple widgets (#8876)
  296. proxiedPrototype = {},
  297. namespace = name.split( "." )[ 0 ];
  298. name = name.split( "." )[ 1 ];
  299. fullName = namespace + "-" + name;
  300. if ( !prototype ) {
  301. prototype = base;
  302. base = $.Widget;
  303. }
  304. // create selector for plugin
  305. $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
  306. return !!$.data( elem, fullName );
  307. };
  308. $[ namespace ] = $[ namespace ] || {};
  309. existingConstructor = $[ namespace ][ name ];
  310. constructor = $[ namespace ][ name ] = function( options, element ) {
  311. // allow instantiation without "new" keyword
  312. if ( !this._createWidget ) {
  313. return new constructor( options, element );
  314. }
  315. // allow instantiation without initializing for simple inheritance
  316. // must use "new" keyword (the code above always passes args)
  317. if ( arguments.length ) {
  318. this._createWidget( options, element );
  319. }
  320. };
  321. // extend with the existing constructor to carry over any static properties
  322. $.extend( constructor, existingConstructor, {
  323. version: prototype.version,
  324. // copy the object used to create the prototype in case we need to
  325. // redefine the widget later
  326. _proto: $.extend( {}, prototype ),
  327. // track widgets that inherit from this widget in case this widget is
  328. // redefined after a widget inherits from it
  329. _childConstructors: []
  330. });
  331. basePrototype = new base();
  332. // we need to make the options hash a property directly on the new instance
  333. // otherwise we'll modify the options hash on the prototype that we're
  334. // inheriting from
  335. basePrototype.options = $.widget.extend( {}, basePrototype.options );
  336. $.each( prototype, function( prop, value ) {
  337. if ( !$.isFunction( value ) ) {
  338. proxiedPrototype[ prop ] = value;
  339. return;
  340. }
  341. proxiedPrototype[ prop ] = (function() {
  342. var _super = function() {
  343. return base.prototype[ prop ].apply( this, arguments );
  344. },
  345. _superApply = function( args ) {
  346. return base.prototype[ prop ].apply( this, args );
  347. };
  348. return function() {
  349. var __super = this._super,
  350. __superApply = this._superApply,
  351. returnValue;
  352. this._super = _super;
  353. this._superApply = _superApply;
  354. returnValue = value.apply( this, arguments );
  355. this._super = __super;
  356. this._superApply = __superApply;
  357. return returnValue;
  358. };
  359. })();
  360. });
  361. constructor.prototype = $.widget.extend( basePrototype, {
  362. // TODO: remove support for widgetEventPrefix
  363. // always use the name + a colon as the prefix, e.g., draggable:start
  364. // don't prefix for widgets that aren't DOM-based
  365. widgetEventPrefix: existingConstructor ? basePrototype.widgetEventPrefix : name
  366. }, proxiedPrototype, {
  367. constructor: constructor,
  368. namespace: namespace,
  369. widgetName: name,
  370. widgetFullName: fullName
  371. });
  372. // If this widget is being redefined then we need to find all widgets that
  373. // are inheriting from it and redefine all of them so that they inherit from
  374. // the new version of this widget. We're essentially trying to replace one
  375. // level in the prototype chain.
  376. if ( existingConstructor ) {
  377. $.each( existingConstructor._childConstructors, function( i, child ) {
  378. var childPrototype = child.prototype;
  379. // redefine the child widget using the same prototype that was
  380. // originally used, but inherit from the new version of the base
  381. $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
  382. });
  383. // remove the list of existing child constructors from the old constructor
  384. // so the old child constructors can be garbage collected
  385. delete existingConstructor._childConstructors;
  386. } else {
  387. base._childConstructors.push( constructor );
  388. }
  389. $.widget.bridge( name, constructor );
  390. };
  391. $.widget.extend = function( target ) {
  392. var input = slice.call( arguments, 1 ),
  393. inputIndex = 0,
  394. inputLength = input.length,
  395. key,
  396. value;
  397. for ( ; inputIndex < inputLength; inputIndex++ ) {
  398. for ( key in input[ inputIndex ] ) {
  399. value = input[ inputIndex ][ key ];
  400. if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
  401. // Clone objects
  402. if ( $.isPlainObject( value ) ) {
  403. target[ key ] = $.isPlainObject( target[ key ] ) ?
  404. $.widget.extend( {}, target[ key ], value ) :
  405. // Don't extend strings, arrays, etc. with objects
  406. $.widget.extend( {}, value );
  407. // Copy everything else by reference
  408. } else {
  409. target[ key ] = value;
  410. }
  411. }
  412. }
  413. }
  414. return target;
  415. };
  416. $.widget.bridge = function( name, object ) {
  417. var fullName = object.prototype.widgetFullName || name;
  418. $.fn[ name ] = function( options ) {
  419. var isMethodCall = typeof options === "string",
  420. args = slice.call( arguments, 1 ),
  421. returnValue = this;
  422. // allow multiple hashes to be passed on init
  423. options = !isMethodCall && args.length ?
  424. $.widget.extend.apply( null, [ options ].concat(args) ) :
  425. options;
  426. if ( isMethodCall ) {
  427. this.each(function() {
  428. var methodValue,
  429. instance = $.data( this, fullName );
  430. if ( !instance ) {
  431. return $.error( "cannot call methods on " + name + " prior to initialization; " +
  432. "attempted to call method '" + options + "'" );
  433. }
  434. if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
  435. return $.error( "no such method '" + options + "' for " + name + " widget instance" );
  436. }
  437. methodValue = instance[ options ].apply( instance, args );
  438. if ( methodValue !== instance && methodValue !== undefined ) {
  439. returnValue = methodValue && methodValue.jquery ?
  440. returnValue.pushStack( methodValue.get() ) :
  441. methodValue;
  442. return false;
  443. }
  444. });
  445. } else {
  446. this.each(function() {
  447. var instance = $.data( this, fullName );
  448. if ( instance ) {
  449. instance.option( options || {} )._init();
  450. } else {
  451. $.data( this, fullName, new object( options, this ) );
  452. }
  453. });
  454. }
  455. return returnValue;
  456. };
  457. };
  458. $.Widget = function( /* options, element */ ) {};
  459. $.Widget._childConstructors = [];
  460. $.Widget.prototype = {
  461. widgetName: "widget",
  462. widgetEventPrefix: "",
  463. defaultElement: "<div>",
  464. options: {
  465. disabled: false,
  466. // callbacks
  467. create: null
  468. },
  469. _createWidget: function( options, element ) {
  470. element = $( element || this.defaultElement || this )[ 0 ];
  471. this.element = $( element );
  472. this.uuid = uuid++;
  473. this.eventNamespace = "." + this.widgetName + this.uuid;
  474. this.options = $.widget.extend( {},
  475. this.options,
  476. this._getCreateOptions(),
  477. options );
  478. this.bindings = $();
  479. this.hoverable = $();
  480. this.focusable = $();
  481. if ( element !== this ) {
  482. $.data( element, this.widgetFullName, this );
  483. this._on( true, this.element, {
  484. remove: function( event ) {
  485. if ( event.target === element ) {
  486. this.destroy();
  487. }
  488. }
  489. });
  490. this.document = $( element.style ?
  491. // element within the document
  492. element.ownerDocument :
  493. // element is window or document
  494. element.document || element );
  495. this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
  496. }
  497. this._create();
  498. this._trigger( "create", null, this._getCreateEventData() );
  499. this._init();
  500. },
  501. _getCreateOptions: $.noop,
  502. _getCreateEventData: $.noop,
  503. _create: $.noop,
  504. _init: $.noop,
  505. destroy: function() {
  506. this._destroy();
  507. // we can probably remove the unbind calls in 2.0
  508. // all event bindings should go through this._on()
  509. this.element
  510. .unbind( this.eventNamespace )
  511. // 1.9 BC for #7810
  512. // TODO remove dual storage
  513. .removeData( this.widgetName )
  514. .removeData( this.widgetFullName )
  515. // support: jquery <1.6.3
  516. // http://bugs.jquery.com/ticket/9413
  517. .removeData( $.camelCase( this.widgetFullName ) );
  518. this.widget()
  519. .unbind( this.eventNamespace )
  520. .removeAttr( "aria-disabled" )
  521. .removeClass(
  522. this.widgetFullName + "-disabled " +
  523. "ui-state-disabled" );
  524. // clean up events and states
  525. this.bindings.unbind( this.eventNamespace );
  526. this.hoverable.removeClass( "ui-state-hover" );
  527. this.focusable.removeClass( "ui-state-focus" );
  528. },
  529. _destroy: $.noop,
  530. widget: function() {
  531. return this.element;
  532. },
  533. option: function( key, value ) {
  534. var options = key,
  535. parts,
  536. curOption,
  537. i;
  538. if ( arguments.length === 0 ) {
  539. // don't return a reference to the internal hash
  540. return $.widget.extend( {}, this.options );
  541. }
  542. if ( typeof key === "string" ) {
  543. // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
  544. options = {};
  545. parts = key.split( "." );
  546. key = parts.shift();
  547. if ( parts.length ) {
  548. curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
  549. for ( i = 0; i < parts.length - 1; i++ ) {
  550. curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
  551. curOption = curOption[ parts[ i ] ];
  552. }
  553. key = parts.pop();
  554. if ( value === undefined ) {
  555. return curOption[ key ] === undefined ? null : curOption[ key ];
  556. }
  557. curOption[ key ] = value;
  558. } else {
  559. if ( value === undefined ) {
  560. return this.options[ key ] === undefined ? null : this.options[ key ];
  561. }
  562. options[ key ] = value;
  563. }
  564. }
  565. this._setOptions( options );
  566. return this;
  567. },
  568. _setOptions: function( options ) {
  569. var key;
  570. for ( key in options ) {
  571. this._setOption( key, options[ key ] );
  572. }
  573. return this;
  574. },
  575. _setOption: function( key, value ) {
  576. this.options[ key ] = value;
  577. if ( key === "disabled" ) {
  578. this.widget()
  579. .toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value )
  580. .attr( "aria-disabled", value );
  581. this.hoverable.removeClass( "ui-state-hover" );
  582. this.focusable.removeClass( "ui-state-focus" );
  583. }
  584. return this;
  585. },
  586. enable: function() {
  587. return this._setOption( "disabled", false );
  588. },
  589. disable: function() {
  590. return this._setOption( "disabled", true );
  591. },
  592. _on: function( suppressDisabledCheck, element, handlers ) {
  593. var delegateElement,
  594. instance = this;
  595. // no suppressDisabledCheck flag, shuffle arguments
  596. if ( typeof suppressDisabledCheck !== "boolean" ) {
  597. handlers = element;
  598. element = suppressDisabledCheck;
  599. suppressDisabledCheck = false;
  600. }
  601. // no element argument, shuffle and use this.element
  602. if ( !handlers ) {
  603. handlers = element;
  604. element = this.element;
  605. delegateElement = this.widget();
  606. } else {
  607. // accept selectors, DOM elements
  608. element = delegateElement = $( element );
  609. this.bindings = this.bindings.add( element );
  610. }
  611. $.each( handlers, function( event, handler ) {
  612. function handlerProxy() {
  613. // allow widgets to customize the disabled handling
  614. // - disabled as an array instead of boolean
  615. // - disabled class as method for disabling individual parts
  616. if ( !suppressDisabledCheck &&
  617. ( instance.options.disabled === true ||
  618. $( this ).hasClass( "ui-state-disabled" ) ) ) {
  619. return;
  620. }
  621. return ( typeof handler === "string" ? instance[ handler ] : handler )
  622. .apply( instance, arguments );
  623. }
  624. // copy the guid so direct unbinding works
  625. if ( typeof handler !== "string" ) {
  626. handlerProxy.guid = handler.guid =
  627. handler.guid || handlerProxy.guid || $.guid++;
  628. }
  629. var match = event.match( /^(\w+)\s*(.*)$/ ),
  630. eventName = match[1] + instance.eventNamespace,
  631. selector = match[2];
  632. if ( selector ) {
  633. delegateElement.delegate( selector, eventName, handlerProxy );
  634. } else {
  635. element.bind( eventName, handlerProxy );
  636. }
  637. });
  638. },
  639. _off: function( element, eventName ) {
  640. eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
  641. element.unbind( eventName ).undelegate( eventName );
  642. },
  643. _delay: function( handler, delay ) {
  644. function handlerProxy() {
  645. return ( typeof handler === "string" ? instance[ handler ] : handler )
  646. .apply( instance, arguments );
  647. }
  648. var instance = this;
  649. return setTimeout( handlerProxy, delay || 0 );
  650. },
  651. _hoverable: function( element ) {
  652. this.hoverable = this.hoverable.add( element );
  653. this._on( element, {
  654. mouseenter: function( event ) {
  655. $( event.currentTarget ).addClass( "ui-state-hover" );
  656. },
  657. mouseleave: function( event ) {
  658. $( event.currentTarget ).removeClass( "ui-state-hover" );
  659. }
  660. });
  661. },
  662. _focusable: function( element ) {
  663. this.focusable = this.focusable.add( element );
  664. this._on( element, {
  665. focusin: function( event ) {
  666. $( event.currentTarget ).addClass( "ui-state-focus" );
  667. },
  668. focusout: function( event ) {
  669. $( event.currentTarget ).removeClass( "ui-state-focus" );
  670. }
  671. });
  672. },
  673. _trigger: function( type, event, data ) {
  674. var prop, orig,
  675. callback = this.options[ type ];
  676. data = data || {};
  677. event = $.Event( event );
  678. event.type = ( type === this.widgetEventPrefix ?
  679. type :
  680. this.widgetEventPrefix + type ).toLowerCase();
  681. // the original event may come from any element
  682. // so we need to reset the target on the new event
  683. event.target = this.element[ 0 ];
  684. // copy original event properties over to the new event
  685. orig = event.originalEvent;
  686. if ( orig ) {
  687. for ( prop in orig ) {
  688. if ( !( prop in event ) ) {
  689. event[ prop ] = orig[ prop ];
  690. }
  691. }
  692. }
  693. this.element.trigger( event, data );
  694. return !( $.isFunction( callback ) &&
  695. callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
  696. event.isDefaultPrevented() );
  697. }
  698. };
  699. $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
  700. $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
  701. if ( typeof options === "string" ) {
  702. options = { effect: options };
  703. }
  704. var hasOptions,
  705. effectName = !options ?
  706. method :
  707. options === true || typeof options === "number" ?
  708. defaultEffect :
  709. options.effect || defaultEffect;
  710. options = options || {};
  711. if ( typeof options === "number" ) {
  712. options = { duration: options };
  713. }
  714. hasOptions = !$.isEmptyObject( options );
  715. options.complete = callback;
  716. if ( options.delay ) {
  717. element.delay( options.delay );
  718. }
  719. if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
  720. element[ method ]( options );
  721. } else if ( effectName !== method && element[ effectName ] ) {
  722. element[ effectName ]( options.duration, options.easing, callback );
  723. } else {
  724. element.queue(function( next ) {
  725. $( this )[ method ]();
  726. if ( callback ) {
  727. callback.call( element[ 0 ] );
  728. }
  729. next();
  730. });
  731. }
  732. };
  733. });
  734. })( jQuery );
  735. (function( $, undefined ) {
  736. var mouseHandled = false;
  737. $( document ).mouseup( function() {
  738. mouseHandled = false;
  739. });
  740. $.widget("ui.mouse", {
  741. version: "1.10.1",
  742. options: {
  743. cancel: "input,textarea,button,select,option",
  744. distance: 1,
  745. delay: 0
  746. },
  747. _mouseInit: function() {
  748. var that = this;
  749. this.element
  750. .bind("mousedown."+this.widgetName, function(event) {
  751. return that._mouseDown(event);
  752. })
  753. .bind("click."+this.widgetName, function(event) {
  754. if (true === $.data(event.target, that.widgetName + ".preventClickEvent")) {
  755. $.removeData(event.target, that.widgetName + ".preventClickEvent");
  756. event.stopImmediatePropagation();
  757. return false;
  758. }
  759. });
  760. this.started = false;
  761. },
  762. // TODO: make sure destroying one instance of mouse doesn't mess with
  763. // other instances of mouse
  764. _mouseDestroy: function() {
  765. this.element.unbind("."+this.widgetName);
  766. if ( this._mouseMoveDelegate ) {
  767. $(document)
  768. .unbind("mousemove."+this.widgetName, this._mouseMoveDelegate)
  769. .unbind("mouseup."+this.widgetName, this._mouseUpDelegate);
  770. }
  771. },
  772. _mouseDown: function(event) {
  773. // don't let more than one widget handle mouseStart
  774. if( mouseHandled ) { return; }
  775. // we may have missed mouseup (out of window)
  776. (this._mouseStarted && this._mouseUp(event));
  777. this._mouseDownEvent = event;
  778. var that = this,
  779. btnIsLeft = (event.which === 1),
  780. // event.target.nodeName works around a bug in IE 8 with
  781. // disabled inputs (#7620)
  782. elIsCancel = (typeof this.options.cancel === "string" && event.target.nodeName ? $(event.target).closest(this.options.cancel).length : false);
  783. if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
  784. return true;
  785. }
  786. this.mouseDelayMet = !this.options.delay;
  787. if (!this.mouseDelayMet) {
  788. this._mouseDelayTimer = setTimeout(function() {
  789. that.mouseDelayMet = true;
  790. }, this.options.delay);
  791. }
  792. if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
  793. this._mouseStarted = (this._mouseStart(event) !== false);
  794. if (!this._mouseStarted) {
  795. event.preventDefault();
  796. return true;
  797. }
  798. }
  799. // Click event may never have fired (Gecko & Opera)
  800. if (true === $.data(event.target, this.widgetName + ".preventClickEvent")) {
  801. $.removeData(event.target, this.widgetName + ".preventClickEvent");
  802. }
  803. // these delegates are required to keep context
  804. this._mouseMoveDelegate = function(event) {
  805. return that._mouseMove(event);
  806. };
  807. this._mouseUpDelegate = function(event) {
  808. return that._mouseUp(event);
  809. };
  810. $(document)
  811. .bind("mousemove."+this.widgetName, this._mouseMoveDelegate)
  812. .bind("mouseup."+this.widgetName, this._mouseUpDelegate);
  813. event.preventDefault();
  814. mouseHandled = true;
  815. return true;
  816. },
  817. _mouseMove: function(event) {
  818. // IE mouseup check - mouseup happened when mouse was out of window
  819. if ($.ui.ie && ( !document.documentMode || document.documentMode < 9 ) && !event.button) {
  820. return this._mouseUp(event);
  821. }
  822. if (this._mouseStarted) {
  823. this._mouseDrag(event);
  824. return event.preventDefault();
  825. }
  826. if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
  827. this._mouseStarted =
  828. (this._mouseStart(this._mouseDownEvent, event) !== false);
  829. (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
  830. }
  831. return !this._mouseStarted;
  832. },
  833. _mouseUp: function(event) {
  834. $(document)
  835. .unbind("mousemove."+this.widgetName, this._mouseMoveDelegate)
  836. .unbind("mouseup."+this.widgetName, this._mouseUpDelegate);
  837. if (this._mouseStarted) {
  838. this._mouseStarted = false;
  839. if (event.target === this._mouseDownEvent.target) {
  840. $.data(event.target, this.widgetName + ".preventClickEvent", true);
  841. }
  842. this._mouseStop(event);
  843. }
  844. return false;
  845. },
  846. _mouseDistanceMet: function(event) {
  847. return (Math.max(
  848. Math.abs(this._mouseDownEvent.pageX - event.pageX),
  849. Math.abs(this._mouseDownEvent.pageY - event.pageY)
  850. ) >= this.options.distance
  851. );
  852. },
  853. _mouseDelayMet: function(/* event */) {
  854. return this.mouseDelayMet;
  855. },
  856. // These are placeholder methods, to be overriden by extending plugin
  857. _mouseStart: function(/* event */) {},
  858. _mouseDrag: function(/* event */) {},
  859. _mouseStop: function(/* event */) {},
  860. _mouseCapture: function(/* event */) { return true; }
  861. });
  862. })(jQuery);
  863. (function( $, undefined ) {
  864. $.ui = $.ui || {};
  865. var cachedScrollbarWidth,
  866. max = Math.max,
  867. abs = Math.abs,
  868. round = Math.round,
  869. rhorizontal = /left|center|right/,
  870. rvertical = /top|center|bottom/,
  871. roffset = /[\+\-]\d+(\.[\d]+)?%?/,
  872. rposition = /^\w+/,
  873. rpercent = /%$/,
  874. _position = $.fn.position;
  875. function getOffsets( offsets, width, height ) {
  876. return [
  877. parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
  878. parseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
  879. ];
  880. }
  881. function parseCss( element, property ) {
  882. return parseInt( $.css( element, property ), 10 ) || 0;
  883. }
  884. function getDimensions( elem ) {
  885. var raw = elem[0];
  886. if ( raw.nodeType === 9 ) {
  887. return {
  888. width: elem.width(),
  889. height: elem.height(),
  890. offset: { top: 0, left: 0 }
  891. };
  892. }
  893. if ( $.isWindow( raw ) ) {
  894. return {
  895. width: elem.width(),
  896. height: elem.height(),
  897. offset: { top: elem.scrollTop(), left: elem.scrollLeft() }
  898. };
  899. }
  900. if ( raw.preventDefault ) {
  901. return {
  902. width: 0,
  903. height: 0,
  904. offset: { top: raw.pageY, left: raw.pageX }
  905. };
  906. }
  907. return {
  908. width: elem.outerWidth(),
  909. height: elem.outerHeight(),
  910. offset: elem.offset()
  911. };
  912. }
  913. $.position = {
  914. scrollbarWidth: function() {
  915. if ( cachedScrollbarWidth !== undefined ) {
  916. return cachedScrollbarWidth;
  917. }
  918. var w1, w2,
  919. div = $( "<div style='display:block;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>" ),
  920. innerDiv = div.children()[0];
  921. $( "body" ).append( div );
  922. w1 = innerDiv.offsetWidth;
  923. div.css( "overflow", "scroll" );
  924. w2 = innerDiv.offsetWidth;
  925. if ( w1 === w2 ) {
  926. w2 = div[0].clientWidth;
  927. }
  928. div.remove();
  929. return (cachedScrollbarWidth = w1 - w2);
  930. },
  931. getScrollInfo: function( within ) {
  932. var overflowX = within.isWindow ? "" : within.element.css( "overflow-x" ),
  933. overflowY = within.isWindow ? "" : within.element.css( "overflow-y" ),
  934. hasOverflowX = overflowX === "scroll" ||
  935. ( overflowX === "auto" && within.width < within.element[0].scrollWidth ),
  936. hasOverflowY = overflowY === "scroll" ||
  937. ( overflowY === "auto" && within.height < within.element[0].scrollHeight );
  938. return {
  939. width: hasOverflowX ? $.position.scrollbarWidth() : 0,
  940. height: hasOverflowY ? $.position.scrollbarWidth() : 0
  941. };
  942. },
  943. getWithinInfo: function( element ) {
  944. var withinElement = $( element || window ),
  945. isWindow = $.isWindow( withinElement[0] );
  946. return {
  947. element: withinElement,
  948. isWindow: isWindow,
  949. offset: withinElement.offset() || { left: 0, top: 0 },
  950. scrollLeft: withinElement.scrollLeft(),
  951. scrollTop: withinElement.scrollTop(),
  952. width: isWindow ? withinElement.width() : withinElement.outerWidth(),
  953. height: isWindow ? withinElement.height() : withinElement.outerHeight()
  954. };
  955. }
  956. };
  957. $.fn.position = function( options ) {
  958. if ( !options || !options.of ) {
  959. return _position.apply( this, arguments );
  960. }
  961. // make a copy, we don't want to modify arguments
  962. options = $.extend( {}, options );
  963. var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
  964. target = $( options.of ),
  965. within = $.position.getWithinInfo( options.within ),
  966. scrollInfo = $.position.getScrollInfo( within ),
  967. collision = ( options.collision || "flip" ).split( " " ),
  968. offsets = {};
  969. dimensions = getDimensions( target );
  970. if ( target[0].preventDefault ) {
  971. // force left top to allow flipping
  972. options.at = "left top";
  973. }
  974. targetWidth = dimensions.width;
  975. targetHeight = dimensions.height;
  976. targetOffset = dimensions.offset;
  977. // clone to reuse original targetOffset later
  978. basePosition = $.extend( {}, targetOffset );
  979. // force my and at to have valid horizontal and vertical positions
  980. // if a value is missing or invalid, it will be converted to center
  981. $.each( [ "my", "at" ], function() {
  982. var pos = ( options[ this ] || "" ).split( " " ),
  983. horizontalOffset,
  984. verticalOffset;
  985. if ( pos.length === 1) {
  986. pos = rhorizontal.test( pos[ 0 ] ) ?
  987. pos.concat( [ "center" ] ) :
  988. rvertical.test( pos[ 0 ] ) ?
  989. [ "center" ].concat( pos ) :
  990. [ "center", "center" ];
  991. }
  992. pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center";
  993. pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center";
  994. // calculate offsets
  995. horizontalOffset = roffset.exec( pos[ 0 ] );
  996. verticalOffset = roffset.exec( pos[ 1 ] );
  997. offsets[ this ] = [
  998. horizontalOffset ? horizontalOffset[ 0 ] : 0,
  999. verticalOffset ? verticalOffset[ 0 ] : 0
  1000. ];
  1001. // reduce to just the positions without the offsets
  1002. options[ this ] = [
  1003. rposition.exec( pos[ 0 ] )[ 0 ],
  1004. rposition.exec( pos[ 1 ] )[ 0 ]
  1005. ];
  1006. });
  1007. // normalize collision option
  1008. if ( collision.length === 1 ) {
  1009. collision[ 1 ] = collision[ 0 ];
  1010. }
  1011. if ( options.at[ 0 ] === "right" ) {
  1012. basePosition.left += targetWidth;
  1013. } else if ( options.at[ 0 ] === "center" ) {
  1014. basePosition.left += targetWidth / 2;
  1015. }
  1016. if ( options.at[ 1 ] === "bottom" ) {
  1017. basePosition.top += targetHeight;
  1018. } else if ( options.at[ 1 ] === "center" ) {
  1019. basePosition.top += targetHeight / 2;
  1020. }
  1021. atOffset = getOffsets( offsets.at, targetWidth, targetHeight );
  1022. basePosition.left += atOffset[ 0 ];
  1023. basePosition.top += atOffset[ 1 ];
  1024. return this.each(function() {
  1025. var collisionPosition, using,
  1026. elem = $( this ),
  1027. elemWidth = elem.outerWidth(),
  1028. elemHeight = elem.outerHeight(),
  1029. marginLeft = parseCss( this, "marginLeft" ),
  1030. marginTop = parseCss( this, "marginTop" ),
  1031. collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) + scrollInfo.width,
  1032. collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) + scrollInfo.height,
  1033. position = $.extend( {}, basePosition ),
  1034. myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() );
  1035. if ( options.my[ 0 ] === "right" ) {
  1036. position.left -= elemWidth;
  1037. } else if ( options.my[ 0 ] === "center" ) {
  1038. position.left -= elemWidth / 2;
  1039. }
  1040. if ( options.my[ 1 ] === "bottom" ) {
  1041. position.top -= elemHeight;
  1042. } else if ( options.my[ 1 ] === "center" ) {
  1043. position.top -= elemHeight / 2;
  1044. }
  1045. position.left += myOffset[ 0 ];
  1046. position.top += myOffset[ 1 ];
  1047. // if the browser doesn't support fractions, then round for consistent results
  1048. if ( !$.support.offsetFractions ) {
  1049. position.left = round( position.left );
  1050. position.top = round( position.top );
  1051. }
  1052. collisionPosition = {
  1053. marginLeft: marginLeft,
  1054. marginTop: marginTop
  1055. };
  1056. $.each( [ "left", "top" ], function( i, dir ) {
  1057. if ( $.ui.position[ collision[ i ] ] ) {
  1058. $.ui.position[ collision[ i ] ][ dir ]( position, {
  1059. targetWidth: targetWidth,
  1060. targetHeight: targetHeight,
  1061. elemWidth: elemWidth,
  1062. elemHeight: elemHeight,
  1063. collisionPosition: collisionPosition,
  1064. collisionWidth: collisionWidth,
  1065. collisionHeight: collisionHeight,
  1066. offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ],
  1067. my: options.my,
  1068. at: options.at,
  1069. within: within,
  1070. elem : elem
  1071. });
  1072. }
  1073. });
  1074. if ( options.using ) {
  1075. // adds feedback as second argument to using callback, if present
  1076. using = function( props ) {
  1077. var left = targetOffset.left - position.left,
  1078. right = left + targetWidth - elemWidth,
  1079. top = targetOffset.top - position.top,
  1080. bottom = top + targetHeight - elemHeight,
  1081. feedback = {
  1082. target: {
  1083. element: target,
  1084. left: targetOffset.left,
  1085. top: targetOffset.top,
  1086. width: targetWidth,
  1087. height: targetHeight
  1088. },
  1089. element: {
  1090. element: elem,
  1091. left: position.left,
  1092. top: position.top,
  1093. width: elemWidth,
  1094. height: elemHeight
  1095. },
  1096. horizontal: right < 0 ? "left" : left > 0 ? "right" : "center",
  1097. vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle"
  1098. };
  1099. if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) {
  1100. feedback.horizontal = "center";
  1101. }
  1102. if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) {
  1103. feedback.vertical = "middle";
  1104. }
  1105. if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) {
  1106. feedback.important = "horizontal";
  1107. } else {
  1108. feedback.important = "vertical";
  1109. }
  1110. options.using.call( this, props, feedback );
  1111. };
  1112. }
  1113. elem.offset( $.extend( position, { using: using } ) );
  1114. });
  1115. };
  1116. $.ui.position = {
  1117. fit: {
  1118. left: function( position, data ) {
  1119. var within = data.within,
  1120. withinOffset = within.isWindow ? within.scrollLeft : within.offset.left,
  1121. outerWidth = within.width,
  1122. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  1123. overLeft = withinOffset - collisionPosLeft,
  1124. overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
  1125. newOverRight;
  1126. // element is wider than within
  1127. if ( data.collisionWidth > outerWidth ) {
  1128. // element is initially over the left side of within
  1129. if ( overLeft > 0 && overRight <= 0 ) {
  1130. newOverRight = position.left + overLeft + data.collisionWidth - outerWidth - withinOffset;
  1131. position.left += overLeft - newOverRight;
  1132. // element is initially over right side of within
  1133. } else if ( overRight > 0 && overLeft <= 0 ) {
  1134. position.left = withinOffset;
  1135. // element is initially over both left and right sides of within
  1136. } else {
  1137. if ( overLeft > overRight ) {
  1138. position.left = withinOffset + outerWidth - data.collisionWidth;
  1139. } else {
  1140. position.left = withinOffset;
  1141. }
  1142. }
  1143. // too far left -> align with left edge
  1144. } else if ( overLeft > 0 ) {
  1145. position.left += overLeft;
  1146. // too far right -> align with right edge
  1147. } else if ( overRight > 0 ) {
  1148. position.left -= overRight;
  1149. // adjust based on position and margin
  1150. } else {
  1151. position.left = max( position.left - collisionPosLeft, position.left );
  1152. }
  1153. },
  1154. top: function( position, data ) {
  1155. var within = data.within,
  1156. withinOffset = within.isWindow ? within.scrollTop : within.offset.top,
  1157. outerHeight = data.within.height,
  1158. collisionPosTop = position.top - data.collisionPosition.marginTop,
  1159. overTop = withinOffset - collisionPosTop,
  1160. overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,
  1161. newOverBottom;
  1162. // element is taller than within
  1163. if ( data.collisionHeight > outerHeight ) {
  1164. // element is initially over the top of within
  1165. if ( overTop > 0 && overBottom <= 0 ) {
  1166. newOverBottom = position.top + overTop + data.collisionHeight - outerHeight - withinOffset;
  1167. position.top += overTop - newOverBottom;
  1168. // element is initially over bottom of within
  1169. } else if ( overBottom > 0 && overTop <= 0 ) {
  1170. position.top = withinOffset;
  1171. // element is initially over both top and bottom of within
  1172. } else {
  1173. if ( overTop > overBottom ) {
  1174. position.top = withinOffset + outerHeight - data.collisionHeight;
  1175. } else {
  1176. position.top = withinOffset;
  1177. }
  1178. }
  1179. // too far up -> align with top
  1180. } else if ( overTop > 0 ) {
  1181. position.top += overTop;
  1182. // too far down -> align with bottom edge
  1183. } else if ( overBottom > 0 ) {
  1184. position.top -= overBottom;
  1185. // adjust based on position and margin
  1186. } else {
  1187. position.top = max( position.top - collisionPosTop, position.top );
  1188. }
  1189. }
  1190. },
  1191. flip: {
  1192. left: function( position, data ) {
  1193. var within = data.within,
  1194. withinOffset = within.offset.left + within.scrollLeft,
  1195. outerWidth = within.width,
  1196. offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left,
  1197. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  1198. overLeft = collisionPosLeft - offsetLeft,
  1199. overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
  1200. myOffset = data.my[ 0 ] === "left" ?
  1201. -data.elemWidth :
  1202. data.my[ 0 ] === "right" ?
  1203. data.elemWidth :
  1204. 0,
  1205. atOffset = data.at[ 0 ] === "left" ?
  1206. data.targetWidth :
  1207. data.at[ 0 ] === "right" ?
  1208. -data.targetWidth :
  1209. 0,
  1210. offset = -2 * data.offset[ 0 ],
  1211. newOverRight,
  1212. newOverLeft;
  1213. if ( overLeft < 0 ) {
  1214. newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth - outerWidth - withinOffset;
  1215. if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) {
  1216. position.left += myOffset + atOffset + offset;
  1217. }
  1218. }
  1219. else if ( overRight > 0 ) {
  1220. newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset + atOffset + offset - offsetLeft;
  1221. if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) {
  1222. position.left += myOffset + atOffset + offset;
  1223. }
  1224. }
  1225. },
  1226. top: function( position, data ) {
  1227. var within = data.within,
  1228. withinOffset = within.offset.top + within.scrollTop,
  1229. outerHeight = within.height,
  1230. offsetTop = within.isWindow ? within.scrollTop : within.offset.top,
  1231. collisionPosTop = position.top - data.collisionPosition.marginTop,
  1232. overTop = collisionPosTop - offsetTop,
  1233. overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,
  1234. top = data.my[ 1 ] === "top",
  1235. myOffset = top ?
  1236. -data.elemHeight :
  1237. data.my[ 1 ] === "bottom" ?
  1238. data.elemHeight :
  1239. 0,
  1240. atOffset = data.at[ 1 ] === "top" ?
  1241. data.targetHeight :
  1242. data.at[ 1 ] === "bottom" ?
  1243. -data.targetHeight :
  1244. 0,
  1245. offset = -2 * data.offset[ 1 ],
  1246. newOverTop,
  1247. newOverBottom;
  1248. if ( overTop < 0 ) {
  1249. newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight - outerHeight - withinOffset;
  1250. if ( ( position.top + myOffset + atOffset + offset) > overTop && ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) ) {
  1251. position.top += myOffset + atOffset + offset;
  1252. }
  1253. }
  1254. else if ( overBottom > 0 ) {
  1255. newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset + offset - offsetTop;
  1256. if ( ( position.top + myOffset + atOffset + offset) > overBottom && ( newOverTop > 0 || abs( newOverTop ) < overBottom ) ) {
  1257. position.top += myOffset + atOffset + offset;
  1258. }
  1259. }
  1260. }
  1261. },
  1262. flipfit: {
  1263. left: function() {
  1264. $.ui.position.flip.left.apply( this, arguments );
  1265. $.ui.position.fit.left.apply( this, arguments );
  1266. },
  1267. top: function() {
  1268. $.ui.position.flip.top.apply( this, arguments );
  1269. $.ui.position.fit.top.apply( this, arguments );
  1270. }
  1271. }
  1272. };
  1273. // fraction support test
  1274. (function () {
  1275. var testElement, testElementParent, testElementStyle, offsetLeft, i,
  1276. body = document.getElementsByTagName( "body" )[ 0 ],
  1277. div = document.createElement( "div" );
  1278. //Create a "fake body" for testing based on method used in jQuery.support
  1279. testElement = document.createElement( body ? "div" : "body" );
  1280. testElementStyle = {
  1281. visibility: "hidden",
  1282. width: 0,
  1283. height: 0,
  1284. border: 0,
  1285. margin: 0,
  1286. background: "none"
  1287. };
  1288. if ( body ) {
  1289. $.extend( testElementStyle, {
  1290. position: "absolute",
  1291. left: "-1000px",
  1292. top: "-1000px"
  1293. });
  1294. }
  1295. for ( i in testElementStyle ) {
  1296. testElement.style[ i ] = testElementStyle[ i ];
  1297. }
  1298. testElement.appendChild( div );
  1299. testElementParent = body || document.documentElement;
  1300. testElementParent.insertBefore( testElement, testElementParent.firstChild );
  1301. div.style.cssText = "position: absolute; left: 10.7432222px;";
  1302. offsetLeft = $( div ).offset().left;
  1303. $.support.offsetFractions = offsetLeft > 10 && offsetLeft < 11;
  1304. testElement.innerHTML = "";
  1305. testElementParent.removeChild( testElement );
  1306. })();
  1307. }( jQuery ) );
  1308. (function( $, undefined ) {
  1309. $.widget("ui.draggable", $.ui.mouse, {
  1310. version: "1.10.1",
  1311. widgetEventPrefix: "drag",
  1312. options: {
  1313. addClasses: true,
  1314. appendTo: "parent",
  1315. axis: false,
  1316. connectToSortable: false,
  1317. containment: false,
  1318. cursor: "auto",
  1319. cursorAt: false,
  1320. grid: false,
  1321. handle: false,
  1322. helper: "original",
  1323. iframeFix: false,
  1324. opacity: false,
  1325. refreshPositions: false,
  1326. revert: false,
  1327. revertDuration: 500,
  1328. scope: "default",
  1329. scroll: true,
  1330. scrollSensitivity: 20,
  1331. scrollSpeed: 20,
  1332. snap: false,
  1333. snapMode: "both",
  1334. snapTolerance: 20,
  1335. stack: false,
  1336. zIndex: false,
  1337. // callbacks
  1338. drag: null,
  1339. start: null,
  1340. stop: null
  1341. },
  1342. _create: function() {
  1343. if (this.options.helper === "original" && !(/^(?:r|a|f)/).test(this.element.css("position"))) {
  1344. this.element[0].style.position = "relative";
  1345. }
  1346. if (this.options.addClasses){
  1347. this.element.addClass("ui-draggable");
  1348. }
  1349. if (this.options.disabled){
  1350. this.element.addClass("ui-draggable-disabled");
  1351. }
  1352. this._mouseInit();
  1353. },
  1354. _destroy: function() {
  1355. this.element.removeClass( "ui-draggable ui-draggable-dragging ui-draggable-disabled" );
  1356. this._mouseDestroy();
  1357. },
  1358. _mouseCapture: function(event) {
  1359. var o = this.options;
  1360. // among others, prevent a drag on a resizable-handle
  1361. if (this.helper || o.disabled || $(event.target).closest(".ui-resizable-handle").length > 0) {
  1362. return false;
  1363. }
  1364. //Quit if we're not on a valid handle
  1365. this.handle = this._getHandle(event);
  1366. if (!this.handle) {
  1367. return false;
  1368. }
  1369. $(o.iframeFix === true ? "iframe" : o.iframeFix).each(function() {
  1370. $("<div class='ui-draggable-iframeFix' style='background: #fff;'></div>")
  1371. .css({
  1372. width: this.offsetWidth+"px", height: this.offsetHeight+"px",
  1373. position: "absolute", opacity: "0.001", zIndex: 1000
  1374. })
  1375. .css($(this).offset())
  1376. .appendTo("body");
  1377. });
  1378. return true;
  1379. },
  1380. _mouseStart: function(event) {
  1381. var o = this.options;
  1382. //Create and append the visible helper
  1383. this.helper = this._createHelper(event);
  1384. this.helper.addClass("ui-draggable-dragging");
  1385. //Cache the helper size
  1386. this._cacheHelperProportions();
  1387. //If ddmanager is used for droppables, set the global draggable
  1388. if($.ui.ddmanager) {
  1389. $.ui.ddmanager.current = this;
  1390. }
  1391. /*
  1392. * - Position generation -
  1393. * This block generates everything position related - it's the core of draggables.
  1394. */
  1395. //Cache the margins of the original element
  1396. this._cacheMargins();
  1397. //Store the helper's css position
  1398. this.cssPosition = this.helper.css("position");
  1399. this.scrollParent = this.helper.scrollParent();
  1400. //The element's absolute position on the page minus margins
  1401. this.offset = this.positionAbs = this.element.offset();
  1402. this.offset = {
  1403. top: this.offset.top - this.margins.top,
  1404. left: this.offset.left - this.margins.left
  1405. };
  1406. $.extend(this.offset, {
  1407. click: { //Where the click happened, relative to the element
  1408. left: event.pageX - this.offset.left,
  1409. top: event.pageY - this.offset.top
  1410. },
  1411. parent: this._getParentOffset(),
  1412. relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
  1413. });
  1414. //Generate the original position
  1415. this.originalPosition = this.position = this._generatePosition(event);
  1416. this.originalPageX = event.pageX;
  1417. this.originalPageY = event.pageY;
  1418. //Adjust the mouse offset relative to the helper if "cursorAt" is supplied
  1419. (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
  1420. //Set a containment if given in the options
  1421. if(o.containment) {
  1422. this._setContainment();
  1423. }
  1424. //Trigger event + callbacks
  1425. if(this._trigger("start", event) === false) {
  1426. this._clear();
  1427. return false;
  1428. }
  1429. //Recache the helper size
  1430. this._cacheHelperProportions();
  1431. //Prepare the droppable offsets
  1432. if ($.ui.ddmanager && !o.dropBehaviour) {
  1433. $.ui.ddmanager.prepareOffsets(this, event);
  1434. }
  1435. this._mouseDrag(event, true); //Execute the drag once - this causes the helper not to be visible before getting its correct position
  1436. //If the ddmanager is used for droppables, inform the manager that dragging has started (see #5003)
  1437. if ( $.ui.ddmanager ) {
  1438. $.ui.ddmanager.dragStart(this, event);
  1439. }
  1440. return true;
  1441. },
  1442. _mouseDrag: function(event, noPropagation) {
  1443. //Compute the helpers position
  1444. this.position = this._generatePosition(event);
  1445. this.positionAbs = this._convertPositionTo("absolute");
  1446. //Call plugins and callbacks and use the resulting position if something is returned
  1447. if (!noPropagation) {
  1448. var ui = this._uiHash();
  1449. if(this._trigger("drag", event, ui) === false) {
  1450. this._mouseUp({});
  1451. return false;
  1452. }
  1453. this.position = ui.position;
  1454. }
  1455. if(!this.options.axis || this.options.axis !== "y") {
  1456. this.helper[0].style.left = this.position.left+"px";
  1457. }
  1458. if(!this.options.axis || this.options.axis !== "x") {
  1459. this.helper[0].style.top = this.position.top+"px";
  1460. }
  1461. if($.ui.ddmanager) {
  1462. $.ui.ddmanager.drag(this, event);
  1463. }
  1464. return false;
  1465. },
  1466. _mouseStop: function(event) {
  1467. //If we are using droppables, inform the manager about the drop
  1468. var element,
  1469. that = this,
  1470. elementInDom = false,
  1471. dropped = false;
  1472. if ($.ui.ddmanager && !this.options.dropBehaviour) {
  1473. dropped = $.ui.ddmanager.drop(this, event);
  1474. }
  1475. //if a drop comes from outside (a sortable)
  1476. if(this.dropped) {
  1477. dropped = this.dropped;
  1478. this.dropped = false;
  1479. }
  1480. //if the original element is no longer in the DOM don't bother to continue (see #8269)
  1481. element = this.element[0];
  1482. while ( element && (element = element.parentNode) ) {
  1483. if (element === document ) {
  1484. elementInDom = true;
  1485. }
  1486. }
  1487. if ( !elementInDom && this.options.helper === "original" ) {
  1488. return false;
  1489. }
  1490. if((this.options.revert === "invalid" && !dropped) || (this.options.revert === "valid" && dropped) || this.options.revert === true || ($.isFunction(this.options.revert) && this.options.revert.call(this.element, dropped))) {
  1491. $(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() {
  1492. if(that._trigger("stop", event) !== false) {
  1493. that._clear();
  1494. }
  1495. });
  1496. } else {
  1497. if(this._trigger("stop", event) !== false) {
  1498. this._clear();
  1499. }
  1500. }
  1501. return false;
  1502. },
  1503. _mouseUp: function(event) {
  1504. //Remove frame helpers
  1505. $("div.ui-draggable-iframeFix").each(function() {
  1506. this.parentNode.removeChild(this);
  1507. });
  1508. //If the ddmanager is used for droppables, inform the manager that dragging has stopped (see #5003)
  1509. if( $.ui.ddmanager ) {
  1510. $.ui.ddmanager.dragStop(this, event);
  1511. }
  1512. return $.ui.mouse.prototype._mouseUp.call(this, event);
  1513. },
  1514. cancel: function() {
  1515. if(this.helper.is(".ui-draggable-dragging")) {
  1516. this._mouseUp({});
  1517. } else {
  1518. this._clear();
  1519. }
  1520. return this;
  1521. },
  1522. _getHandle: function(event) {
  1523. var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false;
  1524. $(this.options.handle, this.element)
  1525. .find("*")
  1526. .addBack()
  1527. .each(function() {
  1528. if(this === event.target) {
  1529. handle = true;
  1530. }
  1531. });
  1532. return handle;
  1533. },
  1534. _createHelper: function(event) {
  1535. var o = this.options,
  1536. helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event])) : (o.helper === "clone" ? this.element.clone().removeAttr("id") : this.element);
  1537. if(!helper.parents("body").length) {
  1538. helper.appendTo((o.appendTo === "parent" ? this.element[0].parentNode : o.appendTo));
  1539. }
  1540. if(helper[0] !== this.element[0] && !(/(fixed|absolute)/).test(helper.css("position"))) {
  1541. helper.css("position", "absolute");
  1542. }
  1543. return helper;
  1544. },
  1545. _adjustOffsetFromHelper: function(obj) {
  1546. if (typeof obj === "string") {
  1547. obj = obj.split(" ");
  1548. }
  1549. if ($.isArray(obj)) {
  1550. obj = {left: +obj[0], top: +obj[1] || 0};
  1551. }
  1552. if ("left" in obj) {
  1553. this.offset.click.left = obj.left + this.margins.left;
  1554. }
  1555. if ("right" in obj) {
  1556. this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
  1557. }
  1558. if ("top" in obj) {
  1559. this.offset.click.top = obj.top + this.margins.top;
  1560. }
  1561. if ("bottom" in obj) {
  1562. this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
  1563. }
  1564. },
  1565. _getParentOffset: function() {
  1566. //Get the offsetParent and cache its position
  1567. this.offsetParent = this.helper.offsetParent();
  1568. var po = this.offsetParent.offset();
  1569. // This is a special case where we need to modify a offset calculated on start, since the following happened:
  1570. // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
  1571. // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
  1572. // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
  1573. if(this.cssPosition === "absolute" && this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) {
  1574. po.left += this.scrollParent.scrollLeft();
  1575. po.top += this.scrollParent.scrollTop();
  1576. }
  1577. //This needs to be actually done for all browsers, since pageX/pageY includes this information
  1578. //Ugly IE fix
  1579. if((this.offsetParent[0] === document.body) ||
  1580. (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() === "html" && $.ui.ie)) {
  1581. po = { top: 0, left: 0 };
  1582. }
  1583. return {
  1584. top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
  1585. left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
  1586. };
  1587. },
  1588. _getRelativeOffset: function() {
  1589. if(this.cssPosition === "relative") {
  1590. var p = this.element.position();
  1591. return {
  1592. top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
  1593. left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft()
  1594. };
  1595. } else {
  1596. return { top: 0, left: 0 };
  1597. }
  1598. },
  1599. _cacheMargins: function() {
  1600. this.margins = {
  1601. left: (parseInt(this.element.css("marginLeft"),10) || 0),
  1602. top: (parseInt(this.element.css("marginTop"),10) || 0),
  1603. right: (parseInt(this.element.css("marginRight"),10) || 0),
  1604. bottom: (parseInt(this.element.css("marginBottom"),10) || 0)
  1605. };
  1606. },
  1607. _cacheHelperProportions: function() {
  1608. this.helperProportions = {
  1609. width: this.helper.outerWidth(),
  1610. height: this.helper.outerHeight()
  1611. };
  1612. },
  1613. _setContainment: function() {
  1614. var over, c, ce,
  1615. o = this.options;
  1616. if(o.containment === "parent") {
  1617. o.containment = this.helper[0].parentNode;
  1618. }
  1619. if(o.containment === "document" || o.containment === "window") {
  1620. this.containment = [
  1621. o.containment === "document" ? 0 : $(window).scrollLeft() - this.offset.relative.left - this.offset.parent.left,
  1622. o.containment === "document" ? 0 : $(window).scrollTop() - this.offset.relative.top - this.offset.parent.top,
  1623. (o.containment === "document" ? 0 : $(window).scrollLeft()) + $(o.containment === "document" ? document : window).width() - this.helperProportions.width - this.margins.left,
  1624. (o.containment === "document" ? 0 : $(window).scrollTop()) + ($(o.containment === "document" ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
  1625. ];
  1626. }
  1627. if(!(/^(document|window|parent)$/).test(o.containment) && o.containment.constructor !== Array) {
  1628. c = $(o.containment);
  1629. ce = c[0];
  1630. if(!ce) {
  1631. return;
  1632. }
  1633. over = ($(ce).css("overflow") !== "hidden");
  1634. this.containment = [
  1635. (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0),
  1636. (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0),
  1637. (over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left - this.margins.right,
  1638. (over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top - this.margins.bottom
  1639. ];
  1640. this.relative_container = c;
  1641. } else if(o.containment.constructor === Array) {
  1642. this.containment = o.containment;
  1643. }
  1644. },
  1645. _convertPositionTo: function(d, pos) {
  1646. if(!pos) {
  1647. pos = this.position;
  1648. }
  1649. var mod = d === "absolute" ? 1 : -1,
  1650. scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
  1651. return {
  1652. top: (
  1653. pos.top + // The absolute mouse position
  1654. this.offset.relative.top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
  1655. this.offset.parent.top * mod - // The offsetParent's offset without borders (offset + border)
  1656. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
  1657. ),
  1658. left: (
  1659. pos.left + // The absolute mouse position
  1660. this.offset.relative.left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
  1661. this.offset.parent.left * mod - // The offsetParent's offset without borders (offset + border)
  1662. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
  1663. )
  1664. };
  1665. },
  1666. _generatePosition: function(event) {
  1667. var containment, co, top, left,
  1668. o = this.options,
  1669. scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent,
  1670. scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName),
  1671. pageX = event.pageX,
  1672. pageY = event.pageY;
  1673. /*
  1674. * - Position constraining -
  1675. * Constrain the position to a mix of grid, containment.
  1676. */
  1677. if(this.originalPosition) { //If we are not dragging yet, we won't check for options
  1678. if(this.containment) {
  1679. if (this.relative_container){
  1680. co = this.relative_container.offset();
  1681. containment = [ this.containment[0] + co.left,
  1682. this.containment[1] + co.top,
  1683. this.containment[2] + co.left,
  1684. this.containment[3] + co.top ];
  1685. }
  1686. else {
  1687. containment = this.containment;
  1688. }
  1689. if(event.pageX - this.offset.click.left < containment[0]) {
  1690. pageX = containment[0] + this.offset.click.left;
  1691. }
  1692. if(event.pageY - this.offset.click.top < containment[1]) {
  1693. pageY = containment[1] + this.offset.click.top;
  1694. }
  1695. if(event.pageX - this.offset.click.left > containment[2]) {
  1696. pageX = containment[2] + this.offset.click.left;
  1697. }
  1698. if(event.pageY - this.offset.click.top > containment[3]) {
  1699. pageY = containment[3] + this.offset.click.top;
  1700. }
  1701. }
  1702. if(o.grid) {
  1703. //Check for grid elements set to 0 to prevent divide by 0 error causing invalid argument errors in IE (see ticket #6950)
  1704. top = o.grid[1] ? this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1] : this.originalPageY;
  1705. pageY = containment ? ((top - this.offset.click.top >= containment[1] || top - this.offset.click.top > containment[3]) ? top : ((top - this.offset.click.top >= containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
  1706. left = o.grid[0] ? this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0] : this.originalPageX;
  1707. pageX = containment ? ((left - this.offset.click.left >= containment[0] || left - this.offset.click.left > containment[2]) ? left : ((left - this.offset.click.left >= containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
  1708. }
  1709. }
  1710. return {
  1711. top: (
  1712. pageY - // The absolute mouse position
  1713. this.offset.click.top - // Click offset (relative to the element)
  1714. this.offset.relative.top - // Only for relative positioned nodes: Relative offset from element to offset parent
  1715. this.offset.parent.top + // The offsetParent's offset without borders (offset + border)
  1716. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
  1717. ),
  1718. left: (
  1719. pageX - // The absolute mouse position
  1720. this.offset.click.left - // Click offset (relative to the element)
  1721. this.offset.relative.left - // Only for relative positioned nodes: Relative offset from element to offset parent
  1722. this.offset.parent.left + // The offsetParent's offset without borders (offset + border)
  1723. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
  1724. )
  1725. };
  1726. },
  1727. _clear: function() {
  1728. this.helper.removeClass("ui-draggable-dragging");
  1729. if(this.helper[0] !== this.element[0] && !this.cancelHelperRemoval) {
  1730. this.helper.remove();
  1731. }
  1732. this.helper = null;
  1733. this.cancelHelperRemoval = false;
  1734. },
  1735. // From now on bulk stuff - mainly helpers
  1736. _trigger: function(type, event, ui) {
  1737. ui = ui || this._uiHash();
  1738. $.ui.plugin.call(this, type, [event, ui]);
  1739. //The absolute position has to be recalculated after plugins
  1740. if(type === "drag") {
  1741. this.positionAbs = this._convertPositionTo("absolute");
  1742. }
  1743. return $.Widget.prototype._trigger.call(this, type, event, ui);
  1744. },
  1745. plugins: {},
  1746. _uiHash: function() {
  1747. return {
  1748. helper: this.helper,
  1749. position: this.position,
  1750. originalPosition: this.originalPosition,
  1751. offset: this.positionAbs
  1752. };
  1753. }
  1754. });
  1755. $.ui.plugin.add("draggable", "connectToSortable", {
  1756. start: function(event, ui) {
  1757. var inst = $(this).data("ui-draggable"), o = inst.options,
  1758. uiSortable = $.extend({}, ui, { item: inst.element });
  1759. inst.sortables = [];
  1760. $(o.connectToSortable).each(function() {
  1761. var sortable = $.data(this, "ui-sortable");
  1762. if (sortable && !sortable.options.disabled) {
  1763. inst.sortables.push({
  1764. instance: sortable,
  1765. shouldRevert: sortable.options.revert
  1766. });
  1767. sortable.refreshPositions(); // Call the sortable's refreshPositions at drag start to refresh the containerCache since the sortable container cache is used in drag and needs to be up to date (this will ensure it's initialised as well as being kept in step with any changes that might have happened on the page).
  1768. sortable._trigger("activate", event, uiSortable);
  1769. }
  1770. });
  1771. },
  1772. stop: function(event, ui) {
  1773. //If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
  1774. var inst = $(this).data("ui-draggable"),
  1775. uiSortable = $.extend({}, ui, { item: inst.element });
  1776. $.each(inst.sortables, function() {
  1777. if(this.instance.isOver) {
  1778. this.instance.isOver = 0;
  1779. inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance
  1780. this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work)
  1781. //The sortable revert is supported, and we have to set a temporary dropped variable on the draggable to support revert: "valid/invalid"
  1782. if(this.shouldRevert) {
  1783. this.instance.options.revert = true;
  1784. }
  1785. //Trigger the stop of the sortable
  1786. this.instance._mouseStop(event);
  1787. this.instance.options.helper = this.instance.options._helper;
  1788. //If the helper has been the original item, restore properties in the sortable
  1789. if(inst.options.helper === "original") {
  1790. this.instance.currentItem.css({ top: "auto", left: "auto" });
  1791. }
  1792. } else {
  1793. this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance
  1794. this.instance._trigger("deactivate", event, uiSortable);
  1795. }
  1796. });
  1797. },
  1798. drag: function(event, ui) {
  1799. var inst = $(this).data("ui-draggable"), that = this;
  1800. $.each(inst.sortables, function() {
  1801. var innermostIntersecting = false,
  1802. thisSortable = this;
  1803. //Copy over some variables to allow calling the sortable's native _intersectsWith
  1804. this.instance.positionAbs = inst.positionAbs;
  1805. this.instance.helperProportions = inst.helperProportions;
  1806. this.instance.offset.click = inst.offset.click;
  1807. if(this.instance._intersectsWith(this.instance.containerCache)) {
  1808. innermostIntersecting = true;
  1809. $.each(inst.sortables, function () {
  1810. this.instance.positionAbs = inst.positionAbs;
  1811. this.instance.helperProportions = inst.helperProportions;
  1812. this.instance.offset.click = inst.offset.click;
  1813. if (this !== thisSortable &&
  1814. this.instance._intersectsWith(this.instance.containerCache) &&
  1815. $.contains(thisSortable.instance.element[0], this.instance.element[0])
  1816. ) {
  1817. innermostIntersecting = false;
  1818. }
  1819. return innermostIntersecting;
  1820. });
  1821. }
  1822. if(innermostIntersecting) {
  1823. //If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once
  1824. if(!this.instance.isOver) {
  1825. this.instance.isOver = 1;
  1826. //Now we fake the start of dragging for the sortable instance,
  1827. //by cloning the list group item, appending it to the sortable and using it as inst.currentItem
  1828. //We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one)
  1829. this.instance.currentItem = $(that).clone().removeAttr("id").appendTo(this.instance.element).data("ui-sortable-item", true);
  1830. this.instance.options._helper = this.instance.options.helper; //Store helper option to later restore it
  1831. this.instance.options.helper = function() { return ui.helper[0]; };
  1832. event.target = this.instance.currentItem[0];
  1833. this.instance._mouseCapture(event, true);
  1834. this.instance._mouseStart(event, true, true);
  1835. //Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
  1836. this.instance.offset.click.top = inst.offset.click.top;
  1837. this.instance.offset.click.left = inst.offset.click.left;
  1838. this.instance.offset.parent.left -= inst.offset.parent.left - this.instance.offset.parent.left;
  1839. this.instance.offset.parent.top -= inst.offset.parent.top - this.instance.offset.parent.top;
  1840. inst._trigger("toSortable", event);
  1841. inst.dropped = this.instance.element; //draggable revert needs that
  1842. //hack so receive/update callbacks work (mostly)
  1843. inst.currentItem = inst.element;
  1844. this.instance.fromOutside = inst;
  1845. }
  1846. //Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable
  1847. if(this.instance.currentItem) {
  1848. this.instance._mouseDrag(event);
  1849. }
  1850. } else {
  1851. //If it doesn't intersect with the sortable, and it intersected before,
  1852. //we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval
  1853. if(this.instance.isOver) {
  1854. this.instance.isOver = 0;
  1855. this.instance.cancelHelperRemoval = true;
  1856. //Prevent reverting on this forced stop
  1857. this.instance.options.revert = false;
  1858. // The out event needs to be triggered independently
  1859. this.instance._trigger("out", event, this.instance._uiHash(this.instance));
  1860. this.instance._mouseStop(event, true);
  1861. this.instance.options.helper = this.instance.options._helper;
  1862. //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
  1863. this.instance.currentItem.remove();
  1864. if(this.instance.placeholder) {
  1865. this.instance.placeholder.remove();
  1866. }
  1867. inst._trigger("fromSortable", event);
  1868. inst.dropped = false; //draggable revert needs that
  1869. }
  1870. }
  1871. });
  1872. }
  1873. });
  1874. $.ui.plugin.add("draggable", "cursor", {
  1875. start: function() {
  1876. var t = $("body"), o = $(this).data("ui-draggable").options;
  1877. if (t.css("cursor")) {
  1878. o._cursor = t.css("cursor");
  1879. }
  1880. t.css("cursor", o.cursor);
  1881. },
  1882. stop: function() {
  1883. var o = $(this).data("ui-draggable").options;
  1884. if (o._cursor) {
  1885. $("body").css("cursor", o._cursor);
  1886. }
  1887. }
  1888. });
  1889. $.ui.plugin.add("draggable", "opacity", {
  1890. start: function(event, ui) {
  1891. var t = $(ui.helper), o = $(this).data("ui-draggable").options;
  1892. if(t.css("opacity")) {
  1893. o._opacity = t.css("opacity");
  1894. }
  1895. t.css("opacity", o.opacity);
  1896. },
  1897. stop: function(event, ui) {
  1898. var o = $(this).data("ui-draggable").options;
  1899. if(o._opacity) {
  1900. $(ui.helper).css("opacity", o._opacity);
  1901. }
  1902. }
  1903. });
  1904. $.ui.plugin.add("draggable", "scroll", {
  1905. start: function() {
  1906. var i = $(this).data("ui-draggable");
  1907. if(i.scrollParent[0] !== document && i.scrollParent[0].tagName !== "HTML") {
  1908. i.overflowOffset = i.scrollParent.offset();
  1909. }
  1910. },
  1911. drag: function( event ) {
  1912. var i = $(this).data("ui-draggable"), o = i.options, scrolled = false;
  1913. if(i.scrollParent[0] !== document && i.scrollParent[0].tagName !== "HTML") {
  1914. if(!o.axis || o.axis !== "x") {
  1915. if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) {
  1916. i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop + o.scrollSpeed;
  1917. } else if(event.pageY - i.overflowOffset.top < o.scrollSensitivity) {
  1918. i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop - o.scrollSpeed;
  1919. }
  1920. }
  1921. if(!o.axis || o.axis !== "y") {
  1922. if((i.overflowOffset.left + i.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) {
  1923. i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft + o.scrollSpeed;
  1924. } else if(event.pageX - i.overflowOffset.left < o.scrollSensitivity) {
  1925. i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft - o.scrollSpeed;
  1926. }
  1927. }
  1928. } else {
  1929. if(!o.axis || o.axis !== "x") {
  1930. if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) {
  1931. scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
  1932. } else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) {
  1933. scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
  1934. }
  1935. }
  1936. if(!o.axis || o.axis !== "y") {
  1937. if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) {
  1938. scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
  1939. } else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) {
  1940. scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
  1941. }
  1942. }
  1943. }
  1944. if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) {
  1945. $.ui.ddmanager.prepareOffsets(i, event);
  1946. }
  1947. }
  1948. });
  1949. $.ui.plugin.add("draggable", "snap", {
  1950. start: function() {
  1951. var i = $(this).data("ui-draggable"),
  1952. o = i.options;
  1953. i.snapElements = [];
  1954. $(o.snap.constructor !== String ? ( o.snap.items || ":data(ui-draggable)" ) : o.snap).each(function() {
  1955. var $t = $(this),
  1956. $o = $t.offset();
  1957. if(this !== i.element[0]) {
  1958. i.snapElements.push({
  1959. item: this,
  1960. width: $t.outerWidth(), height: $t.outerHeight(),
  1961. top: $o.top, left: $o.left
  1962. });
  1963. }
  1964. });
  1965. },
  1966. drag: function(event, ui) {
  1967. var ts, bs, ls, rs, l, r, t, b, i, first,
  1968. inst = $(this).data("ui-draggable"),
  1969. o = inst.options,
  1970. d = o.snapTolerance,
  1971. x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width,
  1972. y1 = ui.offset.top, y2 = y1 + inst.helperProportions.height;
  1973. for (i = inst.snapElements.length - 1; i >= 0; i--){
  1974. l = inst.snapElements[i].left;
  1975. r = l + inst.snapElements[i].width;
  1976. t = inst.snapElements[i].top;
  1977. b = t + inst.snapElements[i].height;
  1978. //Yes, I know, this is insane ;)
  1979. if(!((l-d < x1 && x1 < r+d && t-d < y1 && y1 < b+d) || (l-d < x1 && x1 < r+d && t-d < y2 && y2 < b+d) || (l-d < x2 && x2 < r+d && t-d < y1 && y1 < b+d) || (l-d < x2 && x2 < r+d && t-d < y2 && y2 < b+d))) {
  1980. if(inst.snapElements[i].snapping) {
  1981. (inst.options.snap.release && inst.options.snap.release.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
  1982. }
  1983. inst.snapElements[i].snapping = false;
  1984. continue;
  1985. }
  1986. if(o.snapMode !== "inner") {
  1987. ts = Math.abs(t - y2) <= d;
  1988. bs = Math.abs(b - y1) <= d;
  1989. ls = Math.abs(l - x2) <= d;
  1990. rs = Math.abs(r - x1) <= d;
  1991. if(ts) {
  1992. ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top - inst.margins.top;
  1993. }
  1994. if(bs) {
  1995. ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top - inst.margins.top;
  1996. }
  1997. if(ls) {
  1998. ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left - inst.margins.left;
  1999. }
  2000. if(rs) {
  2001. ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left - inst.margins.left;
  2002. }
  2003. }
  2004. first = (ts || bs || ls || rs);
  2005. if(o.snapMode !== "outer") {
  2006. ts = Math.abs(t - y1) <= d;
  2007. bs = Math.abs(b - y2) <= d;
  2008. ls = Math.abs(l - x1) <= d;
  2009. rs = Math.abs(r - x2) <= d;
  2010. if(ts) {
  2011. ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top - inst.margins.top;
  2012. }
  2013. if(bs) {
  2014. ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top - inst.margins.top;
  2015. }
  2016. if(ls) {
  2017. ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left - inst.margins.left;
  2018. }
  2019. if(rs) {
  2020. ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left - inst.margins.left;
  2021. }
  2022. }
  2023. if(!inst.snapElements[i].snapping && (ts || bs || ls || rs || first)) {
  2024. (inst.options.snap.snap && inst.options.snap.snap.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
  2025. }
  2026. inst.snapElements[i].snapping = (ts || bs || ls || rs || first);
  2027. }
  2028. }
  2029. });
  2030. $.ui.plugin.add("draggable", "stack", {
  2031. start: function() {
  2032. var min,
  2033. o = this.data("ui-draggable").options,
  2034. group = $.makeArray($(o.stack)).sort(function(a,b) {
  2035. return (parseInt($(a).css("zIndex"),10) || 0) - (parseInt($(b).css("zIndex"),10) || 0);
  2036. });
  2037. if (!group.length) { return; }
  2038. min = parseInt($(group[0]).css("zIndex"), 10) || 0;
  2039. $(group).each(function(i) {
  2040. $(this).css("zIndex", min + i);
  2041. });
  2042. this.css("zIndex", (min + group.length));
  2043. }
  2044. });
  2045. $.ui.plugin.add("draggable", "zIndex", {
  2046. start: function(event, ui) {
  2047. var t = $(ui.helper), o = $(this).data("ui-draggable").options;
  2048. if(t.css("zIndex")) {
  2049. o._zIndex = t.css("zIndex");
  2050. }
  2051. t.css("zIndex", o.zIndex);
  2052. },
  2053. stop: function(event, ui) {
  2054. var o = $(this).data("ui-draggable").options;
  2055. if(o._zIndex) {
  2056. $(ui.helper).css("zIndex", o._zIndex);
  2057. }
  2058. }
  2059. });
  2060. })(jQuery);
  2061. (function( $, undefined ) {
  2062. function num(v) {
  2063. return parseInt(v, 10) || 0;
  2064. }
  2065. function isNumber(value) {
  2066. return !isNaN(parseInt(value, 10));
  2067. }
  2068. $.widget("ui.resizable", $.ui.mouse, {
  2069. version: "1.10.1",
  2070. widgetEventPrefix: "resize",
  2071. options: {
  2072. alsoResize: false,
  2073. animate: false,
  2074. animateDuration: "slow",
  2075. animateEasing: "swing",
  2076. aspectRatio: false,
  2077. autoHide: false,
  2078. containment: false,
  2079. ghost: false,
  2080. grid: false,
  2081. handles: "e,s,se",
  2082. helper: false,
  2083. maxHeight: null,
  2084. maxWidth: null,
  2085. minHeight: 10,
  2086. minWidth: 10,
  2087. // See #7960
  2088. zIndex: 90,
  2089. // callbacks
  2090. resize: null,
  2091. start: null,
  2092. stop: null
  2093. },
  2094. _create: function() {
  2095. var n, i, handle, axis, hname,
  2096. that = this,
  2097. o = this.options;
  2098. this.element.addClass("ui-resizable");
  2099. $.extend(this, {
  2100. _aspectRatio: !!(o.aspectRatio),
  2101. aspectRatio: o.aspectRatio,
  2102. originalElement: this.element,
  2103. _proportionallyResizeElements: [],
  2104. _helper: o.helper || o.ghost || o.animate ? o.helper || "ui-resizable-helper" : null
  2105. });
  2106. //Wrap the element if it cannot hold child nodes
  2107. if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)) {
  2108. //Create a wrapper element and set the wrapper to the new current internal element
  2109. this.element.wrap(
  2110. $("<div class='ui-wrapper' style='overflow: hidden;'></div>").css({
  2111. position: this.element.css("position"),
  2112. width: this.element.outerWidth(),
  2113. height: this.element.outerHeight(),
  2114. top: this.element.css("top"),
  2115. left: this.element.css("left")
  2116. })
  2117. );
  2118. //Overwrite the original this.element
  2119. this.element = this.element.parent().data(
  2120. "ui-resizable", this.element.data("ui-resizable")
  2121. );
  2122. this.elementIsWrapper = true;
  2123. //Move margins to the wrapper
  2124. this.element.css({ marginLeft: this.originalElement.css("marginLeft"), marginTop: this.originalElement.css("marginTop"), marginRight: this.originalElement.css("marginRight"), marginBottom: this.originalElement.css("marginBottom") });
  2125. this.originalElement.css({ marginLeft: 0, marginTop: 0, marginRight: 0, marginBottom: 0});
  2126. //Prevent Safari textarea resize
  2127. this.originalResizeStyle = this.originalElement.css("resize");
  2128. this.originalElement.css("resize", "none");
  2129. //Push the actual element to our proportionallyResize internal array
  2130. this._proportionallyResizeElements.push(this.originalElement.css({ position: "static", zoom: 1, display: "block" }));
  2131. // avoid IE jump (hard set the margin)
  2132. this.originalElement.css({ margin: this.originalElement.css("margin") });
  2133. // fix handlers offset
  2134. this._proportionallyResize();
  2135. }
  2136. this.handles = o.handles || (!$(".ui-resizable-handle", this.element).length ? "e,s,se" : { n: ".ui-resizable-n", e: ".ui-resizable-e", s: ".ui-resizable-s", w: ".ui-resizable-w", se: ".ui-resizable-se", sw: ".ui-resizable-sw", ne: ".ui-resizable-ne", nw: ".ui-resizable-nw" });
  2137. if(this.handles.constructor === String) {
  2138. if ( this.handles === "all") {
  2139. this.handles = "n,e,s,w,se,sw,ne,nw";
  2140. }
  2141. n = this.handles.split(",");
  2142. this.handles = {};
  2143. for(i = 0; i < n.length; i++) {
  2144. handle = $.trim(n[i]);
  2145. hname = "ui-resizable-"+handle;
  2146. axis = $("<div class='ui-resizable-handle " + hname + "'></div>");
  2147. // Apply zIndex to all handles - see #7960
  2148. axis.css({ zIndex: o.zIndex });
  2149. //TODO : What's going on here?
  2150. if ("se" === handle) {
  2151. axis.addClass("ui-icon ui-icon-gripsmall-diagonal-se");
  2152. }
  2153. //Insert into internal handles object and append to element
  2154. this.handles[handle] = ".ui-resizable-"+handle;
  2155. this.element.append(axis);
  2156. }
  2157. }
  2158. this._renderAxis = function(target) {
  2159. var i, axis, padPos, padWrapper;
  2160. target = target || this.element;
  2161. for(i in this.handles) {
  2162. if(this.handles[i].constructor === String) {
  2163. this.handles[i] = $(this.handles[i], this.element).show();
  2164. }
  2165. //Apply pad to wrapper element, needed to fix axis position (textarea, inputs, scrolls)
  2166. if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/textarea|input|select|button/i)) {
  2167. axis = $(this.handles[i], this.element);
  2168. //Checking the correct pad and border
  2169. padWrapper = /sw|ne|nw|se|n|s/.test(i) ? axis.outerHeight() : axis.outerWidth();
  2170. //The padding type i have to apply...
  2171. padPos = [ "padding",
  2172. /ne|nw|n/.test(i) ? "Top" :
  2173. /se|sw|s/.test(i) ? "Bottom" :
  2174. /^e$/.test(i) ? "Right" : "Left" ].join("");
  2175. target.css(padPos, padWrapper);
  2176. this._proportionallyResize();
  2177. }
  2178. //TODO: What's that good for? There's not anything to be executed left
  2179. if(!$(this.handles[i]).length) {
  2180. continue;
  2181. }
  2182. }
  2183. };
  2184. //TODO: make renderAxis a prototype function
  2185. this._renderAxis(this.element);
  2186. this._handles = $(".ui-resizable-handle", this.element)
  2187. .disableSelection();
  2188. //Matching axis name
  2189. this._handles.mouseover(function() {
  2190. if (!that.resizing) {
  2191. if (this.className) {
  2192. axis = this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);
  2193. }
  2194. //Axis, default = se
  2195. that.axis = axis && axis[1] ? axis[1] : "se";
  2196. }
  2197. });
  2198. //If we want to auto hide the elements
  2199. if (o.autoHide) {
  2200. this._handles.hide();
  2201. $(this.element)
  2202. .addClass("ui-resizable-autohide")
  2203. .mouseenter(function() {
  2204. if (o.disabled) {
  2205. return;
  2206. }
  2207. $(this).removeClass("ui-resizable-autohide");
  2208. that._handles.show();
  2209. })
  2210. .mouseleave(function(){
  2211. if (o.disabled) {
  2212. return;
  2213. }
  2214. if (!that.resizing) {
  2215. $(this).addClass("ui-resizable-autohide");
  2216. that._handles.hide();
  2217. }
  2218. });
  2219. }
  2220. //Initialize the mouse interaction
  2221. this._mouseInit();
  2222. },
  2223. _destroy: function() {
  2224. this._mouseDestroy();
  2225. var wrapper,
  2226. _destroy = function(exp) {
  2227. $(exp).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing")
  2228. .removeData("resizable").removeData("ui-resizable").unbind(".resizable").find(".ui-resizable-handle").remove();
  2229. };
  2230. //TODO: Unwrap at same DOM position
  2231. if (this.elementIsWrapper) {
  2232. _destroy(this.element);
  2233. wrapper = this.element;
  2234. this.originalElement.css({
  2235. position: wrapper.css("position"),
  2236. width: wrapper.outerWidth(),
  2237. height: wrapper.outerHeight(),
  2238. top: wrapper.css("top"),
  2239. left: wrapper.css("left")
  2240. }).insertAfter( wrapper );
  2241. wrapper.remove();
  2242. }
  2243. this.originalElement.css("resize", this.originalResizeStyle);
  2244. _destroy(this.originalElement);
  2245. return this;
  2246. },
  2247. _mouseCapture: function(event) {
  2248. var i, handle,
  2249. capture = false;
  2250. for (i in this.handles) {
  2251. handle = $(this.handles[i])[0];
  2252. if (handle === event.target || $.contains(handle, event.target)) {
  2253. capture = true;
  2254. }
  2255. }
  2256. return !this.options.disabled && capture;
  2257. },
  2258. _mouseStart: function(event) {
  2259. var curleft, curtop, cursor,
  2260. o = this.options,
  2261. iniPos = this.element.position(),
  2262. el = this.element;
  2263. this.resizing = true;
  2264. // bugfix for http://dev.jquery.com/ticket/1749
  2265. if ( (/absolute/).test( el.css("position") ) ) {
  2266. el.css({ position: "absolute", top: el.css("top"), left: el.css("left") });
  2267. } else if (el.is(".ui-draggable")) {
  2268. el.css({ position: "absolute", top: iniPos.top, left: iniPos.left });
  2269. }
  2270. this._renderProxy();
  2271. curleft = num(this.helper.css("left"));
  2272. curtop = num(this.helper.css("top"));
  2273. if (o.containment) {
  2274. curleft += $(o.containment).scrollLeft() || 0;
  2275. curtop += $(o.containment).scrollTop() || 0;
  2276. }
  2277. //Store needed variables
  2278. this.offset = this.helper.offset();
  2279. this.position = { left: curleft, top: curtop };
  2280. this.size = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() };
  2281. this.originalSize = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() };
  2282. this.originalPosition = { left: curleft, top: curtop };
  2283. this.sizeDiff = { width: el.outerWidth() - el.width(), height: el.outerHeight() - el.height() };
  2284. this.originalMousePosition = { left: event.pageX, top: event.pageY };
  2285. //Aspect Ratio
  2286. this.aspectRatio = (typeof o.aspectRatio === "number") ? o.aspectRatio : ((this.originalSize.width / this.originalSize.height) || 1);
  2287. cursor = $(".ui-resizable-" + this.axis).css("cursor");
  2288. $("body").css("cursor", cursor === "auto" ? this.axis + "-resize" : cursor);
  2289. el.addClass("ui-resizable-resizing");
  2290. this._propagate("start", event);
  2291. return true;
  2292. },
  2293. _mouseDrag: function(event) {
  2294. //Increase performance, avoid regex
  2295. var data,
  2296. el = this.helper, props = {},
  2297. smp = this.originalMousePosition,
  2298. a = this.axis,
  2299. prevTop = this.position.top,
  2300. prevLeft = this.position.left,
  2301. prevWidth = this.size.width,
  2302. prevHeight = this.size.height,
  2303. dx = (event.pageX-smp.left)||0,
  2304. dy = (event.pageY-smp.top)||0,
  2305. trigger = this._change[a];
  2306. if (!trigger) {
  2307. return false;
  2308. }
  2309. // Calculate the attrs that will be change
  2310. data = trigger.apply(this, [event, dx, dy]);
  2311. // Put this in the mouseDrag handler since the user can start pressing shift while resizing
  2312. this._updateVirtualBoundaries(event.shiftKey);
  2313. if (this._aspectRatio || event.shiftKey) {
  2314. data = this._updateRatio(data, event);
  2315. }
  2316. data = this._respectSize(data, event);
  2317. this._updateCache(data);
  2318. // plugins callbacks need to be called first
  2319. this._propagate("resize", event);
  2320. if (this.position.top !== prevTop) {
  2321. props.top = this.position.top + "px";
  2322. }
  2323. if (this.position.left !== prevLeft) {
  2324. props.left = this.position.left + "px";
  2325. }
  2326. if (this.size.width !== prevWidth) {
  2327. props.width = this.size.width + "px";
  2328. }
  2329. if (this.size.height !== prevHeight) {
  2330. props.height = this.size.height + "px";
  2331. }
  2332. el.css(props);
  2333. if (!this._helper && this._proportionallyResizeElements.length) {
  2334. this._proportionallyResize();
  2335. }
  2336. // Call the user callback if the element was resized
  2337. if ( ! $.isEmptyObject(props) ) {
  2338. this._trigger("resize", event, this.ui());
  2339. }
  2340. return false;
  2341. },
  2342. _mouseStop: function(event) {
  2343. this.resizing = false;
  2344. var pr, ista, soffseth, soffsetw, s, left, top,
  2345. o = this.options, that = this;
  2346. if(this._helper) {
  2347. pr = this._proportionallyResizeElements;
  2348. ista = pr.length && (/textarea/i).test(pr[0].nodeName);
  2349. soffseth = ista && $.ui.hasScroll(pr[0], "left") /* TODO - jump height */ ? 0 : that.sizeDiff.height;
  2350. soffsetw = ista ? 0 : that.sizeDiff.width;
  2351. s = { width: (that.helper.width() - soffsetw), height: (that.helper.height() - soffseth) };
  2352. left = (parseInt(that.element.css("left"), 10) + (that.position.left - that.originalPosition.left)) || null;
  2353. top = (parseInt(that.element.css("top"), 10) + (that.position.top - that.originalPosition.top)) || null;
  2354. if (!o.animate) {
  2355. this.element.css($.extend(s, { top: top, left: left }));
  2356. }
  2357. that.helper.height(that.size.height);
  2358. that.helper.width(that.size.width);
  2359. if (this._helper && !o.animate) {
  2360. this._proportionallyResize();
  2361. }
  2362. }
  2363. $("body").css("cursor", "auto");
  2364. this.element.removeClass("ui-resizable-resizing");
  2365. this._propagate("stop", event);
  2366. if (this._helper) {
  2367. this.helper.remove();
  2368. }
  2369. return false;
  2370. },
  2371. _updateVirtualBoundaries: function(forceAspectRatio) {
  2372. var pMinWidth, pMaxWidth, pMinHeight, pMaxHeight, b,
  2373. o = this.options;
  2374. b = {
  2375. minWidth: isNumber(o.minWidth) ? o.minWidth : 0,
  2376. maxWidth: isNumber(o.maxWidth) ? o.maxWidth : Infinity,
  2377. minHeight: isNumber(o.minHeight) ? o.minHeight : 0,
  2378. maxHeight: isNumber(o.maxHeight) ? o.maxHeight : Infinity
  2379. };
  2380. if(this._aspectRatio || forceAspectRatio) {
  2381. // We want to create an enclosing box whose aspect ration is the requested one
  2382. // First, compute the "projected" size for each dimension based on the aspect ratio and other dimension
  2383. pMinWidth = b.minHeight * this.aspectRatio;
  2384. pMinHeight = b.minWidth / this.aspectRatio;
  2385. pMaxWidth = b.maxHeight * this.aspectRatio;
  2386. pMaxHeight = b.maxWidth / this.aspectRatio;
  2387. if(pMinWidth > b.minWidth) {
  2388. b.minWidth = pMinWidth;
  2389. }
  2390. if(pMinHeight > b.minHeight) {
  2391. b.minHeight = pMinHeight;
  2392. }
  2393. if(pMaxWidth < b.maxWidth) {
  2394. b.maxWidth = pMaxWidth;
  2395. }
  2396. if(pMaxHeight < b.maxHeight) {
  2397. b.maxHeight = pMaxHeight;
  2398. }
  2399. }
  2400. this._vBoundaries = b;
  2401. },
  2402. _updateCache: function(data) {
  2403. this.offset = this.helper.offset();
  2404. if (isNumber(data.left)) {
  2405. this.position.left = data.left;
  2406. }
  2407. if (isNumber(data.top)) {
  2408. this.position.top = data.top;
  2409. }
  2410. if (isNumber(data.height)) {
  2411. this.size.height = data.height;
  2412. }
  2413. if (isNumber(data.width)) {
  2414. this.size.width = data.width;
  2415. }
  2416. },
  2417. _updateRatio: function( data ) {
  2418. var cpos = this.position,
  2419. csize = this.size,
  2420. a = this.axis;
  2421. if (isNumber(data.height)) {
  2422. data.width = (data.height * this.aspectRatio);
  2423. } else if (isNumber(data.width)) {
  2424. data.height = (data.width / this.aspectRatio);
  2425. }
  2426. if (a === "sw") {
  2427. data.left = cpos.left + (csize.width - data.width);
  2428. data.top = null;
  2429. }
  2430. if (a === "nw") {
  2431. data.top = cpos.top + (csize.height - data.height);
  2432. data.left = cpos.left + (csize.width - data.width);
  2433. }
  2434. return data;
  2435. },
  2436. _respectSize: function( data ) {
  2437. var o = this._vBoundaries,
  2438. a = this.axis,
  2439. ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height),
  2440. isminw = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height),
  2441. dw = this.originalPosition.left + this.originalSize.width,
  2442. dh = this.position.top + this.size.height,
  2443. cw = /sw|nw|w/.test(a), ch = /nw|ne|n/.test(a);
  2444. if (isminw) {
  2445. data.width = o.minWidth;
  2446. }
  2447. if (isminh) {
  2448. data.height = o.minHeight;
  2449. }
  2450. if (ismaxw) {
  2451. data.width = o.maxWidth;
  2452. }
  2453. if (ismaxh) {
  2454. data.height = o.maxHeight;
  2455. }
  2456. if (isminw && cw) {
  2457. data.left = dw - o.minWidth;
  2458. }
  2459. if (ismaxw && cw) {
  2460. data.left = dw - o.maxWidth;
  2461. }
  2462. if (isminh && ch) {
  2463. data.top = dh - o.minHeight;
  2464. }
  2465. if (ismaxh && ch) {
  2466. data.top = dh - o.maxHeight;
  2467. }
  2468. // fixing jump error on top/left - bug #2330
  2469. if (!data.width && !data.height && !data.left && data.top) {
  2470. data.top = null;
  2471. } else if (!data.width && !data.height && !data.top && data.left) {
  2472. data.left = null;
  2473. }
  2474. return data;
  2475. },
  2476. _proportionallyResize: function() {
  2477. if (!this._proportionallyResizeElements.length) {
  2478. return;
  2479. }
  2480. var i, j, borders, paddings, prel,
  2481. element = this.helper || this.element;
  2482. for ( i=0; i < this._proportionallyResizeElements.length; i++) {
  2483. prel = this._proportionallyResizeElements[i];
  2484. if (!this.borderDif) {
  2485. this.borderDif = [];
  2486. borders = [prel.css("borderTopWidth"), prel.css("borderRightWidth"), prel.css("borderBottomWidth"), prel.css("borderLeftWidth")];
  2487. paddings = [prel.css("paddingTop"), prel.css("paddingRight"), prel.css("paddingBottom"), prel.css("paddingLeft")];
  2488. for ( j = 0; j < borders.length; j++ ) {
  2489. this.borderDif[ j ] = ( parseInt( borders[ j ], 10 ) || 0 ) + ( parseInt( paddings[ j ], 10 ) || 0 );
  2490. }
  2491. }
  2492. prel.css({
  2493. height: (element.height() - this.borderDif[0] - this.borderDif[2]) || 0,
  2494. width: (element.width() - this.borderDif[1] - this.borderDif[3]) || 0
  2495. });
  2496. }
  2497. },
  2498. _renderProxy: function() {
  2499. var el = this.element, o = this.options;
  2500. this.elementOffset = el.offset();
  2501. if(this._helper) {
  2502. this.helper = this.helper || $("<div style='overflow:hidden;'></div>");
  2503. this.helper.addClass(this._helper).css({
  2504. width: this.element.outerWidth() - 1,
  2505. height: this.element.outerHeight() - 1,
  2506. position: "absolute",
  2507. left: this.elementOffset.left +"px",
  2508. top: this.elementOffset.top +"px",
  2509. zIndex: ++o.zIndex //TODO: Don't modify option
  2510. });
  2511. this.helper
  2512. .appendTo("body")
  2513. .disableSelection();
  2514. } else {
  2515. this.helper = this.element;
  2516. }
  2517. },
  2518. _change: {
  2519. e: function(event, dx) {
  2520. return { width: this.originalSize.width + dx };
  2521. },
  2522. w: function(event, dx) {
  2523. var cs = this.originalSize, sp = this.originalPosition;
  2524. return { left: sp.left + dx, width: cs.width - dx };
  2525. },
  2526. n: function(event, dx, dy) {
  2527. var cs = this.originalSize, sp = this.originalPosition;
  2528. return { top: sp.top + dy, height: cs.height - dy };
  2529. },
  2530. s: function(event, dx, dy) {
  2531. return { height: this.originalSize.height + dy };
  2532. },
  2533. se: function(event, dx, dy) {
  2534. return $.extend(this._change.s.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
  2535. },
  2536. sw: function(event, dx, dy) {
  2537. return $.extend(this._change.s.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
  2538. },
  2539. ne: function(event, dx, dy) {
  2540. return $.extend(this._change.n.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
  2541. },
  2542. nw: function(event, dx, dy) {
  2543. return $.extend(this._change.n.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
  2544. }
  2545. },
  2546. _propagate: function(n, event) {
  2547. $.ui.plugin.call(this, n, [event, this.ui()]);
  2548. (n !== "resize" && this._trigger(n, event, this.ui()));
  2549. },
  2550. plugins: {},
  2551. ui: function() {
  2552. return {
  2553. originalElement: this.originalElement,
  2554. element: this.element,
  2555. helper: this.helper,
  2556. position: this.position,
  2557. size: this.size,
  2558. originalSize: this.originalSize,
  2559. originalPosition: this.originalPosition
  2560. };
  2561. }
  2562. });
  2563. /*
  2564. * Resizable Extensions
  2565. */
  2566. $.ui.plugin.add("resizable", "animate", {
  2567. stop: function( event ) {
  2568. var that = $(this).data("ui-resizable"),
  2569. o = that.options,
  2570. pr = that._proportionallyResizeElements,
  2571. ista = pr.length && (/textarea/i).test(pr[0].nodeName),
  2572. soffseth = ista && $.ui.hasScroll(pr[0], "left") /* TODO - jump height */ ? 0 : that.sizeDiff.height,
  2573. soffsetw = ista ? 0 : that.sizeDiff.width,
  2574. style = { width: (that.size.width - soffsetw), height: (that.size.height - soffseth) },
  2575. left = (parseInt(that.element.css("left"), 10) + (that.position.left - that.originalPosition.left)) || null,
  2576. top = (parseInt(that.element.css("top"), 10) + (that.position.top - that.originalPosition.top)) || null;
  2577. that.element.animate(
  2578. $.extend(style, top && left ? { top: top, left: left } : {}), {
  2579. duration: o.animateDuration,
  2580. easing: o.animateEasing,
  2581. step: function() {
  2582. var data = {
  2583. width: parseInt(that.element.css("width"), 10),
  2584. height: parseInt(that.element.css("height"), 10),
  2585. top: parseInt(that.element.css("top"), 10),
  2586. left: parseInt(that.element.css("left"), 10)
  2587. };
  2588. if (pr && pr.length) {
  2589. $(pr[0]).css({ width: data.width, height: data.height });
  2590. }
  2591. // propagating resize, and updating values for each animation step
  2592. that._updateCache(data);
  2593. that._propagate("resize", event);
  2594. }
  2595. }
  2596. );
  2597. }
  2598. });
  2599. $.ui.plugin.add("resizable", "containment", {
  2600. start: function() {
  2601. var element, p, co, ch, cw, width, height,
  2602. that = $(this).data("ui-resizable"),
  2603. o = that.options,
  2604. el = that.element,
  2605. oc = o.containment,
  2606. ce = (oc instanceof $) ? oc.get(0) : (/parent/.test(oc)) ? el.parent().get(0) : oc;
  2607. if (!ce) {
  2608. return;
  2609. }
  2610. that.containerElement = $(ce);
  2611. if (/document/.test(oc) || oc === document) {
  2612. that.containerOffset = { left: 0, top: 0 };
  2613. that.containerPosition = { left: 0, top: 0 };
  2614. that.parentData = {
  2615. element: $(document), left: 0, top: 0,
  2616. width: $(document).width(), height: $(document).height() || document.body.parentNode.scrollHeight
  2617. };
  2618. }
  2619. // i'm a node, so compute top, left, right, bottom
  2620. else {
  2621. element = $(ce);
  2622. p = [];
  2623. $([ "Top", "Right", "Left", "Bottom" ]).each(function(i, name) { p[i] = num(element.css("padding" + name)); });
  2624. that.containerOffset = element.offset();
  2625. that.containerPosition = element.position();
  2626. that.containerSize = { height: (element.innerHeight() - p[3]), width: (element.innerWidth() - p[1]) };
  2627. co = that.containerOffset;
  2628. ch = that.containerSize.height;
  2629. cw = that.containerSize.width;
  2630. width = ($.ui.hasScroll(ce, "left") ? ce.scrollWidth : cw );
  2631. height = ($.ui.hasScroll(ce) ? ce.scrollHeight : ch);
  2632. that.parentData = {
  2633. element: ce, left: co.left, top: co.top, width: width, height: height
  2634. };
  2635. }
  2636. },
  2637. resize: function( event ) {
  2638. var woset, hoset, isParent, isOffsetRelative,
  2639. that = $(this).data("ui-resizable"),
  2640. o = that.options,
  2641. co = that.containerOffset, cp = that.position,
  2642. pRatio = that._aspectRatio || event.shiftKey,
  2643. cop = { top:0, left:0 }, ce = that.containerElement;
  2644. if (ce[0] !== document && (/static/).test(ce.css("position"))) {
  2645. cop = co;
  2646. }
  2647. if (cp.left < (that._helper ? co.left : 0)) {
  2648. that.size.width = that.size.width + (that._helper ? (that.position.left - co.left) : (that.position.left - cop.left));
  2649. if (pRatio) {
  2650. that.size.height = that.size.width / that.aspectRatio;
  2651. }
  2652. that.position.left = o.helper ? co.left : 0;
  2653. }
  2654. if (cp.top < (that._helper ? co.top : 0)) {
  2655. that.size.height = that.size.height + (that._helper ? (that.position.top - co.top) : that.position.top);
  2656. if (pRatio) {
  2657. that.size.width = that.size.height * that.aspectRatio;
  2658. }
  2659. that.position.top = that._helper ? co.top : 0;
  2660. }
  2661. that.offset.left = that.parentData.left+that.position.left;
  2662. that.offset.top = that.parentData.top+that.position.top;
  2663. woset = Math.abs( (that._helper ? that.offset.left - cop.left : (that.offset.left - cop.left)) + that.sizeDiff.width );
  2664. hoset = Math.abs( (that._helper ? that.offset.top - cop.top : (that.offset.top - co.top)) + that.sizeDiff.height );
  2665. isParent = that.containerElement.get(0) === that.element.parent().get(0);
  2666. isOffsetRelative = /relative|absolute/.test(that.containerElement.css("position"));
  2667. if(isParent && isOffsetRelative) {
  2668. woset -= that.parentData.left;
  2669. }
  2670. if (woset + that.size.width >= that.parentData.width) {
  2671. that.size.width = that.parentData.width - woset;
  2672. if (pRatio) {
  2673. that.size.height = that.size.width / that.aspectRatio;
  2674. }
  2675. }
  2676. if (hoset + that.size.height >= that.parentData.height) {
  2677. that.size.height = that.parentData.height - hoset;
  2678. if (pRatio) {
  2679. that.size.width = that.size.height * that.aspectRatio;
  2680. }
  2681. }
  2682. },
  2683. stop: function(){
  2684. var that = $(this).data("ui-resizable"),
  2685. o = that.options,
  2686. co = that.containerOffset,
  2687. cop = that.containerPosition,
  2688. ce = that.containerElement,
  2689. helper = $(that.helper),
  2690. ho = helper.offset(),
  2691. w = helper.outerWidth() - that.sizeDiff.width,
  2692. h = helper.outerHeight() - that.sizeDiff.height;
  2693. if (that._helper && !o.animate && (/relative/).test(ce.css("position"))) {
  2694. $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
  2695. }
  2696. if (that._helper && !o.animate && (/static/).test(ce.css("position"))) {
  2697. $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
  2698. }
  2699. }
  2700. });
  2701. $.ui.plugin.add("resizable", "alsoResize", {
  2702. start: function () {
  2703. var that = $(this).data("ui-resizable"),
  2704. o = that.options,
  2705. _store = function (exp) {
  2706. $(exp).each(function() {
  2707. var el = $(this);
  2708. el.data("ui-resizable-alsoresize", {
  2709. width: parseInt(el.width(), 10), height: parseInt(el.height(), 10),
  2710. left: parseInt(el.css("left"), 10), top: parseInt(el.css("top"), 10)
  2711. });
  2712. });
  2713. };
  2714. if (typeof(o.alsoResize) === "object" && !o.alsoResize.parentNode) {
  2715. if (o.alsoResize.length) { o.alsoResize = o.alsoResize[0]; _store(o.alsoResize); }
  2716. else { $.each(o.alsoResize, function (exp) { _store(exp); }); }
  2717. }else{
  2718. _store(o.alsoResize);
  2719. }
  2720. },
  2721. resize: function (event, ui) {
  2722. var that = $(this).data("ui-resizable"),
  2723. o = that.options,
  2724. os = that.originalSize,
  2725. op = that.originalPosition,
  2726. delta = {
  2727. height: (that.size.height - os.height) || 0, width: (that.size.width - os.width) || 0,
  2728. top: (that.position.top - op.top) || 0, left: (that.position.left - op.left) || 0
  2729. },
  2730. _alsoResize = function (exp, c) {
  2731. $(exp).each(function() {
  2732. var el = $(this), start = $(this).data("ui-resizable-alsoresize"), style = {},
  2733. css = c && c.length ? c : el.parents(ui.originalElement[0]).length ? ["width", "height"] : ["width", "height", "top", "left"];
  2734. $.each(css, function (i, prop) {
  2735. var sum = (start[prop]||0) + (delta[prop]||0);
  2736. if (sum && sum >= 0) {
  2737. style[prop] = sum || null;
  2738. }
  2739. });
  2740. el.css(style);
  2741. });
  2742. };
  2743. if (typeof(o.alsoResize) === "object" && !o.alsoResize.nodeType) {
  2744. $.each(o.alsoResize, function (exp, c) { _alsoResize(exp, c); });
  2745. }else{
  2746. _alsoResize(o.alsoResize);
  2747. }
  2748. },
  2749. stop: function () {
  2750. $(this).removeData("resizable-alsoresize");
  2751. }
  2752. });
  2753. $.ui.plugin.add("resizable", "ghost", {
  2754. start: function() {
  2755. var that = $(this).data("ui-resizable"), o = that.options, cs = that.size;
  2756. that.ghost = that.originalElement.clone();
  2757. that.ghost
  2758. .css({ opacity: 0.25, display: "block", position: "relative", height: cs.height, width: cs.width, margin: 0, left: 0, top: 0 })
  2759. .addClass("ui-resizable-ghost")
  2760. .addClass(typeof o.ghost === "string" ? o.ghost : "");
  2761. that.ghost.appendTo(that.helper);
  2762. },
  2763. resize: function(){
  2764. var that = $(this).data("ui-resizable");
  2765. if (that.ghost) {
  2766. that.ghost.css({ position: "relative", height: that.size.height, width: that.size.width });
  2767. }
  2768. },
  2769. stop: function() {
  2770. var that = $(this).data("ui-resizable");
  2771. if (that.ghost && that.helper) {
  2772. that.helper.get(0).removeChild(that.ghost.get(0));
  2773. }
  2774. }
  2775. });
  2776. $.ui.plugin.add("resizable", "grid", {
  2777. resize: function() {
  2778. var that = $(this).data("ui-resizable"),
  2779. o = that.options,
  2780. cs = that.size,
  2781. os = that.originalSize,
  2782. op = that.originalPosition,
  2783. a = that.axis,
  2784. grid = typeof o.grid === "number" ? [o.grid, o.grid] : o.grid,
  2785. gridX = (grid[0]||1),
  2786. gridY = (grid[1]||1),
  2787. ox = Math.round((cs.width - os.width) / gridX) * gridX,
  2788. oy = Math.round((cs.height - os.height) / gridY) * gridY,
  2789. newWidth = os.width + ox,
  2790. newHeight = os.height + oy,
  2791. isMaxWidth = o.maxWidth && (o.maxWidth < newWidth),
  2792. isMaxHeight = o.maxHeight && (o.maxHeight < newHeight),
  2793. isMinWidth = o.minWidth && (o.minWidth > newWidth),
  2794. isMinHeight = o.minHeight && (o.minHeight > newHeight);
  2795. o.grid = grid;
  2796. if (isMinWidth) {
  2797. newWidth = newWidth + gridX;
  2798. }
  2799. if (isMinHeight) {
  2800. newHeight = newHeight + gridY;
  2801. }
  2802. if (isMaxWidth) {
  2803. newWidth = newWidth - gridX;
  2804. }
  2805. if (isMaxHeight) {
  2806. newHeight = newHeight - gridY;
  2807. }
  2808. if (/^(se|s|e)$/.test(a)) {
  2809. that.size.width = newWidth;
  2810. that.size.height = newHeight;
  2811. } else if (/^(ne)$/.test(a)) {
  2812. that.size.width = newWidth;
  2813. that.size.height = newHeight;
  2814. that.position.top = op.top - oy;
  2815. } else if (/^(sw)$/.test(a)) {
  2816. that.size.width = newWidth;
  2817. that.size.height = newHeight;
  2818. that.position.left = op.left - ox;
  2819. } else {
  2820. that.size.width = newWidth;
  2821. that.size.height = newHeight;
  2822. that.position.top = op.top - oy;
  2823. that.position.left = op.left - ox;
  2824. }
  2825. }
  2826. });
  2827. })(jQuery);
  2828. (function( $, undefined ) {
  2829. // used to prevent race conditions with remote data sources
  2830. var requestIndex = 0;
  2831. $.widget( "ui.autocomplete", {
  2832. version: "1.10.1",
  2833. defaultElement: "<input>",
  2834. options: {
  2835. appendTo: null,
  2836. autoFocus: false,
  2837. delay: 300,
  2838. minLength: 1,
  2839. position: {
  2840. my: "left top",
  2841. at: "left bottom",
  2842. collision: "none"
  2843. },
  2844. source: null,
  2845. // callbacks
  2846. change: null,
  2847. close: null,
  2848. focus: null,
  2849. open: null,
  2850. response: null,
  2851. search: null,
  2852. select: null
  2853. },
  2854. pending: 0,
  2855. _create: function() {
  2856. // Some browsers only repeat keydown events, not keypress events,
  2857. // so we use the suppressKeyPress flag to determine if we've already
  2858. // handled the keydown event. #7269
  2859. // Unfortunately the code for & in keypress is the same as the up arrow,
  2860. // so we use the suppressKeyPressRepeat flag to avoid handling keypress
  2861. // events when we know the keydown event was used to modify the
  2862. // search term. #7799
  2863. var suppressKeyPress, suppressKeyPressRepeat, suppressInput,
  2864. nodeName = this.element[0].nodeName.toLowerCase(),
  2865. isTextarea = nodeName === "textarea",
  2866. isInput = nodeName === "input";
  2867. this.isMultiLine =
  2868. // Textareas are always multi-line
  2869. isTextarea ? true :
  2870. // Inputs are always single-line, even if inside a contentEditable element
  2871. // IE also treats inputs as contentEditable
  2872. isInput ? false :
  2873. // All other element types are determined by whether or not they're contentEditable
  2874. this.element.prop( "isContentEditable" );
  2875. this.valueMethod = this.element[ isTextarea || isInput ? "val" : "text" ];
  2876. this.isNewMenu = true;
  2877. this.element
  2878. .addClass( "ui-autocomplete-input" )
  2879. .attr( "autocomplete", "off" );
  2880. this._on( this.element, {
  2881. keydown: function( event ) {
  2882. /*jshint maxcomplexity:15*/
  2883. if ( this.element.prop( "readOnly" ) ) {
  2884. suppressKeyPress = true;
  2885. suppressInput = true;
  2886. suppressKeyPressRepeat = true;
  2887. return;
  2888. }
  2889. suppressKeyPress = false;
  2890. suppressInput = false;
  2891. suppressKeyPressRepeat = false;
  2892. var keyCode = $.ui.keyCode;
  2893. switch( event.keyCode ) {
  2894. case keyCode.PAGE_UP:
  2895. suppressKeyPress = true;
  2896. this._move( "previousPage", event );
  2897. break;
  2898. case keyCode.PAGE_DOWN:
  2899. suppressKeyPress = true;
  2900. this._move( "nextPage", event );
  2901. break;
  2902. case keyCode.UP:
  2903. suppressKeyPress = true;
  2904. this._keyEvent( "previous", event );
  2905. break;
  2906. case keyCode.DOWN:
  2907. suppressKeyPress = true;
  2908. this._keyEvent( "next", event );
  2909. break;
  2910. case keyCode.ENTER:
  2911. case keyCode.NUMPAD_ENTER:
  2912. // when menu is open and has focus
  2913. if ( this.menu.active ) {
  2914. // #6055 - Opera still allows the keypress to occur
  2915. // which causes forms to submit
  2916. suppressKeyPress = true;
  2917. event.preventDefault();
  2918. this.menu.select( event );
  2919. }
  2920. break;
  2921. case keyCode.TAB:
  2922. if ( this.menu.active ) {
  2923. this.menu.select( event );
  2924. }
  2925. break;
  2926. case keyCode.ESCAPE:
  2927. if ( this.menu.element.is( ":visible" ) ) {
  2928. this._value( this.term );
  2929. this.close( event );
  2930. // Different browsers have different default behavior for escape
  2931. // Single press can mean undo or clear
  2932. // Double press in IE means clear the whole form
  2933. event.preventDefault();
  2934. }
  2935. break;
  2936. default:
  2937. suppressKeyPressRepeat = true;
  2938. // search timeout should be triggered before the input value is changed
  2939. this._searchTimeout( event );
  2940. break;
  2941. }
  2942. },
  2943. keypress: function( event ) {
  2944. if ( suppressKeyPress ) {
  2945. suppressKeyPress = false;
  2946. event.preventDefault();
  2947. return;
  2948. }
  2949. if ( suppressKeyPressRepeat ) {
  2950. return;
  2951. }
  2952. // replicate some key handlers to allow them to repeat in Firefox and Opera
  2953. var keyCode = $.ui.keyCode;
  2954. switch( event.keyCode ) {
  2955. case keyCode.PAGE_UP:
  2956. this._move( "previousPage", event );
  2957. break;
  2958. case keyCode.PAGE_DOWN:
  2959. this._move( "nextPage", event );
  2960. break;
  2961. case keyCode.UP:
  2962. this._keyEvent( "previous", event );
  2963. break;
  2964. case keyCode.DOWN:
  2965. this._keyEvent( "next", event );
  2966. break;
  2967. }
  2968. },
  2969. input: function( event ) {
  2970. if ( suppressInput ) {
  2971. suppressInput = false;
  2972. event.preventDefault();
  2973. return;
  2974. }
  2975. this._searchTimeout( event );
  2976. },
  2977. focus: function() {
  2978. this.selectedItem = null;
  2979. this.previous = this._value();
  2980. },
  2981. blur: function( event ) {
  2982. if ( this.cancelBlur ) {
  2983. delete this.cancelBlur;
  2984. return;
  2985. }
  2986. clearTimeout( this.searching );
  2987. this.close( event );
  2988. this._change( event );
  2989. }
  2990. });
  2991. this._initSource();
  2992. this.menu = $( "<ul>" )
  2993. .addClass( "ui-autocomplete ui-front" )
  2994. .appendTo( this._appendTo() )
  2995. .menu({
  2996. // custom key handling for now
  2997. input: $(),
  2998. // disable ARIA support, the live region takes care of that
  2999. role: null
  3000. })
  3001. .hide()
  3002. .data( "ui-menu" );
  3003. this._on( this.menu.element, {
  3004. mousedown: function( event ) {
  3005. // prevent moving focus out of the text field
  3006. event.preventDefault();
  3007. // IE doesn't prevent moving focus even with event.preventDefault()
  3008. // so we set a flag to know when we should ignore the blur event
  3009. this.cancelBlur = true;
  3010. this._delay(function() {
  3011. delete this.cancelBlur;
  3012. });
  3013. // clicking on the scrollbar causes focus to shift to the body
  3014. // but we can't detect a mouseup or a click immediately afterward
  3015. // so we have to track the next mousedown and close the menu if
  3016. // the user clicks somewhere outside of the autocomplete
  3017. var menuElement = this.menu.element[ 0 ];
  3018. if ( !$( event.target ).closest( ".ui-menu-item" ).length ) {
  3019. this._delay(function() {
  3020. var that = this;
  3021. this.document.one( "mousedown", function( event ) {
  3022. if ( event.target !== that.element[ 0 ] &&
  3023. event.target !== menuElement &&
  3024. !$.contains( menuElement, event.target ) ) {
  3025. that.close();
  3026. }
  3027. });
  3028. });
  3029. }
  3030. },
  3031. menufocus: function( event, ui ) {
  3032. // #7024 - Prevent accidental activation of menu items in Firefox
  3033. if ( this.isNewMenu ) {
  3034. this.isNewMenu = false;
  3035. if ( event.originalEvent && /^mouse/.test( event.originalEvent.type ) ) {
  3036. this.menu.blur();
  3037. this.document.one( "mousemove", function() {
  3038. $( event.target ).trigger( event.originalEvent );
  3039. });
  3040. return;
  3041. }
  3042. }
  3043. var item = ui.item.data( "ui-autocomplete-item" );
  3044. if ( false !== this._trigger( "focus", event, { item: item } ) ) {
  3045. // use value to match what will end up in the input, if it was a key event
  3046. if ( event.originalEvent && /^key/.test( event.originalEvent.type ) ) {
  3047. this._value( item.value );
  3048. }
  3049. } else {
  3050. // Normally the input is populated with the item's value as the
  3051. // menu is navigated, causing screen readers to notice a change and
  3052. // announce the item. Since the focus event was canceled, this doesn't
  3053. // happen, so we update the live region so that screen readers can
  3054. // still notice the change and announce it.
  3055. this.liveRegion.text( item.value );
  3056. }
  3057. },
  3058. menuselect: function( event, ui ) {
  3059. var item = ui.item.data( "ui-autocomplete-item" ),
  3060. previous = this.previous;
  3061. // only trigger when focus was lost (click on menu)
  3062. if ( this.element[0] !== this.document[0].activeElement ) {
  3063. this.element.focus();
  3064. this.previous = previous;
  3065. // #6109 - IE triggers two focus events and the second
  3066. // is asynchronous, so we need to reset the previous
  3067. // term synchronously and asynchronously :-(
  3068. this._delay(function() {
  3069. this.previous = previous;
  3070. this.selectedItem = item;
  3071. });
  3072. }
  3073. if ( false !== this._trigger( "select", event, { item: item } ) ) {
  3074. this._value( item.value );
  3075. }
  3076. // reset the term after the select event
  3077. // this allows custom select handling to work properly
  3078. this.term = this._value();
  3079. this.close( event );
  3080. this.selectedItem = item;
  3081. }
  3082. });
  3083. this.liveRegion = $( "<span>", {
  3084. role: "status",
  3085. "aria-live": "polite"
  3086. })
  3087. .addClass( "ui-helper-hidden-accessible" )
  3088. .insertAfter( this.element );
  3089. // turning off autocomplete prevents the browser from remembering the
  3090. // value when navigating through history, so we re-enable autocomplete
  3091. // if the page is unloaded before the widget is destroyed. #7790
  3092. this._on( this.window, {
  3093. beforeunload: function() {
  3094. this.element.removeAttr( "autocomplete" );
  3095. }
  3096. });
  3097. },
  3098. _destroy: function() {
  3099. clearTimeout( this.searching );
  3100. this.element
  3101. .removeClass( "ui-autocomplete-input" )
  3102. .removeAttr( "autocomplete" );
  3103. this.menu.element.remove();
  3104. this.liveRegion.remove();
  3105. },
  3106. _setOption: function( key, value ) {
  3107. this._super( key, value );
  3108. if ( key === "source" ) {
  3109. this._initSource();
  3110. }
  3111. if ( key === "appendTo" ) {
  3112. this.menu.element.appendTo( this._appendTo() );
  3113. }
  3114. if ( key === "disabled" && value && this.xhr ) {
  3115. this.xhr.abort();
  3116. }
  3117. },
  3118. _appendTo: function() {
  3119. var element = this.options.appendTo;
  3120. if ( element ) {
  3121. element = element.jquery || element.nodeType ?
  3122. $( element ) :
  3123. this.document.find( element ).eq( 0 );
  3124. }
  3125. if ( !element ) {
  3126. element = this.element.closest( ".ui-front" );
  3127. }
  3128. if ( !element.length ) {
  3129. element = this.document[0].body;
  3130. }
  3131. return element;
  3132. },
  3133. _initSource: function() {
  3134. var array, url,
  3135. that = this;
  3136. if ( $.isArray(this.options.source) ) {
  3137. array = this.options.source;
  3138. this.source = function( request, response ) {
  3139. response( $.ui.autocomplete.filter( array, request.term ) );
  3140. };
  3141. } else if ( typeof this.options.source === "string" ) {
  3142. url = this.options.source;
  3143. this.source = function( request, response ) {
  3144. if ( that.xhr ) {
  3145. that.xhr.abort();
  3146. }
  3147. that.xhr = $.ajax({
  3148. url: url,
  3149. data: request,
  3150. dataType: "json",
  3151. success: function( data ) {
  3152. response( data );
  3153. },
  3154. error: function() {
  3155. response( [] );
  3156. }
  3157. });
  3158. };
  3159. } else {
  3160. this.source = this.options.source;
  3161. }
  3162. },
  3163. _searchTimeout: function( event ) {
  3164. clearTimeout( this.searching );
  3165. this.searching = this._delay(function() {
  3166. // only search if the value has changed
  3167. if ( this.term !== this._value() ) {
  3168. this.selectedItem = null;
  3169. this.search( null, event );
  3170. }
  3171. }, this.options.delay );
  3172. },
  3173. search: function( value, event ) {
  3174. value = value != null ? value : this._value();
  3175. // always save the actual value, not the one passed as an argument
  3176. this.term = this._value();
  3177. if ( value.length < this.options.minLength ) {
  3178. return this.close( event );
  3179. }
  3180. if ( this._trigger( "search", event ) === false ) {
  3181. return;
  3182. }
  3183. return this._search( value );
  3184. },
  3185. _search: function( value ) {
  3186. this.pending++;
  3187. this.element.addClass( "ui-autocomplete-loading" );
  3188. this.cancelSearch = false;
  3189. this.source( { term: value }, this._response() );
  3190. },
  3191. _response: function() {
  3192. var that = this,
  3193. index = ++requestIndex;
  3194. return function( content ) {
  3195. if ( index === requestIndex ) {
  3196. that.__response( content );
  3197. }
  3198. that.pending--;
  3199. if ( !that.pending ) {
  3200. that.element.removeClass( "ui-autocomplete-loading" );
  3201. }
  3202. };
  3203. },
  3204. __response: function( content ) {
  3205. if ( content ) {
  3206. content = this._normalize( content );
  3207. }
  3208. this._trigger( "response", null, { content: content } );
  3209. if ( !this.options.disabled && content && content.length && !this.cancelSearch ) {
  3210. this._suggest( content );
  3211. this._trigger( "open" );
  3212. } else {
  3213. // use ._close() instead of .close() so we don't cancel future searches
  3214. this._close();
  3215. }
  3216. },
  3217. close: function( event ) {
  3218. this.cancelSearch = true;
  3219. this._close( event );
  3220. },
  3221. _close: function( event ) {
  3222. if ( this.menu.element.is( ":visible" ) ) {
  3223. this.menu.element.hide();
  3224. this.menu.blur();
  3225. this.isNewMenu = true;
  3226. this._trigger( "close", event );
  3227. }
  3228. },
  3229. _change: function( event ) {
  3230. if ( this.previous !== this._value() ) {
  3231. this._trigger( "change", event, { item: this.selectedItem } );
  3232. }
  3233. },
  3234. _normalize: function( items ) {
  3235. // assume all items have the right format when the first item is complete
  3236. if ( items.length && items[0].label && items[0].value ) {
  3237. return items;
  3238. }
  3239. return $.map( items, function( item ) {
  3240. if ( typeof item === "string" ) {
  3241. return {
  3242. label: item,
  3243. value: item
  3244. };
  3245. }
  3246. return $.extend({
  3247. label: item.label || item.value,
  3248. value: item.value || item.label
  3249. }, item );
  3250. });
  3251. },
  3252. _suggest: function( items ) {
  3253. var ul = this.menu.element.empty();
  3254. this._renderMenu( ul, items );
  3255. this.menu.refresh();
  3256. // size and position menu
  3257. ul.show();
  3258. this._resizeMenu();
  3259. ul.position( $.extend({
  3260. of: this.element
  3261. }, this.options.position ));
  3262. if ( this.options.autoFocus ) {
  3263. this.menu.next();
  3264. }
  3265. },
  3266. _resizeMenu: function() {
  3267. var ul = this.menu.element;
  3268. ul.outerWidth( Math.max(
  3269. // Firefox wraps long text (possibly a rounding bug)
  3270. // so we add 1px to avoid the wrapping (#7513)
  3271. ul.width( "" ).outerWidth() + 1,
  3272. this.element.outerWidth()
  3273. ) );
  3274. },
  3275. _renderMenu: function( ul, items ) {
  3276. var that = this;
  3277. $.each( items, function( index, item ) {
  3278. that._renderItemData( ul, item );
  3279. });
  3280. },
  3281. _renderItemData: function( ul, item ) {
  3282. return this._renderItem( ul, item ).data( "ui-autocomplete-item", item );
  3283. },
  3284. _renderItem: function( ul, item ) {
  3285. return $( "<li>" )
  3286. .append( $( "<a>" ).text( item.label ) )
  3287. .appendTo( ul );
  3288. },
  3289. _move: function( direction, event ) {
  3290. if ( !this.menu.element.is( ":visible" ) ) {
  3291. this.search( null, event );
  3292. return;
  3293. }
  3294. if ( this.menu.isFirstItem() && /^previous/.test( direction ) ||
  3295. this.menu.isLastItem() && /^next/.test( direction ) ) {
  3296. this._value( this.term );
  3297. this.menu.blur();
  3298. return;
  3299. }
  3300. this.menu[ direction ]( event );
  3301. },
  3302. widget: function() {
  3303. return this.menu.element;
  3304. },
  3305. _value: function() {
  3306. return this.valueMethod.apply( this.element, arguments );
  3307. },
  3308. _keyEvent: function( keyEvent, event ) {
  3309. if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
  3310. this._move( keyEvent, event );
  3311. // prevents moving cursor to beginning/end of the text field in some browsers
  3312. event.preventDefault();
  3313. }
  3314. }
  3315. });
  3316. $.extend( $.ui.autocomplete, {
  3317. escapeRegex: function( value ) {
  3318. return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
  3319. },
  3320. filter: function(array, term) {
  3321. var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
  3322. return $.grep( array, function(value) {
  3323. return matcher.test( value.label || value.value || value );
  3324. });
  3325. }
  3326. });
  3327. // live region extension, adding a `messages` option
  3328. // NOTE: This is an experimental API. We are still investigating
  3329. // a full solution for string manipulation and internationalization.
  3330. $.widget( "ui.autocomplete", $.ui.autocomplete, {
  3331. options: {
  3332. messages: {
  3333. noResults: "No search results.",
  3334. results: function( amount ) {
  3335. return amount + ( amount > 1 ? " results are" : " result is" ) +
  3336. " available, use up and down arrow keys to navigate.";
  3337. }
  3338. }
  3339. },
  3340. __response: function( content ) {
  3341. var message;
  3342. this._superApply( arguments );
  3343. if ( this.options.disabled || this.cancelSearch ) {
  3344. return;
  3345. }
  3346. if ( content && content.length ) {
  3347. message = this.options.messages.results( content.length );
  3348. } else {
  3349. message = this.options.messages.noResults;
  3350. }
  3351. this.liveRegion.text( message );
  3352. }
  3353. });
  3354. }( jQuery ));
  3355. (function( $, undefined ) {
  3356. var lastActive, startXPos, startYPos, clickDragged,
  3357. baseClasses = "ui-button ui-widget ui-state-default ui-corner-all",
  3358. stateClasses = "ui-state-hover ui-state-active ",
  3359. typeClasses = "ui-button-icons-only ui-button-icon-only ui-button-text-icons ui-button-text-icon-primary ui-button-text-icon-secondary ui-button-text-only",
  3360. formResetHandler = function() {
  3361. var buttons = $( this ).find( ":ui-button" );
  3362. setTimeout(function() {
  3363. buttons.button( "refresh" );
  3364. }, 1 );
  3365. },
  3366. radioGroup = function( radio ) {
  3367. var name = radio.name,
  3368. form = radio.form,
  3369. radios = $( [] );
  3370. if ( name ) {
  3371. name = name.replace( /'/g, "\\'" );
  3372. if ( form ) {
  3373. radios = $( form ).find( "[name='" + name + "']" );
  3374. } else {
  3375. radios = $( "[name='" + name + "']", radio.ownerDocument )
  3376. .filter(function() {
  3377. return !this.form;
  3378. });
  3379. }
  3380. }
  3381. return radios;
  3382. };
  3383. $.widget( "ui.button", {
  3384. version: "1.10.1",
  3385. defaultElement: "<button>",
  3386. options: {
  3387. disabled: null,
  3388. text: true,
  3389. label: null,
  3390. icons: {
  3391. primary: null,
  3392. secondary: null
  3393. }
  3394. },
  3395. _create: function() {
  3396. this.element.closest( "form" )
  3397. .unbind( "reset" + this.eventNamespace )
  3398. .bind( "reset" + this.eventNamespace, formResetHandler );
  3399. if ( typeof this.options.disabled !== "boolean" ) {
  3400. this.options.disabled = !!this.element.prop( "disabled" );
  3401. } else {
  3402. this.element.prop( "disabled", this.options.disabled );
  3403. }
  3404. this._determineButtonType();
  3405. this.hasTitle = !!this.buttonElement.attr( "title" );
  3406. var that = this,
  3407. options = this.options,
  3408. toggleButton = this.type === "checkbox" || this.type === "radio",
  3409. activeClass = !toggleButton ? "ui-state-active" : "",
  3410. focusClass = "ui-state-focus";
  3411. if ( options.label === null ) {
  3412. options.label = (this.type === "input" ? this.buttonElement.val() : this.buttonElement.html());
  3413. }
  3414. this._hoverable( this.buttonElement );
  3415. this.buttonElement
  3416. .addClass( baseClasses )
  3417. .attr( "role", "button" )
  3418. .bind( "mouseenter" + this.eventNamespace, function() {
  3419. if ( options.disabled ) {
  3420. return;
  3421. }
  3422. if ( this === lastActive ) {
  3423. $( this ).addClass( "ui-state-active" );
  3424. }
  3425. })
  3426. .bind( "mouseleave" + this.eventNamespace, function() {
  3427. if ( options.disabled ) {
  3428. return;
  3429. }
  3430. $( this ).removeClass( activeClass );
  3431. })
  3432. .bind( "click" + this.eventNamespace, function( event ) {
  3433. if ( options.disabled ) {
  3434. event.preventDefault();
  3435. event.stopImmediatePropagation();
  3436. }
  3437. });
  3438. this.element
  3439. .bind( "focus" + this.eventNamespace, function() {
  3440. // no need to check disabled, focus won't be triggered anyway
  3441. that.buttonElement.addClass( focusClass );
  3442. })
  3443. .bind( "blur" + this.eventNamespace, function() {
  3444. that.buttonElement.removeClass( focusClass );
  3445. });
  3446. if ( toggleButton ) {
  3447. this.element.bind( "change" + this.eventNamespace, function() {
  3448. if ( clickDragged ) {
  3449. return;
  3450. }
  3451. that.refresh();
  3452. });
  3453. // if mouse moves between mousedown and mouseup (drag) set clickDragged flag
  3454. // prevents issue where button state changes but checkbox/radio checked state
  3455. // does not in Firefox (see ticket #6970)
  3456. this.buttonElement
  3457. .bind( "mousedown" + this.eventNamespace, function( event ) {
  3458. if ( options.disabled ) {
  3459. return;
  3460. }
  3461. clickDragged = false;
  3462. startXPos = event.pageX;
  3463. startYPos = event.pageY;
  3464. })
  3465. .bind( "mouseup" + this.eventNamespace, function( event ) {
  3466. if ( options.disabled ) {
  3467. return;
  3468. }
  3469. if ( startXPos !== event.pageX || startYPos !== event.pageY ) {
  3470. clickDragged = true;
  3471. }
  3472. });
  3473. }
  3474. if ( this.type === "checkbox" ) {
  3475. this.buttonElement.bind( "click" + this.eventNamespace, function() {
  3476. if ( options.disabled || clickDragged ) {
  3477. return false;
  3478. }
  3479. });
  3480. } else if ( this.type === "radio" ) {
  3481. this.buttonElement.bind( "click" + this.eventNamespace, function() {
  3482. if ( options.disabled || clickDragged ) {
  3483. return false;
  3484. }
  3485. $( this ).addClass( "ui-state-active" );
  3486. that.buttonElement.attr( "aria-pressed", "true" );
  3487. var radio = that.element[ 0 ];
  3488. radioGroup( radio )
  3489. .not( radio )
  3490. .map(function() {
  3491. return $( this ).button( "widget" )[ 0 ];
  3492. })
  3493. .removeClass( "ui-state-active" )
  3494. .attr( "aria-pressed", "false" );
  3495. });
  3496. } else {
  3497. this.buttonElement
  3498. .bind( "mousedown" + this.eventNamespace, function() {
  3499. if ( options.disabled ) {
  3500. return false;
  3501. }
  3502. $( this ).addClass( "ui-state-active" );
  3503. lastActive = this;
  3504. that.document.one( "mouseup", function() {
  3505. lastActive = null;
  3506. });
  3507. })
  3508. .bind( "mouseup" + this.eventNamespace, function() {
  3509. if ( options.disabled ) {
  3510. return false;
  3511. }
  3512. $( this ).removeClass( "ui-state-active" );
  3513. })
  3514. .bind( "keydown" + this.eventNamespace, function(event) {
  3515. if ( options.disabled ) {
  3516. return false;
  3517. }
  3518. if ( event.keyCode === $.ui.keyCode.SPACE || event.keyCode === $.ui.keyCode.ENTER ) {
  3519. $( this ).addClass( "ui-state-active" );
  3520. }
  3521. })
  3522. // see #8559, we bind to blur here in case the button element loses
  3523. // focus between keydown and keyup, it would be left in an "active" state
  3524. .bind( "keyup" + this.eventNamespace + " blur" + this.eventNamespace, function() {
  3525. $( this ).removeClass( "ui-state-active" );
  3526. });
  3527. if ( this.buttonElement.is("a") ) {
  3528. this.buttonElement.keyup(function(event) {
  3529. if ( event.keyCode === $.ui.keyCode.SPACE ) {
  3530. // TODO pass through original event correctly (just as 2nd argument doesn't work)
  3531. $( this ).click();
  3532. }
  3533. });
  3534. }
  3535. }
  3536. // TODO: pull out $.Widget's handling for the disabled option into
  3537. // $.Widget.prototype._setOptionDisabled so it's easy to proxy and can
  3538. // be overridden by individual plugins
  3539. this._setOption( "disabled", options.disabled );
  3540. this._resetButton();
  3541. },
  3542. _determineButtonType: function() {
  3543. var ancestor, labelSelector, checked;
  3544. if ( this.element.is("[type=checkbox]") ) {
  3545. this.type = "checkbox";
  3546. } else if ( this.element.is("[type=radio]") ) {
  3547. this.type = "radio";
  3548. } else if ( this.element.is("input") ) {
  3549. this.type = "input";
  3550. } else {
  3551. this.type = "button";
  3552. }
  3553. if ( this.type === "checkbox" || this.type === "radio" ) {
  3554. // we don't search against the document in case the element
  3555. // is disconnected from the DOM
  3556. ancestor = this.element.parents().last();
  3557. labelSelector = "label[for='" + this.element.attr("id") + "']";
  3558. this.buttonElement = ancestor.find( labelSelector );
  3559. if ( !this.buttonElement.length ) {
  3560. ancestor = ancestor.length ? ancestor.siblings() : this.element.siblings();
  3561. this.buttonElement = ancestor.filter( labelSelector );
  3562. if ( !this.buttonElement.length ) {
  3563. this.buttonElement = ancestor.find( labelSelector );
  3564. }
  3565. }
  3566. this.element.addClass( "ui-helper-hidden-accessible" );
  3567. checked = this.element.is( ":checked" );
  3568. if ( checked ) {
  3569. this.buttonElement.addClass( "ui-state-active" );
  3570. }
  3571. this.buttonElement.prop( "aria-pressed", checked );
  3572. } else {
  3573. this.buttonElement = this.element;
  3574. }
  3575. },
  3576. widget: function() {
  3577. return this.buttonElement;
  3578. },
  3579. _destroy: function() {
  3580. this.element
  3581. .removeClass( "ui-helper-hidden-accessible" );
  3582. this.buttonElement
  3583. .removeClass( baseClasses + " " + stateClasses + " " + typeClasses )
  3584. .removeAttr( "role" )
  3585. .removeAttr( "aria-pressed" )
  3586. .html( this.buttonElement.find(".ui-button-text").html() );
  3587. if ( !this.hasTitle ) {
  3588. this.buttonElement.removeAttr( "title" );
  3589. }
  3590. },
  3591. _setOption: function( key, value ) {
  3592. this._super( key, value );
  3593. if ( key === "disabled" ) {
  3594. if ( value ) {
  3595. this.element.prop( "disabled", true );
  3596. } else {
  3597. this.element.prop( "disabled", false );
  3598. }
  3599. return;
  3600. }
  3601. this._resetButton();
  3602. },
  3603. refresh: function() {
  3604. //See #8237 & #8828
  3605. var isDisabled = this.element.is( "input, button" ) ? this.element.is( ":disabled" ) : this.element.hasClass( "ui-button-disabled" );
  3606. if ( isDisabled !== this.options.disabled ) {
  3607. this._setOption( "disabled", isDisabled );
  3608. }
  3609. if ( this.type === "radio" ) {
  3610. radioGroup( this.element[0] ).each(function() {
  3611. if ( $( this ).is( ":checked" ) ) {
  3612. $( this ).button( "widget" )
  3613. .addClass( "ui-state-active" )
  3614. .attr( "aria-pressed", "true" );
  3615. } else {
  3616. $( this ).button( "widget" )
  3617. .removeClass( "ui-state-active" )
  3618. .attr( "aria-pressed", "false" );
  3619. }
  3620. });
  3621. } else if ( this.type === "checkbox" ) {
  3622. if ( this.element.is( ":checked" ) ) {
  3623. this.buttonElement
  3624. .addClass( "ui-state-active" )
  3625. .attr( "aria-pressed", "true" );
  3626. } else {
  3627. this.buttonElement
  3628. .removeClass( "ui-state-active" )
  3629. .attr( "aria-pressed", "false" );
  3630. }
  3631. }
  3632. },
  3633. _resetButton: function() {
  3634. if ( this.type === "input" ) {
  3635. if ( this.options.label ) {
  3636. this.element.val( this.options.label );
  3637. }
  3638. return;
  3639. }
  3640. var buttonElement = this.buttonElement.removeClass( typeClasses ),
  3641. buttonText = $( "<span></span>", this.document[0] )
  3642. .addClass( "ui-button-text" )
  3643. .html( this.options.label )
  3644. .appendTo( buttonElement.empty() )
  3645. .text(),
  3646. icons = this.options.icons,
  3647. multipleIcons = icons.primary && icons.secondary,
  3648. buttonClasses = [];
  3649. if ( icons.primary || icons.secondary ) {
  3650. if ( this.options.text ) {
  3651. buttonClasses.push( "ui-button-text-icon" + ( multipleIcons ? "s" : ( icons.primary ? "-primary" : "-secondary" ) ) );
  3652. }
  3653. if ( icons.primary ) {
  3654. buttonElement.prepend( "<span class='ui-button-icon-primary ui-icon " + icons.primary + "'></span>" );
  3655. }
  3656. if ( icons.secondary ) {
  3657. buttonElement.append( "<span class='ui-button-icon-secondary ui-icon " + icons.secondary + "'></span>" );
  3658. }
  3659. if ( !this.options.text ) {
  3660. buttonClasses.push( multipleIcons ? "ui-button-icons-only" : "ui-button-icon-only" );
  3661. if ( !this.hasTitle ) {
  3662. buttonElement.attr( "title", $.trim( buttonText ) );
  3663. }
  3664. }
  3665. } else {
  3666. buttonClasses.push( "ui-button-text-only" );
  3667. }
  3668. buttonElement.addClass( buttonClasses.join( " " ) );
  3669. }
  3670. });
  3671. $.widget( "ui.buttonset", {
  3672. version: "1.10.1",
  3673. options: {
  3674. items: "button, input[type=button], input[type=submit], input[type=reset], input[type=checkbox], input[type=radio], a, :data(ui-button)"
  3675. },
  3676. _create: function() {
  3677. this.element.addClass( "ui-buttonset" );
  3678. },
  3679. _init: function() {
  3680. this.refresh();
  3681. },
  3682. _setOption: function( key, value ) {
  3683. if ( key === "disabled" ) {
  3684. this.buttons.button( "option", key, value );
  3685. }
  3686. this._super( key, value );
  3687. },
  3688. refresh: function() {
  3689. var rtl = this.element.css( "direction" ) === "rtl";
  3690. this.buttons = this.element.find( this.options.items )
  3691. .filter( ":ui-button" )
  3692. .button( "refresh" )
  3693. .end()
  3694. .not( ":ui-button" )
  3695. .button()
  3696. .end()
  3697. .map(function() {
  3698. return $( this ).button( "widget" )[ 0 ];
  3699. })
  3700. .removeClass( "ui-corner-all ui-corner-left ui-corner-right" )
  3701. .filter( ":first" )
  3702. .addClass( rtl ? "ui-corner-right" : "ui-corner-left" )
  3703. .end()
  3704. .filter( ":last" )
  3705. .addClass( rtl ? "ui-corner-left" : "ui-corner-right" )
  3706. .end()
  3707. .end();
  3708. },
  3709. _destroy: function() {
  3710. this.element.removeClass( "ui-buttonset" );
  3711. this.buttons
  3712. .map(function() {
  3713. return $( this ).button( "widget" )[ 0 ];
  3714. })
  3715. .removeClass( "ui-corner-left ui-corner-right" )
  3716. .end()
  3717. .button( "destroy" );
  3718. }
  3719. });
  3720. }( jQuery ) );
  3721. (function( $, undefined ) {
  3722. var sizeRelatedOptions = {
  3723. buttons: true,
  3724. height: true,
  3725. maxHeight: true,
  3726. maxWidth: true,
  3727. minHeight: true,
  3728. minWidth: true,
  3729. width: true
  3730. },
  3731. resizableRelatedOptions = {
  3732. maxHeight: true,
  3733. maxWidth: true,
  3734. minHeight: true,
  3735. minWidth: true
  3736. };
  3737. $.widget( "ui.dialog", {
  3738. version: "1.10.1",
  3739. options: {
  3740. appendTo: "body",
  3741. autoOpen: true,
  3742. buttons: [],
  3743. closeOnEscape: true,
  3744. closeText: "close",
  3745. dialogClass: "",
  3746. draggable: true,
  3747. hide: null,
  3748. height: "auto",
  3749. maxHeight: null,
  3750. maxWidth: null,
  3751. minHeight: 150,
  3752. minWidth: 150,
  3753. modal: false,
  3754. position: {
  3755. my: "center",
  3756. at: "center",
  3757. of: window,
  3758. collision: "fit",
  3759. // Ensure the titlebar is always visible
  3760. using: function( pos ) {
  3761. var topOffset = $( this ).css( pos ).offset().top;
  3762. if ( topOffset < 0 ) {
  3763. $( this ).css( "top", pos.top - topOffset );
  3764. }
  3765. }
  3766. },
  3767. resizable: true,
  3768. show: null,
  3769. title: null,
  3770. width: 300,
  3771. // callbacks
  3772. beforeClose: null,
  3773. close: null,
  3774. drag: null,
  3775. dragStart: null,
  3776. dragStop: null,
  3777. focus: null,
  3778. open: null,
  3779. resize: null,
  3780. resizeStart: null,
  3781. resizeStop: null
  3782. },
  3783. _create: function() {
  3784. this.originalCss = {
  3785. display: this.element[0].style.display,
  3786. width: this.element[0].style.width,
  3787. minHeight: this.element[0].style.minHeight,
  3788. maxHeight: this.element[0].style.maxHeight,
  3789. height: this.element[0].style.height
  3790. };
  3791. this.originalPosition = {
  3792. parent: this.element.parent(),
  3793. index: this.element.parent().children().index( this.element )
  3794. };
  3795. this.originalTitle = this.element.attr("title");
  3796. this.options.title = this.options.title || this.originalTitle;
  3797. this._createWrapper();
  3798. this.element
  3799. .show()
  3800. .removeAttr("title")
  3801. .addClass("ui-dialog-content ui-widget-content")
  3802. .appendTo( this.uiDialog );
  3803. this._createTitlebar();
  3804. this._createButtonPane();
  3805. if ( this.options.draggable && $.fn.draggable ) {
  3806. this._makeDraggable();
  3807. }
  3808. if ( this.options.resizable && $.fn.resizable ) {
  3809. this._makeResizable();
  3810. }
  3811. this._isOpen = false;
  3812. },
  3813. _init: function() {
  3814. if ( this.options.autoOpen ) {
  3815. this.open();
  3816. }
  3817. },
  3818. _appendTo: function() {
  3819. var element = this.options.appendTo;
  3820. if ( element && (element.jquery || element.nodeType) ) {
  3821. return $( element );
  3822. }
  3823. return this.document.find( element || "body" ).eq( 0 );
  3824. },
  3825. _destroy: function() {
  3826. var next,
  3827. originalPosition = this.originalPosition;
  3828. this._destroyOverlay();
  3829. this.element
  3830. .removeUniqueId()
  3831. .removeClass("ui-dialog-content ui-widget-content")
  3832. .css( this.originalCss )
  3833. // Without detaching first, the following becomes really slow
  3834. .detach();
  3835. this.uiDialog.stop( true, true ).remove();
  3836. if ( this.originalTitle ) {
  3837. this.element.attr( "title", this.originalTitle );
  3838. }
  3839. next = originalPosition.parent.children().eq( originalPosition.index );
  3840. // Don't try to place the dialog next to itself (#8613)
  3841. if ( next.length && next[0] !== this.element[0] ) {
  3842. next.before( this.element );
  3843. } else {
  3844. originalPosition.parent.append( this.element );
  3845. }
  3846. },
  3847. widget: function() {
  3848. return this.uiDialog;
  3849. },
  3850. disable: $.noop,
  3851. enable: $.noop,
  3852. close: function( event ) {
  3853. var that = this;
  3854. if ( !this._isOpen || this._trigger( "beforeClose", event ) === false ) {
  3855. return;
  3856. }
  3857. this._isOpen = false;
  3858. this._destroyOverlay();
  3859. if ( !this.opener.filter(":focusable").focus().length ) {
  3860. // Hiding a focused element doesn't trigger blur in WebKit
  3861. // so in case we have nothing to focus on, explicitly blur the active element
  3862. // https://bugs.webkit.org/show_bug.cgi?id=47182
  3863. $( this.document[0].activeElement ).blur();
  3864. }
  3865. this._hide( this.uiDialog, this.options.hide, function() {
  3866. that._trigger( "close", event );
  3867. });
  3868. },
  3869. isOpen: function() {
  3870. return this._isOpen;
  3871. },
  3872. moveToTop: function() {
  3873. this._moveToTop();
  3874. },
  3875. _moveToTop: function( event, silent ) {
  3876. var moved = !!this.uiDialog.nextAll(":visible").insertBefore( this.uiDialog ).length;
  3877. if ( moved && !silent ) {
  3878. this._trigger( "focus", event );
  3879. }
  3880. return moved;
  3881. },
  3882. open: function() {
  3883. var that = this;
  3884. if ( this._isOpen ) {
  3885. if ( this._moveToTop() ) {
  3886. this._focusTabbable();
  3887. }
  3888. return;
  3889. }
  3890. this._isOpen = true;
  3891. this.opener = $( this.document[0].activeElement );
  3892. this._size();
  3893. this._position();
  3894. this._createOverlay();
  3895. this._moveToTop( null, true );
  3896. this._show( this.uiDialog, this.options.show, function() {
  3897. that._focusTabbable();
  3898. that._trigger("focus");
  3899. });
  3900. this._trigger("open");
  3901. },
  3902. _focusTabbable: function() {
  3903. // Set focus to the first match:
  3904. // 1. First element inside the dialog matching [autofocus]
  3905. // 2. Tabbable element inside the content element
  3906. // 3. Tabbable element inside the buttonpane
  3907. // 4. The close button
  3908. // 5. The dialog itself
  3909. var hasFocus = this.element.find("[autofocus]");
  3910. if ( !hasFocus.length ) {
  3911. hasFocus = this.element.find(":tabbable");
  3912. }
  3913. if ( !hasFocus.length ) {
  3914. hasFocus = this.uiDialogButtonPane.find(":tabbable");
  3915. }
  3916. if ( !hasFocus.length ) {
  3917. hasFocus = this.uiDialogTitlebarClose.filter(":tabbable");
  3918. }
  3919. if ( !hasFocus.length ) {
  3920. hasFocus = this.uiDialog;
  3921. }
  3922. hasFocus.eq( 0 ).focus();
  3923. },
  3924. _keepFocus: function( event ) {
  3925. function checkFocus() {
  3926. var activeElement = this.document[0].activeElement,
  3927. isActive = this.uiDialog[0] === activeElement ||
  3928. $.contains( this.uiDialog[0], activeElement );
  3929. if ( !isActive ) {
  3930. this._focusTabbable();
  3931. }
  3932. }
  3933. event.preventDefault();
  3934. checkFocus.call( this );
  3935. // support: IE
  3936. // IE <= 8 doesn't prevent moving focus even with event.preventDefault()
  3937. // so we check again later
  3938. this._delay( checkFocus );
  3939. },
  3940. _createWrapper: function() {
  3941. this.uiDialog = $("<div>")
  3942. .addClass( "ui-dialog ui-widget ui-widget-content ui-corner-all ui-front " +
  3943. this.options.dialogClass )
  3944. .hide()
  3945. .attr({
  3946. // Setting tabIndex makes the div focusable
  3947. tabIndex: -1,
  3948. role: "dialog"
  3949. })
  3950. .appendTo( this._appendTo() );
  3951. this._on( this.uiDialog, {
  3952. keydown: function( event ) {
  3953. if ( this.options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
  3954. event.keyCode === $.ui.keyCode.ESCAPE ) {
  3955. event.preventDefault();
  3956. this.close( event );
  3957. return;
  3958. }
  3959. // prevent tabbing out of dialogs
  3960. if ( event.keyCode !== $.ui.keyCode.TAB ) {
  3961. return;
  3962. }
  3963. var tabbables = this.uiDialog.find(":tabbable"),
  3964. first = tabbables.filter(":first"),
  3965. last = tabbables.filter(":last");
  3966. if ( ( event.target === last[0] || event.target === this.uiDialog[0] ) && !event.shiftKey ) {
  3967. first.focus( 1 );
  3968. event.preventDefault();
  3969. } else if ( ( event.target === first[0] || event.target === this.uiDialog[0] ) && event.shiftKey ) {
  3970. last.focus( 1 );
  3971. event.preventDefault();
  3972. }
  3973. },
  3974. mousedown: function( event ) {
  3975. if ( this._moveToTop( event ) ) {
  3976. this._focusTabbable();
  3977. }
  3978. }
  3979. });
  3980. // We assume that any existing aria-describedby attribute means
  3981. // that the dialog content is marked up properly
  3982. // otherwise we brute force the content as the description
  3983. if ( !this.element.find("[aria-describedby]").length ) {
  3984. this.uiDialog.attr({
  3985. "aria-describedby": this.element.uniqueId().attr("id")
  3986. });
  3987. }
  3988. },
  3989. _createTitlebar: function() {
  3990. var uiDialogTitle;
  3991. this.uiDialogTitlebar = $("<div>")
  3992. .addClass("ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix")
  3993. .prependTo( this.uiDialog );
  3994. this._on( this.uiDialogTitlebar, {
  3995. mousedown: function( event ) {
  3996. // Don't prevent click on close button (#8838)
  3997. // Focusing a dialog that is partially scrolled out of view
  3998. // causes the browser to scroll it into view, preventing the click event
  3999. if ( !$( event.target ).closest(".ui-dialog-titlebar-close") ) {
  4000. // Dialog isn't getting focus when dragging (#8063)
  4001. this.uiDialog.focus();
  4002. }
  4003. }
  4004. });
  4005. this.uiDialogTitlebarClose = $("<button></button>")
  4006. .button({
  4007. label: this.options.closeText,
  4008. icons: {
  4009. primary: "ui-icon-closethick"
  4010. },
  4011. text: false
  4012. })
  4013. .addClass("ui-dialog-titlebar-close")
  4014. .appendTo( this.uiDialogTitlebar );
  4015. this._on( this.uiDialogTitlebarClose, {
  4016. click: function( event ) {
  4017. event.preventDefault();
  4018. this.close( event );
  4019. }
  4020. });
  4021. uiDialogTitle = $("<span>")
  4022. .uniqueId()
  4023. .addClass("ui-dialog-title")
  4024. .prependTo( this.uiDialogTitlebar );
  4025. this._title( uiDialogTitle );
  4026. this.uiDialog.attr({
  4027. "aria-labelledby": uiDialogTitle.attr("id")
  4028. });
  4029. },
  4030. _title: function( title ) {
  4031. if ( !this.options.title ) {
  4032. title.html("&#160;");
  4033. }
  4034. title.text( this.options.title );
  4035. },
  4036. _createButtonPane: function() {
  4037. this.uiDialogButtonPane = $("<div>")
  4038. .addClass("ui-dialog-buttonpane ui-widget-content ui-helper-clearfix");
  4039. this.uiButtonSet = $("<div>")
  4040. .addClass("ui-dialog-buttonset")
  4041. .appendTo( this.uiDialogButtonPane );
  4042. this._createButtons();
  4043. },
  4044. _createButtons: function() {
  4045. var that = this,
  4046. buttons = this.options.buttons;
  4047. // if we already have a button pane, remove it
  4048. this.uiDialogButtonPane.remove();
  4049. this.uiButtonSet.empty();
  4050. if ( $.isEmptyObject( buttons ) || ($.isArray( buttons ) && !buttons.length) ) {
  4051. this.uiDialog.removeClass("ui-dialog-buttons");
  4052. return;
  4053. }
  4054. $.each( buttons, function( name, props ) {
  4055. var click, buttonOptions;
  4056. props = $.isFunction( props ) ?
  4057. { click: props, text: name } :
  4058. props;
  4059. // Default to a non-submitting button
  4060. props = $.extend( { type: "button" }, props );
  4061. // Change the context for the click callback to be the main element
  4062. click = props.click;
  4063. props.click = function() {
  4064. click.apply( that.element[0], arguments );
  4065. };
  4066. buttonOptions = {
  4067. icons: props.icons,
  4068. text: props.showText
  4069. };
  4070. delete props.icons;
  4071. delete props.showText;
  4072. $( "<button></button>", props )
  4073. .button( buttonOptions )
  4074. .appendTo( that.uiButtonSet );
  4075. });
  4076. this.uiDialog.addClass("ui-dialog-buttons");
  4077. this.uiDialogButtonPane.appendTo( this.uiDialog );
  4078. },
  4079. _makeDraggable: function() {
  4080. var that = this,
  4081. options = this.options;
  4082. function filteredUi( ui ) {
  4083. return {
  4084. position: ui.position,
  4085. offset: ui.offset
  4086. };
  4087. }
  4088. this.uiDialog.draggable({
  4089. cancel: ".ui-dialog-content, .ui-dialog-titlebar-close",
  4090. handle: ".ui-dialog-titlebar",
  4091. containment: "document",
  4092. start: function( event, ui ) {
  4093. $( this ).addClass("ui-dialog-dragging");
  4094. that._blockFrames();
  4095. that._trigger( "dragStart", event, filteredUi( ui ) );
  4096. },
  4097. drag: function( event, ui ) {
  4098. that._trigger( "drag", event, filteredUi( ui ) );
  4099. },
  4100. stop: function( event, ui ) {
  4101. options.position = [
  4102. ui.position.left - that.document.scrollLeft(),
  4103. ui.position.top - that.document.scrollTop()
  4104. ];
  4105. $( this ).removeClass("ui-dialog-dragging");
  4106. that._unblockFrames();
  4107. that._trigger( "dragStop", event, filteredUi( ui ) );
  4108. }
  4109. });
  4110. },
  4111. _makeResizable: function() {
  4112. var that = this,
  4113. options = this.options,
  4114. handles = options.resizable,
  4115. // .ui-resizable has position: relative defined in the stylesheet
  4116. // but dialogs have to use absolute or fixed positioning
  4117. position = this.uiDialog.css("position"),
  4118. resizeHandles = typeof handles === "string" ?
  4119. handles :
  4120. "n,e,s,w,se,sw,ne,nw";
  4121. function filteredUi( ui ) {
  4122. return {
  4123. originalPosition: ui.originalPosition,
  4124. originalSize: ui.originalSize,
  4125. position: ui.position,
  4126. size: ui.size
  4127. };
  4128. }
  4129. this.uiDialog.resizable({
  4130. cancel: ".ui-dialog-content",
  4131. containment: "document",
  4132. alsoResize: this.element,
  4133. maxWidth: options.maxWidth,
  4134. maxHeight: options.maxHeight,
  4135. minWidth: options.minWidth,
  4136. minHeight: this._minHeight(),
  4137. handles: resizeHandles,
  4138. start: function( event, ui ) {
  4139. $( this ).addClass("ui-dialog-resizing");
  4140. that._blockFrames();
  4141. that._trigger( "resizeStart", event, filteredUi( ui ) );
  4142. },
  4143. resize: function( event, ui ) {
  4144. that._trigger( "resize", event, filteredUi( ui ) );
  4145. },
  4146. stop: function( event, ui ) {
  4147. options.height = $( this ).height();
  4148. options.width = $( this ).width();
  4149. $( this ).removeClass("ui-dialog-resizing");
  4150. that._unblockFrames();
  4151. that._trigger( "resizeStop", event, filteredUi( ui ) );
  4152. }
  4153. })
  4154. .css( "position", position );
  4155. },
  4156. _minHeight: function() {
  4157. var options = this.options;
  4158. return options.height === "auto" ?
  4159. options.minHeight :
  4160. Math.min( options.minHeight, options.height );
  4161. },
  4162. _position: function() {
  4163. // Need to show the dialog to get the actual offset in the position plugin
  4164. var isVisible = this.uiDialog.is(":visible");
  4165. if ( !isVisible ) {
  4166. this.uiDialog.show();
  4167. }
  4168. this.uiDialog.position( this.options.position );
  4169. if ( !isVisible ) {
  4170. this.uiDialog.hide();
  4171. }
  4172. },
  4173. _setOptions: function( options ) {
  4174. var that = this,
  4175. resize = false,
  4176. resizableOptions = {};
  4177. $.each( options, function( key, value ) {
  4178. that._setOption( key, value );
  4179. if ( key in sizeRelatedOptions ) {
  4180. resize = true;
  4181. }
  4182. if ( key in resizableRelatedOptions ) {
  4183. resizableOptions[ key ] = value;
  4184. }
  4185. });
  4186. if ( resize ) {
  4187. this._size();
  4188. this._position();
  4189. }
  4190. if ( this.uiDialog.is(":data(ui-resizable)") ) {
  4191. this.uiDialog.resizable( "option", resizableOptions );
  4192. }
  4193. },
  4194. _setOption: function( key, value ) {
  4195. /*jshint maxcomplexity:15*/
  4196. var isDraggable, isResizable,
  4197. uiDialog = this.uiDialog;
  4198. if ( key === "dialogClass" ) {
  4199. uiDialog
  4200. .removeClass( this.options.dialogClass )
  4201. .addClass( value );
  4202. }
  4203. if ( key === "disabled" ) {
  4204. return;
  4205. }
  4206. this._super( key, value );
  4207. if ( key === "appendTo" ) {
  4208. this.uiDialog.appendTo( this._appendTo() );
  4209. }
  4210. if ( key === "buttons" ) {
  4211. this._createButtons();
  4212. }
  4213. if ( key === "closeText" ) {
  4214. this.uiDialogTitlebarClose.button({
  4215. // Ensure that we always pass a string
  4216. label: "" + value
  4217. });
  4218. }
  4219. if ( key === "draggable" ) {
  4220. isDraggable = uiDialog.is(":data(ui-draggable)");
  4221. if ( isDraggable && !value ) {
  4222. uiDialog.draggable("destroy");
  4223. }
  4224. if ( !isDraggable && value ) {
  4225. this._makeDraggable();
  4226. }
  4227. }
  4228. if ( key === "position" ) {
  4229. this._position();
  4230. }
  4231. if ( key === "resizable" ) {
  4232. // currently resizable, becoming non-resizable
  4233. isResizable = uiDialog.is(":data(ui-resizable)");
  4234. if ( isResizable && !value ) {
  4235. uiDialog.resizable("destroy");
  4236. }
  4237. // currently resizable, changing handles
  4238. if ( isResizable && typeof value === "string" ) {
  4239. uiDialog.resizable( "option", "handles", value );
  4240. }
  4241. // currently non-resizable, becoming resizable
  4242. if ( !isResizable && value !== false ) {
  4243. this._makeResizable();
  4244. }
  4245. }
  4246. if ( key === "title" ) {
  4247. this._title( this.uiDialogTitlebar.find(".ui-dialog-title") );
  4248. }
  4249. },
  4250. _size: function() {
  4251. // If the user has resized the dialog, the .ui-dialog and .ui-dialog-content
  4252. // divs will both have width and height set, so we need to reset them
  4253. var nonContentHeight, minContentHeight, maxContentHeight,
  4254. options = this.options;
  4255. // Reset content sizing
  4256. this.element.show().css({
  4257. width: "auto",
  4258. minHeight: 0,
  4259. maxHeight: "none",
  4260. height: 0
  4261. });
  4262. if ( options.minWidth > options.width ) {
  4263. options.width = options.minWidth;
  4264. }
  4265. // reset wrapper sizing
  4266. // determine the height of all the non-content elements
  4267. nonContentHeight = this.uiDialog.css({
  4268. height: "auto",
  4269. width: options.width
  4270. })
  4271. .outerHeight();
  4272. minContentHeight = Math.max( 0, options.minHeight - nonContentHeight );
  4273. maxContentHeight = typeof options.maxHeight === "number" ?
  4274. Math.max( 0, options.maxHeight - nonContentHeight ) :
  4275. "none";
  4276. if ( options.height === "auto" ) {
  4277. this.element.css({
  4278. minHeight: minContentHeight,
  4279. maxHeight: maxContentHeight,
  4280. height: "auto"
  4281. });
  4282. } else {
  4283. this.element.height( Math.max( 0, options.height - nonContentHeight ) );
  4284. }
  4285. if (this.uiDialog.is(":data(ui-resizable)") ) {
  4286. this.uiDialog.resizable( "option", "minHeight", this._minHeight() );
  4287. }
  4288. },
  4289. _blockFrames: function() {
  4290. this.iframeBlocks = this.document.find( "iframe" ).map(function() {
  4291. var iframe = $( this );
  4292. return $( "<div>" )
  4293. .css({
  4294. position: "absolute",
  4295. width: iframe.outerWidth(),
  4296. height: iframe.outerHeight()
  4297. })
  4298. .appendTo( iframe.parent() )
  4299. .offset( iframe.offset() )[0];
  4300. });
  4301. },
  4302. _unblockFrames: function() {
  4303. if ( this.iframeBlocks ) {
  4304. this.iframeBlocks.remove();
  4305. delete this.iframeBlocks;
  4306. }
  4307. },
  4308. _createOverlay: function() {
  4309. if ( !this.options.modal ) {
  4310. return;
  4311. }
  4312. if ( !$.ui.dialog.overlayInstances ) {
  4313. // Prevent use of anchors and inputs.
  4314. // We use a delay in case the overlay is created from an
  4315. // event that we're going to be cancelling. (#2804)
  4316. this._delay(function() {
  4317. // Handle .dialog().dialog("close") (#4065)
  4318. if ( $.ui.dialog.overlayInstances ) {
  4319. this.document.bind( "focusin.dialog", function( event ) {
  4320. if ( !$( event.target ).closest(".ui-dialog").length &&
  4321. // TODO: Remove hack when datepicker implements
  4322. // the .ui-front logic (#8989)
  4323. !$( event.target ).closest(".ui-datepicker").length ) {
  4324. event.preventDefault();
  4325. $(".ui-dialog:visible:last .ui-dialog-content")
  4326. .data("ui-dialog")._focusTabbable();
  4327. }
  4328. });
  4329. }
  4330. });
  4331. }
  4332. this.overlay = $("<div>")
  4333. .addClass("ui-widget-overlay ui-front")
  4334. .appendTo( this._appendTo() );
  4335. this._on( this.overlay, {
  4336. mousedown: "_keepFocus"
  4337. });
  4338. $.ui.dialog.overlayInstances++;
  4339. },
  4340. _destroyOverlay: function() {
  4341. if ( !this.options.modal ) {
  4342. return;
  4343. }
  4344. if ( this.overlay ) {
  4345. $.ui.dialog.overlayInstances--;
  4346. if ( !$.ui.dialog.overlayInstances ) {
  4347. this.document.unbind( "focusin.dialog" );
  4348. }
  4349. this.overlay.remove();
  4350. this.overlay = null;
  4351. }
  4352. }
  4353. });
  4354. $.ui.dialog.overlayInstances = 0;
  4355. // DEPRECATED
  4356. if ( $.uiBackCompat !== false ) {
  4357. // position option with array notation
  4358. // just override with old implementation
  4359. $.widget( "ui.dialog", $.ui.dialog, {
  4360. _position: function() {
  4361. var position = this.options.position,
  4362. myAt = [],
  4363. offset = [ 0, 0 ],
  4364. isVisible;
  4365. if ( position ) {
  4366. if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) {
  4367. myAt = position.split ? position.split(" ") : [ position[0], position[1] ];
  4368. if ( myAt.length === 1 ) {
  4369. myAt[1] = myAt[0];
  4370. }
  4371. $.each( [ "left", "top" ], function( i, offsetPosition ) {
  4372. if ( +myAt[ i ] === myAt[ i ] ) {
  4373. offset[ i ] = myAt[ i ];
  4374. myAt[ i ] = offsetPosition;
  4375. }
  4376. });
  4377. position = {
  4378. my: myAt[0] + (offset[0] < 0 ? offset[0] : "+" + offset[0]) + " " +
  4379. myAt[1] + (offset[1] < 0 ? offset[1] : "+" + offset[1]),
  4380. at: myAt.join(" ")
  4381. };
  4382. }
  4383. position = $.extend( {}, $.ui.dialog.prototype.options.position, position );
  4384. } else {
  4385. position = $.ui.dialog.prototype.options.position;
  4386. }
  4387. // need to show the dialog to get the actual offset in the position plugin
  4388. isVisible = this.uiDialog.is(":visible");
  4389. if ( !isVisible ) {
  4390. this.uiDialog.show();
  4391. }
  4392. this.uiDialog.position( position );
  4393. if ( !isVisible ) {
  4394. this.uiDialog.hide();
  4395. }
  4396. }
  4397. });
  4398. }
  4399. }( jQuery ) );
  4400. (function( $, undefined ) {
  4401. $.widget( "ui.menu", {
  4402. version: "1.10.1",
  4403. defaultElement: "<ul>",
  4404. delay: 300,
  4405. options: {
  4406. icons: {
  4407. submenu: "ui-icon-carat-1-e"
  4408. },
  4409. menus: "ul",
  4410. position: {
  4411. my: "left top",
  4412. at: "right top"
  4413. },
  4414. role: "menu",
  4415. // callbacks
  4416. blur: null,
  4417. focus: null,
  4418. select: null
  4419. },
  4420. _create: function() {
  4421. this.activeMenu = this.element;
  4422. // flag used to prevent firing of the click handler
  4423. // as the event bubbles up through nested menus
  4424. this.mouseHandled = false;
  4425. this.element
  4426. .uniqueId()
  4427. .addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
  4428. .toggleClass( "ui-menu-icons", !!this.element.find( ".ui-icon" ).length )
  4429. .attr({
  4430. role: this.options.role,
  4431. tabIndex: 0
  4432. })
  4433. // need to catch all clicks on disabled menu
  4434. // not possible through _on
  4435. .bind( "click" + this.eventNamespace, $.proxy(function( event ) {
  4436. if ( this.options.disabled ) {
  4437. event.preventDefault();
  4438. }
  4439. }, this ));
  4440. if ( this.options.disabled ) {
  4441. this.element
  4442. .addClass( "ui-state-disabled" )
  4443. .attr( "aria-disabled", "true" );
  4444. }
  4445. this._on({
  4446. // Prevent focus from sticking to links inside menu after clicking
  4447. // them (focus should always stay on UL during navigation).
  4448. "mousedown .ui-menu-item > a": function( event ) {
  4449. event.preventDefault();
  4450. },
  4451. "click .ui-state-disabled > a": function( event ) {
  4452. event.preventDefault();
  4453. },
  4454. "click .ui-menu-item:has(a)": function( event ) {
  4455. var target = $( event.target ).closest( ".ui-menu-item" );
  4456. if ( !this.mouseHandled && target.not( ".ui-state-disabled" ).length ) {
  4457. this.mouseHandled = true;
  4458. this.select( event );
  4459. // Open submenu on click
  4460. if ( target.has( ".ui-menu" ).length ) {
  4461. this.expand( event );
  4462. } else if ( !this.element.is( ":focus" ) ) {
  4463. // Redirect focus to the menu
  4464. this.element.trigger( "focus", [ true ] );
  4465. // If the active item is on the top level, let it stay active.
  4466. // Otherwise, blur the active item since it is no longer visible.
  4467. if ( this.active && this.active.parents( ".ui-menu" ).length === 1 ) {
  4468. clearTimeout( this.timer );
  4469. }
  4470. }
  4471. }
  4472. },
  4473. "mouseenter .ui-menu-item": function( event ) {
  4474. var target = $( event.currentTarget );
  4475. // Remove ui-state-active class from siblings of the newly focused menu item
  4476. // to avoid a jump caused by adjacent elements both having a class with a border
  4477. target.siblings().children( ".ui-state-active" ).removeClass( "ui-state-active" );
  4478. this.focus( event, target );
  4479. },
  4480. mouseleave: "collapseAll",
  4481. "mouseleave .ui-menu": "collapseAll",
  4482. focus: function( event, keepActiveItem ) {
  4483. // If there's already an active item, keep it active
  4484. // If not, activate the first item
  4485. var item = this.active || this.element.children( ".ui-menu-item" ).eq( 0 );
  4486. if ( !keepActiveItem ) {
  4487. this.focus( event, item );
  4488. }
  4489. },
  4490. blur: function( event ) {
  4491. this._delay(function() {
  4492. if ( !$.contains( this.element[0], this.document[0].activeElement ) ) {
  4493. this.collapseAll( event );
  4494. }
  4495. });
  4496. },
  4497. keydown: "_keydown"
  4498. });
  4499. this.refresh();
  4500. // Clicks outside of a menu collapse any open menus
  4501. this._on( this.document, {
  4502. click: function( event ) {
  4503. if ( !$( event.target ).closest( ".ui-menu" ).length ) {
  4504. this.collapseAll( event );
  4505. }
  4506. // Reset the mouseHandled flag
  4507. this.mouseHandled = false;
  4508. }
  4509. });
  4510. },
  4511. _destroy: function() {
  4512. // Destroy (sub)menus
  4513. this.element
  4514. .removeAttr( "aria-activedescendant" )
  4515. .find( ".ui-menu" ).addBack()
  4516. .removeClass( "ui-menu ui-widget ui-widget-content ui-corner-all ui-menu-icons" )
  4517. .removeAttr( "role" )
  4518. .removeAttr( "tabIndex" )
  4519. .removeAttr( "aria-labelledby" )
  4520. .removeAttr( "aria-expanded" )
  4521. .removeAttr( "aria-hidden" )
  4522. .removeAttr( "aria-disabled" )
  4523. .removeUniqueId()
  4524. .show();
  4525. // Destroy menu items
  4526. this.element.find( ".ui-menu-item" )
  4527. .removeClass( "ui-menu-item" )
  4528. .removeAttr( "role" )
  4529. .removeAttr( "aria-disabled" )
  4530. .children( "a" )
  4531. .removeUniqueId()
  4532. .removeClass( "ui-corner-all ui-state-hover" )
  4533. .removeAttr( "tabIndex" )
  4534. .removeAttr( "role" )
  4535. .removeAttr( "aria-haspopup" )
  4536. .children().each( function() {
  4537. var elem = $( this );
  4538. if ( elem.data( "ui-menu-submenu-carat" ) ) {
  4539. elem.remove();
  4540. }
  4541. });
  4542. // Destroy menu dividers
  4543. this.element.find( ".ui-menu-divider" ).removeClass( "ui-menu-divider ui-widget-content" );
  4544. },
  4545. _keydown: function( event ) {
  4546. /*jshint maxcomplexity:20*/
  4547. var match, prev, character, skip, regex,
  4548. preventDefault = true;
  4549. function escape( value ) {
  4550. return value.replace( /[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&" );
  4551. }
  4552. switch ( event.keyCode ) {
  4553. case $.ui.keyCode.PAGE_UP:
  4554. this.previousPage( event );
  4555. break;
  4556. case $.ui.keyCode.PAGE_DOWN:
  4557. this.nextPage( event );
  4558. break;
  4559. case $.ui.keyCode.HOME:
  4560. this._move( "first", "first", event );
  4561. break;
  4562. case $.ui.keyCode.END:
  4563. this._move( "last", "last", event );
  4564. break;
  4565. case $.ui.keyCode.UP:
  4566. this.previous( event );
  4567. break;
  4568. case $.ui.keyCode.DOWN:
  4569. this.next( event );
  4570. break;
  4571. case $.ui.keyCode.LEFT:
  4572. this.collapse( event );
  4573. break;
  4574. case $.ui.keyCode.RIGHT:
  4575. if ( this.active && !this.active.is( ".ui-state-disabled" ) ) {
  4576. this.expand( event );
  4577. }
  4578. break;
  4579. case $.ui.keyCode.ENTER:
  4580. case $.ui.keyCode.SPACE:
  4581. this._activate( event );
  4582. break;
  4583. case $.ui.keyCode.ESCAPE:
  4584. this.collapse( event );
  4585. break;
  4586. default:
  4587. preventDefault = false;
  4588. prev = this.previousFilter || "";
  4589. character = String.fromCharCode( event.keyCode );
  4590. skip = false;
  4591. clearTimeout( this.filterTimer );
  4592. if ( character === prev ) {
  4593. skip = true;
  4594. } else {
  4595. character = prev + character;
  4596. }
  4597. regex = new RegExp( "^" + escape( character ), "i" );
  4598. match = this.activeMenu.children( ".ui-menu-item" ).filter(function() {
  4599. return regex.test( $( this ).children( "a" ).text() );
  4600. });
  4601. match = skip && match.index( this.active.next() ) !== -1 ?
  4602. this.active.nextAll( ".ui-menu-item" ) :
  4603. match;
  4604. // If no matches on the current filter, reset to the last character pressed
  4605. // to move down the menu to the first item that starts with that character
  4606. if ( !match.length ) {
  4607. character = String.fromCharCode( event.keyCode );
  4608. regex = new RegExp( "^" + escape( character ), "i" );
  4609. match = this.activeMenu.children( ".ui-menu-item" ).filter(function() {
  4610. return regex.test( $( this ).children( "a" ).text() );
  4611. });
  4612. }
  4613. if ( match.length ) {
  4614. this.focus( event, match );
  4615. if ( match.length > 1 ) {
  4616. this.previousFilter = character;
  4617. this.filterTimer = this._delay(function() {
  4618. delete this.previousFilter;
  4619. }, 1000 );
  4620. } else {
  4621. delete this.previousFilter;
  4622. }
  4623. } else {
  4624. delete this.previousFilter;
  4625. }
  4626. }
  4627. if ( preventDefault ) {
  4628. event.preventDefault();
  4629. }
  4630. },
  4631. _activate: function( event ) {
  4632. if ( !this.active.is( ".ui-state-disabled" ) ) {
  4633. if ( this.active.children( "a[aria-haspopup='true']" ).length ) {
  4634. this.expand( event );
  4635. } else {
  4636. this.select( event );
  4637. }
  4638. }
  4639. },
  4640. refresh: function() {
  4641. var menus,
  4642. icon = this.options.icons.submenu,
  4643. submenus = this.element.find( this.options.menus );
  4644. // Initialize nested menus
  4645. submenus.filter( ":not(.ui-menu)" )
  4646. .addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
  4647. .hide()
  4648. .attr({
  4649. role: this.options.role,
  4650. "aria-hidden": "true",
  4651. "aria-expanded": "false"
  4652. })
  4653. .each(function() {
  4654. var menu = $( this ),
  4655. item = menu.prev( "a" ),
  4656. submenuCarat = $( "<span>" )
  4657. .addClass( "ui-menu-icon ui-icon " + icon )
  4658. .data( "ui-menu-submenu-carat", true );
  4659. item
  4660. .attr( "aria-haspopup", "true" )
  4661. .prepend( submenuCarat );
  4662. menu.attr( "aria-labelledby", item.attr( "id" ) );
  4663. });
  4664. menus = submenus.add( this.element );
  4665. // Don't refresh list items that are already adapted
  4666. menus.children( ":not(.ui-menu-item):has(a)" )
  4667. .addClass( "ui-menu-item" )
  4668. .attr( "role", "presentation" )
  4669. .children( "a" )
  4670. .uniqueId()
  4671. .addClass( "ui-corner-all" )
  4672. .attr({
  4673. tabIndex: -1,
  4674. role: this._itemRole()
  4675. });
  4676. // Initialize unlinked menu-items containing spaces and/or dashes only as dividers
  4677. menus.children( ":not(.ui-menu-item)" ).each(function() {
  4678. var item = $( this );
  4679. // hyphen, em dash, en dash
  4680. if ( !/[^\-\u2014\u2013\s]/.test( item.text() ) ) {
  4681. item.addClass( "ui-widget-content ui-menu-divider" );
  4682. }
  4683. });
  4684. // Add aria-disabled attribute to any disabled menu item
  4685. menus.children( ".ui-state-disabled" ).attr( "aria-disabled", "true" );
  4686. // If the active item has been removed, blur the menu
  4687. if ( this.active && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) {
  4688. this.blur();
  4689. }
  4690. },
  4691. _itemRole: function() {
  4692. return {
  4693. menu: "menuitem",
  4694. listbox: "option"
  4695. }[ this.options.role ];
  4696. },
  4697. _setOption: function( key, value ) {
  4698. if ( key === "icons" ) {
  4699. this.element.find( ".ui-menu-icon" )
  4700. .removeClass( this.options.icons.submenu )
  4701. .addClass( value.submenu );
  4702. }
  4703. this._super( key, value );
  4704. },
  4705. focus: function( event, item ) {
  4706. var nested, focused;
  4707. this.blur( event, event && event.type === "focus" );
  4708. this._scrollIntoView( item );
  4709. this.active = item.first();
  4710. focused = this.active.children( "a" ).addClass( "ui-state-focus" );
  4711. // Only update aria-activedescendant if there's a role
  4712. // otherwise we assume focus is managed elsewhere
  4713. if ( this.options.role ) {
  4714. this.element.attr( "aria-activedescendant", focused.attr( "id" ) );
  4715. }
  4716. // Highlight active parent menu item, if any
  4717. this.active
  4718. .parent()
  4719. .closest( ".ui-menu-item" )
  4720. .children( "a:first" )
  4721. .addClass( "ui-state-active" );
  4722. if ( event && event.type === "keydown" ) {
  4723. this._close();
  4724. } else {
  4725. this.timer = this._delay(function() {
  4726. this._close();
  4727. }, this.delay );
  4728. }
  4729. nested = item.children( ".ui-menu" );
  4730. if ( nested.length && ( /^mouse/.test( event.type ) ) ) {
  4731. this._startOpening(nested);
  4732. }
  4733. this.activeMenu = item.parent();
  4734. this._trigger( "focus", event, { item: item } );
  4735. },
  4736. _scrollIntoView: function( item ) {
  4737. var borderTop, paddingTop, offset, scroll, elementHeight, itemHeight;
  4738. if ( this._hasScroll() ) {
  4739. borderTop = parseFloat( $.css( this.activeMenu[0], "borderTopWidth" ) ) || 0;
  4740. paddingTop = parseFloat( $.css( this.activeMenu[0], "paddingTop" ) ) || 0;
  4741. offset = item.offset().top - this.activeMenu.offset().top - borderTop - paddingTop;
  4742. scroll = this.activeMenu.scrollTop();
  4743. elementHeight = this.activeMenu.height();
  4744. itemHeight = item.height();
  4745. if ( offset < 0 ) {
  4746. this.activeMenu.scrollTop( scroll + offset );
  4747. } else if ( offset + itemHeight > elementHeight ) {
  4748. this.activeMenu.scrollTop( scroll + offset - elementHeight + itemHeight );
  4749. }
  4750. }
  4751. },
  4752. blur: function( event, fromFocus ) {
  4753. if ( !fromFocus ) {
  4754. clearTimeout( this.timer );
  4755. }
  4756. if ( !this.active ) {
  4757. return;
  4758. }
  4759. this.active.children( "a" ).removeClass( "ui-state-focus" );
  4760. this.active = null;
  4761. this._trigger( "blur", event, { item: this.active } );
  4762. },
  4763. _startOpening: function( submenu ) {
  4764. clearTimeout( this.timer );
  4765. // Don't open if already open fixes a Firefox bug that caused a .5 pixel
  4766. // shift in the submenu position when mousing over the carat icon
  4767. if ( submenu.attr( "aria-hidden" ) !== "true" ) {
  4768. return;
  4769. }
  4770. this.timer = this._delay(function() {
  4771. this._close();
  4772. this._open( submenu );
  4773. }, this.delay );
  4774. },
  4775. _open: function( submenu ) {
  4776. var position = $.extend({
  4777. of: this.active
  4778. }, this.options.position );
  4779. clearTimeout( this.timer );
  4780. this.element.find( ".ui-menu" ).not( submenu.parents( ".ui-menu" ) )
  4781. .hide()
  4782. .attr( "aria-hidden", "true" );
  4783. submenu
  4784. .show()
  4785. .removeAttr( "aria-hidden" )
  4786. .attr( "aria-expanded", "true" )
  4787. .position( position );
  4788. },
  4789. collapseAll: function( event, all ) {
  4790. clearTimeout( this.timer );
  4791. this.timer = this._delay(function() {
  4792. // If we were passed an event, look for the submenu that contains the event
  4793. var currentMenu = all ? this.element :
  4794. $( event && event.target ).closest( this.element.find( ".ui-menu" ) );
  4795. // If we found no valid submenu ancestor, use the main menu to close all sub menus anyway
  4796. if ( !currentMenu.length ) {
  4797. currentMenu = this.element;
  4798. }
  4799. this._close( currentMenu );
  4800. this.blur( event );
  4801. this.activeMenu = currentMenu;
  4802. }, this.delay );
  4803. },
  4804. // With no arguments, closes the currently active menu - if nothing is active
  4805. // it closes all menus. If passed an argument, it will search for menus BELOW
  4806. _close: function( startMenu ) {
  4807. if ( !startMenu ) {
  4808. startMenu = this.active ? this.active.parent() : this.element;
  4809. }
  4810. startMenu
  4811. .find( ".ui-menu" )
  4812. .hide()
  4813. .attr( "aria-hidden", "true" )
  4814. .attr( "aria-expanded", "false" )
  4815. .end()
  4816. .find( "a.ui-state-active" )
  4817. .removeClass( "ui-state-active" );
  4818. },
  4819. collapse: function( event ) {
  4820. var newItem = this.active &&
  4821. this.active.parent().closest( ".ui-menu-item", this.element );
  4822. if ( newItem && newItem.length ) {
  4823. this._close();
  4824. this.focus( event, newItem );
  4825. }
  4826. },
  4827. expand: function( event ) {
  4828. var newItem = this.active &&
  4829. this.active
  4830. .children( ".ui-menu " )
  4831. .children( ".ui-menu-item" )
  4832. .first();
  4833. if ( newItem && newItem.length ) {
  4834. this._open( newItem.parent() );
  4835. // Delay so Firefox will not hide activedescendant change in expanding submenu from AT
  4836. this._delay(function() {
  4837. this.focus( event, newItem );
  4838. });
  4839. }
  4840. },
  4841. next: function( event ) {
  4842. this._move( "next", "first", event );
  4843. },
  4844. previous: function( event ) {
  4845. this._move( "prev", "last", event );
  4846. },
  4847. isFirstItem: function() {
  4848. return this.active && !this.active.prevAll( ".ui-menu-item" ).length;
  4849. },
  4850. isLastItem: function() {
  4851. return this.active && !this.active.nextAll( ".ui-menu-item" ).length;
  4852. },
  4853. _move: function( direction, filter, event ) {
  4854. var next;
  4855. if ( this.active ) {
  4856. if ( direction === "first" || direction === "last" ) {
  4857. next = this.active
  4858. [ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" )
  4859. .eq( -1 );
  4860. } else {
  4861. next = this.active
  4862. [ direction + "All" ]( ".ui-menu-item" )
  4863. .eq( 0 );
  4864. }
  4865. }
  4866. if ( !next || !next.length || !this.active ) {
  4867. next = this.activeMenu.children( ".ui-menu-item" )[ filter ]();
  4868. }
  4869. this.focus( event, next );
  4870. },
  4871. nextPage: function( event ) {
  4872. var item, base, height;
  4873. if ( !this.active ) {
  4874. this.next( event );
  4875. return;
  4876. }
  4877. if ( this.isLastItem() ) {
  4878. return;
  4879. }
  4880. if ( this._hasScroll() ) {
  4881. base = this.active.offset().top;
  4882. height = this.element.height();
  4883. this.active.nextAll( ".ui-menu-item" ).each(function() {
  4884. item = $( this );
  4885. return item.offset().top - base - height < 0;
  4886. });
  4887. this.focus( event, item );
  4888. } else {
  4889. this.focus( event, this.activeMenu.children( ".ui-menu-item" )
  4890. [ !this.active ? "first" : "last" ]() );
  4891. }
  4892. },
  4893. previousPage: function( event ) {
  4894. var item, base, height;
  4895. if ( !this.active ) {
  4896. this.next( event );
  4897. return;
  4898. }
  4899. if ( this.isFirstItem() ) {
  4900. return;
  4901. }
  4902. if ( this._hasScroll() ) {
  4903. base = this.active.offset().top;
  4904. height = this.element.height();
  4905. this.active.prevAll( ".ui-menu-item" ).each(function() {
  4906. item = $( this );
  4907. return item.offset().top - base + height > 0;
  4908. });
  4909. this.focus( event, item );
  4910. } else {
  4911. this.focus( event, this.activeMenu.children( ".ui-menu-item" ).first() );
  4912. }
  4913. },
  4914. _hasScroll: function() {
  4915. return this.element.outerHeight() < this.element.prop( "scrollHeight" );
  4916. },
  4917. select: function( event ) {
  4918. // TODO: It should never be possible to not have an active item at this
  4919. // point, but the tests don't trigger mouseenter before click.
  4920. this.active = this.active || $( event.target ).closest( ".ui-menu-item" );
  4921. var ui = { item: this.active };
  4922. if ( !this.active.has( ".ui-menu" ).length ) {
  4923. this.collapseAll( event, true );
  4924. }
  4925. this._trigger( "select", event, ui );
  4926. }
  4927. });
  4928. }( jQuery ));