123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406 |
- (function(window) {
- (function( global, factory ) {
- if ( typeof module === "object" && typeof module.exports === "object" ) {
-
-
-
-
-
-
-
- module.exports = global.document ?
- factory( global, true ) :
- function( w ) {
- if ( !w.document ) {
- throw new Error( "jQuery requires a window with a document" );
- }
- return factory( w );
- };
- } else {
- factory( global );
- }
- }(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
- var arr = [];
- var slice = arr.slice;
- var concat = arr.concat;
- var push = arr.push;
- var indexOf = arr.indexOf;
- var class2type = {};
- var toString = class2type.toString;
- var hasOwn = class2type.hasOwnProperty;
- var support = {};
- var
-
- document = window.document,
- version = "2.1.1",
-
- jQuery = function( selector, context ) {
-
-
- return new jQuery.fn.init( selector, context );
- },
-
-
- rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
-
- rmsPrefix = /^-ms-/,
- rdashAlpha = /-([\da-z])/gi,
-
- fcamelCase = function( all, letter ) {
- return letter.toUpperCase();
- };
- jQuery.fn = jQuery.prototype = {
-
- jquery: version,
- constructor: jQuery,
-
- selector: "",
-
- length: 0,
- toArray: function() {
- return slice.call( this );
- },
-
-
- get: function( num ) {
- return num != null ?
-
- ( num < 0 ? this[ num + this.length ] : this[ num ] ) :
-
- slice.call( this );
- },
-
-
- pushStack: function( elems ) {
-
- var ret = jQuery.merge( this.constructor(), elems );
-
- ret.prevObject = this;
- ret.context = this.context;
-
- return ret;
- },
-
-
-
- each: function( callback, args ) {
- return jQuery.each( this, callback, args );
- },
- map: function( callback ) {
- return this.pushStack( jQuery.map(this, function( elem, i ) {
- return callback.call( elem, i, elem );
- }));
- },
- slice: function() {
- return this.pushStack( slice.apply( this, arguments ) );
- },
- first: function() {
- return this.eq( 0 );
- },
- last: function() {
- return this.eq( -1 );
- },
- eq: function( i ) {
- var len = this.length,
- j = +i + ( i < 0 ? len : 0 );
- return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
- },
- end: function() {
- return this.prevObject || this.constructor(null);
- },
-
-
- push: push,
- sort: arr.sort,
- splice: arr.splice
- };
- jQuery.extend = jQuery.fn.extend = function() {
- var options, name, src, copy, copyIsArray, clone,
- target = arguments[0] || {},
- i = 1,
- length = arguments.length,
- deep = false;
-
- if ( typeof target === "boolean" ) {
- deep = target;
-
- target = arguments[ i ] || {};
- i++;
- }
-
- if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
- target = {};
- }
-
- if ( i === length ) {
- target = this;
- i--;
- }
- for ( ; i < length; i++ ) {
-
- if ( (options = arguments[ i ]) != null ) {
-
- for ( name in options ) {
- src = target[ name ];
- copy = options[ name ];
-
- if ( target === copy ) {
- continue;
- }
-
- if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
- if ( copyIsArray ) {
- copyIsArray = false;
- clone = src && jQuery.isArray(src) ? src : [];
- } else {
- clone = src && jQuery.isPlainObject(src) ? src : {};
- }
-
- target[ name ] = jQuery.extend( deep, clone, copy );
-
- } else if ( copy !== undefined ) {
- target[ name ] = copy;
- }
- }
- }
- }
-
- return target;
- };
- jQuery.extend({
-
- expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
-
- isReady: true,
- error: function( msg ) {
- throw new Error( msg );
- },
- noop: function() {},
-
-
-
- isFunction: function( obj ) {
- return jQuery.type(obj) === "function";
- },
- isArray: Array.isArray,
- isWindow: function( obj ) {
- return obj != null && obj === obj.window;
- },
- isNumeric: function( obj ) {
-
-
-
- return !jQuery.isArray( obj ) && obj - parseFloat( obj ) >= 0;
- },
- isPlainObject: function( obj ) {
-
-
-
-
- if ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
- return false;
- }
- if ( obj.constructor &&
- !hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
- return false;
- }
-
-
- return true;
- },
- isEmptyObject: function( obj ) {
- var name;
- for ( name in obj ) {
- return false;
- }
- return true;
- },
- type: function( obj ) {
- if ( obj == null ) {
- return obj + "";
- }
-
- return typeof obj === "object" || typeof obj === "function" ?
- class2type[ toString.call(obj) ] || "object" :
- typeof obj;
- },
-
- globalEval: function( code ) {
- var script,
- indirect = eval;
- code = jQuery.trim( code );
- if ( code ) {
-
-
-
- if ( code.indexOf("use strict") === 1 ) {
- script = document.createElement("script");
- script.text = code;
- document.head.appendChild( script ).parentNode.removeChild( script );
- } else {
-
-
- indirect( code );
- }
- }
- },
-
-
- camelCase: function( string ) {
- return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
- },
- nodeName: function( elem, name ) {
- return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
- },
-
- each: function( obj, callback, args ) {
- var value,
- i = 0,
- length = obj.length,
- isArray = isArraylike( obj );
- if ( args ) {
- if ( isArray ) {
- for ( ; i < length; i++ ) {
- value = callback.apply( obj[ i ], args );
- if ( value === false ) {
- break;
- }
- }
- } else {
- for ( i in obj ) {
- value = callback.apply( obj[ i ], args );
- if ( value === false ) {
- break;
- }
- }
- }
-
- } else {
- if ( isArray ) {
- for ( ; i < length; i++ ) {
- value = callback.call( obj[ i ], i, obj[ i ] );
- if ( value === false ) {
- break;
- }
- }
- } else {
- for ( i in obj ) {
- value = callback.call( obj[ i ], i, obj[ i ] );
- if ( value === false ) {
- break;
- }
- }
- }
- }
- return obj;
- },
-
- trim: function( text ) {
- return text == null ?
- "" :
- ( text + "" ).replace( rtrim, "" );
- },
-
- makeArray: function( arr, results ) {
- var ret = results || [];
- if ( arr != null ) {
- if ( isArraylike( Object(arr) ) ) {
- jQuery.merge( ret,
- typeof arr === "string" ?
- [ arr ] : arr
- );
- } else {
- push.call( ret, arr );
- }
- }
- return ret;
- },
- inArray: function( elem, arr, i ) {
- return arr == null ? -1 : indexOf.call( arr, elem, i );
- },
- merge: function( first, second ) {
- var len = +second.length,
- j = 0,
- i = first.length;
- for ( ; j < len; j++ ) {
- first[ i++ ] = second[ j ];
- }
- first.length = i;
- return first;
- },
- grep: function( elems, callback, invert ) {
- var callbackInverse,
- matches = [],
- i = 0,
- length = elems.length,
- callbackExpect = !invert;
-
-
- for ( ; i < length; i++ ) {
- callbackInverse = !callback( elems[ i ], i );
- if ( callbackInverse !== callbackExpect ) {
- matches.push( elems[ i ] );
- }
- }
- return matches;
- },
-
- map: function( elems, callback, arg ) {
- var value,
- i = 0,
- length = elems.length,
- isArray = isArraylike( elems ),
- ret = [];
-
- if ( isArray ) {
- for ( ; i < length; i++ ) {
- value = callback( elems[ i ], i, arg );
- if ( value != null ) {
- ret.push( value );
- }
- }
-
- } else {
- for ( i in elems ) {
- value = callback( elems[ i ], i, arg );
- if ( value != null ) {
- ret.push( value );
- }
- }
- }
-
- return concat.apply( [], ret );
- },
-
- guid: 1,
-
-
- proxy: function( fn, context ) {
- var tmp, args, proxy;
- if ( typeof context === "string" ) {
- tmp = fn[ context ];
- context = fn;
- fn = tmp;
- }
-
-
- if ( !jQuery.isFunction( fn ) ) {
- return undefined;
- }
-
- args = slice.call( arguments, 2 );
- proxy = function() {
- return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
- };
-
- proxy.guid = fn.guid = fn.guid || jQuery.guid++;
- return proxy;
- },
- now: Date.now,
-
-
- support: support
- });
- jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
- class2type[ "[object " + name + "]" ] = name.toLowerCase();
- });
- function isArraylike( obj ) {
- var length = obj.length,
- type = jQuery.type( obj );
- if ( type === "function" || jQuery.isWindow( obj ) ) {
- return false;
- }
- if ( obj.nodeType === 1 && length ) {
- return true;
- }
- return type === "array" || length === 0 ||
- typeof length === "number" && length > 0 && ( length - 1 ) in obj;
- }
- var Sizzle =
- (function( window ) {
- var i,
- support,
- Expr,
- getText,
- isXML,
- tokenize,
- compile,
- select,
- outermostContext,
- sortInput,
- hasDuplicate,
-
- setDocument,
- document,
- docElem,
- documentIsHTML,
- rbuggyQSA,
- rbuggyMatches,
- matches,
- contains,
-
- expando = "sizzle" + -(new Date()),
- preferredDoc = window.document,
- dirruns = 0,
- done = 0,
- classCache = createCache(),
- tokenCache = createCache(),
- compilerCache = createCache(),
- sortOrder = function( a, b ) {
- if ( a === b ) {
- hasDuplicate = true;
- }
- return 0;
- },
-
- strundefined = typeof undefined,
- MAX_NEGATIVE = 1 << 31,
-
- hasOwn = ({}).hasOwnProperty,
- arr = [],
- pop = arr.pop,
- push_native = arr.push,
- push = arr.push,
- slice = arr.slice,
-
- indexOf = arr.indexOf || function( elem ) {
- var i = 0,
- len = this.length;
- for ( ; i < len; i++ ) {
- if ( this[i] === elem ) {
- return i;
- }
- }
- return -1;
- },
- booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
-
-
- whitespace = "[\\x20\\t\\r\\n\\f]",
-
- characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",
-
-
-
- identifier = characterEncoding.replace( "w", "w#" ),
-
- attributes = "\\[" + whitespace + "*(" + characterEncoding + ")(?:" + whitespace +
-
- "*([*^$|!~]?=)" + whitespace +
-
- "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace +
- "*\\]",
- pseudos = ":(" + characterEncoding + ")(?:\\((" +
-
-
- "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" +
-
- "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" +
-
- ".*" +
- ")\\)|)",
-
- rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
- rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
- rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ),
- rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ),
- rpseudo = new RegExp( pseudos ),
- ridentifier = new RegExp( "^" + identifier + "$" ),
- matchExpr = {
- "ID": new RegExp( "^#(" + characterEncoding + ")" ),
- "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ),
- "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ),
- "ATTR": new RegExp( "^" + attributes ),
- "PSEUDO": new RegExp( "^" + pseudos ),
- "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
- "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
- "*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
- "bool": new RegExp( "^(?:" + booleans + ")$", "i" ),
-
-
- "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
- whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
- },
- rinputs = /^(?:input|select|textarea|button)$/i,
- rheader = /^h\d$/i,
- rnative = /^[^{]+\{\s*\[native \w/,
-
- rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
- rsibling = /[+~]/,
- rescape = /'|\\/g,
-
- runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
- funescape = function( _, escaped, escapedWhitespace ) {
- var high = "0x" + escaped - 0x10000;
-
-
-
- return high !== high || escapedWhitespace ?
- escaped :
- high < 0 ?
-
- String.fromCharCode( high + 0x10000 ) :
-
- String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
- };
- try {
- push.apply(
- (arr = slice.call( preferredDoc.childNodes )),
- preferredDoc.childNodes
- );
-
-
- arr[ preferredDoc.childNodes.length ].nodeType;
- } catch ( e ) {
- push = { apply: arr.length ?
-
- function( target, els ) {
- push_native.apply( target, slice.call(els) );
- } :
-
-
- function( target, els ) {
- var j = target.length,
- i = 0;
-
- while ( (target[j++] = els[i++]) ) {}
- target.length = j - 1;
- }
- };
- }
- function Sizzle( selector, context, results, seed ) {
- var match, elem, m, nodeType,
-
- i, groups, old, nid, newContext, newSelector;
- if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
- setDocument( context );
- }
- context = context || document;
- results = results || [];
- if ( !selector || typeof selector !== "string" ) {
- return results;
- }
- if ( (nodeType = context.nodeType) !== 1 && nodeType !== 9 ) {
- return [];
- }
- if ( documentIsHTML && !seed ) {
-
- if ( (match = rquickExpr.exec( selector )) ) {
-
- if ( (m = match[1]) ) {
- if ( nodeType === 9 ) {
- elem = context.getElementById( m );
-
-
- if ( elem && elem.parentNode ) {
-
-
- if ( elem.id === m ) {
- results.push( elem );
- return results;
- }
- } else {
- return results;
- }
- } else {
-
- if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) &&
- contains( context, elem ) && elem.id === m ) {
- results.push( elem );
- return results;
- }
- }
-
- } else if ( match[2] ) {
- push.apply( results, context.getElementsByTagName( selector ) );
- return results;
-
- } else if ( (m = match[3]) && support.getElementsByClassName && context.getElementsByClassName ) {
- push.apply( results, context.getElementsByClassName( m ) );
- return results;
- }
- }
-
- if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
- nid = old = expando;
- newContext = context;
- newSelector = nodeType === 9 && selector;
-
-
-
-
- if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
- groups = tokenize( selector );
- if ( (old = context.getAttribute("id")) ) {
- nid = old.replace( rescape, "\\$&" );
- } else {
- context.setAttribute( "id", nid );
- }
- nid = "[id='" + nid + "'] ";
- i = groups.length;
- while ( i-- ) {
- groups[i] = nid + toSelector( groups[i] );
- }
- newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context;
- newSelector = groups.join(",");
- }
- if ( newSelector ) {
- try {
- push.apply( results,
- newContext.querySelectorAll( newSelector )
- );
- return results;
- } catch(qsaError) {
- } finally {
- if ( !old ) {
- context.removeAttribute("id");
- }
- }
- }
- }
- }
-
- return select( selector.replace( rtrim, "$1" ), context, results, seed );
- }
- function createCache() {
- var keys = [];
- function cache( key, value ) {
-
- if ( keys.push( key + " " ) > Expr.cacheLength ) {
-
- delete cache[ keys.shift() ];
- }
- return (cache[ key + " " ] = value);
- }
- return cache;
- }
- function markFunction( fn ) {
- fn[ expando ] = true;
- return fn;
- }
- function assert( fn ) {
- var div = document.createElement("div");
- try {
- return !!fn( div );
- } catch (e) {
- return false;
- } finally {
-
- if ( div.parentNode ) {
- div.parentNode.removeChild( div );
- }
-
- div = null;
- }
- }
- function addHandle( attrs, handler ) {
- var arr = attrs.split("|"),
- i = attrs.length;
- while ( i-- ) {
- Expr.attrHandle[ arr[i] ] = handler;
- }
- }
- function siblingCheck( a, b ) {
- var cur = b && a,
- diff = cur && a.nodeType === 1 && b.nodeType === 1 &&
- ( ~b.sourceIndex || MAX_NEGATIVE ) -
- ( ~a.sourceIndex || MAX_NEGATIVE );
-
- if ( diff ) {
- return diff;
- }
-
- if ( cur ) {
- while ( (cur = cur.nextSibling) ) {
- if ( cur === b ) {
- return -1;
- }
- }
- }
- return a ? 1 : -1;
- }
- function createInputPseudo( type ) {
- return function( elem ) {
- var name = elem.nodeName.toLowerCase();
- return name === "input" && elem.type === type;
- };
- }
- function createButtonPseudo( type ) {
- return function( elem ) {
- var name = elem.nodeName.toLowerCase();
- return (name === "input" || name === "button") && elem.type === type;
- };
- }
- function createPositionalPseudo( fn ) {
- return markFunction(function( argument ) {
- argument = +argument;
- return markFunction(function( seed, matches ) {
- var j,
- matchIndexes = fn( [], seed.length, argument ),
- i = matchIndexes.length;
-
- while ( i-- ) {
- if ( seed[ (j = matchIndexes[i]) ] ) {
- seed[j] = !(matches[j] = seed[j]);
- }
- }
- });
- });
- }
- function testContext( context ) {
- return context && typeof context.getElementsByTagName !== strundefined && context;
- }
- support = Sizzle.support = {};
- isXML = Sizzle.isXML = function( elem ) {
-
-
- var documentElement = elem && (elem.ownerDocument || elem).documentElement;
- return documentElement ? documentElement.nodeName !== "HTML" : false;
- };
- setDocument = Sizzle.setDocument = function( node ) {
- var hasCompare,
- doc = node ? node.ownerDocument || node : preferredDoc,
- parent = doc.defaultView;
-
- if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
- return document;
- }
-
- document = doc;
- docElem = doc.documentElement;
-
- documentIsHTML = !isXML( doc );
-
-
-
-
- if ( parent && parent !== parent.top ) {
-
- if ( parent.addEventListener ) {
- parent.addEventListener( "unload", function() {
- setDocument();
- }, false );
- } else if ( parent.attachEvent ) {
- parent.attachEvent( "onunload", function() {
- setDocument();
- });
- }
- }
-
-
-
- support.attributes = assert(function( div ) {
- div.className = "i";
- return !div.getAttribute("className");
- });
-
-
- support.getElementsByTagName = assert(function( div ) {
- div.appendChild( doc.createComment("") );
- return !div.getElementsByTagName("*").length;
- });
-
- support.getElementsByClassName = rnative.test( doc.getElementsByClassName ) && assert(function( div ) {
- div.innerHTML = "<div class='a'></div><div class='a i'></div>";
-
-
- div.firstChild.className = "i";
-
-
- return div.getElementsByClassName("i").length === 2;
- });
-
-
-
-
- support.getById = assert(function( div ) {
- docElem.appendChild( div ).id = expando;
- return !doc.getElementsByName || !doc.getElementsByName( expando ).length;
- });
-
- if ( support.getById ) {
- Expr.find["ID"] = function( id, context ) {
- if ( typeof context.getElementById !== strundefined && documentIsHTML ) {
- var m = context.getElementById( id );
-
-
- return m && m.parentNode ? [ m ] : [];
- }
- };
- Expr.filter["ID"] = function( id ) {
- var attrId = id.replace( runescape, funescape );
- return function( elem ) {
- return elem.getAttribute("id") === attrId;
- };
- };
- } else {
-
-
- delete Expr.find["ID"];
- Expr.filter["ID"] = function( id ) {
- var attrId = id.replace( runescape, funescape );
- return function( elem ) {
- var node = typeof elem.getAttributeNode !== strundefined && elem.getAttributeNode("id");
- return node && node.value === attrId;
- };
- };
- }
-
- Expr.find["TAG"] = support.getElementsByTagName ?
- function( tag, context ) {
- if ( typeof context.getElementsByTagName !== strundefined ) {
- return context.getElementsByTagName( tag );
- }
- } :
- function( tag, context ) {
- var elem,
- tmp = [],
- i = 0,
- results = context.getElementsByTagName( tag );
-
- if ( tag === "*" ) {
- while ( (elem = results[i++]) ) {
- if ( elem.nodeType === 1 ) {
- tmp.push( elem );
- }
- }
- return tmp;
- }
- return results;
- };
-
- Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
- if ( typeof context.getElementsByClassName !== strundefined && documentIsHTML ) {
- return context.getElementsByClassName( className );
- }
- };
-
-
-
- rbuggyMatches = [];
-
-
-
-
-
- rbuggyQSA = [];
- if ( (support.qsa = rnative.test( doc.querySelectorAll )) ) {
-
-
- assert(function( div ) {
-
-
-
-
-
- div.innerHTML = "<select msallowclip=''><option selected=''></option></select>";
-
-
-
-
- if ( div.querySelectorAll("[msallowclip^='']").length ) {
- rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
- }
-
-
- if ( !div.querySelectorAll("[selected]").length ) {
- rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
- }
-
-
-
- if ( !div.querySelectorAll(":checked").length ) {
- rbuggyQSA.push(":checked");
- }
- });
- assert(function( div ) {
-
-
- var input = doc.createElement("input");
- input.setAttribute( "type", "hidden" );
- div.appendChild( input ).setAttribute( "name", "D" );
-
-
- if ( div.querySelectorAll("[name=d]").length ) {
- rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
- }
-
-
- if ( !div.querySelectorAll(":enabled").length ) {
- rbuggyQSA.push( ":enabled", ":disabled" );
- }
-
- div.querySelectorAll("*,:x");
- rbuggyQSA.push(",.*:");
- });
- }
- if ( (support.matchesSelector = rnative.test( (matches = docElem.matches ||
- docElem.webkitMatchesSelector ||
- docElem.mozMatchesSelector ||
- docElem.oMatchesSelector ||
- docElem.msMatchesSelector) )) ) {
- assert(function( div ) {
-
-
- support.disconnectedMatch = matches.call( div, "div" );
-
-
- matches.call( div, "[s!='']:x" );
- rbuggyMatches.push( "!=", pseudos );
- });
- }
- rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
- rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
-
- hasCompare = rnative.test( docElem.compareDocumentPosition );
-
-
-
- contains = hasCompare || rnative.test( docElem.contains ) ?
- function( a, b ) {
- var adown = a.nodeType === 9 ? a.documentElement : a,
- bup = b && b.parentNode;
- return a === bup || !!( bup && bup.nodeType === 1 && (
- adown.contains ?
- adown.contains( bup ) :
- a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
- ));
- } :
- function( a, b ) {
- if ( b ) {
- while ( (b = b.parentNode) ) {
- if ( b === a ) {
- return true;
- }
- }
- }
- return false;
- };
-
-
- sortOrder = hasCompare ?
- function( a, b ) {
-
- if ( a === b ) {
- hasDuplicate = true;
- return 0;
- }
-
- var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
- if ( compare ) {
- return compare;
- }
-
- compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
- a.compareDocumentPosition( b ) :
-
- 1;
-
- if ( compare & 1 ||
- (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {
-
- if ( a === doc || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {
- return -1;
- }
- if ( b === doc || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {
- return 1;
- }
-
- return sortInput ?
- ( indexOf.call( sortInput, a ) - indexOf.call( sortInput, b ) ) :
- 0;
- }
- return compare & 4 ? -1 : 1;
- } :
- function( a, b ) {
-
- if ( a === b ) {
- hasDuplicate = true;
- return 0;
- }
- var cur,
- i = 0,
- aup = a.parentNode,
- bup = b.parentNode,
- ap = [ a ],
- bp = [ b ];
-
- if ( !aup || !bup ) {
- return a === doc ? -1 :
- b === doc ? 1 :
- aup ? -1 :
- bup ? 1 :
- sortInput ?
- ( indexOf.call( sortInput, a ) - indexOf.call( sortInput, b ) ) :
- 0;
-
- } else if ( aup === bup ) {
- return siblingCheck( a, b );
- }
-
- cur = a;
- while ( (cur = cur.parentNode) ) {
- ap.unshift( cur );
- }
- cur = b;
- while ( (cur = cur.parentNode) ) {
- bp.unshift( cur );
- }
-
- while ( ap[i] === bp[i] ) {
- i++;
- }
- return i ?
-
- siblingCheck( ap[i], bp[i] ) :
-
- ap[i] === preferredDoc ? -1 :
- bp[i] === preferredDoc ? 1 :
- 0;
- };
- return doc;
- };
- Sizzle.matches = function( expr, elements ) {
- return Sizzle( expr, null, null, elements );
- };
- Sizzle.matchesSelector = function( elem, expr ) {
-
- if ( ( elem.ownerDocument || elem ) !== document ) {
- setDocument( elem );
- }
-
- expr = expr.replace( rattributeQuotes, "='$1']" );
- if ( support.matchesSelector && documentIsHTML &&
- ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
- ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
- try {
- var ret = matches.call( elem, expr );
-
- if ( ret || support.disconnectedMatch ||
-
-
- elem.document && elem.document.nodeType !== 11 ) {
- return ret;
- }
- } catch(e) {}
- }
- return Sizzle( expr, document, null, [ elem ] ).length > 0;
- };
- Sizzle.contains = function( context, elem ) {
-
- if ( ( context.ownerDocument || context ) !== document ) {
- setDocument( context );
- }
- return contains( context, elem );
- };
- Sizzle.attr = function( elem, name ) {
-
- if ( ( elem.ownerDocument || elem ) !== document ) {
- setDocument( elem );
- }
- var fn = Expr.attrHandle[ name.toLowerCase() ],
-
- val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
- fn( elem, name, !documentIsHTML ) :
- undefined;
- return val !== undefined ?
- val :
- support.attributes || !documentIsHTML ?
- elem.getAttribute( name ) :
- (val = elem.getAttributeNode(name)) && val.specified ?
- val.value :
- null;
- };
- Sizzle.error = function( msg ) {
- throw new Error( "Syntax error, unrecognized expression: " + msg );
- };
- Sizzle.uniqueSort = function( results ) {
- var elem,
- duplicates = [],
- j = 0,
- i = 0;
-
- hasDuplicate = !support.detectDuplicates;
- sortInput = !support.sortStable && results.slice( 0 );
- results.sort( sortOrder );
- if ( hasDuplicate ) {
- while ( (elem = results[i++]) ) {
- if ( elem === results[ i ] ) {
- j = duplicates.push( i );
- }
- }
- while ( j-- ) {
- results.splice( duplicates[ j ], 1 );
- }
- }
-
-
- sortInput = null;
- return results;
- };
- getText = Sizzle.getText = function( elem ) {
- var node,
- ret = "",
- i = 0,
- nodeType = elem.nodeType;
- if ( !nodeType ) {
-
- while ( (node = elem[i++]) ) {
-
- ret += getText( node );
- }
- } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
-
-
- if ( typeof elem.textContent === "string" ) {
- return elem.textContent;
- } else {
-
- for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
- ret += getText( elem );
- }
- }
- } else if ( nodeType === 3 || nodeType === 4 ) {
- return elem.nodeValue;
- }
-
- return ret;
- };
- Expr = Sizzle.selectors = {
-
- cacheLength: 50,
- createPseudo: markFunction,
- match: matchExpr,
- attrHandle: {},
- find: {},
- relative: {
- ">": { dir: "parentNode", first: true },
- " ": { dir: "parentNode" },
- "+": { dir: "previousSibling", first: true },
- "~": { dir: "previousSibling" }
- },
- preFilter: {
- "ATTR": function( match ) {
- match[1] = match[1].replace( runescape, funescape );
-
- match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape );
- if ( match[2] === "~=" ) {
- match[3] = " " + match[3] + " ";
- }
- return match.slice( 0, 4 );
- },
- "CHILD": function( match ) {
-
- match[1] = match[1].toLowerCase();
- if ( match[1].slice( 0, 3 ) === "nth" ) {
-
- if ( !match[3] ) {
- Sizzle.error( match[0] );
- }
-
-
- match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
- match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
-
- } else if ( match[3] ) {
- Sizzle.error( match[0] );
- }
- return match;
- },
- "PSEUDO": function( match ) {
- var excess,
- unquoted = !match[6] && match[2];
- if ( matchExpr["CHILD"].test( match[0] ) ) {
- return null;
- }
-
- if ( match[3] ) {
- match[2] = match[4] || match[5] || "";
-
- } else if ( unquoted && rpseudo.test( unquoted ) &&
-
- (excess = tokenize( unquoted, true )) &&
-
- (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
-
- match[0] = match[0].slice( 0, excess );
- match[2] = unquoted.slice( 0, excess );
- }
-
- return match.slice( 0, 3 );
- }
- },
- filter: {
- "TAG": function( nodeNameSelector ) {
- var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
- return nodeNameSelector === "*" ?
- function() { return true; } :
- function( elem ) {
- return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
- };
- },
- "CLASS": function( className ) {
- var pattern = classCache[ className + " " ];
- return pattern ||
- (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
- classCache( className, function( elem ) {
- return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== strundefined && elem.getAttribute("class") || "" );
- });
- },
- "ATTR": function( name, operator, check ) {
- return function( elem ) {
- var result = Sizzle.attr( elem, name );
- if ( result == null ) {
- return operator === "!=";
- }
- if ( !operator ) {
- return true;
- }
- result += "";
- return operator === "=" ? result === check :
- operator === "!=" ? result !== check :
- operator === "^=" ? check && result.indexOf( check ) === 0 :
- operator === "*=" ? check && result.indexOf( check ) > -1 :
- operator === "$=" ? check && result.slice( -check.length ) === check :
- operator === "~=" ? ( " " + result + " " ).indexOf( check ) > -1 :
- operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
- false;
- };
- },
- "CHILD": function( type, what, argument, first, last ) {
- var simple = type.slice( 0, 3 ) !== "nth",
- forward = type.slice( -4 ) !== "last",
- ofType = what === "of-type";
- return first === 1 && last === 0 ?
-
- function( elem ) {
- return !!elem.parentNode;
- } :
- function( elem, context, xml ) {
- var cache, outerCache, node, diff, nodeIndex, start,
- dir = simple !== forward ? "nextSibling" : "previousSibling",
- parent = elem.parentNode,
- name = ofType && elem.nodeName.toLowerCase(),
- useCache = !xml && !ofType;
- if ( parent ) {
-
- if ( simple ) {
- while ( dir ) {
- node = elem;
- while ( (node = node[ dir ]) ) {
- if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) {
- return false;
- }
- }
-
- start = dir = type === "only" && !start && "nextSibling";
- }
- return true;
- }
- start = [ forward ? parent.firstChild : parent.lastChild ];
-
- if ( forward && useCache ) {
-
- outerCache = parent[ expando ] || (parent[ expando ] = {});
- cache = outerCache[ type ] || [];
- nodeIndex = cache[0] === dirruns && cache[1];
- diff = cache[0] === dirruns && cache[2];
- node = nodeIndex && parent.childNodes[ nodeIndex ];
- while ( (node = ++nodeIndex && node && node[ dir ] ||
-
- (diff = nodeIndex = 0) || start.pop()) ) {
-
- if ( node.nodeType === 1 && ++diff && node === elem ) {
- outerCache[ type ] = [ dirruns, nodeIndex, diff ];
- break;
- }
- }
-
- } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) {
- diff = cache[1];
-
- } else {
-
- while ( (node = ++nodeIndex && node && node[ dir ] ||
- (diff = nodeIndex = 0) || start.pop()) ) {
- if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) {
-
- if ( useCache ) {
- (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ];
- }
- if ( node === elem ) {
- break;
- }
- }
- }
- }
-
- diff -= last;
- return diff === first || ( diff % first === 0 && diff / first >= 0 );
- }
- };
- },
- "PSEUDO": function( pseudo, argument ) {
-
-
-
-
- var args,
- fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
- Sizzle.error( "unsupported pseudo: " + pseudo );
-
-
-
- if ( fn[ expando ] ) {
- return fn( argument );
- }
-
- if ( fn.length > 1 ) {
- args = [ pseudo, pseudo, "", argument ];
- return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
- markFunction(function( seed, matches ) {
- var idx,
- matched = fn( seed, argument ),
- i = matched.length;
- while ( i-- ) {
- idx = indexOf.call( seed, matched[i] );
- seed[ idx ] = !( matches[ idx ] = matched[i] );
- }
- }) :
- function( elem ) {
- return fn( elem, 0, args );
- };
- }
- return fn;
- }
- },
- pseudos: {
-
- "not": markFunction(function( selector ) {
-
-
-
- var input = [],
- results = [],
- matcher = compile( selector.replace( rtrim, "$1" ) );
- return matcher[ expando ] ?
- markFunction(function( seed, matches, context, xml ) {
- var elem,
- unmatched = matcher( seed, null, xml, [] ),
- i = seed.length;
-
- while ( i-- ) {
- if ( (elem = unmatched[i]) ) {
- seed[i] = !(matches[i] = elem);
- }
- }
- }) :
- function( elem, context, xml ) {
- input[0] = elem;
- matcher( input, null, xml, results );
- return !results.pop();
- };
- }),
- "has": markFunction(function( selector ) {
- return function( elem ) {
- return Sizzle( selector, elem ).length > 0;
- };
- }),
- "contains": markFunction(function( text ) {
- return function( elem ) {
- return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
- };
- }),
-
-
-
-
-
-
-
- "lang": markFunction( function( lang ) {
-
- if ( !ridentifier.test(lang || "") ) {
- Sizzle.error( "unsupported lang: " + lang );
- }
- lang = lang.replace( runescape, funescape ).toLowerCase();
- return function( elem ) {
- var elemLang;
- do {
- if ( (elemLang = documentIsHTML ?
- elem.lang :
- elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
- elemLang = elemLang.toLowerCase();
- return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
- }
- } while ( (elem = elem.parentNode) && elem.nodeType === 1 );
- return false;
- };
- }),
-
- "target": function( elem ) {
- var hash = window.location && window.location.hash;
- return hash && hash.slice( 1 ) === elem.id;
- },
- "root": function( elem ) {
- return elem === docElem;
- },
- "focus": function( elem ) {
- return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
- },
-
- "enabled": function( elem ) {
- return elem.disabled === false;
- },
- "disabled": function( elem ) {
- return elem.disabled === true;
- },
- "checked": function( elem ) {
-
-
- var nodeName = elem.nodeName.toLowerCase();
- return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
- },
- "selected": function( elem ) {
-
-
- if ( elem.parentNode ) {
- elem.parentNode.selectedIndex;
- }
- return elem.selected === true;
- },
-
- "empty": function( elem ) {
-
-
-
-
- for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
- if ( elem.nodeType < 6 ) {
- return false;
- }
- }
- return true;
- },
- "parent": function( elem ) {
- return !Expr.pseudos["empty"]( elem );
- },
-
- "header": function( elem ) {
- return rheader.test( elem.nodeName );
- },
- "input": function( elem ) {
- return rinputs.test( elem.nodeName );
- },
- "button": function( elem ) {
- var name = elem.nodeName.toLowerCase();
- return name === "input" && elem.type === "button" || name === "button";
- },
- "text": function( elem ) {
- var attr;
- return elem.nodeName.toLowerCase() === "input" &&
- elem.type === "text" &&
-
-
- ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" );
- },
-
- "first": createPositionalPseudo(function() {
- return [ 0 ];
- }),
- "last": createPositionalPseudo(function( matchIndexes, length ) {
- return [ length - 1 ];
- }),
- "eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
- return [ argument < 0 ? argument + length : argument ];
- }),
- "even": createPositionalPseudo(function( matchIndexes, length ) {
- var i = 0;
- for ( ; i < length; i += 2 ) {
- matchIndexes.push( i );
- }
- return matchIndexes;
- }),
- "odd": createPositionalPseudo(function( matchIndexes, length ) {
- var i = 1;
- for ( ; i < length; i += 2 ) {
- matchIndexes.push( i );
- }
- return matchIndexes;
- }),
- "lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
- var i = argument < 0 ? argument + length : argument;
- for ( ; --i >= 0; ) {
- matchIndexes.push( i );
- }
- return matchIndexes;
- }),
- "gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
- var i = argument < 0 ? argument + length : argument;
- for ( ; ++i < length; ) {
- matchIndexes.push( i );
- }
- return matchIndexes;
- })
- }
- };
- Expr.pseudos["nth"] = Expr.pseudos["eq"];
- for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
- Expr.pseudos[ i ] = createInputPseudo( i );
- }
- for ( i in { submit: true, reset: true } ) {
- Expr.pseudos[ i ] = createButtonPseudo( i );
- }
- function setFilters() {}
- setFilters.prototype = Expr.filters = Expr.pseudos;
- Expr.setFilters = new setFilters();
- tokenize = Sizzle.tokenize = function( selector, parseOnly ) {
- var matched, match, tokens, type,
- soFar, groups, preFilters,
- cached = tokenCache[ selector + " " ];
- if ( cached ) {
- return parseOnly ? 0 : cached.slice( 0 );
- }
- soFar = selector;
- groups = [];
- preFilters = Expr.preFilter;
- while ( soFar ) {
-
- if ( !matched || (match = rcomma.exec( soFar )) ) {
- if ( match ) {
-
- soFar = soFar.slice( match[0].length ) || soFar;
- }
- groups.push( (tokens = []) );
- }
- matched = false;
-
- if ( (match = rcombinators.exec( soFar )) ) {
- matched = match.shift();
- tokens.push({
- value: matched,
-
- type: match[0].replace( rtrim, " " )
- });
- soFar = soFar.slice( matched.length );
- }
-
- for ( type in Expr.filter ) {
- if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
- (match = preFilters[ type ]( match ))) ) {
- matched = match.shift();
- tokens.push({
- value: matched,
- type: type,
- matches: match
- });
- soFar = soFar.slice( matched.length );
- }
- }
- if ( !matched ) {
- break;
- }
- }
-
-
-
- return parseOnly ?
- soFar.length :
- soFar ?
- Sizzle.error( selector ) :
-
- tokenCache( selector, groups ).slice( 0 );
- };
- function toSelector( tokens ) {
- var i = 0,
- len = tokens.length,
- selector = "";
- for ( ; i < len; i++ ) {
- selector += tokens[i].value;
- }
- return selector;
- }
- function addCombinator( matcher, combinator, base ) {
- var dir = combinator.dir,
- checkNonElements = base && dir === "parentNode",
- doneName = done++;
- return combinator.first ?
-
- function( elem, context, xml ) {
- while ( (elem = elem[ dir ]) ) {
- if ( elem.nodeType === 1 || checkNonElements ) {
- return matcher( elem, context, xml );
- }
- }
- } :
-
- function( elem, context, xml ) {
- var oldCache, outerCache,
- newCache = [ dirruns, doneName ];
-
- if ( xml ) {
- while ( (elem = elem[ dir ]) ) {
- if ( elem.nodeType === 1 || checkNonElements ) {
- if ( matcher( elem, context, xml ) ) {
- return true;
- }
- }
- }
- } else {
- while ( (elem = elem[ dir ]) ) {
- if ( elem.nodeType === 1 || checkNonElements ) {
- outerCache = elem[ expando ] || (elem[ expando ] = {});
- if ( (oldCache = outerCache[ dir ]) &&
- oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
-
- return (newCache[ 2 ] = oldCache[ 2 ]);
- } else {
-
- outerCache[ dir ] = newCache;
-
- if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
- return true;
- }
- }
- }
- }
- }
- };
- }
- function elementMatcher( matchers ) {
- return matchers.length > 1 ?
- function( elem, context, xml ) {
- var i = matchers.length;
- while ( i-- ) {
- if ( !matchers[i]( elem, context, xml ) ) {
- return false;
- }
- }
- return true;
- } :
- matchers[0];
- }
- function multipleContexts( selector, contexts, results ) {
- var i = 0,
- len = contexts.length;
- for ( ; i < len; i++ ) {
- Sizzle( selector, contexts[i], results );
- }
- return results;
- }
- function condense( unmatched, map, filter, context, xml ) {
- var elem,
- newUnmatched = [],
- i = 0,
- len = unmatched.length,
- mapped = map != null;
- for ( ; i < len; i++ ) {
- if ( (elem = unmatched[i]) ) {
- if ( !filter || filter( elem, context, xml ) ) {
- newUnmatched.push( elem );
- if ( mapped ) {
- map.push( i );
- }
- }
- }
- }
- return newUnmatched;
- }
- function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
- if ( postFilter && !postFilter[ expando ] ) {
- postFilter = setMatcher( postFilter );
- }
- if ( postFinder && !postFinder[ expando ] ) {
- postFinder = setMatcher( postFinder, postSelector );
- }
- return markFunction(function( seed, results, context, xml ) {
- var temp, i, elem,
- preMap = [],
- postMap = [],
- preexisting = results.length,
-
- elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
-
- matcherIn = preFilter && ( seed || !selector ) ?
- condense( elems, preMap, preFilter, context, xml ) :
- elems,
- matcherOut = matcher ?
-
- postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
-
- [] :
-
- results :
- matcherIn;
-
- if ( matcher ) {
- matcher( matcherIn, matcherOut, context, xml );
- }
-
- if ( postFilter ) {
- temp = condense( matcherOut, postMap );
- postFilter( temp, [], context, xml );
-
- i = temp.length;
- while ( i-- ) {
- if ( (elem = temp[i]) ) {
- matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
- }
- }
- }
- if ( seed ) {
- if ( postFinder || preFilter ) {
- if ( postFinder ) {
-
- temp = [];
- i = matcherOut.length;
- while ( i-- ) {
- if ( (elem = matcherOut[i]) ) {
-
- temp.push( (matcherIn[i] = elem) );
- }
- }
- postFinder( null, (matcherOut = []), temp, xml );
- }
-
- i = matcherOut.length;
- while ( i-- ) {
- if ( (elem = matcherOut[i]) &&
- (temp = postFinder ? indexOf.call( seed, elem ) : preMap[i]) > -1 ) {
- seed[temp] = !(results[temp] = elem);
- }
- }
- }
-
- } else {
- matcherOut = condense(
- matcherOut === results ?
- matcherOut.splice( preexisting, matcherOut.length ) :
- matcherOut
- );
- if ( postFinder ) {
- postFinder( null, results, matcherOut, xml );
- } else {
- push.apply( results, matcherOut );
- }
- }
- });
- }
- function matcherFromTokens( tokens ) {
- var checkContext, matcher, j,
- len = tokens.length,
- leadingRelative = Expr.relative[ tokens[0].type ],
- implicitRelative = leadingRelative || Expr.relative[" "],
- i = leadingRelative ? 1 : 0,
-
- matchContext = addCombinator( function( elem ) {
- return elem === checkContext;
- }, implicitRelative, true ),
- matchAnyContext = addCombinator( function( elem ) {
- return indexOf.call( checkContext, elem ) > -1;
- }, implicitRelative, true ),
- matchers = [ function( elem, context, xml ) {
- return ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
- (checkContext = context).nodeType ?
- matchContext( elem, context, xml ) :
- matchAnyContext( elem, context, xml ) );
- } ];
- for ( ; i < len; i++ ) {
- if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
- matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
- } else {
- matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
-
- if ( matcher[ expando ] ) {
-
- j = ++i;
- for ( ; j < len; j++ ) {
- if ( Expr.relative[ tokens[j].type ] ) {
- break;
- }
- }
- return setMatcher(
- i > 1 && elementMatcher( matchers ),
- i > 1 && toSelector(
-
- tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
- ).replace( rtrim, "$1" ),
- matcher,
- i < j && matcherFromTokens( tokens.slice( i, j ) ),
- j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
- j < len && toSelector( tokens )
- );
- }
- matchers.push( matcher );
- }
- }
- return elementMatcher( matchers );
- }
- function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
- var bySet = setMatchers.length > 0,
- byElement = elementMatchers.length > 0,
- superMatcher = function( seed, context, xml, results, outermost ) {
- var elem, j, matcher,
- matchedCount = 0,
- i = "0",
- unmatched = seed && [],
- setMatched = [],
- contextBackup = outermostContext,
-
- elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
-
- dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
- len = elems.length;
- if ( outermost ) {
- outermostContext = context !== document && context;
- }
-
-
-
-
- for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
- if ( byElement && elem ) {
- j = 0;
- while ( (matcher = elementMatchers[j++]) ) {
- if ( matcher( elem, context, xml ) ) {
- results.push( elem );
- break;
- }
- }
- if ( outermost ) {
- dirruns = dirrunsUnique;
- }
- }
-
- if ( bySet ) {
-
- if ( (elem = !matcher && elem) ) {
- matchedCount--;
- }
-
- if ( seed ) {
- unmatched.push( elem );
- }
- }
- }
-
- matchedCount += i;
- if ( bySet && i !== matchedCount ) {
- j = 0;
- while ( (matcher = setMatchers[j++]) ) {
- matcher( unmatched, setMatched, context, xml );
- }
- if ( seed ) {
-
- if ( matchedCount > 0 ) {
- while ( i-- ) {
- if ( !(unmatched[i] || setMatched[i]) ) {
- setMatched[i] = pop.call( results );
- }
- }
- }
-
- setMatched = condense( setMatched );
- }
-
- push.apply( results, setMatched );
-
- if ( outermost && !seed && setMatched.length > 0 &&
- ( matchedCount + setMatchers.length ) > 1 ) {
- Sizzle.uniqueSort( results );
- }
- }
-
- if ( outermost ) {
- dirruns = dirrunsUnique;
- outermostContext = contextBackup;
- }
- return unmatched;
- };
- return bySet ?
- markFunction( superMatcher ) :
- superMatcher;
- }
- compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {
- var i,
- setMatchers = [],
- elementMatchers = [],
- cached = compilerCache[ selector + " " ];
- if ( !cached ) {
-
- if ( !match ) {
- match = tokenize( selector );
- }
- i = match.length;
- while ( i-- ) {
- cached = matcherFromTokens( match[i] );
- if ( cached[ expando ] ) {
- setMatchers.push( cached );
- } else {
- elementMatchers.push( cached );
- }
- }
-
- cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
-
- cached.selector = selector;
- }
- return cached;
- };
- select = Sizzle.select = function( selector, context, results, seed ) {
- var i, tokens, token, type, find,
- compiled = typeof selector === "function" && selector,
- match = !seed && tokenize( (selector = compiled.selector || selector) );
- results = results || [];
-
- if ( match.length === 1 ) {
-
- tokens = match[0] = match[0].slice( 0 );
- if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
- support.getById && context.nodeType === 9 && documentIsHTML &&
- Expr.relative[ tokens[1].type ] ) {
- context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
- if ( !context ) {
- return results;
-
- } else if ( compiled ) {
- context = context.parentNode;
- }
- selector = selector.slice( tokens.shift().value.length );
- }
-
- i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
- while ( i-- ) {
- token = tokens[i];
-
- if ( Expr.relative[ (type = token.type) ] ) {
- break;
- }
- if ( (find = Expr.find[ type ]) ) {
-
- if ( (seed = find(
- token.matches[0].replace( runescape, funescape ),
- rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
- )) ) {
-
- tokens.splice( i, 1 );
- selector = seed.length && toSelector( tokens );
- if ( !selector ) {
- push.apply( results, seed );
- return results;
- }
- break;
- }
- }
- }
- }
-
-
- ( compiled || compile( selector, match ) )(
- seed,
- context,
- !documentIsHTML,
- results,
- rsibling.test( selector ) && testContext( context.parentNode ) || context
- );
- return results;
- };
- support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
- support.detectDuplicates = !!hasDuplicate;
- setDocument();
- support.sortDetached = assert(function( div1 ) {
-
- return div1.compareDocumentPosition( document.createElement("div") ) & 1;
- });
- if ( !assert(function( div ) {
- div.innerHTML = "<a href='#'></a>";
- return div.firstChild.getAttribute("href") === "#" ;
- }) ) {
- addHandle( "type|href|height|width", function( elem, name, isXML ) {
- if ( !isXML ) {
- return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 );
- }
- });
- }
- if ( !support.attributes || !assert(function( div ) {
- div.innerHTML = "<input/>";
- div.firstChild.setAttribute( "value", "" );
- return div.firstChild.getAttribute( "value" ) === "";
- }) ) {
- addHandle( "value", function( elem, name, isXML ) {
- if ( !isXML && elem.nodeName.toLowerCase() === "input" ) {
- return elem.defaultValue;
- }
- });
- }
- if ( !assert(function( div ) {
- return div.getAttribute("disabled") == null;
- }) ) {
- addHandle( booleans, function( elem, name, isXML ) {
- var val;
- if ( !isXML ) {
- return elem[ name ] === true ? name.toLowerCase() :
- (val = elem.getAttributeNode( name )) && val.specified ?
- val.value :
- null;
- }
- });
- }
- return Sizzle;
- })( window );
- jQuery.find = Sizzle;
- jQuery.expr = Sizzle.selectors;
- jQuery.expr[":"] = jQuery.expr.pseudos;
- jQuery.unique = Sizzle.uniqueSort;
- jQuery.text = Sizzle.getText;
- jQuery.isXMLDoc = Sizzle.isXML;
- jQuery.contains = Sizzle.contains;
- var rneedsContext = jQuery.expr.match.needsContext;
- var rsingleTag = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/);
- var risSimple = /^.[^:#\[\.,]*$/;
- function winnow( elements, qualifier, not ) {
- if ( jQuery.isFunction( qualifier ) ) {
- return jQuery.grep( elements, function( elem, i ) {
-
- return !!qualifier.call( elem, i, elem ) !== not;
- });
- }
- if ( qualifier.nodeType ) {
- return jQuery.grep( elements, function( elem ) {
- return ( elem === qualifier ) !== not;
- });
- }
- if ( typeof qualifier === "string" ) {
- if ( risSimple.test( qualifier ) ) {
- return jQuery.filter( qualifier, elements, not );
- }
- qualifier = jQuery.filter( qualifier, elements );
- }
- return jQuery.grep( elements, function( elem ) {
- return ( indexOf.call( qualifier, elem ) >= 0 ) !== not;
- });
- }
- jQuery.filter = function( expr, elems, not ) {
- var elem = elems[ 0 ];
- if ( not ) {
- expr = ":not(" + expr + ")";
- }
- return elems.length === 1 && elem.nodeType === 1 ?
- jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
- jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
- return elem.nodeType === 1;
- }));
- };
- jQuery.fn.extend({
- find: function( selector ) {
- var i,
- len = this.length,
- ret = [],
- self = this;
- if ( typeof selector !== "string" ) {
- return this.pushStack( jQuery( selector ).filter(function() {
- for ( i = 0; i < len; i++ ) {
- if ( jQuery.contains( self[ i ], this ) ) {
- return true;
- }
- }
- }) );
- }
- for ( i = 0; i < len; i++ ) {
- jQuery.find( selector, self[ i ], ret );
- }
-
- ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
- ret.selector = this.selector ? this.selector + " " + selector : selector;
- return ret;
- },
- filter: function( selector ) {
- return this.pushStack( winnow(this, selector || [], false) );
- },
- not: function( selector ) {
- return this.pushStack( winnow(this, selector || [], true) );
- },
- is: function( selector ) {
- return !!winnow(
- this,
-
-
- typeof selector === "string" && rneedsContext.test( selector ) ?
- jQuery( selector ) :
- selector || [],
- false
- ).length;
- }
- });
- var rootjQuery,
-
-
-
- rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
- init = jQuery.fn.init = function( selector, context ) {
- var match, elem;
-
- if ( !selector ) {
- return this;
- }
-
- if ( typeof selector === "string" ) {
- if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) {
-
- match = [ null, selector, null ];
- } else {
- match = rquickExpr.exec( selector );
- }
-
- if ( match && (match[1] || !context) ) {
-
- if ( match[1] ) {
- context = context instanceof jQuery ? context[0] : context;
-
-
- jQuery.merge( this, jQuery.parseHTML(
- match[1],
- context && context.nodeType ? context.ownerDocument || context : document,
- true
- ) );
-
- if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
- for ( match in context ) {
-
- if ( jQuery.isFunction( this[ match ] ) ) {
- this[ match ]( context[ match ] );
-
- } else {
- this.attr( match, context[ match ] );
- }
- }
- }
- return this;
-
- } else {
- elem = document.getElementById( match[2] );
-
-
- if ( elem && elem.parentNode ) {
-
- this.length = 1;
- this[0] = elem;
- }
- this.context = document;
- this.selector = selector;
- return this;
- }
-
- } else if ( !context || context.jquery ) {
- return ( context || rootjQuery ).find( selector );
-
-
- } else {
- return this.constructor( context ).find( selector );
- }
-
- } else if ( selector.nodeType ) {
- this.context = this[0] = selector;
- this.length = 1;
- return this;
-
-
- } else if ( jQuery.isFunction( selector ) ) {
- return typeof rootjQuery.ready !== "undefined" ?
- rootjQuery.ready( selector ) :
-
- selector( jQuery );
- }
- if ( selector.selector !== undefined ) {
- this.selector = selector.selector;
- this.context = selector.context;
- }
- return jQuery.makeArray( selector, this );
- };
- init.prototype = jQuery.fn;
- rootjQuery = jQuery( document );
- var rparentsprev = /^(?:parents|prev(?:Until|All))/,
-
- guaranteedUnique = {
- children: true,
- contents: true,
- next: true,
- prev: true
- };
- jQuery.extend({
- dir: function( elem, dir, until ) {
- var matched = [],
- truncate = until !== undefined;
- while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
- if ( elem.nodeType === 1 ) {
- if ( truncate && jQuery( elem ).is( until ) ) {
- break;
- }
- matched.push( elem );
- }
- }
- return matched;
- },
- sibling: function( n, elem ) {
- var matched = [];
- for ( ; n; n = n.nextSibling ) {
- if ( n.nodeType === 1 && n !== elem ) {
- matched.push( n );
- }
- }
- return matched;
- }
- });
- jQuery.fn.extend({
- has: function( target ) {
- var targets = jQuery( target, this ),
- l = targets.length;
- return this.filter(function() {
- var i = 0;
- for ( ; i < l; i++ ) {
- if ( jQuery.contains( this, targets[i] ) ) {
- return true;
- }
- }
- });
- },
- closest: function( selectors, context ) {
- var cur,
- i = 0,
- l = this.length,
- matched = [],
- pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
- jQuery( selectors, context || this.context ) :
- 0;
- for ( ; i < l; i++ ) {
- for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
-
- if ( cur.nodeType < 11 && (pos ?
- pos.index(cur) > -1 :
-
- cur.nodeType === 1 &&
- jQuery.find.matchesSelector(cur, selectors)) ) {
- matched.push( cur );
- break;
- }
- }
- }
- return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
- },
-
-
- index: function( elem ) {
-
- if ( !elem ) {
- return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
- }
-
- if ( typeof elem === "string" ) {
- return indexOf.call( jQuery( elem ), this[ 0 ] );
- }
-
- return indexOf.call( this,
-
- elem.jquery ? elem[ 0 ] : elem
- );
- },
- add: function( selector, context ) {
- return this.pushStack(
- jQuery.unique(
- jQuery.merge( this.get(), jQuery( selector, context ) )
- )
- );
- },
- addBack: function( selector ) {
- return this.add( selector == null ?
- this.prevObject : this.prevObject.filter(selector)
- );
- }
- });
- function sibling( cur, dir ) {
- while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
- return cur;
- }
- jQuery.each({
- parent: function( elem ) {
- var parent = elem.parentNode;
- return parent && parent.nodeType !== 11 ? parent : null;
- },
- parents: function( elem ) {
- return jQuery.dir( elem, "parentNode" );
- },
- parentsUntil: function( elem, i, until ) {
- return jQuery.dir( elem, "parentNode", until );
- },
- next: function( elem ) {
- return sibling( elem, "nextSibling" );
- },
- prev: function( elem ) {
- return sibling( elem, "previousSibling" );
- },
- nextAll: function( elem ) {
- return jQuery.dir( elem, "nextSibling" );
- },
- prevAll: function( elem ) {
- return jQuery.dir( elem, "previousSibling" );
- },
- nextUntil: function( elem, i, until ) {
- return jQuery.dir( elem, "nextSibling", until );
- },
- prevUntil: function( elem, i, until ) {
- return jQuery.dir( elem, "previousSibling", until );
- },
- siblings: function( elem ) {
- return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
- },
- children: function( elem ) {
- return jQuery.sibling( elem.firstChild );
- },
- contents: function( elem ) {
- return elem.contentDocument || jQuery.merge( [], elem.childNodes );
- }
- }, function( name, fn ) {
- jQuery.fn[ name ] = function( until, selector ) {
- var matched = jQuery.map( this, fn, until );
- if ( name.slice( -5 ) !== "Until" ) {
- selector = until;
- }
- if ( selector && typeof selector === "string" ) {
- matched = jQuery.filter( selector, matched );
- }
- if ( this.length > 1 ) {
-
- if ( !guaranteedUnique[ name ] ) {
- jQuery.unique( matched );
- }
-
- if ( rparentsprev.test( name ) ) {
- matched.reverse();
- }
- }
- return this.pushStack( matched );
- };
- });
- var rnotwhite = (/\S+/g);
- var optionsCache = {};
- function createOptions( options ) {
- var object = optionsCache[ options ] = {};
- jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) {
- object[ flag ] = true;
- });
- return object;
- }
- jQuery.Callbacks = function( options ) {
-
-
- options = typeof options === "string" ?
- ( optionsCache[ options ] || createOptions( options ) ) :
- jQuery.extend( {}, options );
- var
- memory,
-
- fired,
-
- firing,
-
- firingStart,
-
- firingLength,
-
- firingIndex,
-
- list = [],
-
- stack = !options.once && [],
-
- fire = function( data ) {
- memory = options.memory && data;
- fired = true;
- firingIndex = firingStart || 0;
- firingStart = 0;
- firingLength = list.length;
- firing = true;
- for ( ; list && firingIndex < firingLength; firingIndex++ ) {
- if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) {
- memory = false;
- break;
- }
- }
- firing = false;
- if ( list ) {
- if ( stack ) {
- if ( stack.length ) {
- fire( stack.shift() );
- }
- } else if ( memory ) {
- list = [];
- } else {
- self.disable();
- }
- }
- },
-
- self = {
-
- add: function() {
- if ( list ) {
-
- var start = list.length;
- (function add( args ) {
- jQuery.each( args, function( _, arg ) {
- var type = jQuery.type( arg );
- if ( type === "function" ) {
- if ( !options.unique || !self.has( arg ) ) {
- list.push( arg );
- }
- } else if ( arg && arg.length && type !== "string" ) {
-
- add( arg );
- }
- });
- })( arguments );
-
-
- if ( firing ) {
- firingLength = list.length;
-
-
- } else if ( memory ) {
- firingStart = start;
- fire( memory );
- }
- }
- return this;
- },
-
- remove: function() {
- if ( list ) {
- jQuery.each( arguments, function( _, arg ) {
- var index;
- while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
- list.splice( index, 1 );
-
- if ( firing ) {
- if ( index <= firingLength ) {
- firingLength--;
- }
- if ( index <= firingIndex ) {
- firingIndex--;
- }
- }
- }
- });
- }
- return this;
- },
-
-
- has: function( fn ) {
- return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length );
- },
-
- empty: function() {
- list = [];
- firingLength = 0;
- return this;
- },
-
- disable: function() {
- list = stack = memory = undefined;
- return this;
- },
-
- disabled: function() {
- return !list;
- },
-
- lock: function() {
- stack = undefined;
- if ( !memory ) {
- self.disable();
- }
- return this;
- },
-
- locked: function() {
- return !stack;
- },
-
- fireWith: function( context, args ) {
- if ( list && ( !fired || stack ) ) {
- args = args || [];
- args = [ context, args.slice ? args.slice() : args ];
- if ( firing ) {
- stack.push( args );
- } else {
- fire( args );
- }
- }
- return this;
- },
-
- fire: function() {
- self.fireWith( this, arguments );
- return this;
- },
-
- fired: function() {
- return !!fired;
- }
- };
- return self;
- };
- jQuery.extend({
- Deferred: function( func ) {
- var tuples = [
-
- [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ],
- [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ],
- [ "notify", "progress", jQuery.Callbacks("memory") ]
- ],
- state = "pending",
- promise = {
- state: function() {
- return state;
- },
- always: function() {
- deferred.done( arguments ).fail( arguments );
- return this;
- },
- then: function( /* fnDone, fnFail, fnProgress */ ) {
- var fns = arguments;
- return jQuery.Deferred(function( newDefer ) {
- jQuery.each( tuples, function( i, tuple ) {
- var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
-
- deferred[ tuple[1] ](function() {
- var returned = fn && fn.apply( this, arguments );
- if ( returned && jQuery.isFunction( returned.promise ) ) {
- returned.promise()
- .done( newDefer.resolve )
- .fail( newDefer.reject )
- .progress( newDefer.notify );
- } else {
- newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
- }
- });
- });
- fns = null;
- }).promise();
- },
-
-
- promise: function( obj ) {
- return obj != null ? jQuery.extend( obj, promise ) : promise;
- }
- },
- deferred = {};
-
- promise.pipe = promise.then;
-
- jQuery.each( tuples, function( i, tuple ) {
- var list = tuple[ 2 ],
- stateString = tuple[ 3 ];
-
- promise[ tuple[1] ] = list.add;
-
- if ( stateString ) {
- list.add(function() {
-
- state = stateString;
-
- }, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
- }
-
- deferred[ tuple[0] ] = function() {
- deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments );
- return this;
- };
- deferred[ tuple[0] + "With" ] = list.fireWith;
- });
-
- promise.promise( deferred );
-
- if ( func ) {
- func.call( deferred, deferred );
- }
-
- return deferred;
- },
-
- when: function( subordinate /* , ..., subordinateN */ ) {
- var i = 0,
- resolveValues = slice.call( arguments ),
- length = resolveValues.length,
-
- remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0,
-
- deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
-
- updateFunc = function( i, contexts, values ) {
- return function( value ) {
- contexts[ i ] = this;
- values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
- if ( values === progressValues ) {
- deferred.notifyWith( contexts, values );
- } else if ( !( --remaining ) ) {
- deferred.resolveWith( contexts, values );
- }
- };
- },
- progressValues, progressContexts, resolveContexts;
-
- if ( length > 1 ) {
- progressValues = new Array( length );
- progressContexts = new Array( length );
- resolveContexts = new Array( length );
- for ( ; i < length; i++ ) {
- if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
- resolveValues[ i ].promise()
- .done( updateFunc( i, resolveContexts, resolveValues ) )
- .fail( deferred.reject )
- .progress( updateFunc( i, progressContexts, progressValues ) );
- } else {
- --remaining;
- }
- }
- }
-
- if ( !remaining ) {
- deferred.resolveWith( resolveContexts, resolveValues );
- }
- return deferred.promise();
- }
- });
- var readyList;
- jQuery.fn.ready = function( fn ) {
-
- jQuery.ready.promise().done( fn );
- return this;
- };
- jQuery.extend({
-
- isReady: false,
-
-
- readyWait: 1,
-
- holdReady: function( hold ) {
- if ( hold ) {
- jQuery.readyWait++;
- } else {
- jQuery.ready( true );
- }
- },
-
- ready: function( wait ) {
-
- if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
- return;
- }
-
- jQuery.isReady = true;
-
- if ( wait !== true && --jQuery.readyWait > 0 ) {
- return;
- }
-
- readyList.resolveWith( document, [ jQuery ] );
-
- if ( jQuery.fn.triggerHandler ) {
- jQuery( document ).triggerHandler( "ready" );
- jQuery( document ).off( "ready" );
- }
- }
- });
- function completed() {
- document.removeEventListener( "DOMContentLoaded", completed, false );
- window.removeEventListener( "load", completed, false );
- jQuery.ready();
- }
- jQuery.ready.promise = function( obj ) {
- if ( !readyList ) {
- readyList = jQuery.Deferred();
-
-
-
- if ( document.readyState === "complete" ) {
-
- setTimeout( jQuery.ready );
- } else {
-
- document.addEventListener( "DOMContentLoaded", completed, false );
-
- window.addEventListener( "load", completed, false );
- }
- }
- return readyList.promise( obj );
- };
- jQuery.ready.promise();
- var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
- var i = 0,
- len = elems.length,
- bulk = key == null;
-
- if ( jQuery.type( key ) === "object" ) {
- chainable = true;
- for ( i in key ) {
- jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
- }
-
- } else if ( value !== undefined ) {
- chainable = true;
- if ( !jQuery.isFunction( value ) ) {
- raw = true;
- }
- if ( bulk ) {
-
- if ( raw ) {
- fn.call( elems, value );
- fn = null;
-
- } else {
- bulk = fn;
- fn = function( elem, key, value ) {
- return bulk.call( jQuery( elem ), value );
- };
- }
- }
- if ( fn ) {
- for ( ; i < len; i++ ) {
- fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
- }
- }
- }
- return chainable ?
- elems :
-
- bulk ?
- fn.call( elems ) :
- len ? fn( elems[0], key ) : emptyGet;
- };
- jQuery.acceptData = function( owner ) {
-
-
-
-
-
-
-
- return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );
- };
- function Data() {
-
-
-
- Object.defineProperty( this.cache = {}, 0, {
- get: function() {
- return {};
- }
- });
- this.expando = jQuery.expando + Math.random();
- }
- Data.uid = 1;
- Data.accepts = jQuery.acceptData;
- Data.prototype = {
- key: function( owner ) {
-
-
-
- if ( !Data.accepts( owner ) ) {
- return 0;
- }
- var descriptor = {},
-
- unlock = owner[ this.expando ];
-
- if ( !unlock ) {
- unlock = Data.uid++;
-
- try {
- descriptor[ this.expando ] = { value: unlock };
- Object.defineProperties( owner, descriptor );
-
-
- } catch ( e ) {
- descriptor[ this.expando ] = unlock;
- jQuery.extend( owner, descriptor );
- }
- }
-
- if ( !this.cache[ unlock ] ) {
- this.cache[ unlock ] = {};
- }
- return unlock;
- },
- set: function( owner, data, value ) {
- var prop,
-
-
-
- unlock = this.key( owner ),
- cache = this.cache[ unlock ];
-
- if ( typeof data === "string" ) {
- cache[ data ] = value;
-
- } else {
-
- if ( jQuery.isEmptyObject( cache ) ) {
- jQuery.extend( this.cache[ unlock ], data );
-
- } else {
- for ( prop in data ) {
- cache[ prop ] = data[ prop ];
- }
- }
- }
- return cache;
- },
- get: function( owner, key ) {
-
-
-
-
- var cache = this.cache[ this.key( owner ) ];
- return key === undefined ?
- cache : cache[ key ];
- },
- access: function( owner, key, value ) {
- var stored;
-
-
-
-
-
-
-
-
-
-
-
- if ( key === undefined ||
- ((key && typeof key === "string") && value === undefined) ) {
- stored = this.get( owner, key );
- return stored !== undefined ?
- stored : this.get( owner, jQuery.camelCase(key) );
- }
-
-
-
-
-
-
- this.set( owner, key, value );
-
-
- return value !== undefined ? value : key;
- },
- remove: function( owner, key ) {
- var i, name, camel,
- unlock = this.key( owner ),
- cache = this.cache[ unlock ];
- if ( key === undefined ) {
- this.cache[ unlock ] = {};
- } else {
-
- if ( jQuery.isArray( key ) ) {
-
-
-
-
-
-
- name = key.concat( key.map( jQuery.camelCase ) );
- } else {
- camel = jQuery.camelCase( key );
-
- if ( key in cache ) {
- name = [ key, camel ];
- } else {
-
-
- name = camel;
- name = name in cache ?
- [ name ] : ( name.match( rnotwhite ) || [] );
- }
- }
- i = name.length;
- while ( i-- ) {
- delete cache[ name[ i ] ];
- }
- }
- },
- hasData: function( owner ) {
- return !jQuery.isEmptyObject(
- this.cache[ owner[ this.expando ] ] || {}
- );
- },
- discard: function( owner ) {
- if ( owner[ this.expando ] ) {
- delete this.cache[ owner[ this.expando ] ];
- }
- }
- };
- var data_priv = new Data();
- var data_user = new Data();
- var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
- rmultiDash = /([A-Z])/g;
- function dataAttr( elem, key, data ) {
- var name;
-
-
- if ( data === undefined && elem.nodeType === 1 ) {
- name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
- data = elem.getAttribute( name );
- if ( typeof data === "string" ) {
- try {
- data = data === "true" ? true :
- data === "false" ? false :
- data === "null" ? null :
-
- +data + "" === data ? +data :
- rbrace.test( data ) ? jQuery.parseJSON( data ) :
- data;
- } catch( e ) {}
-
- data_user.set( elem, key, data );
- } else {
- data = undefined;
- }
- }
- return data;
- }
- jQuery.extend({
- hasData: function( elem ) {
- return data_user.hasData( elem ) || data_priv.hasData( elem );
- },
- data: function( elem, name, data ) {
- return data_user.access( elem, name, data );
- },
- removeData: function( elem, name ) {
- data_user.remove( elem, name );
- },
-
-
- _data: function( elem, name, data ) {
- return data_priv.access( elem, name, data );
- },
- _removeData: function( elem, name ) {
- data_priv.remove( elem, name );
- }
- });
- jQuery.fn.extend({
- data: function( key, value ) {
- var i, name, data,
- elem = this[ 0 ],
- attrs = elem && elem.attributes;
-
- if ( key === undefined ) {
- if ( this.length ) {
- data = data_user.get( elem );
- if ( elem.nodeType === 1 && !data_priv.get( elem, "hasDataAttrs" ) ) {
- i = attrs.length;
- while ( i-- ) {
-
-
- if ( attrs[ i ] ) {
- name = attrs[ i ].name;
- if ( name.indexOf( "data-" ) === 0 ) {
- name = jQuery.camelCase( name.slice(5) );
- dataAttr( elem, name, data[ name ] );
- }
- }
- }
- data_priv.set( elem, "hasDataAttrs", true );
- }
- }
- return data;
- }
-
- if ( typeof key === "object" ) {
- return this.each(function() {
- data_user.set( this, key );
- });
- }
- return access( this, function( value ) {
- var data,
- camelKey = jQuery.camelCase( key );
-
-
-
-
-
- if ( elem && value === undefined ) {
-
-
- data = data_user.get( elem, key );
- if ( data !== undefined ) {
- return data;
- }
-
-
- data = data_user.get( elem, camelKey );
- if ( data !== undefined ) {
- return data;
- }
-
-
- data = dataAttr( elem, camelKey, undefined );
- if ( data !== undefined ) {
- return data;
- }
-
- return;
- }
-
- this.each(function() {
-
-
- var data = data_user.get( this, camelKey );
-
-
-
- data_user.set( this, camelKey, value );
-
-
-
- if ( key.indexOf("-") !== -1 && data !== undefined ) {
- data_user.set( this, key, value );
- }
- });
- }, null, value, arguments.length > 1, null, true );
- },
- removeData: function( key ) {
- return this.each(function() {
- data_user.remove( this, key );
- });
- }
- });
- jQuery.extend({
- queue: function( elem, type, data ) {
- var queue;
- if ( elem ) {
- type = ( type || "fx" ) + "queue";
- queue = data_priv.get( elem, type );
-
- if ( data ) {
- if ( !queue || jQuery.isArray( data ) ) {
- queue = data_priv.access( elem, type, jQuery.makeArray(data) );
- } else {
- queue.push( data );
- }
- }
- return queue || [];
- }
- },
- dequeue: function( elem, type ) {
- type = type || "fx";
- var queue = jQuery.queue( elem, type ),
- startLength = queue.length,
- fn = queue.shift(),
- hooks = jQuery._queueHooks( elem, type ),
- next = function() {
- jQuery.dequeue( elem, type );
- };
-
- if ( fn === "inprogress" ) {
- fn = queue.shift();
- startLength--;
- }
- if ( fn ) {
-
-
- if ( type === "fx" ) {
- queue.unshift( "inprogress" );
- }
-
- delete hooks.stop;
- fn.call( elem, next, hooks );
- }
- if ( !startLength && hooks ) {
- hooks.empty.fire();
- }
- },
-
- _queueHooks: function( elem, type ) {
- var key = type + "queueHooks";
- return data_priv.get( elem, key ) || data_priv.access( elem, key, {
- empty: jQuery.Callbacks("once memory").add(function() {
- data_priv.remove( elem, [ type + "queue", key ] );
- })
- });
- }
- });
- jQuery.fn.extend({
- queue: function( type, data ) {
- var setter = 2;
- if ( typeof type !== "string" ) {
- data = type;
- type = "fx";
- setter--;
- }
- if ( arguments.length < setter ) {
- return jQuery.queue( this[0], type );
- }
- return data === undefined ?
- this :
- this.each(function() {
- var queue = jQuery.queue( this, type, data );
-
- jQuery._queueHooks( this, type );
- if ( type === "fx" && queue[0] !== "inprogress" ) {
- jQuery.dequeue( this, type );
- }
- });
- },
- dequeue: function( type ) {
- return this.each(function() {
- jQuery.dequeue( this, type );
- });
- },
- clearQueue: function( type ) {
- return this.queue( type || "fx", [] );
- },
-
-
- promise: function( type, obj ) {
- var tmp,
- count = 1,
- defer = jQuery.Deferred(),
- elements = this,
- i = this.length,
- resolve = function() {
- if ( !( --count ) ) {
- defer.resolveWith( elements, [ elements ] );
- }
- };
- if ( typeof type !== "string" ) {
- obj = type;
- type = undefined;
- }
- type = type || "fx";
- while ( i-- ) {
- tmp = data_priv.get( elements[ i ], type + "queueHooks" );
- if ( tmp && tmp.empty ) {
- count++;
- tmp.empty.add( resolve );
- }
- }
- resolve();
- return defer.promise( obj );
- }
- });
- var pnum = (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source;
- var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
- var isHidden = function( elem, el ) {
-
-
- elem = el || elem;
- return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem );
- };
- var rcheckableType = (/^(?:checkbox|radio)$/i);
- (function() {
- var fragment = document.createDocumentFragment(),
- div = fragment.appendChild( document.createElement( "div" ) ),
- input = document.createElement( "input" );
-
-
-
- input.setAttribute( "type", "radio" );
- input.setAttribute( "checked", "checked" );
- input.setAttribute( "name", "t" );
- div.appendChild( input );
-
-
- support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
-
-
- div.innerHTML = "<textarea>x</textarea>";
- support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;
- })();
- var strundefined = typeof undefined;
- support.focusinBubbles = "onfocusin" in window;
- var
- rkeyEvent = /^key/,
- rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/,
- rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
- rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
- function returnTrue() {
- return true;
- }
- function returnFalse() {
- return false;
- }
- function safeActiveElement() {
- try {
- return document.activeElement;
- } catch ( err ) { }
- }
- jQuery.event = {
- global: {},
- add: function( elem, types, handler, data, selector ) {
- var handleObjIn, eventHandle, tmp,
- events, t, handleObj,
- special, handlers, type, namespaces, origType,
- elemData = data_priv.get( elem );
-
- if ( !elemData ) {
- return;
- }
-
- if ( handler.handler ) {
- handleObjIn = handler;
- handler = handleObjIn.handler;
- selector = handleObjIn.selector;
- }
-
- if ( !handler.guid ) {
- handler.guid = jQuery.guid++;
- }
-
- if ( !(events = elemData.events) ) {
- events = elemData.events = {};
- }
- if ( !(eventHandle = elemData.handle) ) {
- eventHandle = elemData.handle = function( e ) {
-
-
- return typeof jQuery !== strundefined && jQuery.event.triggered !== e.type ?
- jQuery.event.dispatch.apply( elem, arguments ) : undefined;
- };
- }
-
- types = ( types || "" ).match( rnotwhite ) || [ "" ];
- t = types.length;
- while ( t-- ) {
- tmp = rtypenamespace.exec( types[t] ) || [];
- type = origType = tmp[1];
- namespaces = ( tmp[2] || "" ).split( "." ).sort();
-
- if ( !type ) {
- continue;
- }
-
- special = jQuery.event.special[ type ] || {};
-
- type = ( selector ? special.delegateType : special.bindType ) || type;
-
- special = jQuery.event.special[ type ] || {};
-
- handleObj = jQuery.extend({
- type: type,
- origType: origType,
- data: data,
- handler: handler,
- guid: handler.guid,
- selector: selector,
- needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
- namespace: namespaces.join(".")
- }, handleObjIn );
-
- if ( !(handlers = events[ type ]) ) {
- handlers = events[ type ] = [];
- handlers.delegateCount = 0;
-
- if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
- if ( elem.addEventListener ) {
- elem.addEventListener( type, eventHandle, false );
- }
- }
- }
- if ( special.add ) {
- special.add.call( elem, handleObj );
- if ( !handleObj.handler.guid ) {
- handleObj.handler.guid = handler.guid;
- }
- }
-
- if ( selector ) {
- handlers.splice( handlers.delegateCount++, 0, handleObj );
- } else {
- handlers.push( handleObj );
- }
-
- jQuery.event.global[ type ] = true;
- }
- },
-
- remove: function( elem, types, handler, selector, mappedTypes ) {
- var j, origCount, tmp,
- events, t, handleObj,
- special, handlers, type, namespaces, origType,
- elemData = data_priv.hasData( elem ) && data_priv.get( elem );
- if ( !elemData || !(events = elemData.events) ) {
- return;
- }
-
- types = ( types || "" ).match( rnotwhite ) || [ "" ];
- t = types.length;
- while ( t-- ) {
- tmp = rtypenamespace.exec( types[t] ) || [];
- type = origType = tmp[1];
- namespaces = ( tmp[2] || "" ).split( "." ).sort();
-
- if ( !type ) {
- for ( type in events ) {
- jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
- }
- continue;
- }
- special = jQuery.event.special[ type ] || {};
- type = ( selector ? special.delegateType : special.bindType ) || type;
- handlers = events[ type ] || [];
- tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" );
-
- origCount = j = handlers.length;
- while ( j-- ) {
- handleObj = handlers[ j ];
- if ( ( mappedTypes || origType === handleObj.origType ) &&
- ( !handler || handler.guid === handleObj.guid ) &&
- ( !tmp || tmp.test( handleObj.namespace ) ) &&
- ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
- handlers.splice( j, 1 );
- if ( handleObj.selector ) {
- handlers.delegateCount--;
- }
- if ( special.remove ) {
- special.remove.call( elem, handleObj );
- }
- }
- }
-
-
- if ( origCount && !handlers.length ) {
- if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
- jQuery.removeEvent( elem, type, elemData.handle );
- }
- delete events[ type ];
- }
- }
-
- if ( jQuery.isEmptyObject( events ) ) {
- delete elemData.handle;
- data_priv.remove( elem, "events" );
- }
- },
- trigger: function( event, data, elem, onlyHandlers ) {
- var i, cur, tmp, bubbleType, ontype, handle, special,
- eventPath = [ elem || document ],
- type = hasOwn.call( event, "type" ) ? event.type : event,
- namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : [];
- cur = tmp = elem = elem || document;
-
- if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
- return;
- }
-
- if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
- return;
- }
- if ( type.indexOf(".") >= 0 ) {
-
- namespaces = type.split(".");
- type = namespaces.shift();
- namespaces.sort();
- }
- ontype = type.indexOf(":") < 0 && "on" + type;
-
- event = event[ jQuery.expando ] ?
- event :
- new jQuery.Event( type, typeof event === "object" && event );
-
- event.isTrigger = onlyHandlers ? 2 : 3;
- event.namespace = namespaces.join(".");
- event.namespace_re = event.namespace ?
- new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) :
- null;
-
- event.result = undefined;
- if ( !event.target ) {
- event.target = elem;
- }
-
- data = data == null ?
- [ event ] :
- jQuery.makeArray( data, [ event ] );
-
- special = jQuery.event.special[ type ] || {};
- if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
- return;
- }
-
-
- if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
- bubbleType = special.delegateType || type;
- if ( !rfocusMorph.test( bubbleType + type ) ) {
- cur = cur.parentNode;
- }
- for ( ; cur; cur = cur.parentNode ) {
- eventPath.push( cur );
- tmp = cur;
- }
-
- if ( tmp === (elem.ownerDocument || document) ) {
- eventPath.push( tmp.defaultView || tmp.parentWindow || window );
- }
- }
-
- i = 0;
- while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) {
- event.type = i > 1 ?
- bubbleType :
- special.bindType || type;
-
- handle = ( data_priv.get( cur, "events" ) || {} )[ event.type ] && data_priv.get( cur, "handle" );
- if ( handle ) {
- handle.apply( cur, data );
- }
-
- handle = ontype && cur[ ontype ];
- if ( handle && handle.apply && jQuery.acceptData( cur ) ) {
- event.result = handle.apply( cur, data );
- if ( event.result === false ) {
- event.preventDefault();
- }
- }
- }
- event.type = type;
-
- if ( !onlyHandlers && !event.isDefaultPrevented() ) {
- if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) &&
- jQuery.acceptData( elem ) ) {
-
-
- if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) {
-
- tmp = elem[ ontype ];
- if ( tmp ) {
- elem[ ontype ] = null;
- }
-
- jQuery.event.triggered = type;
- elem[ type ]();
- jQuery.event.triggered = undefined;
- if ( tmp ) {
- elem[ ontype ] = tmp;
- }
- }
- }
- }
- return event.result;
- },
- dispatch: function( event ) {
-
- event = jQuery.event.fix( event );
- var i, j, ret, matched, handleObj,
- handlerQueue = [],
- args = slice.call( arguments ),
- handlers = ( data_priv.get( this, "events" ) || {} )[ event.type ] || [],
- special = jQuery.event.special[ event.type ] || {};
-
- args[0] = event;
- event.delegateTarget = this;
-
- if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
- return;
- }
-
- handlerQueue = jQuery.event.handlers.call( this, event, handlers );
-
- i = 0;
- while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) {
- event.currentTarget = matched.elem;
- j = 0;
- while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) {
-
-
- if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) {
- event.handleObj = handleObj;
- event.data = handleObj.data;
- ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
- .apply( matched.elem, args );
- if ( ret !== undefined ) {
- if ( (event.result = ret) === false ) {
- event.preventDefault();
- event.stopPropagation();
- }
- }
- }
- }
- }
-
- if ( special.postDispatch ) {
- special.postDispatch.call( this, event );
- }
- return event.result;
- },
- handlers: function( event, handlers ) {
- var i, matches, sel, handleObj,
- handlerQueue = [],
- delegateCount = handlers.delegateCount,
- cur = event.target;
-
-
-
- if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) {
- for ( ; cur !== this; cur = cur.parentNode || this ) {
-
- if ( cur.disabled !== true || event.type !== "click" ) {
- matches = [];
- for ( i = 0; i < delegateCount; i++ ) {
- handleObj = handlers[ i ];
-
- sel = handleObj.selector + " ";
- if ( matches[ sel ] === undefined ) {
- matches[ sel ] = handleObj.needsContext ?
- jQuery( sel, this ).index( cur ) >= 0 :
- jQuery.find( sel, this, null, [ cur ] ).length;
- }
- if ( matches[ sel ] ) {
- matches.push( handleObj );
- }
- }
- if ( matches.length ) {
- handlerQueue.push({ elem: cur, handlers: matches });
- }
- }
- }
- }
-
- if ( delegateCount < handlers.length ) {
- handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) });
- }
- return handlerQueue;
- },
-
- props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
- fixHooks: {},
- keyHooks: {
- props: "char charCode key keyCode".split(" "),
- filter: function( event, original ) {
-
- if ( event.which == null ) {
- event.which = original.charCode != null ? original.charCode : original.keyCode;
- }
- return event;
- }
- },
- mouseHooks: {
- props: "button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),
- filter: function( event, original ) {
- var eventDoc, doc, body,
- button = original.button;
-
- if ( event.pageX == null && original.clientX != null ) {
- eventDoc = event.target.ownerDocument || document;
- doc = eventDoc.documentElement;
- body = eventDoc.body;
- event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
- event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
- }
-
-
- if ( !event.which && button !== undefined ) {
- event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
- }
- return event;
- }
- },
- fix: function( event ) {
- if ( event[ jQuery.expando ] ) {
- return event;
- }
-
- var i, prop, copy,
- type = event.type,
- originalEvent = event,
- fixHook = this.fixHooks[ type ];
- if ( !fixHook ) {
- this.fixHooks[ type ] = fixHook =
- rmouseEvent.test( type ) ? this.mouseHooks :
- rkeyEvent.test( type ) ? this.keyHooks :
- {};
- }
- copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
- event = new jQuery.Event( originalEvent );
- i = copy.length;
- while ( i-- ) {
- prop = copy[ i ];
- event[ prop ] = originalEvent[ prop ];
- }
-
-
- if ( !event.target ) {
- event.target = document;
- }
-
-
- if ( event.target.nodeType === 3 ) {
- event.target = event.target.parentNode;
- }
- return fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
- },
- special: {
- load: {
-
- noBubble: true
- },
- focus: {
-
- trigger: function() {
- if ( this !== safeActiveElement() && this.focus ) {
- this.focus();
- return false;
- }
- },
- delegateType: "focusin"
- },
- blur: {
- trigger: function() {
- if ( this === safeActiveElement() && this.blur ) {
- this.blur();
- return false;
- }
- },
- delegateType: "focusout"
- },
- click: {
-
- trigger: function() {
- if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) {
- this.click();
- return false;
- }
- },
-
- _default: function( event ) {
- return jQuery.nodeName( event.target, "a" );
- }
- },
- beforeunload: {
- postDispatch: function( event ) {
-
-
- if ( event.result !== undefined && event.originalEvent ) {
- event.originalEvent.returnValue = event.result;
- }
- }
- }
- },
- simulate: function( type, elem, event, bubble ) {
-
-
-
- var e = jQuery.extend(
- new jQuery.Event(),
- event,
- {
- type: type,
- isSimulated: true,
- originalEvent: {}
- }
- );
- if ( bubble ) {
- jQuery.event.trigger( e, null, elem );
- } else {
- jQuery.event.dispatch.call( elem, e );
- }
- if ( e.isDefaultPrevented() ) {
- event.preventDefault();
- }
- }
- };
- jQuery.removeEvent = function( elem, type, handle ) {
- if ( elem.removeEventListener ) {
- elem.removeEventListener( type, handle, false );
- }
- };
- jQuery.Event = function( src, props ) {
-
- if ( !(this instanceof jQuery.Event) ) {
- return new jQuery.Event( src, props );
- }
-
- if ( src && src.type ) {
- this.originalEvent = src;
- this.type = src.type;
-
-
- this.isDefaultPrevented = src.defaultPrevented ||
- src.defaultPrevented === undefined &&
-
- src.returnValue === false ?
- returnTrue :
- returnFalse;
-
- } else {
- this.type = src;
- }
-
- if ( props ) {
- jQuery.extend( this, props );
- }
-
- this.timeStamp = src && src.timeStamp || jQuery.now();
-
- this[ jQuery.expando ] = true;
- };
- jQuery.Event.prototype = {
- isDefaultPrevented: returnFalse,
- isPropagationStopped: returnFalse,
- isImmediatePropagationStopped: returnFalse,
- preventDefault: function() {
- var e = this.originalEvent;
- this.isDefaultPrevented = returnTrue;
- if ( e && e.preventDefault ) {
- e.preventDefault();
- }
- },
- stopPropagation: function() {
- var e = this.originalEvent;
- this.isPropagationStopped = returnTrue;
- if ( e && e.stopPropagation ) {
- e.stopPropagation();
- }
- },
- stopImmediatePropagation: function() {
- var e = this.originalEvent;
- this.isImmediatePropagationStopped = returnTrue;
- if ( e && e.stopImmediatePropagation ) {
- e.stopImmediatePropagation();
- }
- this.stopPropagation();
- }
- };
- jQuery.each({
- mouseenter: "mouseover",
- mouseleave: "mouseout",
- pointerenter: "pointerover",
- pointerleave: "pointerout"
- }, function( orig, fix ) {
- jQuery.event.special[ orig ] = {
- delegateType: fix,
- bindType: fix,
- handle: function( event ) {
- var ret,
- target = this,
- related = event.relatedTarget,
- handleObj = event.handleObj;
-
-
- if ( !related || (related !== target && !jQuery.contains( target, related )) ) {
- event.type = handleObj.origType;
- ret = handleObj.handler.apply( this, arguments );
- event.type = fix;
- }
- return ret;
- }
- };
- });
- if ( !support.focusinBubbles ) {
- jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
-
- var handler = function( event ) {
- jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true );
- };
- jQuery.event.special[ fix ] = {
- setup: function() {
- var doc = this.ownerDocument || this,
- attaches = data_priv.access( doc, fix );
- if ( !attaches ) {
- doc.addEventListener( orig, handler, true );
- }
- data_priv.access( doc, fix, ( attaches || 0 ) + 1 );
- },
- teardown: function() {
- var doc = this.ownerDocument || this,
- attaches = data_priv.access( doc, fix ) - 1;
- if ( !attaches ) {
- doc.removeEventListener( orig, handler, true );
- data_priv.remove( doc, fix );
- } else {
- data_priv.access( doc, fix, attaches );
- }
- }
- };
- });
- }
- jQuery.fn.extend({
- on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
- var origFn, type;
-
- if ( typeof types === "object" ) {
-
- if ( typeof selector !== "string" ) {
-
- data = data || selector;
- selector = undefined;
- }
- for ( type in types ) {
- this.on( type, selector, data, types[ type ], one );
- }
- return this;
- }
- if ( data == null && fn == null ) {
-
- fn = selector;
- data = selector = undefined;
- } else if ( fn == null ) {
- if ( typeof selector === "string" ) {
-
- fn = data;
- data = undefined;
- } else {
-
- fn = data;
- data = selector;
- selector = undefined;
- }
- }
- if ( fn === false ) {
- fn = returnFalse;
- } else if ( !fn ) {
- return this;
- }
- if ( one === 1 ) {
- origFn = fn;
- fn = function( event ) {
-
- jQuery().off( event );
- return origFn.apply( this, arguments );
- };
-
- fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
- }
- return this.each( function() {
- jQuery.event.add( this, types, fn, data, selector );
- });
- },
- one: function( types, selector, data, fn ) {
- return this.on( types, selector, data, fn, 1 );
- },
- off: function( types, selector, fn ) {
- var handleObj, type;
- if ( types && types.preventDefault && types.handleObj ) {
-
- handleObj = types.handleObj;
- jQuery( types.delegateTarget ).off(
- handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
- handleObj.selector,
- handleObj.handler
- );
- return this;
- }
- if ( typeof types === "object" ) {
-
- for ( type in types ) {
- this.off( type, selector, types[ type ] );
- }
- return this;
- }
- if ( selector === false || typeof selector === "function" ) {
-
- fn = selector;
- selector = undefined;
- }
- if ( fn === false ) {
- fn = returnFalse;
- }
- return this.each(function() {
- jQuery.event.remove( this, types, fn, selector );
- });
- },
- trigger: function( type, data ) {
- return this.each(function() {
- jQuery.event.trigger( type, data, this );
- });
- },
- triggerHandler: function( type, data ) {
- var elem = this[0];
- if ( elem ) {
- return jQuery.event.trigger( type, data, elem, true );
- }
- }
- });
- var
- rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
- rtagName = /<([\w:]+)/,
- rhtml = /<|&#?\w+;/,
- rnoInnerhtml = /<(?:script|style|link)/i,
-
- rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
- rscriptType = /^$|\/(?:java|ecma)script/i,
- rscriptTypeMasked = /^true\/(.*)/,
- rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,
-
- wrapMap = {
-
- option: [ 1, "<select multiple='multiple'>", "</select>" ],
- thead: [ 1, "<table>", "</table>" ],
- col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
- tr: [ 2, "<table><tbody>", "</tbody></table>" ],
- td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
- _default: [ 0, "", "" ]
- };
- wrapMap.optgroup = wrapMap.option;
- wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
- wrapMap.th = wrapMap.td;
- function manipulationTarget( elem, content ) {
- return jQuery.nodeName( elem, "table" ) &&
- jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ?
- elem.getElementsByTagName("tbody")[0] ||
- elem.appendChild( elem.ownerDocument.createElement("tbody") ) :
- elem;
- }
- function disableScript( elem ) {
- elem.type = (elem.getAttribute("type") !== null) + "/" + elem.type;
- return elem;
- }
- function restoreScript( elem ) {
- var match = rscriptTypeMasked.exec( elem.type );
- if ( match ) {
- elem.type = match[ 1 ];
- } else {
- elem.removeAttribute("type");
- }
- return elem;
- }
- function setGlobalEval( elems, refElements ) {
- var i = 0,
- l = elems.length;
- for ( ; i < l; i++ ) {
- data_priv.set(
- elems[ i ], "globalEval", !refElements || data_priv.get( refElements[ i ], "globalEval" )
- );
- }
- }
- function cloneCopyEvent( src, dest ) {
- var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
- if ( dest.nodeType !== 1 ) {
- return;
- }
-
- if ( data_priv.hasData( src ) ) {
- pdataOld = data_priv.access( src );
- pdataCur = data_priv.set( dest, pdataOld );
- events = pdataOld.events;
- if ( events ) {
- delete pdataCur.handle;
- pdataCur.events = {};
- for ( type in events ) {
- for ( i = 0, l = events[ type ].length; i < l; i++ ) {
- jQuery.event.add( dest, type, events[ type ][ i ] );
- }
- }
- }
- }
-
- if ( data_user.hasData( src ) ) {
- udataOld = data_user.access( src );
- udataCur = jQuery.extend( {}, udataOld );
- data_user.set( dest, udataCur );
- }
- }
- function getAll( context, tag ) {
- var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) :
- context.querySelectorAll ? context.querySelectorAll( tag || "*" ) :
- [];
- return tag === undefined || tag && jQuery.nodeName( context, tag ) ?
- jQuery.merge( [ context ], ret ) :
- ret;
- }
- function fixInput( src, dest ) {
- var nodeName = dest.nodeName.toLowerCase();
-
- if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
- dest.checked = src.checked;
-
- } else if ( nodeName === "input" || nodeName === "textarea" ) {
- dest.defaultValue = src.defaultValue;
- }
- }
- jQuery.extend({
- clone: function( elem, dataAndEvents, deepDataAndEvents ) {
- var i, l, srcElements, destElements,
- clone = elem.cloneNode( true ),
- inPage = jQuery.contains( elem.ownerDocument, elem );
-
-
- if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
- !jQuery.isXMLDoc( elem ) ) {
-
- destElements = getAll( clone );
- srcElements = getAll( elem );
- for ( i = 0, l = srcElements.length; i < l; i++ ) {
- fixInput( srcElements[ i ], destElements[ i ] );
- }
- }
-
- if ( dataAndEvents ) {
- if ( deepDataAndEvents ) {
- srcElements = srcElements || getAll( elem );
- destElements = destElements || getAll( clone );
- for ( i = 0, l = srcElements.length; i < l; i++ ) {
- cloneCopyEvent( srcElements[ i ], destElements[ i ] );
- }
- } else {
- cloneCopyEvent( elem, clone );
- }
- }
-
- destElements = getAll( clone, "script" );
- if ( destElements.length > 0 ) {
- setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
- }
-
- return clone;
- },
- buildFragment: function( elems, context, scripts, selection ) {
- var elem, tmp, tag, wrap, contains, j,
- fragment = context.createDocumentFragment(),
- nodes = [],
- i = 0,
- l = elems.length;
- for ( ; i < l; i++ ) {
- elem = elems[ i ];
- if ( elem || elem === 0 ) {
-
- if ( jQuery.type( elem ) === "object" ) {
-
-
- jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
-
- } else if ( !rhtml.test( elem ) ) {
- nodes.push( context.createTextNode( elem ) );
-
- } else {
- tmp = tmp || fragment.appendChild( context.createElement("div") );
-
- tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
- wrap = wrapMap[ tag ] || wrapMap._default;
- tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1></$2>" ) + wrap[ 2 ];
-
- j = wrap[ 0 ];
- while ( j-- ) {
- tmp = tmp.lastChild;
- }
-
-
- jQuery.merge( nodes, tmp.childNodes );
-
- tmp = fragment.firstChild;
-
-
- tmp.textContent = "";
- }
- }
- }
-
- fragment.textContent = "";
- i = 0;
- while ( (elem = nodes[ i++ ]) ) {
-
-
- if ( selection && jQuery.inArray( elem, selection ) !== -1 ) {
- continue;
- }
- contains = jQuery.contains( elem.ownerDocument, elem );
-
- tmp = getAll( fragment.appendChild( elem ), "script" );
-
- if ( contains ) {
- setGlobalEval( tmp );
- }
-
- if ( scripts ) {
- j = 0;
- while ( (elem = tmp[ j++ ]) ) {
- if ( rscriptType.test( elem.type || "" ) ) {
- scripts.push( elem );
- }
- }
- }
- }
- return fragment;
- },
- cleanData: function( elems ) {
- var data, elem, type, key,
- special = jQuery.event.special,
- i = 0;
- for ( ; (elem = elems[ i ]) !== undefined; i++ ) {
- if ( jQuery.acceptData( elem ) ) {
- key = elem[ data_priv.expando ];
- if ( key && (data = data_priv.cache[ key ]) ) {
- if ( data.events ) {
- for ( type in data.events ) {
- if ( special[ type ] ) {
- jQuery.event.remove( elem, type );
-
- } else {
- jQuery.removeEvent( elem, type, data.handle );
- }
- }
- }
- if ( data_priv.cache[ key ] ) {
-
- delete data_priv.cache[ key ];
- }
- }
- }
-
- delete data_user.cache[ elem[ data_user.expando ] ];
- }
- }
- });
- jQuery.fn.extend({
- text: function( value ) {
- return access( this, function( value ) {
- return value === undefined ?
- jQuery.text( this ) :
- this.empty().each(function() {
- if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
- this.textContent = value;
- }
- });
- }, null, value, arguments.length );
- },
- append: function() {
- return this.domManip( arguments, function( elem ) {
- if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
- var target = manipulationTarget( this, elem );
- target.appendChild( elem );
- }
- });
- },
- prepend: function() {
- return this.domManip( arguments, function( elem ) {
- if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
- var target = manipulationTarget( this, elem );
- target.insertBefore( elem, target.firstChild );
- }
- });
- },
- before: function() {
- return this.domManip( arguments, function( elem ) {
- if ( this.parentNode ) {
- this.parentNode.insertBefore( elem, this );
- }
- });
- },
- after: function() {
- return this.domManip( arguments, function( elem ) {
- if ( this.parentNode ) {
- this.parentNode.insertBefore( elem, this.nextSibling );
- }
- });
- },
- remove: function( selector, keepData /* Internal Use Only */ ) {
- var elem,
- elems = selector ? jQuery.filter( selector, this ) : this,
- i = 0;
- for ( ; (elem = elems[i]) != null; i++ ) {
- if ( !keepData && elem.nodeType === 1 ) {
- jQuery.cleanData( getAll( elem ) );
- }
- if ( elem.parentNode ) {
- if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) {
- setGlobalEval( getAll( elem, "script" ) );
- }
- elem.parentNode.removeChild( elem );
- }
- }
- return this;
- },
- empty: function() {
- var elem,
- i = 0;
- for ( ; (elem = this[i]) != null; i++ ) {
- if ( elem.nodeType === 1 ) {
-
- jQuery.cleanData( getAll( elem, false ) );
-
- elem.textContent = "";
- }
- }
- return this;
- },
- clone: function( dataAndEvents, deepDataAndEvents ) {
- dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
- deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
- return this.map(function() {
- return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
- });
- },
- html: function( value ) {
- return access( this, function( value ) {
- var elem = this[ 0 ] || {},
- i = 0,
- l = this.length;
- if ( value === undefined && elem.nodeType === 1 ) {
- return elem.innerHTML;
- }
-
- if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
- !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
- value = value.replace( rxhtmlTag, "<$1></$2>" );
- try {
- for ( ; i < l; i++ ) {
- elem = this[ i ] || {};
-
- if ( elem.nodeType === 1 ) {
- jQuery.cleanData( getAll( elem, false ) );
- elem.innerHTML = value;
- }
- }
- elem = 0;
-
- } catch( e ) {}
- }
- if ( elem ) {
- this.empty().append( value );
- }
- }, null, value, arguments.length );
- },
- replaceWith: function() {
- var arg = arguments[ 0 ];
-
- this.domManip( arguments, function( elem ) {
- arg = this.parentNode;
- jQuery.cleanData( getAll( this ) );
- if ( arg ) {
- arg.replaceChild( elem, this );
- }
- });
-
- return arg && (arg.length || arg.nodeType) ? this : this.remove();
- },
- detach: function( selector ) {
- return this.remove( selector, true );
- },
- domManip: function( args, callback ) {
-
- args = concat.apply( [], args );
- var fragment, first, scripts, hasScripts, node, doc,
- i = 0,
- l = this.length,
- set = this,
- iNoClone = l - 1,
- value = args[ 0 ],
- isFunction = jQuery.isFunction( value );
- // We can't cloneNode fragments that contain checked, in WebKit
- if ( isFunction ||
- ( l > 1 && typeof value === "string" &&
- !support.checkClone && rchecked.test( value ) ) ) {
- return this.each(function( index ) {
- var self = set.eq( index );
- if ( isFunction ) {
- args[ 0 ] = value.call( this, index, self.html() );
- }
- self.domManip( args, callback );
- });
- }
- if ( l ) {
- fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this );
- first = fragment.firstChild;
- if ( fragment.childNodes.length === 1 ) {
- fragment = first;
- }
- if ( first ) {
- scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
- hasScripts = scripts.length;
-
-
- for ( ; i < l; i++ ) {
- node = fragment;
- if ( i !== iNoClone ) {
- node = jQuery.clone( node, true, true );
-
- if ( hasScripts ) {
-
-
- jQuery.merge( scripts, getAll( node, "script" ) );
- }
- }
- callback.call( this[ i ], node, i );
- }
- if ( hasScripts ) {
- doc = scripts[ scripts.length - 1 ].ownerDocument;
-
- jQuery.map( scripts, restoreScript );
-
- for ( i = 0; i < hasScripts; i++ ) {
- node = scripts[ i ];
- if ( rscriptType.test( node.type || "" ) &&
- !data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
- if ( node.src ) {
-
- if ( jQuery._evalUrl ) {
- jQuery._evalUrl( node.src );
- }
- } else {
- jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) );
- }
- }
- }
- }
- }
- }
- return this;
- }
- });
- jQuery.each({
- appendTo: "append",
- prependTo: "prepend",
- insertBefore: "before",
- insertAfter: "after",
- replaceAll: "replaceWith"
- }, function( name, original ) {
- jQuery.fn[ name ] = function( selector ) {
- var elems,
- ret = [],
- insert = jQuery( selector ),
- last = insert.length - 1,
- i = 0;
- for ( ; i <= last; i++ ) {
- elems = i === last ? this : this.clone( true );
- jQuery( insert[ i ] )[ original ]( elems );
-
-
- push.apply( ret, elems.get() );
- }
- return this.pushStack( ret );
- };
- });
- var iframe,
- elemdisplay = {};
- function actualDisplay( name, doc ) {
- var style,
- elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
-
- display = window.getDefaultComputedStyle && ( style = window.getDefaultComputedStyle( elem[ 0 ] ) ) ?
-
-
- style.display : jQuery.css( elem[ 0 ], "display" );
-
-
- elem.detach();
- return display;
- }
- function defaultDisplay( nodeName ) {
- var doc = document,
- display = elemdisplay[ nodeName ];
- if ( !display ) {
- display = actualDisplay( nodeName, doc );
-
- if ( display === "none" || !display ) {
-
- iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
-
- doc = iframe[ 0 ].contentDocument;
-
- doc.write();
- doc.close();
- display = actualDisplay( nodeName, doc );
- iframe.detach();
- }
-
- elemdisplay[ nodeName ] = display;
- }
- return display;
- }
- var rmargin = (/^margin/);
- var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
- var getStyles = function( elem ) {
- return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
- };
- function curCSS( elem, name, computed ) {
- var width, minWidth, maxWidth, ret,
- style = elem.style;
- computed = computed || getStyles( elem );
-
-
- if ( computed ) {
- ret = computed.getPropertyValue( name ) || computed[ name ];
- }
- if ( computed ) {
- if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
- ret = jQuery.style( elem, name );
- }
-
-
-
-
- if ( rnumnonpx.test( ret ) && rmargin.test( name ) ) {
-
- width = style.width;
- minWidth = style.minWidth;
- maxWidth = style.maxWidth;
-
- style.minWidth = style.maxWidth = style.width = ret;
- ret = computed.width;
-
- style.width = width;
- style.minWidth = minWidth;
- style.maxWidth = maxWidth;
- }
- }
- return ret !== undefined ?
-
-
- ret + "" :
- ret;
- }
- function addGetHookIf( conditionFn, hookFn ) {
-
- return {
- get: function() {
- if ( conditionFn() ) {
-
-
-
- delete this.get;
- return;
- }
-
- return (this.get = hookFn).apply( this, arguments );
- }
- };
- }
- (function() {
- var pixelPositionVal, boxSizingReliableVal,
- docElem = document.documentElement,
- container = document.createElement( "div" ),
- div = document.createElement( "div" );
- if ( !div.style ) {
- return;
- }
- div.style.backgroundClip = "content-box";
- div.cloneNode( true ).style.backgroundClip = "";
- support.clearCloneStyle = div.style.backgroundClip === "content-box";
- container.style.cssText = "border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;" +
- "position:absolute";
- container.appendChild( div );
-
-
- function computePixelPositionAndBoxSizingReliable() {
- div.style.cssText =
-
-
- "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" +
- "box-sizing:border-box;display:block;margin-top:1%;top:1%;" +
- "border:1px;padding:1px;width:4px;position:absolute";
- div.innerHTML = "";
- docElem.appendChild( container );
- var divStyle = window.getComputedStyle( div, null );
- pixelPositionVal = divStyle.top !== "1%";
- boxSizingReliableVal = divStyle.width === "4px";
- docElem.removeChild( container );
- }
-
-
- if ( window.getComputedStyle ) {
- jQuery.extend( support, {
- pixelPosition: function() {
-
-
-
- computePixelPositionAndBoxSizingReliable();
- return pixelPositionVal;
- },
- boxSizingReliable: function() {
- if ( boxSizingReliableVal == null ) {
- computePixelPositionAndBoxSizingReliable();
- }
- return boxSizingReliableVal;
- },
- reliableMarginRight: function() {
-
-
-
-
-
- var ret,
- marginDiv = div.appendChild( document.createElement( "div" ) );
-
- marginDiv.style.cssText = div.style.cssText =
-
-
- "-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
- "box-sizing:content-box;display:block;margin:0;border:0;padding:0";
- marginDiv.style.marginRight = marginDiv.style.width = "0";
- div.style.width = "1px";
- docElem.appendChild( container );
- ret = !parseFloat( window.getComputedStyle( marginDiv, null ).marginRight );
- docElem.removeChild( container );
- return ret;
- }
- });
- }
- })();
- jQuery.swap = function( elem, options, callback, args ) {
- var ret, name,
- old = {};
-
- for ( name in options ) {
- old[ name ] = elem.style[ name ];
- elem.style[ name ] = options[ name ];
- }
- ret = callback.apply( elem, args || [] );
-
- for ( name in options ) {
- elem.style[ name ] = old[ name ];
- }
- return ret;
- };
- var
-
-
- rdisplayswap = /^(none|table(?!-c[ea]).+)/,
- rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
- rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
- cssShow = { position: "absolute", visibility: "hidden", display: "block" },
- cssNormalTransform = {
- letterSpacing: "0",
- fontWeight: "400"
- },
- cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
- function vendorPropName( style, name ) {
-
- if ( name in style ) {
- return name;
- }
-
- var capName = name[0].toUpperCase() + name.slice(1),
- origName = name,
- i = cssPrefixes.length;
- while ( i-- ) {
- name = cssPrefixes[ i ] + capName;
- if ( name in style ) {
- return name;
- }
- }
- return origName;
- }
- function setPositiveNumber( elem, value, subtract ) {
- var matches = rnumsplit.exec( value );
- return matches ?
-
- Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
- value;
- }
- function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
- var i = extra === ( isBorderBox ? "border" : "content" ) ?
-
- 4 :
-
- name === "width" ? 1 : 0,
- val = 0;
- for ( ; i < 4; i += 2 ) {
-
- if ( extra === "margin" ) {
- val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
- }
- if ( isBorderBox ) {
-
- if ( extra === "content" ) {
- val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
- }
-
- if ( extra !== "margin" ) {
- val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
- }
- } else {
-
- val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
-
- if ( extra !== "padding" ) {
- val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
- }
- }
- }
- return val;
- }
- function getWidthOrHeight( elem, name, extra ) {
-
- var valueIsBorderBox = true,
- val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
- styles = getStyles( elem ),
- isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
-
-
-
- if ( val <= 0 || val == null ) {
-
- val = curCSS( elem, name, styles );
- if ( val < 0 || val == null ) {
- val = elem.style[ name ];
- }
-
- if ( rnumnonpx.test(val) ) {
- return val;
- }
-
-
- valueIsBorderBox = isBorderBox &&
- ( support.boxSizingReliable() || val === elem.style[ name ] );
-
- val = parseFloat( val ) || 0;
- }
-
- return ( val +
- augmentWidthOrHeight(
- elem,
- name,
- extra || ( isBorderBox ? "border" : "content" ),
- valueIsBorderBox,
- styles
- )
- ) + "px";
- }
- function showHide( elements, show ) {
- var display, elem, hidden,
- values = [],
- index = 0,
- length = elements.length;
- for ( ; index < length; index++ ) {
- elem = elements[ index ];
- if ( !elem.style ) {
- continue;
- }
- values[ index ] = data_priv.get( elem, "olddisplay" );
- display = elem.style.display;
- if ( show ) {
-
-
- if ( !values[ index ] && display === "none" ) {
- elem.style.display = "";
- }
-
-
-
- if ( elem.style.display === "" && isHidden( elem ) ) {
- values[ index ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) );
- }
- } else {
- hidden = isHidden( elem );
- if ( display !== "none" || !hidden ) {
- data_priv.set( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) );
- }
- }
- }
-
-
- for ( index = 0; index < length; index++ ) {
- elem = elements[ index ];
- if ( !elem.style ) {
- continue;
- }
- if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
- elem.style.display = show ? values[ index ] || "" : "none";
- }
- }
- return elements;
- }
- jQuery.extend({
-
-
- cssHooks: {
- opacity: {
- get: function( elem, computed ) {
- if ( computed ) {
-
- var ret = curCSS( elem, "opacity" );
- return ret === "" ? "1" : ret;
- }
- }
- }
- },
-
- cssNumber: {
- "columnCount": true,
- "fillOpacity": true,
- "flexGrow": true,
- "flexShrink": true,
- "fontWeight": true,
- "lineHeight": true,
- "opacity": true,
- "order": true,
- "orphans": true,
- "widows": true,
- "zIndex": true,
- "zoom": true
- },
-
-
- cssProps: {
-
- "float": "cssFloat"
- },
-
- style: function( elem, name, value, extra ) {
-
- if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
- return;
- }
-
- var ret, type, hooks,
- origName = jQuery.camelCase( name ),
- style = elem.style;
- name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) );
-
-
- hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
-
- if ( value !== undefined ) {
- type = typeof value;
-
- if ( type === "string" && (ret = rrelNum.exec( value )) ) {
- value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) );
-
- type = "number";
- }
-
- if ( value == null || value !== value ) {
- return;
- }
-
- if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
- value += "px";
- }
-
-
- if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
- style[ name ] = "inherit";
- }
-
- if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) {
- style[ name ] = value;
- }
- } else {
-
- if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
- return ret;
- }
-
- return style[ name ];
- }
- },
- css: function( elem, name, extra, styles ) {
- var val, num, hooks,
- origName = jQuery.camelCase( name );
-
- name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) );
-
-
- hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
-
- if ( hooks && "get" in hooks ) {
- val = hooks.get( elem, true, extra );
- }
-
- if ( val === undefined ) {
- val = curCSS( elem, name, styles );
- }
-
- if ( val === "normal" && name in cssNormalTransform ) {
- val = cssNormalTransform[ name ];
- }
-
- if ( extra === "" || extra ) {
- num = parseFloat( val );
- return extra === true || jQuery.isNumeric( num ) ? num || 0 : val;
- }
- return val;
- }
- });
- jQuery.each([ "height", "width" ], function( i, name ) {
- jQuery.cssHooks[ name ] = {
- get: function( elem, computed, extra ) {
- if ( computed ) {
-
-
- return rdisplayswap.test( jQuery.css( elem, "display" ) ) && elem.offsetWidth === 0 ?
- jQuery.swap( elem, cssShow, function() {
- return getWidthOrHeight( elem, name, extra );
- }) :
- getWidthOrHeight( elem, name, extra );
- }
- },
- set: function( elem, value, extra ) {
- var styles = extra && getStyles( elem );
- return setPositiveNumber( elem, value, extra ?
- augmentWidthOrHeight(
- elem,
- name,
- extra,
- jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
- styles
- ) : 0
- );
- }
- };
- });
- jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
- function( elem, computed ) {
- if ( computed ) {
-
-
- return jQuery.swap( elem, { "display": "inline-block" },
- curCSS, [ elem, "marginRight" ] );
- }
- }
- );
- jQuery.each({
- margin: "",
- padding: "",
- border: "Width"
- }, function( prefix, suffix ) {
- jQuery.cssHooks[ prefix + suffix ] = {
- expand: function( value ) {
- var i = 0,
- expanded = {},
-
- parts = typeof value === "string" ? value.split(" ") : [ value ];
- for ( ; i < 4; i++ ) {
- expanded[ prefix + cssExpand[ i ] + suffix ] =
- parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
- }
- return expanded;
- }
- };
- if ( !rmargin.test( prefix ) ) {
- jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
- }
- });
- jQuery.fn.extend({
- css: function( name, value ) {
- return access( this, function( elem, name, value ) {
- var styles, len,
- map = {},
- i = 0;
- if ( jQuery.isArray( name ) ) {
- styles = getStyles( elem );
- len = name.length;
- for ( ; i < len; i++ ) {
- map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
- }
- return map;
- }
- return value !== undefined ?
- jQuery.style( elem, name, value ) :
- jQuery.css( elem, name );
- }, name, value, arguments.length > 1 );
- },
- show: function() {
- return showHide( this, true );
- },
- hide: function() {
- return showHide( this );
- },
- toggle: function( state ) {
- if ( typeof state === "boolean" ) {
- return state ? this.show() : this.hide();
- }
- return this.each(function() {
- if ( isHidden( this ) ) {
- jQuery( this ).show();
- } else {
- jQuery( this ).hide();
- }
- });
- }
- });
- function Tween( elem, options, prop, end, easing ) {
- return new Tween.prototype.init( elem, options, prop, end, easing );
- }
- jQuery.Tween = Tween;
- Tween.prototype = {
- constructor: Tween,
- init: function( elem, options, prop, end, easing, unit ) {
- this.elem = elem;
- this.prop = prop;
- this.easing = easing || "swing";
- this.options = options;
- this.start = this.now = this.cur();
- this.end = end;
- this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
- },
- cur: function() {
- var hooks = Tween.propHooks[ this.prop ];
- return hooks && hooks.get ?
- hooks.get( this ) :
- Tween.propHooks._default.get( this );
- },
- run: function( percent ) {
- var eased,
- hooks = Tween.propHooks[ this.prop ];
- if ( this.options.duration ) {
- this.pos = eased = jQuery.easing[ this.easing ](
- percent, this.options.duration * percent, 0, 1, this.options.duration
- );
- } else {
- this.pos = eased = percent;
- }
- this.now = ( this.end - this.start ) * eased + this.start;
- if ( this.options.step ) {
- this.options.step.call( this.elem, this.now, this );
- }
- if ( hooks && hooks.set ) {
- hooks.set( this );
- } else {
- Tween.propHooks._default.set( this );
- }
- return this;
- }
- };
- Tween.prototype.init.prototype = Tween.prototype;
- Tween.propHooks = {
- _default: {
- get: function( tween ) {
- var result;
- if ( tween.elem[ tween.prop ] != null &&
- (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) {
- return tween.elem[ tween.prop ];
- }
-
-
-
-
- result = jQuery.css( tween.elem, tween.prop, "" );
-
- return !result || result === "auto" ? 0 : result;
- },
- set: function( tween ) {
-
-
- if ( jQuery.fx.step[ tween.prop ] ) {
- jQuery.fx.step[ tween.prop ]( tween );
- } else if ( tween.elem.style && ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || jQuery.cssHooks[ tween.prop ] ) ) {
- jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
- } else {
- tween.elem[ tween.prop ] = tween.now;
- }
- }
- }
- };
- Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
- set: function( tween ) {
- if ( tween.elem.nodeType && tween.elem.parentNode ) {
- tween.elem[ tween.prop ] = tween.now;
- }
- }
- };
- jQuery.easing = {
- linear: function( p ) {
- return p;
- },
- swing: function( p ) {
- return 0.5 - Math.cos( p * Math.PI ) / 2;
- }
- };
- jQuery.fx = Tween.prototype.init;
- jQuery.fx.step = {};
- var
- fxNow, timerId,
- rfxtypes = /^(?:toggle|show|hide)$/,
- rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
- rrun = /queueHooks$/,
- animationPrefilters = [ defaultPrefilter ],
- tweeners = {
- "*": [ function( prop, value ) {
- var tween = this.createTween( prop, value ),
- target = tween.cur(),
- parts = rfxnum.exec( value ),
- unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
-
- start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) &&
- rfxnum.exec( jQuery.css( tween.elem, prop ) ),
- scale = 1,
- maxIterations = 20;
- if ( start && start[ 3 ] !== unit ) {
-
- unit = unit || start[ 3 ];
-
- parts = parts || [];
-
- start = +target || 1;
- do {
-
-
- scale = scale || ".5";
-
- start = start / scale;
- jQuery.style( tween.elem, prop, start + unit );
-
-
- } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations );
- }
-
- if ( parts ) {
- start = tween.start = +start || +target || 0;
- tween.unit = unit;
-
- tween.end = parts[ 1 ] ?
- start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
- +parts[ 2 ];
- }
- return tween;
- } ]
- };
- function createFxNow() {
- setTimeout(function() {
- fxNow = undefined;
- });
- return ( fxNow = jQuery.now() );
- }
- function genFx( type, includeWidth ) {
- var which,
- i = 0,
- attrs = { height: type };
-
-
- includeWidth = includeWidth ? 1 : 0;
- for ( ; i < 4 ; i += 2 - includeWidth ) {
- which = cssExpand[ i ];
- attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
- }
- if ( includeWidth ) {
- attrs.opacity = attrs.width = type;
- }
- return attrs;
- }
- function createTween( value, prop, animation ) {
- var tween,
- collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ),
- index = 0,
- length = collection.length;
- for ( ; index < length; index++ ) {
- if ( (tween = collection[ index ].call( animation, prop, value )) ) {
-
- return tween;
- }
- }
- }
- function defaultPrefilter( elem, props, opts ) {
-
- var prop, value, toggle, tween, hooks, oldfire, display, checkDisplay,
- anim = this,
- orig = {},
- style = elem.style,
- hidden = elem.nodeType && isHidden( elem ),
- dataShow = data_priv.get( elem, "fxshow" );
-
- if ( !opts.queue ) {
- hooks = jQuery._queueHooks( elem, "fx" );
- if ( hooks.unqueued == null ) {
- hooks.unqueued = 0;
- oldfire = hooks.empty.fire;
- hooks.empty.fire = function() {
- if ( !hooks.unqueued ) {
- oldfire();
- }
- };
- }
- hooks.unqueued++;
- anim.always(function() {
-
-
- anim.always(function() {
- hooks.unqueued--;
- if ( !jQuery.queue( elem, "fx" ).length ) {
- hooks.empty.fire();
- }
- });
- });
- }
-
- if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
-
-
-
-
- opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
-
-
- display = jQuery.css( elem, "display" );
-
- checkDisplay = display === "none" ?
- data_priv.get( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display;
- if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) {
- style.display = "inline-block";
- }
- }
- if ( opts.overflow ) {
- style.overflow = "hidden";
- anim.always(function() {
- style.overflow = opts.overflow[ 0 ];
- style.overflowX = opts.overflow[ 1 ];
- style.overflowY = opts.overflow[ 2 ];
- });
- }
-
- for ( prop in props ) {
- value = props[ prop ];
- if ( rfxtypes.exec( value ) ) {
- delete props[ prop ];
- toggle = toggle || value === "toggle";
- if ( value === ( hidden ? "hide" : "show" ) ) {
-
- if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
- hidden = true;
- } else {
- continue;
- }
- }
- orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
-
- } else {
- display = undefined;
- }
- }
- if ( !jQuery.isEmptyObject( orig ) ) {
- if ( dataShow ) {
- if ( "hidden" in dataShow ) {
- hidden = dataShow.hidden;
- }
- } else {
- dataShow = data_priv.access( elem, "fxshow", {} );
- }
-
- if ( toggle ) {
- dataShow.hidden = !hidden;
- }
- if ( hidden ) {
- jQuery( elem ).show();
- } else {
- anim.done(function() {
- jQuery( elem ).hide();
- });
- }
- anim.done(function() {
- var prop;
- data_priv.remove( elem, "fxshow" );
- for ( prop in orig ) {
- jQuery.style( elem, prop, orig[ prop ] );
- }
- });
- for ( prop in orig ) {
- tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
- if ( !( prop in dataShow ) ) {
- dataShow[ prop ] = tween.start;
- if ( hidden ) {
- tween.end = tween.start;
- tween.start = prop === "width" || prop === "height" ? 1 : 0;
- }
- }
- }
-
- } else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) {
- style.display = display;
- }
- }
- function propFilter( props, specialEasing ) {
- var index, name, easing, value, hooks;
-
- for ( index in props ) {
- name = jQuery.camelCase( index );
- easing = specialEasing[ name ];
- value = props[ index ];
- if ( jQuery.isArray( value ) ) {
- easing = value[ 1 ];
- value = props[ index ] = value[ 0 ];
- }
- if ( index !== name ) {
- props[ name ] = value;
- delete props[ index ];
- }
- hooks = jQuery.cssHooks[ name ];
- if ( hooks && "expand" in hooks ) {
- value = hooks.expand( value );
- delete props[ name ];
-
-
- for ( index in value ) {
- if ( !( index in props ) ) {
- props[ index ] = value[ index ];
- specialEasing[ index ] = easing;
- }
- }
- } else {
- specialEasing[ name ] = easing;
- }
- }
- }
- function Animation( elem, properties, options ) {
- var result,
- stopped,
- index = 0,
- length = animationPrefilters.length,
- deferred = jQuery.Deferred().always( function() {
-
- delete tick.elem;
- }),
- tick = function() {
- if ( stopped ) {
- return false;
- }
- var currentTime = fxNow || createFxNow(),
- remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
-
- temp = remaining / animation.duration || 0,
- percent = 1 - temp,
- index = 0,
- length = animation.tweens.length;
- for ( ; index < length ; index++ ) {
- animation.tweens[ index ].run( percent );
- }
- deferred.notifyWith( elem, [ animation, percent, remaining ]);
- if ( percent < 1 && length ) {
- return remaining;
- } else {
- deferred.resolveWith( elem, [ animation ] );
- return false;
- }
- },
- animation = deferred.promise({
- elem: elem,
- props: jQuery.extend( {}, properties ),
- opts: jQuery.extend( true, { specialEasing: {} }, options ),
- originalProperties: properties,
- originalOptions: options,
- startTime: fxNow || createFxNow(),
- duration: options.duration,
- tweens: [],
- createTween: function( prop, end ) {
- var tween = jQuery.Tween( elem, animation.opts, prop, end,
- animation.opts.specialEasing[ prop ] || animation.opts.easing );
- animation.tweens.push( tween );
- return tween;
- },
- stop: function( gotoEnd ) {
- var index = 0,
-
-
- length = gotoEnd ? animation.tweens.length : 0;
- if ( stopped ) {
- return this;
- }
- stopped = true;
- for ( ; index < length ; index++ ) {
- animation.tweens[ index ].run( 1 );
- }
-
-
- if ( gotoEnd ) {
- deferred.resolveWith( elem, [ animation, gotoEnd ] );
- } else {
- deferred.rejectWith( elem, [ animation, gotoEnd ] );
- }
- return this;
- }
- }),
- props = animation.props;
- propFilter( props, animation.opts.specialEasing );
- for ( ; index < length ; index++ ) {
- result = animationPrefilters[ index ].call( animation, elem, props, animation.opts );
- if ( result ) {
- return result;
- }
- }
- jQuery.map( props, createTween, animation );
- if ( jQuery.isFunction( animation.opts.start ) ) {
- animation.opts.start.call( elem, animation );
- }
- jQuery.fx.timer(
- jQuery.extend( tick, {
- elem: elem,
- anim: animation,
- queue: animation.opts.queue
- })
- );
-
- return animation.progress( animation.opts.progress )
- .done( animation.opts.done, animation.opts.complete )
- .fail( animation.opts.fail )
- .always( animation.opts.always );
- }
- jQuery.Animation = jQuery.extend( Animation, {
- tweener: function( props, callback ) {
- if ( jQuery.isFunction( props ) ) {
- callback = props;
- props = [ "*" ];
- } else {
- props = props.split(" ");
- }
- var prop,
- index = 0,
- length = props.length;
- for ( ; index < length ; index++ ) {
- prop = props[ index ];
- tweeners[ prop ] = tweeners[ prop ] || [];
- tweeners[ prop ].unshift( callback );
- }
- },
- prefilter: function( callback, prepend ) {
- if ( prepend ) {
- animationPrefilters.unshift( callback );
- } else {
- animationPrefilters.push( callback );
- }
- }
- });
- jQuery.speed = function( speed, easing, fn ) {
- var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
- complete: fn || !fn && easing ||
- jQuery.isFunction( speed ) && speed,
- duration: speed,
- easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
- };
- opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
- opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
-
- if ( opt.queue == null || opt.queue === true ) {
- opt.queue = "fx";
- }
-
- opt.old = opt.complete;
- opt.complete = function() {
- if ( jQuery.isFunction( opt.old ) ) {
- opt.old.call( this );
- }
- if ( opt.queue ) {
- jQuery.dequeue( this, opt.queue );
- }
- };
- return opt;
- };
- jQuery.fn.extend({
- fadeTo: function( speed, to, easing, callback ) {
-
- return this.filter( isHidden ).css( "opacity", 0 ).show()
-
- .end().animate({ opacity: to }, speed, easing, callback );
- },
- animate: function( prop, speed, easing, callback ) {
- var empty = jQuery.isEmptyObject( prop ),
- optall = jQuery.speed( speed, easing, callback ),
- doAnimation = function() {
-
- var anim = Animation( this, jQuery.extend( {}, prop ), optall );
-
- if ( empty || data_priv.get( this, "finish" ) ) {
- anim.stop( true );
- }
- };
- doAnimation.finish = doAnimation;
- return empty || optall.queue === false ?
- this.each( doAnimation ) :
- this.queue( optall.queue, doAnimation );
- },
- stop: function( type, clearQueue, gotoEnd ) {
- var stopQueue = function( hooks ) {
- var stop = hooks.stop;
- delete hooks.stop;
- stop( gotoEnd );
- };
- if ( typeof type !== "string" ) {
- gotoEnd = clearQueue;
- clearQueue = type;
- type = undefined;
- }
- if ( clearQueue && type !== false ) {
- this.queue( type || "fx", [] );
- }
- return this.each(function() {
- var dequeue = true,
- index = type != null && type + "queueHooks",
- timers = jQuery.timers,
- data = data_priv.get( this );
- if ( index ) {
- if ( data[ index ] && data[ index ].stop ) {
- stopQueue( data[ index ] );
- }
- } else {
- for ( index in data ) {
- if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
- stopQueue( data[ index ] );
- }
- }
- }
- for ( index = timers.length; index--; ) {
- if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
- timers[ index ].anim.stop( gotoEnd );
- dequeue = false;
- timers.splice( index, 1 );
- }
- }
-
-
-
- if ( dequeue || !gotoEnd ) {
- jQuery.dequeue( this, type );
- }
- });
- },
- finish: function( type ) {
- if ( type !== false ) {
- type = type || "fx";
- }
- return this.each(function() {
- var index,
- data = data_priv.get( this ),
- queue = data[ type + "queue" ],
- hooks = data[ type + "queueHooks" ],
- timers = jQuery.timers,
- length = queue ? queue.length : 0;
-
- data.finish = true;
-
- jQuery.queue( this, type, [] );
- if ( hooks && hooks.stop ) {
- hooks.stop.call( this, true );
- }
-
- for ( index = timers.length; index--; ) {
- if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
- timers[ index ].anim.stop( true );
- timers.splice( index, 1 );
- }
- }
-
- for ( index = 0; index < length; index++ ) {
- if ( queue[ index ] && queue[ index ].finish ) {
- queue[ index ].finish.call( this );
- }
- }
-
- delete data.finish;
- });
- }
- });
- jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
- var cssFn = jQuery.fn[ name ];
- jQuery.fn[ name ] = function( speed, easing, callback ) {
- return speed == null || typeof speed === "boolean" ?
- cssFn.apply( this, arguments ) :
- this.animate( genFx( name, true ), speed, easing, callback );
- };
- });
- jQuery.each({
- slideDown: genFx("show"),
- slideUp: genFx("hide"),
- slideToggle: genFx("toggle"),
- fadeIn: { opacity: "show" },
- fadeOut: { opacity: "hide" },
- fadeToggle: { opacity: "toggle" }
- }, function( name, props ) {
- jQuery.fn[ name ] = function( speed, easing, callback ) {
- return this.animate( props, speed, easing, callback );
- };
- });
- jQuery.timers = [];
- jQuery.fx.tick = function() {
- var timer,
- i = 0,
- timers = jQuery.timers;
- fxNow = jQuery.now();
- for ( ; i < timers.length; i++ ) {
- timer = timers[ i ];
-
- if ( !timer() && timers[ i ] === timer ) {
- timers.splice( i--, 1 );
- }
- }
- if ( !timers.length ) {
- jQuery.fx.stop();
- }
- fxNow = undefined;
- };
- jQuery.fx.timer = function( timer ) {
- jQuery.timers.push( timer );
- if ( timer() ) {
- jQuery.fx.start();
- } else {
- jQuery.timers.pop();
- }
- };
- jQuery.fx.interval = 13;
- jQuery.fx.start = function() {
- if ( !timerId ) {
- timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
- }
- };
- jQuery.fx.stop = function() {
- clearInterval( timerId );
- timerId = null;
- };
- jQuery.fx.speeds = {
- slow: 600,
- fast: 200,
-
- _default: 400
- };
- jQuery.fn.delay = function( time, type ) {
- time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
- type = type || "fx";
- return this.queue( type, function( next, hooks ) {
- var timeout = setTimeout( next, time );
- hooks.stop = function() {
- clearTimeout( timeout );
- };
- });
- };
- (function() {
- var input = document.createElement( "input" ),
- select = document.createElement( "select" ),
- opt = select.appendChild( document.createElement( "option" ) );
- input.type = "checkbox";
-
-
- support.checkOn = input.value !== "";
-
-
- support.optSelected = opt.selected;
-
-
- select.disabled = true;
- support.optDisabled = !opt.disabled;
-
-
- input = document.createElement( "input" );
- input.value = "t";
- input.type = "radio";
- support.radioValue = input.value === "t";
- })();
- var nodeHook, boolHook,
- attrHandle = jQuery.expr.attrHandle;
- jQuery.fn.extend({
- attr: function( name, value ) {
- return access( this, jQuery.attr, name, value, arguments.length > 1 );
- },
- removeAttr: function( name ) {
- return this.each(function() {
- jQuery.removeAttr( this, name );
- });
- }
- });
- jQuery.extend({
- attr: function( elem, name, value ) {
- var hooks, ret,
- nType = elem.nodeType;
-
- if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
- return;
- }
-
- if ( typeof elem.getAttribute === strundefined ) {
- return jQuery.prop( elem, name, value );
- }
-
-
- if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
- name = name.toLowerCase();
- hooks = jQuery.attrHooks[ name ] ||
- ( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
- }
- if ( value !== undefined ) {
- if ( value === null ) {
- jQuery.removeAttr( elem, name );
- } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
- return ret;
- } else {
- elem.setAttribute( name, value + "" );
- return value;
- }
- } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
- return ret;
- } else {
- ret = jQuery.find.attr( elem, name );
-
- return ret == null ?
- undefined :
- ret;
- }
- },
- removeAttr: function( elem, value ) {
- var name, propName,
- i = 0,
- attrNames = value && value.match( rnotwhite );
- if ( attrNames && elem.nodeType === 1 ) {
- while ( (name = attrNames[i++]) ) {
- propName = jQuery.propFix[ name ] || name;
-
- if ( jQuery.expr.match.bool.test( name ) ) {
-
- elem[ propName ] = false;
- }
- elem.removeAttribute( name );
- }
- }
- },
- attrHooks: {
- type: {
- set: function( elem, value ) {
- if ( !support.radioValue && value === "radio" &&
- jQuery.nodeName( elem, "input" ) ) {
-
-
- var val = elem.value;
- elem.setAttribute( "type", value );
- if ( val ) {
- elem.value = val;
- }
- return value;
- }
- }
- }
- }
- });
- boolHook = {
- set: function( elem, value, name ) {
- if ( value === false ) {
-
- jQuery.removeAttr( elem, name );
- } else {
- elem.setAttribute( name, name );
- }
- return name;
- }
- };
- jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
- var getter = attrHandle[ name ] || jQuery.find.attr;
- attrHandle[ name ] = function( elem, name, isXML ) {
- var ret, handle;
- if ( !isXML ) {
-
- handle = attrHandle[ name ];
- attrHandle[ name ] = ret;
- ret = getter( elem, name, isXML ) != null ?
- name.toLowerCase() :
- null;
- attrHandle[ name ] = handle;
- }
- return ret;
- };
- });
- var rfocusable = /^(?:input|select|textarea|button)$/i;
- jQuery.fn.extend({
- prop: function( name, value ) {
- return access( this, jQuery.prop, name, value, arguments.length > 1 );
- },
- removeProp: function( name ) {
- return this.each(function() {
- delete this[ jQuery.propFix[ name ] || name ];
- });
- }
- });
- jQuery.extend({
- propFix: {
- "for": "htmlFor",
- "class": "className"
- },
- prop: function( elem, name, value ) {
- var ret, hooks, notxml,
- nType = elem.nodeType;
-
- if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
- return;
- }
- notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
- if ( notxml ) {
-
- name = jQuery.propFix[ name ] || name;
- hooks = jQuery.propHooks[ name ];
- }
- if ( value !== undefined ) {
- return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ?
- ret :
- ( elem[ name ] = value );
- } else {
- return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ?
- ret :
- elem[ name ];
- }
- },
- propHooks: {
- tabIndex: {
- get: function( elem ) {
- return elem.hasAttribute( "tabindex" ) || rfocusable.test( elem.nodeName ) || elem.href ?
- elem.tabIndex :
- -1;
- }
- }
- }
- });
- if ( !support.optSelected ) {
- jQuery.propHooks.selected = {
- get: function( elem ) {
- var parent = elem.parentNode;
- if ( parent && parent.parentNode ) {
- parent.parentNode.selectedIndex;
- }
- return null;
- }
- };
- }
- jQuery.each([
- "tabIndex",
- "readOnly",
- "maxLength",
- "cellSpacing",
- "cellPadding",
- "rowSpan",
- "colSpan",
- "useMap",
- "frameBorder",
- "contentEditable"
- ], function() {
- jQuery.propFix[ this.toLowerCase() ] = this;
- });
- var rclass = /[\t\r\n\f]/g;
- jQuery.fn.extend({
- addClass: function( value ) {
- var classes, elem, cur, clazz, j, finalValue,
- proceed = typeof value === "string" && value,
- i = 0,
- len = this.length;
- if ( jQuery.isFunction( value ) ) {
- return this.each(function( j ) {
- jQuery( this ).addClass( value.call( this, j, this.className ) );
- });
- }
- if ( proceed ) {
-
- classes = ( value || "" ).match( rnotwhite ) || [];
- for ( ; i < len; i++ ) {
- elem = this[ i ];
- cur = elem.nodeType === 1 && ( elem.className ?
- ( " " + elem.className + " " ).replace( rclass, " " ) :
- " "
- );
- if ( cur ) {
- j = 0;
- while ( (clazz = classes[j++]) ) {
- if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
- cur += clazz + " ";
- }
- }
-
- finalValue = jQuery.trim( cur );
- if ( elem.className !== finalValue ) {
- elem.className = finalValue;
- }
- }
- }
- }
- return this;
- },
- removeClass: function( value ) {
- var classes, elem, cur, clazz, j, finalValue,
- proceed = arguments.length === 0 || typeof value === "string" && value,
- i = 0,
- len = this.length;
- if ( jQuery.isFunction( value ) ) {
- return this.each(function( j ) {
- jQuery( this ).removeClass( value.call( this, j, this.className ) );
- });
- }
- if ( proceed ) {
- classes = ( value || "" ).match( rnotwhite ) || [];
- for ( ; i < len; i++ ) {
- elem = this[ i ];
-
- cur = elem.nodeType === 1 && ( elem.className ?
- ( " " + elem.className + " " ).replace( rclass, " " ) :
- ""
- );
- if ( cur ) {
- j = 0;
- while ( (clazz = classes[j++]) ) {
-
- while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
- cur = cur.replace( " " + clazz + " ", " " );
- }
- }
-
- finalValue = value ? jQuery.trim( cur ) : "";
- if ( elem.className !== finalValue ) {
- elem.className = finalValue;
- }
- }
- }
- }
- return this;
- },
- toggleClass: function( value, stateVal ) {
- var type = typeof value;
- if ( typeof stateVal === "boolean" && type === "string" ) {
- return stateVal ? this.addClass( value ) : this.removeClass( value );
- }
- if ( jQuery.isFunction( value ) ) {
- return this.each(function( i ) {
- jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
- });
- }
- return this.each(function() {
- if ( type === "string" ) {
-
- var className,
- i = 0,
- self = jQuery( this ),
- classNames = value.match( rnotwhite ) || [];
- while ( (className = classNames[ i++ ]) ) {
-
- if ( self.hasClass( className ) ) {
- self.removeClass( className );
- } else {
- self.addClass( className );
- }
- }
-
- } else if ( type === strundefined || type === "boolean" ) {
- if ( this.className ) {
-
- data_priv.set( this, "__className__", this.className );
- }
-
-
-
-
- this.className = this.className || value === false ? "" : data_priv.get( this, "__className__" ) || "";
- }
- });
- },
- hasClass: function( selector ) {
- var className = " " + selector + " ",
- i = 0,
- l = this.length;
- for ( ; i < l; i++ ) {
- if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
- return true;
- }
- }
- return false;
- }
- });
- var rreturn = /\r/g;
- jQuery.fn.extend({
- val: function( value ) {
- var hooks, ret, isFunction,
- elem = this[0];
- if ( !arguments.length ) {
- if ( elem ) {
- hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
- if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
- return ret;
- }
- ret = elem.value;
- return typeof ret === "string" ?
-
- ret.replace(rreturn, "") :
-
- ret == null ? "" : ret;
- }
- return;
- }
- isFunction = jQuery.isFunction( value );
- return this.each(function( i ) {
- var val;
- if ( this.nodeType !== 1 ) {
- return;
- }
- if ( isFunction ) {
- val = value.call( this, i, jQuery( this ).val() );
- } else {
- val = value;
- }
-
- if ( val == null ) {
- val = "";
- } else if ( typeof val === "number" ) {
- val += "";
- } else if ( jQuery.isArray( val ) ) {
- val = jQuery.map( val, function( value ) {
- return value == null ? "" : value + "";
- });
- }
- hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
-
- if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
- this.value = val;
- }
- });
- }
- });
- jQuery.extend({
- valHooks: {
- option: {
- get: function( elem ) {
- var val = jQuery.find.attr( elem, "value" );
- return val != null ?
- val :
-
-
- jQuery.trim( jQuery.text( elem ) );
- }
- },
- select: {
- get: function( elem ) {
- var value, option,
- options = elem.options,
- index = elem.selectedIndex,
- one = elem.type === "select-one" || index < 0,
- values = one ? null : [],
- max = one ? index + 1 : options.length,
- i = index < 0 ?
- max :
- one ? index : 0;
-
- for ( ; i < max; i++ ) {
- option = options[ i ];
-
- if ( ( option.selected || i === index ) &&
-
- ( support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) &&
- ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
-
- value = jQuery( option ).val();
-
- if ( one ) {
- return value;
- }
-
- values.push( value );
- }
- }
- return values;
- },
- set: function( elem, value ) {
- var optionSet, option,
- options = elem.options,
- values = jQuery.makeArray( value ),
- i = options.length;
- while ( i-- ) {
- option = options[ i ];
- if ( (option.selected = jQuery.inArray( option.value, values ) >= 0) ) {
- optionSet = true;
- }
- }
-
- if ( !optionSet ) {
- elem.selectedIndex = -1;
- }
- return values;
- }
- }
- }
- });
- jQuery.each([ "radio", "checkbox" ], function() {
- jQuery.valHooks[ this ] = {
- set: function( elem, value ) {
- if ( jQuery.isArray( value ) ) {
- return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
- }
- }
- };
- if ( !support.checkOn ) {
- jQuery.valHooks[ this ].get = function( elem ) {
-
-
- return elem.getAttribute("value") === null ? "on" : elem.value;
- };
- }
- });
- jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
- "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
- "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
-
- jQuery.fn[ name ] = function( data, fn ) {
- return arguments.length > 0 ?
- this.on( name, null, data, fn ) :
- this.trigger( name );
- };
- });
- jQuery.fn.extend({
- hover: function( fnOver, fnOut ) {
- return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
- },
- bind: function( types, data, fn ) {
- return this.on( types, null, data, fn );
- },
- unbind: function( types, fn ) {
- return this.off( types, null, fn );
- },
- delegate: function( selector, types, data, fn ) {
- return this.on( types, selector, data, fn );
- },
- undelegate: function( selector, types, fn ) {
-
- return arguments.length === 1 ? this.off( selector, "**" ) : this.off( types, selector || "**", fn );
- }
- });
- var nonce = jQuery.now();
- var rquery = (/\?/);
- jQuery.parseJSON = function( data ) {
- return JSON.parse( data + "" );
- };
- jQuery.parseXML = function( data ) {
- var xml, tmp;
- if ( !data || typeof data !== "string" ) {
- return null;
- }
-
- try {
- tmp = new DOMParser();
- xml = tmp.parseFromString( data, "text/xml" );
- } catch ( e ) {
- xml = undefined;
- }
- if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
- jQuery.error( "Invalid XML: " + data );
- }
- return xml;
- };
- var
-
- ajaxLocParts,
- ajaxLocation,
- rhash = /#.*$/,
- rts = /([?&])_=[^&]*/,
- rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
-
- rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
- rnoContent = /^(?:GET|HEAD)$/,
- rprotocol = /^\/\//,
- rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
-
- prefilters = {},
-
- transports = {},
-
- allTypes = "*/".concat("*");
- try {
- ajaxLocation = location.href;
- } catch( e ) {
-
-
- ajaxLocation = document.createElement( "a" );
- ajaxLocation.href = "";
- ajaxLocation = ajaxLocation.href;
- }
- ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
- function addToPrefiltersOrTransports( structure ) {
-
- return function( dataTypeExpression, func ) {
- if ( typeof dataTypeExpression !== "string" ) {
- func = dataTypeExpression;
- dataTypeExpression = "*";
- }
- var dataType,
- i = 0,
- dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
- if ( jQuery.isFunction( func ) ) {
-
- while ( (dataType = dataTypes[i++]) ) {
-
- if ( dataType[0] === "+" ) {
- dataType = dataType.slice( 1 ) || "*";
- (structure[ dataType ] = structure[ dataType ] || []).unshift( func );
-
- } else {
- (structure[ dataType ] = structure[ dataType ] || []).push( func );
- }
- }
- }
- };
- }
- function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
- var inspected = {},
- seekingTransport = ( structure === transports );
- function inspect( dataType ) {
- var selected;
- inspected[ dataType ] = true;
- jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
- var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
- if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
- options.dataTypes.unshift( dataTypeOrTransport );
- inspect( dataTypeOrTransport );
- return false;
- } else if ( seekingTransport ) {
- return !( selected = dataTypeOrTransport );
- }
- });
- return selected;
- }
- return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
- }
- function ajaxExtend( target, src ) {
- var key, deep,
- flatOptions = jQuery.ajaxSettings.flatOptions || {};
- for ( key in src ) {
- if ( src[ key ] !== undefined ) {
- ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
- }
- }
- if ( deep ) {
- jQuery.extend( true, target, deep );
- }
- return target;
- }
- function ajaxHandleResponses( s, jqXHR, responses ) {
- var ct, type, finalDataType, firstDataType,
- contents = s.contents,
- dataTypes = s.dataTypes;
-
- while ( dataTypes[ 0 ] === "*" ) {
- dataTypes.shift();
- if ( ct === undefined ) {
- ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
- }
- }
-
- if ( ct ) {
- for ( type in contents ) {
- if ( contents[ type ] && contents[ type ].test( ct ) ) {
- dataTypes.unshift( type );
- break;
- }
- }
- }
-
- if ( dataTypes[ 0 ] in responses ) {
- finalDataType = dataTypes[ 0 ];
- } else {
-
- for ( type in responses ) {
- if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
- finalDataType = type;
- break;
- }
- if ( !firstDataType ) {
- firstDataType = type;
- }
- }
-
- finalDataType = finalDataType || firstDataType;
- }
-
-
-
- if ( finalDataType ) {
- if ( finalDataType !== dataTypes[ 0 ] ) {
- dataTypes.unshift( finalDataType );
- }
- return responses[ finalDataType ];
- }
- }
- function ajaxConvert( s, response, jqXHR, isSuccess ) {
- var conv2, current, conv, tmp, prev,
- converters = {},
-
- dataTypes = s.dataTypes.slice();
-
- if ( dataTypes[ 1 ] ) {
- for ( conv in s.converters ) {
- converters[ conv.toLowerCase() ] = s.converters[ conv ];
- }
- }
- current = dataTypes.shift();
-
- while ( current ) {
- if ( s.responseFields[ current ] ) {
- jqXHR[ s.responseFields[ current ] ] = response;
- }
-
- if ( !prev && isSuccess && s.dataFilter ) {
- response = s.dataFilter( response, s.dataType );
- }
- prev = current;
- current = dataTypes.shift();
- if ( current ) {
-
- if ( current === "*" ) {
- current = prev;
-
- } else if ( prev !== "*" && prev !== current ) {
-
- conv = converters[ prev + " " + current ] || converters[ "* " + current ];
-
- if ( !conv ) {
- for ( conv2 in converters ) {
-
- tmp = conv2.split( " " );
- if ( tmp[ 1 ] === current ) {
-
- conv = converters[ prev + " " + tmp[ 0 ] ] ||
- converters[ "* " + tmp[ 0 ] ];
- if ( conv ) {
-
- if ( conv === true ) {
- conv = converters[ conv2 ];
-
- } else if ( converters[ conv2 ] !== true ) {
- current = tmp[ 0 ];
- dataTypes.unshift( tmp[ 1 ] );
- }
- break;
- }
- }
- }
- }
-
- if ( conv !== true ) {
-
- if ( conv && s[ "throws" ] ) {
- response = conv( response );
- } else {
- try {
- response = conv( response );
- } catch ( e ) {
- return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
- }
- }
- }
- }
- }
- }
- return { state: "success", data: response };
- }
- jQuery.extend({
-
- active: 0,
-
- lastModified: {},
- etag: {},
- ajaxSettings: {
- url: ajaxLocation,
- type: "GET",
- isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
- global: true,
- processData: true,
- async: true,
- contentType: "application/x-www-form-urlencoded; charset=UTF-8",
-
- accepts: {
- "*": allTypes,
- text: "text/plain",
- html: "text/html",
- xml: "application/xml, text/xml",
- json: "application/json, text/javascript"
- },
- contents: {
- xml: /xml/,
- html: /html/,
- json: /json/
- },
- responseFields: {
- xml: "responseXML",
- text: "responseText",
- json: "responseJSON"
- },
-
-
- converters: {
-
- "* text": String,
-
- "text html": true,
-
- "text json": jQuery.parseJSON,
-
- "text xml": jQuery.parseXML
- },
-
-
-
-
- flatOptions: {
- url: true,
- context: true
- }
- },
-
-
-
- ajaxSetup: function( target, settings ) {
- return settings ?
-
- ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
-
- ajaxExtend( jQuery.ajaxSettings, target );
- },
- ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
- ajaxTransport: addToPrefiltersOrTransports( transports ),
-
- ajax: function( url, options ) {
-
- if ( typeof url === "object" ) {
- options = url;
- url = undefined;
- }
-
- options = options || {};
- var transport,
-
- cacheURL,
-
- responseHeadersString,
- responseHeaders,
-
- timeoutTimer,
-
- parts,
-
- fireGlobals,
-
- i,
-
- s = jQuery.ajaxSetup( {}, options ),
-
- callbackContext = s.context || s,
-
- globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
- jQuery( callbackContext ) :
- jQuery.event,
-
- deferred = jQuery.Deferred(),
- completeDeferred = jQuery.Callbacks("once memory"),
-
- statusCode = s.statusCode || {},
-
- requestHeaders = {},
- requestHeadersNames = {},
-
- state = 0,
-
- strAbort = "canceled",
-
- jqXHR = {
- readyState: 0,
-
- getResponseHeader: function( key ) {
- var match;
- if ( state === 2 ) {
- if ( !responseHeaders ) {
- responseHeaders = {};
- while ( (match = rheaders.exec( responseHeadersString )) ) {
- responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
- }
- }
- match = responseHeaders[ key.toLowerCase() ];
- }
- return match == null ? null : match;
- },
-
- getAllResponseHeaders: function() {
- return state === 2 ? responseHeadersString : null;
- },
-
- setRequestHeader: function( name, value ) {
- var lname = name.toLowerCase();
- if ( !state ) {
- name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
- requestHeaders[ name ] = value;
- }
- return this;
- },
-
- overrideMimeType: function( type ) {
- if ( !state ) {
- s.mimeType = type;
- }
- return this;
- },
-
- statusCode: function( map ) {
- var code;
- if ( map ) {
- if ( state < 2 ) {
- for ( code in map ) {
-
- statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
- }
- } else {
-
- jqXHR.always( map[ jqXHR.status ] );
- }
- }
- return this;
- },
-
- abort: function( statusText ) {
- var finalText = statusText || strAbort;
- if ( transport ) {
- transport.abort( finalText );
- }
- done( 0, finalText );
- return this;
- }
- };
-
- deferred.promise( jqXHR ).complete = completeDeferred.add;
- jqXHR.success = jqXHR.done;
- jqXHR.error = jqXHR.fail;
-
-
-
-
- s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" )
- .replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
-
- s.type = options.method || options.type || s.method || s.type;
-
- s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
-
- if ( s.crossDomain == null ) {
- parts = rurl.exec( s.url.toLowerCase() );
- s.crossDomain = !!( parts &&
- ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
- ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
- ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
- );
- }
-
- if ( s.data && s.processData && typeof s.data !== "string" ) {
- s.data = jQuery.param( s.data, s.traditional );
- }
-
- inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
-
- if ( state === 2 ) {
- return jqXHR;
- }
-
- fireGlobals = s.global;
-
- if ( fireGlobals && jQuery.active++ === 0 ) {
- jQuery.event.trigger("ajaxStart");
- }
-
- s.type = s.type.toUpperCase();
-
- s.hasContent = !rnoContent.test( s.type );
-
-
- cacheURL = s.url;
-
- if ( !s.hasContent ) {
-
- if ( s.data ) {
- cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
-
- delete s.data;
- }
-
- if ( s.cache === false ) {
- s.url = rts.test( cacheURL ) ?
-
- cacheURL.replace( rts, "$1_=" + nonce++ ) :
-
- cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
- }
- }
-
- if ( s.ifModified ) {
- if ( jQuery.lastModified[ cacheURL ] ) {
- jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
- }
- if ( jQuery.etag[ cacheURL ] ) {
- jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
- }
- }
-
- if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
- jqXHR.setRequestHeader( "Content-Type", s.contentType );
- }
-
- jqXHR.setRequestHeader(
- "Accept",
- s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
- s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
- s.accepts[ "*" ]
- );
-
- for ( i in s.headers ) {
- jqXHR.setRequestHeader( i, s.headers[ i ] );
- }
-
- if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
-
- return jqXHR.abort();
- }
-
- strAbort = "abort";
-
- for ( i in { success: 1, error: 1, complete: 1 } ) {
- jqXHR[ i ]( s[ i ] );
- }
-
- transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
-
- if ( !transport ) {
- done( -1, "No Transport" );
- } else {
- jqXHR.readyState = 1;
-
- if ( fireGlobals ) {
- globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
- }
-
- if ( s.async && s.timeout > 0 ) {
- timeoutTimer = setTimeout(function() {
- jqXHR.abort("timeout");
- }, s.timeout );
- }
- try {
- state = 1;
- transport.send( requestHeaders, done );
- } catch ( e ) {
-
- if ( state < 2 ) {
- done( -1, e );
-
- } else {
- throw e;
- }
- }
- }
-
- function done( status, nativeStatusText, responses, headers ) {
- var isSuccess, success, error, response, modified,
- statusText = nativeStatusText;
-
- if ( state === 2 ) {
- return;
- }
-
- state = 2;
-
- if ( timeoutTimer ) {
- clearTimeout( timeoutTimer );
- }
-
-
- transport = undefined;
-
- responseHeadersString = headers || "";
-
- jqXHR.readyState = status > 0 ? 4 : 0;
-
- isSuccess = status >= 200 && status < 300 || status === 304;
-
- if ( responses ) {
- response = ajaxHandleResponses( s, jqXHR, responses );
- }
-
- response = ajaxConvert( s, response, jqXHR, isSuccess );
-
- if ( isSuccess ) {
-
- if ( s.ifModified ) {
- modified = jqXHR.getResponseHeader("Last-Modified");
- if ( modified ) {
- jQuery.lastModified[ cacheURL ] = modified;
- }
- modified = jqXHR.getResponseHeader("etag");
- if ( modified ) {
- jQuery.etag[ cacheURL ] = modified;
- }
- }
-
- if ( status === 204 || s.type === "HEAD" ) {
- statusText = "nocontent";
-
- } else if ( status === 304 ) {
- statusText = "notmodified";
-
- } else {
- statusText = response.state;
- success = response.data;
- error = response.error;
- isSuccess = !error;
- }
- } else {
-
-
- error = statusText;
- if ( status || !statusText ) {
- statusText = "error";
- if ( status < 0 ) {
- status = 0;
- }
- }
- }
-
- jqXHR.status = status;
- jqXHR.statusText = ( nativeStatusText || statusText ) + "";
-
- if ( isSuccess ) {
- deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
- } else {
- deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
- }
-
- jqXHR.statusCode( statusCode );
- statusCode = undefined;
- if ( fireGlobals ) {
- globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
- [ jqXHR, s, isSuccess ? success : error ] );
- }
-
- completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
- if ( fireGlobals ) {
- globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
-
- if ( !( --jQuery.active ) ) {
- jQuery.event.trigger("ajaxStop");
- }
- }
- }
- return jqXHR;
- },
- getJSON: function( url, data, callback ) {
- return jQuery.get( url, data, callback, "json" );
- },
- getScript: function( url, callback ) {
- return jQuery.get( url, undefined, callback, "script" );
- }
- });
- jQuery.each( [ "get", "post" ], function( i, method ) {
- jQuery[ method ] = function( url, data, callback, type ) {
-
- if ( jQuery.isFunction( data ) ) {
- type = type || callback;
- callback = data;
- data = undefined;
- }
- return jQuery.ajax({
- url: url,
- type: method,
- dataType: type,
- data: data,
- success: callback
- });
- };
- });
- jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) {
- jQuery.fn[ type ] = function( fn ) {
- return this.on( type, fn );
- };
- });
- jQuery._evalUrl = function( url ) {
- return jQuery.ajax({
- url: url,
- type: "GET",
- dataType: "script",
- async: false,
- global: false,
- "throws": true
- });
- };
- jQuery.fn.extend({
- wrapAll: function( html ) {
- var wrap;
- if ( jQuery.isFunction( html ) ) {
- return this.each(function( i ) {
- jQuery( this ).wrapAll( html.call(this, i) );
- });
- }
- if ( this[ 0 ] ) {
-
- wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
- if ( this[ 0 ].parentNode ) {
- wrap.insertBefore( this[ 0 ] );
- }
- wrap.map(function() {
- var elem = this;
- while ( elem.firstElementChild ) {
- elem = elem.firstElementChild;
- }
- return elem;
- }).append( this );
- }
- return this;
- },
- wrapInner: function( html ) {
- if ( jQuery.isFunction( html ) ) {
- return this.each(function( i ) {
- jQuery( this ).wrapInner( html.call(this, i) );
- });
- }
- return this.each(function() {
- var self = jQuery( this ),
- contents = self.contents();
- if ( contents.length ) {
- contents.wrapAll( html );
- } else {
- self.append( html );
- }
- });
- },
- wrap: function( html ) {
- var isFunction = jQuery.isFunction( html );
- return this.each(function( i ) {
- jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
- });
- },
- unwrap: function() {
- return this.parent().each(function() {
- if ( !jQuery.nodeName( this, "body" ) ) {
- jQuery( this ).replaceWith( this.childNodes );
- }
- }).end();
- }
- });
- jQuery.expr.filters.hidden = function( elem ) {
-
-
- return elem.offsetWidth <= 0 && elem.offsetHeight <= 0;
- };
- jQuery.expr.filters.visible = function( elem ) {
- return !jQuery.expr.filters.hidden( elem );
- };
- var r20 = /%20/g,
- rbracket = /\[\]$/,
- rCRLF = /\r?\n/g,
- rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
- rsubmittable = /^(?:input|select|textarea|keygen)/i;
- function buildParams( prefix, obj, traditional, add ) {
- var name;
- if ( jQuery.isArray( obj ) ) {
-
- jQuery.each( obj, function( i, v ) {
- if ( traditional || rbracket.test( prefix ) ) {
-
- add( prefix, v );
- } else {
-
- buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
- }
- });
- } else if ( !traditional && jQuery.type( obj ) === "object" ) {
-
- for ( name in obj ) {
- buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
- }
- } else {
-
- add( prefix, obj );
- }
- }
- jQuery.param = function( a, traditional ) {
- var prefix,
- s = [],
- add = function( key, value ) {
-
- value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
- s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
- };
-
- if ( traditional === undefined ) {
- traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
- }
-
- if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
-
- jQuery.each( a, function() {
- add( this.name, this.value );
- });
- } else {
-
-
- for ( prefix in a ) {
- buildParams( prefix, a[ prefix ], traditional, add );
- }
- }
-
- return s.join( "&" ).replace( r20, "+" );
- };
- jQuery.fn.extend({
- serialize: function() {
- return jQuery.param( this.serializeArray() );
- },
- serializeArray: function() {
- return this.map(function() {
-
- var elements = jQuery.prop( this, "elements" );
- return elements ? jQuery.makeArray( elements ) : this;
- })
- .filter(function() {
- var type = this.type;
-
- return this.name && !jQuery( this ).is( ":disabled" ) &&
- rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
- ( this.checked || !rcheckableType.test( type ) );
- })
- .map(function( i, elem ) {
- var val = jQuery( this ).val();
- return val == null ?
- null :
- jQuery.isArray( val ) ?
- jQuery.map( val, function( val ) {
- return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
- }) :
- { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
- }).get();
- }
- });
- jQuery.ajaxSettings.xhr = function() {
- try {
- return new XMLHttpRequest();
- } catch( e ) {}
- };
- var xhrId = 0,
- xhrCallbacks = {},
- xhrSuccessStatus = {
-
- 0: 200,
-
-
- 1223: 204
- },
- xhrSupported = jQuery.ajaxSettings.xhr();
- if ( window.ActiveXObject ) {
- jQuery( window ).on( "unload", function() {
- for ( var key in xhrCallbacks ) {
- xhrCallbacks[ key ]();
- }
- });
- }
- support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
- support.ajax = xhrSupported = !!xhrSupported;
- jQuery.ajaxTransport(function( options ) {
- var callback;
-
- if ( support.cors || xhrSupported && !options.crossDomain ) {
- return {
- send: function( headers, complete ) {
- var i,
- xhr = options.xhr(),
- id = ++xhrId;
- xhr.open( options.type, options.url, options.async, options.username, options.password );
-
- if ( options.xhrFields ) {
- for ( i in options.xhrFields ) {
- xhr[ i ] = options.xhrFields[ i ];
- }
- }
-
- if ( options.mimeType && xhr.overrideMimeType ) {
- xhr.overrideMimeType( options.mimeType );
- }
-
-
-
-
-
- if ( !options.crossDomain && !headers["X-Requested-With"] ) {
- headers["X-Requested-With"] = "XMLHttpRequest";
- }
-
- for ( i in headers ) {
- xhr.setRequestHeader( i, headers[ i ] );
- }
-
- callback = function( type ) {
- return function() {
- if ( callback ) {
- delete xhrCallbacks[ id ];
- callback = xhr.onload = xhr.onerror = null;
- if ( type === "abort" ) {
- xhr.abort();
- } else if ( type === "error" ) {
- complete(
-
- xhr.status,
- xhr.statusText
- );
- } else {
- complete(
- xhrSuccessStatus[ xhr.status ] || xhr.status,
- xhr.statusText,
-
-
-
- typeof xhr.responseText === "string" ? {
- text: xhr.responseText
- } : undefined,
- xhr.getAllResponseHeaders()
- );
- }
- }
- };
- };
-
- xhr.onload = callback();
- xhr.onerror = callback("error");
-
- callback = xhrCallbacks[ id ] = callback("abort");
- try {
-
- xhr.send( options.hasContent && options.data || null );
- } catch ( e ) {
-
- if ( callback ) {
- throw e;
- }
- }
- },
- abort: function() {
- if ( callback ) {
- callback();
- }
- }
- };
- }
- });
- jQuery.ajaxSetup({
- accepts: {
- script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
- },
- contents: {
- script: /(?:java|ecma)script/
- },
- converters: {
- "text script": function( text ) {
- jQuery.globalEval( text );
- return text;
- }
- }
- });
- jQuery.ajaxPrefilter( "script", function( s ) {
- if ( s.cache === undefined ) {
- s.cache = false;
- }
- if ( s.crossDomain ) {
- s.type = "GET";
- }
- });
- jQuery.ajaxTransport( "script", function( s ) {
-
- if ( s.crossDomain ) {
- var script, callback;
- return {
- send: function( _, complete ) {
- script = jQuery("<script>").prop({
- async: true,
- charset: s.scriptCharset,
- src: s.url
- }).on(
- "load error",
- callback = function( evt ) {
- script.remove();
- callback = null;
- if ( evt ) {
- complete( evt.type === "error" ? 404 : 200, evt.type );
- }
- }
- );
- document.head.appendChild( script[ 0 ] );
- },
- abort: function() {
- if ( callback ) {
- callback();
- }
- }
- };
- }
- });
- var oldCallbacks = [],
- rjsonp = /(=)\?(?=&|$)|\?\?/;
- jQuery.ajaxSetup({
- jsonp: "callback",
- jsonpCallback: function() {
- var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
- this[ callback ] = true;
- return callback;
- }
- });
- jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
- var callbackName, overwritten, responseContainer,
- jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
- "url" :
- typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data"
- );
-
- if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
-
- callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
- s.jsonpCallback() :
- s.jsonpCallback;
-
- if ( jsonProp ) {
- s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
- } else if ( s.jsonp !== false ) {
- s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
- }
-
- s.converters["script json"] = function() {
- if ( !responseContainer ) {
- jQuery.error( callbackName + " was not called" );
- }
- return responseContainer[ 0 ];
- };
-
- s.dataTypes[ 0 ] = "json";
-
- overwritten = window[ callbackName ];
- window[ callbackName ] = function() {
- responseContainer = arguments;
- };
-
- jqXHR.always(function() {
-
- window[ callbackName ] = overwritten;
-
- if ( s[ callbackName ] ) {
-
- s.jsonpCallback = originalSettings.jsonpCallback;
-
- oldCallbacks.push( callbackName );
- }
-
- if ( responseContainer && jQuery.isFunction( overwritten ) ) {
- overwritten( responseContainer[ 0 ] );
- }
- responseContainer = overwritten = undefined;
- });
-
- return "script";
- }
- });
- jQuery.parseHTML = function( data, context, keepScripts ) {
- if ( !data || typeof data !== "string" ) {
- return null;
- }
- if ( typeof context === "boolean" ) {
- keepScripts = context;
- context = false;
- }
- context = context || document;
- var parsed = rsingleTag.exec( data ),
- scripts = !keepScripts && [];
-
- if ( parsed ) {
- return [ context.createElement( parsed[1] ) ];
- }
- parsed = jQuery.buildFragment( [ data ], context, scripts );
- if ( scripts && scripts.length ) {
- jQuery( scripts ).remove();
- }
- return jQuery.merge( [], parsed.childNodes );
- };
- var _load = jQuery.fn.load;
- jQuery.fn.load = function( url, params, callback ) {
- if ( typeof url !== "string" && _load ) {
- return _load.apply( this, arguments );
- }
- var selector, type, response,
- self = this,
- off = url.indexOf(" ");
- if ( off >= 0 ) {
- selector = jQuery.trim( url.slice( off ) );
- url = url.slice( 0, off );
- }
-
- if ( jQuery.isFunction( params ) ) {
-
- callback = params;
- params = undefined;
-
- } else if ( params && typeof params === "object" ) {
- type = "POST";
- }
-
- if ( self.length > 0 ) {
- jQuery.ajax({
- url: url,
-
- type: type,
- dataType: "html",
- data: params
- }).done(function( responseText ) {
-
- response = arguments;
- self.html( selector ?
-
-
- jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
-
- responseText );
- }).complete( callback && function( jqXHR, status ) {
- self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
- });
- }
- return this;
- };
- jQuery.expr.filters.animated = function( elem ) {
- return jQuery.grep(jQuery.timers, function( fn ) {
- return elem === fn.elem;
- }).length;
- };
- var docElem = window.document.documentElement;
- function getWindow( elem ) {
- return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
- }
- jQuery.offset = {
- setOffset: function( elem, options, i ) {
- var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
- position = jQuery.css( elem, "position" ),
- curElem = jQuery( elem ),
- props = {};
-
- if ( position === "static" ) {
- elem.style.position = "relative";
- }
- curOffset = curElem.offset();
- curCSSTop = jQuery.css( elem, "top" );
- curCSSLeft = jQuery.css( elem, "left" );
- calculatePosition = ( position === "absolute" || position === "fixed" ) &&
- ( curCSSTop + curCSSLeft ).indexOf("auto") > -1;
-
- if ( calculatePosition ) {
- curPosition = curElem.position();
- curTop = curPosition.top;
- curLeft = curPosition.left;
- } else {
- curTop = parseFloat( curCSSTop ) || 0;
- curLeft = parseFloat( curCSSLeft ) || 0;
- }
- if ( jQuery.isFunction( options ) ) {
- options = options.call( elem, i, curOffset );
- }
- if ( options.top != null ) {
- props.top = ( options.top - curOffset.top ) + curTop;
- }
- if ( options.left != null ) {
- props.left = ( options.left - curOffset.left ) + curLeft;
- }
- if ( "using" in options ) {
- options.using.call( elem, props );
- } else {
- curElem.css( props );
- }
- }
- };
- jQuery.fn.extend({
- offset: function( options ) {
- if ( arguments.length ) {
- return options === undefined ?
- this :
- this.each(function( i ) {
- jQuery.offset.setOffset( this, options, i );
- });
- }
- var docElem, win,
- elem = this[ 0 ],
- box = { top: 0, left: 0 },
- doc = elem && elem.ownerDocument;
- if ( !doc ) {
- return;
- }
- docElem = doc.documentElement;
-
- if ( !jQuery.contains( docElem, elem ) ) {
- return box;
- }
-
-
- if ( typeof elem.getBoundingClientRect !== strundefined ) {
- box = elem.getBoundingClientRect();
- }
- win = getWindow( doc );
- return {
- top: box.top + win.pageYOffset - docElem.clientTop,
- left: box.left + win.pageXOffset - docElem.clientLeft
- };
- },
- position: function() {
- if ( !this[ 0 ] ) {
- return;
- }
- var offsetParent, offset,
- elem = this[ 0 ],
- parentOffset = { top: 0, left: 0 };
-
- if ( jQuery.css( elem, "position" ) === "fixed" ) {
-
- offset = elem.getBoundingClientRect();
- } else {
-
- offsetParent = this.offsetParent();
-
- offset = this.offset();
- if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
- parentOffset = offsetParent.offset();
- }
-
- parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
- parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
- }
-
- return {
- top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
- left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
- };
- },
- offsetParent: function() {
- return this.map(function() {
- var offsetParent = this.offsetParent || docElem;
- while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
- offsetParent = offsetParent.offsetParent;
- }
- return offsetParent || docElem;
- });
- }
- });
- jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
- var top = "pageYOffset" === prop;
- jQuery.fn[ method ] = function( val ) {
- return access( this, function( elem, method, val ) {
- var win = getWindow( elem );
- if ( val === undefined ) {
- return win ? win[ prop ] : elem[ method ];
- }
- if ( win ) {
- win.scrollTo(
- !top ? val : window.pageXOffset,
- top ? val : window.pageYOffset
- );
- } else {
- elem[ method ] = val;
- }
- }, method, val, arguments.length, null );
- };
- });
- jQuery.each( [ "top", "left" ], function( i, prop ) {
- jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
- function( elem, computed ) {
- if ( computed ) {
- computed = curCSS( elem, prop );
-
- return rnumnonpx.test( computed ) ?
- jQuery( elem ).position()[ prop ] + "px" :
- computed;
- }
- }
- );
- });
- jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
- jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
-
- jQuery.fn[ funcName ] = function( margin, value ) {
- var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
- extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
- return access( this, function( elem, type, value ) {
- var doc;
- if ( jQuery.isWindow( elem ) ) {
-
-
-
- return elem.document.documentElement[ "client" + name ];
- }
-
- if ( elem.nodeType === 9 ) {
- doc = elem.documentElement;
-
-
- return Math.max(
- elem.body[ "scroll" + name ], doc[ "scroll" + name ],
- elem.body[ "offset" + name ], doc[ "offset" + name ],
- doc[ "client" + name ]
- );
- }
- return value === undefined ?
-
- jQuery.css( elem, type, extra ) :
-
- jQuery.style( elem, type, value, extra );
- }, type, chainable ? margin : undefined, chainable, null );
- };
- });
- });
- jQuery.fn.size = function() {
- return this.length;
- };
- jQuery.fn.andSelf = jQuery.fn.addBack;
- if ( typeof define === "function" && define.amd ) {
- define( "jquery", [], function() {
- return jQuery;
- });
- }
- var
-
- _jQuery = window.jQuery,
-
- _$ = window.$;
- jQuery.noConflict = function( deep ) {
- if ( window.$ === jQuery ) {
- window.$ = _$;
- }
- if ( deep && window.jQuery === jQuery ) {
- window.jQuery = _jQuery;
- }
- return jQuery;
- };
- if ( typeof noGlobal === strundefined ) {
- window.jQuery = window.$ = jQuery;
- }
- return jQuery;
- }));
- (function() {
- var define, requireModule, require, requirejs;
- (function() {
- var registry = {}, seen = {};
- define = function(name, deps, callback) {
- registry[name] = { deps: deps, callback: callback };
- };
- requirejs = require = requireModule = function(name) {
- requirejs._eak_seen = registry;
- if (seen[name]) { return seen[name]; }
- seen[name] = {};
- if (!registry[name]) {
- throw new Error("Could not find module " + name);
- }
- var mod = registry[name],
- deps = mod.deps,
- callback = mod.callback,
- reified = [],
- exports;
- for (var i=0, l=deps.length; i<l; i++) {
- if (deps[i] === 'exports') {
- reified.push(exports = {});
- } else {
- reified.push(requireModule(resolve(deps[i])));
- }
- }
- var value = callback.apply(this, reified);
- return seen[name] = exports || value;
- function resolve(child) {
- if (child.charAt(0) !== '.') { return child; }
- var parts = child.split("/");
- var parentBase = name.split("/").slice(0, -1);
- for (var i=0, l=parts.length; i<l; i++) {
- var part = parts[i];
- if (part === '..') { parentBase.pop(); }
- else if (part === '.') { continue; }
- else { parentBase.push(part); }
- }
- return parentBase.join("/");
- }
- };
- })();
- define("promise/all",
- ["./utils","exports"],
- function(__dependency1__, __exports__) {
- "use strict";
-
- var isArray = __dependency1__.isArray;
- var isFunction = __dependency1__.isFunction;
-
- function all(promises) {
-
- var Promise = this;
- if (!isArray(promises)) {
- throw new TypeError('You must pass an array to all.');
- }
- return new Promise(function(resolve, reject) {
- var results = [], remaining = promises.length,
- promise;
- if (remaining === 0) {
- resolve([]);
- }
- function resolver(index) {
- return function(value) {
- resolveAll(index, value);
- };
- }
- function resolveAll(index, value) {
- results[index] = value;
- if (--remaining === 0) {
- resolve(results);
- }
- }
- for (var i = 0; i < promises.length; i++) {
- promise = promises[i];
- if (promise && isFunction(promise.then)) {
- promise.then(resolver(i), reject);
- } else {
- resolveAll(i, promise);
- }
- }
- });
- }
- __exports__.all = all;
- });
- define("promise/asap",
- ["exports"],
- function(__exports__) {
- "use strict";
- var browserGlobal = (typeof window !== 'undefined') ? window : {};
- var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
- var local = (typeof global !== 'undefined') ? global : (this === undefined? window:this);
-
- function useNextTick() {
- return function() {
- process.nextTick(flush);
- };
- }
- function useMutationObserver() {
- var iterations = 0;
- var observer = new BrowserMutationObserver(flush);
- var node = document.createTextNode('');
- observer.observe(node, { characterData: true });
- return function() {
- node.data = (iterations = ++iterations % 2);
- };
- }
- function useSetTimeout() {
- return function() {
- local.setTimeout(flush, 1);
- };
- }
- var queue = [];
- function flush() {
- for (var i = 0; i < queue.length; i++) {
- var tuple = queue[i];
- var callback = tuple[0], arg = tuple[1];
- callback(arg);
- }
- queue = [];
- }
- var scheduleFlush;
-
- if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
- scheduleFlush = useNextTick();
- } else if (BrowserMutationObserver) {
- scheduleFlush = useMutationObserver();
- } else {
- scheduleFlush = useSetTimeout();
- }
- function asap(callback, arg) {
- var length = queue.push([callback, arg]);
- if (length === 1) {
-
-
-
- scheduleFlush();
- }
- }
- __exports__.asap = asap;
- });
- define("promise/config",
- ["exports"],
- function(__exports__) {
- "use strict";
- var config = {
- instrument: false
- };
- function configure(name, value) {
- if (arguments.length === 2) {
- config[name] = value;
- } else {
- return config[name];
- }
- }
- __exports__.config = config;
- __exports__.configure = configure;
- });
- define("promise/polyfill",
- ["./promise","./utils","exports"],
- function(__dependency1__, __dependency2__, __exports__) {
- "use strict";
-
- var RSVPPromise = __dependency1__.Promise;
- var isFunction = __dependency2__.isFunction;
- function polyfill() {
- var local;
- if (typeof global !== 'undefined') {
- local = global;
- } else if (typeof window !== 'undefined' && window.document) {
- local = window;
- } else {
- local = self;
- }
- var es6PromiseSupport =
- "Promise" in local &&
-
-
- "resolve" in local.Promise &&
- "reject" in local.Promise &&
- "all" in local.Promise &&
- "race" in local.Promise &&
-
-
- (function() {
- var resolve;
- new local.Promise(function(r) { resolve = r; });
- return isFunction(resolve);
- }());
-
- if (true) {
- local.Promise = RSVPPromise;
- }
- }
- __exports__.polyfill = polyfill;
- });
- define("promise/promise",
- ["./config","./utils","./all","./race","./resolve","./reject","./asap","exports"],
- function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __dependency7__, __exports__) {
- "use strict";
- var config = __dependency1__.config;
- var configure = __dependency1__.configure;
- var objectOrFunction = __dependency2__.objectOrFunction;
- var isFunction = __dependency2__.isFunction;
- var now = __dependency2__.now;
- var all = __dependency3__.all;
- var race = __dependency4__.race;
- var staticResolve = __dependency5__.resolve;
- var staticReject = __dependency6__.reject;
- var asap = __dependency7__.asap;
- var counter = 0;
- config.async = asap;
- function Promise(resolver) {
- if (!isFunction(resolver)) {
- throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
- }
- if (!(this instanceof Promise)) {
- throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
- }
- this._subscribers = [];
- invokeResolver(resolver, this);
- }
- function invokeResolver(resolver, promise) {
- function resolvePromise(value) {
- resolve(promise, value);
- }
- function rejectPromise(reason) {
- reject(promise, reason);
- }
- try {
- resolver(resolvePromise, rejectPromise);
- } catch(e) {
- rejectPromise(e);
- }
- }
- function invokeCallback(settled, promise, callback, detail) {
- var hasCallback = isFunction(callback),
- value, error, succeeded, failed;
- if (hasCallback) {
- try {
- value = callback(detail);
- succeeded = true;
- } catch(e) {
- failed = true;
- error = e;
- }
- } else {
- value = detail;
- succeeded = true;
- }
- if (handleThenable(promise, value)) {
- return;
- } else if (hasCallback && succeeded) {
- resolve(promise, value);
- } else if (failed) {
- reject(promise, error);
- } else if (settled === FULFILLED) {
- resolve(promise, value);
- } else if (settled === REJECTED) {
- reject(promise, value);
- }
- }
- var PENDING = void 0;
- var SEALED = 0;
- var FULFILLED = 1;
- var REJECTED = 2;
- function subscribe(parent, child, onFulfillment, onRejection) {
- var subscribers = parent._subscribers;
- var length = subscribers.length;
- subscribers[length] = child;
- subscribers[length + FULFILLED] = onFulfillment;
- subscribers[length + REJECTED] = onRejection;
- }
- function publish(promise, settled) {
- var child, callback, subscribers = promise._subscribers, detail = promise._detail;
- for (var i = 0; i < subscribers.length; i += 3) {
- child = subscribers[i];
- callback = subscribers[i + settled];
- invokeCallback(settled, child, callback, detail);
- }
- promise._subscribers = null;
- }
- Promise.prototype = {
- constructor: Promise,
- _state: undefined,
- _detail: undefined,
- _subscribers: undefined,
- then: function(onFulfillment, onRejection) {
- var promise = this;
- var thenPromise = new this.constructor(function() {});
- if (this._state) {
- var callbacks = arguments;
- config.async(function invokePromiseCallback() {
- invokeCallback(promise._state, thenPromise, callbacks[promise._state - 1], promise._detail);
- });
- } else {
- subscribe(this, thenPromise, onFulfillment, onRejection);
- }
- return thenPromise;
- },
- 'catch': function(onRejection) {
- return this.then(null, onRejection);
- }
- };
- Promise.all = all;
- Promise.race = race;
- Promise.resolve = staticResolve;
- Promise.reject = staticReject;
- function handleThenable(promise, value) {
- var then = null,
- resolved;
- try {
- if (promise === value) {
- throw new TypeError("A promises callback cannot return that same promise.");
- }
- if (objectOrFunction(value)) {
- then = value.then;
- if (isFunction(then)) {
- then.call(value, function(val) {
- if (resolved) { return true; }
- resolved = true;
- if (value !== val) {
- resolve(promise, val);
- } else {
- fulfill(promise, val);
- }
- }, function(val) {
- if (resolved) { return true; }
- resolved = true;
- reject(promise, val);
- });
- return true;
- }
- }
- } catch (error) {
- if (resolved) { return true; }
- reject(promise, error);
- return true;
- }
- return false;
- }
- function resolve(promise, value) {
- if (promise === value) {
- fulfill(promise, value);
- } else if (!handleThenable(promise, value)) {
- fulfill(promise, value);
- }
- }
- function fulfill(promise, value) {
- if (promise._state !== PENDING) { return; }
- promise._state = SEALED;
- promise._detail = value;
- config.async(publishFulfillment, promise);
- }
- function reject(promise, reason) {
- if (promise._state !== PENDING) { return; }
- promise._state = SEALED;
- promise._detail = reason;
- config.async(publishRejection, promise);
- }
- function publishFulfillment(promise) {
- publish(promise, promise._state = FULFILLED);
- }
- function publishRejection(promise) {
- publish(promise, promise._state = REJECTED);
- }
- __exports__.Promise = Promise;
- });
- define("promise/race",
- ["./utils","exports"],
- function(__dependency1__, __exports__) {
- "use strict";
-
- var isArray = __dependency1__.isArray;
-
- function race(promises) {
-
- var Promise = this;
- if (!isArray(promises)) {
- throw new TypeError('You must pass an array to race.');
- }
- return new Promise(function(resolve, reject) {
- var results = [], promise;
- for (var i = 0; i < promises.length; i++) {
- promise = promises[i];
- if (promise && typeof promise.then === 'function') {
- promise.then(resolve, reject);
- } else {
- resolve(promise);
- }
- }
- });
- }
- __exports__.race = race;
- });
- define("promise/reject",
- ["exports"],
- function(__exports__) {
- "use strict";
-
- function reject(reason) {
-
- var Promise = this;
- return new Promise(function (resolve, reject) {
- reject(reason);
- });
- }
- __exports__.reject = reject;
- });
- define("promise/resolve",
- ["exports"],
- function(__exports__) {
- "use strict";
- function resolve(value) {
-
- if (value && typeof value === 'object' && value.constructor === this) {
- return value;
- }
- var Promise = this;
- return new Promise(function(resolve) {
- resolve(value);
- });
- }
- __exports__.resolve = resolve;
- });
- define("promise/utils",
- ["exports"],
- function(__exports__) {
- "use strict";
- function objectOrFunction(x) {
- return isFunction(x) || (typeof x === "object" && x !== null);
- }
- function isFunction(x) {
- return typeof x === "function";
- }
- function isArray(x) {
- return Object.prototype.toString.call(x) === "[object Array]";
- }
-
-
- var now = Date.now || function() { return new Date().getTime(); };
- __exports__.objectOrFunction = objectOrFunction;
- __exports__.isFunction = isFunction;
- __exports__.isArray = isArray;
- __exports__.now = now;
- });
- requireModule('promise/polyfill').polyfill();
- }());
- ;if(window.jQuery) (function($){
-
-
- $.extend({
-
-
- xml2json: function(xml, extended) {
- if(!xml) return {};
-
-
-
- function parseXML(node, simple){
- if(!node) return null;
- var txt = '', obj = null, att = null;
- var nt = node.nodeType, nn = jsVar(node.localName || node.nodeName);
- var nv = node.text || node.nodeValue || '';
-
- if(node.childNodes){
- if(node.childNodes.length>0){
-
- $.each(node.childNodes, function(n,cn){
- var cnt = cn.nodeType, cnn = jsVar(cn.localName || cn.nodeName);
- var cnv = cn.text || cn.nodeValue || '';
-
- if(cnt == 8){
-
- return;
- }
- else if(cnt == 3 || cnt == 4 || !cnn){
-
- if(cnv.match(/^\s+$/)){
-
- return;
- };
-
- txt += cnv.replace(/^\s+/,'').replace(/\s+$/,'');
-
- }
- else{
-
- obj = obj || {};
- if(obj[cnn]){
-
-
-
- if(!obj[cnn].length) obj[cnn] = myArr(obj[cnn]);
- obj[cnn] = myArr(obj[cnn]);
-
- obj[cnn][ obj[cnn].length ] = parseXML(cn, true);
- obj[cnn].length = obj[cnn].length;
- }
- else{
-
- obj[cnn] = parseXML(cn);
- };
- };
- });
- };
- };
- if(node.attributes){
- if(node.attributes.length>0){
-
- att = {}; obj = obj || {};
- $.each(node.attributes, function(a,at){
- var atn = jsVar(at.name), atv = at.value;
- att[atn] = atv;
- if(obj[atn]){
-
-
-
-
- obj[cnn] = myArr(obj[cnn]);
-
- obj[atn][ obj[atn].length ] = atv;
- obj[atn].length = obj[atn].length;
- }
- else{
-
- obj[atn] = atv;
- };
- });
-
- };
- };
- if(obj){
- obj = $.extend( (txt!='' ? new String(txt) : {}), obj || {});
-
- txt = (obj.text) ? ([obj.text || '']).concat([txt]) : txt;
- if(txt) obj.text = txt;
- txt = '';
- };
- var out = obj || txt;
-
- if(extended){
- if(txt) out = {};
- txt = out.text || txt || '';
- if(txt) out.text = txt;
- if(!simple) out = myArr(out);
- };
- return out;
- };
-
-
- var jsVar = function(s){ return String(s || '').replace(/-/g,"_"); };
-
-
-
- function isNum(s){
-
-
-
-
-
-
- var regexp=/^((-)?([0-9]+)(([\.\,]{0,1})([0-9]+))?$)/
- return (typeof s == "number") || regexp.test(String((s && typeof s == "string") ? jQuery.trim(s) : ''));
- };
-
-
-
- var myArr = function(o){
-
-
-
- if(!$.isArray(o)) o = [ o ]; o.length=o.length;
-
-
- return o;
- };
-
-
-
-
- if(typeof xml=='string') xml = $.text2xml(xml);
-
-
- if(!xml.nodeType) return;
- if(xml.nodeType == 3 || xml.nodeType == 4) return xml.nodeValue;
-
-
- var root = (xml.nodeType == 9) ? xml.documentElement : xml;
-
-
- var out = parseXML(root, true );
-
-
- xml = null; root = null;
-
-
- return out;
- },
-
-
- text2xml: function(str) {
-
-
-
-
-
-
- return $.parseXML(str);
- }
-
- });
- })(jQuery);
- (function(t,e){if(typeof define==="function"&&define.amd){define(["jquery"],e)}else if(typeof exports==="object"){module.exports=e(require("jquery"))}else{e(t.jQuery)}})(this,function(t){t.transit={version:"0.9.12",propertyMap:{marginLeft:"margin",marginRight:"margin",marginBottom:"margin",marginTop:"margin",paddingLeft:"padding",paddingRight:"padding",paddingBottom:"padding",paddingTop:"padding"},enabled:true,useTransitionEnd:false};var e=document.createElement("div");var n={};function i(t){if(t in e.style)return t;var n=["Moz","Webkit","O","ms"];var i=t.charAt(0).toUpperCase()+t.substr(1);for(var r=0;r<n.length;++r){var s=n[r]+i;if(s in e.style){return s}}}function r(){e.style[n.transform]="";e.style[n.transform]="rotateY(90deg)";return e.style[n.transform]!==""}var s=navigator.userAgent.toLowerCase().indexOf("chrome")>-1;n.transition=i("transition");n.transitionDelay=i("transitionDelay");n.transform=i("transform");n.transformOrigin=i("transformOrigin");n.filter=i("Filter");n.transform3d=r();var a={transition:"transitionend",MozTransition:"transitionend",OTransition:"oTransitionEnd",WebkitTransition:"webkitTransitionEnd",msTransition:"MSTransitionEnd"};var o=n.transitionEnd=a[n.transition]||null;for(var u in n){if(n.hasOwnProperty(u)&&typeof t.support[u]==="undefined"){t.support[u]=n[u]}}e=null;t.cssEase={_default:"ease","in":"ease-in",out:"ease-out","in-out":"ease-in-out",snap:"cubic-bezier(0,1,.5,1)",easeInCubic:"cubic-bezier(.550,.055,.675,.190)",easeOutCubic:"cubic-bezier(.215,.61,.355,1)",easeInOutCubic:"cubic-bezier(.645,.045,.355,1)",easeInCirc:"cubic-bezier(.6,.04,.98,.335)",easeOutCirc:"cubic-bezier(.075,.82,.165,1)",easeInOutCirc:"cubic-bezier(.785,.135,.15,.86)",easeInExpo:"cubic-bezier(.95,.05,.795,.035)",easeOutExpo:"cubic-bezier(.19,1,.22,1)",easeInOutExpo:"cubic-bezier(1,0,0,1)",easeInQuad:"cubic-bezier(.55,.085,.68,.53)",easeOutQuad:"cubic-bezier(.25,.46,.45,.94)",easeInOutQuad:"cubic-bezier(.455,.03,.515,.955)",easeInQuart:"cubic-bezier(.895,.03,.685,.22)",easeOutQuart:"cubic-bezier(.165,.84,.44,1)",easeInOutQuart:"cubic-bezier(.77,0,.175,1)",easeInQuint:"cubic-bezier(.755,.05,.855,.06)",easeOutQuint:"cubic-bezier(.23,1,.32,1)",easeInOutQuint:"cubic-bezier(.86,0,.07,1)",easeInSine:"cubic-bezier(.47,0,.745,.715)",easeOutSine:"cubic-bezier(.39,.575,.565,1)",easeInOutSine:"cubic-bezier(.445,.05,.55,.95)",easeInBack:"cubic-bezier(.6,-.28,.735,.045)",easeOutBack:"cubic-bezier(.175, .885,.32,1.275)",easeInOutBack:"cubic-bezier(.68,-.55,.265,1.55)"};t.cssHooks["transit:transform"]={get:function(e){return t(e).data("transform")||new f},set:function(e,i){var r=i;if(!(r instanceof f)){r=new f(r)}if(n.transform==="WebkitTransform"&&!s){e.style[n.transform]=r.toString(true)}else{e.style[n.transform]=r.toString()}t(e).data("transform",r)}};t.cssHooks.transform={set:t.cssHooks["transit:transform"].set};t.cssHooks.filter={get:function(t){return t.style[n.filter]},set:function(t,e){t.style[n.filter]=e}};if(t.fn.jquery<"1.8"){t.cssHooks.transformOrigin={get:function(t){return t.style[n.transformOrigin]},set:function(t,e){t.style[n.transformOrigin]=e}};t.cssHooks.transition={get:function(t){return t.style[n.transition]},set:function(t,e){t.style[n.transition]=e}}}p("scale");p("scaleX");p("scaleY");p("translate");p("rotate");p("rotateX");p("rotateY");p("rotate3d");p("perspective");p("skewX");p("skewY");p("x",true);p("y",true);function f(t){if(typeof t==="string"){this.parse(t)}return this}f.prototype={setFromString:function(t,e){var n=typeof e==="string"?e.split(","):e.constructor===Array?e:[e];n.unshift(t);f.prototype.set.apply(this,n)},set:function(t){var e=Array.prototype.slice.apply(arguments,[1]);if(this.setter[t]){this.setter[t].apply(this,e)}else{this[t]=e.join(",")}},get:function(t){if(this.getter[t]){return this.getter[t].apply(this)}else{return this[t]||0}},setter:{rotate:function(t){this.rotate=b(t,"deg")},rotateX:function(t){this.rotateX=b(t,"deg")},rotateY:function(t){this.rotateY=b(t,"deg")},scale:function(t,e){if(e===undefined){e=t}this.scale=t+","+e},skewX:function(t){this.skewX=b(t,"deg")},skewY:function(t){this.skewY=b(t,"deg")},perspective:function(t){this.perspective=b(t,"px")},x:function(t){this.set("translate",t,null)},y:function(t){this.set("translate",null,t)},translate:function(t,e){if(this._translateX===undefined){this._translateX=0}if(this._translateY===undefined){this._translateY=0}if(t!==null&&t!==undefined){this._translateX=b(t,"px")}if(e!==null&&e!==undefined){this._translateY=b(e,"px")}this.translate=this._translateX+","+this._translateY}},getter:{x:function(){return this._translateX||0},y:function(){return this._translateY||0},scale:function(){var t=(this.scale||"1,1").split(",");if(t[0]){t[0]=parseFloat(t[0])}if(t[1]){t[1]=parseFloat(t[1])}return t[0]===t[1]?t[0]:t},rotate3d:function(){var t=(this.rotate3d||"0,0,0,0deg").split(",");for(var e=0;e<=3;++e){if(t[e]){t[e]=parseFloat(t[e])}}if(t[3]){t[3]=b(t[3],"deg")}return t}},parse:function(t){var e=this;t.replace(/([a-zA-Z0-9]+)\((.*?)\)/g,function(t,n,i){e.setFromString(n,i)})},toString:function(t){var e=[];for(var i in this){if(this.hasOwnProperty(i)){if(!n.transform3d&&(i==="rotateX"||i==="rotateY"||i==="perspective"||i==="transformOrigin")){continue}if(i[0]!=="_"){if(t&&i==="scale"){e.push(i+"3d("+this[i]+",1)")}else if(t&&i==="translate"){e.push(i+"3d("+this[i]+",0)")}else{e.push(i+"("+this[i]+")")}}}}return e.join(" ")}};function c(t,e,n){if(e===true){t.queue(n)}else if(e){t.queue(e,n)}else{t.each(function(){n.call(this)})}}function l(e){var i=[];t.each(e,function(e){e=t.camelCase(e);e=t.transit.propertyMap[e]||t.cssProps[e]||e;e=h(e);if(n[e])e=h(n[e]);if(t.inArray(e,i)===-1){i.push(e)}});return i}function d(e,n,i,r){var s=l(e);if(t.cssEase[i]){i=t.cssEase[i]}var a=""+y(n)+" "+i;if(parseInt(r,10)>0){a+=" "+y(r)}var o=[];t.each(s,function(t,e){o.push(e+" "+a)});return o.join(", ")}t.fn.transition=t.fn.transit=function(e,i,r,s){var a=this;var u=0;var f=true;var l=t.extend(true,{},e);if(typeof i==="function"){s=i;i=undefined}if(typeof i==="object"){r=i.easing;u=i.delay||0;f=typeof i.queue==="undefined"?true:i.queue;s=i.complete;i=i.duration}if(typeof r==="function"){s=r;r=undefined}if(typeof l.easing!=="undefined"){r=l.easing;delete l.easing}if(typeof l.duration!=="undefined"){i=l.duration;delete l.duration}if(typeof l.complete!=="undefined"){s=l.complete;delete l.complete}if(typeof l.queue!=="undefined"){f=l.queue;delete l.queue}if(typeof l.delay!=="undefined"){u=l.delay;delete l.delay}if(typeof i==="undefined"){i=t.fx.speeds._default}if(typeof r==="undefined"){r=t.cssEase._default}i=y(i);var p=d(l,i,r,u);var h=t.transit.enabled&&n.transition;var b=h?parseInt(i,10)+parseInt(u,10):0;if(b===0){var g=function(t){a.css(l);if(s){s.apply(a)}if(t){t()}};c(a,f,g);return a}var m={};var v=function(e){var i=false;var r=function(){if(i){a.unbind(o,r)}if(b>0){a.each(function(){this.style[n.transition]=m[this]||null})}if(typeof s==="function"){s.apply(a)}if(typeof e==="function"){e()}};if(b>0&&o&&t.transit.useTransitionEnd){i=true;a.bind(o,r)}else{window.setTimeout(r,b)}a.each(function(){if(b>0){this.style[n.transition]=p}t(this).css(l)})};var z=function(t){this.offsetWidth;v(t)};c(a,f,z);return this};function p(e,i){if(!i){t.cssNumber[e]=true}t.transit.propertyMap[e]=n.transform;t.cssHooks[e]={get:function(n){var i=t(n).css("transit:transform");return i.get(e)},set:function(n,i){var r=t(n).css("transit:transform");r.setFromString(e,i);t(n).css({"transit:transform":r})}}}function h(t){return t.replace(/([A-Z])/g,function(t){return"-"+t.toLowerCase()})}function b(t,e){if(typeof t==="string"&&!t.match(/^[\-0-9\.]+$/)){return t}else{return""+t+e}}function y(e){var n=e;if(typeof n==="string"&&!n.match(/^[\-0-9\.]+/)){n=t.fx.speeds[n]||t.fx.speeds._default}return b(n,"ms")}t.transit.getTransitionValue=d;return t});
- var jhtmls="undefined"==typeof exports?jhtmls||{}:exports;void function(e){"use strict";function n(e){return String(e).replace(/["<>& ]/g,function(e){return"&"+u[e]+";"})}function t(e){var n=[];return n.push("with(this){"),n.push(e.replace(/<(script|style)[^>]*>[\s\S]*?<\/\1>/g,function(e){return['!#{unescape("',escape(e),'")}'].join("")}).replace(/[\r\n]+/g,"\n").replace(/^\n+|\s+$/gm,"").replace(/^([ \w\t_$]*([^&\^?|\n\w\/'"{}\[\]+\-():; \t=\.$_]|:\/\/).*$|^(?!\s*(else|do|try|finally|void|typeof\s[\w$_]*)\s*$)[^'":;{}()\n|=&\/^?]+$)\s?/gm,function(e){return e=e.replace(/&none;/g,"").replace(/["'\\]/g,"\\$&").replace(/\n/g,"\\n").replace(/(!?#)\{(.*?)\}|(!?\$)([a-z_]+\w*(?:\.[a-z_]+\w*)*)/g,function(e,n,t,r,u){if(r&&(n=r,t=u),!t)return"";t=t.replace(/\\n/g,"\n").replace(/\\([\\'"])/g,"$1");var o=/^[a-z$][\w+$]+$/i.test(t)&&!/^(true|false|NaN|null|this)$/.test(t);return["',",o?["typeof ",t,"==='undefined'?'':"].join(""):"","#"===n||"$"===n?"_encode_":"","(",t,"),'"].join("")}),e=["'",e,"'"].join("").replace(/^'',|,''$/g,""),e?["_output_.push(",e,");"].join(""):""})),n.push("}"),new Function("_output_","_encode_","helper","jhtmls",n.join(""))}function r(r,u,o){"function"==typeof r&&(r=String(r).replace(/^[^\{]*\{\s*\/\*!?[ \f\t\v]*\n?|[ \f\t\v]*\*\/[;|\s]*\}$/g,""));var i=t(r),s=function(t,r){r=r||e;var u=[];return i.call(t,u,n,r,e),u.join("")};return arguments.length<=1?s:s(u,o)}var u={'"':"quot","<":"lt",">":"gt","&":"amp"," ":"nbsp"};e.render=r}(jhtmls);
- (function () {
- var _p = {
- r: function(index) {
- if (_p[index].inited) {
- return _p[index].value;
- }
- if (typeof _p[index].value === "function") {
- var module = {
- exports: {}
- }, returnValue = _p[index].value(null, module.exports, module);
- _p[index].inited = true;
- _p[index].value = returnValue;
- if (returnValue !== undefined) {
- return returnValue;
- } else {
- for (var key in module.exports) {
- if (module.exports.hasOwnProperty(key)) {
- _p[index].inited = true;
- _p[index].value = module.exports;
- return module.exports;
- }
- }
- }
- } else {
- _p[index].inited = true;
- return _p[index].value;
- }
- }
- };
- _p[0] = {
- value: function(require) {
- var Creator = {}, $ = _p.r(4), FUI_NS = _p.r(11);
- $.extend(Creator, {
- parse: function(options) {
- var pool = [];
- if ($.isArray(options)) {
- $.each(options, function(i, opt) {
- pool.push(getInstance(opt));
- });
- return pool;
- } else {
- return getInstance(options);
- }
- }
- });
- function getInstance(option) {
- var Constructor = FUI_NS[option.clazz];
- if (!Constructor) {
- return null;
- }
- return new Constructor(option);
- }
- return Creator;
- }
- };
- _p[1] = {
- value: function(require) {
- var FUI_NS = _p.r(11);
-
- FUI_NS.___register({
- ALLOW_FOCUS: true
- });
- FUI_NS.___register({
- Widget: _p.r(60),
- Icon: _p.r(42),
- Label: _p.r(48),
- Button: _p.r(37),
- ToggleButton: _p.r(59),
- Buttonset: _p.r(36),
- Separator: _p.r(56),
- Item: _p.r(46),
- Input: _p.r(45),
- InputButton: _p.r(43),
- Mask: _p.r(49),
- ColorPicker: _p.r(38),
- Tabs: _p.r(58),
- SpinButton: _p.r(57),
- Container: _p.r(39),
- Panel: _p.r(51),
- PPanel: _p.r(54),
- LabelPanel: _p.r(47),
- Menu: _p.r(50),
- InputMenu: _p.r(44),
- ButtonMenu: _p.r(34),
- DropPanel: _p.r(41),
- Popup: _p.r(53),
- PopupMenu: _p.r(52),
- SelectMenu: _p.r(55),
- Dialog: _p.r(40),
- Utils: _p.r(13),
- Creator: _p.r(0)
- });
- FUI_NS.__export();
- }
- };
- _p[2] = {
- value: function(require) {
- var FUI_NS = _p.r(11);
- FUI_NS.___register({
- TablePicker: _p.r(17)
- });
- }
- };
- _p[3] = {
- value: function() {
-
- return jhtmls;
- }
- };
- _p[4] = {
- value: function(require) {
- return window.jQuery;
- }
- };
- _p[5] = {
- value: function(require, exports) {
-
- Function.prototype.bind = Function.prototype.bind || function(thisObj) {
- var args = Array.prototype.slice.call(arguments, 1);
- return this.apply(thisObj, args);
- };
-
- function Class() {}
- Class.__KityClassName = "Class";
-
- Class.prototype.base = function(name) {
- var caller = arguments.callee.caller;
- var method = caller.__KityMethodClass.__KityBaseClass.prototype[name];
- return method.apply(this, Array.prototype.slice.call(arguments, 1));
- };
-
- Class.prototype.callBase = function() {
- var caller = arguments.callee.caller;
- var method = caller.__KityMethodClass.__KityBaseClass.prototype[caller.__KityMethodName];
- return method.apply(this, arguments);
- };
- Class.prototype.mixin = function(name) {
- var caller = arguments.callee.caller;
- var mixins = caller.__KityMethodClass.__KityMixins;
- if (!mixins) {
- return this;
- }
- var method = mixins[name];
- return method.apply(this, Array.prototype.slice.call(arguments, 1));
- };
- Class.prototype.callMixin = function() {
- var caller = arguments.callee.caller;
- var methodName = caller.__KityMethodName;
- var mixins = caller.__KityMethodClass.__KityMixins;
- if (!mixins) {
- return this;
- }
- var method = mixins[methodName];
- if (methodName == "constructor") {
- for (var i = 0, l = method.length; i < l; i++) {
- method[i].call(this);
- }
- return this;
- } else {
- return method.apply(this, arguments);
- }
- };
- Class.prototype.pipe = function(fn) {
- if (typeof fn == "function") {
- fn.call(this, this);
- }
- return this;
- };
- Class.prototype.getType = function() {
- return this.__KityClassName;
- };
- Class.prototype.getClass = function() {
- return this.constructor;
- };
-
-
- function checkBaseConstructorCall(targetClass, classname) {
- var code = targetClass.toString();
- if (!/this\.callBase/.test(code)) {
- throw new Error(classname + " : 类构造函数没有调用父类的构造函数!为了安全,请调用父类的构造函数");
- }
- }
- var KITY_INHERIT_FLAG = "__KITY_INHERIT_FLAG_" + +new Date();
- function inherit(constructor, BaseClass, classname) {
- var KityClass = eval("(function " + classname + "( __inherit__flag ) {" + "if( __inherit__flag != KITY_INHERIT_FLAG ) {" + "KityClass.__KityConstructor.apply(this, arguments);" + "}" + "this.__KityClassName = KityClass.__KityClassName;" + "})||0");
- KityClass.__KityConstructor = constructor;
- KityClass.prototype = new BaseClass(KITY_INHERIT_FLAG);
- for (var methodName in BaseClass.prototype) {
- if (BaseClass.prototype.hasOwnProperty(methodName) && methodName.indexOf("__Kity") !== 0) {
- KityClass.prototype[methodName] = BaseClass.prototype[methodName];
- }
- }
- KityClass.prototype.constructor = KityClass;
- return KityClass;
- }
- function mixin(NewClass, mixins) {
- if (false === mixins instanceof Array) {
- return NewClass;
- }
- var i, length = mixins.length, proto, method;
- NewClass.__KityMixins = {
- constructor: []
- };
- for (i = 0; i < length; i++) {
- proto = mixins[i].prototype;
- for (method in proto) {
- if (false === proto.hasOwnProperty(method) || method.indexOf("__Kity") === 0) {
- continue;
- }
- if (method === "constructor") {
-
- NewClass.__KityMixins.constructor.push(proto[method]);
- } else {
- NewClass.prototype[method] = NewClass.__KityMixins[method] = proto[method];
- }
- }
- }
- return NewClass;
- }
- function extend(BaseClass, extension) {
- if (extension.__KityClassName) {
- extension = extension.prototype;
- }
- for (var methodName in extension) {
- if (extension.hasOwnProperty(methodName) && methodName.indexOf("__Kity") && methodName != "constructor") {
- var method = BaseClass.prototype[methodName] = extension[methodName];
- method.__KityMethodClass = BaseClass;
- method.__KityMethodName = methodName;
- }
- }
- return BaseClass;
- }
- Class.prototype._accessProperty = function() {
- return this._propertyRawData || (this._propertyRawData = {});
- };
- exports.createClass = function(classname, defines) {
- var constructor, NewClass, BaseClass;
- if (arguments.length === 1) {
- defines = arguments[0];
- classname = "AnonymousClass";
- }
- BaseClass = defines.base || Class;
- if (defines.hasOwnProperty("constructor")) {
- constructor = defines.constructor;
- if (BaseClass != Class) {
- checkBaseConstructorCall(constructor, classname);
- }
- } else {
- constructor = function() {
- this.callBase.apply(this, arguments);
- this.callMixin.apply(this, arguments);
- };
- }
- NewClass = inherit(constructor, BaseClass, classname);
- NewClass = mixin(NewClass, defines.mixins);
- NewClass.__KityClassName = constructor.__KityClassName = classname;
- NewClass.__KityBaseClass = constructor.__KityBaseClass = BaseClass;
- NewClass.__KityMethodName = constructor.__KityMethodName = "constructor";
- NewClass.__KityMethodClass = constructor.__KityMethodClass = NewClass;
- // 下面这些不需要拷贝到原型链上
- delete defines.mixins;
- delete defines.constructor;
- delete defines.base;
- NewClass = extend(NewClass, defines);
- return NewClass;
- };
- exports.extendClass = extend;
- }
- };
- //src/base/kit/common.js
- /**
- * 通用工具包
- */
- _p[6] = {
- value: function(require) {
- var $ = _p.r(4), __marker = "__fui__marker__" + +new Date();
- return {
- isElement: function(target) {
- return target.nodeType === 1;
- },
- getMarker: function() {
- return __marker;
- },
- getRect: function(node) {
- var rect = node.getBoundingClientRect();
- return {
- width: rect.width,
- height: rect.height,
- top: rect.top,
- bottom: rect.bottom,
- left: rect.left,
- right: rect.right
- };
- },
- getBound: function(node) {
- var w = 0, h = 0;
- if (node.tagName.toLowerCase() === "body") {
- h = $(this.getView(node));
- w = h.width();
- h = h.height();
- return {
- top: 0,
- left: 0,
- bottom: h,
- right: w,
- width: w,
- height: h
- };
- } else {
- return this.getRect(node);
- }
- },
- getView: function(node) {
- return node.ownerDocument.defaultView || node.ownerDocument.parentWindow;
- }
- };
- }
- };
- _p[7] = {
- value: function(require) {
- var jhtmls = _p.r(3), $ = _p.r(4);
- var Helper = {
- forEach: function(arras, cb) {
- $.each(arras, function(i, item) {
- cb.call(null, i, item);
- });
- }
- };
- return {
- compile: function(tpl, data) {
- tpl = $.trim(tpl);
- if (tpl.length === 0) {
- return "";
- }
- return jhtmls.render(tpl, data, Helper);
- }
- };
- }
- };
- _p[8] = {
- value: function(require, exports) {
- var $ = _p.r(4), common = _p.r(6), DEFAULT_OPTIONS = {
- handler: null,
- target: null,
- axis: "all",
- range: null
- };
- function Draggable(options) {
- this.__options = $.extend({}, DEFAULT_OPTIONS, options);
- this.__started = false;
- this.__point = {
- x: 0,
- y: 0
- };
- this.__location = {
- x: 0,
- y: 0
- };
- this.__range = {
- top: 0,
- left: 0,
- bottom: 0,
- right: 0
- };
- }
- $.extend(Draggable.prototype, {
- bind: function(target) {
- if (target) {
- this.__options.target = target;
- }
- if (!this.__options.target) {
- throw new Error("target unset");
- }
- this.__target = this.__options.target;
- this.__handler = this.__options.handler;
- this.__rangeNode = this.__options.range;
- this.__initOptions();
- this.__initEnv();
- this.__initEvent();
- },
- __initEvent: function() {
- var handler = this.__handler, _self = this;
- $(handler).on("mousedown", function(e) {
- if (e.which !== 1) {
- return;
- }
- var location = common.getRect(handler);
- e.preventDefault();
- _self.__started = true;
- _self.__point = {
- x: e.clientX,
- y: e.clientY
- };
- _self.__location = {
- x: location.left,
- y: location.top
- };
- _self.__range = _self.__getRange();
- });
- $(handler.ownerDocument).on("mousemove", function(e) {
- if (!_self.__started) {
- return;
- }
- var x = e.clientX, y = e.clientY;
- if (_self.__allowAxisX) {
- _self.__xMove(x);
- }
- if (_self.__allowAxisY) {
- _self.__yMove(y);
- }
- }).on("mouseup", function(e) {
- _self.__started = false;
- });
- },
- __xMove: function(x) {
- var diff = x - this.__point.x;
- diff = this.__location.x + diff;
- if (diff < this.__range.left) {
- diff = this.__range.left;
- } else if (diff > this.__range.right) {
- diff = this.__range.right;
- }
- this.__target.style.left = diff + "px";
- },
- __yMove: function(y) {
- var diff = y - this.__point.y;
- diff = this.__location.y + diff;
- if (diff < this.__range.top) {
- diff = this.__range.top;
- } else if (diff > this.__range.bottom) {
- diff = this.__range.bottom;
- }
- this.__target.style.top = diff + "px";
- },
- __initEnv: function() {
- var $handler = $(this.__handler);
- $handler.css("cursor", "move");
- },
- __initOptions: function() {
- if (!this.__handler) {
- this.__handler = this.__target;
- }
- if (!this.__rangeNode) {
- this.__rangeNode = this.__options.target.ownerDocument.body;
- }
- this.__allowAxisX = this.__options.axis !== "y";
- this.__allowAxisY = this.__options.axis !== "x";
- },
- __getRange: function() {
- var range = this.__rangeNode, targetRect = common.getRect(this.__target);
- if (range.tagName.toLowerCase() === "body") {
- range = $(this.__rangeNode.ownerDocument);
- range = {
- top: 0,
- left: 0,
- bottom: range.height(),
- right: range.width()
- };
- } else {
- range = common.getRect(range);
- }
- return {
- top: range.top,
- left: range.left,
- bottom: range.bottom - targetRect.height,
- right: range.right - targetRect.width
- };
- }
- });
- return function(options) {
- return new Draggable(options);
- };
- }
- };
- _p[9] = {
- value: function(require) {
- var $ = _p.r(4);
- function extend(target) {
- var isPlainObject = false, isArray = false, sourceObj = null;
- if (arguments.length === 1) {
- return copy(target);
- }
- $.each([].slice.call(arguments, 1), function(i, source) {
- for (var key in source) {
- sourceObj = source[key];
- if (!source.hasOwnProperty(key)) {
- continue;
- }
- isPlainObject = $.isPlainObject(sourceObj);
- isArray = $.isArray(sourceObj);
- if (!isPlainObject && !isArray) {
- target[key] = source[key];
- } else if (isPlainObject) {
- if (!$.isPlainObject(target[key])) {
- target[key] = {};
- }
- target[key] = extend(target[key], sourceObj);
- } else if (isArray) {
- target[key] = extend(sourceObj);
- }
- }
- });
- return target;
- }
- function copy(target) {
- var tmp = null;
- if ($.isPlainObject(target)) {
- return extend({}, target);
- } else if ($.isArray(target)) {
- tmp = [];
- $.each(target, function(index, item) {
- if ($.isPlainObject(item) || $.isArray(item)) {
- tmp.push(copy(item));
- } else {
- tmp.push(item);
- }
- });
- return tmp;
- } else {
- return target;
- }
- }
- return extend;
- }
- };
- _p[10] = {
- value: function(require) {
- return {
- isContainer: function(widget) {
- return widget.__widgetType === "container";
- }
- };
- }
- };
- _p[11] = {
- value: function() {
-
- var WIDGET_POOL = {};
- return {
- widgets: WIDGET_POOL,
-
- __export: function() {
- window.FUI = this;
- },
- ___register: function(widgetName, widget) {
- if (typeof widgetName === "string") {
- this[widgetName] = widget;
- } else {
- widget = widgetName;
- for (var key in widget) {
- if (widget.hasOwnProperty(key)) {
- this[key] = widget[key];
- }
- }
- }
- },
- __registerInstance: function(widget) {
- WIDGET_POOL[widget.getId()] = widget;
- }
- };
- }
- };
- _p[12] = {
- value: function(require) {
- var NS = _p.r(11);
- return {
- classPrefix: "fui-",
- layout: {
- TOP: "top",
- LEFT: "left",
- BOTTOM: "bottom",
- RIGHT: "right",
- CENTER: "center",
- MIDDLE: "middle",
-
- LEFT_TOP: "left-top",
- RIGHT_TOP: "right-top",
- LEFT_BOTTOM: "left-bottom",
- RIGHT_BOTTOM: "right-bottom"
- },
- allowFocus: !!NS.ALLOW_FOCUS,
- control: {
- input: 1,
- textarea: 1,
- button: 1,
- select: 1,
- option: 1,
- object: 1,
- embed: 1
- }
- };
- }
- };
- _p[13] = {
- value: function(require) {
- var $ = _p.r(4), Utils = {
- Tpl: _p.r(7),
- Widget: _p.r(10),
- createDraggable: _p.r(8)
- };
- return $.extend(Utils, _p.r(6), _p.r(5));
- }
- };
- _p[14] = {
- value: function() {
- return '<div unselectable="on" class="fui-t-picker"></div>\n';
- }
- };
- _p[15] = {
- value: function() {
- return '<div unselectable="on" class="fui-table-picker"></div>\n';
- }
- };
- _p[16] = {
- value: function(require) {
- var $ = _p.r(4), CONF = _p.r(12), tpl = _p.r(14);
- return _p.r(13).createClass("TPicker", {
- base: _p.r(60),
- constructor: function(options) {
- var defaultOptions = {
-
- row: 10,
- col: 10
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "TPicker";
- this.__tpl = tpl;
-
- this.__backplane = null;
- },
- __render: function() {
- this.callBase();
- this.__backplane = this.__createBackplane();
- this.__element.appendChild(this.__backplane);
- },
- __initEvent: function() {
- var _self = this;
- var info = {};
- this.callBase();
- $(this.__backplane).delegate("td", "mousemove", function(e) {
- info = e.target.getAttribute("data-index").split(",");
- info = {
- row: parseInt(info[0], 10),
- col: parseInt(info[1], 10)
- };
- _self.__update(info.row, info.col);
- });
- $(this.__backplane).on("click", function(e) {
- _self.__select(info.row, info.col);
- });
- },
- __select: function(row, col) {
- this.trigger("pickerselect", {
- row: row,
- col: col
- });
- },
- __update: function(row, col) {
- var tr = null, rowCount = this.__options.row, colCount = this.__options.col, className = CONF.classPrefix + "table-picker-hoverin";
- for (var i = 0; i < rowCount; i++) {
- tr = this.__backplane.rows[i];
- for (var j = 0; j < colCount; j++) {
- if (i <= row && j <= col) {
- tr.cells[j].className = className;
- } else {
- tr.cells[j].className = "";
- }
- }
- }
- this.trigger("pickerhover", {
- row: row,
- col: col
- });
- },
- __createBackplane: function() {
- var tpl = [], tmp = null;
- for (var i = 0, len = this.__options.row; i < len; i++) {
- tmp = [];
- for (var j = 0, jlen = this.__options.col; j < jlen; j++) {
- tmp.push('<td data-index="' + i + "," + j + '"></td>');
- }
- tpl.push("<tr>" + tmp.join("") + "</tr>");
- }
- tpl = $("<table><tbody>" + tpl.join("") + "</tbody></table>");
- tpl.addClass(CONF.classPrefix + "t-picker-table");
- return tpl[0];
- }
- });
- }
- };
- _p[17] = {
- value: function(require) {
- var $ = _p.r(4), CONF = _p.r(12), tpl = _p.r(15), Label = _p.r(48), TPicker = _p.r(16), Button = _p.r(37), PPanel = _p.r(54), Mask = _p.r(49);
- return _p.r(13).createClass("TablePicker", {
- base: _p.r(60),
- constructor: function(options) {
- var defaultOptions = {
- button: null,
- row: 10,
- col: 10
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- open: function() {
- this.__panelWidget.show();
- this.__maskWidget.show();
- },
- close: function() {
- this.__panelWidget.hide();
- this.__maskWidget.hide();
- },
-
- appendTo: function(container) {
- container.appendChild(this.__buttonWidget.getElement());
- },
- getButton: function() {
- return this.__buttonWidget;
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "TablePicker";
- this.__tpl = tpl;
- this.__pickerWidget = null;
- this.__labelWidget = null;
- this.__buttonWidget = null;
- this.__panelWidget = null;
- this.__maskWidget = null;
- },
- __render: function() {
- this.callBase();
- this.__pickerWidget = new TPicker(this.__options);
- this.__labelWidget = new Label({
- text: "插入表格"
- });
- this.__buttonWidget = new Button(this.__options.button);
- this.__panelWidget = new PPanel({
- className: CONF.classPrefix + "table-picker-panel",
- column: true,
- resize: "none"
- });
- this.__maskWidget = new Mask();
- this.__panelWidget.appendWidget(this.__labelWidget);
- this.__panelWidget.appendWidget(this.__pickerWidget);
- this.__panelWidget.positionTo(this.__buttonWidget);
- },
- __initEvent: function() {
- var _self = this;
- this.callBase();
- this.__buttonWidget.on("btnclick", function(e) {
- _self.open();
- });
- this.__maskWidget.on("maskclick", function(e) {
- _self.close();
- });
- this.__pickerWidget.on("pickerhover", function(e, info) {
- var row = info.row + 1, col = info.col + 1;
- _self.__labelWidget.setText(row + "x" + col + " 表格");
- }).on("pickerselect", function(e, info) {
- var row = info.row + 1, col = info.col + 1;
- _self.close();
- _self.trigger("pickerselect", {
- row: row,
- col: col
- });
- });
- },
- __createBackplane: function() {
- var tpl = [], tmp = null;
- for (var i = 0, len = this.__options.row; i < len; i++) {
- tmp = [];
- for (var j = 0, jlen = this.__options.col; j < jlen; j++) {
- tmp.push('<td data-index="' + i + "," + j + '"></td>');
- }
- tpl.push("<tr>" + tmp.join("") + "</tr>");
- }
- tpl = $("<table><tbody>" + tpl.join("") + "</tbody></table>");
- tpl.addClass(CONF.classPrefix + "t-picker-table");
- return tpl[0];
- }
- });
- }
- };
- _p[18] = {
- value: function() {
- return '<div unselectable="on" class="fui-button-menu"></div>\n';
- }
- };
- _p[19] = {
- value: function() {
- return '<div unselectable="on" class="fui-button"></div>\n';
- }
- };
- _p[20] = {
- value: function() {
- return '<div unselectable="on" class="fui-colorpicker-container">\n' + '<div unselectable="on" class="fui-colorpicker-toolbar">\n' + '<div unselectable="on" class="fui-colorpicker-preview"></div>\n' + '<div unselectable="on" class="fui-colorpicker-clear">$clearText</div>\n' + "</div>\n" + '<div unselectable="on" class="fui-colorpicker-title">$commonText</div>\n' + '<div unselectable="on" class="fui-colorpicker-commoncolor">\n' + "helper.forEach( commonColor, function ( index, colors ) {\n" + '<div unselectable="on" class="fui-colorpicker-colors fui-colorpicker-colors-line$index">\n' + "helper.forEach( colors, function( i, color ) {\n" + '<span unselectable="on" class="fui-colorpicker-item" style="background-color: $color; border-color: #{color.toLowerCase() == \'#ffffff\' ? \'#eeeeee\': color};" data-color="$color"></span>\n' + "});\n" + "</div>\n" + "} );\n" + "</div>\n" + '<div unselectable="on" class="fui-colorpicker-title">$standardText</div>\n' + '<div unselectable="on" class="fui-colorpicker-standardcolor fui-colorpicker-colors">\n' + "helper.forEach( standardColor, function ( i, color ) {\n" + '<span unselectable="on" class="fui-colorpicker-item" style="background-color: $color; border-color: $color;" data-color="$color"></span>\n' + "} );\n" + "</div>\n" + "</div>\n";
- }
- };
- _p[21] = {
- value: function() {
- return '<div unselectable="on" class="fui-dialog-wrap">\n' + '<div unselectable="on" class="fui-dialog-head">\n' + '<h1 unselectable="on" class="fui-dialog-caption">$caption</h1>\n' + "</div>\n" + '<div unselectable="on" class="fui-dialog-body"></div>\n' + '<div unselectable="on" class="fui-dialog-foot"></div>\n' + "</div>\n";
- }
- };
- _p[22] = {
- value: function() {
- return "<div unselectable=\"on\" class=\"fui-drop-panel\" #{ text ? 'title=\"' + m.text + '\"' : '' }></div>\n";
- }
- };
- _p[23] = {
- value: function() {
- return '<div unselectable="on" class="fui-icon" >\n' + "if ( this.img ) {\n" + '<img unselectable="on" src="#{this.img}" >\n' + "}\n" + "</div>\n";
- }
- };
- _p[24] = {
- value: function() {
- return '<div unselectable="on" class="fui-input-button"></div>\n';
- }
- };
- _p[25] = {
- value: function() {
- return '<div unselectable="on" class="fui-input-menu"></div>\n';
- }
- };
- _p[26] = {
- value: function() {
- return '<input unselectable="on" class="fui-input" autocomplete="off" !#{ value ? \'value="\' + value + \'"\' : \'\'}>\n';
- }
- };
- _p[27] = {
- value: function() {
- return "<div unselectable=\"on\" class=\"fui-item!#{ selected ? ' fui-item-selected': '' }\" ></div>\n";
- }
- };
- _p[28] = {
- value: function() {
- return '<div unselectable="on" class="fui-label">$text</div>\n';
- }
- };
- _p[29] = {
- value: function() {
- return '<div unselectable="on" class="fui-mask" style="background-color: $bgcolor; opacity: $opacity;"></div>\n';
- }
- };
- _p[30] = {
- value: function() {
- return '<div unselectable="on" class="fui-panel"></div>\n';
- }
- };
- _p[31] = {
- value: function() {
- return '<div unselectable="on" class="fui-separator"></div>\n';
- }
- };
- _p[32] = {
- value: function() {
- return '<div unselectable="on" class="fui-spin-button"></div>\n';
- }
- };
- _p[33] = {
- value: function() {
- return '<div unselectable="on" class="fui-tabs">\n' + '<div unselectable="on" class="fui-tabs-button-wrap"></div>\n' + '<div unselectable="on" class="fui-tabs-panel-wrap"></div>\n' + "</div>\n";
- }
- };
- _p[34] = {
- value: function(require) {
- var $ = _p.r(4), CONF = _p.r(12), tpl = _p.r(18), Button = _p.r(37), Menu = _p.r(50), Mask = _p.r(49), LAYOUT = CONF.layout;
- return _p.r(13).createClass("ButtonMenu", {
- base: _p.r(60),
- constructor: function(options) {
- var defaultOptions = {
-
- menu: null,
- mask: null,
- buttons: [],
- selected: -1,
- layout: LAYOUT.RIGHT
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- open: function() {
- this.__openState = true;
- this.__maskWidget.show();
- this.__menuWidget.show();
- this.addClass(CONF.classPrefix + "button-active");
- },
- close: function() {
- this.__openState = false;
- this.__maskWidget.hide();
- this.__menuWidget.hide();
- this.removeClass(CONF.classPrefix + "button-active");
- },
- isOpen: function() {
- return !!this.__openState;
- },
- getSelected: function() {
- return this.__menuWidget.getSelected();
- },
- getSelectedItem: function() {
- return this.__menuWidget.getSelectedItem();
- },
- getValue: function() {
- return this.getSelectedItem().getValue();
- },
- __render: function() {
- this.callBase();
- this.__initButtons();
- this.__menuWidget = new Menu(this.__options.menu);
- this.__maskWidget = new Mask(this.__options.mask);
- this.__menuWidget.positionTo(this.__element);
- this.__menuWidget.appendTo(this.__element.ownerDocument.body);
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "ButtonMenu";
- this.__tpl = tpl;
- this.__buttonWidgets = null;
- this.__menuWidget = null;
- this.__maskWidget = null;
- this.__openState = false;
- if (this.__options.selected !== -1) {
- this.__options.menu.selected = this.__options.selected;
- }
- },
- __initButtons: function() {
- var buttons = [], ele = this.__element, btn = null, lastIndex = this.__options.buttons.length - 1;
- if (this.__options.layout === LAYOUT.TOP || this.__options.layout === LAYOUT.LEFT) {
- btn = new Button(this.__options.buttons[lastIndex]);
- btn.appendTo(ele);
- } else {
- lastIndex = -1;
- }
- $.each(this.__options.buttons, function(index, options) {
- if (lastIndex !== index) {
- var button = new Button(options);
- button.appendTo(ele);
- buttons.push(button);
- } else {
- buttons.push(btn);
- }
- });
- this.addClass(CONF.classPrefix + "layout-" + this.__options.layout);
- buttons[buttons.length - 1].addClass(CONF.classPrefix + "open-btn");
- this.__buttonWidgets = buttons;
- },
- __initEvent: function() {
- var lastBtn = this.__buttonWidgets[this.__buttonWidgets.length - 1], _self = this;
- this.callBase();
- lastBtn.on("click", function(e) {
- _self.open();
- });
- this.__maskWidget.on("maskclick", function() {
- _self.close();
- });
- this.__menuWidget.on("select", function(e, info) {
- e.stopPropagation();
- _self.close();
- _self.trigger("select", info);
- }).on("change", function(e, info) {
- _self.trigger("change", info);
- });
- this.on("btnclick", function(e) {
- e.stopPropagation();
- var btnIndex = $.inArray(e.widget, this.__buttonWidgets);
- if (btnIndex > -1 && btnIndex < this.__buttonWidgets.length - 1) {
- this.trigger("buttonclick", {
- button: this.__buttonWidgets[btnIndex]
- });
- }
- });
- }
- });
- }
- };
- _p[35] = {
- value: function(require) {
- var $ = _p.r(4), tpl = _p.r(25), InputButton = _p.r(43), Menu = _p.r(50), Mask = _p.r(49), Utils = _p.r(13);
- return _p.r(13).createClass("InputMenu", {
- base: _p.r(60),
- constructor: function(options) {
- var marker = Utils.getMarker();
- this.callBase(marker);
- var defaultOptions = {
- input: null,
- menu: null,
- mask: null
- };
- this.__extendOptions(defaultOptions, options);
- this.widgetName = "InputMenu";
- this.__tpl = tpl;
-
- this.__lastTime = 0;
-
- this.__lastSelect = null;
- this.__inputWidget = null;
- this.__menuWidget = null;
- this.__maskWidget = null;
-
- this.__menuState = false;
- if (options !== marker) {
- this.__render();
- }
- },
- select: function(index) {
- this.__menuWidget.select(index);
- },
- setValue: function(value) {
- this.__inputWidget.setValue(value);
- return this;
- },
- getValue: function() {
- return this.__inputWidget.getValue();
- },
- __render: function() {
- if (this.__rendered) {
- return this;
- }
- this.__inputWidget = new InputButton(this.__options.input);
- this.__menuWidget = new Menu(this.__options.menu);
- this.__maskWidget = new Mask(this.__options.mask);
- this.callBase();
- this.__inputWidget.appendTo(this.__element);
- this.__menuWidget.positionTo(this.__inputWidget);
- this.__initInputMenuEvent();
- },
- open: function() {
- this.__maskWidget.show();
- this.__menuWidget.show();
- },
- close: function() {
- this.__maskWidget.hide();
- this.__menuWidget.hide();
- },
- __initInputMenuEvent: function() {
- var _self = this;
- this.on("buttonclick", function() {
- if (!this.__menuState) {
- this.__appendMenu();
- this.__menuState = true;
- }
- this.__inputWidget.unfocus();
- this.open();
- });
- this.on("keypress", function(e) {
- this.__lastTime = new Date();
- });
- this.on("keyup", function(e) {
- if (e.keyCode !== 8 && e.keyCode !== 13 && new Date() - this.__lastTime < 500) {
- this.__update();
- }
- });
- this.on("inputcomplete", function() {
- this.__inputWidget.selectRange(99999999);
- this.__inputComplete();
- });
- this.__menuWidget.on("select", function(e, info) {
- e.stopPropagation();
- _self.setValue(info.value);
- _self.trigger("select", info);
- _self.close();
- });
- this.__menuWidget.on("change", function(e, info) {
- e.stopPropagation();
- _self.trigger("change", info);
- });
-
- this.__inputWidget.on("select change", function(e) {
- e.stopPropagation();
- });
-
- this.__maskWidget.on("maskclick", function() {
- _self.close();
- });
-
- this.on("select", function(e, info) {
- this.__lastSelect = info;
- });
- },
-
- __update: function() {
- var inputValue = this.getValue(), lowerCaseValue = inputValue.toLowerCase(), values = this.__getItemValues(), targetValue = null;
- if (!inputValue) {
- return;
- }
- $.each(values, function(i, val) {
- if (val.toLowerCase().indexOf(lowerCaseValue) === 0) {
- targetValue = val;
- return false;
- }
- });
- if (targetValue) {
- this.__inputWidget.setValue(targetValue);
- this.__inputWidget.selectRange(inputValue.length);
- }
- },
-
- __getItemValues: function() {
- var vals = [];
- $.each(this.__menuWidget.getWidgets(), function(index, item) {
- vals.push(item.getValue());
- });
- return vals;
- },
-
- __inputComplete: function() {
- var values = this.__getItemValues(), targetIndex = -1, inputValue = this.getValue(), lastSelect = this.__lastSelect;
- $.each(values, function(i, val) {
- if (val === inputValue) {
- targetIndex = i;
- return false;
- }
- });
- this.trigger("select", {
- index: targetIndex,
- value: inputValue
- });
- if (!lastSelect || lastSelect.value !== inputValue) {
- this.trigger("change", {
- from: lastSelect || {
- index: -1,
- value: null
- },
- to: {
- index: targetIndex,
- value: inputValue
- }
- });
- }
- },
- __appendMenu: function() {
- this.__menuWidget.appendTo(this.__inputWidget.getElement().ownerDocument.body);
- }
- });
- }
- };
- _p[36] = {
- value: function(require) {
- var $ = _p.r(4), CONF = _p.r(12), ToggleButton = _p.r(59);
- return _p.r(13).createClass("Buttonset", {
- base: _p.r(51),
- constructor: function(options) {
- var defaultOptions = {
-
- selected: -1
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- getButtons: function() {
- return this.getWidgets();
- },
- getButton: function(index) {
- return this.getWidgets()[index] || null;
- },
- getValue: function() {
- if (this.__currentIndex > -1) {
- return this.__widgets[this.__currentIndex].getValue();
- }
- return null;
- },
- getSelectedIndex: function() {
- return this.__currentIndex;
- },
- appendButton: function() {
- return this.appendWidget.apply(this, arguments);
- },
- insertButton: function() {
- return this.insertWidget.apply(this, arguments);
- },
- select: function(indexOrWidget) {
- if (this.__options.disabled) {
- return this;
- }
- if (indexOrWidget instanceof ToggleButton) {
- indexOrWidget = $.inArray(indexOrWidget, this.__widgets);
- }
- if (indexOrWidget < 0) {
- return this.clearSelect();
- }
- indexOrWidget = this.__widgets[indexOrWidget];
- this.__pressButton(indexOrWidget);
- return this;
- },
- selectByValue: function(value) {
- var values = this.__widgets.map(function(button) {
- return button.getValue();
- });
- return this.select(values.indexOf(value));
- },
- clearSelect: function() {
- this.__pressButton(null);
- return this;
- },
- removeButton: function() {
- return this.removeWidget.apply(this, arguments);
- },
- insertWidget: function(index, widget) {
- var returnValue = this.callBase(index, widget);
- if (returnValue === null) {
- return returnValue;
- }
- if (index <= this.__currentIndex) {
- this.__currentIndex++;
- }
- if (index <= this.__prevIndex) {
- this.__prevIndex++;
- }
- return returnValue;
- },
- removeWidget: function(widget) {
- var index = widget;
- if (typeof index !== "number") {
- index = this.indexOf(widget);
- }
- widget = this.callBase(widget);
- if (index === this.__currentIndex) {
- this.__currentIndex = -1;
- } else if (index < this.__currentIndex) {
- this.__currentIndex--;
- }
- if (index === this.__prevIndex) {
- this.__prevIndex = -1;
- } else if (index < this.__prevIndex) {
- this.__prevIndex--;
- }
- return widget;
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "Buttonset";
-
- this.__currentIndex = this.__options.selected;
-
- this.__prevIndex = -1;
- },
- __render: function() {
- this.callBase();
- $(this.__element).addClass(CONF.classPrefix + "buttonset");
- this.__initButtons();
- return this;
- },
- __initButtons: function() {
- var _self = this, buttonWidget = null;
- $.each(this.__options.buttons, function(index, buttonOption) {
- buttonWidget = new ToggleButton($.extend({}, buttonOption, {
- pressed: index === _self.__options.selected,
- preventDefault: true
- }));
-
- buttonWidget.__on("click", function(e) {
- if (!_self.isDisabled()) {
- _self.__pressButton(this);
- }
- });
- buttonWidget.__on("change", function(e) {
-
- e.stopPropagation();
- });
- _self.appendButton(buttonWidget);
- });
- },
-
- __pressButton: function(button) {
- this.__prevIndex = this.__currentIndex;
- this.__currentIndex = this.indexOf(button);
- if (this.__currentIndex === this.__prevIndex) {
- return;
- }
- if (button) {
- button.press();
- }
-
- $.each(this.__widgets, function(i, otherButton) {
- if (otherButton !== button) {
- otherButton.bounce();
- }
- });
- this.trigger("change", {
- currentIndex: this.__currentIndex,
- prevIndex: this.__prevIndex
- });
- },
- __valid: function(ele) {
- return ele instanceof ToggleButton;
- }
- });
- }
- };
- _p[37] = {
- value: function(require) {
- var $ = _p.r(4), CONF = _p.r(12), buttonTpl = _p.r(19), Icon = _p.r(42), Label = _p.r(48);
- return _p.r(13).createClass("Button", {
- base: _p.r(60),
- constructor: function(options) {
- var defaultOptions = {
- label: null,
- text: null,
- icon: null,
-
- layout: "right"
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- getLabel: function() {
- return this.__labelWidget.getText();
- },
- setLabel: function(text) {
- return this.__labelWidget.setText(text);
- },
- getLabelWidget: function() {
- return this.__labelWidget;
- },
- getIconWidget: function() {
- return this.__iconWidget;
- },
- __render: function() {
- this.callBase();
- this.__iconWidget = new Icon(this.__options.icon);
- this.__labelWidget = new Label(this.__options.label);
-
- switch (this.__options.layout) {
- case "left":
-
- case "top":
- this.__element.appendChild(this.__labelWidget.getElement());
- this.__element.appendChild(this.__iconWidget.getElement());
- break;
- case "right":
-
- case "bottom":
-
- default:
- this.__element.appendChild(this.__iconWidget.getElement());
- this.__element.appendChild(this.__labelWidget.getElement());
- break;
- }
- $(this.__element).addClass(CONF.classPrefix + "button-layout-" + this.__options.layout);
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "Button";
- this.__tpl = buttonTpl;
- this.__iconWidget = null;
- this.__labelWidget = null;
- if (typeof this.__options.label !== "object") {
- this.__options.label = {
- text: this.__options.label
- };
- }
- if (typeof this.__options.icon !== "object") {
- this.__options.icon = {
- img: this.__options.icon
- };
- }
- },
- __initEvent: function() {
- this.callBase();
- this.on("click", function() {
- this.__trigger("btnclick");
- });
- }
- });
- }
- };
- _p[38] = {
- value: function(require) {
- var Utils = _p.r(13), CONF = _p.r(12), Mask = _p.r(49), tpl = _p.r(20), $ = _p.r(4);
- return Utils.createClass("ColorPicker", {
- base: _p.r(54),
- constructor: function(options) {
- var defaultOptions = {
- clearText: "",
- commonText: "",
- commonColor: [ [ "#ffffff", "#000000", "#eeece1", "#1f497d", "#4f81bd", "#c0504d", "#9bbb59", "#8064a2", "#4bacc6", "#f79646" ], [ "#f2f2f2", "#808080", "#ddd8c2", "#c6d9f1", "#dbe5f1", "#f2dbdb", "#eaf1dd", "#e5dfec", "#daeef3", "#fde9d9" ], [ "#d9d9d9", "#595959", "#c4bc96", "#8db3e2", "#b8cce4", "#e5b8b7", "#d6e3bc", "#ccc0d9", "#b6dde8", "#fbd4b4" ], [ "#bfbfbf", "#404040", "#938953", "#548dd4", "#95b3d7", "#d99594", "#c2d69b", "#b2a1c7", "#92cddc", "#fabf8f" ], [ "#a6a6a6", "#262626", "#4a442a", "#17365d", "#365f91", "#943634", "#76923c", "#5f497a", "#31849b", "#e36c0a" ], [ "#7f7f7f", "#0d0d0d", "#1c1a10", "#0f243e", "#243f60", "#622423", "#4e6128", "#3f3151", "#205867", "#974706" ] ],
- standardText: "",
- standardColor: [ "#c00000", "#ff0000", "#ffc000", "#ffff00", "#92d050", "#00b050", "#00b0f0", "#0070c0", "#002060", "#7030a0" ]
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- show: function() {
- if (!this.__inDoc) {
- this.__inDoc = true;
- this.appendTo(this.__element.ownerDocument.body);
- }
- this.__maskWidget.show();
- this.callBase();
- return this;
- },
- hide: function() {
- this.callBase();
- this.__maskWidget.hide();
- return this;
- },
- attachTo: function($obj) {
- var _self = this;
- $obj.on("click", function() {
- _self.appendTo($obj.getElement().ownerDocument.body);
- _self.positionTo($obj);
- _self.show();
- });
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "ColorPicker";
- this.__contentElement = null;
- this.__maskWidget = null;
- this.__inDoc = false;
- },
- __render: function() {
- this.callBase();
- $(this.__element).addClass(CONF.classPrefix + "colorpicker");
- var contentHtml = Utils.Tpl.compile(tpl, this.__options);
- this.__contentElement.appendChild($(contentHtml)[0]);
- this.__previewElement = $(this.__contentElement).find("." + CONF.classPrefix + "colorpicker-preview");
- this.__clearElement = $(this.__contentElement).find("." + CONF.classPrefix + "colorpicker-clear");
- this.__maskWidget = new Mask(this.__options.mask);
- },
-
- __initEvent: function() {
- var _self = this;
- this.callBase();
- this.on("click", function(e) {
- var color, $target = $(e.target);
- if ($target.hasClass(CONF.classPrefix + "colorpicker-item")) {
- color = $target.attr("data-color");
- _self.trigger("selectcolor", color);
- _self.hide();
- } else if ($target.hasClass(CONF.classPrefix + "colorpicker-clear")) {
- _self.trigger("selectcolor", "");
- _self.hide();
- }
- });
- this.on("mouseover", function(e) {
- var color, $target = $(e.target);
- if ($target.hasClass(CONF.classPrefix + "colorpicker-item")) {
- color = $target.attr("data-color");
- $(_self.__element).find("." + CONF.classPrefix + "colorpicker-preview").css({
- "background-color": color,
- "border-color": color
- });
- }
- });
- this.__maskWidget.on("click", function() {
- _self.hide();
- });
- }
- });
- }
- };
- _p[39] = {
- value: function(require) {
- var Utils = _p.r(13), CONF = _p.r(12), Widget = _p.r(60), Creator = _p.r(0), $ = _p.r(4);
- return Utils.createClass("Container", {
- base: Widget,
- constructor: function(options) {
- var defaultOptions = {
- column: false,
- widgets: null
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- indexOf: function(widget) {
- return $.inArray(widget, this.__widgets);
- },
- disable: function() {
- this.callBase();
- $.each(this.__widgets, function(index, widget) {
- widget.disable();
- });
- },
- enable: function() {
- this.callBase();
- $.each(this.__widgets, function(index, widget) {
- widget.enable();
- });
- },
- getWidgets: function() {
- return this.__widgets;
- },
- getWidget: function(index) {
- return this.__widgets[index] || null;
- },
- getWidgetByValue: function(value) {
- var widget = null;
- $.each(this.__widgets, function(i, wgt) {
- if (wgt.getValue() === value) {
- widget = wgt;
- return false;
- }
- });
- return widget;
- },
- appendWidget: function(widget) {
- if (!this.__valid(widget)) {
- return null;
- }
- if (this.__options.disabled) {
- widget.disable();
- }
- this.__widgets.push(widget);
- widget.appendTo(this.__contentElement);
- if (!this.__options.column) {
- return widget;
- }
- if (this.__widgets.length > 0 && this.__widgets.length % this.__options.column === 0) {
- this.__contentElement.appendChild($('<span class="fui-column"></span>')[0]);
- }
- $(widget.getElement()).addClass(CONF.classPrefix + "panel-column-widget");
- return widget;
- },
- appendWidgets: function(widgetArray) {
- var _self = this, widgets = widgetArray;
- if (!$.isArray(widgetArray)) {
- widgets = arguments;
- }
- $.each(widgets, function(i, widget) {
- _self.appendWidget(widget);
- });
- return this;
- },
-
- insertWidget: function(index, widget) {
- var oldElement = null;
- if (this.__widgets.length === 0) {
- return this.appendWidget(widget);
- }
- if (!this.__valid(widget)) {
- return null;
- }
- if (this.__options.disabled) {
- widget.disable();
- }
- oldElement = this.__widgets[index];
- this.__widgets.splice(index, 0, widget);
- this.__contentElement.insertBefore(widget.getElement(), oldElement.getElement());
- if (this.__options.column === false) {
- return widget;
- }
- this.__contentElement.insertBefore($('<span class="fui-column"></span>')[0], oldElement.getElement());
- $(widget.getElement()).addClass(CONF.classPrefix + "panel-column-widget");
- return widget;
- },
- insertWidgets: function(index, widgetArray) {
- var _self = this, widgets = widgetArray;
- if (!$.isArray(widgetArray)) {
- widgets = [].slice.call(arguments, 1);
- }
- $.each(widgets, function(i, widget) {
- _self.insertWidget(index, widget);
- index++;
- });
- return this;
- },
- getContentElement: function() {
- return this.__contentElement;
- },
- removeWidget: function(widget) {
- if (typeof widget === "number") {
- widget = this.__widgets.splice(widget, 1)[0];
- } else {
- this.__widgets.splice(this.indexOf(widget), 1);
- }
- this.__contentElement.removeChild(widget.getElement());
- $(widget.getElement()).removeClass(CONF.classPrefix + "panel-column-widget");
- return widget;
- },
- __initOptions: function() {
- this.widgetName = "Container";
- this.__widgets = [];
- this.__contentElement = null;
- this.__options.column -= 0;
- },
- __render: function() {
- this.callBase();
- this.__contentElement = this.__element;
- $(this.__element).addClass(CONF.classPrefix + "container");
- if (this.__options.column) {
- $(this.__element).addClass(CONF.classPrefix + "container-column");
- }
- return this;
- },
-
- __appendChild: function(childWidget) {
- return this.appendWidget(childWidget);
- },
- __initWidgets: function() {
- if (!this.__options.widgets) {
- return;
- }
- var widgets = Creator.parse(this.__options.widgets), _self = this;
- if (!$.isArray(widgets)) {
- widgets = [ widgets ];
- }
- $.each(widgets, function(i, widget) {
- _self.appendWidget(widget);
- });
- },
-
- __valid: function(ele) {
- return ele instanceof Widget;
- }
- });
- }
- };
- _p[40] = {
- value: function(require) {
- var Utils = _p.r(13), CONF = _p.r(12), Widget = _p.r(60), Mask = _p.r(49), tpl = _p.r(21), Button = _p.r(37), LAYOUT = CONF.layout, $ = _p.r(4), ACTION = {
- CANCEL: "cancel",
- OK: "ok"
- };
- return Utils.createClass("Dialog", {
- base: _p.r(54),
- constructor: function(options) {
- var defaultOptions = {
- layout: LAYOUT.CENTER,
- caption: null,
- resize: "height",
- draggable: true,
-
- closeButton: true,
- mask: {
- color: "#000",
- opacity: .2
- },
- prompt: false,
-
- buttons: [ {
- className: CONF.classPrefix + "xdialog-ok-btn",
- action: "ok",
- label: "确定"
- }, {
- className: CONF.classPrefix + "xdialog-cancel-btn",
- action: "cancel",
- label: "取消"
- } ]
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- open: function() {
- this.__fire("open", function() {
- this.show();
- });
- return this;
- },
- close: function() {
- this.__fire("close", function() {
- this.hide();
- });
- return this;
- },
- getButtons: function() {
- return this.__buttons;
- },
- getButton: function(index) {
- return this.__buttons[index];
- },
- appendTo: function(container) {
- this.callBase(container);
- this.__maskWidget.appendTo(container);
- this.__inDoc = true;
- return this;
- },
- show: function() {
- if (!this.__target) {
- this.__target = this.__element.ownerDocument.body;
- }
- if (!this.__inDoc) {
- this.appendTo(this.__element.ownerDocument.body);
- }
- this.__maskWidget.show();
- this.callBase();
- this.__openState = true;
- return this;
- },
- hide: function() {
- this.callBase();
- this.__maskWidget.hide();
- this.__openState = false;
- return this;
- },
- toggle: function() {
- this.isOpen() ? this.close() : this.open();
- return this;
- },
- isOpen: function() {
- return this.__openState;
- },
- getHeadElement: function() {
- return this.__headElement;
- },
- getBodyElement: function() {
- return this.getContentElement();
- },
- getFootElement: function() {
- return this.__footElement;
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "Dialog";
- this.__target = this.__options.target;
- this.__layout = this.__options.layout;
- this.__inDoc = false;
- this.__hinting = false;
- this.__openState = false;
- this.__headElement = null;
- this.__bodyElement = null;
- this.__footElement = null;
- this.__maskWidget = null;
- this.__buttons = [];
- if (this.__target instanceof Widget) {
- this.__target = this.__target.getElement();
- }
- },
- __render: function() {
- this.callBase();
- this.__innerTpl = Utils.Tpl.compile(tpl, this.__options);
- this.__contentElement.appendChild($(this.__innerTpl)[0]);
- $(this.__element).addClass(CONF.classPrefix + "dialog");
- this.__headElement = $(".fui-dialog-head", this.__contentElement)[0];
- this.__bodyElement = $(".fui-dialog-body", this.__contentElement)[0];
- this.__footElement = $(".fui-dialog-foot", this.__contentElement)[0];
- this.__maskWidget = new Mask(this.__options.mask);
- this.__contentElement = this.__bodyElement;
- if (this.__options.draggable) {
- this.__initDraggable();
- }
- if (this.__options.closeButton) {
- this.__initCloseButton();
- }
- this.__initButtons();
- this.__initMaskLint();
- },
- __action: function(type, btn) {
- switch (type) {
- case ACTION.OK:
- if (this.__triggerHandler(type) !== false) {
- this.close();
- }
- break;
- case ACTION.CANCEL:
- this.__triggerHandler(type);
- this.close();
- break;
- }
- },
- __initButtons: function() {
- var _self = this, button = null, foot = this.__footElement;
- $.each(this.__options.buttons, function(index, buttonOption) {
- button = new Button(buttonOption);
- button.appendTo(foot);
- _self.__buttons.push(button);
- });
- },
- __initEvent: function() {
- var _self = this;
- this.callBase();
- $([ this.__footElement, this.__headElement ]).on("btnclick", function(e, btn) {
- _self.__action(btn.getOptions().action, btn);
- });
- if (this.__options.prompt) {
- $(this.__element).on("keydown", function(e) {
- switch (e.keyCode) {
- case 13:
- _self.__action(ACTION.OK);
- break;
- case 27:
- _self.__action(ACTION.CANCEL);
- break;
- }
- });
- }
- },
- __initDraggable: function() {
- Utils.createDraggable({
- handler: this.__headElement,
- target: this.__element
- }).bind();
- },
- __initCloseButton: function() {
- var closeButton = new Button({
- className: "fui-close-button",
- action: "cancel",
- icon: {
- className: "fui-close-button-icon"
- }
- });
- closeButton.appendTo(this.__headElement);
- },
- __initMaskLint: function() {
- var _self = this;
- this.__maskWidget.on("click", function() {
- _self.__hint();
- });
- },
- __hint: function() {
- if (this.__hinting) {
- return;
- }
- this.__hinting = true;
- var $ele = $(this.__element), _self = this, classNmae = [ CONF.classPrefix + "mask-hint", CONF.classPrefix + "mask-animate" ];
- $ele.addClass(classNmae.join(" "));
- window.setTimeout(function() {
- $ele.removeClass(classNmae[0]);
- window.setTimeout(function() {
- $ele.removeClass(classNmae[1]);
- _self.__hinting = false;
- }, 200);
- }, 200);
- }
- });
- }
- };
- _p[41] = {
- value: function(require) {
- var $ = _p.r(4), CONF = _p.r(12), tpl = _p.r(22), Button = _p.r(37), Panel = _p.r(51), PPanel = _p.r(54), Mask = _p.r(49);
- return _p.r(13).createClass("DropPanel", {
- base: _p.r(60),
- constructor: function(options) {
- var defaultOptions = {
- button: null,
- panel: null,
- width: null,
- height: null
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- disable: function() {
- this.callBase();
- },
- enable: function() {
- this.callBase();
- },
- open: function() {
- this.__popupWidget.appendWidget(this.__panelWidget);
- this.__maskWidget.show();
- this.__popupWidget.show();
- var $popup = $(this.__popupWidget.getElement());
- $popup.css("top", parseInt($popup.css("top")) - $(this.__element).outerHeight());
- $popup.css("min-width", $(this.__element).outerWidth());
- $popup.css("min-height", $(this.__element).height());
- },
- close: function() {
- this.__maskWidget.hide();
- this.__popupWidget.hide();
- this.__panelWidget.appendTo(this.__contentElement);
- },
- getPanelElement: function() {
- return this.__panelWidget.getElement();
- },
- appendWidget: function(widget) {
- this.__panelWidget.appendWidget(widget);
- },
- getWidgets: function() {
- return this.__panelWidget.getWidgets();
- },
- getWidget: function(index) {
- return this.__panelWidget.getWidget(index);
- },
- appendWidgets: function(widgets) {
- this.__panelWidget.appendWidgets.apply(this, arguments);
- return this;
- },
- insertWidget: function(index, widget) {
- this.__panelWidget.insertWidget(index, widget);
- },
- insertWidgets: function(index, widgets) {
- this.__panelWidget.insertWidgets.apply(this, arguments);
- return this;
- },
- removeWidget: function(widget) {
- return this.__panelWidget.removeWidget(widget);
- },
- __render: function() {
- this.__initOptions();
- this.__buttonWidget = new Button(this.__options.button);
- this.__panelWidget = new Panel(this.__options.content);
- this.__popupWidget = new PPanel();
- this.__maskWidget = new Mask(this.__options.mask);
- this.callBase();
- this.__popupWidget.positionTo(this.__element);
- $(this.__popupWidget.getElement()).addClass(CONF.classPrefix + "drop-panel-popup");
-
- var $content = $('<div class="' + CONF.classPrefix + 'drop-panel-content"></div>').append(this.__panelWidget.getElement());
- this.__contentElement = $content[0];
-
- $(this.__element).append($content).append(this.__buttonWidget.getElement());
- this.__initDropPanelEvent();
- },
- __initOptions: function() {
- this.widgetName = "DropPanel";
- this.__tpl = tpl;
- this.__buttonWidget = null;
- this.__popupWidget = null;
- this.__panelWidget = null;
- this.__contentElement = null;
- this.__maskWidget = null;
- this.__popupState = false;
- if (typeof this.__options.button !== "object") {
- this.__options.input = {
- icon: this.__options.button
- };
- }
- },
- __initDropPanelEvent: function() {
- var _self = this;
- this.__buttonWidget.on("click", function() {
- if (!_self.__popupState) {
- _self.__appendPopup();
- _self.__popupState = true;
- }
- _self.trigger("buttonclick");
- _self.open();
- });
- this.__panelWidget.on("click", function() {
- _self.trigger("panelclick");
- });
-
- this.__maskWidget.on("maskclick", function() {
- _self.close();
- });
- },
- __appendPopup: function() {
- this.__popupWidget.appendTo(this.__element.ownerDocument.body);
- }
- });
- }
- };
- _p[42] = {
- value: function(require) {
- var $ = _p.r(4), iconTpl = _p.r(23);
- return _p.r(13).createClass("Icon", {
- base: _p.r(60),
- constructor: function(options) {
- var defaultOptions = {
- img: null
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- getValue: function() {
- return this.__options.value || this.__options.img;
- },
- setImage: function(imageSrc) {
- if (this.__options.img === imageSrc) {
- return this;
- }
- if (this.__image) {
- this.__image.src = imageSrc;
- }
- this.trigger("iconchange", {
- prevImage: this.__prevIcon,
- currentImage: this.__currentIcon
- });
- },
- getImage: function() {
- return this.__currentIcon;
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "Icon";
- this.__tpl = iconTpl;
- this.__prevIcon = null;
- this.__currentIcon = this.__options.img;
- this.__image = null;
- },
- __render: function() {
- this.__options.__width = this.__options.width;
- this.__options.__height = this.__options.height;
- this.__options.width = null;
- this.__options.height = null;
- this.callBase();
- if (!this.__options.img) {
- return;
- }
- this.__image = $("img", this.__element)[0];
- if (this.__options.__width !== null) {
- this.__image.width = this.__options.__width;
- }
- if (this.__options.__height !== null) {
- this.__image.height = this.__options.__height;
- }
- }
- });
- }
- };
- _p[43] = {
- value: function(require) {
- var $ = _p.r(4), CONF = _p.r(12), tpl = _p.r(24), Button = _p.r(37), Input = _p.r(45);
- return _p.r(13).createClass("InputButton", {
- base: _p.r(60),
- constructor: function(options) {
- var defaultOptions = {
- button: null,
- input: null,
- placeholder: null,
-
- layout: "right"
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- getValue: function() {
- return this.__inputWidget.getValue();
- },
- setValue: function(value) {
- this.__inputWidget.setValue(value);
- return this;
- },
- reset: function() {
- this.__inputWidget.reset();
- },
- selectAll: function() {
- this.__inputWidget.selectAll();
- return this;
- },
- selectRange: function(start, end) {
- this.__inputWidget.selectRange(start, end);
- return this;
- },
- focus: function() {
- this.__inputWidget.focus();
- return this;
- },
- unfocus: function() {
- this.__inputWidget.unfocus();
- return this;
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "InputButton";
- this.__tpl = tpl;
- this.__inputWidget = null;
- this.__buttonWidget = null;
- if (typeof this.__options.input !== "object") {
- this.__options.input = {
- placeholder: this.__options.input
- };
- }
- this.__options.input = $.extend({}, this.__options.input, {
- placeholder: this.__options.placeholder
- });
- if (typeof this.__options.button !== "object") {
- this.__options.button = {
- icon: this.__options.button
- };
- }
- },
- __render: function() {
- var _self = this;
- this.callBase();
- this.__buttonWidget = new Button(this.__options.button);
- this.__inputWidget = new Input(this.__options.input);
-
- switch (this.__options.layout) {
- case "left":
-
- case "top":
- this.__buttonWidget.appendTo(this.__element);
- this.__inputWidget.appendTo(this.__element);
- break;
- case "right":
-
- case "bottom":
-
- default:
- this.__inputWidget.appendTo(this.__element);
- this.__buttonWidget.appendTo(this.__element);
- break;
- }
- $(this.__element).addClass(CONF.classPrefix + "layout-" + this.__options.layout);
- this.__buttonWidget.on("click", function() {
- _self.trigger("buttonclick");
- });
- }
- });
- }
- };
- _p[44] = {
- value: function(require) {
- var $ = _p.r(4), tpl = _p.r(25), InputButton = _p.r(43), Menu = _p.r(50), Mask = _p.r(49);
- return _p.r(13).createClass("InputMenu", {
- base: _p.r(60),
- constructor: function(options) {
- var defaultOptions = {
- input: null,
- menu: null,
- mask: null,
- selected: -1
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- select: function(index) {
- this.__menuWidget.select(index);
- },
- selectByValue: function(value) {
- return this.__selectBy("values", value);
- },
- selectByLabel: function(value) {
- return this.__selectBy("labels", value);
- },
- clearSelect: function() {
- this.__lastSelect = -1;
- this.__menuWidget.clearSelect();
- this.__inputWidget.reset();
- return this;
- },
- setValue: function(value) {
- return this;
- },
- getValue: function() {
- return this.__menuWidget.getSelectedItem().getValue();
- },
- open: function() {
- this.__maskWidget.show();
- this.__menuWidget.show();
- },
- close: function() {
- this.__maskWidget.hide();
- this.__menuWidget.hide();
- },
- __render: function() {
- this.__inputWidget = new InputButton(this.__options.input);
- this.__menuWidget = new Menu(this.__options.menu);
- this.__maskWidget = new Mask(this.__options.mask);
- this.callBase();
- this.__inputWidget.appendTo(this.__element);
- this.__menuWidget.positionTo(this.__inputWidget);
- this.__initInputValue();
- },
- __selectBy: function(type, value) {
- var values = this.__getItemValues()[type], index = -1;
- $.each(values, function(i, val) {
- if (value === val) {
- index = i;
- return false;
- }
- });
- if (index !== -1) {
- this.select(index);
- return this.__menuWidget.getSelectedItem();
- }
- return null;
- },
- __initInputValue: function() {
- var selectedItem = this.__menuWidget.getItem(this.__options.selected);
- if (selectedItem) {
- this.__inputWidget.setValue(selectedItem.getLabel());
- }
- },
- __initEvent: function() {
- var _self = this;
- this.callBase();
- this.on("buttonclick", function() {
- if (!this.__menuState) {
- this.__appendMenu();
- this.__menuState = true;
- }
- this.__inputWidget.unfocus();
- this.open();
- });
- this.on("keypress", function(e) {
- this.__lastTime = new Date();
- });
- this.on("keyup", function(e) {
- if (e.keyCode !== 8 && e.keyCode !== 13 && new Date() - this.__lastTime < 500) {
- this.__update();
- }
- });
- this.on("inputcomplete", function() {
- this.__inputWidget.selectRange(99999999);
- this.__inputComplete();
- });
- this.__menuWidget.on("select", function(e, info) {
- e.stopPropagation();
- _self.__inputWidget.setValue(info.label);
- _self.trigger("select", info);
- _self.close();
- });
- this.__menuWidget.on("menuitemclick", function(e, info) {
- _self.trigger("itemclick", info);
- });
- this.__menuWidget.on("change", function(e, info) {
- e.stopPropagation();
- _self.trigger("change", info);
- });
-
- this.__inputWidget.on("select change", function(e) {
- e.stopPropagation();
- });
-
- this.__maskWidget.on("maskclick", function() {
- _self.close();
- });
-
- this.on("select", function(e, info) {
- this.__lastSelect = info;
- });
- },
-
- __update: function() {
- var inputValue = this.__inputWidget.getValue(), lowerCaseValue = inputValue.toLowerCase(), values = this.__getItemValues().labels, targetValue = null;
- if (!inputValue) {
- return;
- }
- $.each(values, function(i, val) {
- if (val.toLowerCase().indexOf(lowerCaseValue) === 0) {
- targetValue = val;
- return false;
- }
- });
- if (targetValue) {
- this.__inputWidget.setValue(targetValue);
- this.__inputWidget.selectRange(inputValue.length);
- }
- },
-
- __getItemValues: function() {
- var vals = [], labels = [];
- $.each(this.__menuWidget.getWidgets(), function(index, item) {
- labels.push(item.getLabel());
- vals.push(item.getValue());
- });
- return {
- labels: labels,
- values: vals
- };
- },
-
- __inputComplete: function() {
- var itemsInfo = this.__getItemValues(), labels = itemsInfo.labels, targetIndex = -1, inputValue = this.__inputWidget.getValue(), lastSelect = this.__lastSelect;
- $.each(labels, function(i, label) {
- if (label === inputValue) {
- targetIndex = i;
- return false;
- }
- });
- this.trigger("select", {
- index: targetIndex,
- label: inputValue,
- value: itemsInfo.values[targetIndex]
- });
- if (!lastSelect || lastSelect.value !== inputValue) {
- this.trigger("change", {
- from: lastSelect || {
- index: -1,
- label: null,
- value: null
- },
- to: {
- index: targetIndex,
- label: inputValue,
- value: itemsInfo.values[targetIndex]
- }
- });
- }
- },
- __appendMenu: function() {
- this.__menuWidget.appendTo(this.__inputWidget.getElement().ownerDocument.body);
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "InputMenu";
- this.__tpl = tpl;
-
- this.__lastTime = 0;
-
- this.__lastSelect = null;
- this.__inputWidget = null;
- this.__menuWidget = null;
- this.__maskWidget = null;
-
- this.__menuState = false;
- if (this.__options.selected !== -1) {
- this.__options.menu.selected = this.__options.selected;
- }
- }
- });
- }
- };
- _p[45] = {
- value: function(require) {
- var CONF = _p.r(12), $ = _p.r(4), tpl = _p.r(26);
- return _p.r(13).createClass("Input", {
- base: _p.r(60),
- constructor: function(options) {
- var defaultOptions = {
- placeholder: null
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- getValue: function() {
- return this.__element.value;
- },
- setValue: function(value) {
- this.__element.value = value;
- return this;
- },
- disable: function() {
- this.callBase();
- this.__element.disabled = true;
- },
- enable: function() {
- this.__element.disabled = false;
- this.callBase();
- },
- reset: function() {
- this.__element.value = this.__options.value || "";
- return this;
- },
- selectAll: function() {
- this.__element.select();
- },
- selectRange: function(startIndex, endIndex) {
- if (!startIndex) {
- startIndex = 0;
- }
- if (!endIndex) {
- endIndex = 1e9;
- }
- this.__element.setSelectionRange(startIndex, endIndex);
- },
- focus: function() {
- this.__element.focus();
- return this;
- },
- unfocus: function() {
- this.__element.blur();
- return this;
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "Input";
- this.__tpl = tpl;
-
- this.__allow_focus = true;
- },
- __render: function() {
- this.callBase();
- this.__element.removeAttribute("unselectable");
- if (this.__options.placeholder) {
- this.__element.setAttribute("placeholder", this.__options.placeholder);
- }
- this.addClass(CONF.classPrefix + "selectable");
- },
- __initEvent: function() {
- this.callBase();
- this.on("keydown", function(e) {
- if (e.keyCode === 13) {
- this.trigger("inputcomplete", {
- value: this.getValue()
- });
- }
- });
- }
- });
- }
- };
- _p[46] = {
- value: function(require) {
- var Utils = _p.r(13), itemTpl = _p.r(27), Icon = _p.r(42), Label = _p.r(48), CONF = _p.r(12), $ = _p.r(4);
- return Utils.createClass("Item", {
- base: _p.r(60),
- constructor: function(options) {
- var defaultOptions = {
- label: "",
- icon: null,
- selected: false,
- textAlign: "left"
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- getValue: function() {
- return this.__options.value || this.__labelWidget.getValue() || this.__iconWidget.getValue() || null;
- },
- select: function() {
- this.__update(true);
- return this;
- },
- unselect: function() {
- this.__update(false);
- return this;
- },
- isSelected: function() {
- return this.__selectState;
- },
- setLabel: function(text) {
- this.__labelWidget.setText(text);
- return this;
- },
- getLabel: function() {
- return this.__labelWidget.getText();
- },
- setIcon: function(imageSrc) {
- this.__iconWidget.setImage(imageSrc);
- return this;
- },
- getIcon: function() {
- return this.__iconWidget.getImage();
- },
- __render: function() {
- this.callBase();
- this.__iconWidget = new Icon(this.__options.icon);
- this.__labelWidget = new Label(this.__options.label);
- this.__iconWidget.appendTo(this.__element);
- this.__labelWidget.appendTo(this.__element);
- },
- __update: function(state) {
- var fn = state ? "addClass" : "removeClass";
- state = !!state;
- $(this.__element)[fn](CONF.classPrefix + "item-selected");
- this.__selectState = state;
- this.trigger(state ? "itemselect" : "itemunselect");
- return this;
- },
- __initEvent: function() {
- this.callBase();
- this.on("click", function() {
- this.trigger("itemclick");
- });
- },
-
- __initOptions: function() {
- this.callBase();
- this.widgetName = "Item";
- this.__tpl = itemTpl;
- this.__iconWidget = null;
- this.__labelWidget = null;
- this.__selectState = this.__options.selected;
- if (typeof this.__options.label !== "object") {
- this.__options.label = {
- text: this.__options.label
- };
- }
- if (!this.__options.label.textAlign) {
- this.__options.label.textAlign = this.__options.textAlign;
- }
- if (typeof this.__options.icon !== "object") {
- this.__options.icon = {
- img: this.__options.icon
- };
- }
- }
- });
- }
- };
- _p[47] = {
- value: function(require) {
- var Utils = _p.r(13), CONF = _p.r(12), Label = _p.r(48), $ = _p.r(4);
- return Utils.createClass("LabelPanel", {
- base: _p.r(51),
- constructor: function(options) {
- var defaultOptions = {
- layout: "bottom"
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- disable: function() {
- this.callBase();
- this.__labelWidget.disable();
- },
- enable: function() {
- this.callBase();
- this.__labelWidget.enable();
- },
- __render: function() {
- var $contentElement = null, opts = this.__options, ele = this.__element, classPrefix = CONF.classPrefix, labelClass = "fui-label-panel-content", originEle = null;
- this.__labelWidget = new Label(opts.label);
- this.callBase();
- originEle = this.__contentElement;
- $(ele).addClass(classPrefix + "label-panel");
- $(ele).addClass(classPrefix + "layout-" + opts.layout);
- $contentElement = $('<div class="' + labelClass + '"></div>');
- originEle.appendChild(this.__labelWidget.getElement());
- originEle.appendChild($contentElement[0]);
-
- this.__contentElement = $contentElement[0];
- return this;
- },
- __initOptions: function() {
- var label = this.__options.label;
- this.callBase();
- this.widgetName = "LabelPanel";
- this.__labelWidget = null;
- if (typeof label !== "object") {
- this.__options.label = {
- text: label
- };
- }
- if (!this.__options.label.className) {
- this.__options.label.className = "";
- }
- this.__options.label.className += " fui-label-panel-label";
- }
- });
- }
- };
- _p[48] = {
- value: function(require) {
- var Utils = _p.r(13), labelTpl = _p.r(28), $ = _p.r(4);
- return Utils.createClass("Label", {
- base: _p.r(60),
- constructor: function(options) {
- var defaultOptions = {
- text: "",
- textAlign: "center"
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- getValue: function() {
- return this.__options.text;
- },
- setText: function(text) {
- var oldtext = this.__options.text;
- this.__options.text = text;
- $(this.__element).text(text);
- this.trigger("labelchange", {
- currentText: text,
- prevText: oldtext
- });
- return this;
- },
- getText: function() {
- return this.__options.text;
- },
-
- __allowShowTitle: function() {
- return false;
- },
-
- __initOptions: function() {
- this.callBase();
- this.widgetName = "Label";
- this.__tpl = labelTpl;
- this.__options.text = this.__options.text.toString();
- }
- });
- }
- };
- _p[49] = {
- value: function(require) {
- var Utils = _p.r(13), tpl = _p.r(29), Widget = _p.r(60), $ = _p.r(4), __cache_inited = false, __MASK_CACHE = [];
- return Utils.createClass("Mask", {
- base: _p.r(60),
- constructor: function(options) {
- var defaultOptions = {
- bgcolor: "#000",
- opacity: 0,
- inner: true,
- target: null,
-
- scroll: false,
- hide: true
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- maskTo: function(target) {
- if (target) {
- this.__target = target;
- }
- return this;
- },
- show: function() {
- var docNode = null;
- if (!this.__target) {
- this.__target = this.__element.ownerDocument.body;
- }
- docNode = this.__target.ownerDocument.documentElement;
-
- if (!$.contains(docNode, this.__element)) {
- this.appendTo(this.__target.ownerDocument.body);
- }
- this.callBase();
- this.__position();
- this.__resize();
- this.__hideState = false;
- },
- hide: function() {
- this.callBase();
- this.__hideState = true;
- },
- isHide: function() {
- return this.__hideState;
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "Mask";
- this.__tpl = tpl;
- this.__cacheId = __MASK_CACHE.length;
- this.__hideState = true;
- __MASK_CACHE.push(this);
- this.__target = this.__options.target;
- if (this.__target instanceof Widget) {
- this.__target = this.__target.getElement();
- }
- },
- __render: function() {
- this.callBase();
- this.__initMaskEvent();
- if (!__cache_inited) {
- __cache_inited = true;
- __initCacheEvent();
- }
- },
- __initMaskEvent: function() {
- this.on("mousewheel", function(e) {
- var evt = e.originalEvent;
- e.preventDefault();
- e.stopPropagation();
- this.trigger("scroll", {
- delta: evt.wheelDelta || evt.deltaY || evt.detail
- });
- });
- this.on("click", function(e) {
- e.stopPropagation();
- if (e.target === this.__element) {
- this.trigger("maskclick");
- }
- });
- },
-
- __resize: function() {
- var targetRect = null;
-
- if (this.__targetIsBody()) {
- targetRect = $(Utils.getView(this.__target));
- targetRect = {
- width: targetRect.width(),
- height: targetRect.height()
- };
- } else {
- targetRect = Utils.getRect(this.__target);
- }
- this.__element.style.width = targetRect.width + "px";
- this.__element.style.height = targetRect.height + "px";
- },
- __position: function() {
- var location = null, targetRect = null;
- if (this.__targetIsBody()) {
- location = {
- top: 0,
- left: 0
- };
- } else {
- targetRect = Utils.getRect(this.__target);
- location = {
- top: targetRect.top,
- left: targetRect.left
- };
- }
- $(this.__element).css("top", location.top + "px").css("left", location.left + "px");
- },
- __targetIsBody: function() {
- return this.__target.tagName.toLowerCase() === "body";
- }
- });
-
- function __initCacheEvent() {
- $(window).on("resize", function() {
- $.each(__MASK_CACHE, function(i, mask) {
- if (mask && !mask.isHide()) {
- mask.__resize();
- }
- });
- });
- }
- }
- };
- _p[50] = {
- value: function(require) {
- var Utils = _p.r(13), Item = _p.r(46), CONF = _p.r(12), $ = _p.r(4);
- return Utils.createClass("Menu", {
- base: _p.r(54),
- constructor: function(options) {
- var defaultOptions = {
- column: true,
- selected: -1,
- textAlign: "left",
- items: []
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- select: function(index) {
- var item = this.__widgets[index];
- if (!item) {
- return this;
- }
- this.__selectItem(item);
- return this;
- },
- clearSelect: function() {
- var selectedItem = this.getSelectedItem();
- if (selectedItem) {
- selectedItem.unselect();
- }
- this.__currentSelect = -1;
- this.__prevSelect = -1;
- },
- getItems: function() {
- return this.getWidgets.apply(this, arguments);
- },
- getItem: function() {
- return this.getWidget.apply(this, arguments);
- },
- appendItem: function(item) {
- return this.appendWidget.apply(this, arguments);
- },
- insertItem: function(item) {
- return this.insertWidget.apply(this, arguments);
- },
- removeItem: function(item) {
- return this.removeWidget.apply(this, arguments);
- },
- clearItems: function() {
- while (this.getItems().length) {
- this.removeItem(0);
- }
- return this;
- },
- getSelected: function() {
- return this.__currentSelect;
- },
- getSelectedItem: function() {
- return this.getItem(this.__currentSelect);
- },
- insertWidget: function(index, widget) {
- var returnValue = this.callBase(index, widget);
- if (returnValue === null) {
- return returnValue;
- }
- if (index <= this.__currentSelect) {
- this.__currentSelect++;
- }
- if (index <= this.__prevSelect) {
- this.__prevSelect++;
- }
- return returnValue;
- },
- removeWidget: function(widget) {
- var index = widget;
- if (typeof index !== "number") {
- index = this.indexOf(widget);
- }
- widget = this.callBase(widget);
- if (index === this.__currentSelect) {
- this.__currentSelect = -1;
- } else if (index < this.__currentSelect) {
- this.__currentSelect--;
- }
- if (index === this.__prevSelect) {
- this.__prevSelect = -1;
- } else if (index < this.__prevSelect) {
- this.__prevSelect--;
- }
- return widget;
- },
- __initOptions: function() {
- this.callBase();
- this.__prevSelect = -1;
- this.__currentSelect = this.__options.selected;
- this.widgetName = "Menu";
- },
- __render: function() {
- var _self = this, textAlign = this.__options.textAlign, selected = this.__options.selected;
- this.callBase();
- $(this.__element).addClass(CONF.classPrefix + "menu");
- $.each(this.__options.items, function(index, itemOption) {
- if (typeof itemOption !== "object") {
- itemOption = {
- label: itemOption
- };
- }
- itemOption.selected = index === selected;
- itemOption.textAlign = textAlign;
- _self.appendItem(new Item(itemOption));
- });
- },
-
- __initEvent: function() {
- this.callBase();
- this.on("itemclick", function(e) {
- this.__selectItem(e.widget, true);
- });
- },
- __selectItem: function(item, isUserTrigger) {
- var info = null;
- if (this.__currentSelect > -1) {
- this.__widgets[this.__currentSelect].unselect();
- }
- this.__prevSelect = this.__currentSelect;
- this.__currentSelect = this.indexOf(item);
- item.select();
- info = {
- index: this.__currentSelect,
- label: item.getLabel(),
- value: item.getValue()
- };
- if (isUserTrigger) {
- this.trigger("menuitemclick", info);
- }
- this.trigger("select", info);
- if (this.__prevSelect !== this.__currentSelect) {
- var fromItem = this.__widgets[this.__prevSelect] || null;
- this.trigger("change", {
- from: {
- index: this.__prevSelect,
- label: fromItem && fromItem.getLabel(),
- value: fromItem && fromItem.getValue()
- },
- to: {
- index: this.__currentSelect,
- label: item.getLabel(),
- value: item.getValue()
- }
- });
- }
- },
- __valid: function(target) {
- return target instanceof Item;
- }
- });
- }
- };
- _p[51] = {
- value: function(require) {
- var Utils = _p.r(13), panelTpl = _p.r(30), $ = _p.r(4);
- return Utils.createClass("Panel", {
- base: _p.r(39),
- constructor: function(options) {
- var defaultOptions = {};
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- __render: function() {
- var $content = null;
- this.callBase();
- $content = $('<div class="fui-panel-content"></div>');
- this.__contentElement.appendChild($content[0]);
- this.__contentElement = $content[0];
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "Panel";
- this.__tpl = panelTpl;
- }
- });
- }
- };
- _p[52] = {
- value: function(require) {
- var Utils = _p.r(13), CONF = _p.r(12), $ = _p.r(4), Menu = _p.r(50);
- return Utils.createClass("PopupMenu", {
- base: _p.r(53),
- constructor: function(options) {
- this.callBase($.extend({
- menu: {}
- }, options));
- },
- getMenuWidget: function() {
- return this.__menuWidget;
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "PopupMenu";
- },
- __render: function() {
- this.callBase();
- this.__menuWidget = new Menu();
- this.appendWidget(this.__menuWidget);
- $(this.__element).addClass(CONF.classPrefix + "popup-menu");
- }
- });
- }
- };
- _p[53] = {
- value: function(require) {
- var Utils = _p.r(13), CONF = _p.r(12), Widget = _p.r(60), Mask = _p.r(49), $ = _p.r(4);
- return Utils.createClass("Popup", {
- base: _p.r(54),
- constructor: function(options) {
- var defaultOptions = {
- mask: {}
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- open: function() {
- this.__fire("open", function() {
- this.show();
- });
- return this;
- },
- close: function() {
- this.__fire("close", function() {
- this.hide();
- });
- return this;
- },
- show: function() {
- if (!this.__target) {
- this.__target = this.__element.ownerDocument.body;
- }
- if (!this.__inDoc) {
- this.__inDoc = true;
- this.appendTo(this.__element.ownerDocument.body);
- }
- this.__maskWidget.show();
- this.callBase();
- this.__openState = true;
- return this;
- },
- hide: function() {
- this.callBase();
- this.__maskWidget.hide();
- this.__openState = false;
- return this;
- },
- toggle: function() {
- this.isOpen() ? this.close() : this.open();
- return this;
- },
- isOpen: function() {
- return this.__openState;
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "Popup";
- this.__target = this.__options.target;
- this.__layout = this.__options.layout;
- this.__inDoc = false;
- this.__openState = false;
- this.__maskWidget = null;
- if (this.__target instanceof Widget) {
- this.__target = this.__target.getElement();
- }
- },
- __render: function() {
- this.callBase();
- $(this.__element).addClass(CONF.classPrefix + "popup");
- this.__maskWidget = new Mask(this.__options.mask);
- if (this.__options.draggable) {
- this.__initDraggable();
- }
- this.__initMaskEvent();
- },
- __initMaskEvent: function() {
- var _self = this;
- this.__maskWidget.on("click", function() {
- _self.close();
- });
- }
- });
- }
- };
- _p[54] = {
- value: function(require) {
- var Utils = _p.r(13), CONF = _p.r(12), Widget = _p.r(60), LAYOUT = CONF.layout, $ = _p.r(4);
- return Utils.createClass("PPanel", {
- base: _p.r(51),
- constructor: function(options) {
- var defaultOptions = {
- layout: LAYOUT.BOTTOM,
- target: null,
-
- bound: null,
-
- diff: 10,
- hide: true,
- resize: "all",
- iframe: false
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- positionTo: function(target, layout) {
- if (target instanceof Widget) {
- target = target.getElement();
- }
- this.__target = target;
- if (layout) {
- this.__layout = layout;
- }
- return this;
- },
- show: function() {
- var docNode = null;
- if (!this.__target) {
- return this.callBase();
- }
- if (!this.__options.bound) {
- this.__options.bound = this.__target.ownerDocument.body;
- }
- docNode = this.__target.ownerDocument.documentElement;
- if (!$.contains(docNode, this.__element)) {
- this.__target.ownerDocument.body.appendChild(this.__element);
- }
- if ($.contains(docNode, this.__target)) {
- this.callBase(Utils.getMarker());
- this.__position();
- this.__resize();
- }
- return this;
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "PPanel";
- this.__target = this.__options.target;
- this.__layout = this.__options.layout;
-
- this.__height_resized = false;
- },
- __render: function() {
- this.callBase();
- if (this.__options.iframe) {
- $('<iframe class="fui-ppanel-cover" frameborder="0"></iframe>').appendTo(this.__element);
- }
- $(this.__element).addClass(CONF.classPrefix + "ppanel");
- },
-
- __position: function() {
- var location = null, className = CONF.classPrefix + "ppanel-position";
- $(this.__element).addClass(className);
- location = this.__getLocation();
- $(this.__element).css("top", location.top + "px").css("left", location.left + "px");
- },
- __resize: function() {
- var targetRect = Utils.getBound(this.__target);
- switch (this.__options.resize) {
- case "all":
- this.__resizeWidth(targetRect);
- this.__resizeHeight();
- break;
- case "width":
- this.__resizeWidth(targetRect);
- break;
- case "height":
- this.__resizeHeight();
- break;
- }
- },
-
- __resizeWidth: function(targetRect) {
- if (!this.__target) {
- return;
- }
- var $ele = $(this.__element), w = $ele.outerWidth(), h = $ele.outerHeight(), minWidth = targetRect.width - w - h;
- this.__element.style.minWidth = minWidth + "px";
- },
-
- __resizeHeight: function() {
- var boundRect = null, panelRect = null, diff = 0;
- panelRect = Utils.getRect(this.__element);
- panelRect.height = this.__element.scrollHeight;
- panelRect.bottom = panelRect.top + panelRect.height;
- boundRect = this.__getBoundRect();
- diff = panelRect.bottom - boundRect.bottom;
- if (diff > 0) {
- this.__height_resized = true;
- diff = panelRect.height - diff - this.__options.diff;
- $(this.__element).css("height", diff + "px");
- } else if (this.__height_resized) {
- this.__element.style.height = null;
- }
- },
- __getLocation: function() {
- var targetRect = Utils.getBound(this.__target);
- switch (this.__layout) {
- case LAYOUT.CENTER:
- case LAYOUT.MIDDLE:
- return this.__getCenterLayout(targetRect);
- case LAYOUT.LEFT:
- case LAYOUT.RIGHT:
- case LAYOUT.BOTTOM:
- case LAYOUT.TOP:
- return this.__getOuterLayout(targetRect);
- default:
- return this.__getInnerLayout(targetRect);
- }
- return location;
- },
-
- __getCenterLayout: function(targetRect) {
- var location = {
- top: 0,
- left: 0
- }, panelRect = Utils.getRect(this.__element), diff = 0;
- diff = targetRect.height - panelRect.height;
- if (diff > 0) {
- location.top = targetRect.top + diff / 2;
- }
- diff = targetRect.width - panelRect.width;
- if (diff > 0) {
- location.left = targetRect.left + diff / 2;
- }
- return location;
- },
-
- __getOuterLayout: function(targetRect) {
- var location = {
- top: 0,
- left: 0
- }, panelRect = Utils.getRect(this.__element);
- switch (this.__layout) {
- case LAYOUT.TOP:
- location.left = targetRect.left;
- location.top = targetRect.top - panelRect.height;
- break;
- case LAYOUT.LEFT:
- location.top = targetRect.top;
- location.left = targetRect.left - panelRect.width;
- break;
- case LAYOUT.RIGHT:
- location.top = targetRect.top;
- location.left = targetRect.right;
- break;
- case LAYOUT.BOTTOM:
-
- default:
- location.left = targetRect.left;
- location.top = targetRect.bottom;
- break;
- }
- return location;
- },
-
- __getInnerLayout: function(targetRect) {
- var location = {
- top: 0,
- left: 0
- }, rect = targetRect, panelRect = Utils.getRect(this.__element);
- switch (this.__layout) {
- case LAYOUT.LEFT_TOP:
- location.top = rect.top;
- location.left = rect.left;
- break;
- case LAYOUT.RIGHT_TOP:
- location.top = rect.top;
- location.left = rect.left + rect.width - panelRect.width;
- break;
- case LAYOUT.LEFT_BOTTOM:
- location.top = rect.top + rect.height - panelRect.height;
- location.left = rect.left;
- break;
- case LAYOUT.RIGHT_BOTTOM:
- location.top = rect.top + rect.height - panelRect.height;
- location.left = rect.left + rect.width - panelRect.width;
- break;
- }
- return this.__correctionLocation(location);
- },
- __getBoundRect: function() {
- var width = -1, height = -1, view = null;
- if (this.__options.bound.tagName.toLowerCase() === "body") {
- view = Utils.getView(this.__options.bound);
- width = $(view).width();
- height = $(view).height();
- return {
- top: 0,
- left: 0,
- right: width,
- bottom: height,
- width: width,
- height: height
- };
- } else {
- return Utils.getRect(this.__options.bound);
- }
- },
-
- __correctionLocation: function(location) {
- var panelRect = Utils.getRect(this.__element), targetRect = Utils.getRect(this.__target), boundRect = this.__getBoundRect();
- switch (this.__layout) {
- case LAYOUT.LEFT_TOP:
- case LAYOUT.LEFT_BOTTOM:
- if (location.left + panelRect.width > boundRect.right) {
- location.left += targetRect.width - panelRect.width;
- }
- break;
- case LAYOUT.RIGHT_TOP:
- case LAYOUT.RIGHT_BOTTOM:
- if (location.left < boundRect.left) {
- location.left = targetRect.left;
- }
- break;
- }
- return location;
- }
- });
- }
- };
- _p[55] = {
- value: function(require) {
- var $ = _p.r(4), CONF = _p.r(12), Panel = _p.r(51), PPanel = _p.r(54), Button = _p.r(37), Creator = _p.r(0), Mask = _p.r(49);
- return _p.r(13).createClass("SelectMenu", {
- base: Panel,
- constructor: function(options) {
- var defaultOptions = {
-
- bed: {
- className: "fui-select-menu-bed"
- },
- button: {
- className: "fui-select-menu-btn"
- },
- events: [ "btnclick" ],
- selected: -1
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- show: function() {
- this.__widgetMenu.show();
- this.__mask.show();
- },
- hide: function() {
- this.__widgetMenu.hide();
- this.__mask.hide();
- },
- getValue: function() {
- var selectedWidet = this.__widgets[this.__selected];
- return selectedWidet ? selectedWidet.getValue() : null;
- },
- getSelected: function() {
- return this.__widgets[this.__selected];
- },
- select: function(index) {
- var widget = this.__widgets[index], className = "fui-select-menu-selected", oldIndex = this.__selected, oldSelected = this.__widgets[this.__selected], bedElement = this.__bed.getElement();
- if (!widget) {
- return this;
- }
- if (oldSelected) {
- oldSelected.removeClass(className);
- }
- bedElement.innerHTML = "";
- bedElement.appendChild(widget.cloneElement());
- widget.addClass(className);
- this.__selected = index;
- this.trigger("select", {
- index: index,
- widget: widget
- });
- if (this.__selected !== oldIndex) {
- this.trigger("change", {
- from: {
- index: oldIndex,
- widget: oldSelected
- },
- to: {
- index: index,
- widget: widget
- }
- });
- }
- return this;
- },
- selectByWidget: function(widget) {
- return this.select(this.indexOf(widget));
- },
- selectByValue: function(value) {
- var index = -1;
- $.each(this.__widgets, function(i, widget) {
- if (widget.getValue() === value) {
- index = i;
- return false;
- }
- });
- return this.select(index);
- },
- __render: function() {
- this.__bed = new Panel(this.__options.bed);
- this.__dropBtn = new Button(this.__options.button);
- this.__widgetMenu = new PPanel({
- className: "fui-select-menu-container",
- layout: CONF.layout.LEFT_TOP,
- column: this.__column
- });
- this.__mask = new Mask();
- var widgets = this.__initWidgets();
- this.callBase();
- $(this.__element).addClass(CONF.classPrefix + "select-menu");
- this.appendWidgets([ this.__bed, this.__dropBtn, this.__mask, this.__widgetMenu ]);
- this.__widgets = [];
- this.__oldContentElement = this.__contentElement;
- this.__contentElement = this.__widgetMenu;
- this.appendWidgets(widgets);
- this.__widgetMenu.positionTo(this.getElement());
- if (!$.isNumeric(this.__options.selected)) {
- this.__bed.appendWidget(Creator.parse(this.__options.selected));
- } else if (this.__options.selected != -1) {
- this.select(this.__options.selected);
- }
- },
- __initWidgets: function() {
- var widgets = [];
- if (!this.__options.widgets) {
- return;
- }
- $.each(this.__options.widgets, function(index, widget) {
- widgets.push(Creator.parse(widget));
- });
- return widgets;
- },
- __initEvent: function() {
- this.callBase();
- var _self = this;
- this.__dropBtn.on("btnclick", function() {
- _self.show();
- });
- this.__mask.on("click", function() {
- _self.hide();
- });
- this.__widgetMenu.on(this.__options.events.join(" "), function(e) {
- var target = e.target;
- if (target === _self.__oldContentElement || target === _self.getElement) {
- return;
- }
- e.stopPropagation();
- _self.selectByWidget(e.widget);
- _self.hide();
- return false;
- });
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "SelectMenu";
-
- this.__bed = null;
-
- this.__dropBtn = null;
- this.__widgetMenu = null;
- this.__mask = null;
- this.__widgets = [];
- this.__selected = -1;
- this.__oldContentElement = null;
- this.__column = this.__options.column;
- delete this.__options.column;
- }
- });
- }
- };
- _p[56] = {
- value: function(require) {
- var Utils = _p.r(13), separatorTpl = _p.r(31), $ = _p.r(4);
- return Utils.createClass("Separator", {
- base: _p.r(60),
- constructor: function(options) {
- var defaultOptions = {
- width: 1,
- height: "100%",
- bgcolor: "#e1e1e1"
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "Separator";
- this.__tpl = separatorTpl;
- }
- });
- }
- };
- _p[57] = {
- value: function(require) {
- var $ = _p.r(4), CONF = _p.r(12), tpl = _p.r(32), Button = _p.r(37), Input = _p.r(45), Panel = _p.r(51);
- return _p.r(13).createClass("SpinButton", {
- base: _p.r(60),
- constructor: function(options) {
- var defaultOptions = {
- suffix: null,
- selected: -1,
- items: []
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- getValue: function() {
- return this.__options.items[this.__currentSelected] || null;
- },
-
- setValue: function(value) {},
- select: function(index) {
- this.__update(index);
- },
-
- selectByValue: function(value) {
- value = value + "";
- this.__update($.inArray(value, this.__options.items));
- },
- __render: function() {
- this.callBase();
- this.__buttons = [ new Button({
- className: CONF.classPrefix + "spin-up-btn"
- }), new Button({
- className: CONF.classPrefix + "spin-down-btn"
- }) ];
- this.__inputWidget = new Input();
- this.__panelWidget = new Panel({
- column: true
- });
- this.__inputWidget.appendTo(this.__element);
- this.__panelWidget.appendWidget(this.__buttons[0]);
- this.__panelWidget.appendWidget(this.__buttons[1]);
- this.__panelWidget.appendTo(this.__element);
- this.__initSelected(this.__options.selected);
- },
- __initEvent: function() {
- var _self = this;
- this.callBase();
- this.__buttons[0].on("btnclick", function() {
- _self.__update(_self.__currentSelected - 1);
- });
- this.__buttons[1].on("btnclick", function() {
- _self.__update(_self.__currentSelected + 1);
- });
- },
- __initSelected: function(index) {
- this.__update(index, false);
- },
- __update: function(index, isTrigger) {
- var oldIndex = -1, value = null, toValue = null;
- if (index < 0 || index >= this.__options.items.length) {
- return;
- }
- oldIndex = this.__currentSelected;
- this.__currentSelected = index;
- toValue = this.__options.items[this.__currentSelected];
- value = toValue + " " + (this.__options.suffix || "");
- this.__inputWidget.setValue(value);
- if (isTrigger !== false) {
- this.trigger("change", {
- from: this.__options.items[oldIndex] || null,
- to: toValue
- });
- }
- },
- __initOptions: function() {
- var items = this.__options.items;
- this.callBase();
- this.widgetName = "SpinButton";
- this.__tpl = tpl;
- this.__buttons = [];
- this.__panelWidget = null;
- this.__inputWidget = null;
- this.__currentSelected = -1;
- $.each(items, function(index, val) {
- items[index] = val + "";
- });
- }
- });
- }
- };
- _p[58] = {
- value: function(require) {
- var $ = _p.r(4), CONF = _p.r(12), tpl = _p.r(33), Button = _p.r(37), Panel = _p.r(51);
- return _p.r(13).createClass("Tabs", {
- base: _p.r(60),
- constructor: function(options) {
- var defaultOptions = {
- selected: 0,
- buttons: [],
- panels: []
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
- getButtons: function() {
- return this.__btns;
- },
- getButton: function(index) {
- return this.getButtons()[index] || null;
- },
- getButtonByValue: function(value) {
- var button = null;
- $.each(this.__btns, function(i, btn) {
- if (btn.getValue() === value) {
- button = btn;
- return false;
- }
- });
- return button;
- },
- getPanels: function() {
- return this.__panels;
- },
- getPanel: function(index) {
- return this.getPanels()[index] || null;
- },
- getPanelByValue: function(value) {
- var panel = null;
- $.each(this.__panels, function(i, pan) {
- if (pan.getValue() === value) {
- panel = pan;
- return false;
- }
- });
- return panel;
- },
- getSelectedIndex: function() {
- return this.__selected;
- },
- getSelected: function() {
- var index = this.getSelectedIndex();
- return {
- button: this.getButton(index),
- panel: this.getPanel(index)
- };
- },
- appendTab: function(tabOpt) {
- tabOpt.panels = tabOpt.panels || [];
- return this.__renderByOptions(tabOpt);
- },
- removeTab: function(index) {
- if (index < 0) {
- return null;
- }
- var btn = this.__btns.splice(index, 1), panel = this.__panels.splice(index, 1);
- if (!btn.length) {
- return null;
- }
- btn = btn[0];
- panel = panel[0];
- btn.remove();
- panel.remove();
- return {
- button: btn,
- panel: panel
- };
- },
-
- select: function(index) {
- var toInfo = null;
- if (!this.__selectItem(index)) {
- return this;
- }
- toInfo = this.__getInfo(index);
- this.trigger("tabsselect", toInfo);
- if (this.__prevSelected !== this.__selected) {
- this.trigger("tabschange", {
- from: this.__getInfo(this.__prevSelected),
- to: toInfo
- });
- }
- return this;
- },
- getIndexByButton: function(btn) {
- return $.inArray(btn, this.__btns);
- },
-
- appendButtonTo: function(container) {
- $.each(this.__btns, function(index, btn) {
- btn.appendTo(container);
- });
- },
- appendPanelTo: function(container) {
- $.each(this.__panels, function(index, panel) {
- panel.appendTo(container);
- });
- },
- __render: function() {
- this.callBase();
- this.__btnWrap = $(".fui-tabs-button-wrap", this.__element)[0];
- this.__panelWrap = $(".fui-tabs-panel-wrap", this.__element)[0];
- this.__renderByOptions(this.__options);
- this.__selectItem(this.__options.selected);
- },
- __renderByOptions: function(options) {
- var _self = this, mapping = [], btns = this.__btns, panels = this.__panels, btnWrap = this.__btnWrap, panelWrap = this.__panelWrap;
- $.each(options.buttons, function(index, opt) {
- var btn = null, panel = null;
- if (typeof opt !== "object") {
- opt = {
- label: opt
- };
- }
- btn = new Button(opt);
- btn.on("click", function() {
- _self.select(_self.getIndexByButton(this));
- });
- opt = options.panels[index] || {};
- opt.hide = true;
- panel = new Panel(opt);
- btns.push(btn);
- panels.push(panel);
- mapping.push({
- button: btn,
- panel: panel
- });
- btn.appendTo(btnWrap);
- panel.appendTo(panelWrap);
- });
- return mapping;
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "Tabs";
- this.__tpl = tpl;
- this.__btns = [];
- this.__panels = [];
- this.__prevSelected = -1;
- this.__selected = -1;
- this.__btnWrap = null;
- this.__panelWrap = null;
-
- if (this.__options.panels === null) {
- this.__options.panels = [];
- this.__options.panels.length = this.__options.buttons.length;
- }
- },
- __selectItem: function(index) {
- var btn = this.getButton(index), prevBtn = this.getButton(this.__selected), className = CONF.classPrefix + "selected";
- if (!btn) {
- return false;
- }
- if (prevBtn) {
- prevBtn.removeClass(className);
- this.getPanel(this.__selected).hide();
- }
- btn.addClass(className);
- this.getPanel(index).show();
- this.__prevSelected = this.__selected;
- this.__selected = index;
- return true;
- },
-
- __getInfo: function(index) {
- return {
- index: index,
- button: this.getButton(index),
- panel: this.getPanel(index)
- };
- }
- });
- }
- };
- _p[59] = {
- value: function(require) {
- var $ = _p.r(4), CONF = _p.r(12);
- return _p.r(13).createClass("ToggleButton", {
- base: _p.r(37),
- constructor: function(options) {
- var defaultOptions = {
-
- pressed: false
- };
- options = $.extend({}, defaultOptions, options);
- this.callBase(options);
- },
-
- isPressed: function() {
- return this.__state;
- },
-
- press: function() {
- var className = CONF.classPrefix + "button-pressed";
- $(this.__element).addClass(className);
- this.__updateState(true);
- },
-
- bounce: function() {
- var className = CONF.classPrefix + "button-pressed";
- $(this.__element).removeClass(className);
- this.__updateState(false);
- },
- toggle: function() {
- if (this.__state) {
- this.bounce();
- } else {
- this.press();
- }
- },
- __initOptions: function() {
- this.callBase();
- this.widgetName = "ToggleButton";
-
- this.__state = false;
- },
- __render: function() {
- this.callBase();
- $(this.__element).addClass(CONF.classPrefix + "toggle-button");
- this.__initButtonState();
- return this;
- },
- __initButtonState: function() {
- if (!this.__options.pressed) {
- return;
- }
-
- $(this.__element).addClass(CONF.classPrefix + "button-pressed");
- this.__state = true;
- },
-
- __initEvent: function() {
- this.callBase();
- this.on("click", function() {
- this.toggle();
- });
- },
- __updateState: function(state) {
- state = !!state;
- this.__state = state;
- this.trigger("change", state, !state);
- }
- });
- }
- };
- _p[60] = {
- value: function(require) {
- var prefix = "_fui_", uid = 0, CONF = _p.r(12), FUI_NS = _p.r(11), $ = _p.r(4), Utils = _p.r(13);
- var Widget = Utils.createClass("Widget", {
- constructor: function(options) {
- var defaultOptions = {
- id: null,
- className: "",
- disabled: false,
- preventDefault: false,
- text: "",
- value: null,
- hide: false,
- width: null,
- height: null
- };
- this.__widgetType = "widget";
- this.__tpl = "";
- this.__compiledTpl = "";
- this.__options = {};
- this.__element = null;
-
- this.__allow_focus = !!CONF.allowFocus;
- this.widgetName = "Widget";
- this.__extendOptions(defaultOptions, options);
- this.__initOptions();
- this.__render();
- this.__initEvent();
- this.__initWidgets && this.__initWidgets();
- },
- getId: function() {
- return this.id;
- },
- getValue: function() {
- return this.__options.value;
- },
- getOptions: function() {
- return this.__options;
- },
- setValue: function(value) {
- this.__options.value = value;
- return this;
- },
- show: function() {
- this.__show();
- return this;
- },
- hide: function() {
- this.__hide();
- return this;
- },
- addClass: function(className) {
- $(this.__element).addClass(className);
- return this;
- },
- removeClass: function(className) {
- $(this.__element).removeClass(className);
- return this;
- },
- setStyle: function() {
- $.fn.css.apply($(this.__element), arguments);
- return this;
- },
- getStyle: function() {
- return $.fn.css.apply($(this.__element), arguments);
- },
-
- isDisabled: function() {
- return this.__options.disabled;
- },
-
- enable: function() {
- this.__options.disabled = false;
- $(this.__element).removeClass(CONF.classPrefix + "disabled");
- return this;
- },
-
- disable: function() {
- this.__options.disabled = true;
- $(this.__element).addClass(CONF.classPrefix + "disabled");
- return this;
- },
- cloneElement: function() {
- return this.__element.cloneNode(true);
- },
-
- getElement: function() {
- return this.__element;
- },
- appendTo: function(container) {
- if (Utils.isElement(container)) {
- container.appendChild(this.__element);
- } else if (container instanceof Widget) {
- container.__appendChild(this);
- } else {
- throw new Error("TypeError: Widget.appendTo()");
- }
- return this;
- },
- remove: function() {
- var parent = this.__element.parentNode;
- if (parent) {
- parent.removeChild(this.__element);
- }
- return this;
- },
- off: function(type, cb) {
- $(this.__element).off(cb && cb.__fui_listener);
- return this;
- },
- on: function(type, cb) {
- if (!this.__options.preventDefault) {
- this.__on(type, cb);
- }
- return this;
- },
- __initOptions: function() {},
-
- __render: function() {
- var $ele = null, tpl = this.__tpl, opts = this.__options, className = null;
- this.id = this.__id();
-
- FUI_NS.__registerInstance(this);
- this.__compiledTpl = Utils.Tpl.compile(tpl, opts);
- this.__element = $(this.__compiledTpl)[0];
- this.__element.setAttribute("id", this.id);
- $ele = $(this.__element);
- if (opts.disabled) {
- $ele.addClass(CONF.classPrefix + "disabled");
- }
- $ele.addClass(CONF.classPrefix + "widget");
-
- className = opts.className;
- if (className.length > 0) {
- if ($.isArray(className)) {
- $ele.addClass(className.join(" "));
- } else {
- $ele.addClass(className);
- }
- }
- this.__initBasicEnv();
- if (opts.hide) {
- this.__hide();
- }
- if (opts.style) {
- this.setStyle(opts.style);
- }
- return this;
- },
-
- __appendChild: function(childWidget) {
- return this.__element.appendChild(childWidget.getElement());
- },
- __initEvent: function() {
- this.on("mousedown", function(e) {
- var tagName = e.target.tagName.toLowerCase();
- if (!CONF.control[tagName] && !this.__allowFocus()) {
- e.preventDefault();
- } else {
- e.stopPropagation();
- }
- });
- },
- __on: function(type, cb) {
- var _self = this;
- cb.__fui_listener = function(e, widget) {
- var params = [];
- for (var i = 0, len = arguments.length; i < len; i++) {
- if (i !== 1) {
- params.push(arguments[i]);
- }
- }
- e.widget = widget;
- if (!_self.isDisabled()) {
- return cb.apply(_self, params);
- }
- };
- $(this.__element).on(type, cb.__fui_listener);
- return this;
- },
- trigger: function(type, params) {
- if (!this.__options.preventDefault) {
- this.__trigger.apply(this, arguments);
- }
- return this;
- },
- __allowShowTitle: function() {
- return true;
- },
- __allowFocus: function() {
- return !!this.__allow_focus;
- },
- __trigger: function(type, params) {
- var args = [].slice.call(arguments, 1);
- $(this.__element).trigger(type, [ this ].concat(args));
- return this;
- },
- __triggerHandler: function(type, params) {
- var args = [ this ].concat([].slice.call(arguments, 1));
- return $(this.__element).triggerHandler(type, args);
- },
-
- __fire: function(type, handler) {
- var result = {
- cancel: false
- };
- if (/^(before|after)/.test(type)) {
- return this;
- }
- this.__trigger("before" + type, result);
- if (result.cancel === true) {
- return this;
- }
- result = handler.call(this, type);
- this.__trigger(type);
- this.__trigger("after" + type, result);
- return this;
- },
- __extendOptions: function() {
- var args = [ {}, this.__options ], params = [ true ];
- args = args.concat([].slice.call(arguments, 0));
- for (var i = 0, len = args.length; i < len; i++) {
- if (typeof args[i] !== "string") {
- params.push(args[i]);
- }
- }
- this.__options = $.extend.apply($, params);
- },
- __hide: function() {
- $(this.__element).addClass(CONF.classPrefix + "hide");
- },
- __show: function() {
- $(this.__element).removeClass(CONF.classPrefix + "hide");
- },
- __initBasicEnv: function() {
- if (this.__options.text && this.__allowShowTitle()) {
- this.__element.setAttribute("title", this.__options.text);
- }
- if (this.__options.width) {
- this.__element.style.width = this.__options.width + "px";
- }
- if (this.__options.height) {
- this.__element.style.height = this.__options.height + "px";
- }
- if (this.widgetName) {
- this.__element.setAttribute("rule", this.widgetName);
- }
- },
- __id: function() {
- return this.__options.id || generatorId();
- }
- });
-
- function generatorId() {
- return prefix + ++uid;
- }
- return Widget;
- }
- };
- _p[61] = {
- value: function(require) {
- _p.r(1);
- _p.r(2);
- }
- };
- var moduleMapping = {
- "fui.export": 61
- };
- function use(name) {
- _p.r([ moduleMapping[name] ]);
- }
- use( 'fui.export' );})();
- ;(function() {
- var block = {
- newline: /^\n+/,
- code: /^( {4}[^\n]+\n*)+/,
- fences: noop,
- hr: /^( *[-*_]){3,} *(?:\n+|$)/,
- heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
- nptable: noop,
- lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
- blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
- list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
- html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
- def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
- table: noop,
- paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
- text: /^[^\n]+/
- };
- block.bullet = /(?:[*+-]|\d+\.)/;
- block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
- block.item = replace(block.item, 'gm')
- (/bull/g, block.bullet)
- ();
- block.list = replace(block.list)
- (/bull/g, block.bullet)
- ('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')
- ('def', '\\n+(?=' + block.def.source + ')')
- ();
- block.blockquote = replace(block.blockquote)
- ('def', block.def)
- ();
- block._tag = '(?!(?:'
- + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
- + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
- + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b';
- block.html = replace(block.html)
- ('comment', /<!--[\s\S]*?-->/)
- ('closed', /<(tag)[\s\S]+?<\/\1>/)
- ('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)
- (/tag/g, block._tag)
- ();
- block.paragraph = replace(block.paragraph)
- ('hr', block.hr)
- ('heading', block.heading)
- ('lheading', block.lheading)
- ('blockquote', block.blockquote)
- ('tag', '<' + block._tag)
- ('def', block.def)
- ();
- /**
- * Normal Block Grammar
- */
- block.normal = merge({}, block);
- /**
- * GFM Block Grammar
- */
- block.gfm = merge({}, block.normal, {
- fences: /^ *(`{3,}|~{3,}) *(\S+)? *\n([\s\S]+?)\s*\1 *(?:\n+|$)/,
- paragraph: /^/
- });
- block.gfm.paragraph = replace(block.paragraph)
- ('(?!', '(?!'
- + block.gfm.fences.source.replace('\\1', '\\2') + '|'
- + block.list.source.replace('\\1', '\\3') + '|')
- ();
- /**
- * GFM + Tables Block Grammar
- */
- block.tables = merge({}, block.gfm, {
- nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,
- table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/
- });
- /**
- * Block Lexer
- */
- function Lexer(options) {
- this.tokens = [];
- this.tokens.links = {};
- this.options = options || marked.defaults;
- this.rules = block.normal;
- if (this.options.gfm) {
- if (this.options.tables) {
- this.rules = block.tables;
- } else {
- this.rules = block.gfm;
- }
- }
- }
- /**
- * Expose Block Rules
- */
- Lexer.rules = block;
- /**
- * Static Lex Method
- */
- Lexer.lex = function(src, options) {
- var lexer = new Lexer(options);
- return lexer.lex(src);
- };
- /**
- * Preprocessing
- */
- Lexer.prototype.lex = function(src) {
- src = src
- .replace(/\r\n|\r/g, '\n')
- .replace(/\t/g, ' ')
- .replace(/\u00a0/g, ' ')
- .replace(/\u2424/g, '\n');
- return this.token(src, true);
- };
- /**
- * Lexing
- */
- Lexer.prototype.token = function(src, top, bq) {
- var src = src.replace(/^ +$/gm, '')
- , next
- , loose
- , cap
- , bull
- , b
- , item
- , space
- , i
- , l;
- while (src) {
- // newline
- if (cap = this.rules.newline.exec(src)) {
- src = src.substring(cap[0].length);
- if (cap[0].length > 1) {
- this.tokens.push({
- type: 'space'
- });
- }
- }
- // code
- if (cap = this.rules.code.exec(src)) {
- src = src.substring(cap[0].length);
- cap = cap[0].replace(/^ {4}/gm, '');
- this.tokens.push({
- type: 'code',
- text: !this.options.pedantic
- ? cap.replace(/\n+$/, '')
- : cap
- });
- continue;
- }
- // fences (gfm)
- if (cap = this.rules.fences.exec(src)) {
- src = src.substring(cap[0].length);
- this.tokens.push({
- type: 'code',
- lang: cap[2],
- text: cap[3]
- });
- continue;
- }
- // heading
- if (cap = this.rules.heading.exec(src)) {
- src = src.substring(cap[0].length);
- this.tokens.push({
- type: 'heading',
- depth: cap[1].length,
- text: cap[2]
- });
- continue;
- }
- // table no leading pipe (gfm)
- if (top && (cap = this.rules.nptable.exec(src))) {
- src = src.substring(cap[0].length);
- item = {
- type: 'table',
- header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
- align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
- cells: cap[3].replace(/\n$/, '').split('\n')
- };
- for (i = 0; i < item.align.length; i++) {
- if (/^ *-+: *$/.test(item.align[i])) {
- item.align[i] = 'right';
- } else if (/^ *:-+: *$/.test(item.align[i])) {
- item.align[i] = 'center';
- } else if (/^ *:-+ *$/.test(item.align[i])) {
- item.align[i] = 'left';
- } else {
- item.align[i] = null;
- }
- }
- for (i = 0; i < item.cells.length; i++) {
- item.cells[i] = item.cells[i].split(/ *\| */);
- }
- this.tokens.push(item);
- continue;
- }
- // lheading
- if (cap = this.rules.lheading.exec(src)) {
- src = src.substring(cap[0].length);
- this.tokens.push({
- type: 'heading',
- depth: cap[2] === '=' ? 1 : 2,
- text: cap[1]
- });
- continue;
- }
- // hr
- if (cap = this.rules.hr.exec(src)) {
- src = src.substring(cap[0].length);
- this.tokens.push({
- type: 'hr'
- });
- continue;
- }
- // blockquote
- if (cap = this.rules.blockquote.exec(src)) {
- src = src.substring(cap[0].length);
- this.tokens.push({
- type: 'blockquote_start'
- });
- cap = cap[0].replace(/^ *> ?/gm, '');
- // Pass `top` to keep the current
- // "toplevel" state. This is exactly
- // how markdown.pl works.
- this.token(cap, top, true);
- this.tokens.push({
- type: 'blockquote_end'
- });
- continue;
- }
- // list
- if (cap = this.rules.list.exec(src)) {
- src = src.substring(cap[0].length);
- bull = cap[2];
- this.tokens.push({
- type: 'list_start',
- ordered: bull.length > 1
- });
- // Get each top-level item.
- cap = cap[0].match(this.rules.item);
- next = false;
- l = cap.length;
- i = 0;
- for (; i < l; i++) {
- item = cap[i];
- // Remove the list item's bullet
- // so it is seen as the next token.
- space = item.length;
- item = item.replace(/^ *([*+-]|\d+\.) +/, '');
- // Outdent whatever the
- // list item contains. Hacky.
- if (~item.indexOf('\n ')) {
- space -= item.length;
- item = !this.options.pedantic
- ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
- : item.replace(/^ {1,4}/gm, '');
- }
- // Determine whether the next list item belongs here.
- // Backpedal if it does not belong in this list.
- if (this.options.smartLists && i !== l - 1) {
- b = block.bullet.exec(cap[i + 1])[0];
- if (bull !== b && !(bull.length > 1 && b.length > 1)) {
- src = cap.slice(i + 1).join('\n') + src;
- i = l - 1;
- }
- }
- // Determine whether item is loose or not.
- // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
- // for discount behavior.
- loose = next || /\n\n(?!\s*$)/.test(item);
- if (i !== l - 1) {
- next = item.charAt(item.length - 1) === '\n';
- if (!loose) loose = next;
- }
- this.tokens.push({
- type: loose
- ? 'loose_item_start'
- : 'list_item_start'
- });
- // Recurse.
- this.token(item, false, bq);
- this.tokens.push({
- type: 'list_item_end'
- });
- }
- this.tokens.push({
- type: 'list_end'
- });
- continue;
- }
- // html
- if (cap = this.rules.html.exec(src)) {
- src = src.substring(cap[0].length);
- this.tokens.push({
- type: this.options.sanitize
- ? 'paragraph'
- : 'html',
- pre: cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style',
- text: cap[0]
- });
- continue;
- }
- // def
- if ((!bq && top) && (cap = this.rules.def.exec(src))) {
- src = src.substring(cap[0].length);
- this.tokens.links[cap[1].toLowerCase()] = {
- href: cap[2],
- title: cap[3]
- };
- continue;
- }
- // table (gfm)
- if (top && (cap = this.rules.table.exec(src))) {
- src = src.substring(cap[0].length);
- item = {
- type: 'table',
- header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
- align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
- cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
- };
- for (i = 0; i < item.align.length; i++) {
- if (/^ *-+: *$/.test(item.align[i])) {
- item.align[i] = 'right';
- } else if (/^ *:-+: *$/.test(item.align[i])) {
- item.align[i] = 'center';
- } else if (/^ *:-+ *$/.test(item.align[i])) {
- item.align[i] = 'left';
- } else {
- item.align[i] = null;
- }
- }
- for (i = 0; i < item.cells.length; i++) {
- item.cells[i] = item.cells[i]
- .replace(/^ *\| *| *\| *$/g, '')
- .split(/ *\| */);
- }
- this.tokens.push(item);
- continue;
- }
- // top-level paragraph
- if (top && (cap = this.rules.paragraph.exec(src))) {
- src = src.substring(cap[0].length);
- this.tokens.push({
- type: 'paragraph',
- text: cap[1].charAt(cap[1].length - 1) === '\n'
- ? cap[1].slice(0, -1)
- : cap[1]
- });
- continue;
- }
- // text
- if (cap = this.rules.text.exec(src)) {
- // Top-level should never reach here.
- src = src.substring(cap[0].length);
- this.tokens.push({
- type: 'text',
- text: cap[0]
- });
- continue;
- }
- if (src) {
- throw new
- Error('Infinite loop on byte: ' + src.charCodeAt(0));
- }
- }
- return this.tokens;
- };
- /**
- * Inline-Level Grammar
- */
- var inline = {
- escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
- autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
- url: noop,
- tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
- link: /^!?\[(inside)\]\(href\)/,
- reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
- nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
- strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
- em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
- code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
- br: /^ {2,}\n(?!\s*$)/,
- del: noop,
- text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
- };
- inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;
- inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
- inline.link = replace(inline.link)
- ('inside', inline._inside)
- ('href', inline._href)
- ();
- inline.reflink = replace(inline.reflink)
- ('inside', inline._inside)
- ();
- /**
- * Normal Inline Grammar
- */
- inline.normal = merge({}, inline);
- /**
- * Pedantic Inline Grammar
- */
- inline.pedantic = merge({}, inline.normal, {
- strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
- em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/
- });
- /**
- * GFM Inline Grammar
- */
- inline.gfm = merge({}, inline.normal, {
- escape: replace(inline.escape)('])', '~|])')(),
- url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
- del: /^~~(?=\S)([\s\S]*?\S)~~/,
- text: replace(inline.text)
- (']|', '~]|')
- ('|', '|https?://|')
- ()
- });
- /**
- * GFM + Line Breaks Inline Grammar
- */
- inline.breaks = merge({}, inline.gfm, {
- br: replace(inline.br)('{2,}', '*')(),
- text: replace(inline.gfm.text)('{2,}', '*')()
- });
- /**
- * Inline Lexer & Compiler
- */
- function InlineLexer(links, options) {
- this.options = options || marked.defaults;
- this.links = links;
- this.rules = inline.normal;
- this.renderer = this.options.renderer || new Renderer;
- this.renderer.options = this.options;
- if (!this.links) {
- throw new
- Error('Tokens array requires a `links` property.');
- }
- if (this.options.gfm) {
- if (this.options.breaks) {
- this.rules = inline.breaks;
- } else {
- this.rules = inline.gfm;
- }
- } else if (this.options.pedantic) {
- this.rules = inline.pedantic;
- }
- }
- /**
- * Expose Inline Rules
- */
- InlineLexer.rules = inline;
- /**
- * Static Lexing/Compiling Method
- */
- InlineLexer.output = function(src, links, options) {
- var inline = new InlineLexer(links, options);
- return inline.output(src);
- };
- /**
- * Lexing/Compiling
- */
- InlineLexer.prototype.output = function(src) {
- var out = ''
- , link
- , text
- , href
- , cap;
- while (src) {
- // escape
- if (cap = this.rules.escape.exec(src)) {
- src = src.substring(cap[0].length);
- out += cap[1];
- continue;
- }
- // autolink
- if (cap = this.rules.autolink.exec(src)) {
- src = src.substring(cap[0].length);
- if (cap[2] === '@') {
- text = cap[1].charAt(6) === ':'
- ? this.mangle(cap[1].substring(7))
- : this.mangle(cap[1]);
- href = this.mangle('mailto:') + text;
- } else {
- text = escape(cap[1]);
- href = text;
- }
- out += this.renderer.link(href, null, text);
- continue;
- }
- // url (gfm)
- if (!this.inLink && (cap = this.rules.url.exec(src))) {
- src = src.substring(cap[0].length);
- text = escape(cap[1]);
- href = text;
- out += this.renderer.link(href, null, text);
- continue;
- }
- // tag
- if (cap = this.rules.tag.exec(src)) {
- if (!this.inLink && /^<a /i.test(cap[0])) {
- this.inLink = true;
- } else if (this.inLink && /^<\/a>/i.test(cap[0])) {
- this.inLink = false;
- }
- src = src.substring(cap[0].length);
- out += this.options.sanitize
- ? escape(cap[0])
- : cap[0];
- continue;
- }
- // link
- if (cap = this.rules.link.exec(src)) {
- src = src.substring(cap[0].length);
- this.inLink = true;
- out += this.outputLink(cap, {
- href: cap[2],
- title: cap[3]
- });
- this.inLink = false;
- continue;
- }
- // reflink, nolink
- if ((cap = this.rules.reflink.exec(src))
- || (cap = this.rules.nolink.exec(src))) {
- src = src.substring(cap[0].length);
- link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
- link = this.links[link.toLowerCase()];
- if (!link || !link.href) {
- out += cap[0].charAt(0);
- src = cap[0].substring(1) + src;
- continue;
- }
- this.inLink = true;
- out += this.outputLink(cap, link);
- this.inLink = false;
- continue;
- }
- // strong
- if (cap = this.rules.strong.exec(src)) {
- src = src.substring(cap[0].length);
- out += this.renderer.strong(this.output(cap[2] || cap[1]));
- continue;
- }
- // em
- if (cap = this.rules.em.exec(src)) {
- src = src.substring(cap[0].length);
- out += this.renderer.em(this.output(cap[2] || cap[1]));
- continue;
- }
- // code
- if (cap = this.rules.code.exec(src)) {
- src = src.substring(cap[0].length);
- out += this.renderer.codespan(escape(cap[2], true));
- continue;
- }
- // br
- if (cap = this.rules.br.exec(src)) {
- src = src.substring(cap[0].length);
- out += this.renderer.br();
- continue;
- }
- // del (gfm)
- if (cap = this.rules.del.exec(src)) {
- src = src.substring(cap[0].length);
- out += this.renderer.del(this.output(cap[1]));
- continue;
- }
- // text
- if (cap = this.rules.text.exec(src)) {
- src = src.substring(cap[0].length);
- out += escape(this.smartypants(cap[0]));
- continue;
- }
- if (src) {
- throw new
- Error('Infinite loop on byte: ' + src.charCodeAt(0));
- }
- }
- return out;
- };
- /**
- * Compile Link
- */
- InlineLexer.prototype.outputLink = function(cap, link) {
- var href = escape(link.href)
- , title = link.title ? escape(link.title) : null;
- return cap[0].charAt(0) !== '!'
- ? this.renderer.link(href, title, this.output(cap[1]))
- : this.renderer.image(href, title, escape(cap[1]));
- };
- /**
- * Smartypants Transformations
- */
- InlineLexer.prototype.smartypants = function(text) {
- if (!this.options.smartypants) return text;
- return text
- // em-dashes
- .replace(/--/g, '\u2014')
- // opening singles
- .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
- // closing singles & apostrophes
- .replace(/'/g, '\u2019')
- // opening doubles
- .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
- // closing doubles
- .replace(/"/g, '\u201d')
- // ellipses
- .replace(/\.{3}/g, '\u2026');
- };
- /**
- * Mangle Links
- */
- InlineLexer.prototype.mangle = function(text) {
- var out = ''
- , l = text.length
- , i = 0
- , ch;
- for (; i < l; i++) {
- ch = text.charCodeAt(i);
- if (Math.random() > 0.5) {
- ch = 'x' + ch.toString(16);
- }
- out += '&#' + ch + ';';
- }
- return out;
- };
- /**
- * Renderer
- */
- function Renderer(options) {
- this.options = options || {};
- }
- Renderer.prototype.code = function(code, lang, escaped) {
- if (this.options.highlight) {
- var out = this.options.highlight(code, lang);
- if (out != null && out !== code) {
- escaped = true;
- code = out;
- }
- }
- if (!lang) {
- return '<pre><code>'
- + (escaped ? code : escape(code, true))
- + '\n</code></pre>';
- }
- return '<pre><code class="'
- + this.options.langPrefix
- + escape(lang, true)
- + '">'
- + (escaped ? code : escape(code, true))
- + '\n</code></pre>\n';
- };
- Renderer.prototype.blockquote = function(quote) {
- return '<blockquote>\n' + quote + '</blockquote>\n';
- };
- Renderer.prototype.html = function(html) {
- return html;
- };
- Renderer.prototype.heading = function(text, level, raw) {
- return '<h'
- + level
- + ' id="'
- + this.options.headerPrefix
- + raw.toLowerCase().replace(/[^\w]+/g, '-')
- + '">'
- + text
- + '</h'
- + level
- + '>\n';
- };
- Renderer.prototype.hr = function() {
- return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
- };
- Renderer.prototype.list = function(body, ordered) {
- var type = ordered ? 'ol' : 'ul';
- return '<' + type + '>\n' + body + '</' + type + '>\n';
- };
- Renderer.prototype.listitem = function(text) {
- return '<li>' + text + '</li>\n';
- };
- Renderer.prototype.paragraph = function(text) {
- return '<p>' + text + '</p>\n';
- };
- Renderer.prototype.table = function(header, body) {
- return '<table>\n'
- + '<thead>\n'
- + header
- + '</thead>\n'
- + '<tbody>\n'
- + body
- + '</tbody>\n'
- + '</table>\n';
- };
- Renderer.prototype.tablerow = function(content) {
- return '<tr>\n' + content + '</tr>\n';
- };
- Renderer.prototype.tablecell = function(content, flags) {
- var type = flags.header ? 'th' : 'td';
- var tag = flags.align
- ? '<' + type + ' style="text-align:' + flags.align + '">'
- : '<' + type + '>';
- return tag + content + '</' + type + '>\n';
- };
- // span level renderer
- Renderer.prototype.strong = function(text) {
- return '<strong>' + text + '</strong>';
- };
- Renderer.prototype.em = function(text) {
- return '<em>' + text + '</em>';
- };
- Renderer.prototype.codespan = function(text) {
- return '<code>' + text + '</code>';
- };
- Renderer.prototype.br = function() {
- return this.options.xhtml ? '<br/>' : '<br>';
- };
- Renderer.prototype.del = function(text) {
- return '<del>' + text + '</del>';
- };
- Renderer.prototype.link = function(href, title, text) {
- if (this.options.sanitize) {
- try {
- var prot = decodeURIComponent(unescape(href))
- .replace(/[^\w:]/g, '')
- .toLowerCase();
- } catch (e) {
- return '';
- }
- if (prot.indexOf('javascript:') === 0) {
- return '';
- }
- }
- var out = '<a href="' + href + '"';
- if (title) {
- out += ' title="' + title + '"';
- }
- out += '>' + text + '</a>';
- return out;
- };
- Renderer.prototype.image = function(href, title, text) {
- var out = '<img src="' + href + '" alt="' + text + '"';
- if (title) {
- out += ' title="' + title + '"';
- }
- out += this.options.xhtml ? '/>' : '>';
- return out;
- };
- /**
- * Parsing & Compiling
- */
- function Parser(options) {
- this.tokens = [];
- this.token = null;
- this.options = options || marked.defaults;
- this.options.renderer = this.options.renderer || new Renderer;
- this.renderer = this.options.renderer;
- this.renderer.options = this.options;
- }
- /**
- * Static Parse Method
- */
- Parser.parse = function(src, options, renderer) {
- var parser = new Parser(options, renderer);
- return parser.parse(src);
- };
- /**
- * Parse Loop
- */
- Parser.prototype.parse = function(src) {
- this.inline = new InlineLexer(src.links, this.options, this.renderer);
- this.tokens = src.reverse();
- var out = '';
- while (this.next()) {
- out += this.tok();
- }
- return out;
- };
- /**
- * Next Token
- */
- Parser.prototype.next = function() {
- return this.token = this.tokens.pop();
- };
- /**
- * Preview Next Token
- */
- Parser.prototype.peek = function() {
- return this.tokens[this.tokens.length - 1] || 0;
- };
- /**
- * Parse Text Tokens
- */
- Parser.prototype.parseText = function() {
- var body = this.token.text;
- while (this.peek().type === 'text') {
- body += '\n' + this.next().text;
- }
- return this.inline.output(body);
- };
- /**
- * Parse Current Token
- */
- Parser.prototype.tok = function() {
- switch (this.token.type) {
- case 'space': {
- return '';
- }
- case 'hr': {
- return this.renderer.hr();
- }
- case 'heading': {
- return this.renderer.heading(
- this.inline.output(this.token.text),
- this.token.depth,
- this.token.text);
- }
- case 'code': {
- return this.renderer.code(this.token.text,
- this.token.lang,
- this.token.escaped);
- }
- case 'table': {
- var header = ''
- , body = ''
- , i
- , row
- , cell
- , flags
- , j;
- // header
- cell = '';
- for (i = 0; i < this.token.header.length; i++) {
- flags = { header: true, align: this.token.align[i] };
- cell += this.renderer.tablecell(
- this.inline.output(this.token.header[i]),
- { header: true, align: this.token.align[i] }
- );
- }
- header += this.renderer.tablerow(cell);
- for (i = 0; i < this.token.cells.length; i++) {
- row = this.token.cells[i];
- cell = '';
- for (j = 0; j < row.length; j++) {
- cell += this.renderer.tablecell(
- this.inline.output(row[j]),
- { header: false, align: this.token.align[j] }
- );
- }
- body += this.renderer.tablerow(cell);
- }
- return this.renderer.table(header, body);
- }
- case 'blockquote_start': {
- var body = '';
- while (this.next().type !== 'blockquote_end') {
- body += this.tok();
- }
- return this.renderer.blockquote(body);
- }
- case 'list_start': {
- var body = ''
- , ordered = this.token.ordered;
- while (this.next().type !== 'list_end') {
- body += this.tok();
- }
- return this.renderer.list(body, ordered);
- }
- case 'list_item_start': {
- var body = '';
- while (this.next().type !== 'list_item_end') {
- body += this.token.type === 'text'
- ? this.parseText()
- : this.tok();
- }
- return this.renderer.listitem(body);
- }
- case 'loose_item_start': {
- var body = '';
- while (this.next().type !== 'list_item_end') {
- body += this.tok();
- }
- return this.renderer.listitem(body);
- }
- case 'html': {
- var html = !this.token.pre && !this.options.pedantic
- ? this.inline.output(this.token.text)
- : this.token.text;
- return this.renderer.html(html);
- }
- case 'paragraph': {
- return this.renderer.paragraph(this.inline.output(this.token.text));
- }
- case 'text': {
- return this.renderer.paragraph(this.parseText());
- }
- }
- };
- /**
- * Helpers
- */
- function escape(html, encode) {
- return html
- .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&')
- .replace(/</g, '<')
- .replace(/>/g, '>')
- .replace(/"/g, '"')
- .replace(/'/g, ''');
- }
- function unescape(html) {
- return html.replace(/&([#\w]+);/g, function(_, n) {
- n = n.toLowerCase();
- if (n === 'colon') return ':';
- if (n.charAt(0) === '#') {
- return n.charAt(1) === 'x'
- ? String.fromCharCode(parseInt(n.substring(2), 16))
- : String.fromCharCode(+n.substring(1));
- }
- return '';
- });
- }
- function replace(regex, opt) {
- regex = regex.source;
- opt = opt || '';
- return function self(name, val) {
- if (!name) return new RegExp(regex, opt);
- val = val.source || val;
- val = val.replace(/(^|[^\[])\^/g, '$1');
- regex = regex.replace(name, val);
- return self;
- };
- }
- function noop() {}
- noop.exec = noop;
- function merge(obj) {
- var i = 1
- , target
- , key;
- for (; i < arguments.length; i++) {
- target = arguments[i];
- for (key in target) {
- if (Object.prototype.hasOwnProperty.call(target, key)) {
- obj[key] = target[key];
- }
- }
- }
- return obj;
- }
- /**
- * Marked
- */
- function marked(src, opt, callback) {
- if (callback || typeof opt === 'function') {
- if (!callback) {
- callback = opt;
- opt = null;
- }
- opt = merge({}, marked.defaults, opt || {});
- var highlight = opt.highlight
- , tokens
- , pending
- , i = 0;
- try {
- tokens = Lexer.lex(src, opt)
- } catch (e) {
- return callback(e);
- }
- pending = tokens.length;
- var done = function(err) {
- if (err) {
- opt.highlight = highlight;
- return callback(err);
- }
- var out;
- try {
- out = Parser.parse(tokens, opt);
- } catch (e) {
- err = e;
- }
- opt.highlight = highlight;
- return err
- ? callback(err)
- : callback(null, out);
- };
- if (!highlight || highlight.length < 3) {
- return done();
- }
- delete opt.highlight;
- if (!pending) return done();
- for (; i < tokens.length; i++) {
- (function(token) {
- if (token.type !== 'code') {
- return --pending || done();
- }
- return highlight(token.text, token.lang, function(err, code) {
- if (err) return done(err);
- if (code == null || code === token.text) {
- return --pending || done();
- }
- token.text = code;
- token.escaped = true;
- --pending || done();
- });
- })(tokens[i]);
- }
- return;
- }
- try {
- if (opt) opt = merge({}, marked.defaults, opt);
- return Parser.parse(Lexer.lex(src, opt), opt);
- } catch (e) {
- e.message += '\nPlease report this to https://github.com/chjj/marked.';
- if ((opt || marked.defaults).silent) {
- return '<p>An error occured:</p><pre>'
- + escape(e.message + '', true)
- + '</pre>';
- }
- throw e;
- }
- }
- /**
- * Options
- */
- marked.options =
- marked.setOptions = function(opt) {
- merge(marked.defaults, opt);
- return marked;
- };
- marked.defaults = {
- gfm: true,
- tables: true,
- breaks: false,
- pedantic: false,
- sanitize: false,
- smartLists: false,
- silent: false,
- highlight: null,
- langPrefix: 'lang-',
- smartypants: false,
- headerPrefix: '',
- renderer: new Renderer,
- xhtml: false
- };
- /**
- * Expose
- */
- marked.Parser = Parser;
- marked.parser = Parser.parse;
- marked.Renderer = Renderer;
- marked.Lexer = Lexer;
- marked.lexer = Lexer.lex;
- marked.InlineLexer = InlineLexer;
- marked.inlineLexer = InlineLexer.output;
- marked.parse = marked;
- if (typeof module !== 'undefined' && typeof exports === 'object') {
- module.exports = marked;
- } else if (typeof define === 'function' && define.amd) {
- define(function() { return marked; });
- } else {
- this.marked = marked;
- }
- }).call(function() {
- return this || (typeof window !== 'undefined' ? window : global);
- }());
- /*!
- * ====================================================
- * kity - v2.0.0 - 2015-01-12
- * https://github.com/fex-team/kity
- * GitHub: https://github.com/fex-team/kity.git
- * Copyright (c) 2015 Baidu FEX; Licensed BSD
- * ====================================================
- */
- (function () {
- var _p = {
- r: function(index) {
- if (_p[index].inited) {
- return _p[index].value;
- }
- if (typeof _p[index].value === "function") {
- var module = {
- exports: {}
- }, returnValue = _p[index].value(null, module.exports, module);
- _p[index].inited = true;
- _p[index].value = returnValue;
- if (returnValue !== undefined) {
- return returnValue;
- } else {
- for (var key in module.exports) {
- if (module.exports.hasOwnProperty(key)) {
- _p[index].inited = true;
- _p[index].value = module.exports;
- return module.exports;
- }
- }
- }
- } else {
- _p[index].inited = true;
- return _p[index].value;
- }
- }
- };
- //src/animate/animator.js
- /**
- * @fileOverview
- *
- * 提供基本的动画支持
- */
- _p[0] = {
- value: function(require) {
- function parseTime(str) {
- var value = parseFloat(str, 10);
- if (/ms/.test(str)) {
- return value;
- }
- if (/s/.test(str)) {
- return value * 1e3;
- }
- if (/min/.test(str)) {
- return value * 60 * 1e3;
- }
- return value;
- }
- var Timeline = _p.r(8);
- var easingTable = _p.r(1);
- /**
- * @class kity.Animator
- * @catalog animate
- * @description 表示一个动画启动器,可以作用于不同的对象进行动画
- */
- var Animator = _p.r(11).createClass("Animator", {
- /**
- * @constructor
- * @for kity.Animator
- * @catalog animate
- *
- * @grammar new kity.Animator(beginValue, finishValue, setter)
- * @grammar new kity.Animator(option)
- *
- * @param {any} beginValue|opt.beginValue
- * 动画的起始值,允许的类型有数字、数组、字面量、kity.Point、kity.Vector、kity.Box、kity.Matrix
- *
- * @param {any} finishValue|opt.beginValue
- * 动画的结束值,类型应于起始值相同
- *
- * @param {Function} setter|opt.setter
- * 值的使用函数,接受三个参数: function(target, value, timeline)
- * target {object} 动画的目标
- * value {any} 动画的当前值
- * timeline {kity.Timeline} 动画当前的时间线对象
- */
- constructor: function(beginValue, finishValue, setter) {
- if (arguments.length == 1) {
- var opt = arguments[0];
- this.beginValue = opt.beginValue;
- this.finishValue = opt.finishValue;
- this.setter = opt.setter;
- } else {
- this.beginValue = beginValue;
- this.finishValue = finishValue;
- this.setter = setter;
- }
- },
- /**
- * @method start()
- * @for kity.Animator
- * @description 使用当前的动画器启动在指定目标上启动动画
- *
- * @grammar start(target, duration, easing, delay, callback) => {kity.Timeline}
- * @grammar start(target, option) => {kity.Timeline}
- *
- * @param {object} target
- * 启动动画的目标
- *
- * @param {Number|String} duration|option.duration
- * [Optional] 动画的持续时间,如 300、"300ms"、"1.5min"
- *
- * @param {String|Function} easing|option.easing
- * [Optional] 动画使用的缓动函数,如 "ease"、"linear"、"swing"
- *
- * @param {Number|String} delay|option.delay
- * [Optional] 动画的播放延迟时间
- *
- * @param {Function} callback|option.callback
- * [Optional] 动画结束后的回调函数
- *
- * @example
- *
- * ```js
- * var turnRed = new kity.Animator(
- * new kity.Color('yellow'),
- * new kity.Color('red'),
- * function(target, value) {
- * target.fill(value);
- * });
- *
- * turnRed.start(rect, 300, 'ease', function() {
- * console.log('I am red!');
- * });
- * ```
- */
- start: function(target, duration, easing, delay, callback) {
- if (arguments.length === 2 && typeof duration == "object") {
- easing = duration.easing;
- delay = duration.delay;
- callback = duration.callback;
- duration = duration.duration;
- }
- if (arguments.length === 4 && typeof delay == "function") {
- callback = delay;
- delay = 0;
- }
- var timeline = this.create(target, duration, easing, callback);
- delay = parseTime(delay);
- if (delay > 0) {
- setTimeout(function() {
- timeline.play();
- }, delay);
- } else {
- timeline.play();
- }
- return timeline;
- },
- /**
- * @method create()
- * @for kity.Animator
- * @description 使用当前的动画器为指定目标创建时间线
- *
- * @grammar create(target, duration, easing, callback) => {kity.Timeline}
- *
- * @param {object} target 要创建的时间线的目标
- * @param {Number|String} duration 要创建的时间线的长度,如 300、"5s"、"0.5min"
- * @param {String|Function} easing 要创建的时间线的缓动函数,如 'ease'、'linear'、'swing'
- * @param {Function} callback 时间线播放结束之后的回调函数
- *
- * @example
- *
- * ```js
- * var expand = new kity.Animator({
- * beginValue: function(target) {
- * return target.getBox();
- * },
- * finishValue: function(target) {
- * return target.getBox().expand(100, 100, 100, 100);
- * },
- * setter: function(target, value) {
- * target.setBox(value)
- * }
- * });
- *
- * var timeline = expand.create(rect, 300);
- * timeline.repeat(3).play();
- * ```
- */
- create: function(target, duration, easing, callback) {
- var timeline;
- duration = duration && parseTime(duration) || Animator.DEFAULT_DURATION;
- easing = easing || Animator.DEFAULT_EASING;
- if (typeof easing == "string") {
- easing = easingTable[easing];
- }
- timeline = new Timeline(this, target, duration, easing);
- if (typeof callback == "function") {
- timeline.on("finish", callback);
- }
- return timeline;
- },
- /**
- * @method reverse()
- * @for kity.Animator
- * @grammar reverse() => {kity.Animator}
- * @description 创建一个与当前动画器相反的动画器
- *
- * @example
- *
- * ```js
- * var turnYellow = turnRed.reverse();
- * ```
- */
- reverse: function() {
- return new Animator(this.finishValue, this.beginValue, this.setter);
- }
- });
- Animator.DEFAULT_DURATION = 300;
- Animator.DEFAULT_EASING = "linear";
- var Shape = _p.r(60);
- _p.r(11).extendClass(Shape, {
- /**
- * @method animate()
- * @for kity.Shape
- * @description 在图形上播放使用指定的动画器播放动画,如果图形当前有动画正在播放,则会加入播放队列
- *
- * @grammar animate(animator, duration, easing, delay, callback)
- *
- * @param {object} animator 播放动画使用的动画器
- * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
- * @param {Number|String} delay 动画播放前的延时
- * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
- * @param {Function} callback 播放结束之后的回调函数
- *
- * @example
- *
- * ```js
- * rect.animate(turnRed, 300); // turnRect 是一个动画器
- * rect.animate(expand, 500); // turnRect 播放结束后播放 expand
- * ```
- */
- animate: function(animator, duration, easing, delay, callback) {
- var queue = this._KityAnimateQueue = this._KityAnimateQueue || [];
- var timeline = animator.create(this, duration, easing, callback);
- function dequeue() {
- queue.shift();
- if (queue.length) {
- setTimeout(queue[0].t.play.bind(queue[0].t), queue[0].d);
- }
- }
- timeline.on("finish", dequeue);
- queue.push({
- t: timeline,
- d: delay
- });
- if (queue.length == 1) {
- setTimeout(timeline.play.bind(timeline), delay);
- }
- return this;
- },
- /**
- * @method timeline()
- * @for kity.Shape
- * @description 获得当前正在播放的动画的时间线
- *
- * @grammar timeline() => {kity.Timeline}
- *
- * @example
- *
- * ```js
- * rect.timeline().repeat(2);
- * ```
- */
- timeline: function() {
- return this._KityAnimateQueue[0].t;
- },
- /**
- * @method stop()
- * @for kity.Shape
- * @description 停止当前正在播放的动画
- *
- * @grammar stop() => {this}
- *
- * @example
- *
- * ```js
- * rect.stop(); // 停止 rect 上的动画
- * ```
- */
- stop: function() {
- var queue = this._KityAnimateQueue;
- if (queue) {
- while (queue.length) {
- queue.shift().t.stop();
- }
- }
- return this;
- }
- });
- return Animator;
- }
- };
- //src/animate/easing.js
- /**
- * Kity Animate Easing modified from jQuery Easing
- * Author: techird
- * Changes:
- * 1. make easing functions standalone
- * 2. remove the 'x' parameter
- */
- /* ============================================================
- * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
- *
- * Open source under the BSD License.
- *
- * Copyright © 2008 George McGinley Smith
- * All rights reserved.
- * https://raw.github.com/danro/jquery-easing/master/LICENSE
- * ======================================================== */
- _p[1] = {
- value: function(require, exports, module) {
- var easings = {
- // t: current_time, b: begin_value, c: change_value, d: duration
- linear: function(t, b, c, d) {
- return c * (t / d) + b;
- },
- swing: function(t, b, c, d) {
- return easings.easeOutQuad(t, b, c, d);
- },
- ease: function(t, b, c, d) {
- return easings.easeInOutCubic(t, b, c, d);
- },
- easeInQuad: function(t, b, c, d) {
- return c * (t /= d) * t + b;
- },
- easeOutQuad: function(t, b, c, d) {
- return -c * (t /= d) * (t - 2) + b;
- },
- easeInOutQuad: function(t, b, c, d) {
- if ((t /= d / 2) < 1) return c / 2 * t * t + b;
- return -c / 2 * (--t * (t - 2) - 1) + b;
- },
- easeInCubic: function(t, b, c, d) {
- return c * (t /= d) * t * t + b;
- },
- easeOutCubic: function(t, b, c, d) {
- return c * ((t = t / d - 1) * t * t + 1) + b;
- },
- easeInOutCubic: function(t, b, c, d) {
- if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
- return c / 2 * ((t -= 2) * t * t + 2) + b;
- },
- easeInQuart: function(t, b, c, d) {
- return c * (t /= d) * t * t * t + b;
- },
- easeOutQuart: function(t, b, c, d) {
- return -c * ((t = t / d - 1) * t * t * t - 1) + b;
- },
- easeInOutQuart: function(t, b, c, d) {
- if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
- return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
- },
- easeInQuint: function(t, b, c, d) {
- return c * (t /= d) * t * t * t * t + b;
- },
- easeOutQuint: function(t, b, c, d) {
- return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
- },
- easeInOutQuint: function(t, b, c, d) {
- if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
- return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
- },
- easeInSine: function(t, b, c, d) {
- return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
- },
- easeOutSine: function(t, b, c, d) {
- return c * Math.sin(t / d * (Math.PI / 2)) + b;
- },
- easeInOutSine: function(t, b, c, d) {
- return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
- },
- easeInExpo: function(t, b, c, d) {
- return t === 0 ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
- },
- easeOutExpo: function(t, b, c, d) {
- return t == d ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
- },
- easeInOutExpo: function(t, b, c, d) {
- if (t === 0) return b;
- if (t == d) return b + c;
- if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
- return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
- },
- easeInCirc: function(t, b, c, d) {
- return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
- },
- easeOutCirc: function(t, b, c, d) {
- return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
- },
- easeInOutCirc: function(t, b, c, d) {
- if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
- return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
- },
- easeInElastic: function(t, b, c, d) {
- var s = 1.70158;
- var p = 0;
- var a = c;
- if (t === 0) return b;
- if ((t /= d) == 1) return b + c;
- if (!p) p = d * .3;
- if (a < Math.abs(c)) {
- a = c;
- s = p / 4;
- } else s = p / (2 * Math.PI) * Math.asin(c / a);
- return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
- },
- easeOutElastic: function(t, b, c, d) {
- var s = 1.70158;
- var p = 0;
- var a = c;
- if (t === 0) return b;
- if ((t /= d) == 1) return b + c;
- if (!p) p = d * .3;
- if (a < Math.abs(c)) {
- a = c;
- s = p / 4;
- } else s = p / (2 * Math.PI) * Math.asin(c / a);
- return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
- },
- easeInOutElastic: function(t, b, c, d) {
- var s = 1.70158;
- var p = 0;
- var a = c;
- if (t === 0) return b;
- if ((t /= d / 2) == 2) return b + c;
- if (!p) p = d * (.3 * 1.5);
- if (a < Math.abs(c)) {
- a = c;
- var s = p / 4;
- } else var s = p / (2 * Math.PI) * Math.asin(c / a);
- if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
- return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
- },
- easeInBack: function(t, b, c, d, s) {
- if (s == undefined) s = 1.70158;
- return c * (t /= d) * t * ((s + 1) * t - s) + b;
- },
- easeOutBack: function(t, b, c, d, s) {
- if (s == undefined) s = 1.70158;
- return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
- },
- easeInOutBack: function(t, b, c, d, s) {
- if (s == undefined) s = 1.70158;
- if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= 1.525) + 1) * t - s)) + b;
- return c / 2 * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2) + b;
- },
- easeInBounce: function(t, b, c, d) {
- return c - easings.easeOutBounce(d - t, 0, c, d) + b;
- },
- easeOutBounce: function(t, b, c, d) {
- if ((t /= d) < 1 / 2.75) {
- return c * (7.5625 * t * t) + b;
- } else if (t < 2 / 2.75) {
- return c * (7.5625 * (t -= 1.5 / 2.75) * t + .75) + b;
- } else if (t < 2.5 / 2.75) {
- return c * (7.5625 * (t -= 2.25 / 2.75) * t + .9375) + b;
- } else {
- return c * (7.5625 * (t -= 2.625 / 2.75) * t + .984375) + b;
- }
- },
- easeInOutBounce: function(t, b, c, d) {
- if (t < d / 2) return easings.easeInBounce(t * 2, 0, c, d) * .5 + b;
- return easings.easeOutBounce(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
- }
- };
- return easings;
- }
- };
- /*
- *
- * TERMS OF USE - EASING EQUATIONS
- *
- * Open source under the BSD License.
- *
- * Copyright © 2001 Robert Penner
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * Redistributions of source code must retain the above copyright notice, this list of
- * conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice, this list
- * of conditions and the following disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * Neither the name of the author nor the names of contributors may be used to endorse
- * or promote products derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
- //src/animate/frame.js
- /**
- * @fileOverview
- *
- * 提供动画帧的基本支持
- */
- _p[2] = {
- value: function(require, exports) {
- // 原生动画帧方法 polyfill
- var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || function(fn) {
- return setTimeout(fn, 1e3 / 60);
- };
- var cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.msCancelAnimationFrame || window.clearTimeout;
- // 上一个请求的原生动画帧 id
- var frameRequestId;
- // 等待执行的帧动作的集合,这些帧的方法将在下个原生动画帧同步执行
- var pendingFrames = [];
- /**
- * 添加一个帧到等待集合中
- *
- * 如果添加的帧是序列的第一个,至少有一个帧需要被执行,则会请求一个原生动画帧来执行
- */
- function pushFrame(frame) {
- if (pendingFrames.push(frame) === 1) {
- frameRequestId = requestAnimationFrame(executePendingFrames);
- }
- }
- /**
- * 执行所有等待帧
- */
- function executePendingFrames() {
- var frames = pendingFrames;
- pendingFrames = [];
- while (frames.length) {
- executeFrame(frames.pop());
- }
- frameRequestId = 0;
- }
- /**
- * @method kity.requestFrame
- * @catalog animate
- * @grammar kity.requestFrame(action) => {frame}
- * @description 请求一个帧,执行指定的动作。动作回调提供一些有用的信息
- *
- * @param {Function} action
- *
- * 要执行的动作,该动作回调有一个参数 frame,其中:
- *
- * frame.time {Number}
- * 动作执行时的时间戳(ms)
- *
- * frame.index {Number}
- * 当前执行的帧的编号(首帧为 0)
- *
- * frame.dur {Number}
- * 上一帧至当前帧经过的时间,单位 ms
- *
- * frame.elapsed {Number}
- * 从首帧开始到当前帧经过的时间,单位 ms
- *
- * frame.action {Number}
- * 指向当前的帧处理函数
- *
- * frame.next()
- * 表示下一帧继续执行。如果不调用该方法,将不会执行下一帧。
- *
- * @example
- *
- * ```js
- * kity.requestFrame(function(frame) {
- * console.log('平均帧率:' + frame.elapsed / (frame.index + 1));
- *
- * // 更新或渲染动作
- *
- * frame.next(); //继续执行下一帧
- * });
- * ```
- */
- function requestFrame(action) {
- var frame = initFrame(action);
- pushFrame(frame);
- return frame;
- }
- /**
- * @method kity.releaseFrame
- * @catalog animate
- * @grammar kity.releaseFrame(frame)
- * @description 释放一个已经请求过的帧,如果该帧在等待集合里,将移除,下个动画帧不会执行释放的帧
- *
- * @param {frame} frame 使用 kity.requestFrame() 返回的帧
- *
- * @example
- *
- * ```js
- * var frame = kity.requestFrame(function() {....});
- * kity.releaseFrame(frame);
- * ```
- */
- function releaseFrame(frame) {
- var index = pendingFrames.indexOf(frame);
- if (~index) {
- pendingFrames.splice(index, 1);
- }
- if (pendingFrames.length === 0) {
- cancelAnimationFrame(frameRequestId);
- }
- }
- /**
- * 初始化一个帧,主要用于后续计算
- */
- function initFrame(action) {
- var frame = {
- index: 0,
- time: +new Date(),
- elapsed: 0,
- action: action,
- next: function() {
- pushFrame(frame);
- }
- };
- return frame;
- }
- /**
- * 执行一个帧动作
- */
- function executeFrame(frame) {
- // 当前帧时间错
- var time = +new Date();
- // 当上一帧到当前帧经过的时间
- var dur = time - frame.time;
- //
- // http://stackoverflow.com/questions/13133434/requestanimationframe-detect-stop
- // 浏览器最小化或切换标签,requestAnimationFrame 不会执行。
- // 检测时间超过 200 ms(频率小于 5Hz ) 判定为计时器暂停,重置为一帧长度
- //
- if (dur > 200) {
- dur = 1e3 / 60;
- }
- frame.dur = dur;
- frame.elapsed += dur;
- frame.time = time;
- frame.action.call(null, frame);
- frame.index++;
- }
- // 暴露
- exports.requestFrame = requestFrame;
- exports.releaseFrame = releaseFrame;
- }
- };
- //src/animate/motionanimator.js
- /**
- * @fileOverview
- *
- * 路径动画器,可以让一个物体沿着某个轨迹运动
- */
- _p[3] = {
- value: function(require) {
- var Animator = _p.r(0);
- var g = _p.r(34);
- var Path = _p.r(46);
- var Shape = _p.r(60);
- /**
- * @class kity.MotionAnimator
- * @catalog animate
- * @base kity.Animator
- * @description 路径动画器,可以让一个物体沿着某个轨迹运动
- *
- * @example
- *
- * ```js
- * var motionAnimator = new MotionAnimator('M0,0C100,0,100,0,100,100L200,200');
- * motionAnimator.start(rect, 3000);
- * ```
- */
- var MotionAnimator = _p.r(11).createClass("MotionAnimator", {
- base: Animator,
- /**
- * @constructor
- * @for kity.MotionAnimator
- * @grammar new kity.MotionAnimator(path, doRotate)
- * @param {kity.Path|String|PathSegment} path 运动的轨迹,或者是 kity.Path 对象
- * @param {boolean} doRotate 是否让运动的目标沿着路径的切线方向旋转
- */
- constructor: function(path, doRotate) {
- var me = this;
- this.callBase({
- beginValue: 0,
- finishValue: 1,
- setter: function(target, value) {
- var path = me.motionPath instanceof Path ? me.motionPath.getPathData() : me.motionPath;
- var point = g.pointAtPath(path, value);
- target.setTranslate(point.x, point.y);
- if (this.doRotate) target.setRotate(point.tan.getAngle());
- }
- });
- /**
- * @property doRotate
- * @for kity.MotionAnimator
- * @type {boolean}
- * @description 是否让运动的目标沿着路径的切线方向旋转
- *
- * @example
- *
- * ```js
- * motionAnimator.doRotate = true; // 目标沿着切线方向旋转
- * ```
- */
- this.doRotate = doRotate;
- /**
- * @property motionPath
- * @for kity.MotionAnimator
- * @type {kity.Path|String|PathSegment}
- * @description 运动沿着的路径,可以在动画过程中更新
- */
- this.motionPath = path;
- }
- });
- _p.r(11).extendClass(Shape, {
- /**
- * @method motion()
- * @catalog animate
- * @for kity.Shape
- * @description 让图形沿着指定的路径运动
- *
- * @grammar motion(path, duration, easing, delay, callback) => this
- *
- * @param {kity.Path|String|PathSegment} path 运动的轨迹,或者是 kity.Path 对象
- * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
- * @param {Number|String} delay 动画播放前的延时
- * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
- * @param {Function} callback 播放结束之后的回调函数
- */
- motion: function(path, duration, easing, delay, callback) {
- return this.animate(new MotionAnimator(path), duration, easing, delay, callback);
- }
- });
- return MotionAnimator;
- }
- };
- //src/animate/opacityanimator.js
- /**
- * @fileOverview
- *
- * 透明度动画器,让图形动画过度到指定的透明度。
- */
- _p[4] = {
- value: function(require) {
- var Animator = _p.r(0);
- /**
- * @class kity.OpacityAnimator
- * @catalog animate
- * @base kity.Animator
- * @description 透明度动画器,让图形动画过度到指定的透明度
- */
- var OpacityAnimator = _p.r(11).createClass("OpacityAnimator", {
- base: Animator,
- /**
- * @constructor
- * @for kity.OpacityAnimator
- * @grammar new kity.OpacityAnimator(opacity)
- *
- * @param {Number} opacity 目标透明度,取值范围 0 - 1
- */
- constructor: function(opacity) {
- this.callBase({
- beginValue: function(target) {
- return target.getOpacity();
- },
- finishValue: opacity,
- setter: function(target, value) {
- target.setOpacity(value);
- }
- });
- }
- });
- var Shape = _p.r(60);
- _p.r(11).extendClass(Shape, {
- /**
- * @method fxOpacity()
- * @catalog animate
- * @for kity.Shape
- * @description 让图形的透明度以动画的形式过渡到指定的值
- *
- * @grammar fxOpacity(opacity, duration, easing, delay, callback) => {this}
- *
- * @param {Number} opacity 动画的目标透明度
- * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
- * @param {Number|String} delay 动画播放前的延时
- * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
- * @param {Function} callback 播放结束之后的回调函数
- */
- fxOpacity: function(opacity, duration, easing, delay, callback) {
- return this.animate(new OpacityAnimator(opacity), duration, easing, delay, callback);
- },
- /**
- * @method fadeTo()
- * @catalog animate
- * @for kity.Shape
- * @description 让图形的透明度以动画的形式过渡到指定的值
- *
- * @grammar fadeTo(opacity, duration, easing, delay, callback) => {this}
- *
- * @param {Number} opacity 动画的目标透明度
- * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
- * @param {Number|String} delay 动画播放前的延时
- * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
- * @param {Function} callback 播放结束之后的回调函数
- */
- fadeTo: function() {
- return this.fxOpacity.apply(this, arguments);
- },
- /**
- * @method fadeIn()
- * @catalog animate
- * @for kity.Shape
- * @description 让图形淡入
- *
- * @grammar fadeIn(duration, easing, delay, callback) => {this}
- *
- * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
- * @param {Number|String} delay 动画播放前的延时
- * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
- * @param {Function} callback 播放结束之后的回调函数
- */
- fadeIn: function() {
- return this.fxOpacity.apply(this, [ 1 ].concat([].slice.call(arguments)));
- },
- /**
- * @method fadeOut()
- * @catalog animate
- * @for kity.Shape
- * @description 让图形淡出
- *
- * @grammar fadeIn(duration, easing, delay, callback) => {this}
- *
- * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
- * @param {Number|String} delay 动画播放前的延时
- * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
- * @param {Function} callback 播放结束之后的回调函数
- */
- fadeOut: function() {
- return this.fxOpacity.apply(this, [ 0 ].concat([].slice.call(arguments)));
- }
- });
- return OpacityAnimator;
- }
- };
- //src/animate/pathanimator.js
- /**
- * @fileOverview
- *
- * 路径补间动画器,让图形从一个形状变为另一个形状
- */
- _p[5] = {
- value: function(require) {
- var Animator = _p.r(0);
- var g = _p.r(34);
- /**
- * @catalog animate
- *
- * @class kity.PathAnimator
- * @base kity.Animator
- * @description 路径补间动画器,让图形从一个形状变为另一个形状
- *
- * @example
- *
- * ```js
- * var path = new kity.Path('M0,0L0,100');
- * var pa = new kity.PathAnimator('M0,0C100,0,100,0,100,100');
- * pa.start(path, 300);
- * ```
- */
- var PathAnimator = _p.r(11).createClass("OpacityAnimator", {
- base: Animator,
- /**
- * @constructor
- * @for kity.PathAnimator
- *
- * @grammar new kity.Path.Animator(path)
- *
- * @param {String|PathSegment} path 目标形状的路径数据
- *
- */
- constructor: function(path) {
- this.callBase({
- beginValue: function(target) {
- this.beginPath = target.getPathData();
- return 0;
- },
- finishValue: 1,
- setter: function(target, value) {
- target.setPathData(g.pathTween(this.beginPath, path, value));
- }
- });
- }
- });
- var Path = _p.r(46);
- _p.r(11).extendClass(Path, {
- /**
- * @catalog animate
- *
- * @method fxPath()
- * @for kity.Shape
- * @description 以动画的形式把路径变换为新路径
- *
- * @grammar fxPath(path, duration, easing, delay, callback) => {this}
- *
- * @param {String|PathSegment} path 要变换新路径
- * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
- * @param {Number|String} delay 动画播放前的延时
- * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
- * @param {Function} callback 播放结束之后的回调函数
- */
- fxPath: function(path, duration, easing, delay, callback) {
- return this.animate(new PathAnimator(path), duration, easing, delay, callback);
- }
- });
- return PathAnimator;
- }
- };
- //src/animate/rotateanimator.js
- /**
- * @fileOverview
- *
- * 提供支持目标旋转的动画器
- */
- _p[6] = {
- value: function(require) {
- var Animator = _p.r(0);
- /**
- * @class kity.RotateAnimator
- * @base Animator
- * @description 提供支持目标旋转的动画器
- */
- var RotateAnimator = _p.r(11).createClass("RotateAnimator", {
- base: Animator,
- /**
- * @constructor
- * @for kity.RotateAnimator
- *
- * @grammar new kity.RotateAnimator(deg, ax, ay)
- *
- * @param {Number} deg 要旋转的角度
- */
- constructor: function(deg) {
- this.callBase({
- beginValue: 0,
- finishValue: deg,
- setter: function(target, value, timeline) {
- var delta = timeline.getDelta();
- target.rotate(delta, ax, ay);
- }
- });
- }
- });
- var Shape = _p.r(60);
- _p.r(11).extendClass(Shape, {
- /**
- * @method fxRotate()
- * @for kity.Shape
- * @description 让目标以动画旋转指定的角度
- *
- * @grammar fxRotate(deg, duration, easing, delay) => {this}
- *
- * @param {Number} deg 要旋转的角度
- * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
- * @param {Number|String} delay 动画播放前的延时
- * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
- * @param {Function} callback 播放结束之后的回调函数
- */
- fxRotate: function(deg, duration, easing, delay, callback) {
- return this.animate(new RotateAnimator(deg), duration, easing, delay, callback);
- }
- });
- return RotateAnimator;
- }
- };
- //src/animate/scaleanimator.js
- /**
- * @fileOverview
- *
- * 提供支持目标缩放的动画器
- */
- _p[7] = {
- value: function(require) {
- var Animator = _p.r(0);
- /**
- * @class kity.ScaleAnimator
- * @base kity.Animator
- * @description 提供支持目标缩放的动画器
- */
- var ScaleAnimator = _p.r(11).createClass("ScaleAnimator", {
- base: Animator,
- /**
- * @constructor
- * @for kity.ScaleAnimator
- *
- * @grammar new kity.ScaleAnimator(sx, sy)
- * @param {Number} sx x 轴的缩放比例
- * @param {Number} sy y 轴的缩放比例
- */
- constructor: function(sx, sy) {
- this.callBase({
- beginValue: 0,
- finishValue: 1,
- setter: function(target, value, timeline) {
- var delta = timeline.getDelta();
- var kx = Math.pow(sx, delta);
- var ky = Math.pow(sy, delta);
- target.scale(ky, kx);
- }
- });
- }
- });
- var Shape = _p.r(60);
- _p.r(11).extendClass(Shape, {
- /**
- * @method fxScale
- * @for kity.Shape
- * @description 动画缩放当前的图形
- *
- * @grammar fxScale(sx, sy, duration, easing, delay, callback) => {this}
- *
- * @param {Number} sx x 轴的缩放比例
- * @param {Number} sy y 轴的缩放比例
- * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
- * @param {Number|String} delay 动画播放前的延时
- * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
- * @param {Function} callback 播放结束之后的回调函数
- */
- fxScale: function(sx, sy, duration, easing, delay, callback) {
- return this.animate(new ScaleAnimator(sx, sy), duration, easing, delay, callback);
- }
- });
- return ScaleAnimator;
- }
- };
- //src/animate/timeline.js
- /**
- * @fileOverview
- *
- * 动画时间线的实现
- */
- _p[8] = {
- value: function(require) {
- var EventHandler = _p.r(33);
- var utils = _p.r(12);
- var frame = _p.r(2);
- function getPercentValue(b, f, p) {
- return utils.paralle(b, f, function(b, f) {
- return b + (f - b) * p;
- });
- }
- function getDelta(v1, v2) {
- return utils.paralle(v1, v2, function(v1, v2) {
- return v2 - v1;
- });
- }
- function TimelineEvent(timeline, type, param) {
- this.timeline = timeline;
- this.target = timeline.target;
- this.type = type;
- for (var name in param) {
- if (param.hasOwnProperty(name)) {
- this[name] = param[name];
- }
- }
- }
- /**
- * @class kity.Timeline
- * @catalog animate
- * @mixins EventHandler
- * @description 动画时间线
- */
- var Timeline = _p.r(11).createClass("Timeline", {
- mixins: [ EventHandler ],
- /**
- * @constructor
- * @for kity.Timeline
- * @private
- * @description 时间线应该由动画器进行构造,不应手动创建
- *
- */
- constructor: function(animator, target, duration, easing) {
- this.callMixin();
- this.target = target;
- this.time = 0;
- this.duration = duration;
- this.easing = easing;
- this.animator = animator;
- this.beginValue = animator.beginValue;
- this.finishValue = animator.finishValue;
- this.setter = animator.setter;
- this.status = "ready";
- },
- /**
- * @private
- *
- * 让时间线进入下一帧
- */
- nextFrame: function(frame) {
- if (this.status != "playing") {
- return;
- }
- this.time += frame.dur;
- this.setValue(this.getValue());
- if (this.time >= this.duration) {
- this.timeUp();
- }
- frame.next();
- },
- /**
- * @method getPlayTime()
- * @for kity.Timeline
- * @grammar getPlayTime() => {Number}
- * @description 获得当前播放的时间,取值区间为 [0, duration]
- */
- getPlayTime: function() {
- return this.rollbacking ? this.duration - this.time : this.time;
- },
- /**
- * @method getTimeProportion()
- * @for kity.Timeline
- * @grammar getTimeProportion() => {Number}
- * @description 获得当前播放时间的比例,取值区间为 [0, 1]
- */
- getTimeProportion: function() {
- return this.getPlayTime() / this.duration;
- },
- /**
- * @method getValueProportion()
- * @for kity.Timeline
- * @grammar getValueProportion() => {Number}
- * @description 获得当前播放时间对应值的比例,取值区间为 [0, 1];该值实际上是时间比例值经过缓动函数计算之后的值。
- */
- getValueProportion: function() {
- return this.easing(this.getPlayTime(), 0, 1, this.duration);
- },
- /**
- * @method getValue()
- * @for kity.Timeline
- * @grammar getValue() => {any}
- * @description 返回当前播放时间对应的值。
- */
- getValue: function() {
- var b = this.beginValue;
- var f = this.finishValue;
- var p = this.getValueProportion();
- return getPercentValue(b, f, p);
- },
- /**
- * @private
- *
- * 把值通过动画器的 setter 设置到目标上
- */
- setValue: function(value) {
- this.lastValue = this.currentValue;
- this.currentValue = value;
- this.setter.call(this.target, this.target, value, this);
- },
- /**
- * @method getDelta()
- * @for kity.Timeline
- * @grammar getDelta() => {any}
- * @description 返回当前值和上一帧的值的差值
- */
- getDelta: function() {
- this.lastValue = this.lastValue === undefined ? this.beginValue : this.lastValue;
- return getDelta(this.lastValue, this.currentValue);
- },
- /**
- * @method play()
- * @for kity.Timeline
- * @grammar play() => {this}
- * @description 让时间线播放,如果时间线还没开始,或者已停止、已结束,则重头播放;如果是已暂停,从暂停的位置继续播放
- */
- play: function() {
- var lastStatus = this.status;
- this.status = "playing";
- switch (lastStatus) {
- case "ready":
- if (utils.isFunction(this.beginValue)) {
- this.beginValue = this.beginValue.call(this.target, this.target);
- }
- if (utils.isFunction(this.finishValue)) {
- this.finishValue = this.finishValue.call(this.target, this.target);
- }
- this.time = 0;
- this.setValue(this.beginValue);
- this.frame = frame.requestFrame(this.nextFrame.bind(this));
- break;
- case "finished":
- case "stoped":
- this.time = 0;
- this.frame = frame.requestFrame(this.nextFrame.bind(this));
- break;
- case "paused":
- this.frame.next();
- }
- /**
- * @event play
- * @for kity.Timeline
- * @description 在时间线播放后触发
- *
- * @param {String} event.lastStatus
- * 表示播放前的上一个状态,可能取值为 'ready'、'finished'、'stoped'、'paused'
- */
- this.fire("play", new TimelineEvent(this, "play", {
- lastStatus: lastStatus
- }));
- return this;
- },
- /**
- * @method pause()
- * @for kity.Timeline
- * @description 暂停当前的时间线
- *
- * @grammar pause() => {this}
- */
- pause: function() {
- this.status = "paused";
- /**
- * @event pause
- * @for kity.Timeline
- * @description 暂停事件,在时间线暂停时触发
- */
- this.fire("pause", new TimelineEvent(this, "pause"));
- frame.releaseFrame(this.frame);
- return this;
- },
- /**
- * @method stop()
- * @for kity.Timeline
- * @description 停止当前时间线
- *
- * @grammar stop() => {this}
- */
- stop: function() {
- this.status = "stoped";
- this.setValue(this.finishValue);
- this.rollbacking = false;
- /**
- * @event stop
- * @for kity.Timeline
- * @description 停止时间,在时间线停止时触发
- */
- this.fire("stop", new TimelineEvent(this, "stop"));
- frame.releaseFrame(this.frame);
- return this;
- },
- /**
- * @private
- *
- * 播放结束之后的处理
- */
- timeUp: function() {
- if (this.repeatOption) {
- this.time = 0;
- if (this.rollback) {
- if (this.rollbacking) {
- this.decreaseRepeat();
- this.rollbacking = false;
- } else {
- this.rollbacking = true;
- /**
- * @event rollback
- * @for kity.Timeline
- * @description 回滚事件,在时间线回滚播放开始的时候触发
- */
- this.fire("rollback", new TimelineEvent(this, "rollback"));
- }
- } else {
- this.decreaseRepeat();
- }
- if (!this.repeatOption) {
- this.finish();
- } else {
- /**
- * @event repeat
- * @for kity.Timeline
- * @description 循环事件,在时间线循环播放开始的时候触发
- */
- this.fire("repeat", new TimelineEvent(this, "repeat"));
- }
- } else {
- this.finish();
- }
- },
- /**
- * @private
- *
- * 决定播放结束的处理
- */
- finish: function() {
- this.setValue(this.finishValue);
- this.status = "finished";
- /**
- * @event finish
- * @for kity.Timeline
- * @description 结束事件,在时间线播放结束后触发(包括重复和回滚都结束)
- */
- this.fire("finish", new TimelineEvent(this, "finish"));
- frame.releaseFrame(this.frame);
- },
- /**
- * @private
- *
- * 循环次数递减
- */
- decreaseRepeat: function() {
- if (this.repeatOption !== true) {
- this.repeatOption--;
- }
- },
- /**
- * @method repeat()
- * @for kity.Timeline
- * @description 设置时间线的重复选项
- *
- * @grammar repeat(repeat, rollback) => {this}
- *
- * @param {Number|Boolean} repeat
- * 是否重复播放,设置为 true 无限循环播放,设置数值则循环指定的次数
- * @param {Boolean} rollback
- * 指示是否要回滚播放。
- * 如果设置为真,一次事件到 duration 则一个来回算一次循环次数,否则播放完成一次算一次循环次数
- *
- */
- repeat: function(repeat, rollback) {
- this.repeatOption = repeat;
- this.rollback = rollback;
- return this;
- }
- });
- Timeline.requestFrame = frame.requestFrame;
- Timeline.releaseFrame = frame.releaseFrame;
- return Timeline;
- }
- };
- //src/animate/translateanimator.js
- /**
- * @fileOverview
- *
- * 提供让图形移动的动画器
- */
- _p[9] = {
- value: function(require) {
- var Animator = _p.r(0);
- /**
- * @class kity.TranslateAnimator
- * @base kity.Animator
- * @description 提供让图形移动的动画器
- */
- var TranslateAnimator = _p.r(11).createClass("TranslateAnimator", {
- base: Animator,
- /**
- * @constructor
- * @for kity.TranslateAnimator
- * @grammar new kity.TranslateAnimator(x, y)
- * @param {Number} x x 方向上需要移动的距离
- * @param {Number} y y 方向上需要移动的距离
- */
- constructor: function(x, y) {
- this.callBase({
- x: 0,
- y: 0
- }, {
- x: x,
- y: y
- }, function(target, value, timeline) {
- var delta = timeline.getDelta();
- target.translate(delta.x, delta.y);
- });
- }
- });
- var Shape = _p.r(60);
- _p.r(11).extendClass(Shape, {
- /**
- * @method fxTranslate()
- * @for kity.Shape
- * @description 让目标以动画平移指定的距离
- *
- * @grammar fxTranslate(x, y, duration, easing, delay, callback) => {this}
- *
- * @param {Number} x x 方向上需要移动的距离
- * @param {Number} y y 方向上需要移动的距离
- * @param {Number|String} duration 动画的播放长度,如 300、"5s"、"0.5min"
- * @param {Number|String} delay 动画播放前的延时
- * @param {String|Function} easing 动画播放使用的缓动函数,如 'ease'、'linear'、'swing'
- * @param {Function} callback 播放结束之后的回调函数
- */
- fxTranslate: function(x, y, duration, easing, delay, callback) {
- return this.animate(new TranslateAnimator(x, y), duration, easing, delay, callback);
- }
- });
- return TranslateAnimator;
- }
- };
- //src/core/browser.js
- /**
- * @fileOverview
- *
- * 提供浏览器判断的一些字段
- */
- _p[10] = {
- value: function() {
- /**
- * @class kity.Browser
- * @catalog core
- * @static
- * @description 提供浏览器信息
- */
- var browser = function() {
- var agent = navigator.userAgent.toLowerCase(), opera = window.opera, browser;
- // 浏览器对象
- browser = {
- /**
- * @property ie
- * @for kity.Browser
- * @description 判断是否为 IE 浏览器
- * @type {boolean}
- */
- ie: /(msie\s|trident.*rv:)([\w.]+)/.test(agent),
- /**
- * @property opera
- * @for kity.Browser
- * @description 判断是否为 Opera 浏览器
- * @type {boolean}
- */
- opera: !!opera && opera.version,
- /**
- * @property webkit
- * @for kity.Browser
- * @description 判断是否为 Webkit 内核的浏览器
- * @type {boolean}
- */
- webkit: agent.indexOf(" applewebkit/") > -1,
- /**
- * @property mac
- * @for kity.Browser
- * @description 判断是否为 Mac 下的浏览器
- * @type {boolean}
- */
- mac: agent.indexOf("macintosh") > -1
- };
- browser.gecko = navigator.product == "Gecko" && !browser.webkit && !browser.opera && !browser.ie;
- var version = 0;
- // Internet Explorer 6.0+
- if (browser.ie) {
- version = (agent.match(/(msie\s|trident.*rv:)([\w.]+)/)[2] || 0) * 1;
- browser.ie11Compat = document.documentMode == 11;
- browser.ie9Compat = document.documentMode == 9;
- }
- // Gecko.
- if (browser.gecko) {
- var geckoRelease = agent.match(/rv:([\d\.]+)/);
- if (geckoRelease) {
- geckoRelease = geckoRelease[1].split(".");
- version = geckoRelease[0] * 1e4 + (geckoRelease[1] || 0) * 100 + (geckoRelease[2] || 0) * 1;
- }
- }
- if (/chrome\/(\d+\.\d)/i.test(agent)) {
- /**
- * @property chrome
- * @for kity.Browser
- * @description 判断是否为 Chrome 浏览器
- * @type {boolean}
- */
- browser.chrome = +RegExp["$1"];
- }
- if (/(\d+\.\d)?(?:\.\d)?\s+safari\/?(\d+\.\d+)?/i.test(agent) && !/chrome/i.test(agent)) {
- browser.safari = +(RegExp["$1"] || RegExp["$2"]);
- }
- // Opera 9.50+
- if (browser.opera) version = parseFloat(opera.version());
- // WebKit 522+ (Safari 3+)
- if (browser.webkit) version = parseFloat(agent.match(/ applewebkit\/(\d+)/)[1]);
- /**
- * @property version
- * @for kity.Browser
- * @description 获取当前浏览器的版本
- * @type {Number}
- */
- browser.version = version;
- browser.isCompatible = !browser.mobile && (browser.ie && version >= 6 || browser.gecko && version >= 10801 || browser.opera && version >= 9.5 || browser.air && version >= 1 || browser.webkit && version >= 522 || false);
- return browser;
- }();
- return browser;
- }
- };
- //src/core/class.js
- /**
- * @fileOverview
- *
- * 提供 Kity 的 OOP 支持
- */
- _p[11] = {
- value: function(require, exports) {
- /**
- * @class kity.Class
- * @catalog core
- * @description 所有 kity 类的基类
- * @abstract
- */
- function Class() {}
- exports.Class = Class;
- Class.__KityClassName = "Class";
- /**
- * @method base()
- * @for kity.Class
- * @protected
- * @grammar base(name, args...) => {any}
- * @description 调用父类指定名称的函数
- * @param {string} name 函数的名称
- * @param {parameter} args... 传递给父类函数的参数
- *
- * @example
- *
- * ```js
- * var Person = kity.createClass('Person', {
- * toString: function() {
- * return 'I am a person';
- * }
- * });
- *
- * var Male = kity.createClass('Male', {
- * base: Person,
- *
- * toString: function() {
- * return 'I am a man';
- * },
- *
- * speak: function() {
- * return this.base('toString') + ',' + this.toString();
- * }
- * })
- * ```
- */
- Class.prototype.base = function(name) {
- var caller = arguments.callee.caller;
- var method = caller.__KityMethodClass.__KityBaseClass.prototype[name];
- return method.apply(this, Array.prototype.slice.call(arguments, 1));
- };
- /**
- * @method callBase()
- * @for kity.Class
- * @protected
- * @grammar callBase(args...) => {any}
- * @description 调用父类同名函数
- * @param {parameter} args... 传递到父类同名函数的参数
- *
- * @example
- *
- * ```js
- * var Animal = kity.createClass('Animal', {
- * constructor: function(name) {
- * this.name = name;
- * },
- * toString: function() {
- * return 'I am an animal name ' + this.name;
- * }
- * });
- *
- * var Dog = kity.createClass('Dog', {
- * constructor: function(name) {
- * this.callBase(name);
- * },
- * toString: function() {
- * return this.callBase() + ', a dog';
- * }
- * });
- *
- * var dog = new Dog('Dummy');
- * console.log(dog.toString()); // "I am an animal name Dummy, a dog";
- * ```
- */
- Class.prototype.callBase = function() {
- var caller = arguments.callee.caller;
- var method = caller.__KityMethodClass.__KityBaseClass.prototype[caller.__KityMethodName];
- return method.apply(this, arguments);
- };
- Class.prototype.mixin = function(name) {
- var caller = arguments.callee.caller;
- var mixins = caller.__KityMethodClass.__KityMixins;
- if (!mixins) {
- return this;
- }
- var method = mixins[name];
- return method.apply(this, Array.prototype.slice.call(arguments, 1));
- };
- Class.prototype.callMixin = function() {
- var caller = arguments.callee.caller;
- var methodName = caller.__KityMethodName;
- var mixins = caller.__KityMethodClass.__KityMixins;
- if (!mixins) {
- return this;
- }
- var method = mixins[methodName];
- if (methodName == "constructor") {
- for (var i = 0, l = method.length; i < l; i++) {
- method[i].call(this);
- }
- return this;
- } else {
- return method.apply(this, arguments);
- }
- };
- /**
- * @method pipe()
- * @for kity.Class
- * @grammar pipe() => {this}
- * @description 以当前对象为上线文以及管道函数的第一个参数,执行一个管道函数
- * @param {Function} fn 进行管道操作的函数
- *
- * @example
- *
- * ```js
- * var rect = new kity.Rect().pipe(function() {
- * this.setWidth(500);
- * this.setHeight(300);
- * });
- * ```
- */
- Class.prototype.pipe = function(fn) {
- if (typeof fn == "function") {
- fn.call(this, this);
- }
- return this;
- };
- /**
- * @method getType()
- * @for kity.Class
- * @grammar getType() => {string}
- * @description 获得对象的类型
- *
- * @example
- *
- * ```js
- * var rect = new kity.Rect();
- * var circle = new kity.Circle();
- *
- * console.log(rect.getType()); // "Rect"
- * console.log(rect.getType()); // "Circle"
- * ```
- */
- Class.prototype.getType = function() {
- return this.__KityClassName;
- };
- /**
- * @method getClass()
- * @for kity.Class
- * @grammar getClass() => {Class}
- * @description 获得对象的类
- *
- * @example
- *
- * ```js
- * var rect = new kity.Rect();
- *
- * console.log(rect.getClass() === kity.Rect); // true
- * console.log(rect instanceof kity.Rect); // true
- * ```
- */
- Class.prototype.getClass = function() {
- return this.constructor;
- };
- // 检查基类是否调用了父类的构造函数
- // 该检查是弱检查,假如调用的代码被注释了,同样能检查成功(这个特性可用于知道建议调用,但是出于某些原因不想调用的情况)
- function checkBaseConstructorCall(targetClass, classname) {
- var code = targetClass.toString();
- if (!/this\.callBase/.test(code)) {
- throw new Error(classname + " : 类构造函数没有调用父类的构造函数!为了安全,请调用父类的构造函数");
- }
- }
- var KITY_INHERIT_FLAG = "__KITY_INHERIT_FLAG_" + +new Date();
- function inherit(constructor, BaseClass, classname) {
- var KityClass = eval("(function " + classname + "( __inherit__flag ) {" + "if( __inherit__flag != KITY_INHERIT_FLAG ) {" + "KityClass.__KityConstructor.apply(this, arguments);" + "}" + "this.__KityClassName = KityClass.__KityClassName;" + "})");
- KityClass.__KityConstructor = constructor;
- KityClass.prototype = new BaseClass(KITY_INHERIT_FLAG);
- for (var methodName in BaseClass.prototype) {
- if (BaseClass.prototype.hasOwnProperty(methodName) && methodName.indexOf("__Kity") !== 0) {
- KityClass.prototype[methodName] = BaseClass.prototype[methodName];
- }
- }
- KityClass.prototype.constructor = KityClass;
- return KityClass;
- }
- function mixin(NewClass, mixins) {
- if (false === mixins instanceof Array) {
- return NewClass;
- }
- var i, length = mixins.length, proto, method;
- NewClass.__KityMixins = {
- constructor: []
- };
- for (i = 0; i < length; i++) {
- proto = mixins[i].prototype;
- for (method in proto) {
- if (false === proto.hasOwnProperty(method) || method.indexOf("__Kity") === 0) {
- continue;
- }
- if (method === "constructor") {
- // constructor 特殊处理
- NewClass.__KityMixins.constructor.push(proto[method]);
- } else {
- NewClass.prototype[method] = NewClass.__KityMixins[method] = proto[method];
- }
- }
- }
- return NewClass;
- }
- function extend(BaseClass, extension) {
- if (extension.__KityClassName) {
- extension = extension.prototype;
- }
- for (var methodName in extension) {
- if (extension.hasOwnProperty(methodName) && methodName.indexOf("__Kity") && methodName != "constructor") {
- var method = BaseClass.prototype[methodName] = extension[methodName];
- method.__KityMethodClass = BaseClass;
- method.__KityMethodName = methodName;
- }
- }
- return BaseClass;
- }
- /**
- * @method kity.createClass()
- * @grammar kity.createClass(classname, defines) => {Class}
- * @description 创建一个类
- * @param {string} classname 类名,用于调试的时候查看,可选
- * @param {object} defines 类定义
- * defines.base {Class}
- * 定义的类的基类,如果不配置,则表示基类为 kity.Class
- * defines.mixins {Class[]}
- * 定义的类要融合的类列表
- * defines.constructor {Function}
- * 定义类的构造函数,如果父类显式定义了构造函数,需要在构造函数中使用 callBase() 方法调用父类的构造函数
- * defines.* {Function}
- * 定义类的其它函数
- *
- * @example 创建一个类
- *
- * ```js
- * var Animal = kity.createClass('Animal', {
- * constructor: function(name) {
- * this.name = name;
- * },
- * toString: function() {
- * return this.name;
- * }
- * });
- *
- * var a = new Animal('kity');
- * console.log(a.toString()); // "kity"
- * ```
- *
- * @example 继承一个类
- *
- * ```js
- * var Cat = kity.createClass('Cat', {
- * base: Animal,
- * constructor: function(name, color) {
- * // 调用父类构造函数
- * this.callBase(name);
- * },
- * toString: function() {
- * return 'A ' + this.color + ' cat, ' + this.callBase();
- * }
- * });
- *
- * var cat = new Cat('kity', 'black');
- * console.log(cat.toString()); // "A black cat, kity"
- * ```
- *
- * @example 混合类的能力
- * ```js
- * var Walkable = kity.createClass('Walkable', {
- * constructor: function() {
- * this.speed = 'fast';
- * },
- * walk: function() {
- * console.log('I am walking ' + this.speed);
- * }
- * });
- *
- * var Dog = kity.createClass('Dog', {
- * base: Animal,
- * mixins: [Walkable],
- * constructor: function(name) {
- * this.callBase(name);
- * this.callMixins();
- * }
- * });
- *
- * var dog = new Dog('doggy');
- * console.log(dog.toString() + ' say:');
- * dog.walk();
- * ```
- */
- exports.createClass = function(classname, defines) {
- var constructor, NewClass, BaseClass;
- if (arguments.length === 1) {
- defines = arguments[0];
- classname = "AnonymousClass";
- }
- BaseClass = defines.base || Class;
- if (defines.hasOwnProperty("constructor")) {
- constructor = defines.constructor;
- if (BaseClass != Class) {
- checkBaseConstructorCall(constructor, classname);
- }
- } else {
- constructor = function() {
- this.callBase.apply(this, arguments);
- this.callMixin.apply(this, arguments);
- };
- }
- NewClass = inherit(constructor, BaseClass, classname);
- NewClass = mixin(NewClass, defines.mixins);
- NewClass.__KityClassName = constructor.__KityClassName = classname;
- NewClass.__KityBaseClass = constructor.__KityBaseClass = BaseClass;
- NewClass.__KityMethodName = constructor.__KityMethodName = "constructor";
- NewClass.__KityMethodClass = constructor.__KityMethodClass = NewClass;
- // 下面这些不需要拷贝到原型链上
- delete defines.mixins;
- delete defines.constructor;
- delete defines.base;
- NewClass = extend(NewClass, defines);
- return NewClass;
- };
- /**
- * @method kity.extendClass()
- * @grammar kity.extendClass(clazz, extension) => {Class}
- * @description 拓展一个已有的类
- *
- * @example
- *
- * ```js
- * kity.extendClass(Dog, {
- * spark: function() {
- * console.log('wao wao wao!');
- * }
- * });
- *
- * new Dog().spark(); // "wao wao wao!";
- * ```
- */
- exports.extendClass = extend;
- }
- };
- //src/core/utils.js
- /**
- * @fileOverview
- *
- * 一些常用的工具方法
- */
- _p[12] = {
- value: function() {
- /**
- * @class kity.Utils
- * @catalog core
- * @static
- * @description 提供常用的工具方法
- */
- var utils = {
- /**
- * @method each()
- * @for kity.Utils
- * @grammar each(obj, interator, context)
- * @param {Object|Array} obj 要迭代的对象或数组
- * @param {Function} iterator 迭代函数
- * @param {Any} context 迭代函数的上下文
- *
- * @example 迭代数组
- *
- * ```js
- * kity.Utils.each([1, 2, 3, 4, 5], function(value, index, array) {
- * console.log(value, index);
- * });
- * // 1, 0
- * // 2, 1
- * // 3, 2
- * // 4, 3
- * // 5, 4
- * ```
- *
- * @example 迭代对象
- *
- * ```js
- * var obj = {
- * name: 'kity',
- * version: '1.2.1'
- * };
- * var param = [];
- * kity.Utils.each(obj, function(value, key, obj) {
- * param.push(key + '=' + value);
- * });
- * console.log(param.join('&')); // "name=kity&version=1.2.1"
- * ```
- */
- each: function each(obj, iterator, context) {
- if (obj === null) {
- return;
- }
- if (obj.length === +obj.length) {
- for (var i = 0, l = obj.length; i < l; i++) {
- if (iterator.call(context, obj[i], i, obj) === false) {
- return false;
- }
- }
- } else {
- for (var key in obj) {
- if (obj.hasOwnProperty(key)) {
- if (iterator.call(context, obj[key], key, obj) === false) {
- return false;
- }
- }
- }
- }
- },
- /**
- * @method extend()
- * @for kity.Utils
- * @grammar extend(target, sources..., notCover) => {object}
- * @description 把源对象的属性合并到目标对象上
- * @param {object} target 目标对象
- * @param {parameter} sources 源对象
- * @param {boolean} notCover 是否不要覆盖源对象已有的属性
- *
- * @example
- *
- * ```js
- * var a = {
- * key1: 'a1',
- * key2: 'a2'
- * };
- *
- * var b = {
- * key2: 'b2',
- * key3: 'b3'
- * };
- *
- * var c = {
- * key4: 'c4'
- * };
- *
- * var d = kity.extend(a, b, c);
- *
- * console.log(d === a); // true
- * console.log(a); // {key1: 'a1', key2: 'b2', key3: 'b3', key4: 'c4'}
- * ```
- */
- extend: function extend(t) {
- var a = arguments, notCover = this.isBoolean(a[a.length - 1]) ? a[a.length - 1] : false, len = this.isBoolean(a[a.length - 1]) ? a.length - 1 : a.length;
- for (var i = 1; i < len; i++) {
- var x = a[i];
- for (var k in x) {
- if (!notCover || !t.hasOwnProperty(k)) {
- t[k] = x[k];
- }
- }
- }
- return t;
- },
- /**
- * @method deepExtend()
- * @for kity.Utils
- * @grammar deepExtend(target, sources..., notCover)
- * @description 把源对象的属性合并到目标对象上,如果属性是对象,会递归合并
- * @param {object} target 目标对象
- * @param {parameter} sources 源对象
- * @param {boolean} notCover 是否不要覆盖源对象已有的属性
- */
- deepExtend: function(t, s) {
- var a = arguments, notCover = this.isBoolean(a[a.length - 1]) ? a[a.length - 1] : false, len = this.isBoolean(a[a.length - 1]) ? a.length - 1 : a.length;
- for (var i = 1; i < len; i++) {
- var x = a[i];
- for (var k in x) {
- if (!notCover || !t.hasOwnProperty(k)) {
- if (this.isObject(t[k]) && this.isObject(x[k])) {
- this.deepExtend(t[k], x[k], notCover);
- } else {
- t[k] = x[k];
- }
- }
- }
- }
- return t;
- },
- /**
- * @method clone()
- * @for kity.Utils
- * @grammar clone(obj) => {object}
- * @description 返回一个对象的克隆副本(非深度复制)
- * @param {object} obj 要克隆的对象
- *
- * @example
- *
- * ```js
- * var source = {
- * key1: {
- * key2: 'value2'
- * },
- * key3: 'value3'
- * };
- *
- * var target = kity.Utils.clone(source);
- *
- * console.log(target === source); // false
- * console.log(target.key1 === source.key1); // true
- * console.log(target.key3 === source.key3); // true
- * ```
- */
- clone: function clone(obj) {
- var cloned = {};
- for (var m in obj) {
- if (obj.hasOwnProperty(m)) {
- cloned[m] = obj[m];
- }
- }
- return cloned;
- },
- /**
- * @method copy()
- * @for kity.Utils
- * @grammar copy(obj) => {object}
- * @description 返回一个对象的拷贝副本(深度复制)
- * @param {object} obj 要拷贝的对象
- *
- * @example
- *
- * ```js
- * var source = {
- * key1: {
- * key2: 'value2'
- * },
- * key3: 'value3'
- * };
- *
- * var target = kity.Utils.copy(source);
- *
- * console.log(target === source); // false
- * console.log(target.key1 === source.key1); // false
- * console.log(target.key3 === source.key3); // true,因为是值类型
- * ```
- */
- copy: function copy(obj) {
- if (typeof obj !== "object") return obj;
- if (typeof obj === "function") return null;
- return JSON.parse(JSON.stringify(obj));
- },
- queryPath: function(path, obj) {
- var arr = path.split(".");
- var i = 0, tmp = obj, l = arr.length;
- while (i < l) {
- if (arr[i] in tmp) {
- tmp = tmp[arr[i]];
- i++;
- if (i >= l || tmp === undefined) {
- return tmp;
- }
- } else {
- return undefined;
- }
- }
- },
- getValue: function(value, defaultValue) {
- return value !== undefined ? value : defaultValue;
- },
- /**
- * @method flatten()
- * @for kity.Utils
- * @grammar flatten(arr) => {Array}
- * @description 返回给定数组的扁平化版本
- * @param {Array} arr 要扁平化的数组
- *
- * @example
- *
- * ```js
- * var flattened = kity.Utils.flatten([[1, 2], [2, 3], [[4, 5], [6, 7]]]);
- * console.log(flattened); // [1, 2, 3, 4, 5, 6, 7];
- * ```
- */
- flatten: function flatten(arr) {
- var result = [], length = arr.length, i;
- for (i = 0; i < length; i++) {
- if (arr[i] instanceof Array) {
- result = result.concat(utils.flatten(arr[i]));
- } else {
- result.push(arr[i]);
- }
- }
- return result;
- },
- /**
- * @method paralle()
- * @for kity.Utils
- * @grammar paralle() => {Any}
- *
- * @description 平行地对 v1 和 v2 进行指定的操作
- *
- * 如果 v1 是数字,那么直接进行 op 操作
- * 如果 v1 是对象,那么返回一个对象,其元素是 v1 和 v2 同键值的每个元素平行地进行 op 操作的结果
- * 如果 v1 是数组,那么返回一个数组,其元素是 v1 和 v2 同索引的每个元素平行地进行 op 操作的结果
- *
- * @param {Number|Object|Array} v1 第一个操作数
- * @param {Number|Object|Array} v2 第二个操作数
- * @param {Function} op 操作函数
- *
- *
- *
- * @example
- *
- * ```js
- * var a = {
- * value1: 1,
- * value2: 2,
- * value3: [3, 4, 5]
- * };
- *
- * var b = {
- * value1: 2,
- * value2: 3,
- * value3: [4, 5, 6]
- * };
- *
- * var c = kity.Utils.paralle(a, b, function(v1, v2) {
- * return v1 + v2;
- * });
- *
- * console.log(c.value1); // 3
- * console.log(c.value2); // 5
- * console.log(c.value3); // [7, 9, 11]
- *
- * ```
- */
- paralle: function paralle(v1, v2, op) {
- var Class, field, index, name, value;
- // 数组
- if (v1 instanceof Array) {
- value = [];
- for (index = 0; index < v1.length; index++) {
- value.push(utils.paralle(v1[index], v2[index], op));
- }
- return value;
- }
- // 对象
- if (v1 instanceof Object) {
- // 如果值是一个支持原始表示的实例,获取其原始表示
- Class = v1.getClass && v1.getClass();
- if (Class && Class.parse) {
- v1 = v1.valueOf();
- v2 = v2.valueOf();
- value = utils.paralle(v1, v2, op);
- value = Class.parse(value);
- } else {
- value = {};
- for (name in v1) {
- if (v1.hasOwnProperty(name) && v2.hasOwnProperty(name)) {
- value[name] = utils.paralle(v1[name], v2[name], op);
- }
- }
- }
- return value;
- }
- // 是否数字
- if (false === isNaN(parseFloat(v1))) {
- return op(v1, v2);
- }
- return value;
- },
- /**
- * 创建 op 操作的一个平行化版本
- */
- parallelize: function parallelize(op) {
- return function(v1, v2) {
- return utils.paralle(v1, v2, op);
- };
- }
- };
- /**
- * @method isString()
- * @for kity.Utils
- * @grammar isString(unknown) => {boolean}
- * @description 判断一个值是否为字符串类型
- * @param {any} unknown 要判断的值
- */
- /**
- * @method isFunction()
- * @for kity.Utils
- * @grammar isFunction(unknown) => {boolean}
- * @description 判断一个值是否为函数类型
- * @param {any} unknown 要判断的值
- */
- /**
- * @method isArray()
- * @for kity.Utils
- * @grammar isArray(unknown) => {boolean}
- * @description 判断一个值是否为数组类型
- * @param {any} unknown 要判断的值
- */
- /**
- * @method isNumber()
- * @for kity.Utils
- * @grammar isNumber(unknown) => {boolean}
- * @description 判断一个值是否为数字类型
- * @param {any} unknown 要判断的值
- */
- /**
- * @method isRegExp()
- * @for kity.Utils
- * @grammar isRegExp(unknown) => {boolean}
- * @description 判断一个值是否为正则表达式类型
- * @param {any} unknown 要判断的值
- */
- /**
- * @method isObject()
- * @for kity.Utils
- * @grammar isObject(unknown) => {boolean}
- * @description 判断一个值是否为对象类型
- * @param {any} unknown 要判断的值
- */
- /**
- * @method isBoolean()
- * @for kity.Utils
- * @grammar isBoolean(unknown) => {boolean}
- * @description 判断一个值是否为布尔类型
- * @param {any} unknown 要判断的值
- */
- utils.each([ "String", "Function", "Array", "Number", "RegExp", "Object", "Boolean" ], function(v) {
- utils["is" + v] = function typeCheck(obj) {
- return Object.prototype.toString.apply(obj) == "[object " + v + "]";
- };
- });
- return utils;
- }
- };
- //src/filter/effect/colormatrixeffect.js
- /**
- * 颜色矩阵运算效果封装
- */
- _p[13] = {
- value: function(require, exports, module) {
- var Effect = _p.r(16), Utils = _p.r(12);
- var ColorMatrixEffect = _p.r(11).createClass("ColorMatrixEffect", {
- base: Effect,
- constructor: function(type, input) {
- this.callBase(Effect.NAME_COLOR_MATRIX);
- this.set("type", Utils.getValue(type, ColorMatrixEffect.TYPE_MATRIX));
- this.set("in", Utils.getValue(input, Effect.INPUT_SOURCE_GRAPHIC));
- }
- });
- Utils.extend(ColorMatrixEffect, {
- // 类型常量
- TYPE_MATRIX: "matrix",
- TYPE_SATURATE: "saturate",
- TYPE_HUE_ROTATE: "hueRotate",
- TYPE_LUMINANCE_TO_ALPHA: "luminanceToAlpha",
- // 矩阵常量
- MATRIX_ORIGINAL: "10000010000010000010".split("").join(" "),
- MATRIX_EMPTY: "00000000000000000000".split("").join(" ")
- });
- return ColorMatrixEffect;
- }
- };
- //src/filter/effect/compositeeffect.js
- /**
- * 高斯模糊效果封装
- */
- _p[14] = {
- value: function(require, exports, module) {
- var Effect = _p.r(16), Utils = _p.r(12);
- var CompositeEffect = _p.r(11).createClass("CompositeEffect", {
- base: Effect,
- constructor: function(operator, input, input2) {
- this.callBase(Effect.NAME_COMPOSITE);
- this.set("operator", Utils.getValue(operator, CompositeEffect.OPERATOR_OVER));
- if (input) {
- this.set("in", input);
- }
- if (input2) {
- this.set("in2", input2);
- }
- }
- });
- Utils.extend(CompositeEffect, {
- // operator 常量
- OPERATOR_OVER: "over",
- OPERATOR_IN: "in",
- OPERATOR_OUT: "out",
- OPERATOR_ATOP: "atop",
- OPERATOR_XOR: "xor",
- OPERATOR_ARITHMETIC: "arithmetic"
- });
- return CompositeEffect;
- }
- };
- //src/filter/effect/convolvematrixeffect.js
- /**
- * 像素级别的矩阵卷积运算效果封装
- */
- _p[15] = {
- value: function(require, exports, module) {
- var Effect = _p.r(16), Utils = _p.r(12);
- var ConvolveMatrixEffect = _p.r(11).createClass("ConvolveMatrixEffect", {
- base: Effect,
- constructor: function(edgeMode, input) {
- this.callBase(Effect.NAME_CONVOLVE_MATRIX);
- this.set("edgeMode", Utils.getValue(edgeMode, ConvolveMatrixEffect.MODE_DUPLICATE));
- this.set("in", Utils.getValue(input, Effect.INPUT_SOURCE_GRAPHIC));
- }
- });
- Utils.extend(ConvolveMatrixEffect, {
- MODE_DUPLICATE: "duplicate",
- MODE_WRAP: "wrap",
- MODE_NONE: "none"
- });
- return ConvolveMatrixEffect;
- }
- };
- //src/filter/effect/effect.js
- /*
- * 效果类
- * 该类型的对象不存储任何内部属性, 所有操作都是针对该类对象所维护的节点进行的
- */
- _p[16] = {
- value: function(require, exports, module) {
- var svg = _p.r(67), Effect = _p.r(11).createClass("Effect", {
- constructor: function(type) {
- this.node = svg.createNode(type);
- },
- getId: function() {
- return this.node.id;
- },
- setId: function(id) {
- this.node.id = id;
- return this;
- },
- set: function(key, value) {
- this.node.setAttribute(key, value);
- return this;
- },
- get: function(key) {
- return this.node.getAttribute(key);
- },
- getNode: function() {
- return this.node;
- },
- // 返回该效果的result
- toString: function() {
- return this.node.getAttribute("result") || "";
- }
- });
- _p.r(12).extend(Effect, {
- // 特效名称常量
- NAME_GAUSSIAN_BLUR: "feGaussianBlur",
- NAME_OFFSET: "feOffset",
- NAME_COMPOSITE: "feComposite",
- NAME_COLOR_MATRIX: "feColorMatrix",
- NAME_CONVOLVE_MATRIX: "feConvolveMatrix",
- // 输入常量
- INPUT_SOURCE_GRAPHIC: "SourceGraphic",
- INPUT_SOURCE_ALPHA: "SourceAlpha",
- INPUT_BACKGROUND_IMAGE: "BackgroundImage",
- INPUT_BACKGROUND_ALPHA: "BackgroundAlpha",
- INPUT_FILL_PAINT: "FillPaint",
- INPUT_STROKE_PAINT: "StrokePaint"
- });
- return Effect;
- }
- };
- //src/filter/effect/gaussianblureffect.js
- /**
- * 高斯模糊效果封装
- */
- _p[17] = {
- value: function(require, exports, module) {
- var Effect = _p.r(16), Utils = _p.r(12);
- return _p.r(11).createClass("GaussianblurEffect", {
- base: Effect,
- constructor: function(stdDeviation, input) {
- this.callBase(Effect.NAME_GAUSSIAN_BLUR);
- this.set("stdDeviation", Utils.getValue(stdDeviation, 1));
- this.set("in", Utils.getValue(input, Effect.INPUT_SOURCE_GRAPHIC));
- }
- });
- }
- };
- //src/filter/effect/offseteffect.js
- /**
- * 偏移效果封装
- */
- _p[18] = {
- value: function(require, exports, module) {
- var Effect = _p.r(16), Utils = _p.r(12);
- return _p.r(11).createClass("OffsetEffect", {
- base: Effect,
- constructor: function(dx, dy, input) {
- this.callBase(Effect.NAME_OFFSET);
- this.set("dx", Utils.getValue(dx, 0));
- this.set("dy", Utils.getValue(dy, 0));
- this.set("in", Utils.getValue(input, Effect.INPUT_SOURCE_GRAPHIC));
- }
- });
- }
- };
- //src/filter/effectcontainer.js
- /*
- * Effect所用的container
- */
- _p[19] = {
- value: function(require) {
- return _p.r(11).createClass("EffectContainer", {
- base: _p.r(29),
- addEffect: function(point, pos) {
- return this.addItem.apply(this, arguments);
- },
- prependEffect: function() {
- return this.prependItem.apply(this, arguments);
- },
- appendEffect: function() {
- return this.appendItem.apply(this, arguments);
- },
- removeEffect: function(pos) {
- return this.removeItem.apply(this, arguments);
- },
- addEffects: function() {
- return this.addItems.apply(this, arguments);
- },
- setEffects: function() {
- return this.setItems.apply(this, arguments);
- },
- getEffect: function() {
- return this.getItem.apply(this, arguments);
- },
- getEffects: function() {
- return this.getItems.apply(this, arguments);
- },
- getFirstEffect: function() {
- return this.getFirstItem.apply(this, arguments);
- },
- getLastEffect: function() {
- return this.getLastItem.apply(this, arguments);
- },
- handleAdd: function(effectItem, pos) {
- var count = this.getEffects().length, nextEffectItem = this.getItem(pos + 1);
- // 最后一个节点, 直接追加
- if (count === pos + 1) {
- this.node.appendChild(effectItem.getNode());
- return;
- }
- this.node.insertBefore(effectItem.getNode(), nextEffectItem.getNode());
- }
- });
- }
- };
- //src/filter/filter.js
- /**
- * Filter 基类
- */
- _p[20] = {
- value: function(require, exports, module) {
- var svg = _p.r(67);
- var Class = _p.r(11);
- var Filter = Class.createClass("Filter", {
- mixins: [ _p.r(19) ],
- constructor: function(x, y, width, height) {
- this.node = svg.createNode("filter");
- if (x !== undefined) {
- this.set("x", x);
- }
- if (y !== undefined) {
- this.set("y", y);
- }
- if (width !== undefined) {
- this.set("width", width);
- }
- if (height !== undefined) {
- this.set("height", height);
- }
- },
- getId: function() {
- return this.id;
- },
- setId: function(id) {
- this.node.id = id;
- return this;
- },
- set: function(key, value) {
- this.node.setAttribute(key, value);
- return this;
- },
- get: function(key) {
- return this.node.getAttribute(key);
- },
- getNode: function() {
- return this.node;
- }
- });
- var Shape = _p.r(60);
- Class.extendClass(Shape, {
- applyFilter: function(filter) {
- var filterId = filter.get("id");
- if (filterId) {
- this.node.setAttribute("filter", "url(#" + filterId + ")");
- }
- return this;
- }
- });
- return Filter;
- }
- };
- //src/filter/gaussianblurfilter.js
- /*
- * 高斯模糊滤镜
- */
- _p[21] = {
- value: function(require, exports, module) {
- var GaussianblurEffect = _p.r(17);
- return _p.r(11).createClass("GaussianblurFilter", {
- base: _p.r(20),
- constructor: function(stdDeviation) {
- this.callBase();
- this.addEffect(new GaussianblurEffect(stdDeviation));
- }
- });
- }
- };
- //src/filter/projectionfilter.js
- /*
- * 投影滤镜
- */
- _p[22] = {
- value: function(require, exports, module) {
- var GaussianblurEffect = _p.r(17), Effect = _p.r(16), ColorMatrixEffect = _p.r(13), Color = _p.r(28), Utils = _p.r(12), CompositeEffect = _p.r(14), OffsetEffect = _p.r(18);
- return _p.r(11).createClass("ProjectionFilter", {
- base: _p.r(20),
- constructor: function(stdDeviation, dx, dy) {
- this.callBase();
- this.gaussianblurEffect = new GaussianblurEffect(stdDeviation, Effect.INPUT_SOURCE_ALPHA);
- this.gaussianblurEffect.set("result", "gaussianblur");
- this.addEffect(this.gaussianblurEffect);
- this.offsetEffect = new OffsetEffect(dx, dy, this.gaussianblurEffect);
- this.offsetEffect.set("result", "offsetBlur");
- this.addEffect(this.offsetEffect);
- this.colorMatrixEffect = new ColorMatrixEffect(ColorMatrixEffect.TYPE_MATRIX, this.offsetEffect);
- this.colorMatrixEffect.set("values", ColorMatrixEffect.MATRIX_ORIGINAL);
- this.colorMatrixEffect.set("result", "colorOffsetBlur");
- this.addEffect(this.colorMatrixEffect);
- this.compositeEffect = new CompositeEffect(CompositeEffect.OPERATOR_OVER, Effect.INPUT_SOURCE_GRAPHIC, this.colorMatrixEffect);
- this.addEffect(this.compositeEffect);
- },
- // 设置投影颜色
- setColor: function(color) {
- var matrix = null, originMatrix = null, colorValue = [];
- if (Utils.isString(color)) {
- color = Color.parse(color);
- }
- if (!color) {
- return this;
- }
- matrix = ColorMatrixEffect.MATRIX_EMPTY.split(" ");
- colorValue.push(color.get("r"));
- colorValue.push(color.get("g"));
- colorValue.push(color.get("b"));
- // rgb 分量更改
- for (var i = 0, len = colorValue.length; i < len; i++) {
- matrix[i * 5 + 3] = colorValue[i] / 255;
- }
- // alpha 分量更改
- matrix[18] = color.get("a");
- this.colorMatrixEffect.set("values", matrix.join(" "));
- return this;
- },
- // 设置投影透明度
- setOpacity: function(opacity) {
- var matrix = this.colorMatrixEffect.get("values").split(" ");
- matrix[18] = opacity;
- this.colorMatrixEffect.set("values", matrix.join(" "));
- return this;
- },
- // 设置阴影偏移量
- setOffset: function(dx, dy) {
- this.setOffsetX(dx);
- this.setOffsetY(dy);
- },
- setOffsetX: function(dx) {
- this.offsetEffect.set("dx", dx);
- },
- setOffsetY: function(dy) {
- this.offsetEffect.set("dy", dy);
- },
- setDeviation: function(deviation) {
- this.gaussianblurEffect.set("stdDeviation", deviation);
- }
- });
- }
- };
- //src/graphic/bezier.js
- /**
- * @fileOverview
- *
- * 贝塞尔曲线
- */
- _p[23] = {
- value: function(require, exports, module) {
- /**
- * @class kity.Bezier
- * @mixins kity.PointContainer
- * @base kity.Path
- * @description 绘制和使用贝塞尔曲线。贝塞尔曲线作为一个贝塞尔点的容器,任何贝塞尔点的改变都会更改贝塞尔曲线的外观
- */
- return _p.r(11).createClass("Bezier", {
- mixins: [ _p.r(51) ],
- base: _p.r(46),
- /**
- * @constructor
- * @for kity.Bezier
- *
- * @grammar new kity.Bezier(bezierPoints)
- *
- * @param {kity.BezierPoints[]} bezierPoints 贝塞尔点集合,每个元素应该是 {kity.BezierPoint} 类型
- *
- * @example
- *
- * ```js
- * var bezier = new kity.Bezier([
- * new kity.BezierPoint(0, 0).setForward(100, 0),
- * new kity.BezierPoint(100, 100).setBackward(100, 0)
- * ]);
- * ```
- */
- constructor: function(bezierPoints) {
- this.callBase();
- bezierPoints = bezierPoints || [];
- this.changeable = true;
- this.setBezierPoints(bezierPoints);
- },
- /**
- * @method getBezierPoints()
- * @for kity.Bezier
- * @description 返回当前贝塞尔曲线的贝塞尔点集合
- *
- * @grammar getBezierPoints() => {kity.BezierPoints[]}
- *
- */
- getBezierPoints: function() {
- return this.getPoints();
- },
- /**
- * @method setBezierPoints()
- * @for kity.Bezier
- * @description 设置当前贝塞尔曲线的贝塞尔点集合
- *
- * @grammar setBeizerPoints(bezierPoints) => {this}
- *
- * @param {kity.BezierPoint[]} bezierPoints 贝塞尔点集合
- */
- setBezierPoints: function(bezierPoints) {
- return this.setPoints(bezierPoints);
- },
- //当点集合发生变化时采取的动作
- onContainerChanged: function() {
- if (this.changeable) {
- this.update();
- }
- },
- update: function() {
- var drawer = null, bezierPoints = this.getBezierPoints();
- //单独的一个点不画任何图形
- if (bezierPoints.length < 2) {
- return;
- }
- drawer = this.getDrawer();
- drawer.clear();
- var vertex = bezierPoints[0].getVertex(), forward = null, backward = null;
- drawer.moveTo(vertex.x, vertex.y);
- for (var i = 1, len = bezierPoints.length; i < len; i++) {
- vertex = bezierPoints[i].getVertex();
- backward = bezierPoints[i].getBackward();
- forward = bezierPoints[i - 1].getForward();
- drawer.bezierTo(forward.x, forward.y, backward.x, backward.y, vertex.x, vertex.y);
- }
- return this;
- }
- });
- }
- };
- //src/graphic/bezierpoint.js
- /**
- * @fileOverview
- *
- * 表示一个贝塞尔点
- */
- _p[24] = {
- value: function(require, exports, module) {
- var ShapePoint = _p.r(63);
- var Vector = _p.r(73);
- /**
- * @class kity.BezierPoint
- *
- * @description 表示一个贝塞尔点
- * 一个贝塞尔点由顶点坐标(曲线经过的点)、前方控制点、后方控制点表示
- */
- var BezierPoint = _p.r(11).createClass("BezierPoint", {
- /**
- * @constructor
- * @for kity.BezierPoint
- *
- * @description 创建一个具有默认顶点坐标的贝塞尔点,两个控制点的坐标和顶点一致
- *
- * @param {Number} x 顶点的 x 坐标
- * @param {Number} y 顶点的 y 坐标
- * @param {Boolean} isSmooth 指示当前贝塞尔点是否光滑,光滑会约束顶点和两个控制点共线
- */
- constructor: function(x, y, isSmooth) {
- //顶点
- this.vertex = new ShapePoint(x, y);
- //控制点
- this.forward = new ShapePoint(x, y);
- this.backward = new ShapePoint(x, y);
- //是否平滑
- this.setSmooth(isSmooth === undefined || isSmooth);
- this.setSymReflaction(true);
- },
- /**
- * @method clone()
- * @for kity.BezierPoint
- * @description 返回贝塞尔点的一份拷贝
- *
- * @grammar clone() => {kity.BezierPoint}
- */
- clone: function() {
- var newPoint = new BezierPoint(), tmp = null;
- tmp = this.getVertex();
- newPoint.setVertex(tmp.x, tmp.y);
- tmp = this.getForward();
- newPoint.setForward(tmp.x, tmp.y);
- tmp = this.getBackward();
- newPoint.setBackward(tmp.x, tmp.y);
- newPoint.setSymReflaction(this.isSymReflaction);
- newPoint.setSmooth(this.isSmooth());
- return newPoint;
- },
- /**
- * @method setVertex()
- * @for kity.BezierPoint
- * @description 设置贝塞尔点的顶点坐标,注意,控制点的坐标不会跟着变化。希望控制点的坐标跟着变化,请用 moveTo() 方法
- *
- * @grammar setVertex(x, y) => {this}
- *
- * @param {Number} x 顶点的 x 坐标
- * @param {Number} y 顶点的 y 坐标
- */
- setVertex: function(x, y) {
- this.vertex.setPoint(x, y);
- this.update();
- return this;
- },
- /**
- * @method moveTo()
- * @for kity.BezierPoint
- * @description 同步移动整个贝塞尔点,使顶点的移动到指定的坐标中。控制点的位置相对顶点坐标固定。
- *
- * @grammar moveTo() => {this}
- *
- * @param {Number} x 顶点的目标 x 坐标
- * @param {Number} y 顶点的目标 y 坐标
- *
- */
- moveTo: function(x, y) {
- var oldForward = this.forward.getPoint(), oldBackward = this.backward.getPoint(), oldVertex = this.vertex.getPoint(), //移动距离
- distance = {
- left: x - oldVertex.x,
- top: y - oldVertex.y
- };
- // 更新
- this.forward.setPoint(oldForward.x + distance.left, oldForward.y + distance.top);
- this.backward.setPoint(oldBackward.x + distance.left, oldBackward.y + distance.top);
- this.vertex.setPoint(x, y);
- this.update();
- },
- /**
- * @method setForward()
- * @for kity.BezierPoint
- * @description 设置前方控制点的位置,如果贝塞尔点光滑,后方控制点会跟着联动
- *
- * @grammar setForward(x, y) => {this}
- *
- * @param {Number} x 前方控制点的 x 坐标
- * @param {Number} y 前方控制点的 y 坐标
- */
- setForward: function(x, y) {
- this.forward.setPoint(x, y);
- //更新后置点
- if (this.smooth) {
- this.updateAnother(this.forward, this.backward);
- }
- this.update();
- this.lastControlPointSet = this.forward;
- return this;
- },
- /**
- * @method setBackward()
- * @for kity.BezierPoint
- * @description 设置后方控制点的位置,如果贝塞尔点光滑,前方控制点会跟着联动
- *
- * @grammar setBackward(x, y) => {this}
- *
- * @param {Number} x 后方控制点的 x 坐标
- * @param {Number} y 后方控制点的 y 坐标
- */
- setBackward: function(x, y) {
- this.backward.setPoint(x, y);
- //更新前置点
- if (this.smooth) {
- this.updateAnother(this.backward, this.forward);
- }
- this.update();
- this.lastControlPointSet = this.backward;
- return this;
- },
- /**
- * @method setSymReflaction()
- * @for kity.BezierPoint
- * @description 设定是否镜像两个控制点的位置
- *
- * @grammar setSymReflaction(value) => {this}
- *
- * @param {boolean} value 如果设置为 true,且贝塞尔点光滑,两个控制点离顶点的距离相等
- */
- setSymReflaction: function(value) {
- this.symReflaction = value;
- if (this.smooth) this.setSmooth(true);
- return this;
- },
- /**
- * @method isSymReflaction()
- * @for kity.BezierPoint
- * @description 当前贝塞尔点的两个控制点是否被镜像约束
- *
- * @grammar isSymReflaction() => {boolean}
- */
- isSymReflaction: function() {
- return this.symReflaction;
- },
- /**
- * @private
- *
- * 根据前方控制点或后方控制点更新另一方
- */
- updateAnother: function(p, q) {
- var v = this.getVertex(), pv = Vector.fromPoints(p.getPoint(), v), vq = Vector.fromPoints(v, q.getPoint());
- vq = pv.normalize(this.isSymReflaction() ? pv.length() : vq.length());
- q.setPoint(v.x + vq.x, v.y + vq.y);
- return this;
- },
- /**
- * @method setSmooth()
- * @for kity.BezierPoint
- * @description 设置贝塞尔点是否光滑,光滑会约束顶点和两个控制点共线
- *
- * @param {Boolean} isSmooth 设置为 true 让贝塞尔点光滑
- */
- setSmooth: function(isSmooth) {
- var lc;
- this.smooth = !!isSmooth;
- if (this.smooth && (lc = this.lastControlPointSet)) {
- this.updateAnother(lc, lc == this.forward ? this.backward : this.forward);
- }
- return this;
- },
- /**
- * @method isSmooth()
- * @for kity.BezierPoint
- * @description 判断贝塞尔点是否光滑
- *
- * @grammar isSmooth() => {boolean}
- */
- isSmooth: function() {
- return this.smooth;
- },
- /**
- * @method getVertex()
- * @for kity.BezierPoint
- * @description 获得当前贝塞尔点的顶点
- *
- * @grammar getVertex() => {kity.ShapePoint}
- */
- getVertex: function() {
- return this.vertex.getPoint();
- },
- /**
- * @method getForward()
- * @for kity.BezierPoint
- * @description 获得当前贝塞尔点的前方控制点
- *
- * @grammar getForward() => {kity.ShapePoint}
- */
- getForward: function() {
- return this.forward.getPoint();
- },
- /**
- * @method getBackward()
- * @for kity.BezierPoint
- * @description 获得当前贝塞尔点的后方控制点
- *
- * @grammar getBackward() => {kity.ShapePoint}
- */
- getBackward: function() {
- return this.backward.getPoint();
- },
- /**
- * @private
- *
- * 联动更新相关的贝塞尔曲线
- */
- update: function() {
- if (!this.container) {
- return this;
- }
- //新增参数 this, 把当前引起变化的点传递过去, 以便有需要的地方可以获取到引起变化的源
- if (this.container.update) this.container.update(this);
- }
- });
- return BezierPoint;
- }
- };
- //src/graphic/box.js
- /**
- * @fileOverview
- *
- * 表示一个矩形区域
- */
- _p[25] = {
- value: function(require, exports, module) {
- /**
- * @class kity.Box
- * @description 表示一个矩形区域
- */
- var Box = _p.r(11).createClass("Box", {
- /**
- * @constructor
- * @for kity.Box
- *
- * @grammar new kity.Box(x, y, width, height)
- * @grammar new kity.Box(box)
- *
- * @param {Number} x|box.x 矩形区域的 x 坐标
- * @param {Number} y|box.y 矩形区域的 y 坐标
- * @param {Number} width|box.width 矩形区域的宽度
- * @param {Number} height|box.height 矩形区域的高度
- *
- * @example
- *
- * ```js
- * var box = new kity.Box(10, 20, 50, 50);
- * var box2 = new kity.Box({x: 10, y: 20, width: 50, height: 50});
- * ```
- */
- constructor: function(x, y, width, height) {
- var box = arguments[0];
- if (box && typeof box === "object") {
- x = box.x;
- y = box.y;
- width = box.width;
- height = box.height;
- }
- if (width < 0) {
- x -= width = -width;
- }
- if (height < 0) {
- y -= height = -height;
- }
- /**
- * @property x
- * @for kity.Box
- * @type {Number}
- * @readOnly
- * @description 矩形区域的 x 坐标
- */
- this.x = x || 0;
- /**
- * @property y
- * @for kity.Box
- * @type {Number}
- * @readOnly
- * @description 矩形区域的 y 坐标
- */
- this.y = y || 0;
- /**
- * @property width
- * @for kity.Box
- * @type {Number}
- * @readOnly
- * @description 矩形区域的宽度
- */
- this.width = width || 0;
- /**
- * @property height
- * @for kity.Box
- * @type {Number}
- * @readOnly
- * @description 矩形区域的高度
- */
- this.height = height || 0;
- /**
- * @property left
- * @for kity.Box
- * @type {Number}
- * @readOnly
- * @description 矩形区域的最左侧坐标,等价于 x 的值
- */
- this.left = this.x;
- /**
- * @property right
- * @for kity.Box
- * @type {Number}
- * @readOnly
- * @description 矩形区域的最右侧坐标,等价于 x + width 的值
- */
- this.right = this.x + this.width;
- /**
- * @property top
- * @for kity.Box
- * @type {Number}
- * @readOnly
- * @description 矩形区域的最上侧坐标,等价于 y 的值
- */
- this.top = this.y;
- /**
- * @property bottom
- * @for kity.Box
- * @type {Number}
- * @readOnly
- * @description 矩形区域的最下侧坐标,等价于 y + height 的值
- */
- this.bottom = this.y + this.height;
- /**
- * @property cx
- * @for kity.Box
- * @type {Number}
- * @readOnly
- * @description 矩形区域的中心 x 坐标
- */
- this.cx = this.x + this.width / 2;
- /**
- * @property cy
- * @for kity.Box
- * @type {Number}
- * @readOnly
- * @description 矩形区域的中心 y 坐标
- */
- this.cy = this.y + this.height / 2;
- },
- /**
- * @method getRangeX()
- * @for kity.Box
- * @description 获得矩形区域的 x 值域
- *
- * @grammar getRangeX() => {Number[]}
- *
- * @example
- *
- * var box = new kity.Box(10, 10, 30, 50);
- * console.log(box.getRangeX()); // [10, 40]
- */
- getRangeX: function() {
- return [ this.left, this.right ];
- },
- /**
- * @method getRangeY()
- * @for kity.Box
- * @description 获得矩形区域的 y 值域
- *
- * @grammar getRangeY() => {Number[]}
- *
- * @example
- *
- * var box = new kity.Box(10, 10, 30, 50);
- * console.log(box.getRangeY()); // [10, 60]
- */
- getRangeY: function() {
- return [ this.top, this.bottom ];
- },
- /**
- * @method merge()
- * @for kity.Box
- * @description 把当前矩形区域和指定的矩形区域合并,返回一个新的矩形区域(即包含两个源矩形区域的最小矩形区域)
- *
- * @grammar merge(another) => {kity.Box}
- * @param {kity.Box} another 要合并的矩形区域
- *
- * @example
- *
- * ```js
- * var box1 = new kity.Box(10, 10, 50, 50);
- * var box2 = new kity.Box(30, 30, 50, 50);
- * var box3 = box1.merge(box2);
- * console.log(box3.valueOf()); // [10, 10, 70, 70]
- * ```
- */
- merge: function(another) {
- if (this.isEmpty()) {
- return new Box(another.x, another.y, another.width, another.height);
- }
- var left = Math.min(this.left, another.left), right = Math.max(this.right, another.right), top = Math.min(this.top, another.top), bottom = Math.max(this.bottom, another.bottom);
- return new Box(left, top, right - left, bottom - top);
- },
- /**
- * @method intersect()
- * @for kity.Box
- * @description 求当前矩形区域和指定的矩形区域重叠的矩形区域
- *
- * @grammar intersect(another) => {kity.Box}
- * @param {kity.Box} another 要求重叠的矩形区域
- *
- * @example
- *
- * ```js
- * var box1 = new kity.Box(10, 10, 50, 50);
- * var box2 = new kity.Box(30, 30, 50, 50);
- * var box3 = box1.intersect(box2);
- * console.log(box3.valueOf()); // [30, 30, 20, 20]
- * ```
- */
- intersect: function(another) {
- if (!another instanceof Box) {
- another = new Box(another);
- }
- var left = Math.max(this.left, another.left), right = Math.min(this.right, another.right), top = Math.max(this.top, another.top), bottom = Math.min(this.bottom, another.bottom);
- if (left > right || top > bottom) return new Box();
- return new Box(left, top, right - left, bottom - top);
- },
- /**
- * @method expand()
- * @for kity.Box
- * @description 扩展(或收缩)当前的盒子,返回新的盒子
- *
- * @param {Number} top
- * 矩形区域的上边界往上扩展的值;如果是负数,则上边界往下收缩
- *
- * @param {Number} right
- * [Optional] 矩形区域的右边界往右拓展的值;
- * 如果是负数,则右边界往左收缩;
- * 如果不设置该值,使用和 top 同样的值。
- *
- * @param {Number} bottom
- * [Optional] 矩形区域的下边界往下拓展的值;
- * 如果是负数,则下边界往上收缩;
- * 如果不设置该值,使用和 top 同样的值。
- *
- * @param {Number} left
- * [Optional] 矩形区域的左边界往左拓展的值;
- * 如果是负数,则左边界往右收缩;
- * 如果不设置该值,使用和 right 同样的值。
- *
- * @example
- *
- * ```js
- * var box = new kity.Box(10, 10, 20, 20);
- * var box1 = box.expand(10); // [0, 0, 40, 40]
- * var box2 = box.expand(10, 20); // [0, -10, 40, 60]
- * var box3 = box.expand(1, 2, 3, 4); // [9, 8, 24, 26]
- * ```
- */
- expand: function(top, right, bottom, left) {
- if (arguments.length < 1) {
- return new Box(this);
- }
- if (arguments.length < 2) {
- right = top;
- }
- if (arguments.length < 3) {
- bottom = top;
- }
- if (arguments.length < 4) {
- left = right;
- }
- var x = this.left - left, y = this.top - top, width = this.width + right, height = this.height + top;
- return new Box(x, y, width, height);
- },
- /**
- * @method valueOf()
- * @for kity.Box
- * @description 返回当前盒子的数组表示
- *
- * @grammar valueOf() => {Number[]}
- *
- * @example
- *
- * ```js
- * var box = new kity.Box(0, 0, 200, 50);
- * console.log(box.valueOf()); // [0, 0, 200, 50]
- * ```
- */
- valueOf: function() {
- return [ this.x, this.y, this.width, this.height ];
- },
- /**
- * @method toString()
- * @for kity.Box
- * @description 返回当前盒子的字符串表示
- *
- * @grammar toString() => {String}
- *
- * @example
- *
- * ```js
- * var box = new kity.Box(0, 0, 200, 50);
- * console.log(box.toString()); // "0 0 200 50"
- */
- toString: function() {
- return this.valueOf().join(" ");
- },
- /**
- * @method isEmpty()
- * @for kity.Box
- * @description 判断当前盒子是否具有尺寸(面积大
- *
- * @grammar isEmpty() => {boolean}
- *
- * @example
- * ```js
- * var box = new kity.Box(0, 0, 0, 100000);
- * console.log(box.isEmpty()); // true
- * ```
- */
- isEmpty: function() {
- return !this.width || !this.height;
- }
- });
- /**
- * @method parse()
- * @static
- * @for kity.Box
- * @description 解析一个字符串或数组为 kity.Box 对象
- *
- * @grammar kity.Box.parse(any) => {kity.Box}
- *
- * @param {Number[]|String} any 要解析的字符串或数组
- *
- * @example
- *
- * ```js
- * console.log(kity.Box.parse('0 0 100 200'));
- * console.log(kity.Box.parse([0, 0, 100, 200]));
- * ```
- */
- Box.parse = function(any) {
- if (typeof any == "string") {
- return Box.parse(any.split(/[\s,]+/).map(parseFloat));
- }
- if (any instanceof Array) {
- return new Box(any[0], any[1], any[2], any[3]);
- }
- if ("x" in any) return new Box(any);
- return null;
- };
- return Box;
- }
- };
- //src/graphic/circle.js
- /**
- * @fileOverview
- *
- * 绘制和使用圆形
- */
- _p[26] = {
- value: function(require, exports, module) {
- /**
- * @class kity.Circle
- * @base kity.Ellipse
- * @description 表示一个圆形
- */
- return _p.r(11).createClass("Circle", {
- base: _p.r(32),
- /**
- * @constructor
- * @for kity.Circle
- *
- * @grammar new kity.Circle(radius, cx, cy)
- *
- * @param {Number} radius 半径
- * @param {Number} cx 圆心 x 坐标
- * @param {Number} cy 圆心 y 坐标
- */
- constructor: function(radius, cx, cy) {
- this.callBase(radius, radius, cx, cy);
- },
- /**
- * @method
- * @for kity.Circle
- * @description 获取圆形的半径
- *
- * @grammar getRadius() => {Number}
- */
- getRadius: function() {
- return this.getRadiusX();
- },
- /**
- * @method
- * @for kity.Circle
- * @description 设置圆形的半径
- *
- * @grammar setRadius() => {this}
- *
- * @param {Number} radius 半径大小
- */
- setRadius: function(radius) {
- return this.callBase(radius, radius);
- }
- });
- }
- };
- //src/graphic/clip.js
- /**
- * @fileOverview
- *
- * 支持图形裁切
- */
- _p[27] = {
- value: function(require, exports, module) {
- var Class = _p.r(11);
- var Shape = _p.r(60);
- /**
- * @class kity.Clip
- * @base kity.Resource
- * @mixins kity.ShapeContainer
- *
- * @description 创建图形裁切,用于裁切目标图形
- */
- var Clip = Class.createClass("Clip", {
- base: Shape,
- mixins: [ _p.r(61) ],
- /**
- * @constructor
- * @for kity.Clip
- *
- * @grammar new kity.Clip(paper)
- *
- * @param {kity.Paper} paper 资源所属的文档
- *
- * @example
- *
- * ```js
- * var circle = paper.put(new kity.Circle(100).fill('yellow'));
- * var clip = new kity.Clip(paper);
- * clip.addShape(new kity.Circle(100, 50, 0));
- * clip.clip(circle);
- * ```
- */
- constructor: function(paper) {
- this.callBase("clipPath", paper);
- },
- /**
- * @method clip()
- * @for kity.Clip
- * @description 将裁切应用到指定的图形上,应用之后,目标图形将显示与裁切形状重合的部分
- *
- * @grammar clip(shape) => {this}
- *
- * @param {kity.Shape} shape 要应用裁切的图形
- */
- clip: function(shape) {
- shape.getNode().setAttribute("clip-path", this);
- return this;
- }
- });
- Class.extendClass(Shape, {
- /**
- * @method clipWidth()
- * @for kity.Shape
- *
- * @grammar clipWidth(clip) => {this}
- *
- * @param {kity.Clip|kity.Shape} clip 要用于裁切当前图形的图形;
- * 如果 clip 本身是一个裁切对象(kity.Clip 类型),则直接裁切;
- * 否则将创建新的裁切包含给定的图形,然后对当前图形进行裁切
- *
- * @example
- *
- * ```js
- * var circle = paper.put(new kity.Circle(100));
- * var rect = paper.put(new kity.Rect(100, 100, -100, 0));
- *
- * circle.clipWidth(rect);
- * ```
- */
- clipWith: function(clip) {
- if (clip instanceof Shape) {
- clip = new Clip(clip.getPaper()).addShape(clip);
- }
- clip.clip(this);
- return this;
- }
- });
- return Clip;
- }
- };
- //src/graphic/color.js
- /**
- * @fileOverview
- *
- * 提供颜色支持
- */
- _p[28] = {
- value: function(require, exports, module) {
- var Utils = _p.r(12), StandardColor = _p.r(64), ColorUtils = {}, /**
- * @class kity.Color
- * @description 表示一个颜色
- */
- Color = _p.r(11).createClass("Color", {
- /**
- * @constructor
- * @for kity.Color
- *
- * @grammar new kity.Color(r, g, b)
- * @grammar new kity.Color(r, g, b, a)
- * @grammar new kity.Color(colorString)
- *
- * @param {Number} r 红色分量,取值 0 - 255
- * @param {Number} g 绿色分量,取值 0 - 255
- * @param {Number} b 蓝色分量,取值 0 - 255
- * @param {Number} a 透明度(可选),取值 0 - 100
- * @param {String} colorString 一个代表颜色的字符串,可以是:
- * 熟知颜色表:如 'red', 'yellow'
- * HEX 表示:如 '#368', '#123456'
- * RGB 表示:如 'RGB(200, 200, 0)', 'RGBA(200, 200, 200, .5)'
- * HSL 表示:如 'HSL(100, 60%, 80%)', 'HSLA(100, 60%, 80%, .5)'
- */
- constructor: function() {
- var colorValue = null;
- //parse构造
- if (typeof arguments[0] === "string") {
- colorValue = ColorUtils.parseToValue(arguments[0]);
- //解析失败
- if (colorValue === null) {
- colorValue = {
- r: 0,
- g: 0,
- b: 0,
- h: 0,
- s: 0,
- l: 0,
- a: 1
- };
- }
- } else {
- colorValue = {
- r: arguments[0] | 0,
- g: arguments[1] | 0,
- b: arguments[2] | 0,
- //alpha 默认为1
- a: arguments[3] === undefined ? 1 : parseFloat(arguments[3])
- };
- colorValue = ColorUtils.overflowFormat(colorValue);
- //获取hsl分量
- colorValue = Utils.extend(colorValue, ColorUtils.rgbValueToHslValue(colorValue));
- }
- this._color = colorValue;
- },
- /**
- * @method set()
- * @for kity.Color
- *
- * @description 设置当前颜色某个分量的值
- *
- * @grammar set(name, value) => {this}
- *
- * @param {string} name 要设置的颜色通道的名称
- * r: 红色(Red),取值范围 [0, 255]
- * g: 绿色(Green),取值范围 [0, 255]
- * b: 蓝色(Blue),取值范围 [0, 255]
- * a: 透明度(Alpha),取值范围 [0, 1]
- * h: 色环角度(Hue),取值范围 [0, 359]
- * s: 饱和度(Saturation),取值范围 [0, 100]
- * l: 亮度(Lightness),取值范围 [0, 100]
- * r、g、b 值和 h、s、l 值会联动修改
- * @param {number} value 要设置的值
- */
- set: function(name, value) {
- var values = null;
- //设置的值非法
- if (!Color._MAX_VALUE[name]) {
- throw new Error("Color set(): Illegal parameter");
- }
- if (name !== "a") {
- value = Math.floor(value);
- }
- if (name == "h") {
- value = (value + 360) % 360;
- }
- this._color[name] = Math.max(Color._MIN_VALUE[name], Math.min(Color._MAX_VALUE[name], value));
- if ("rgb".indexOf(name) !== -1) {
- this._color = Utils.extend(this._color, ColorUtils.rgbValueToHslValue(this._color));
- } else if ("hsl".indexOf(name) !== -1) {
- this._color = Utils.extend(this._color, ColorUtils.hslValueToRGBValue(this._color));
- }
- return this;
- },
- /**
- * @method inc()
- *
- * @description 返回新的颜色,表示当前颜色增加指定通道的值之后的颜色
- *
- * @grammar inc(name, value) => {this}
- *
- * @param {string} name 要增加的通道的名称,具体含义请查看 set 方法
- * @param {number} value 增量值
- */
- inc: function(name, value) {
- value = this.get(name) + value;
- if (name == "h") {
- value = (value + 360) % 360;
- } else {
- value = Math.min(Color._MAX_VALUE[name], value);
- value = Math.max(Color._MIN_VALUE[name], value);
- }
- return this.clone().set(name, value);
- },
- /**
- * @method dec()
- * @for kity.Color
- *
- * @description 返回新的颜色,表示当前颜色减少指定通道的值之后的颜色
- *
- * @grammar dec(name, value) => {this}
- *
- * @param {string} name 要减少值的通道的名称,具体含义请查看 set 方法
- * @param {number} value 减量值
- */
- dec: function(name, value) {
- return this.inc(name, -value);
- },
- /**
- * @method clone()
- * @for kity.Color
- *
- * @description 返回当前颜色的一个拷贝
- *
- * @grammar clone() => {kity.Color}
- */
- clone: function() {
- return new Color(this.toRGBA());
- },
- /**
- * @method get()
- * @for kity.Color
- *
- * @description 返回当前颜色指定的分量
- *
- * @grammar get() => {number}
- */
- get: function(name) {
- if (!Color._MAX_VALUE[name]) {
- return null;
- }
- return this._color[name];
- },
- getValues: function() {
- return Utils.clone(this._color);
- },
- /**
- * @method valueOf()
- * @for kity.Color
- *
- * @description 返回当前颜色的一个字面量表示
- *
- * @return {plain} 颜色字面量,其结构为:
- * {
- * r: 0,
- * g: 0,
- * b: 0,
- * a: 0,
- * h: 0,
- * s: 0,
- * l: 0
- * }
- */
- valueOf: function() {
- return this.getValues();
- },
- /**
- * @method toRGB()
- * @for kity.Color
- *
- * @description 返回当前颜色的 RGB 表示,如果颜色有透明度,将抛弃透明度属性(想要保留请使用 toRGBA())方法。
- *
- * @grammar toRGB() => {string}
- */
- toRGB: function() {
- return ColorUtils.toString(this._color, "rgb");
- },
- /**
- * @method toRGBA()
- * @for kity.Color
- *
- * @description 返回当前颜色的 RGBA 表示
- *
- * @grammar toRGBA() => {string}
- */
- toRGBA: function() {
- return ColorUtils.toString(this._color, "rgba");
- },
- /**
- * @method toHEX()
- * @for kity.Color
- *
- * @description 返回当前颜色的 HEX 表示,如果颜色有透明度,将抛弃透明度属性(想要保留请使用 toRGBA())方法。
- *
- * @grammar toHEX() => {string}
- */
- toHEX: function() {
- return ColorUtils.toString(this._color, "hex");
- },
- /**
- * @method toHSL()
- * @for kity.Color
- *
- * @description 返回当前颜色的 HSL 表示,如果颜色有透明度,将抛弃透明度属性(想要保留请使用 toHSLA())方法。
- *
- * @grammar toHSL() => {string}
- */
- toHSL: function() {
- return ColorUtils.toString(this._color, "hsl");
- },
- /**
- * @method toHSLA()
- * @for kity.Color
- *
- * @description 返回当前颜色的 HSLA 表示
- *
- * @grammar toHSLA() => {string}
- */
- toHSLA: function() {
- return ColorUtils.toString(this._color, "hsla");
- },
- /**
- * @method toString()
- * @for kity.Color
- *
- * @description 返回当前颜色的 RGB 或 RGBA 表示,如果颜色有透明度,将使用 RGBA 形式,否则是 RGB 形式
- * @grammar toString() => {string}
- */
- toString: function() {
- if (this._color.a === 1) {
- return this.toRGB();
- }
- return this.toRGBA();
- }
- });
- //Color 静态方法
- Utils.extend(Color, {
- //各分量可表示的最大值
- _MAX_VALUE: {
- r: 255,
- g: 255,
- b: 255,
- h: 360,
- s: 100,
- l: 100,
- a: 1
- },
- //各分量最小值
- _MIN_VALUE: {
- r: 0,
- g: 0,
- b: 0,
- h: 0,
- s: 0,
- l: 0,
- a: 0
- },
- //分量常量
- R: "r",
- G: "g",
- B: "b",
- H: "h",
- S: "s",
- L: "l",
- A: "a",
- /**
- * @method parse()
- * @static
- * @for kity.Color
- *
- * @description 解析一个颜色字符串为 kity.Color 对象
- *
- * @grammar kity.Color.parse(valStr)
- *
- * @param {string} valStr 一个代表颜色的字符串,可以是:
- * 熟知颜色表:如 'red', 'yellow'
- * HEX 表示:如 '#368', '#123456'
- * RGB 表示:如 'RGB(200, 200, 0)', 'RGBA(200, 200, 200, .5)'
- * HSL 表示:如 'HSL(100, 60%, 80%)', 'HSLA(100, 60%, 80%, .5)'
- */
- parse: function(valStr) {
- var rgbValue;
- if (Utils.isString(valStr)) {
- rgbValue = ColorUtils.parseToValue(valStr);
- }
- if (Utils.isObject(valStr) && "r" in valStr) {
- rgbValue = valStr;
- }
- //解析失败, 返回一个默认color实例
- if (rgbValue === null) {
- return new Color();
- }
- return new Color(rgbValue.r, rgbValue.g, rgbValue.b, rgbValue.a);
- },
- /**
- * @method createHSL()
- * @for kity.Color
- * @static
- *
- * @description 创建一个 HSL 颜色
- *
- * @grammar kity.Color.createHSL(h, s, l) => {kity.Color}
- *
- * @param {number} h 色环(Hue)分量值,取值范围 [0, 359]
- * @param {number} s 饱和度(Saturation)分量值,取值范围 [0, 100]
- * @param {number} l 亮度(Lighteness)分量值,取值范围 [0, 100]
- */
- createHSL: function(h, s, l) {
- return Color.createHSLA(h, s, l, 1);
- },
- /**
- * @method createHSLA()
- * @for kity.Color
- * @static
- *
- * @description 创建一个 HSLA 颜色
- *
- * @grammar kity.Color.createHSLA(h, s, l, a) => {kity.Color}
- *
- * @param {number} h 色环(Hue)分量值,取值范围 [0, 359]
- * @param {number} s 饱和度(Saturation)分量值,取值范围 [0, 100]
- * @param {number} l 亮度(Lighteness)分量值,取值范围 [0, 100]
- * @param {number} a 透明度(Alpha)分量值,取值范围 [0, 1]
- */
- createHSLA: function(h, s, l, a) {
- var colorValue = null;
- s += "%";
- l += "%";
- colorValue = [ "hsla(" + h, s, l, a + ")" ];
- return Color.parse(colorValue.join(", "));
- },
- /**
- * @method createRGB()
- * @for kity.Color
- * @static
- *
- * @description 创建一个 RGB 颜色
- *
- * @grammar kity.Color.createRGB(r, g, b) => {kity.Color}
- *
- * @param {number} r 红色(Red)分量值,取值范围 [0, 255]
- * @param {number} g 绿色(Green)分量值,取值范围 [0, 255]
- * @param {number} b 蓝色(Blue)分量值,取值范围 [0, 255]
- */
- createRGB: function(r, g, b) {
- return Color.createRGBA(r, g, b, 1);
- },
- /**
- * @method createRGBA()
- * @for kity.Color
- * @static
- *
- * @description 创建一个 RGBA 颜色
- *
- * @grammar kity.Color.createRGBA(r, g, b, a) => {kity.Color}
- *
- * @param {number} r 红色(Red)分量值,取值范围 [0, 255]
- * @param {number} g 绿色(Green)分量值,取值范围 [0, 255]
- * @param {number} b 蓝色(Blue)分量值,取值范围 [0, 255]
- * @param {number} a 透明度(Alpha)分量值,取值范围 [0, 1]
- */
- createRGBA: function(r, g, b, a) {
- return new Color(r, g, b, a);
- }
- });
- //内部工具对象
- Utils.extend(ColorUtils, {
- parseToValue: function(valStr) {
- var rgbaValue = {};
- /* 优先检测在调色板中是否有对应的颜色 */
- valStr = StandardColor.EXTEND_STANDARD[valStr] || StandardColor.COLOR_STANDARD[valStr] || valStr;
- /* 颜色转换 */
- //hex格式
- if (/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(valStr)) {
- rgbaValue = ColorUtils.hexToValue(valStr);
- } else if (/^(rgba?)/i.test(valStr)) {
- rgbaValue = ColorUtils.rgbaToValue(valStr);
- } else if (/^(hsla?)/i.test(valStr)) {
- rgbaValue = ColorUtils.hslaToValue(valStr);
- } else {
- return null;
- }
- return ColorUtils.overflowFormat(rgbaValue);
- },
- hexToValue: function(hexStr) {
- var result = {}, keys = [ "r", "g", "b" ];
- if (/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(hexStr)) {
- hexStr = RegExp.$1.split("");
- Utils.each(keys, function(key, index) {
- if (hexStr.length === 3) {
- result[key] = ColorUtils.toNumber(hexStr[index] + hexStr[index]);
- } else {
- result[key] = ColorUtils.toNumber(hexStr[index * 2] + hexStr[index * 2 + 1]);
- }
- });
- //转换出hsl值
- result = Utils.extend(result, ColorUtils.rgbValueToHslValue(result));
- result.a = 1;
- return result;
- }
- return null;
- },
- rgbaToValue: function(rgbaStr) {
- var result = {}, hasAlpha = false, keys = [ "r", "g", "b" ];
- if (/^(rgba?)/i.test(rgbaStr)) {
- hasAlpha = RegExp.$1.length === 4;
- rgbaStr = rgbaStr.replace(/^rgba?/i, "").replace(/\s+/g, "").replace(/[^0-9,.]/g, "").split(",");
- Utils.each(keys, function(key, index) {
- result[key] = rgbaStr[index] | 0;
- });
- //转换出hsl值
- result = Utils.extend(result, ColorUtils.rgbValueToHslValue(result));
- result.a = hasAlpha ? parseFloat(rgbaStr[3]) : 1;
- return result;
- }
- return null;
- },
- hslaToValue: function(hslaStr) {
- var result = {}, hasAlpha = false;
- if (/^(hsla?)/i.test(hslaStr)) {
- hasAlpha = RegExp.$1.length === 4;
- hslaStr = hslaStr.replace(/^hsla?/i, "").replace(/\s+/g, "").replace(/[^0-9,.]/g, "").split(",");
- //记录hsl值
- result.h = hslaStr[0] | 0;
- result.s = hslaStr[1] | 0;
- result.l = hslaStr[2] | 0;
- //转换出rgb值
- result = Utils.extend(result, ColorUtils.hslValueToRGBValue(result));
- //hsl值转换为rgb值
- result = ColorUtils.hslValueToRGBValue(result);
- result.a = hasAlpha ? parseFloat(hslaStr[3]) : 1;
- return result;
- }
- return null;
- },
- //hsl值对象转换为rgb值对象
- hslValueToRGBValue: function(hslValue) {
- function trans(v1, v2, vH) {
- if (vH < 0) {
- vH += 1;
- } else if (vH > 1) {
- vH -= 1;
- }
- if (6 * vH < 1) {
- return v1 + (v2 - v1) * 6 * vH;
- } else if (2 * vH < 1) {
- return v2;
- } else if (3 * vH < 2) {
- return v1 + (v2 - v1) * ((2 / 3 - vH) * 6);
- }
- return v1;
- }
- var q = null, p = null, result = {};
- hslValue = Utils.extend({}, hslValue);
- hslValue.h = hslValue.h / 360;
- hslValue.s = hslValue.s / 100;
- hslValue.l = hslValue.l / 100;
- //分量计算
- if (hslValue.s === 0) {
- result.r = result.g = result.b = hslValue.l;
- } else {
- if (hslValue.l < .5) {
- q = hslValue.l * (1 + hslValue.s);
- } else {
- q = hslValue.l + hslValue.s - hslValue.l * hslValue.s;
- }
- p = 2 * hslValue.l - q;
- result.r = trans(p, q, hslValue.h + 1 / 3);
- result.g = trans(p, q, hslValue.h);
- result.b = trans(p, q, hslValue.h - 1 / 3);
- }
- result.r = Math.min(Math.round(result.r * 255), 255);
- result.g = Math.min(Math.round(result.g * 255), 255);
- result.b = Math.min(Math.round(result.b * 255), 255);
- return result;
- },
- //rgb值对象转换为hsl值对象
- rgbValueToHslValue: function(rgbValue) {
- var max = null, min = null, result = {};
- rgbValue = Utils.extend({}, rgbValue);
- rgbValue.r = rgbValue.r / 255;
- rgbValue.g = rgbValue.g / 255;
- rgbValue.b = rgbValue.b / 255;
- max = Math.max(rgbValue.r, rgbValue.g, rgbValue.b);
- min = Math.min(rgbValue.r, rgbValue.g, rgbValue.b);
- //h分量计算
- if (max === min) {
- result.h = 0;
- } else if (max === rgbValue.r) {
- if (rgbValue.g >= rgbValue.b) {
- result.h = 60 * (rgbValue.g - rgbValue.b) / (max - min);
- } else {
- result.h = 60 * (rgbValue.g - rgbValue.b) / (max - min) + 360;
- }
- } else if (max === rgbValue.g) {
- result.h = 60 * (rgbValue.b - rgbValue.r) / (max - min) + 120;
- } else if (max === rgbValue.b) {
- result.h = 60 * (rgbValue.r - rgbValue.g) / (max - min) + 240;
- }
- //l分量计算
- result.l = (max + min) / 2;
- //s分量计算
- if (result.l === 0 || max === min) {
- result.s = 0;
- } else if (result.l > 0 && result.l <= .5) {
- result.s = (max - min) / (max + min);
- } else {
- result.s = (max - min) / (2 - max - min);
- }
- //格式化hsl结果
- result.h = Math.round(result.h);
- result.s = Math.round(result.s * 100);
- result.l = Math.round(result.l * 100);
- return result;
- },
- toString: function(colorValue, type) {
- var vals = [];
- colorValue = Utils.extend({}, colorValue);
- if (type.indexOf("hsl") !== -1) {
- colorValue.s += "%";
- colorValue.l += "%";
- }
- if (type !== "hex") {
- Utils.each(type.split(""), function(key) {
- vals.push(colorValue[key]);
- });
- return (type + "(" + vals.join(", ") + ")").toLowerCase();
- } else {
- vals.push(ColorUtils.toHexValue(+colorValue.r));
- vals.push(ColorUtils.toHexValue(+colorValue.g));
- vals.push(ColorUtils.toHexValue(+colorValue.b));
- return ("#" + vals.join("")).toLowerCase();
- }
- },
- //16进制的2个数字转化为10进制, 如果转化失败, 返回0
- toNumber: function(value) {
- return Number("0x" + value) | 0;
- },
- toHexValue: function(value) {
- var result = value.toString(16);
- return result.length === 1 ? "0" + result : result;
- },
- //溢出控制
- overflowFormat: function(value) {
- var tmpValue = Utils.extend({}, value), keys = "rgba";
- Utils.each(keys.split(""), function(key) {
- if (!tmpValue.hasOwnProperty(key)) {
- return;
- }
- //上溢出
- tmpValue[key] = Math.min(Color._MAX_VALUE[key], tmpValue[key]);
- //下溢出
- tmpValue[key] = Math.max(Color._MIN_VALUE[key], tmpValue[key]);
- });
- return tmpValue;
- }
- });
- return Color;
- }
- };
- //src/graphic/container.js
- _p[29] = {
- value: function(require, exports, module) {
- function itemRemove() {
- this.container.removeItem(this);
- return this;
- }
- return _p.r(11).createClass("Container", {
- getItems: function() {
- return this.items || (this.items = []);
- },
- getItem: function(index) {
- return this.getItems()[index];
- },
- getFirstItem: function() {
- return this.getItem(0);
- },
- getLastItem: function() {
- return this.getItem(this.getItems().length - 1);
- },
- indexOf: function(item) {
- return this.getItems().indexOf(item);
- },
- eachItem: function(fn) {
- var items = this.getItems(), length = items.length, i;
- for (i = 0; i < length; i++) {
- fn.call(this, i, items[i]);
- }
- return this;
- },
- addItem: function(item, pos, noEvent) {
- var items = this.getItems(), length = items.length;
- if (~items.indexOf(item)) {
- return this;
- }
- if (!(pos >= 0 && pos < length)) {
- pos = length;
- }
- items.splice(pos, 0, item);
- if (typeof item === "object") {
- item.container = this;
- item.remove = itemRemove;
- }
- this.handleAdd(item, pos);
- if (!noEvent) {
- this.onContainerChanged("add", [ item ]);
- }
- return this;
- },
- addItems: function(items) {
- for (var i = 0, l = items.length; i < l; i++) {
- this.addItem(items[i], -1, true);
- }
- this.onContainerChanged("add", items);
- return this;
- },
- setItems: function(items) {
- return this.clear().addItems(items);
- },
- appendItem: function(item) {
- return this.addItem(item);
- },
- prependItem: function(item) {
- return this.addItem(item, 0);
- },
- removeItem: function(pos, noEvent) {
- if (typeof pos !== "number") {
- return this.removeItem(this.indexOf(pos));
- }
- var items = this.getItems(), length = items.length, item = items[pos];
- if (item === undefined) {
- return this;
- }
- items.splice(pos, 1);
- if (item.container) {
- delete item.container;
- }
- if (item.remove) {
- delete item.remove;
- }
- this.handleRemove(item, pos);
- if (!noEvent) {
- this.onContainerChanged("remove", [ item ]);
- }
- return this;
- },
- clear: function() {
- var removed = [];
- var item;
- while (item = this.getFirstItem()) {
- removed.push(item);
- this.removeItem(0, true);
- }
- this.onContainerChanged("remove", removed);
- return this;
- },
- onContainerChanged: function(type, items) {},
- handleAdd: function(item, index) {},
- handleRemove: function(item, index) {}
- });
- }
- };
- //src/graphic/curve.js
- /*
- * 曲线
- * */
- _p[30] = {
- value: function(require, exports, module) {
- var Utils = _p.r(12), CurveUtil = {
- /*
- * 获取由两个以上的点组成的曲线的平移线
- * @param points 曲线上的点的集合, 集合中的点的数量必须大于2
- * @return 平移线数组
- */
- getCurvePanLines: function(points, smoothFactor) {
- //计算原始点的中点坐标
- var centerPoints = CurveUtil.getCenterPoints(points), //注意:计算中点连线的中点坐标, 得出平移线
- panLines = CurveUtil.getPanLine(points.length, centerPoints);
- //平移线移动到顶点
- return CurveUtil.getMovedPanLines(points, panLines, smoothFactor);
- },
- /*
- * 计算给定点集合的连线的中点
- * @param points
- */
- getCenterPoints: function(points) {
- var centerPoints = {}, key = null;
- for (var i = 0, j = 0, len = points.length; i < len; i++) {
- //j是下一个点的索引
- j = i === len - 1 ? 0 : i + 1;
- key = i + "," + j;
- //计算中点坐标
- centerPoints[key] = {
- x: (points[i].x + points[j].y) / 2,
- y: (points[i].x + points[j].y) / 2
- };
- }
- return centerPoints;
- },
- /*
- * 对getCenterPoints()接口获取到的数据做处理, 计算出各个顶点对应的平移线数据
- * @param length 集合中点的个数
- * @param points 点集合, 该集合应该是getCenterPoints()接口返回的数据
- */
- getPanLine: function(length, points) {
- var result = {}, //顶点索引
- pointIndex = null;
- for (var i = 0, j; i < length; i++) {
- var point1 = null, point2 = null;
- //计算当前点
- j = (i + 1) % length;
- //保存当前处理的顶点索引
- pointIndex = j;
- point1 = points[i + "," + j];
- //计算下一个点
- i = j;
- j = (i + 1) % length;
- point2 = points[i + "," + j];
- result[pointIndex] = {
- points: [ {
- x: point1.x,
- y: point1.y
- }, {
- x: point2.x,
- y: point2.y
- } ],
- center: {
- x: (point1.x + point2.x) / 2,
- y: (point1.y + point2.y) / 2
- }
- };
- //还原i值
- i = (pointIndex + length - 1) % length;
- }
- return result;
- },
- /*
- * 计算平移线移动到顶点后的位置
- * @param points 顶点集合
- * @param panLines 平移线集合
- */
- getMovedPanLines: function(points, panLines, smoothFactor) {
- var result = {};
- Utils.each(points, function(point, index) {
- //当前平移线
- var currentPanLine = panLines[index], //平移线中点
- center = currentPanLine.center, //移动距离
- distance = {
- x: center.x - point.x,
- y: center.y - point.y
- };
- var currentResult = result[index] = {
- points: [],
- center: {
- x: point.x,
- y: point.y
- }
- };
- //计算控制点到顶点的距离, 并且应用平滑系数到距离上
- Utils.each(currentPanLine.points, function(controlPoint, index) {
- var moved = {
- x: controlPoint.x - distance.x,
- y: controlPoint.y - distance.y
- };
- var vertex = currentResult.center;
- var dx = moved.x - vertex.x;
- var dy = moved.y - vertex.y;
- moved.x = vertex.x + smoothFactor * dx;
- moved.y = vertex.y + smoothFactor * dy;
- currentResult.points.push(moved);
- });
- });
- return result;
- }
- };
- return _p.r(11).createClass("Curve", {
- base: _p.r(46),
- mixins: [ _p.r(51) ],
- constructor: function(points, isColse) {
- this.callBase();
- this.setPoints(points || []);
- this.closeState = !!isColse;
- this.changeable = true;
- this.smoothFactor = 1;
- this.update();
- },
- //当点集合发生变化时采取的动作
- onContainerChanged: function() {
- if (this.changeable) {
- this.update();
- }
- },
- setSmoothFactor: function(factor) {
- this.smoothFactor = factor < 0 ? 0 : factor;
- this.update();
- return this;
- },
- getSmoothFactor: function() {
- return this.smoothFactor;
- },
- update: function() {
- var points = this.getPoints(), withControlPoints = null, drawer = this.getDrawer(), curPoint = null, curControlPoint = null, prevControlPoint = null;
- drawer.clear();
- if (points.length === 0) {
- return this;
- } else {
- drawer.moveTo(points[0]);
- }
- if (points.length === 1) {
- return this;
- }
- if (points.length === 2) {
- drawer.lineTo(points[1]);
- return this;
- }
- //获取已转换过后的带控制点的所有点
- withControlPoints = CurveUtil.getCurvePanLines(points, this.getSmoothFactor());
- for (var i = 1, len = points.length; i < len; i++) {
- //当前顶点
- curPoint = withControlPoints[i].center;
- //当前控制点
- if (this.closeState || i != len - 1) {
- curControlPoint = withControlPoints[i].points[0];
- } else {
- //非闭合状态下最后一个点的处理
- curControlPoint = withControlPoints[i].center;
- }
- if (this.closeState || i != 1) {
- prevControlPoint = withControlPoints[i - 1].points[1];
- } else {
- //非闭合状态下第一个点的处理
- prevControlPoint = withControlPoints[i - 1].center;
- }
- drawer.bezierTo(prevControlPoint.x, prevControlPoint.y, curControlPoint.x, curControlPoint.y, curPoint.x, curPoint.y);
- }
- //处理闭合
- if (this.closeState) {
- curPoint = withControlPoints[0].center;
- curControlPoint = withControlPoints[0].points[0];
- prevControlPoint = withControlPoints[points.length - 1].points[1];
- drawer.bezierTo(prevControlPoint.x, prevControlPoint.y, curControlPoint.x, curControlPoint.y, curPoint.x, curPoint.y);
- }
- return this;
- },
- close: function() {
- this.closeState = true;
- return this.update();
- },
- open: function() {
- this.closeState = false;
- return this.update();
- },
- isClose: function() {
- return !!this.closeState;
- }
- });
- }
- };
- //src/graphic/data.js
- _p[31] = {
- value: function(require, exports, module) {
- return _p.r(11).createClass("Data", {
- constructor: function() {
- this._data = {};
- },
- setData: function(name, value) {
- this._data[name] = value;
- return this;
- },
- getData: function(name) {
- return this._data[name];
- },
- removeData: function(name) {
- delete this._data[name];
- return this;
- }
- });
- }
- };
- //src/graphic/ellipse.js
- _p[32] = {
- value: function(require, exports, module) {
- var Utils = _p.r(12), Point = _p.r(50);
- return _p.r(11).createClass("Ellipse", {
- base: _p.r(46),
- constructor: function(rx, ry, cx, cy) {
- this.callBase();
- this.rx = rx || 0;
- this.ry = ry || 0;
- this.cx = cx || 0;
- this.cy = cy || 0;
- this.update();
- },
- update: function() {
- var rx = this.rx, ry = this.ry, x1 = this.cx + rx, x2 = this.cx - rx, y = this.cy;
- var drawer = this.getDrawer();
- drawer.clear();
- drawer.moveTo(x1, y);
- drawer.arcTo(rx, ry, 0, 1, 1, x2, y);
- drawer.arcTo(rx, ry, 0, 1, 1, x1, y);
- return this;
- },
- getRadius: function() {
- return {
- x: this.rx,
- y: this.ry
- };
- },
- getRadiusX: function() {
- return this.rx;
- },
- getRadiusY: function() {
- return this.ry;
- },
- getCenter: function() {
- return new Point(this.cx, this.cy);
- },
- getCenterX: function() {
- return this.cx;
- },
- getCenterY: function() {
- return this.cy;
- },
- setRadius: function(rx, ry) {
- this.rx = rx;
- this.ry = ry;
- return this.update();
- },
- setRadiusX: function(rx) {
- this.rx = rx;
- return this.update();
- },
- setRadiusY: function(ry) {
- this.ry = ry;
- return this.update();
- },
- setCenter: function(cx, cy) {
- if (arguments.length == 1) {
- var p = Point.parse(arguments[0]);
- cx = p.x;
- cy = p.y;
- }
- this.cx = cx;
- this.cy = cy;
- return this.update();
- },
- setCenterX: function(cx) {
- this.cx = cx;
- return this.update();
- },
- setCenterY: function(cy) {
- this.cy = cy;
- return this.update();
- }
- });
- }
- };
- //src/graphic/eventhandler.js
- /*
- * kity event 实现
- */
- _p[33] = {
- value: function(require, exports, module) {
- // polyfill
- (function() {
- function CustomEvent(event, params) {
- params = params || {
- bubbles: false,
- cancelable: false,
- detail: undefined
- };
- var evt = document.createEvent("CustomEvent");
- evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
- return evt;
- }
- CustomEvent.prototype = window.Event.prototype;
- window.CustomEvent = CustomEvent;
- })();
- var Utils = _p.r(12), ShapeEvent = _p.r(62);
- // 内部处理器缓存
- var INNER_HANDLER_CACHE = {}, // 用户处理器缓存
- USER_HANDLER_CACHE = {}, guid = 0;
- // 添加事件统一入口
- function _addEvent(type, handler, isOnce) {
- isOnce = !!isOnce;
- if (Utils.isString(type)) {
- type = type.match(/\S+/g);
- }
- Utils.each(type, function(currentType) {
- listen.call(this, this.node, currentType, handler, isOnce);
- }, this);
- return this;
- }
- // 移除事件统一入口
- function _removeEvent(type, handler) {
- var userHandlerList = null, eventId = this._EVNET_UID, isRemoveAll = handler === undefined;
- userHandlerList = USER_HANDLER_CACHE[eventId][type];
- //移除指定的监听器
- if (!isRemoveAll) {
- isRemoveAll = true;
- Utils.each(userHandlerList, function removeKityEvent(fn, index) {
- if (fn === handler) {
- // 不能结束, 需要查找完整个list, 避免丢失移除多次绑定同一个处理器的情况
- delete userHandlerList[index];
- } else {
- isRemoveAll = false;
- }
- });
- }
- //删除所有监听器
- if (isRemoveAll) {
- deleteDomEvent(this.node, type, INNER_HANDLER_CACHE[eventId][type]);
- delete USER_HANDLER_CACHE[eventId][type];
- delete INNER_HANDLER_CACHE[eventId][type];
- }
- return this;
- }
- // 执行绑定, 该方法context为shape或者mixin了eventhandler的对象
- function listen(node, type, handler, isOnce) {
- var eid = this._EVNET_UID, targetObject = this;
- // 初始化内部监听器
- if (!INNER_HANDLER_CACHE[eid]) {
- INNER_HANDLER_CACHE[eid] = {};
- }
- if (!INNER_HANDLER_CACHE[eid][type]) {
- // 内部监听器
- INNER_HANDLER_CACHE[eid][type] = function kityEventHandler(e) {
- e = new ShapeEvent(e || window.event);
- Utils.each(USER_HANDLER_CACHE[eid][type], function executeKityEvent(fn) {
- var result;
- if (fn) {
- result = fn.call(targetObject, e);
- //once 绑定, 执行完后删除
- if (isOnce) {
- targetObject.off(type, fn);
- }
- }
- // 如果用户handler里return了false, 则该节点上的此后的同类型事件将不再执行
- return result;
- }, targetObject);
- };
- }
- // 初始化用户监听器列表
- if (!USER_HANDLER_CACHE[eid]) {
- USER_HANDLER_CACHE[eid] = {};
- }
- if (!USER_HANDLER_CACHE[eid][type]) {
- USER_HANDLER_CACHE[eid][type] = [ handler ];
- // 绑定对应类型的事件
- // dom对象利用dom event进行处理, 非dom对象, 由消息分发机制处理
- if (!!node && "on" + type in node) {
- bindDomEvent(node, type, INNER_HANDLER_CACHE[eid][type]);
- }
- } else {
- USER_HANDLER_CACHE[eid][type].push(handler);
- }
- }
- // 绑定dom事件
- function bindDomEvent(node, type, handler) {
- if (node.addEventListener) {
- node.addEventListener(type, handler, false);
- } else {
- node.attachEvent("on" + type, handler);
- }
- }
- // 删除dom事件
- function deleteDomEvent(node, type, handler) {
- if (node.removeEventListener) {
- node.removeEventListener(type, handler, false);
- } else {
- node.detachEvent(type, handler);
- }
- }
- // 触发dom事件
- function triggerDomEvent(node, type, params) {
- var event = new CustomEvent(type, {
- bubbles: true,
- cancelable: true
- });
- event._kityParam = params;
- node.dispatchEvent(event);
- }
- // 发送消息
- function sendMessage(messageObj, type, msg) {
- var event = null, handler = null;
- var handlers = INNER_HANDLER_CACHE[messageObj._EVNET_UID];
- if (!handlers) return;
- handler = handlers[type];
- if (!handler) {
- return;
- }
- event = Utils.extend({
- type: type,
- target: messageObj
- }, msg || {});
- handler.call(messageObj, event);
- }
- // 对外接口
- return _p.r(11).createClass("EventHandler", {
- constructor: function() {
- this._EVNET_UID = ++guid;
- },
- addEventListener: function(type, handler) {
- return _addEvent.call(this, type, handler, false);
- },
- addOnceEventListener: function(type, handler) {
- return _addEvent.call(this, type, handler, true);
- },
- removeEventListener: function(type, handler) {
- return _removeEvent.call(this, type, handler);
- },
- on: function(type, handler) {
- return this.addEventListener.apply(this, arguments);
- },
- once: function(type, handler) {
- return this.addOnceEventListener.apply(this, arguments);
- },
- off: function() {
- return this.removeEventListener.apply(this, arguments);
- },
- fire: function(type, params) {
- return this.trigger.apply(this, arguments);
- },
- trigger: function(type, params) {
- sendMessage(this, type, params);
- return this;
- }
- });
- }
- };
- //src/graphic/geometry.js
- _p[34] = {
- value: function(require) {
- var utils = _p.r(12);
- var Point = _p.r(50);
- var Vector = _p.r(73);
- var Matrix = _p.r(43);
- var g = {};
- var pathCommand = /([achlmrqstvz])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\s]*,?\s*)+)/gi, pathValues = /(-?\d*\.?\d*(?:e[\-+]?\d+)?)\s*,?\s*/gi, paramCounts = {
- a: 7,
- c: 6,
- h: 1,
- l: 2,
- m: 2,
- q: 4,
- s: 4,
- t: 2,
- v: 1,
- z: 0
- };
- function pathClone(path) {
- var result, i, j, segment, segmentCopy;
- result = [];
- for (i = 0; i < path.length; i++) {
- segment = path[i];
- result.push(segmentCopy = []);
- for (j = 0; j < segment.length; j++) {
- segmentCopy.push(segment[j]);
- }
- }
- if (path.isUniform) result.isUniform = true;
- if (path.isAbsolute) result.isAbsolute = true;
- if (path.isCurve) result.isCurve = true;
- return result;
- }
- // 缓存函数
- // from raphael.js
- function cacher(f, scope, postprocessor) {
- function repush(array, item) {
- for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) {
- return array.push(array.splice(i, 1)[0]);
- }
- }
- function newf() {
- var arg = Array.prototype.slice.call(arguments, 0), args = arg.join("␀"), cache = newf.cache = newf.cache || {}, count = newf.count = newf.count || [];
- if (cache.hasOwnProperty(args)) {
- repush(count, args);
- return postprocessor ? postprocessor(cache[args]) : cache[args];
- }
- if (count.length >= 1e3) {
- delete cache[count.shift()];
- }
- count.push(args);
- cache[args] = f.apply(scope, arg);
- return postprocessor ? postprocessor(cache[args]) : cache[args];
- }
- return newf;
- }
- /**
- *
- * kity.g.pathToString(pathSegment)
- *
- * 返回表示 PathSegment 的字符串
- *
- * @param {Array} pathSegment
- * 要表示的 Path Segment
- *
- * @return {String} 表示该 Path 的字符串
- *
- * @example
- *
- * var pathSegment = [['M', 0, 0], ['L', 10, 10]]
- * var pathString = kity.g.pathToString(pathSegment);
- * // 返回 'M0,0L10,10'
- */
- g.pathToString = function(pathSegment) {
- pathSegment = pathSegment || this;
- if (typeof pathSegment == "string") return pathSegment;
- if (pathSegment instanceof Array) {
- pathSegment = utils.flatten(pathSegment);
- return pathSegment.join(",").replace(/,?([achlmqrstvxz]),?/gi, "$1");
- }
- };
- /**
- * kity.g.parsePathString(pathString)
- *
- * 解析 Path 字符串成 PathSegment
- *
- * @copyright rapheal.js
- *
- * @example
- *
- * var seg = kity.g.parsePathString('M10,12l21-23-21.5,11z');
- * // 返回: [['M', 10, 12], ['l', 21, -23], ['l', -21.5, 11], ['z']]
- *
- * @param {String} pathString Path 字符串
- * @return {Array}
- */
- g.parsePathString = cacher(function(pathString) {
- var data = [];
- pathString.replace(pathCommand, function(a, b, c) {
- var params = [], name = b.toLowerCase();
- c.replace(pathValues, function(a, b) {
- if (b) params.push(+b);
- });
- if (name == "m" && params.length > 2) {
- data.push([ b ].concat(params.splice(0, 2)));
- name = "l";
- b = b == "m" ? "l" : "L";
- }
- if (name == "r") {
- data.push([ b ].concat(params));
- } else {
- while (params.length >= paramCounts[name]) {
- data.push([ b ].concat(params.splice(0, paramCounts[name])));
- if (!paramCounts[name]) {
- break;
- }
- }
- }
- });
- data.isUniform = true;
- data.toString = g.pathToString;
- return data;
- });
- /**
- * kity.g.pathToAbsolute(path)
- *
- * 把路径转换为绝对路径的形式
- *
- * @param {Array|String} path
- * 要转换的 path 路径或者数组
- *
- * @return {Array}
- * 转换后的 Path Segment
- *
- * @example
- *
- * var path = 'M10,10l50,50';
- * var absPath = kity.g.pathToAbsolute(path);
- * // 返回 [['M', 10, 10], ['L', 60, 60]]
- */
- g.pathToAbsolute = cacher(function(path) {
- var pathArray = path.isUniform ? path : g.parsePathString(g.pathToString(path));
- var res = [], x = 0, y = 0, mx = 0, my = 0, start = 0;
- var r, pa, i, j, k, ii, jj, kk;
- if (pathArray[0][0] == "M") {
- x = +pathArray[0][1];
- y = +pathArray[0][2];
- mx = x;
- my = y;
- start++;
- res[0] = [ "M", x, y ];
- }
- for (r, pa, i = start, ii = pathArray.length; i < ii; i++) {
- res.push(r = []);
- pa = pathArray[i];
- if (pa[0] != pa[0].toUpperCase()) {
- r[0] = pa[0].toUpperCase();
- switch (r[0]) {
- case "A":
- r[1] = pa[1];
- r[2] = pa[2];
- r[3] = pa[3];
- r[4] = pa[4];
- r[5] = pa[5];
- r[6] = +(pa[6] + x);
- r[7] = +(pa[7] + y);
- break;
- case "V":
- r[1] = +pa[1] + y;
- break;
- case "H":
- r[1] = +pa[1] + x;
- break;
- case "M":
- mx = +pa[1] + x;
- my = +pa[2] + y;
- break;
- default:
- for (j = 1, jj = pa.length; j < jj; j++) {
- r[j] = +pa[j] + (j % 2 ? x : y);
- }
- }
- } else {
- for (k = 0, kk = pa.length; k < kk; k++) {
- r[k] = pa[k];
- }
- }
- switch (r[0]) {
- case "Z":
- x = mx;
- y = my;
- break;
- case "H":
- x = r[1];
- break;
- case "V":
- y = r[1];
- break;
- case "M":
- mx = r[r.length - 2];
- my = r[r.length - 1];
- break;
- default:
- x = r[r.length - 2];
- y = r[r.length - 1];
- }
- }
- res.isUniform = true;
- res.isAbsolute = true;
- res.toString = g.pathToString;
- return res;
- });
- // 把圆弧绘制的曲线转化为对应的三次贝塞尔形式
- function a2c(x1, y1, rx, ry, angle, laf, sf, x2, y2, recursive) {
- // copy from raphael.js
- // for more information of where this math came from visit:
- // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
- var math = Math, PI = math.PI, abs = Math.abs, _120 = PI * 120 / 180, rad = PI / 180 * (+angle || 0), res = [], xy, rotate = function(x, y, rad) {
- var X = x * math.cos(rad) - y * math.sin(rad), Y = x * math.sin(rad) + y * math.cos(rad);
- return {
- x: X,
- y: Y
- };
- };
- var cos, sin, h, x, y, rx2, ry2, k, cx, cy, f1, f2, df, f2old, x2old, y2old, c1, s1, c2, s2, t, hx, hy, m1, m2, m3, m4, newres, i, ii;
- if (!recursive) {
- xy = rotate(x1, y1, -rad);
- x1 = xy.x;
- y1 = xy.y;
- xy = rotate(x2, y2, -rad);
- x2 = xy.x;
- y2 = xy.y;
- cos = math.cos(PI / 180 * angle);
- sin = math.sin(PI / 180 * angle);
- x = (x1 - x2) / 2;
- y = (y1 - y2) / 2;
- h = x * x / (rx * rx) + y * y / (ry * ry);
- if (h > 1) {
- h = math.sqrt(h);
- rx = h * rx;
- ry = h * ry;
- }
- rx2 = rx * rx;
- ry2 = ry * ry;
- k = (laf == sf ? -1 : 1) * math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x)));
- cx = k * rx * y / ry + (x1 + x2) / 2;
- cy = k * -ry * x / rx + (y1 + y2) / 2;
- f1 = math.asin(((y1 - cy) / ry).toFixed(9));
- f2 = math.asin(((y2 - cy) / ry).toFixed(9));
- f1 = x1 < cx ? PI - f1 : f1;
- f2 = x2 < cx ? PI - f2 : f2;
- if (f1 < 0) f1 = PI * 2 + f1;
- if (f2 < 0) f2 = PI * 2 + f2;
- if (sf && f1 > f2) {
- f1 = f1 - PI * 2;
- }
- if (!sf && f2 > f1) {
- f2 = f2 - PI * 2;
- }
- } else {
- f1 = recursive[0];
- f2 = recursive[1];
- cx = recursive[2];
- cy = recursive[3];
- }
- df = f2 - f1;
- if (abs(df) > _120) {
- f2old = f2;
- x2old = x2;
- y2old = y2;
- f2 = f1 + _120 * (sf && f2 > f1 ? 1 : -1);
- x2 = cx + rx * math.cos(f2);
- y2 = cy + ry * math.sin(f2);
- res = a2c(x2, y2, rx, ry, angle, 0, sf, x2old, y2old, [ f2, f2old, cx, cy ]);
- }
- df = f2 - f1;
- c1 = math.cos(f1);
- s1 = math.sin(f1);
- c2 = math.cos(f2);
- s2 = math.sin(f2);
- t = math.tan(df / 4);
- hx = 4 / 3 * rx * t;
- hy = 4 / 3 * ry * t;
- m1 = [ x1, y1 ];
- m2 = [ x1 + hx * s1, y1 - hy * c1 ];
- m3 = [ x2 + hx * s2, y2 - hy * c2 ];
- m4 = [ x2, y2 ];
- m2[0] = 2 * m1[0] - m2[0];
- m2[1] = 2 * m1[1] - m2[1];
- if (recursive) {
- return [ m2, m3, m4 ].concat(res);
- } else {
- res = [ m2, m3, m4 ].concat(res).join().split(",");
- newres = [];
- for (i = 0, ii = res.length; i < ii; i++) {
- newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x;
- }
- return newres;
- }
- }
- // 把二次贝塞尔曲线参数转化为三次贝塞尔曲线参数
- function q2c(x1, y1, ax, ay, x2, y2) {
- // copy from raphael.js
- var _13 = 1 / 3, _23 = 2 / 3;
- return [ _13 * x1 + _23 * ax, _13 * y1 + _23 * ay, _13 * x2 + _23 * ax, _13 * y2 + _23 * ay, x2, y2 ];
- }
- /**
- * kity.g.pathToCurve(path)
- *
- * 把路径转换为贝塞尔路径
- *
- * @param {Array|String} path
- * 要转换的 path 路径或数组
- *
- * @return {Array}
- * 转换后的 PathSegment,每一段都是 'C'
- */
- g.pathToCurve = cacher(function(path) {
- var i, j, command, param;
- var initPoint, currentPoint, endPoint, shouldClose, lastControlPoint, aussumedControlPoint;
- var controlPoint1, controlPoint2;
- var res = [];
- // 处理的路径要求是一个绝对路径
- if (!path.isAbsolute) path = g.pathToAbsolute(path);
- for (i = 0; i < path.length; i++) {
- command = path[i][0];
- param = path[i].slice(1);
- // 画笔移动
- if (command == "M") {
- initPoint = lastControlPoint = currentPoint = param;
- res.push(path[i]);
- continue;
- }
- // 路径闭合
- if (command == "Z") {
- shouldClose = true;
- command = "L";
- param = initPoint;
- }
- // 绘制命令的目的位置
- endPoint = param.slice(param.length - 2);
- // 对 'H' 命令的修正
- if (command == "H") {
- endPoint = [ param[0], currentPoint[1] ];
- command = "L";
- }
- // 对 'V' 命令的修正
- if (command == "V") {
- endPoint = [ currentPoint[0], param[0] ];
- command = "L";
- }
- // 对 'S' 命令求出隐含的控制点位置
- if (command == "S" || command == "T") {
- // 隐含控制点是上一个控制点关于当前位置的镜像
- aussumedControlPoint = [ currentPoint[0] + (currentPoint[0] - lastControlPoint[0]), currentPoint[1] + (currentPoint[1] - lastControlPoint[1]) ];
- }
- // 针对不同的命令求控制点
- switch (command) {
- case "L":
- controlPoint1 = currentPoint;
- controlPoint2 = endPoint;
- break;
- case "C":
- controlPoint1 = param.slice(0, 2);
- controlPoint2 = param.slice(2, 4);
- break;
- case "S":
- controlPoint1 = aussumedControlPoint.slice();
- controlPoint2 = param.slice(0, 2);
- break;
- case "Q":
- lastControlPoint = param.slice(0, 2);
- param = q2c.apply(null, currentPoint.concat(param));
- controlPoint1 = param.slice(0, 2);
- controlPoint2 = param.slice(2, 4);
- break;
- case "T":
- param = q2c.apply(null, currentPoint.concat(aussumedControlPoint).concat(param));
- controlPoint1 = param.slice(0, 2);
- controlPoint2 = param.slice(2, 4);
- break;
- case "A":
- param = a2c.apply(null, currentPoint.concat(param));
- j = 0;
- while (j in param) {
- controlPoint1 = param.slice(j, j + 2);
- controlPoint2 = param.slice(j + 2, j + 4);
- endPoint = param.slice(j + 4, j + 6);
- // 写入当前一段曲线
- res.push([ "C" ].concat(controlPoint1).concat(controlPoint2).concat(endPoint));
- j += 6;
- }
- break;
- }
- if (command != "A") {
- // 写入当前一段曲线
- res.push([ "C" ].concat(controlPoint1).concat(controlPoint2).concat(endPoint));
- }
- // 为下次循环准备当前位置
- currentPoint = endPoint;
- // 二次贝塞尔曲线自己已经记录了上个控制点的位置,其它的记录控制点 2 的位置
- if (command != "Q") {
- lastControlPoint = controlPoint2;
- }
- if (shouldClose) {
- res.push([ "Z" ]);
- shouldClose = false;
- }
- }
- res.isUniform = true;
- res.isAbsolute = true;
- res.isCurve = true;
- res.toString = g.pathToString;
- return res;
- });
- /**
- * 将贝塞尔曲线切成两部分
- *
- * @see http://stackoverflow.com/questions/18655135/divide-bezier-curve-into-two-equal-halves
- */
- function cutBezier(bezierArray, t) {
- function __(t) {
- return function(p, q) {
- return p + t * (q - p);
- };
- }
- var _ = __(t || .5), ba = bezierArray, ax = ba[0], ay = ba[1], bx = ba[2], by = ba[3], cx = ba[4], cy = ba[5], dx = ba[6], dy = ba[7], ex = _(ax, bx), ey = _(ay, by), fx = _(bx, cx), fy = _(by, cy), gx = _(cx, dx), gy = _(cy, dy), hx = _(ex, fx), hy = _(ey, fy), jx = _(fx, gx), jy = _(fy, gy), kx = _(hx, jx), ky = _(hy, jy);
- return [ [ ax, ay, ex, ey, hx, hy, kx, ky ], [ kx, ky, jx, jy, gx, gy, dx, dy ] ];
- }
- /**
- * kity.g.cutBezier(bezierArray, t)
- *
- * 在指定位置把贝塞尔曲线切割为两部分
- *
- * @param {Array} bezierArray
- * 表示贝塞尔曲线的一个数组 [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y]
- * p1 和 p2 是贝塞尔曲线的起点和终点,c1 和 c2 是两个控制点
- *
- * @param {Number} t
- * 切割的位置(0 到 1)
- *
- * @return {Array}
- * 切割的两个贝塞尔曲线:[
- * [p1x1, p1y1, c1x1, c1y1, c2x1, c2y1, p2x1, p2y1],
- * [p1x2, p1y2, c1x2, c1y2, c2x2, c2y2, p2x2, p2y2]
- * ]
- *
- */
- g.cutBezier = cacher(cutBezier);
- /**
- * 求一段贝塞尔曲线的子段
- *
- * @param {Array} bezierArray
- * 长度为 8 的数组,表示 [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y]
- *
- * @param {Number} t
- * 子段的结束位置(0 到 1)
- *
- * @param {Number} t0
- * 字段的开始位置(0 到 t),可不传,默认为 0
- *
- * @return {Array}
- * 长度为 8 的数组,表示给定贝塞尔曲线的子段
- */
- g.subBezier = function(bezierArray, t, t0) {
- var b2t = cutBezier(bezierArray, t)[0];
- return t0 ? cutBezier(b2t, t0 / t)[1] : b2t;
- };
- /**
- * 求贝塞尔曲线上的一个点
- *
- * @param {Array} bezierArray
- * 长度为 8 的数组,表示 [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y]
- *
- * @param {Number} t
- * 所求点的开始位置(0 到 1)
- *
- * @return {Point} p
- * p.x: x 坐标
- * p.y: y 坐标
- * p.tan: 在 t 处的切线方向(类型为 kity.Vector,模为 1)
- */
- g.pointAtBezier = function(bezierArray, t) {
- var b2t = cutBezier(bezierArray, t)[0];
- var p = Point.parse(b2t.slice(6)), c = Point.parse(b2t.slice(4, 2)), v = Vector.fromPoints(c, p);
- if (t === 0) {
- p.tan = g.pointAtBezier(bezierArray, .01).tan;
- } else {
- p.tan = v.normalize();
- }
- return p;
- };
- /**
- * 求贝塞尔曲线的长度
- *
- * @param {Array} bezierArray
- * 长度为 8 的数组,表示 [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y]
- *
- * @param {Number} tolerate
- * 允许的误差,默认是 0.1
- *
- * @return {Number} 贝塞尔曲线的长度
- */
- g.bezierLength = cacher(function bezierLength(bezierArray) {
- // 表示(c[0]*t^4 + c[1]*t^3 + c[2]*t^2 + c[3]*t^1 + c[4])^(1/2)的函数
- function f(x) {
- var m = c0 * Math.pow(x, 4) + c1 * Math.pow(x, 3) + c2 * Math.pow(x, 2) + c3 * x + c4;
- if (m < 0) {
- m = 0;
- }
- return Math.pow(m, .5);
- }
- // 用Newton-Cotes型求积公式
- var arr = bezierArray;
- // 三次贝塞尔曲线函数求导后,求出对应的方程系数,用cx[],cy[]表示x`(t)和y`(t)的系数
- var cx0, cx1, cx2;
- var cy0, cy1, cy2;
- // 用c[]表示x`(t)^2 + y`(t)^2的结果的系数
- var c0, c1, c2, c3, c4;
- // 求x`(t) 和 y`(t)的系数
- cx0 = -3 * arr[0] + 9 * arr[2] - 9 * arr[4] + 3 * arr[6];
- cx1 = 6 * arr[0] - 12 * arr[2] + 6 * arr[4];
- cx2 = -3 * arr[0] + 3 * arr[2];
- cy0 = -3 * arr[1] + 9 * arr[3] - 9 * arr[5] + 3 * arr[7];
- cy1 = 6 * arr[1] - 12 * arr[3] + 6 * arr[5];
- cy2 = -3 * arr[1] + 3 * arr[3];
- // 求x`(t)^2 + y`(t)^2的结果的系数 c[]
- c0 = Math.pow(cx0, 2) + Math.pow(cy0, 2);
- c1 = 2 * (cx0 * cx1 + cy0 * cy1);
- c2 = 2 * (cx0 * cx2 + cy0 * cy2) + Math.pow(cx1, 2) + Math.pow(cy1, 2);
- c3 = 2 * (cx1 * cx2 + cy1 * cy2);
- c4 = Math.pow(cx2, 2) + Math.pow(cy2, 2);
- // 用cotes积分公式求值
- return (f(0) + f(1) + 4 * (f(.125) + f(.375) + f(.625) + f(.875)) + 2 * (f(.25) + f(.5) + f(.75))) / 24;
- });
- // 计算一个 pathSegment 中每一段的在整体中所占的长度范围,以及总长度
- // 方法要求每一段都是贝塞尔曲线
- var getBezierPathSegmentRanges = cacher(function(pathSegment) {
- var i, ii, segment, position, bezierLength, segmentRanges, totalLength;
- segmentRanges = [];
- // 总长度
- totalLength = 0;
- for (i = 0, ii = pathSegment.length; i < ii; i++) {
- segment = pathSegment[i];
- if (segment[0] == "M") {
- position = segment.slice(1);
- segmentRanges.push(null);
- continue;
- }
- if (segment[0] == "Z") {
- segmentRanges.push(null);
- continue;
- }
- bezierLength = g.bezierLength(position.concat(segment.slice(1)));
- segmentRanges.push([ totalLength, totalLength + bezierLength ]);
- totalLength += bezierLength;
- // 迭代当前位置
- position = segment.slice(4);
- }
- segmentRanges.totalLength = totalLength;
- return segmentRanges;
- });
- /**
- * 求一段路径的子路径
- *
- * @param {Array|String} path
- * 原路径
- *
- * @param {Number} t1
- * 要求的子路径的结束位置(0 到 1)
- *
- * @param {Number} t0
- * 要求的子路径的开始位置(0 到 t1),可不传,默认为 0
- *
- * @return {Array}
- * 子路径的 PathSegment
- */
- g.subPath = function(path, t1, t0) {
- var dt;
- t0 = t0 || 0;
- dt = t1 - t0;
- dt = dt - (dt | 0);
- t0 = t0 - (t0 | 0);
- t1 = t0 + dt;
- if (t1 > 1) {
- return g.subPath(path, 1, t0).concat(g.subPath(path, t1 - 1));
- }
- if (!path.isCurve) {
- path = g.pathToCurve(path);
- }
- // path 每一段在整体中的长度区间
- var segmentRanges = getBezierPathSegmentRanges(path);
- // path 总长度
- var totalLength = segmentRanges.totalLength;
- // t1 和 t0 位置命中的长度位置
- var t1Length = totalLength * t1, t0Length = totalLength * (t0 || 0);
- // 产生的子路径
- var subPath = [];
- // 迭代变量,a 是一段的长度区间左值,b 是右值,d 是区间长度
- var i, ii, a, b, d;
- var position;
- var bezier, subBezier, stared;
- for (i = 0, ii = path.length; i < ii; i++) {
- if (path[i][0] == "M") {
- position = path[i].slice(1);
- if (stared) {
- subPath.push(path[i].slice());
- }
- continue;
- }
- if (path[i][0] == "Z") {
- // subpath 路径不闭合
- continue;
- }
- a = segmentRanges[i][0];
- b = segmentRanges[i][1];
- d = b - a;
- bezier = position.concat(path[i].slice(1));
- if (t0Length > b) {
- // t0 和 t1 都右溢出
- // -----------------------------------
- // t0 t1
- // |________|
- //
- // 需要跳过当前块
- position = bezier.slice(bezier.length - 2);
- continue;
- } else if (t0Length >= a) {
- // 命中 t0;t1 可能命中或右溢出
- // -----------------------------------
- // t0 t1
- // |______|__|
- //
- // or: |_|____|__|
- //
- // 取当前块 t0 到 t1 的部分
- subBezier = g.subBezier(bezier, Math.min((t1Length - a) / d, 1), (t0Length - a) / d);
- stared = true;
- position = subBezier.slice(0, 2);
- subPath.push([ "M" ].concat(subBezier.slice(0, 2)));
- subPath.push([ "C" ].concat(subBezier.slice(2)));
- } else if (t1Length >= b) {
- // t0 左溢出;t1 右溢出,整个块是需要的
- // -----------------------------------
- // t0 t1
- // |_________|
- //
- // 此时取整个块
- subPath.push(path[i].slice());
- } else if (t1Length >= a) {
- // t0 左溢出;t1 命中,取当前块 t1 之前的部分
- // -----------------------------------
- // t0 t1
- // |__|______|
- // 取当前块 t1 之前的部分
- subBezier = g.subBezier(bezier, (t1Length - a) / d);
- subPath.push([ "C" ].concat(subBezier.slice(2)));
- stared = false;
- } else {
- // 没有可以再要的了
- break;
- }
- position = bezier.slice(bezier.length - 2);
- }
- subPath.isAbsolute = true;
- subPath.isCurve = true;
- subPath.isUniform = true;
- subPath.toString = g.pathToString;
- return subPath;
- };
- /**
- * 求路径上的一个点
- *
- * @param {Array|String} path
- * 要求点的路径
- *
- * @param {Number} t
- * 要求的点的位置(0 到 1)
- *
- * @return {Point} p
- * p.x: x 坐标
- * p.y: y 坐标
- * p.tan: 在 t 处的切线方向(类型为 kity.Vector,模为 1)
- */
- g.pointAtPath = function(path, t) {
- if (!path.isCurve) {
- path = g.pathToCurve(path);
- }
- var subPath = g.subPath(path, t);
- var lastCurve = subPath[subPath.length - 1][0] == "Z" ? subPath[subPath.length - 2] : subPath[subPath.length - 1];
- // 跳过 'C' 命令,只留参数
- lastCurve = lastCurve.slice(1);
- var p = Point.parse(lastCurve.slice(4)), c = Point.parse(lastCurve.slice(2, 4));
- p.tan = Vector.fromPoints(c, p).normalize();
- return p;
- };
- /**
- * 求一段路径的长度
- *
- * @param {string|Array} path
- * 要求的路径
- *
- * @return {Number}
- * 路径的长度
- */
- g.pathLength = cacher(function(path) {
- if (!path.isCurve) {
- path = g.pathToCurve(path);
- }
- // path 每一段在整体中的长度区间
- var segmentRanges = getBezierPathSegmentRanges(path);
- return segmentRanges.totalLength;
- });
- /**
- * 求一段路径的关键点
- *
- * @param {string|Array} path
- * 要求的路径
- *
- * @return {Array}
- * 关键点的集合
- */
- g.pathKeyPoints = cacher(function(path) {
- var i, ii, command, keyPoints;
- if (!path.isCurve) {
- path = g.pathToCurve(path);
- }
- keyPoints = [];
- for (i = 0, ii = path.length; i < ii; i++) {
- if (path[i][0] == "z") continue;
- keyPoints.push(path[i].slice(path[i].length - 2));
- }
- return keyPoints;
- });
- // 对比两个路径的关键位置,在合适的位置切割合适的路径,使得两个路径的段数一致
- // TODO: 使用插值算法,使对应点更合理
- var alignCurve = cacher(function(path1, path2) {
- if (!path1.isCurve) path1 = g.pathToCurve(path1);
- if (!path2.isCurve) path2 = g.pathToCurve(path2);
- var p1 = pathClone(path1);
- var p2 = pathClone(path2);
- p1.i = 0;
- p2.i = 0;
- p1.o = p2;
- p2.o = p1;
- function command(p, i) {
- return p[i || p.i] && p[i || p.i][0];
- }
- function param(p, i) {
- return p[i || p.i] && p[i || p.i].slice(1);
- }
- function point(p, i) {
- var _param = param(p, i);
- return _param && _param.slice(-2);
- }
- function fixZ(p) {
- if (command(p) == "Z") {
- p.splice(p.i, 1);
- return true;
- }
- return false;
- }
- function fixM(p) {
- if (command(p) == "M") {
- p.o.splice(p.o.i, 0, [ "M" ].concat(point(p.o, p.o.i - 1)));
- p.i++;
- p.o.i++;
- return true;
- }
- return false;
- }
- function fill(p) {
- var lastPoint;
- var i = 1;
- while (!lastPoint) {
- lastPoint = point(p, p.length - i++);
- }
- p.o.i = p.i;
- while (p.length < p.o.length) {
- if (fixZ(p.o)) continue;
- if (fixM(p.o)) continue;
- p.push([ "C" ].concat(lastPoint).concat(lastPoint).concat(lastPoint));
- p.i++;
- p.o.i++;
- }
- }
- while (p1.i < p1.length && p2.i < p2.length) {
- if (fixZ(p1) || fixZ(p2)) continue;
- if (command(p1) == command(p2)) {
- p1.i++;
- p2.i++;
- continue;
- }
- if (fixM(p1) || fixM(p2)) continue;
- p1.i++;
- p2.i++;
- }
- if (p1.i == p1.length) fill(p1);
- if (p2.i == p2.length) fill(p2);
- delete p1.i;
- delete p1.o;
- delete p2.i;
- delete p2.o;
- return [ p1, p2 ];
- });
- g.alignCurve = alignCurve;
- /**
- * 获得两个路径的补间结果
- *
- * @param {string|Array} path1
- * 补间起始路径
- *
- * @param {string|Array} path2
- * 补间结束路径
- *
- * @param {Number} t
- * 补间比例,0 返回跟 path1 等效的结果;1 返回跟 path2 等效的结果
- *
- * @return {PathSegment}
- * 补间的结果
- */
- g.pathTween = function(path1, path2, t) {
- if (t === 0) return path1;
- if (t === 1) return path2;
- var aligned = alignCurve(path1, path2);
- var result = [], seg, i, j;
- path1 = aligned[0];
- path2 = aligned[1];
- for (i = 0; i < path1.length; i++) {
- result.push(seg = []);
- seg.push(path1[i][0]);
- for (j = 1; j < path1[i].length; j++) {
- seg.push(path1[i][j] + t * (path2[i][j] - path1[i][j]));
- }
- }
- result.isUniform = result.isCurve = result.isAbsolute = true;
- return result;
- };
- /**
- * 变换指定的路径
- *
- * @param {String|Array} path
- * 需要变换的路径
- *
- * @param {kity.Matrix} matrix
- * 使用的变换矩阵
- *
- * @return {Array}
- * 变换后的路径
- */
- g.transformPath = cacher(function(path, matrix) {
- var i, ii, j, result, seg, pair;
- if (!path.isCurve) {
- path = g.pathToCurve(path);
- }
- result = [];
- for (i = 0, ii = path.length; i < ii; i++) {
- result.push(seg = [ path[i][0] ]);
- for (j = 1; j < path[i].length; j += 2) {
- pair = path[i].slice(j, j + 2);
- pair = matrix.transformPoint(Point.parse(pair));
- result.push(pair);
- }
- }
- return result;
- });
- // entend
- _p.r(11).extendClass(Matrix, {
- transformPath: function(path) {
- return g.transformPath(path, this);
- }
- });
- return g;
- }
- };
- //src/graphic/gradient.js
- _p[35] = {
- value: function(require, exports, module) {
- var svg = _p.r(67);
- var Resource = _p.r(58);
- var Color = _p.r(28);
- return _p.r(11).createClass("GradientBrush", {
- base: Resource,
- constructor: function(gradientNodeType, paper) {
- this.callBase(gradientNodeType, paper);
- this.stops = [];
- },
- addStop: function(offset, color, opacity) {
- var gstop = svg.createNode("stop");
- if (!(color instanceof Color)) {
- color = Color.parse(color);
- }
- if (opacity === undefined) {
- opacity = color.get("a");
- }
- gstop.setAttribute("offset", offset);
- gstop.setAttribute("stop-color", color.toRGB());
- if (opacity < 1) {
- gstop.setAttribute("stop-opacity", opacity);
- }
- this.node.appendChild(gstop);
- return this;
- }
- });
- }
- };
- //src/graphic/group.js
- _p[36] = {
- value: function(require, exports, module) {
- var ShapeContainer = _p.r(61);
- return _p.r(11).createClass("Group", {
- mixins: [ ShapeContainer ],
- base: _p.r(60),
- constructor: function Group() {
- this.callBase("g");
- }
- });
- }
- };
- //src/graphic/hyperlink.js
- _p[37] = {
- value: function(require, exports, module) {
- var ShapeContainer = _p.r(61);
- return _p.r(11).createClass("HyperLink", {
- mixins: [ ShapeContainer ],
- base: _p.r(60),
- constructor: function(url) {
- this.callBase("a");
- this.setHref(url);
- },
- setHref: function(href) {
- this.node.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", href);
- return this;
- },
- getHref: function() {
- return this.node.getAttributeNS("xlink:href");
- },
- setTarget: function(target) {
- this.node.setAttribute("target", target);
- return this;
- },
- getTarget: function() {
- return this.node.getAttribute("target");
- }
- });
- }
- };
- //src/graphic/image.js
- _p[38] = {
- value: function(require, exports, module) {
- return _p.r(11).createClass("Image", {
- base: _p.r(60),
- constructor: function(url, width, height, x, y) {
- this.callBase("image");
- this.url = url;
- this.width = width || 0;
- this.height = height || 0;
- this.x = x || 0;
- this.y = y || 0;
- this.update();
- },
- update: function() {
- this.node.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", this.url);
- this.node.setAttribute("x", this.x);
- this.node.setAttribute("y", this.y);
- this.node.setAttribute("width", this.width);
- this.node.setAttribute("height", this.height);
- return this;
- },
- setUrl: function(url) {
- this.url = url === "" ? null : url;
- return this.update();
- },
- getUrl: function() {
- return this.url;
- },
- setWidth: function(width) {
- this.width = width;
- return this.update();
- },
- getWidth: function() {
- return this.width;
- },
- setHeight: function(height) {
- this.height = height;
- return this.update();
- },
- getHeight: function() {
- return this.height;
- },
- setX: function(x) {
- this.x = x;
- return this.update();
- },
- getX: function() {
- return this.x;
- },
- setY: function(y) {
- this.y = y;
- return this.update();
- },
- getY: function() {
- return this.y;
- }
- });
- }
- };
- //src/graphic/line.js
- _p[39] = {
- value: function(require, exports, module) {
- return _p.r(11).createClass("Line", {
- base: _p.r(46),
- constructor: function(x1, y1, x2, y2) {
- this.callBase();
- this.point1 = {
- x: x1 || 0,
- y: y1 || 0
- };
- this.point2 = {
- x: x2 || 0,
- y: y2 || 0
- };
- this.update();
- },
- setPoint1: function(x, y) {
- this.point1.x = x;
- this.point1.y = y;
- return this.update();
- },
- setPoint2: function(x, y) {
- this.point2.x = x;
- this.point2.y = y;
- return this.update();
- },
- getPoint1: function() {
- return {
- x: this.point1.x,
- y: this.point1.y
- };
- },
- getPoint2: function() {
- return {
- x: this.point2.x,
- y: this.point2.y
- };
- },
- update: function() {
- var drawer = this.getDrawer();
- drawer.clear();
- drawer.moveTo(this.point1.x, this.point1.y);
- drawer.lineTo(this.point2.x, this.point2.y);
- return this;
- }
- });
- }
- };
- //src/graphic/lineargradient.js
- _p[40] = {
- value: function(require, exports, module) {
- var svg = _p.r(67);
- var Gradient = _p.r(35);
- return _p.r(11).createClass("LinearGradientBrush", {
- base: Gradient,
- constructor: function(paper) {
- this.callBase("linearGradient", paper);
- this.setStartPosition(0, 0);
- this.setEndPosition(1, 0);
- },
- setStartPosition: function(px, py) {
- this.node.setAttribute("x1", px);
- this.node.setAttribute("y1", py);
- return this;
- },
- setEndPosition: function(px, py) {
- this.node.setAttribute("x2", px);
- this.node.setAttribute("y2", py);
- return this;
- },
- getStartPosition: function() {
- return {
- x: +this.node.getAttribute("x1"),
- y: +this.node.getAttribute("y1")
- };
- },
- getEndPosition: function() {
- return {
- x: +this.node.getAttribute("x2"),
- y: +this.node.getAttribute("y2")
- };
- }
- });
- }
- };
- //src/graphic/marker.js
- _p[41] = {
- value: function(require, exports, module) {
- var Point = _p.r(50);
- var Marker = _p.r(11).createClass("Marker", {
- base: _p.r(58),
- mixins: [ _p.r(61), _p.r(75) ],
- constructor: function() {
- this.callBase("marker");
- this.setOrient("auto");
- },
- setRef: function(x, y) {
- if (arguments.length === 1) {
- y = x.y;
- x = x.x;
- }
- this.node.setAttribute("refX", x);
- this.node.setAttribute("refY", y);
- return this;
- },
- getRef: function() {
- return new Point(+this.node.getAttribute("refX"), +this.node.getAttribute("refY"));
- },
- setWidth: function(width) {
- this.node.setAttribute("markerWidth", this.width = width);
- return this;
- },
- setOrient: function(orient) {
- this.node.setAttribute("orient", this.orient = orient);
- return this;
- },
- getOrient: function() {
- return this.orient;
- },
- getWidth: function() {
- return +this.width;
- },
- setHeight: function(height) {
- this.node.setAttribute("markerHeight", this.height = height);
- return this;
- },
- getHeight: function() {
- return +this.height;
- }
- });
- var Path = _p.r(46);
- _p.r(11).extendClass(Path, {
- setMarker: function(marker, pos) {
- pos = pos || "end";
- if (!marker) {
- this.node.removeAttribute("marker-" + pos);
- } else {
- this.node.setAttribute("marker-" + pos, marker.toString());
- }
- return this;
- }
- });
- return Marker;
- }
- };
- //src/graphic/mask.js
- /**
- * 蒙板
- */
- _p[42] = {
- value: function(require, exports, module) {
- var Class = _p.r(11);
- var Shape = _p.r(60);
- var Mask = Class.createClass("Mask", {
- base: Shape,
- mixins: [ _p.r(61) ],
- constructor: function() {
- this.callBase("mask");
- },
- mask: function(shape) {
- shape.getNode().setAttribute("mask", "url(#" + this.getId() + ")");
- return this;
- }
- });
- Class.extendClass(Shape, {
- maskWith: function(mask) {
- mask.mask(this);
- return this;
- }
- });
- return Mask;
- }
- };
- //src/graphic/matrix.js
- _p[43] = {
- value: function(require, exports, module) {
- var utils = _p.r(12);
- var Box = _p.r(25);
- var mPattern = /matrix\s*\((.+)\)/i;
- var Point = _p.r(50);
- // 注意,合并的结果是先执行m2,再执行m1的结果
- function mergeMatrixData(m2, m1) {
- return {
- a: m1.a * m2.a + m1.c * m2.b,
- b: m1.b * m2.a + m1.d * m2.b,
- c: m1.a * m2.c + m1.c * m2.d,
- d: m1.b * m2.c + m1.d * m2.d,
- e: m1.a * m2.e + m1.c * m2.f + m1.e,
- f: m1.b * m2.e + m1.d * m2.f + m1.f
- };
- }
- function d2r(deg) {
- return deg * Math.PI / 180;
- }
- var Matrix = _p.r(11).createClass("Matrix", {
- constructor: function() {
- if (arguments.length) {
- this.setMatrix.apply(this, arguments);
- } else {
- this.setMatrix(1, 0, 0, 1, 0, 0);
- }
- },
- translate: function(x, y) {
- this.m = mergeMatrixData(this.m, {
- a: 1,
- c: 0,
- e: x,
- b: 0,
- d: 1,
- f: y
- });
- return this;
- },
- rotate: function(deg) {
- var rad = d2r(deg);
- var sin = Math.sin(rad), cos = Math.cos(rad);
- this.m = mergeMatrixData(this.m, {
- a: cos,
- c: -sin,
- e: 0,
- b: sin,
- d: cos,
- f: 0
- });
- return this;
- },
- scale: function(sx, sy) {
- if (sy === undefined) {
- sy = sx;
- }
- this.m = mergeMatrixData(this.m, {
- a: sx,
- c: 0,
- e: 0,
- b: 0,
- d: sy,
- f: 0
- });
- return this;
- },
- skew: function(degX, degY) {
- if (degY === undefined) {
- degY = degX;
- }
- var tx = Math.tan(d2r(degX)), ty = Math.tan(d2r(degY));
- this.m = mergeMatrixData(this.m, {
- a: 1,
- c: tx,
- e: 0,
- b: ty,
- d: 1,
- f: 0
- });
- return this;
- },
- /**
- * 获得反转矩阵
- *
- * 这是我解方程算出来的
- */
- inverse: function() {
- var m = this.m, a = m.a, b = m.b, c = m.c, d = m.d, e = m.e, f = m.f, k, aa, bb, cc, dd, ee, ff;
- k = a * d - b * c;
- aa = d / k;
- bb = -b / k;
- cc = -c / k;
- dd = a / k;
- ee = (c * f - e * d) / k;
- ff = (b * e - a * f) / k;
- return new Matrix(aa, bb, cc, dd, ee, ff);
- },
- setMatrix: function(a, b, c, d, e, f) {
- if (arguments.length === 1) {
- this.m = utils.clone(arguments[0]);
- } else {
- this.m = {
- a: a,
- b: b,
- c: c,
- d: d,
- e: e,
- f: f
- };
- }
- return this;
- },
- getMatrix: function() {
- return utils.clone(this.m);
- },
- getTranslate: function() {
- var m = this.m;
- return {
- x: m.e / m.a,
- y: m.f / m.d
- };
- },
- mergeMatrix: function(matrix) {
- return new Matrix(mergeMatrixData(this.m, matrix.m));
- },
- merge: function(matrix) {
- return this.mergeMatrix(matrix);
- },
- toString: function() {
- return this.valueOf().join(" ");
- },
- valueOf: function() {
- var m = this.m;
- return [ m.a, m.b, m.c, m.d, m.e, m.f ];
- },
- equals: function(matrix) {
- var m1 = this.m, m2 = matrix.m;
- return m1.a == m2.a && m1.b == m2.b && m1.c == m2.c && m1.d == m2.d && m1.e == m2.e && m1.f == m2.f;
- },
- transformPoint: function() {
- return Matrix.transformPoint.apply(null, [].slice.call(arguments).concat([ this.m ]));
- },
- transformBox: function(box) {
- return Matrix.transformBox(box, this.m);
- },
- clone: function() {
- return new Matrix(this.m);
- }
- });
- Matrix.parse = function(str) {
- var match;
- var f = parseFloat;
- if (str instanceof Array) {
- return new Matrix({
- a: str[0],
- b: str[1],
- c: str[2],
- d: str[3],
- e: str[4],
- f: str[5]
- });
- }
- if (match = mPattern.exec(str)) {
- var values = match[1].split(",");
- if (values.length != 6) {
- values = match[1].split(" ");
- }
- return new Matrix({
- a: f(values[0]),
- b: f(values[1]),
- c: f(values[2]),
- d: f(values[3]),
- e: f(values[4]),
- f: f(values[5])
- });
- }
- return new Matrix();
- };
- Matrix.transformPoint = function(x, y, m) {
- if (arguments.length === 2) {
- m = y;
- y = x.y;
- x = x.x;
- }
- return new Point(m.a * x + m.c * y + m.e, m.b * x + m.d * y + m.f);
- };
- Matrix.transformBox = function(box, matrix) {
- var xMin = Number.MAX_VALUE, xMax = -Number.MAX_VALUE, yMin = Number.MAX_VALUE, yMax = -Number.MAX_VALUE;
- var bps = [ [ box.x, box.y ], [ box.x + box.width, box.y ], [ box.x, box.y + box.height ], [ box.x + box.width, box.y + box.height ] ];
- var bp, rp, rps = [];
- while (bp = bps.pop()) {
- rp = Matrix.transformPoint(bp[0], bp[1], matrix);
- rps.push(rp);
- xMin = Math.min(xMin, rp.x);
- xMax = Math.max(xMax, rp.x);
- yMin = Math.min(yMin, rp.y);
- yMax = Math.max(yMax, rp.y);
- }
- box = new Box({
- x: xMin,
- y: yMin,
- width: xMax - xMin,
- height: yMax - yMin
- });
- utils.extend(box, {
- closurePoints: rps
- });
- return box;
- };
- // 获得从 node 到 refer 的变换矩阵
- Matrix.getCTM = function(target, refer) {
- var ctm = {
- a: 1,
- b: 0,
- c: 0,
- d: 1,
- e: 0,
- f: 0
- };
- var node = target.shapeNode || target.node;
- refer = refer || "parent";
- // 根据参照坐标系选区的不一样,返回不同的结果
- switch (refer) {
- case "screen":
- // 以浏览器屏幕为参照坐标系
- ctm = node.getScreenCTM();
- break;
- case "doc":
- case "paper":
- // 以文档(Paper)为参照坐标系
- ctm = node.getCTM();
- break;
- case "view":
- case "top":
- // 以顶层绘图容器(视野)为参照坐标系
- if (target.getPaper()) {
- ctm = node.getTransformToElement(target.getPaper().shapeNode);
- }
- break;
- case "parent":
- // 以父容器为参照坐标系
- if (target.node.parentNode) {
- ctm = node.getTransformToElement(target.node.parentNode);
- }
- break;
- default:
- // 其他情况,指定参照物
- if (refer.node) {
- ctm = node.getTransformToElement(refer.shapeNode || refer.node);
- }
- }
- return ctm ? new Matrix(ctm.a, ctm.b, ctm.c, ctm.d, ctm.e, ctm.f) : new Matrix();
- };
- return Matrix;
- }
- };
- //src/graphic/palette.js
- /**
- * 调色板
- */
- _p[44] = {
- value: function(require, exports, module) {
- //标准color
- var StandardColor = _p.r(64), Color = _p.r(28), Utils = _p.r(12);
- var Palette = _p.r(11).createClass("Palette", {
- constructor: function() {
- this.color = {};
- },
- /*
- * 获取颜色名称所对应的颜色值的Color对象
- * @param name 需要获取的颜色名称
- * @return 对应颜色名称的color对象, 如果未找到对应的名称, 则返回null
- */
- get: function(name) {
- var colorValue = this.color[name] || StandardColor.EXTEND_STANDARD[name] || StandardColor.COLOR_STANDARD[name] || "";
- if (colorValue) {
- return new Color(colorValue);
- }
- return null;
- },
- /*
- * 获取给定名称的颜色的hex值表示
- * @param name 需要获取的颜色名称
- * @return 如果找到对应的名称, 则返回该名称所对应的hex格式的值, 否则, 返回一个空字符串
- */
- getColorValue: function(name) {
- return this.color[name] || StandardColor.EXTEND_STANDARD[name] || StandardColor.COLOR_STANDARD[name] || "";
- },
- /*
- * 向调色板实例添加自己独有的颜色名称,对已存在的颜色名称, 将会覆盖掉
- * @param name 新添加的颜色名称
- * @param value 新添加的颜色名称所对应的值, 可以是一个合法的颜色字符串或者是一个color对象
- * @return 新添加的颜色的值
- */
- add: function(name, value) {
- if (typeof value === "string") {
- this.color[name] = new Color(value).toRGBA();
- } else {
- this.color[name] = value.toRGBA();
- }
- return value;
- },
- /*
- * 删除调色板实例上用户自己添加的颜色, 该方法不能删除内置的颜色
- * @param name 需要删除的颜色名称
- * @return 删除是否成功的bool值
- */
- remove: function(name) {
- if (this.color.hasOwnProperty(name)) {
- delete this.color[name];
- return true;
- }
- return false;
- }
- });
- Utils.extend(Palette, {
- getColor: function(name) {
- var colorValue = StandardColor.EXTEND_STANDARD[name] || StandardColor.COLOR_STANDARD[name];
- if (colorValue) {
- return new Color(colorValue);
- }
- return null;
- },
- /*
- * 通过给定的名字获取标准的颜色值表示, 返回的值以hex的方式提供
- * @param name 需要获取的标准颜色名称
- * @return 名字所对应的颜色值的hex表示, 如果未找到对应名称的值, 则返回一个空字符串
- */
- getColorValue: function(name) {
- return StandardColor.EXTEND_STANDARD[name] || StandardColor.COLOR_STANDARD[name] || "";
- },
- /*
- * 向调色板添加颜色名称,新添加的颜色对所有的调色板对象都可见
- * 对已存在的颜色名称, 将会覆盖掉
- * @param name 新添加的颜色名称
- * @param value 新添加的颜色名称所对于的值, 应该是一个hex格式的颜色字符串, 如: ”#ff0000“
- * @return 新添加的颜色的值
- */
- addColor: function(name, value) {
- if (typeof value === "string") {
- StandardColor.EXTEND_STANDARD[name] = new Color(value).toRGBA();
- } else {
- StandardColor.EXTEND_STANDARD[name] = value.toRGBA();
- }
- return value;
- },
- /*
- * 删除用户自己添加的颜色, 该方法不能删除内置的颜色, 该方法不会影响调色板实例自由的颜色
- * @param name 需要删除的颜色名称
- * @return 删除是否成功的bool值
- */
- removeColor: function(name) {
- if (StandardColor.EXTEND_STANDARD.hasOwnProperty(name)) {
- delete StandardColor.EXTEND_STANDARD[name];
- return true;
- }
- return false;
- }
- });
- return Palette;
- }
- };
- //src/graphic/paper.js
- _p[45] = {
- value: function(require, exports, module) {
- var Class = _p.r(11);
- var utils = _p.r(12);
- var svg = _p.r(67);
- var Container = _p.r(29);
- var ShapeContainer = _p.r(61);
- var ViewBox = _p.r(75);
- var EventHandler = _p.r(33);
- var Styled = _p.r(66);
- var Matrix = _p.r(43);
- var Paper = Class.createClass("Paper", {
- mixins: [ ShapeContainer, EventHandler, Styled, ViewBox ],
- constructor: function(container) {
- this.callBase();
- this.node = this.createSVGNode();
- this.node.paper = this;
- this.node.appendChild(this.resourceNode = svg.createNode("defs"));
- this.node.appendChild(this.shapeNode = svg.createNode("g"));
- this.resources = new Container();
- this.setWidth("100%").setHeight("100%");
- if (container) {
- this.renderTo(container);
- }
- this.callMixin();
- },
- renderTo: function(container) {
- if (utils.isString(container)) {
- container = document.getElementById(container);
- }
- this.container = container;
- container.appendChild(this.node);
- },
- createSVGNode: function() {
- var node = svg.createNode("svg");
- node.setAttribute("xmlns", "http://www.w3.org/2000/svg");
- node.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
- node.setAttribute("version", "1.1");
- return node;
- },
- getNode: function() {
- return this.node;
- },
- getContainer: function() {
- return this.container;
- },
- getWidth: function() {
- return this.node.clientWidth;
- },
- setWidth: function(width) {
- this.node.setAttribute("width", width);
- return this;
- },
- getHeight: function() {
- return this.node.clientHeight;
- },
- setHeight: function(height) {
- this.node.setAttribute("height", height);
- return this;
- },
- setViewPort: function(cx, cy, zoom) {
- var viewport, box;
- if (arguments.length == 1) {
- viewport = arguments[0];
- cx = viewport.center.x;
- cy = viewport.center.y;
- zoom = viewport.zoom;
- }
- zoom = zoom || 1;
- box = this.getViewBox();
- var matrix = new Matrix();
- var dx = box.x + box.width / 2 - cx, dy = box.y + box.height / 2 - cy;
- matrix.translate(-cx, -cy);
- matrix.scale(zoom);
- matrix.translate(cx, cy);
- matrix.translate(dx, dy);
- this.shapeNode.setAttribute("transform", "matrix(" + matrix + ")");
- this.viewport = {
- center: {
- x: cx,
- y: cy
- },
- offset: {
- x: dx,
- y: dy
- },
- zoom: zoom
- };
- return this;
- },
- getViewPort: function() {
- if (!this.viewport) {
- var box = this.getViewBox();
- return {
- zoom: 1,
- center: {
- x: box.x + box.width / 2,
- y: box.y + box.height / 2
- },
- offset: {
- x: 0,
- y: 0
- }
- };
- }
- return this.viewport;
- },
- getViewPortMatrix: function() {
- return Matrix.parse(this.shapeNode.getAttribute("transform"));
- },
- getViewPortTransform: function() {
- var m = this.shapeNode.getCTM();
- return new Matrix(m.a, m.b, m.c, m.d, m.e, m.f);
- },
- getTransform: function() {
- return this.getViewPortTransform().reverse();
- },
- addResource: function(resource) {
- this.resources.appendItem(resource);
- if (resource.node) {
- this.resourceNode.appendChild(resource.node);
- }
- return this;
- },
- removeResource: function(resource) {
- if (resource.remove) {
- resource.remove();
- }
- if (resource.node) {
- this.resourceNode.removeChild(resource.node);
- }
- return this;
- },
- getPaper: function() {
- return this;
- }
- });
- var Shape = _p.r(60);
- Class.extendClass(Shape, {
- getPaper: function() {
- var parent = this.container;
- while (parent && parent instanceof Paper === false) {
- parent = parent.container;
- }
- return parent;
- },
- isAttached: function() {
- return !!this.getPaper();
- },
- whenPaperReady: function(fn) {
- var me = this;
- function check() {
- var paper = me.getPaper();
- if (paper && fn) {
- fn.call(me, paper);
- }
- return paper;
- }
- if (!check()) {
- this.on("add treeadd", function listen() {
- if (check()) {
- me.off("add", listen);
- me.off("treeadd", listen);
- }
- });
- }
- return this;
- }
- });
- return Paper;
- }
- };
- //src/graphic/path.js
- _p[46] = {
- value: function(require, exports, module) {
- var Utils = _p.r(12);
- var createClass = _p.r(11).createClass;
- var Shape = _p.r(60);
- var svg = _p.r(67);
- var g = _p.r(34);
- var slice = Array.prototype.slice, flatten = Utils.flatten;
- var PathDrawer = createClass("PathDrawer", {
- constructor: function(path) {
- this.segment = [];
- this.path = path;
- this.__clear = false;
- },
- getPath: function() {
- return this.path;
- },
- redraw: function() {
- this._transation = this._transation || [];
- return this.clear();
- },
- done: function() {
- var transation = this._transation;
- this._transation = null;
- this.push(transation);
- return this;
- },
- clear: function() {
- if (this._transation) {
- this._transation = [];
- } else {
- this.path.setPathData("M 0 0");
- }
- this._clear = true;
- return this;
- },
- push: function() {
- var segment = slice.call(arguments);
- var originData;
- if (this._transation) {
- this._transation.push(segment);
- return this;
- }
- if (this._clear) {
- originData = "";
- this._clear = false;
- } else {
- originData = this.path.getPathData();
- }
- originData = originData || "";
- this.path.setPathData(originData + g.pathToString(segment));
- return this;
- },
- moveTo: function(x, y) {
- return this.push("M", slice.call(arguments));
- },
- moveBy: function(dx, dy) {
- return this.push("m", slice.call(arguments));
- },
- lineTo: function(x, y) {
- return this.push("L", slice.call(arguments));
- },
- lineBy: function(dx, dy) {
- return this.push("l", slice.call(arguments));
- },
- arcTo: function(rx, ry, xr, laf, sf, x, y) {
- return this.push("A", slice.call(arguments));
- },
- arcBy: function(rx, ry, xr, laf, sf, dx, dy) {
- return this.push("a", arguments);
- },
- carcTo: function(r, laf, sf, x, y) {
- return this.push("A", [ r, r, 0 ].concat(slice.call(arguments, 1)));
- },
- carcBy: function(r, laf, sf, dx, dy) {
- return this.push("a", [ r, r, 0 ].concat(slice.call(arguments, 1)));
- },
- bezierTo: function(x1, y1, x2, y2, x, y) {
- return this.push("C", slice.call(arguments));
- },
- bezierBy: function(dx1, dy1, dx2, dy2, dx, dy) {
- return this.push("c", slice.call(arguments));
- },
- close: function() {
- return this.push("z");
- }
- });
- return createClass("Path", {
- base: Shape,
- constructor: function(data) {
- this.callBase("path");
- if (data) {
- this.setPathData(data);
- }
- this.node.setAttribute("fill", svg.defaults.fill);
- this.node.setAttribute("stroke", svg.defaults.stroke);
- },
- setPathData: function(data) {
- data = data || "M0,0";
- this.pathdata = g.pathToString(data);
- this.node.setAttribute("d", this.pathdata);
- this.trigger("shapeupdate", {
- type: "pathdata"
- });
- return this;
- },
- getPathData: function() {
- return this.pathdata || "";
- },
- getDrawer: function() {
- return new PathDrawer(this);
- },
- isClosed: function() {
- var data = this.getPathData();
- return !!~data.indexOf("z") || !!~data.indexOf("Z");
- }
- });
- }
- };
- //src/graphic/pattern.js
- _p[47] = {
- value: function(require, exports, module) {
- var Resource = _p.r(58);
- var ShapeContainer = _p.r(61);
- var svg = _p.r(67);
- return _p.r(11).createClass("PatternBrush", {
- base: Resource,
- mixins: [ ShapeContainer ],
- constructor: function(paper) {
- this.callBase("pattern", paper);
- this.node.setAttribute("patternUnits", "userSpaceOnUse");
- },
- setX: function(x) {
- this.x = x;
- this.node.setAttribute("x", x);
- return this;
- },
- setY: function(y) {
- this.y = y;
- this.node.setAttribute("y", y);
- return this;
- },
- setWidth: function(width) {
- this.width = width;
- this.node.setAttribute("width", width);
- return this;
- },
- setHeight: function(height) {
- this.height = height;
- this.node.setAttribute("height", height);
- return this;
- },
- getWidth: function() {
- return this.width;
- },
- getHeight: function() {
- return this.height;
- }
- });
- }
- };
- //src/graphic/pen.js
- _p[48] = {
- value: function(require, exports, module) {
- var Color = _p.r(28);
- return _p.r(11).createClass("Pen", {
- constructor: function(brush, width) {
- this.brush = brush;
- this.width = width || 1;
- this.linecap = null;
- this.linejoin = null;
- this.dashArray = null;
- this.opacity = 1;
- },
- getBrush: function() {
- return this.brush;
- },
- setBrush: function(brush) {
- this.brush = brush;
- return this;
- },
- setColor: function(color) {
- return this.setBrush(color);
- },
- getColor: function() {
- return this.brush instanceof Color ? this.brush : null;
- },
- getWidth: function() {
- return this.width;
- },
- setWidth: function(width) {
- this.width = width;
- return this;
- },
- getOpacity: function() {
- return this.opacity;
- },
- setOpacity: function(opacity) {
- this.opacity = opacity;
- },
- getLineCap: function() {
- return this.linecap;
- },
- setLineCap: function(linecap) {
- this.linecap = linecap;
- return this;
- },
- getLineJoin: function() {
- return this.linejoin;
- },
- setLineJoin: function(linejoin) {
- this.linejoin = linejoin;
- return this;
- },
- getDashArray: function() {
- return this.dashArray;
- },
- setDashArray: function(dashArray) {
- this.dashArray = dashArray;
- return this;
- },
- stroke: function(shape) {
- var node = shape.node;
- node.setAttribute("stroke", this.brush.toString());
- node.setAttribute("stroke-width", this.getWidth());
- if (this.getOpacity() < 1) {
- node.setAttribute("stroke-opacity", this.getOpacity());
- }
- if (this.getLineCap()) {
- node.setAttribute("stroke-linecap", this.getLineCap());
- }
- if (this.getLineJoin()) {
- node.setAttribute("stroke-linejoin", this.getLineJoin());
- }
- if (this.getDashArray()) {
- node.setAttribute("stroke-dasharray", this.getDashArray());
- }
- }
- });
- }
- };
- //src/graphic/pie.js
- _p[49] = {
- value: function(require, exports, module) {
- return _p.r(11).createClass({
- base: _p.r(68),
- constructor: function(radius, angle, angleOffset) {
- this.callBase([ 0, radius ], angle, angleOffset);
- },
- getRadius: function() {
- return this.getSectionArray()[1];
- },
- setRadius: function(radius) {
- this.setSectionArray([ 0, radius ]);
- }
- });
- }
- };
- //src/graphic/point.js
- /*
- * 点对象抽象
- */
- _p[50] = {
- value: function(require, exports, module) {
- /**
- * @class kity.Point
- * @description 表示一个点
- */
- var Point = _p.r(11).createClass("Point", {
- /**
- * @constructor
- * @for kity.Point
- * @description 指定默认的 x 和 y 创建一个点
- *
- * @param {Number} x 点的 x 坐标
- * @param {Number} y 点的 y 坐标
- */
- constructor: function(x, y) {
- /**
- * @property
- * @for kity.Point
- * @description 表示点的 x 坐标
- * @type {Number}
- */
- this.x = x || 0;
- /**
- * @property
- * @for kity.Point
- * @description 表示点的 y 坐标
- * @type {Number}
- */
- this.y = y || 0;
- },
- offset: function(dx, dy) {
- if (arguments.length == 1) {
- dy = dx.y;
- dx = dx.x;
- }
- return new Point(this.x + dx, this.y + dy);
- },
- valueOf: function() {
- return [ this.x, this.y ];
- },
- toString: function() {
- return this.valueOf().join(" ");
- },
- spof: function() {
- return new Point((this.x | 0) + .5, (this.y | 0) + .5);
- },
- round: function() {
- return new Point(this.x | 0, this.y | 0);
- },
- isOrigin: function() {
- return this.x === 0 && this.y === 0;
- }
- });
- /**
- * @static
- * @method fromPolar()
- * @for kity.Point
- * @grammar kity.Point.fromPolar(radius, angle, unit) => kity.Point
- * @param {Number} radius 极坐标中的半径
- * @param {Number} angle 极坐标中的角度
- * @param {String} unit 角度使用的单位,默认为 'deg' (角度),可以取值为 'rad',表示传入的是弧度值
- */
- Point.fromPolar = function(radius, angle, unit) {
- if (unit != "rad") {
- // deg to rad
- angle = angle / 180 * Math.PI;
- }
- return new Point(radius * Math.cos(angle), radius * Math.sin(angle));
- };
- Point.parse = function(unknown) {
- if (!unknown) return new Point();
- if (unknown instanceof Point) {
- return unknown;
- }
- if (typeof unknown == "string") {
- return Point.parse(unknown.split(/\s*[\s,]\s*/));
- }
- if ("0" in unknown && "1" in unknown) {
- return new Point(unknown[0], unknown[1]);
- }
- };
- return Point;
- }
- };
- //src/graphic/pointcontainer.js
- /**
- * 点集合容器
- */
- _p[51] = {
- value: function(require, exports, module) {
- return _p.r(11).createClass("PointContainer", {
- base: _p.r(29),
- constructor: function() {
- this.callBase();
- },
- addPoint: function(point, pos) {
- return this.addItem.apply(this, arguments);
- },
- prependPoint: function() {
- return this.prependItem.apply(this, arguments);
- },
- appendPoint: function() {
- return this.appendItem.apply(this, arguments);
- },
- removePoint: function(pos) {
- return this.removeItem.apply(this, arguments);
- },
- addPoints: function() {
- return this.addItems.apply(this, arguments);
- },
- setPoints: function() {
- return this.setItems.apply(this, arguments);
- },
- getPoint: function() {
- return this.getItem.apply(this, arguments);
- },
- getPoints: function() {
- return this.getItems.apply(this, arguments);
- },
- getFirstPoint: function() {
- return this.getFirstItem.apply(this, arguments);
- },
- getLastPoint: function() {
- return this.getLastItem.apply(this, arguments);
- }
- });
- }
- };
- //src/graphic/poly.js
- /*
- * 通过点来决定图形的公共父类
- */
- _p[52] = {
- value: function(require, exports, module) {
- var Utils = _p.r(12);
- return _p.r(11).createClass("Poly", {
- base: _p.r(46),
- mixins: [ _p.r(51) ],
- constructor: function(points, closeable) {
- this.callBase();
- //是否可闭合
- this.closeable = !!closeable;
- this.setPoints(points || []);
- this.changeable = true;
- this.update();
- },
- //当点集合发生变化时采取的动作
- onContainerChanged: function() {
- if (this.changeable) {
- this.update();
- }
- },
- update: function() {
- var drawer = this.getDrawer(), points = this.getPoints();
- drawer.clear();
- if (!points.length) {
- return this;
- }
- drawer.moveTo(points[0]);
- for (var i = 1, point, len = points.length; i < len; i++) {
- point = points[i];
- drawer.lineTo(point);
- }
- if (this.closeable && points.length > 2) {
- drawer.close();
- }
- return this;
- }
- });
- }
- };
- //src/graphic/polygon.js
- _p[53] = {
- value: function(require, exports, module) {
- return _p.r(11).createClass("Polygon", {
- base: _p.r(52),
- constructor: function(points) {
- this.callBase(points, true);
- }
- });
- }
- };
- //src/graphic/polyline.js
- _p[54] = {
- value: function(require, exports, module) {
- return _p.r(11).createClass("Polyline", {
- base: _p.r(52),
- constructor: function(points) {
- this.callBase(points);
- }
- });
- }
- };
- //src/graphic/radialgradient.js
- _p[55] = {
- value: function(require, exports, module) {
- var Gradient = _p.r(35);
- return _p.r(11).createClass("RadialGradientBrush", {
- base: Gradient,
- constructor: function(paper) {
- this.callBase("radialGradient", paper);
- this.setCenter(.5, .5);
- this.setFocal(.5, .5);
- this.setRadius(.5);
- },
- setCenter: function(cx, cy) {
- this.node.setAttribute("cx", cx);
- this.node.setAttribute("cy", cy);
- return this;
- },
- getCenter: function() {
- return {
- x: +this.node.getAttribute("cx"),
- y: +this.node.getAttribute("cy")
- };
- },
- setFocal: function(fx, fy) {
- this.node.setAttribute("fx", fx);
- this.node.setAttribute("fy", fy);
- return this;
- },
- getFocal: function() {
- return {
- x: +this.node.getAttribute("fx"),
- y: +this.node.getAttribute("fy")
- };
- },
- setRadius: function(r) {
- this.node.setAttribute("r", r);
- return this;
- },
- getRadius: function() {
- return +this.node.getAttribute("r");
- }
- });
- }
- };
- //src/graphic/rect.js
- _p[56] = {
- value: function(require, exports, module) {
- var RectUtils = {}, Utils = _p.r(12), Point = _p.r(50), Box = _p.r(25);
- Utils.extend(RectUtils, {
- //根据传递进来的width、height和radius属性,
- //获取最适合的radius值
- formatRadius: function(width, height, radius) {
- var minValue = Math.floor(Math.min(width / 2, height / 2));
- return Math.min(minValue, radius);
- }
- });
- /**
- * @class kity.Rect
- * @description 表示一个矩形
- * @base kity.Path
- */
- var Rect = _p.r(11).createClass("Rect", {
- base: _p.r(46),
- /**
- * @constructor
- * @for kity.Rect
- * @grammar new kity.Rect(width, height, x, y, radius)
- * @param {Number} width 矩形的初始化宽度
- * @param {Number} height 矩形的初始化高度
- * @param {Number} x 矩形的初始化 x 坐标
- * @param {Number} y 矩形的初始化 y 坐标
- * @param {Number} radius 矩形的初始化圆角大小
- */
- constructor: function(width, height, x, y, radius) {
- this.callBase();
- this.x = x || 0;
- this.y = y || 0;
- this.width = width || 0;
- this.height = height || 0;
- this.radius = RectUtils.formatRadius(this.width, this.height, radius || 0);
- this.update();
- },
- update: function() {
- var x = this.x, y = this.y, w = this.width, h = this.height, r = this.radius;
- var drawer = this.getDrawer().redraw();
- if (!r) {
- // 直角
- drawer.push("M", x, y);
- drawer.push("h", w);
- drawer.push("v", h);
- drawer.push("h", -w);
- drawer.push("z");
- } else {
- //圆角
- w -= 2 * r;
- h -= 2 * r;
- drawer.push("M", x + r, y);
- drawer.push("h", w);
- drawer.push("a", r, r, 0, 0, 1, r, r);
- drawer.push("v", h);
- drawer.push("a", r, r, 0, 0, 1, -r, r);
- drawer.push("h", -w);
- drawer.push("a", r, r, 0, 0, 1, -r, -r);
- drawer.push("v", -h);
- drawer.push("a", r, r, 0, 0, 1, r, -r);
- drawer.push("z");
- }
- drawer.done();
- return this;
- },
- /**
- * @method setWidth
- * @for kity.Rect
- * @grammar setWidth(width) => kity.Rect
- * @description 设置矩形的宽度,设置后返回矩形实例本身
- * @param {Number} width 宽度值
- *
- * @example
- * ```js
- * rect.setWidth(300);
- * ```
- */
- setWidth: function(width) {
- this.width = width;
- return this.update();
- },
- /**
- * @method setHeight
- * @for kity.Rect
- * @grammar setHeight(height) => kity.Rect
- * @description 设置矩形的高度,设置后返回矩形实例本身
- * @param {Number} height 高度值
- *
- * @example
- * ```js
- * rect.setHeight(200);
- * ```
- */
- setHeight: function(height) {
- this.height = height;
- return this.update();
- },
- /**
- * @method setSize
- * @for kity.Rect
- * @grammar setSize(width, height) => kity.Rect
- * @description 设置矩形的尺寸,设置后返回矩形本身
- * @param {Number} width 矩形的宽度值
- * @param {Number} height 矩形的高度值
- *
- * @example
- * ```js
- * rect.setSize(300, 200);
- * ```
- */
- setSize: function(width, height) {
- this.width = width;
- this.height = height;
- return this.update();
- },
- /**
- * @method setBox
- * @for kity.Rect
- * @grammar setBox(box) => kity.Rect
- * @description 使用一个 kity 的盒子数据,
- * @param {kity.Box} box 盒子数据
- */
- setBox: function(box) {
- this.x = box.x;
- this.y = box.y;
- this.width = box.width;
- this.height = box.height;
- return this.update();
- },
- getBox: function() {
- return new Box(this.x, this.y, this.width, this.height);
- },
- getRadius: function() {
- return this.radius;
- },
- setRadius: function(radius) {
- this.radius = RectUtils.formatRadius(this.width, this.height, radius || 0);
- return this.update();
- },
- getPosition: function() {
- return new Point(this.x, this.y);
- },
- setPosition: function(x, y) {
- if (arguments.length == 1) {
- var p = Point.parse(arguments[0]);
- y = p.y;
- x = p.x;
- }
- this.x = x;
- this.y = y;
- return this.update();
- },
- getWidth: function() {
- return this.width;
- },
- getHeight: function() {
- return this.height;
- },
- getPositionX: function() {
- return this.x;
- },
- getPositionY: function() {
- return this.y;
- },
- setPositionX: function(x) {
- this.x = x;
- return this.update();
- },
- setPositionY: function(y) {
- this.y = y;
- return this.update();
- }
- });
- return Rect;
- }
- };
- //src/graphic/regularpolygon.js
- _p[57] = {
- value: function(require, exports, module) {
- var Point = _p.r(50);
- return _p.r(11).createClass("RegularPolygon", {
- base: _p.r(46),
- constructor: function(side, radius, x, y) {
- this.callBase();
- this.radius = radius || 0;
- this.side = Math.max(side || 3, 3);
- if (arguments.length > 2) {
- if (arguments.length == 3) {
- y = x.y;
- x = x.x;
- }
- }
- this.center = new Point(x, y);
- this.draw();
- },
- getSide: function() {
- return this.side;
- },
- setSide: function(side) {
- this.side = side;
- return this.draw();
- },
- getRadius: function() {
- return this.radius;
- },
- setRadius: function(radius) {
- this.radius = radius;
- return this.draw();
- },
- draw: function() {
- var radius = this.radius, side = this.side, step = Math.PI * 2 / side, drawer = this.getDrawer(), i;
- drawer.clear();
- drawer.moveTo(Point.fromPolar(radius, Math.PI / 2, "rad").offset(this.center));
- for (i = 0; i <= side; i++) {
- drawer.lineTo(Point.fromPolar(radius, step * i + Math.PI / 2, "rad").offset(this.center));
- }
- drawer.close();
- return this;
- }
- });
- }
- };
- //src/graphic/resource.js
- /**
- * @fileOverview
- *
- * 资源节点基类
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- _p[58] = {
- value: function(require, exports, module) {
- var svg = _p.r(67);
- return _p.r(11).createClass("Resource", {
- constructor: function(nodeType, paper) {
- this.callBase();
- this.node = svg.createNode(nodeType);
- if (paper) {
- paper.addResource(this);
- }
- },
- toString: function() {
- return "url(#" + this.node.id + ")";
- }
- });
- }
- };
- //src/graphic/ring.js
- _p[59] = {
- value: function(require, exports, module) {
- return _p.r(11).createClass({
- base: _p.r(68),
- constructor: function(innerRadius, outerRadius) {
- this.callBase([ innerRadius, outerRadius ], 360, 0);
- },
- getInnerRadius: function() {
- return this.getSectionArray()[0];
- },
- getOuterRadius: function() {
- return this.getSectionArray()[1];
- },
- setInnerRadius: function(value) {
- this.setSectionArray([ value, this.getOuterRadius() ]);
- },
- setOuterRadius: function(value) {
- this.setSectionArray([ this.getInnerRadius(), value ]);
- }
- });
- }
- };
- //src/graphic/shape.js
- _p[60] = {
- value: function(require, exports, module) {
- var svg = _p.r(67);
- var utils = _p.r(12);
- var EventHandler = _p.r(33);
- var Styled = _p.r(66);
- var Data = _p.r(31);
- var Matrix = _p.r(43);
- var Pen = _p.r(48);
- var slice = Array.prototype.slice;
- var Box = _p.r(25);
- var Shape = _p.r(11).createClass("Shape", {
- mixins: [ EventHandler, Styled, Data ],
- constructor: function Shape(tagName) {
- this.node = svg.createNode(tagName);
- this.node.shape = this;
- this.transform = {
- translate: null,
- rotate: null,
- scale: null,
- matrix: null
- };
- this.callMixin();
- },
- getId: function() {
- return this.node.id;
- },
- setId: function(id) {
- this.node.id = id;
- return this;
- },
- getNode: function() {
- return this.node;
- },
- getBoundaryBox: function() {
- var box;
- try {
- box = this.node.getBBox();
- } catch (e) {
- box = {
- x: this.node.clientLeft,
- y: this.node.clientTop,
- width: this.node.clientWidth,
- height: this.node.clientHeight
- };
- }
- return new Box(box);
- },
- getRenderBox: function(refer) {
- var box = this.getBoundaryBox();
- var matrix = this.getTransform(refer);
- return matrix.transformBox(box);
- },
- getWidth: function() {
- return this.getRenderBox().width;
- },
- getHeight: function() {
- return this.getRenderBox().height;
- },
- getSize: function() {
- var box = this.getRenderBox();
- delete box.x;
- delete box.y;
- return box;
- },
- setOpacity: function(value) {
- this.node.setAttribute("opacity", value);
- return this;
- },
- getOpacity: function() {
- var opacity = this.node.getAttribute("opacity");
- return opacity ? +opacity : 1;
- },
- setVisible: function(value) {
- if (value) {
- this.node.removeAttribute("display");
- } else {
- this.node.setAttribute("display", "none");
- }
- return this;
- },
- getVisible: function() {
- this.node.getAttribute("display");
- },
- hasAncestor: function(node) {
- var parent = this.container;
- while (parent) {
- if (parent === node) {
- return true;
- }
- parent = parent.container;
- }
- return false;
- },
- getTransform: function(refer) {
- return Matrix.getCTM(this, refer);
- },
- clearTransform: function() {
- this.node.removeAttribute("transform");
- this.transform = {
- translate: null,
- rotate: null,
- scale: null,
- matrix: null
- };
- this.trigger("shapeupdate", {
- type: "transform"
- });
- return this;
- },
- _applyTransform: function() {
- var t = this.transform, result = [];
- if (t.translate) {
- result.push([ "translate(", t.translate, ")" ]);
- }
- if (t.rotate) {
- result.push([ "rotate(", t.rotate, ")" ]);
- }
- if (t.scale) {
- result.push([ "scale(", t.scale, ")" ]);
- }
- if (t.matrix) {
- result.push([ "matrix(", t.matrix, ")" ]);
- }
- this.node.setAttribute("transform", utils.flatten(result).join(" "));
- return this;
- },
- setMatrix: function(m) {
- this.transform.matrix = m;
- return this._applyTransform();
- },
- setTranslate: function(t) {
- this.transform.translate = t !== null && slice.call(arguments) || null;
- return this._applyTransform();
- },
- setRotate: function(r) {
- this.transform.rotate = r !== null && slice.call(arguments) || null;
- return this._applyTransform();
- },
- setScale: function(s) {
- this.transform.scale = s !== null && slice.call(arguments) || null;
- return this._applyTransform();
- },
- translate: function(dx, dy) {
- var m = this.transform.matrix || new Matrix();
- if (dy === undefined) {
- dy = 0;
- }
- this.transform.matrix = m.translate(dx, dy);
- return this._applyTransform();
- },
- rotate: function(deg) {
- var m = this.transform.matrix || new Matrix();
- this.transform.matrix = m.rotate(deg);
- return this._applyTransform();
- },
- scale: function(sx, sy) {
- var m = this.transform.matrix || new Matrix();
- if (sy === undefined) {
- sy = sx;
- }
- this.transform.matrix = m.scale(sx, sy);
- return this._applyTransform();
- },
- skew: function(sx, sy) {
- var m = this.transform.matrix || new Matrix();
- if (sy === undefined) {
- sy = sx;
- }
- this.transform.matrix = m.skew(sx, sy);
- return this._applyTransform();
- },
- stroke: function(pen, width) {
- if (pen && pen.stroke) {
- pen.stroke(this);
- } else if (pen) {
- // 字符串或重写了 toString 的对象
- this.node.setAttribute("stroke", pen.toString());
- if (width) {
- this.node.setAttribute("stroke-width", width);
- }
- } else if (pen === null) {
- this.node.removeAttribute("stroe");
- }
- return this;
- },
- fill: function(brush) {
- // 字符串或重写了 toString 的对象
- if (brush) {
- this.node.setAttribute("fill", brush.toString());
- }
- if (brush === null) {
- this.node.removeAttribute("fill");
- }
- return this;
- },
- setAttr: function(a, v) {
- var me = this;
- if (utils.isObject(a)) {
- utils.each(a, function(val, key) {
- me.setAttr(key, val);
- });
- }
- if (v === undefined || v === null || v === "") {
- this.node.removeAttribute(a);
- } else {
- this.node.setAttribute(a, v);
- }
- return this;
- },
- getAttr: function(a) {
- return this.node.getAttribute(a);
- }
- });
- return Shape;
- }
- };
- //src/graphic/shapecontainer.js
- _p[61] = {
- value: function(require, exports, module) {
- var Container = _p.r(29);
- var utils = _p.r(12);
- var ShapeContainer = _p.r(11).createClass("ShapeContainer", {
- base: Container,
- isShapeContainer: true,
- /* private */
- handleAdd: function(shape, index) {
- var parent = this.getShapeNode();
- parent.insertBefore(shape.node, parent.childNodes[index] || null);
- shape.trigger("add", {
- container: this
- });
- if (shape.notifyTreeModification) {
- shape.notifyTreeModification("treeadd", this);
- }
- },
- /* private */
- handleRemove: function(shape, index) {
- var parent = this.getShapeNode();
- parent.removeChild(shape.node);
- shape.trigger("remove", {
- container: this
- });
- if (shape.notifyTreeModification) {
- shape.notifyTreeModification("treeremove", this);
- }
- },
- /* private */
- notifyTreeModification: function(type, container) {
- this.eachItem(function(index, shape) {
- if (shape.notifyTreeModification) {
- shape.notifyTreeModification(type, container);
- }
- shape.trigger(type, {
- container: container
- });
- });
- },
- /* public */
- getShape: function(index) {
- return this.getItem(index);
- },
- /* public */
- addShape: function(shape, index) {
- return this.addItem(shape, index);
- },
- put: function(shape) {
- this.addShape(shape);
- return shape;
- },
- appendShape: function(shape) {
- return this.addShape(shape);
- },
- prependShape: function(shape) {
- return this.addShape(shape, 0);
- },
- replaceShape: function(replacer, origin) {
- var index = this.indexOf(origin);
- if (index === -1) {
- return;
- }
- this.removeShape(index);
- this.addShape(replacer, index);
- return this;
- },
- addShapeBefore: function(shape, refer) {
- var index = this.indexOf(refer);
- return this.addShape(shape, index);
- },
- addShapeAfter: function(shape, refer) {
- var index = this.indexOf(refer);
- return this.addShape(shape, index === -1 ? undefined : index + 1);
- },
- /* public */
- addShapes: function(shapes) {
- return this.addItems(shapes);
- },
- /* public */
- removeShape: function(index) {
- return this.removeItem(index);
- },
- getShapes: function() {
- return this.getItems();
- },
- getShapesByType: function(name) {
- var shapes = [];
- function getShapes(shape) {
- if (name.toLowerCase() == shape.getType().toLowerCase()) {
- shapes.push(shape);
- }
- if (shape.isShapeContainer) {
- utils.each(shape.getShapes(), function(n) {
- getShapes(n);
- });
- }
- }
- getShapes(this);
- return shapes;
- },
- /* public */
- getShapeById: function(id) {
- return this.getShapeNode().getElementById(id).shape;
- },
- arrangeShape: function(shape, index) {
- return this.removeShape(shape).addShape(shape, index);
- },
- /* protected */
- getShapeNode: function() {
- return this.shapeNode || this.node;
- }
- });
- var Shape = _p.r(60);
- _p.r(11).extendClass(Shape, {
- bringTo: function(index) {
- this.container.arrangeShape(this, index);
- return this;
- },
- bringFront: function() {
- return this.bringTo(this.container.indexOf(this) + 1);
- },
- bringBack: function() {
- return this.bringTo(this.container.indexOf(this) - 1);
- },
- bringTop: function() {
- this.container.removeShape(this).addShape(this);
- return this;
- },
- bringRear: function() {
- return this.bringTo(0);
- },
- bringRefer: function(referShape, offset) {
- if (referShape.container) {
- if (this.remove) {
- this.remove();
- }
- referShape.container.addShape(this, referShape.container.indexOf(referShape) + (offset || 0));
- }
- return this;
- },
- bringAbove: function(referShape) {
- return this.bringRefer(referShape);
- },
- bringBelow: function(referShape) {
- return this.bringRefer(referShape, 1);
- },
- replaceBy: function(newShape) {
- if (this.container) {
- newShape.bringAbove(this);
- this.remove();
- }
- return this;
- }
- });
- return ShapeContainer;
- }
- };
- //src/graphic/shapeevent.js
- /*
- * 图形事件包装类
- * */
- _p[62] = {
- value: function(require, exprots, module) {
- var Matrix = _p.r(43), Utils = _p.r(12), Point = _p.r(50);
- return _p.r(11).createClass("ShapeEvent", {
- constructor: function(event) {
- var target = null;
- // dom 事件封装对象
- if (!Utils.isObject(event.target)) {
- this.type = event.type;
- target = event.target;
- // use标签有特殊属性, 需要区别对待
- if (target.correspondingUseElement) {
- target = target.correspondingUseElement;
- }
- this.originEvent = event;
- this.targetShape = target.shape || target.paper || event.currentTarget && (event.currentTarget.shape || event.currentTarget.paper);
- if (event._kityParam) {
- Utils.extend(this, event._kityParam);
- }
- } else {
- Utils.extend(this, event);
- }
- },
- preventDefault: function() {
- var evt = this.originEvent;
- if (!evt) {
- return true;
- }
- if (evt.preventDefault) {
- evt.preventDefault();
- return evt.cancelable;
- } else {
- evt.returnValue = false;
- return true;
- }
- },
- //当前鼠标事件在用户坐标系中点击的点的坐标位置
- getPosition: function(refer, touchIndex) {
- if (!this.originEvent) {
- return null;
- }
- var eventClient = this.originEvent.touches ? this.originEvent.touches[touchIndex || 0] : this.originEvent;
- var target = this.targetShape;
- var targetNode = target.shapeNode || target.node;
- var pScreen = new Point(eventClient && eventClient.clientX || 0, eventClient && eventClient.clientY || 0);
- var pTarget = Matrix.transformPoint(pScreen, targetNode.getScreenCTM().inverse());
- var pRefer = Matrix.getCTM(target, refer || "view").transformPoint(pTarget);
- return pRefer;
- },
- stopPropagation: function() {
- var evt = this.originEvent;
- if (!evt) {
- return true;
- }
- if (evt.stopPropagation) {
- evt.stopPropagation();
- } else {
- evt.cancelBubble = false;
- }
- }
- });
- }
- };
- //src/graphic/shapepoint.js
- /*
- * 图形上的点抽象
- */
- _p[63] = {
- value: function(require, exports, module) {
- return _p.r(11).createClass("ShapePoint", {
- base: _p.r(50),
- constructor: function(px, py) {
- this.callBase(px, py);
- },
- setX: function(x) {
- return this.setPoint(x, this.y);
- },
- setY: function(y) {
- return this.setPoint(this.x, y);
- },
- setPoint: function(x, y) {
- this.x = x;
- this.y = y;
- this.update();
- return this;
- },
- getPoint: function() {
- return this;
- },
- update: function() {
- if (this.container && this.container.update) {
- this.container.update();
- }
- return this;
- }
- });
- }
- };
- //src/graphic/standardcolor.js
- /**
- * 标准颜色映射
- */
- _p[64] = {
- value: {
- COLOR_STANDARD: {
- aliceblue: "#f0f8ff",
- antiquewhite: "#faebd7",
- aqua: "#00ffff",
- aquamarine: "#7fffd4",
- azure: "#f0ffff",
- beige: "#f5f5dc",
- bisque: "#ffe4c4",
- black: "#000000",
- blanchedalmond: "#ffebcd",
- blue: "#0000ff",
- blueviolet: "#8a2be2",
- brown: "#a52a2a",
- burlywood: "#deb887",
- cadetblue: "#5f9ea0",
- chartreuse: "#7fff00",
- chocolate: "#d2691e",
- coral: "#ff7f50",
- cornflowerblue: "#6495ed",
- cornsilk: "#fff8dc",
- crimson: "#dc143c",
- cyan: "#00ffff",
- darkblue: "#00008b",
- darkcyan: "#008b8b",
- darkgoldenrod: "#b8860b",
- darkgray: "#a9a9a9",
- darkgreen: "#006400",
- darkgrey: "#a9a9a9",
- darkkhaki: "#bdb76b",
- darkmagenta: "#8b008b",
- darkolivegreen: "#556b2f",
- darkorange: "#ff8c00",
- darkorchid: "#9932cc",
- darkred: "#8b0000",
- darksalmon: "#e9967a",
- darkseagreen: "#8fbc8f",
- darkslateblue: "#483d8b",
- darkslategray: "#2f4f4f",
- darkslategrey: "#2f4f4f",
- darkturquoise: "#00ced1",
- darkviolet: "#9400d3",
- deeppink: "#ff1493",
- deepskyblue: "#00bfff",
- dimgray: "#696969",
- dimgrey: "#696969",
- dodgerblue: "#1e90ff",
- firebrick: "#b22222",
- floralwhite: "#fffaf0",
- forestgreen: "#228b22",
- fuchsia: "#ff00ff",
- gainsboro: "#dcdcdc",
- ghostwhite: "#f8f8ff",
- gold: "#ffd700",
- goldenrod: "#daa520",
- gray: "#808080",
- green: "#008000",
- greenyellow: "#adff2f",
- grey: "#808080",
- honeydew: "#f0fff0",
- hotpink: "#ff69b4",
- indianred: "#cd5c5c",
- indigo: "#4b0082",
- ivory: "#fffff0",
- khaki: "#f0e68c",
- lavender: "#e6e6fa",
- lavenderblush: "#fff0f5",
- lawngreen: "#7cfc00",
- lemonchiffon: "#fffacd",
- lightblue: "#add8e6",
- lightcoral: "#f08080",
- lightcyan: "#e0ffff",
- lightgoldenrodyellow: "#fafad2",
- lightgray: "#d3d3d3",
- lightgreen: "#90ee90",
- lightgrey: "#d3d3d3",
- lightpink: "#ffb6c1",
- lightsalmon: "#ffa07a",
- lightseagreen: "#20b2aa",
- lightskyblue: "#87cefa",
- lightslategray: "#778899",
- lightslategrey: "#778899",
- lightsteelblue: "#b0c4de",
- lightyellow: "#ffffe0",
- lime: "#00ff00",
- limegreen: "#32cd32",
- linen: "#faf0e6",
- magenta: "#ff00ff",
- maroon: "#800000",
- mediumaquamarine: "#66cdaa",
- mediumblue: "#0000cd",
- mediumorchid: "#ba55d3",
- mediumpurple: "#9370db",
- mediumseagreen: "#3cb371",
- mediumslateblue: "#7b68ee",
- mediumspringgreen: "#00fa9a",
- mediumturquoise: "#48d1cc",
- mediumvioletred: "#c71585",
- midnightblue: "#191970",
- mintcream: "#f5fffa",
- mistyrose: "#ffe4e1",
- moccasin: "#ffe4b5",
- navajowhite: "#ffdead",
- navy: "#000080",
- oldlace: "#fdf5e6",
- olive: "#808000",
- olivedrab: "#6b8e23",
- orange: "#ffa500",
- orangered: "#ff4500",
- orchid: "#da70d6",
- palegoldenrod: "#eee8aa",
- palegreen: "#98fb98",
- paleturquoise: "#afeeee",
- palevioletred: "#db7093",
- papayawhip: "#ffefd5",
- peachpuff: "#ffdab9",
- peru: "#cd853f",
- pink: "#ffc0cb",
- plum: "#dda0dd",
- powderblue: "#b0e0e6",
- purple: "#800080",
- red: "#ff0000",
- rosybrown: "#bc8f8f",
- royalblue: "#4169e1",
- saddlebrown: "#8b4513",
- salmon: "#fa8072",
- sandybrown: "#f4a460",
- seagreen: "#2e8b57",
- seashell: "#fff5ee",
- sienna: "#a0522d",
- silver: "#c0c0c0",
- skyblue: "#87ceeb",
- slateblue: "#6a5acd",
- slategray: "#708090",
- slategrey: "#708090",
- snow: "#fffafa",
- springgreen: "#00ff7f",
- steelblue: "#4682b4",
- tan: "#d2b48c",
- teal: "#008080",
- thistle: "#d8bfd8",
- tomato: "#ff6347",
- turquoise: "#40e0d0",
- violet: "#ee82ee",
- wheat: "#f5deb3",
- white: "#ffffff",
- whitesmoke: "#f5f5f5",
- yellow: "#ffff00"
- },
- //标准扩展
- EXTEND_STANDARD: {}
- }
- };
- //src/graphic/star.js
- _p[65] = {
- value: function(require, exports, module) {
- /**
- * @see http://www.jdawiseman.com/papers/easymath/surds_star_inner_radius.html
- */
- var defaultRatioForStar = {
- "3": .2,
- // yy
- "5": .38196601125,
- "6": .57735026919,
- "8": .541196100146,
- "10": .726542528005,
- "12": .707106781187
- };
- var Point = _p.r(50);
- return _p.r(11).createClass("Star", {
- base: _p.r(46),
- constructor: function(vertex, radius, shrink, offset, angleOffset) {
- this.callBase();
- this.vertex = vertex || 3;
- this.radius = radius || 0;
- this.shrink = shrink;
- this.offset = offset || new Point(0, 0);
- this.angleOffset = angleOffset || 0;
- this.draw();
- },
- getVertex: function() {
- return this.vertex;
- },
- setVertex: function(value) {
- this.vertex = value;
- return this.draw();
- },
- getRadius: function() {
- return this.radius;
- },
- setRadius: function(value) {
- this.radius = value;
- return this.draw();
- },
- getShrink: function() {
- return this.shrink;
- },
- setShrink: function(value) {
- this.shrink = value;
- return this.draw();
- },
- getOffset: function() {
- return this.offset;
- },
- setOffset: function(value) {
- this.offset = value;
- return this.draw();
- },
- getAngleOffset: function() {
- return this.angleOffset;
- },
- setAngleOffset: function(value) {
- this.angleOffset = value;
- return this.draw();
- },
- draw: function() {
- var innerRadius = this.radius, outerRadius = this.radius * (this.shrink || defaultRatioForStar[this.vertex] || .5), vertex = this.vertex, offset = this.offset, angleStart = 90, angleStep = 180 / vertex, angleOffset = this.angleOffset, drawer = this.getDrawer(), i, angle;
- drawer.clear();
- drawer.moveTo(Point.fromPolar(outerRadius, angleStart));
- for (i = 1; i <= vertex * 2; i++) {
- angle = angleStart + angleStep * i;
- // 绘制内点
- if (i % 2) {
- drawer.lineTo(Point.fromPolar(innerRadius, angle + angleOffset).offset(offset));
- } else {
- drawer.lineTo(Point.fromPolar(outerRadius, angle));
- }
- }
- drawer.close();
- }
- });
- }
- };
- //src/graphic/styled.js
- _p[66] = {
- value: function(require, exports, module) {
- // polyfill for ie
- var ClassList = _p.r(11).createClass("ClassList", {
- constructor: function(node) {
- this._node = node;
- this._list = node.className.toString().split(" ");
- },
- _update: function() {
- this._node.className = this._list.join(" ");
- },
- add: function(name) {
- this._list.push(name);
- this._update();
- },
- remove: function(name) {
- var index = this._list.indexOf(name);
- if (~index) {
- this._list.splice(index, 1);
- }
- this._update();
- },
- contains: function(name) {
- return !!~this._list.indexOf(name);
- }
- });
- function getClassList(node) {
- if (!node.classList) {
- node.classList = new ClassList(node);
- }
- return node.classList;
- }
- return _p.r(11).createClass("Styled", {
- addClass: function(name) {
- getClassList(this.node).add(name);
- return this;
- },
- removeClass: function(name) {
- getClassList(this.node).remove(name);
- return this;
- },
- hasClass: function(name) {
- return getClassList(this.node).contains(name);
- },
- setStyle: function(styles) {
- if (arguments.length == 2) {
- this.node.style[arguments[0]] = arguments[1];
- return this;
- }
- for (var name in styles) {
- if (styles.hasOwnProperty(name)) {
- this.node.style[name] = styles[name];
- }
- }
- return this;
- }
- });
- }
- };
- //src/graphic/svg.js
- _p[67] = {
- value: function(require, exports, module) {
- var doc = document;
- var id = 0;
- var svg = {
- createNode: function(name) {
- var node = doc.createElementNS(svg.ns, name);
- node.id = "kity_" + name + "_" + id++;
- return node;
- },
- defaults: {
- stroke: "none",
- fill: "none"
- },
- xlink: "http://www.w3.org/1999/xlink",
- ns: "http://www.w3.org/2000/svg"
- };
- return svg;
- }
- };
- //src/graphic/sweep.js
- _p[68] = {
- value: function(require, exports, module) {
- var Point = _p.r(50);
- return _p.r(11).createClass("Sweep", {
- base: _p.r(46),
- constructor: function(sectionArray, angle, angleOffset) {
- this.callBase();
- this.sectionArray = sectionArray || [];
- this.angle = angle || 0;
- this.angleOffset = angleOffset || 0;
- this.draw();
- },
- getSectionArray: function() {
- return this.sectionArray;
- },
- setSectionArray: function(value) {
- this.sectionArray = value;
- return this.draw();
- },
- getAngle: function() {
- return this.angle;
- },
- setAngle: function(value) {
- this.angle = value;
- return this.draw();
- },
- getAngleOffset: function() {
- return this.angleOffset;
- },
- setAngleOffset: function(value) {
- this.angleOffset = value;
- return this.draw();
- },
- draw: function() {
- var sectionArray = this.sectionArray, i;
- for (i = 0; i < sectionArray.length; i += 2) {
- this.drawSection(sectionArray[i], sectionArray[i + 1]);
- }
- return this;
- },
- drawSection: function(from, to) {
- var angleLength = this.angle && (this.angle % 360 ? this.angle % 360 : 360), angleStart = this.angleOffset, angleHalf = angleStart + angleLength / 2, angleEnd = angleStart + angleLength, sweepFlag = angleLength < 0 ? 0 : 1, drawer = this.getDrawer();
- drawer.redraw();
- if (angleLength === 0) {
- drawer.done();
- return;
- }
- drawer.moveTo(Point.fromPolar(from, angleStart));
- drawer.lineTo(Point.fromPolar(to, angleStart));
- if (to) {
- drawer.carcTo(to, 0, sweepFlag, Point.fromPolar(to, angleHalf));
- drawer.carcTo(to, 0, sweepFlag, Point.fromPolar(to, angleEnd));
- }
- drawer.lineTo(Point.fromPolar(from, angleEnd));
- if (from) {
- drawer.carcTo(from, 0, sweepFlag, Point.fromPolar(from, angleHalf));
- drawer.carcTo(from, 0, sweepFlag, Point.fromPolar(from, angleStart));
- }
- drawer.close();
- drawer.done();
- }
- });
- }
- };
- //src/graphic/text.js
- _p[69] = {
- value: function(require, exports, module) {
- var TextContent = _p.r(70);
- var ShapeContainer = _p.r(61);
- var svg = _p.r(67);
- var utils = _p.r(12);
- var offsetHash = {};
- function getTextBoundOffset(text) {
- var font = text._cachedFontHash;
- if (offsetHash[font]) {
- return offsetHash[font];
- }
- var textContent = text.getContent();
- text.setContent("百度Fex");
- var bbox = text.getBoundaryBox(), y = text.getY();
- var topOffset = y - bbox.y + +text.node.getAttribute("dy"), bottomOffset = topOffset - bbox.height;
- text.setContent(textContent);
- return offsetHash[font] = {
- top: topOffset,
- bottom: bottomOffset,
- middle: (topOffset + bottomOffset) / 2
- };
- }
- return _p.r(11).createClass("Text", {
- base: TextContent,
- mixins: [ ShapeContainer ],
- constructor: function(content) {
- this.callBase("text");
- if (content !== undefined) {
- this.setContent(content);
- }
- this._buildFontHash();
- },
- _buildFontHash: function() {
- var style = window.getComputedStyle(this.node);
- this._cachedFontHash = [ style.fontFamily, style.fontSize, style.fontStretch, style.fontStyle, style.fontVariant, style.fontWeight ].join("-");
- },
- _fontChanged: function(font) {
- var last = this._lastFont;
- var current = utils.extend({}, last, font);
- if (!last) {
- this._lastFont = font;
- return true;
- }
- var changed = last.family != current.family || last.size != current.size || last.style != current.style || last.weight != current.weight;
- this._lastFont = current;
- return changed;
- },
- setX: function(x) {
- this.node.setAttribute("x", x);
- return this;
- },
- setPosition: function(x, y) {
- return this.setX(x).setY(y);
- },
- setY: function(y) {
- this.node.setAttribute("y", y);
- return this;
- },
- getX: function() {
- return +this.node.getAttribute("x") || 0;
- },
- getY: function() {
- return +this.node.getAttribute("y") || 0;
- },
- setFont: function(font) {
- this.callBase(font);
- if (this._fontChanged(font)) {
- this._buildFontHash();
- this.setVerticalAlign(this.getVerticalAlign());
- }
- return this;
- },
- setTextAnchor: function(anchor) {
- this.node.setAttribute("text-anchor", anchor);
- return this;
- },
- getTextAnchor: function() {
- return this.node.getAttribute("text-anchor") || "start";
- },
- // top/bottom/middle/baseline
- setVerticalAlign: function(align) {
- this.whenPaperReady(function() {
- var dy;
- switch (align) {
- case "top":
- dy = getTextBoundOffset(this).top;
- break;
- case "bottom":
- dy = getTextBoundOffset(this).bottom;
- break;
- case "middle":
- dy = getTextBoundOffset(this).middle;
- break;
- default:
- dy = 0;
- }
- this.node.setAttribute("dy", dy);
- });
- this.verticalAlign = align;
- return this;
- },
- getVerticalAlign: function() {
- return this.verticalAlign || "baseline";
- },
- setStartOffset: function(offset) {
- // only for text path
- if (this.shapeNode != this.node) {
- this.shapeNode.setAttribute("startOffset", offset * 100 + "%");
- }
- },
- addSpan: function(span) {
- this.addShape(span);
- return this;
- },
- setPath: function(path) {
- var textpath = this.shapeNode;
- if (this.shapeNode == this.node) {
- // 当前还不是 textpath
- textpath = this.shapeNode = svg.createNode("textPath");
- while (this.node.firstChild) {
- this.shapeNode.appendChild(this.node.firstChild);
- }
- this.node.appendChild(textpath);
- }
- textpath.setAttributeNS(svg.xlink, "xlink:href", "#" + path.node.id);
- this.setTextAnchor(this.getTextAnchor());
- return this;
- }
- });
- }
- };
- //src/graphic/textcontent.js
- _p[70] = {
- value: function(require, exports, module) {
- var Shape = _p.r(60);
- return _p.r(11).createClass("TextContent", {
- base: Shape,
- constructor: function(nodeType) {
- // call shape constructor
- this.callBase(nodeType);
- this.shapeNode = this.shapeNode || this.node;
- this.shapeNode.setAttribute("text-rendering", "geometricPrecision");
- },
- clearContent: function() {
- while (this.shapeNode.firstChild) {
- this.shapeNode.removeChild(this.shapeNode.firstChild);
- }
- return this;
- },
- setContent: function(content) {
- this.shapeNode.textContent = content;
- return this;
- },
- getContent: function() {
- return this.shapeNode.textContent;
- },
- appendContent: function(content) {
- this.shapeNode.textContent += content;
- return this;
- },
- setSize: function(value) {
- return this.setFontSize(value);
- },
- setFontSize: function(value) {
- return this.setFont({
- size: value
- });
- },
- setFontFamily: function(value) {
- return this.setFont({
- family: value
- });
- },
- setFontBold: function(bold) {
- return this.setFont({
- weight: bold ? "bold" : "normal"
- });
- },
- setFontItalic: function(italic) {
- return this.setFont({
- style: italic ? "italic" : "normal"
- });
- },
- setFont: function(font) {
- var node = this.node;
- [ "family", "size", "weight", "style" ].forEach(function(section) {
- if (font[section] === null) {
- node.removeAttribute("font-" + section);
- } else if (font[section]) {
- node.setAttribute("font-" + section, font[section]);
- }
- });
- return this;
- },
- getExtentOfChar: function(index) {
- return this.node.getExtentOfChar(index);
- },
- getRotationOfChar: function(index) {
- return this.node.getRotationOfChar(index);
- },
- getCharNumAtPosition: function(x, y) {
- return this.node.getCharNumAtPosition(this.node.viewportElement.createSVGPoint(x, y));
- }
- });
- }
- };
- //src/graphic/textspan.js
- _p[71] = {
- value: function(require, exports, module) {
- var TextContent = _p.r(70);
- var Styled = _p.r(66);
- return _p.r(11).createClass("TextSpan", {
- base: TextContent,
- mixins: [ Styled ],
- constructor: function(content) {
- this.callBase("tspan");
- this.setContent(content);
- }
- });
- }
- };
- //src/graphic/use.js
- /*
- * USE 功能
- */
- _p[72] = {
- value: function(require, exports, module) {
- var Svg = _p.r(67);
- var Class = _p.r(11);
- var Use = Class.createClass("Use", {
- base: _p.r(60),
- constructor: function(shape) {
- this.callBase("use");
- this.ref(shape);
- },
- ref: function(shape) {
- if (!shape) {
- this.node.removeAttributeNS(Svg.xlink, "xlink:href");
- return this;
- }
- var shapeId = shape.getId();
- if (shapeId) {
- this.node.setAttributeNS(Svg.xlink, "xlink:href", "#" + shapeId);
- }
- // by techird
- // 作为 Use 的图形,如果没有 fill 和 stroke,移除默认的 'none' 值,用于 Use 覆盖
- if (shape.node.getAttribute("fill") === "none") {
- shape.node.removeAttribute("fill");
- }
- if (shape.node.getAttribute("stroke") === "none") {
- shape.node.removeAttribute("stroke");
- }
- return this;
- }
- });
- var Shape = _p.r(60);
- Class.extendClass(Shape, {
- // fast-use
- use: function() {
- return new Use(this);
- }
- });
- return Use;
- }
- };
- //src/graphic/vector.js
- _p[73] = {
- value: function(require, exports, module) {
- var Point = _p.r(50);
- var Matrix = _p.r(43);
- var Vector = _p.r(11).createClass("Vector", {
- base: Point,
- constructor: function(x, y) {
- this.callBase(x, y);
- },
- square: function() {
- return this.x * this.x + this.y * this.y;
- },
- length: function() {
- return Math.sqrt(this.square());
- },
- add: function(q) {
- return new Vector(this.x + q.x, this.y + q.y);
- },
- minus: function(q) {
- return new Vector(this.x - q.x, this.y - q.y);
- },
- dot: function(q) {
- return this.x * q.x + this.y * q.y;
- },
- project: function(q) {
- return q.multipy(this.dot(q) / q.square());
- },
- normalize: function(length) {
- if (length === undefined) {
- length = 1;
- }
- return this.multipy(length / this.length());
- },
- multipy: function(scale) {
- return new Vector(this.x * scale, this.y * scale);
- },
- rotate: function(angle, unit) {
- if (unit == "rad") {
- angle = angle / Math.PI * 180;
- }
- var p = new Matrix().rotate(angle).transformPoint(this);
- return new Vector(p.x, p.y);
- },
- vertical: function() {
- return new Vector(this.y, -this.x);
- },
- reverse: function() {
- return this.multipy(-1);
- },
- getAngle: function() {
- var length = this.length();
- if (length === 0) return 0;
- var rad = Math.acos(this.x / length);
- var sign = this.y > 0 ? 1 : -1;
- return sign * 180 * rad / Math.PI;
- }
- });
- Vector.fromPoints = function(p1, p2) {
- return new Vector(p2.x - p1.x, p2.y - p1.y);
- };
- Vector.fromPolar = function() {
- var p = Point.fromPolar.apply(Point, arguments);
- return new Vector(p.x, p.y);
- };
- _p.r(11).extendClass(Point, {
- asVector: function() {
- return new Vector(this.x, this.y);
- }
- });
- return Vector;
- }
- };
- //src/graphic/view.js
- _p[74] = {
- value: function(require, exports, module) {
- var ShapeContainer = _p.r(61);
- var ViewBox = _p.r(75);
- return _p.r(11).createClass("View", {
- mixins: [ ShapeContainer, ViewBox ],
- base: _p.r(74),
- constructor: function() {
- this.callBase("view");
- }
- });
- }
- };
- //src/graphic/viewbox.js
- _p[75] = {
- value: function(require, exports, module) {
- return _p.r(11).createClass("ViewBox", {
- getViewBox: function() {
- var attr = this.node.getAttribute("viewBox");
- if (attr === null) {
- // firefox:
- // 1. viewBox 没有设置过的时候获得的是 null
- // 2. svg 标签没有指定绝对大小的时候 clientWidth 和 clientHeigt 为 0,需要在父容器上查找
- // TODO: 第 2 条取得的不准确(假如有 padding 之类的)
- return {
- x: 0,
- y: 0,
- width: this.node.clientWidth || this.node.parentNode.clientWidth,
- height: this.node.clientHeight || this.node.parentNode.clientHeight
- };
- } else {
- attr = attr.split(" ");
- return {
- x: +attr[0],
- y: +attr[1],
- width: +attr[2],
- height: +attr[3]
- };
- }
- },
- setViewBox: function(x, y, width, height) {
- this.node.setAttribute("viewBox", [ x, y, width, height ].join(" "));
- return this;
- }
- });
- }
- };
- //src/kity.js
- /**
- * @fileOverview kity 暴露的方法或对象
- */
- _p[76] = {
- value: function(require, exports, module) {
- var kity = {}, utils = _p.r(12);
- kity.version = "2.0.0";
- utils.extend(kity, {
- // core
- createClass: _p.r(11).createClass,
- extendClass: _p.r(11).extendClass,
- Utils: utils,
- Browser: _p.r(10),
- // shape
- Box: _p.r(25),
- Bezier: _p.r(23),
- BezierPoint: _p.r(24),
- Circle: _p.r(26),
- Clip: _p.r(27),
- Color: _p.r(28),
- Container: _p.r(29),
- Curve: _p.r(30),
- Ellipse: _p.r(32),
- Group: _p.r(36),
- Gradient: _p.r(35),
- HyperLink: _p.r(37),
- Image: _p.r(38),
- Line: _p.r(39),
- LinearGradient: _p.r(40),
- Mask: _p.r(42),
- Matrix: _p.r(43),
- Marker: _p.r(41),
- Palette: _p.r(44),
- Paper: _p.r(45),
- Path: _p.r(46),
- Pattern: _p.r(47),
- Pen: _p.r(48),
- Point: _p.r(50),
- PointContainer: _p.r(51),
- Polygon: _p.r(53),
- Polyline: _p.r(54),
- Pie: _p.r(49),
- RadialGradient: _p.r(55),
- Resource: _p.r(58),
- Rect: _p.r(56),
- RegularPolygon: _p.r(57),
- Ring: _p.r(59),
- Shape: _p.r(60),
- ShapePoint: _p.r(63),
- ShapeContainer: _p.r(61),
- Sweep: _p.r(68),
- Star: _p.r(65),
- Text: _p.r(69),
- TextSpan: _p.r(71),
- Use: _p.r(72),
- Vector: _p.r(73),
- g: _p.r(34),
- // animate
- Animator: _p.r(0),
- Easing: _p.r(1),
- OpacityAnimator: _p.r(4),
- RotateAnimator: _p.r(6),
- ScaleAnimator: _p.r(7),
- Timeline: _p.r(8),
- TranslateAnimator: _p.r(9),
- PathAnimator: _p.r(5),
- MotionAnimator: _p.r(3),
- requestFrame: _p.r(2).requestFrame,
- releaseFrame: _p.r(2).releaseFrame,
- // filter
- Filter: _p.r(20),
- GaussianblurFilter: _p.r(21),
- ProjectionFilter: _p.r(22),
- // effect
- ColorMatrixEffect: _p.r(13),
- CompositeEffect: _p.r(14),
- ConvolveMatrixEffect: _p.r(15),
- Effect: _p.r(16),
- GaussianblurEffect: _p.r(17),
- OffsetEffect: _p.r(18)
- });
- return window.kity = kity;
- }
- };
- var moduleMapping = {
- kity: 76
- };
- function use(name) {
- _p.r([ moduleMapping[name] ]);
- }
- /* global use, inc: true */
- /**
- * 模块暴露
- */
- use('kity');
- })();
- var KityMinder = window.KM = window.KityMinder = function() {
- var instanceMap = {},
- instanceId = 0,
- uuidMap = {};
- return {
- version: '1.3.5',
- uuid: function(name) {
- name = name || 'unknown';
- uuidMap[name] = uuidMap[name] || 0;
- ++uuidMap[name];
- return name + '_' + uuidMap[name];
- },
- createMinder: function(renderTarget, options) {
- options = options || {};
- options.renderTo = Utils.isString(renderTarget) ? document.getElementById(renderTarget) : renderTarget;
- var minder = new Minder(options);
- this.addMinder(options.renderTo, minder);
- return minder;
- },
- addMinder: function(target, minder) {
- var id;
- if (typeof(target) === 'string') {
- id = target;
- } else {
- id = target.id || ("KM_INSTANCE_" + instanceId++);
- }
- instanceMap[id] = minder;
- },
- getMinder: function(target, options) {
- var id;
- if (typeof(target) === 'string') {
- id = target;
- } else {
- id = target.id || ("KM_INSTANCE_" + instanceId++);
- }
- return instanceMap[id] || this.createMinder(target, options);
- },
- //挂接多语言
- LANG: {}
- };
- }();
- var utils = Utils = KityMinder.Utils = {
- extend: kity.Utils.extend.bind(kity.Utils),
- listen: function(element, type, handler) {
- var types = utils.isArray(type) ? type : utils.trim(type).split(/\s+/),
- k = types.length;
- if (k)
- while (k--) {
- type = types[k];
- if (element.addEventListener) {
- element.addEventListener(type, handler, false);
- } else {
- if (!handler._d) {
- handler._d = {
- els: []
- };
- }
- var key = type + handler.toString(),
- index = utils.indexOf(handler._d.els, element);
- if (!handler._d[key] || index == -1) {
- if (index == -1) {
- handler._d.els.push(element);
- }
- if (!handler._d[key]) {
- handler._d[key] = function(evt) {
- return handler.call(evt.srcElement, evt || window.event);
- };
- }
- element.attachEvent('on' + type, handler._d[key]);
- }
- }
- }
- element = null;
- },
- trim: function(str) {
- return str.replace(/(^[ \t\n\r]+)|([ \t\n\r]+$)/g, '');
- },
- each: function(obj, iterator, context) {
- if (obj == null) return;
- if (obj.length === +obj.length) {
- for (var i = 0, l = obj.length; i < l; i++) {
- if (iterator.call(context, i, obj[i], obj) === false)
- return false;
- }
- } else {
- for (var key in obj) {
- if (obj.hasOwnProperty(key)) {
- if (iterator.call(context, key, obj[key], obj) === false)
- return false;
- }
- }
- }
- },
- addCssRule: function(key, style, doc) {
- var head, node;
- if (style === undefined || style && style.nodeType && style.nodeType == 9) {
- //获取样式
- doc = style && style.nodeType && style.nodeType == 9 ? style : (doc || document);
- node = doc.getElementById(key);
- return node ? node.innerHTML : undefined;
- }
- doc = doc || document;
- node = doc.getElementById(key);
- //清除样式
- if (style === '') {
- if (node) {
- node.parentNode.removeChild(node);
- return true
- }
- return false;
- }
- //添加样式
- if (node) {
- node.innerHTML = style;
- } else {
- node = doc.createElement('style');
- node.id = key;
- node.innerHTML = style;
- doc.getElementsByTagName('head')[0].appendChild(node);
- }
- },
- keys: function(plain) {
- var keys = [];
- for (var key in plain) {
- if (plain.hasOwnProperty(key)) {
- keys.push(key);
- }
- }
- return keys;
- },
- proxy: function(fn, context) {
- return function() {
- return fn.apply(context, arguments);
- };
- },
- indexOf: function(array, item, start) {
- var index = -1;
- start = this.isNumber(start) ? start : 0;
- this.each(array, function(v, i) {
- if (i >= start && v === item) {
- index = i;
- return false;
- }
- });
- return index;
- },
- argsToArray: function(args, index) {
- return Array.prototype.slice.call(args, index || 0);
- },
- clonePlainObject: function(source, target) {
- var tmp;
- target = target || {};
- for (var i in source) {
- if (source.hasOwnProperty(i)) {
- tmp = source[i];
- if (utils.isObject(tmp) || utils.isArray(tmp)) {
- target[i] = utils.isArray(tmp) ? [] : {};
- utils.clonePlainObject(source[i], target[i])
- } else {
- target[i] = tmp;
- }
- }
- }
- return target;
- },
- compareObject: function(source, target) {
- var tmp;
- if (this.isEmptyObject(source) !== this.isEmptyObject(target)) {
- return false
- }
- if (this.getObjectLength(source) != this.getObjectLength(target)) {
- return false;
- }
- for (var p in source) {
- if (source.hasOwnProperty(p)) {
- tmp = source[p];
- if (target[p] === undefined) {
- return false;
- }
- if (this.isObject(tmp) || this.isArray(tmp)) {
- if (this.isObject(target[p]) !== this.isObject(tmp)) {
- return false;
- }
- if (this.isArray(tmp) !== this.isArray(target[p])) {
- return false;
- }
- if (this.compareObject(tmp, target[p]) === false) {
- return false
- }
- } else {
- if (tmp != target[p]) {
- return false
- }
- }
- }
- }
- return true;
- },
- getObjectLength: function(obj) {
- if (this.isArray(obj) || this.isString(obj)) return obj.length;
- var count = 0;
- for (var key in obj)
- if (obj.hasOwnProperty(key)) count++;
- return count;
- },
- isEmptyObject: function(obj) {
- if (obj == null) return true;
- if (this.isArray(obj) || this.isString(obj)) return obj.length === 0;
- for (var key in obj)
- if (obj.hasOwnProperty(key)) return false;
- return true;
- },
- loadFile: function() {
- var tmpList = [];
- function getItem(doc, obj) {
- try {
- for (var i = 0, ci; ci = tmpList[i++];) {
- if (ci.doc === doc && ci.url == (obj.src || obj.href)) {
- return ci;
- }
- }
- } catch (e) {
- return null;
- }
- }
- return function(doc, obj, fn) {
- var item = getItem(doc, obj);
- if (item) {
- if (item.ready) {
- fn && fn();
- } else {
- item.funs.push(fn)
- }
- return;
- }
- tmpList.push({
- doc: doc,
- url: obj.src || obj.href,
- funs: [fn]
- });
- if (!doc.body) {
- var html = [];
- for (var p in obj) {
- if (p == 'tag') continue;
- html.push(p + '="' + obj[p] + '"')
- }
- doc.write('<' + obj.tag + ' ' + html.join(' ') + ' ></' + obj.tag + '>');
- return;
- }
- if (obj.id && doc.getElementById(obj.id)) {
- return;
- }
- var element = doc.createElement(obj.tag);
- delete obj.tag;
- for (var p in obj) {
- element.setAttribute(p, obj[p]);
- }
- element.onload = element.onreadystatechange = function() {
- if (!this.readyState || /loaded|complete/.test(this.readyState)) {
- item = getItem(doc, obj);
- if (item.funs.length > 0) {
- item.ready = 1;
- for (var fi; fi = item.funs.pop();) {
- fi();
- }
- }
- element.onload = element.onreadystatechange = null;
- }
- };
- // element.onerror = function () {
- // throw Error('The load ' + (obj.href || obj.src) + ' fails,check the url settings of file ')
- // };
- doc.getElementsByTagName("head")[0].appendChild(element);
- }
- }(),
- clone: function(source, target) {
- var tmp;
- target = target || {};
- for (var i in source) {
- if (source.hasOwnProperty(i)) {
- tmp = source[i];
- if (typeof tmp == 'object') {
- target[i] = utils.isArray(tmp) ? [] : {};
- utils.clone(source[i], target[i])
- } else {
- target[i] = tmp;
- }
- }
- }
- return target;
- },
- unhtml: function(str, reg) {
- return str ? str.replace(reg || /[&<">'](?:(amp|lt|quot|gt|#39|nbsp);)?/g, function(a, b) {
- if (b) {
- return a;
- } else {
- return {
- '<': '<',
- '&': '&',
- '"': '"',
- '>': '>',
- "'": '''
- }[a]
- }
- }) : '';
- },
- cloneArr:function(arr){
- return [].concat(arr);
- },
- clearWhitespace:function(str){
- return str.replace(/[\u200b\t\r\n]/g, '');
- },
- getValueByIndex:function(data,index){
- var initIndex = 0,result = 0;
- utils.each(data,function(i,arr){
- if(initIndex + arr.length >= index){
- if(index - initIndex == arr.length){
- if(arr.length == 1 && arr[0].width === 0){
- initIndex++;
- return;
- }
- result = {
- x: arr[arr.length - 1].x + arr[arr.length - 1].width,
- y: arr[arr.length - 1].y
- };
- }else{
- result = arr[index - initIndex];
- }
- return false;
- }else{
- initIndex += arr.length + (arr.length == 1 && arr[0].width === 0 ? 0 : 1);
- }
- });
- return result;
- },
- getNodeIndex:function (node, ignoreTextNode) {
- var preNode = node,
- i = 0;
- while (preNode = preNode.previousSibling) {
- if (ignoreTextNode && preNode.nodeType == 3) {
- if(preNode.nodeType != preNode.nextSibling.nodeType ){
- i++;
- }
- continue;
- }
- i++;
- }
- return i;
- }
- };
- Utils.each(['String', 'Function', 'Array', 'Number', 'RegExp', 'Object'], function(i, v) {
- KityMinder.Utils['is' + v] = function(obj) {
- return Object.prototype.toString.apply(obj) == '[object ' + v + ']';
- }
- });
- /**
- * 提供浏览器检测的模块
- * @unfile
- * @module KM.browser
- */
- var browser = KityMinder.browser = function(){
- var agent = navigator.userAgent.toLowerCase(),
- opera = window.opera,
- browser = {
- /**
- * @property {boolean} ie 检测当前浏览器是否为IE
- * @example
- * ```javascript
- * if ( UE.browser.ie ) {
- * console.log( '当前浏览器是IE' );
- * }
- * ```
- */
- ie : /(msie\s|trident.*rv:)([\w.]+)/.test(agent),
- /**
- * @property {boolean} opera 检测当前浏览器是否为Opera
- * @example
- * ```javascript
- * if ( UE.browser.opera ) {
- * console.log( '当前浏览器是Opera' );
- * }
- * ```
- */
- opera : ( !!opera && opera.version ),
- /**
- * @property {boolean} webkit 检测当前浏览器是否是webkit内核的浏览器
- * @example
- * ```javascript
- * if ( UE.browser.webkit ) {
- * console.log( '当前浏览器是webkit内核浏览器' );
- * }
- * ```
- */
- webkit : ( agent.indexOf( ' applewebkit/' ) > -1 ),
- /**
- * @property {boolean} mac 检测当前浏览器是否是运行在mac平台下
- * @example
- * ```javascript
- * if ( UE.browser.mac ) {
- * console.log( '当前浏览器运行在mac平台下' );
- * }
- * ```
- */
- mac : ( agent.indexOf( 'macintosh' ) > -1 ),
- /**
- * @property {boolean} quirks 检测当前浏览器是否处于“怪异模式”下
- * @example
- * ```javascript
- * if ( UE.browser.quirks ) {
- * console.log( '当前浏览器运行处于“怪异模式”' );
- * }
- * ```
- */
- quirks : ( document.compatMode == 'BackCompat' ),
- ipad : ( agent.indexOf( 'ipad' ) > -1 )
- };
- /**
- * @property {boolean} gecko 检测当前浏览器内核是否是gecko内核
- * @example
- * ```javascript
- * if ( UE.browser.gecko ) {
- * console.log( '当前浏览器内核是gecko内核' );
- * }
- * ```
- */
- browser.gecko =( navigator.product == 'Gecko' && !browser.webkit && !browser.opera && !browser.ie);
- var version = 0;
- // Internet Explorer 6.0+
- if ( browser.ie ){
- var v1 = agent.match(/(?:msie\s([\w.]+))/);
- var v2 = agent.match(/(?:trident.*rv:([\w.]+))/);
- if(v1 && v2 && v1[1] && v2[1]){
- version = Math.max(v1[1]*1,v2[1]*1);
- }else if(v1 && v1[1]){
- version = v1[1]*1;
- }else if(v2 && v2[1]){
- version = v2[1]*1;
- }else{
- version = 0;
- }
- browser.ie11Compat = document.documentMode == 11;
- /**
- * @property { boolean } ie9Compat 检测浏览器模式是否为 IE9 兼容模式
- * @warning 如果浏览器不是IE, 则该值为undefined
- * @example
- * ```javascript
- * if ( UE.browser.ie9Compat ) {
- * console.log( '当前浏览器运行在IE9兼容模式下' );
- * }
- * ```
- */
- browser.ie9Compat = document.documentMode == 9;
- /**
- * @property { boolean } ie8 检测浏览器是否是IE8浏览器
- * @warning 如果浏览器不是IE, 则该值为undefined
- * @example
- * ```javascript
- * if ( UE.browser.ie8 ) {
- * console.log( '当前浏览器是IE8浏览器' );
- * }
- * ```
- */
- browser.ie8 = !!document.documentMode;
- /**
- * @property { boolean } ie8Compat 检测浏览器模式是否为 IE8 兼容模式
- * @warning 如果浏览器不是IE, 则该值为undefined
- * @example
- * ```javascript
- * if ( UE.browser.ie8Compat ) {
- * console.log( '当前浏览器运行在IE8兼容模式下' );
- * }
- * ```
- */
- browser.ie8Compat = document.documentMode == 8;
- /**
- * @property { boolean } ie7Compat 检测浏览器模式是否为 IE7 兼容模式
- * @warning 如果浏览器不是IE, 则该值为undefined
- * @example
- * ```javascript
- * if ( UE.browser.ie7Compat ) {
- * console.log( '当前浏览器运行在IE7兼容模式下' );
- * }
- * ```
- */
- browser.ie7Compat = ( ( version == 7 && !document.documentMode )
- || document.documentMode == 7 );
- /**
- * @property { boolean } ie6Compat 检测浏览器模式是否为 IE6 模式 或者怪异模式
- * @warning 如果浏览器不是IE, 则该值为undefined
- * @example
- * ```javascript
- * if ( UE.browser.ie6Compat ) {
- * console.log( '当前浏览器运行在IE6模式或者怪异模式下' );
- * }
- * ```
- */
- browser.ie6Compat = ( version < 7 || browser.quirks );
- browser.ie9above = version > 8;
- browser.ie9below = version < 9;
- }
- // Gecko.
- if ( browser.gecko ){
- var geckoRelease = agent.match( /rv:([\d\.]+)/ );
- if ( geckoRelease )
- {
- geckoRelease = geckoRelease[1].split( '.' );
- version = geckoRelease[0] * 10000 + ( geckoRelease[1] || 0 ) * 100 + ( geckoRelease[2] || 0 ) * 1;
- }
- }
- /**
- * @property { Number } chrome 检测当前浏览器是否为Chrome, 如果是,则返回Chrome的大版本号
- * @warning 如果浏览器不是chrome, 则该值为undefined
- * @example
- * ```javascript
- * if ( UE.browser.chrome ) {
- * console.log( '当前浏览器是Chrome' );
- * }
- * ```
- */
- if (/chrome\/(\d+\.\d)/i.test(agent)) {
- browser.chrome = + RegExp['\x241'];
- }
- /**
- * @property { Number } safari 检测当前浏览器是否为Safari, 如果是,则返回Safari的大版本号
- * @warning 如果浏览器不是safari, 则该值为undefined
- * @example
- * ```javascript
- * if ( UE.browser.safari ) {
- * console.log( '当前浏览器是Safari' );
- * }
- * ```
- */
- if(/(\d+\.\d)?(?:\.\d)?\s+safari\/?(\d+\.\d+)?/i.test(agent) && !/chrome/i.test(agent)){
- browser.safari = + (RegExp['\x241'] || RegExp['\x242']);
- }
- // Opera 9.50+
- if ( browser.opera )
- version = parseFloat( opera.version() );
- // WebKit 522+ (Safari 3+)
- if ( browser.webkit )
- version = parseFloat( agent.match( / applewebkit\/(\d+)/ )[1] );
- /**
- * @property { Number } version 检测当前浏览器版本号
- * @remind
- * <ul>
- * <li>IE系列返回值为5,6,7,8,9,10等</li>
- * <li>gecko系列会返回10900,158900等</li>
- * <li>webkit系列会返回其build号 (如 522等)</li>
- * </ul>
- * @example
- * ```javascript
- * console.log( '当前浏览器版本号是: ' + UE.browser.version );
- * ```
- */
- browser.version = version;
- /**
- * @property { boolean } isCompatible 检测当前浏览器是否能够与UEditor良好兼容
- * @example
- * ```javascript
- * if ( UE.browser.isCompatible ) {
- * console.log( '浏览器与UEditor能够良好兼容' );
- * }
- * ```
- */
- browser.isCompatible =
- !browser.mobile && (
- ( browser.ie && version >= 6 ) ||
- ( browser.gecko && version >= 10801 ) ||
- ( browser.opera && version >= 9.5 ) ||
- ( browser.air && version >= 1 ) ||
- ( browser.webkit && version >= 522 ) ||
- false );
- return browser;
- }();
- //快捷方式
- var ie = browser.ie,
- webkit = browser.webkit,
- gecko = browser.gecko,
- opera = browser.opera;
- /* jshint -W079 */
- var Minder = KityMinder.Minder = kity.createClass('KityMinder', {
- constructor: function(options) {
- this._options = Utils.extend(window.KITYMINDER_CONFIG || {}, options);
- var initQueue = Minder._initFnQueue.slice();
- // @see option.js
- // @see event.js
- // @see status.js
- // @see paper.js
- // @see select.js
- // @see key.js
- // @see contextmenu.js
- // @see module.js
- // @see data.js
- // @see readonly.js
- // @see layout.js
- // @see theme.js
- while (initQueue.length) initQueue.shift().call(this, options);
-
- this.fire('ready');
- }
- });
- /* jshint +W079 */
- Minder._initFnQueue = [];
- Minder.registerInit = function(fn) {
- Minder._initFnQueue.push(fn);
- };
- var Command = kity.createClass( "Command", {
- constructor: function () {
- this._isContentChange = true;
- this._isSelectionChange = false;
- },
- execute: function ( minder, args ) {
- },
- setContentChanged: function ( val ) {
- this._isContentChange = !! val;
- },
- isContentChanged: function () {
- return this._isContentChange;
- },
- setSelectionChanged: function ( val ) {
- this._isSelectionChange = !! val;
- },
- isSelectionChanged: function () {
- return this._isContentChange;
- },
- queryState: function ( km ) {
- return 0;
- },
- queryValue: function ( km ) {
- return 0;
- },
- isNeedUndo: function () {
- return true;
- }
- } );
- kity.extendClass(Minder, {
- _getCommand: function (name) {
- return this._commands[name.toLowerCase()];
- },
- _queryCommand: function (name, type, args) {
- var cmd = this._getCommand(name);
- if (cmd) {
- var queryCmd = cmd['query' + type];
- if (queryCmd)
- return queryCmd.apply(cmd, [this].concat(args));
- }
- return 0;
- },
- queryCommandState: function (name) {
- return this._queryCommand(name, "State", Utils.argsToArray(1));
- },
- queryCommandValue: function (name) {
- return this._queryCommand(name, "Value", Utils.argsToArray(1));
- },
- execCommand: function (name) {
- name = name.toLowerCase();
- var cmdArgs = Utils.argsToArray(arguments, 1),
- cmd, stoped, result, eventParams;
- var me = this;
- cmd = this._getCommand(name);
- eventParams = {
- command: cmd,
- commandName: name.toLowerCase(),
- commandArgs: cmdArgs
- };
- if (!cmd || !~this.queryCommandState(name)) {
- return false;
- }
- if (!this._hasEnterExecCommand && cmd.isNeedUndo()) {
- this._hasEnterExecCommand = true;
- stoped = this._fire(new MinderEvent('beforeExecCommand', eventParams, true));
- if (!stoped) {
- //保存场景
- this._fire(new MinderEvent('saveScene'));
- this._fire(new MinderEvent("preExecCommand", eventParams, false));
- result = cmd.execute.apply(cmd, [me].concat(cmdArgs));
- this._fire(new MinderEvent('execCommand', eventParams, false));
- //保存场景
- this._fire(new MinderEvent('saveScene'));
- if (cmd.isContentChanged()) {
- this._firePharse(new MinderEvent('contentchange'));
- }
- this._interactChange();
- }
- this._hasEnterExecCommand = false;
- } else {
- result = cmd.execute.apply(cmd, [me].concat(cmdArgs));
- if (!this._hasEnterExecCommand) {
- this._interactChange();
- }
- }
- return result === undefined ? null : result;
- }
- });
- /* jshint -W079 */
- var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
- /* jshint +W079 */
- /**
- * 创建一个节点
- *
- * @param {KityMinder} minder
- * 节点绑定的脑图的实例
- *
- * @param {String|Object} unknown
- * 节点的初始数据或文本
- */
- constructor: function(unknown) {
- this.parent = null;
- this.root = this;
- this.children = [];
- this.data = {};
- this.tmpData = {};
- this.initContainers();
- if (Utils.isString(unknown)) {
- this.setText(unknown);
- } else {
- this.setData(unknown);
- }
- },
- initContainers: function() {
- this.rc = new kity.Group().setId(KityMinder.uuid('minder_node'));
- this.rc.minderNode = this;
- },
- /**
- * 判断节点是否根节点
- */
- isRoot: function() {
- return this.root === this;
- },
- /**
- * 判断节点是否叶子
- */
- isLeaf: function() {
- return this.children.length === 0;
- },
- /**
- * 获取节点的根节点
- */
- getRoot: function() {
- return this.root || this;
- },
- /**
- * 获得节点的父节点
- */
- getParent: function() {
- return this.parent;
- },
- /**
- * 获得节点的深度
- */
- getLevel: function() {
- var level = 0,
- parent = this.parent;
- while (parent) {
- level++;
- parent = parent.parent;
- }
- return level;
- },
- /**
- * 获得节点的复杂度(即子树中节点的数量)
- */
- getComplex: function() {
- var complex = 0;
- this.traverse(function() {
- complex++;
- });
- return complex;
- },
- /**
- * 获得节点的类型(root|main|sub)
- */
- getType: function(type) {
- this.type = ['root', 'main', 'sub'][Math.min(this.getLevel(), 2)];
- return this.type;
- },
- /**
- * 判断当前节点是否被测试节点的祖先
- * @param {MinderNode} test 被测试的节点
- */
- isAncestorOf: function(test) {
- var p = test.parent;
- while (p) {
- if (p == this) return true;
- p = p.parent;
- }
- return false;
- },
- /**
- * 设置节点的文本数据
- * @param {String} text 文本数据
- */
- setText: function(text) {
- if(utils.isArray(text)){
- text = text.join('\n');
- }
- return this.setData('text', text);
- },
- /**
- * 获取节点的文本数据
- * @return {String}
- */
- getText: function(str2arr) {
- var text = this.getData('text') || '';
- if(str2arr){
- text = text.split('\n');
- }
- return text;
- },
- /**
- * 先序遍历当前节点树
- * @param {Function} fn 遍历函数
- */
- preTraverse: function(fn, excludeThis) {
- var children = this.getChildren();
- if (!excludeThis) fn(this);
- for (var i = 0; i < children.length; i++) {
- children[i].preTraverse(fn);
- }
- },
- /**
- * 后序遍历当前节点树
- * @param {Function} fn 遍历函数
- */
- postTraverse: function(fn, excludeThis) {
- var children = this.getChildren();
- for (var i = 0; i < children.length; i++) {
- children[i].postTraverse(fn);
- }
- if (!excludeThis) fn(this);
- },
- traverse: function(fn, excludeThis) {
- return this.postTraverse(fn, excludeThis);
- },
- getChildren: function() {
- return this.children;
- },
- getIndex: function() {
- return this.parent ? this.parent.children.indexOf(this) : -1;
- },
- insertChild: function(node, index) {
- if (index === undefined) {
- index = this.children.length;
- }
- if (node.parent) {
- node.parent.removeChild(node);
- }
- node.parent = this;
- node.root = this.root;
- this.children.splice(index, 0, node);
- },
- appendChild: function(node) {
- return this.insertChild(node);
- },
- prependChild: function(node) {
- return this.insertChild(node, 0);
- },
- removeChild: function(elem) {
- var index = elem,
- removed;
- if (elem instanceof MinderNode) {
- index = this.children.indexOf(elem);
- }
- if (index >= 0) {
- removed = this.children.splice(index, 1)[0];
- removed.parent = null;
- removed.root = removed;
- }
- },
- getChild: function(index) {
- return this.children[index];
- },
- getFirstChild: function() {
- return this.children[0];
- },
- getLastChild: function() {
- return this.children[this.children.length - 1];
- },
- getData: function(name) {
- if (name === undefined) {
- return this.data;
- }
- return this.data[name];
- },
- setData: function(name, value) {
- if (name === undefined) {
- this.data = {};
- } else if (utils.isObject(name)) {
- Utils.extend(this.data, name);
- } else {
- if (value === undefined) {
- this.data[name] = null;
- delete this.data[name];
- } else {
- this.data[name] = value;
- }
- }
- return this;
- },
- getRenderContainer: function() {
- return this.rc;
- },
- getCommonAncestor: function(node) {
- return Utils.getNodeCommonAncestor(this, node);
- },
- contains: function(node) {
- return this == node || this.isAncestorOf(node);
- },
- clone: function() {
- function cloneNode(parent, isClonedNode) {
- var cloned = new KM.MinderNode();
- cloned.data = Utils.clonePlainObject(isClonedNode.getData());
- cloned.tmpData = Utils.clonePlainObject(isClonedNode.getTmpData());
- if (parent) {
- parent.appendChild(cloned);
- }
- for (var i = 0, ci;
- (ci = isClonedNode.children[i++]);) {
- cloneNode(cloned, ci);
- }
- return cloned;
- }
- return cloneNode(null, this);
- },
- equals: function(node,ignoreSelected) {
- var me = this;
- function restoreSelected(){
- if(isSelectedA){
- me.setSelectedFlag();
- }
- if(isSelectedB){
- node.setSelectedFlag();
- }
- }
- if(ignoreSelected){
- var isSelectedA = false;
- var isSelectedB = false;
- if(me.isSelected()){
- isSelectedA = true;
- me.clearSelectedFlag();
- }
- if(node.isSelected()){
- isSelectedB = true;
- node.clearSelectedFlag();
- }
- }
- if (node.children.length != this.children.length) {
- restoreSelected();
- return false;
- }
- if (utils.compareObject(node.getData(), me.getData()) === false) {
- restoreSelected();
- return false;
- }
- if (utils.compareObject(node.getTmpData(), me.getTmpData()) === false) {
- restoreSelected();
- return false;
- }
- for (var i = 0, ci;
- (ci = me.children[i]); i++) {
- if (ci.equals(node.children[i],ignoreSelected) === false) {
- restoreSelected();
- return false;
- }
- }
- restoreSelected();
- return true;
- },
- clearChildren: function() {
- this.children = [];
- },
- setTmpData: function(a, v) {
- var me = this;
- if (utils.isObject(a)) {
- utils.each(a, function(key, val) {
- me.setTmpData(key, val);
- });
- }
- if (v === undefined || v === null || v === '') {
- delete this.tmpData[a];
- } else {
- this.tmpData[a] = v;
- }
- },
- getTmpData: function(a) {
- if (a === undefined) {
- return this.tmpData;
- }
- return this.tmpData[a];
- },
- setValue: function(node) {
- this.data = {};
- this.setData(utils.clonePlainObject(node.getData()));
- this.tmpData = {};
- this.setTmpData(utils.clonePlainObject(node.getTmpData()));
- return this;
- }
- });
- MinderNode.getCommonAncestor = function(nodeA, nodeB) {
- if (nodeA instanceof Array) {
- return MinderNode.getCommonAncestor.apply(this, nodeA);
- }
- switch (arguments.length) {
- case 1:
- return nodeA.parent || nodeA;
- case 2:
- if (nodeA.isAncestorOf(nodeB)) {
- return nodeA;
- }
- if (nodeB.isAncestorOf(nodeA)) {
- return nodeB;
- }
- var ancestor = nodeA.parent;
- while (ancestor && !ancestor.isAncestorOf(nodeB)) {
- ancestor = ancestor.parent;
- }
- return ancestor;
- default:
- return Array.prototype.reduce.call(arguments, function(prev, current) {
- return MinderNode.getCommonAncestor(prev, current);
- }, nodeA);
- }
- };
- kity.extendClass(Minder, {
- getRoot: function() {
- return this._root;
- },
- setRoot: function(root) {
- this._root = root;
- root.minder = this;
- },
- createNode: function(unknown, parent, index) {
- var node = new MinderNode(unknown);
- this.fire('nodecreate', { node: node, parent: parent, index: index });
- this.appendNode(node, parent, index);
- return node;
- },
- appendNode: function(node, parent, index) {
- if (parent) parent.insertChild(node, index);
- this.attachNode(node);
- return this;
- },
- removeNode: function(node) {
- if (node.parent) {
- node.parent.removeChild(node);
- this.detachNode(node);
- this.fire('noderemove', { node: node });
- }
- },
- attachNode: function(node) {
- var rc = this._rc;
- node.traverse(function(current) {
- current.attached = true;
- rc.addShape(current.getRenderContainer());
- });
- rc.addShape(node.getRenderContainer());
- this.fire('nodeattach', {
- node: node
- });
- },
- detachNode: function(node) {
- var rc = this._rc;
- node.traverse(function(current) {
- current.attached = false;
- rc.removeShape(current.getRenderContainer());
- });
- this.fire('nodedetach', {
- node: node
- });
- },
- getMinderTitle: function() {
- return this.getRoot().getText();
- }
- });
- kity.extendClass(MinderNode, {
- getMinder: function() {
- return this.getRoot().minder;
- }
- });
- /**
- * @fileOverview
- *
- * 提供脑图选项支持
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- kity.extendClass(Minder, {
- getOptions: function(key) {
- var val;
- if (key) {
- val = this.getPreferences(key);
- return val && val[key] || this._options[key];
- } else {
- val = this.getPreferences();
- return utils.extend(val, this._options, true);
- }
- },
- setDefaultOptions: function(key, val, cover) {
- var obj = {};
- if (Utils.isString(key)) {
- obj[key] = val;
- } else {
- obj = key;
- }
- utils.extend(this._options, obj, !cover);
- },
- setOptions: function(key, val) {
- this.setPreferences(key, val);
- }
- });
- Minder.registerInit(function(option) {
- this.setDefaultOptions(KM.defaultOptions);
- });
- var MinderEvent = kity.createClass('MindEvent', {
- constructor: function(type, params, canstop) {
- params = params || {};
- if (params.getType && params.getType() == 'ShapeEvent') {
- this.kityEvent = params;
- this.originEvent = params.originEvent;
- this.getPosition = params.getPosition.bind(params);
- } else if (params.target && params.preventDefault) {
- this.originEvent = params;
- } else {
- kity.Utils.extend(this, params);
- }
- this.type = type;
- this._canstop = canstop || false;
- },
- getTargetNode: function() {
- var findShape = this.kityEvent && this.kityEvent.targetShape;
- if (!findShape) return null;
- while (!findShape.minderNode && findShape.container) {
- findShape = findShape.container;
- }
- var node = findShape.minderNode;
- if (node && findShape.getOpacity() < 1) return null;
- return node || null;
- },
- stopPropagation: function() {
- this._stoped = true;
- },
- stopPropagationImmediately: function() {
- this._immediatelyStoped = true;
- this._stoped = true;
- },
- shouldStopPropagation: function() {
- return this._canstop && this._stoped;
- },
- shouldStopPropagationImmediately: function() {
- return this._canstop && this._immediatelyStoped;
- },
- preventDefault: function() {
- this.originEvent.preventDefault();
- },
- isRightMB: function() {
- var isRightMB = false;
- if (!this.originEvent) {
- return false;
- }
- if ("which" in this.originEvent)
- isRightMB = this.originEvent.which == 3;
- else if ("button" in this.originEvent)
- isRightMB = this.originEvent.button == 2;
- return isRightMB;
- },
- getKeyCode: function(){
- var evt = this.originEvent;
- return evt.keyCode || evt.which;
- }
- });
- Minder.registerInit(function() {
- this._initEvents();
- });
- // 事件机制
- kity.extendClass(Minder, {
- _initEvents: function() {
- this._eventCallbacks = {};
- },
- _bindEvents: function() {
- this._bindPaperEvents();
- this._bindKeyboardEvents();
- },
- _resetEvents: function() {
- this._initEvents();
- this._bindEvents();
- },
- // TODO: mousemove lazy bind
- _bindPaperEvents: function() {
- this._paper.on('click dblclick mousedown contextmenu mouseup mousemove mouseover mousewheel DOMMouseScroll touchstart touchmove touchend dragenter dragleave drop', this._firePharse.bind(this));
- if (window) {
- window.addEventListener('resize', this._firePharse.bind(this));
- window.addEventListener('blur', this._firePharse.bind(this));
- }
- },
- _bindKeyboardEvents: function() {
- if ((navigator.userAgent.indexOf('iPhone') == -1) && (navigator.userAgent.indexOf('iPod') == -1) && (navigator.userAgent.indexOf('iPad') == -1)) {
- //只能在这里做,要不无法触发
- Utils.listen(document.body, 'keydown keyup keypress paste', this._firePharse.bind(this));
- }
- },
- _firePharse: function(e) {
- // //只读模式下强了所有的事件操作
- // if(this.readOnly === true){
- // return false;
- // }
- var beforeEvent, preEvent, executeEvent;
- if (e.type == 'DOMMouseScroll') {
- e.type = 'mousewheel';
- e.wheelDelta = e.originEvent.wheelDelta = e.originEvent.detail * -10;
- e.wheelDeltaX = e.originEvent.mozMovementX;
- e.wheelDeltaY = e.originEvent.mozMovementY;
- }
- beforeEvent = new MinderEvent('before' + e.type, e, true);
- if (this._fire(beforeEvent)) {
- return;
- }
- preEvent = new MinderEvent('pre' + e.type, e, true);
- executeEvent = new MinderEvent(e.type, e, true);
- if (this._fire(preEvent) ||
- this._fire(executeEvent))
- this._fire(new MinderEvent('after' + e.type, e, false));
- },
- _interactChange: function(e) {
- var me = this;
- if (me._interactScheduled) return;
- setTimeout(function() {
- me._fire(new MinderEvent('interactchange'));
- me._interactScheduled = false;
- }, 100);
- me._interactScheduled = true;
- },
- _listen: function(type, callback) {
- var callbacks = this._eventCallbacks[type] || (this._eventCallbacks[type] = []);
- callbacks.push(callback);
- },
- _fire: function(e) {
- var status = this.getStatus();
- var callbacks = this._eventCallbacks[e.type.toLowerCase()] || [];
- if (status) {
- callbacks = callbacks.concat(this._eventCallbacks[status + '.' + e.type.toLowerCase()] || []);
- }
- if (callbacks.length === 0) {
- return;
- }
- var lastStatus = this.getStatus();
- for (var i = 0; i < callbacks.length; i++) {
- callbacks[i].call(this, e);
- /* this.getStatus() != lastStatus ||*/
- if (e.shouldStopPropagationImmediately()) {
- break;
- }
- }
- return e.shouldStopPropagation();
- },
- on: function(name, callback) {
- var km = this;
- utils.each(name.split(/\s+/), function(i, n) {
- km._listen(n.toLowerCase(), callback);
- });
- return this;
- },
- off: function(name, callback) {
- var types = name.split(/\s+/);
- var i, j, callbacks, removeIndex;
- for (i = 0; i < types.length; i++) {
- callbacks = this._eventCallbacks[types[i].toLowerCase()];
- if (callbacks) {
- removeIndex = null;
- for (j = 0; j < callbacks.length; j++) {
- if (callbacks[j] == callback) {
- removeIndex = j;
- }
- }
- if (removeIndex !== null) {
- callbacks.splice(removeIndex, 1);
- }
- }
- }
- },
- fire: function(type, params) {
- var e = new MinderEvent(type, params);
- this._fire(e);
- return this;
- }
- });
- /**
- * @fileOverview
- *
- * 状态切换控制
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- Minder.registerInit(function() {
- this._initStatus();
- });
- kity.extendClass(Minder, {
- _initStatus: function() {
- this._status = 'normal';
- this._rollbackStatus = 'normal';
- },
- setStatus: (function() {
- var sf = ~window.location.href.indexOf('status');
- var tf = ~window.location.href.indexOf('trace');
- // 在 readonly 模式下,只有 force 为 true 才能切换回来
- return function(status, force) {
- if (this._status == 'readonly' && !force) return this;
- if (status != this._status) {
- this._rollbackStatus = this._status;
- this._status = status;
- this.fire('statuschange', {
- lastStatus: this._rollbackStatus,
- currentStatus: this._status
- });
- if (sf) {
- console.log(window.event.type, this._rollbackStatus, '->', this._status);
- if (tf) {
- console.trace();
- }
- }
- }
- return this;
- };
- })(),
- rollbackStatus: function() {
- this.setStatus(this._rollbackStatus);
- },
- getRollbackStatus:function(){
- return this._rollbackStatus;
- },
- getStatus: function() {
- return this._status;
- }
- });
- /**
- * @fileOverview
- *
- * 初始化渲染容器
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- Minder.registerInit(function() {
- this._initPaper();
- });
- kity.extendClass(Minder, {
-
- _initPaper: function() {
- this._paper = new kity.Paper();
- this._paper.getNode().setAttribute('contenteditable', true);
- this._paper.getNode().ondragstart = function(e) {
- e.preventDefault();
- };
- this._paper.shapeNode.setAttribute('transform', 'translate(0.5, 0.5)');
- this._addRenderContainer();
- this.setRoot(this.createNode(this.getLang().maintopic));
- if (this._options.renderTo) {
- this.renderTo(this._options.renderTo);
- }
- },
- _addRenderContainer: function() {
- this._rc = new kity.Group().setId(KityMinder.uuid('minder'));
- this._paper.addShape(this._rc);
- },
- renderTo: function(target) {
- this._paper.renderTo(this._renderTarget = target);
- this._bindEvents();
- },
- getRenderContainer: function() {
- return this._rc;
- },
- getPaper: function() {
- return this._paper;
- },
- getRenderTarget: function() {
- return this._renderTarget;
- },
- });
- Minder.registerInit(function() {
- this._initSelection();
- });
- // 选区管理
- kity.extendClass(Minder, {
- _initSelection: function() {
- this._selectedNodes = [];
- },
- renderChangedSelection: function(last) {
- var current = this.getSelectedNodes();
- var changed = [];
- var i = 0;
- current.forEach(function(node) {
- if (last.indexOf(node) == -1) {
- changed.push(node);
- node.setTmpData('selected', true);
- }
- });
- last.forEach(function(node) {
- if (current.indexOf(node) == -1) {
- changed.push(node);
- node.setTmpData('selected', false);
- }
- });
- if (changed.length) {
- this._interactChange();
- this.fire('selectionchange');
- }
- while (i < changed.length) changed[i++].render();
- },
- getSelectedNodes: function() {
- //不能克隆返回,会对当前选区操作,从而影响querycommand
- return this._selectedNodes;
- },
- getSelectedNode: function() {
- return this.getSelectedNodes()[0] || null;
- },
- removeAllSelectedNodes: function() {
- var me = this;
- var last = this._selectedNodes.splice(0);
- this._selectedNodes = [];
- this.renderChangedSelection(last);
- return this.fire('selectionclear');
- },
- removeSelectedNodes: function(nodes) {
- var me = this;
- var last = this._selectedNodes.slice(0);
- nodes = Utils.isArray(nodes) ? nodes : [nodes];
- Utils.each(nodes, function(i, n) {
- var index;
- if ((index = me._selectedNodes.indexOf(n)) === -1) return;
- me._selectedNodes.splice(index, 1);
- });
- this.renderChangedSelection(last);
- return this;
- },
- select: function(nodes, isSingleSelect) {
- var lastSelect = this.getSelectedNodes().slice(0);
- if (isSingleSelect) {
- this._selectedNodes = [];
- }
- var me = this;
- nodes = Utils.isArray(nodes) ? nodes : [nodes];
- Utils.each(nodes, function(i, n) {
- if (me._selectedNodes.indexOf(n) !== -1) return;
- me._selectedNodes.push(n);
- });
- this.renderChangedSelection(lastSelect);
- return this;
- },
- //当前选区中的节点在给定的节点范围内的保留选中状态,
- //没在给定范围的取消选中,给定范围中的但没在当前选中范围的也做选中效果
- toggleSelect: function(node) {
- if (Utils.isArray(node)) {
- node.forEach(this.toggleSelect.bind(this));
- } else {
- if (node.isSelected()) this.removeSelectedNodes(node);
- else this.select(node);
- }
- return this;
- },
- isSingleSelect: function() {
- return this._selectedNodes.length == 1;
- },
- getSelectedAncestors: function(includeRoot) {
- var nodes = this.getSelectedNodes().slice(0),
- ancestors = [],
- judge;
- // 根节点不参与计算
- var rootIndex = nodes.indexOf(this.getRoot());
- if (~rootIndex && !includeRoot) {
- nodes.splice(rootIndex, 1);
- }
- // 判断 nodes 列表中是否存在 judge 的祖先
- function hasAncestor(nodes, judge) {
- for (var i = nodes.length - 1; i >= 0; --i) {
- if (nodes[i].isAncestorOf(judge)) return true;
- }
- return false;
- }
- // 按照拓扑排序
- nodes.sort(function(node1, node2) {
- return node1.getLevel() - node2.getLevel();
- });
- // 因为是拓扑有序的,所以只需往上查找
- while ((judge = nodes.pop())) {
- if (!hasAncestor(nodes, judge)) {
- ancestors.push(judge);
- }
- }
- return ancestors;
- }
- });
- kity.extendClass(MinderNode, {
- isSelected: function() {
- return this.getTmpData('selected');
- },
- clearSelectedFlag:function(){
- this.setTmpData('selected');
- },
- setSelectedFlag:function(){
- this.setTmpData('selected',true);
- }
- });
- /**
- * @fileOverview
- *
- * 添加快捷键支持
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- /**
- * 计算包含 meta 键的 keycode
- *
- * @param {String|KeyEvent} unknown
- */
- function getMetaKeyCode(unknown) {
- var CTRL_MASK = 0x1000;
- var ALT_MASK = 0x2000;
- var SHIFT_MASK = 0x4000;
- var metaKeyCode = 0;
- if (typeof(unknown) == 'string') {
- // unknown as string
- unknown.toLowerCase().split(/\+\s*/).forEach(function(name) {
- switch(name) {
- case 'ctrl':
- case 'cmd':
- metaKeyCode |= CTRL_MASK;
- break;
- case 'alt':
- metaKeyCode |= ALT_MASK;
- break;
- case 'shift':
- metaKeyCode |= SHIFT_MASK;
- break;
- default:
- metaKeyCode |= keymap[name];
- }
- });
- } else {
- // unknown as key event
- if (unknown.ctrlKey || unknown.metaKey) {
- metaKeyCode |= CTRL_MASK;
- }
- if (unknown.altKey) {
- metaKeyCode |= ALT_MASK;
- }
- if (unknown.shiftKey) {
- metaKeyCode |= SHIFT_MASK;
- }
- metaKeyCode |= unknown.keyCode;
- }
- return metaKeyCode;
- }
- kity.extendClass(MinderEvent, {
- isShortcutKey: function(keyCombine) {
- var keyEvent = this.originEvent;
- if (!keyEvent) return false;
- return getMetaKeyCode(keyCombine) == getMetaKeyCode(keyEvent);
- }
- });
- Minder.registerInit(function() {
- this._initShortcutKey();
- });
- kity.extendClass(Minder, {
- _initShortcutKey: function() {
- this._bindShortcutKeys();
- },
-
- _bindShortcutKeys: function() {
- var map = this._shortcutKeys = {};
- var has = 'hasOwnProperty';
- this.on('keydown', function(e) {
- for (var keys in map) {
- if (!map[has](keys)) continue;
- if (e.isShortcutKey(keys)) {
- var fn = map[keys];
- if (fn.__statusCondition && fn.__statusCondition != this.getStatus()) return;
- fn();
- e.preventDefault();
- }
- }
- });
- },
-
- addShortcut: function(keys, fn) {
- var binds = this._shortcutKeys;
- keys.split(/\|\s*/).forEach(function(combine) {
- var parts = combine.split('::');
- var status;
- if (parts.length > 1) {
- combine = parts[1];
- status = parts[0];
- fn.__statusCondition = status;
- }
- binds[combine] = fn;
- });
- },
- addCommandShortcutKeys: function(cmd, keys) {
- var binds = this._commandShortcutKeys || (this._commandShortcutKeys = {});
- var obj = {},
- km = this;
- if (keys) {
- obj[cmd] = keys;
- } else {
- obj = cmd;
- }
- var minder = this;
- utils.each(obj, function(command, keys) {
- binds[command] = keys;
- minder.addShortcut(keys, function execCommandByShortcut() {
- if (minder.queryCommandState(command) === 0) {
- minder.execCommand(command);
- }
- });
- });
- },
- getCommandShortcutKey: function(cmd) {
- var binds = this._commandShortcutKeys;
- return binds && binds[cmd] || null;
- }
- });
- /**
- * @fileOverview
- *
- * 添加模块上下文菜单支持
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- Minder.registerInit(function() {
- this._initContextMenu();
- });
- kity.extendClass(Minder, {
- _initContextMenu: function() {
- this.contextmenus = [];
- },
- addContextMenu: function(item) {
- if (utils.isArray(item)) {
- this.contextmenus = this.contextmenus.concat(item);
- } else {
- this.contextmenus.push(item);
- }
- return this;
- },
- getContextMenu: function() {
- return this.contextmenus;
- }
- });
- //模块注册&暴露模块接口
- ( function () {
- var _modules;
- KityMinder.registerModule = function ( name, module ) {
- //初始化模块列表
- if ( !_modules ) {
- _modules = {};
- }
- _modules[ name ] = module;
- };
- KityMinder.getModules = function () {
- return _modules;
- };
- } )();
- Minder.registerInit(function() {
- this._initModules();
- });
- // 模块声明周期维护
- kity.extendClass(Minder, {
- _initModules: function() {
- var modulesPool = KityMinder.getModules();
- var modulesToLoad = this._options.modules || Utils.keys(modulesPool);
- this._commands = {};
- this._query = {};
- this._modules = {};
- this._rendererClasses = {};
- var i, name, type, module, moduleDeals,
- dealCommands, dealEvents, dealRenderers;
- var me = this;
- for (i = 0; i < modulesToLoad.length; i++) {
- name = modulesToLoad[i];
- if (!modulesPool[name]) continue;
- // 执行模块初始化,抛出后续处理对象
- if (typeof(modulesPool[name]) == 'function') {
- moduleDeals = modulesPool[name].call(me);
- } else {
- moduleDeals = modulesPool[name];
- }
- this._modules[name] = moduleDeals;
- if (!moduleDeals) continue;
- if (moduleDeals.init) {
- moduleDeals.init.call(me, this._options);
- }
- // command加入命令池子
- dealCommands = moduleDeals.commands;
- for (name in dealCommands) {
- this._commands[name.toLowerCase()] = new dealCommands[name]();
- }
- // 绑定事件
- dealEvents = moduleDeals.events;
- if (dealEvents) {
- for (type in dealEvents) {
- me.on(type, dealEvents[type]);
- }
- }
- // 渲染器
- dealRenderers = moduleDeals.renderers;
- if (dealRenderers) {
- for (type in dealRenderers) {
- this._rendererClasses[type] = this._rendererClasses[type] || [];
- if (Utils.isArray(dealRenderers[type])) {
- this._rendererClasses[type] = this._rendererClasses[type].concat(dealRenderers[type]);
- } else {
- this._rendererClasses[type].push(dealRenderers[type]);
- }
- }
- }
- if (moduleDeals.defaultOptions) {
- this.setDefaultOptions(moduleDeals.defaultOptions);
- }
- //添加模块的快捷键
- if (moduleDeals.commandShortcutKeys) {
- this.addCommandShortcutKeys(moduleDeals.commandShortcutKeys);
- }
- //添加邮件菜单
- if (moduleDeals.contextmenu) {
- this.addContextMenu(moduleDeals.contextmenu);
- }
- }
- },
- _garbage: function() {
- this.clearSelect();
- while (this._root.getChildren().length) {
- this._root.removeChild(0);
- }
- },
- destroy: function() {
- var modules = this._modules;
- this._resetEvents();
- this._garbage();
- for (var key in modules) {
- if (!modules[key].destroy) continue;
- modules[key].destroy.call(this);
- }
- },
- reset: function() {
- var modules = this._modules;
- this._garbage();
- for (var key in modules) {
- if (!modules[key].reset) continue;
- modules[key].reset.call(this);
- }
- }
- });
- Utils.extend(KityMinder, {
- _protocols: {},
- registerProtocol: function(name, protocolDeal) {
- KityMinder._protocols[name] = protocolDeal;
- }
- });
- var DEFAULT_TEXT = {
- 'root': 'maintopic',
- 'main': 'topic',
- 'sub': 'topic'
- };
- Minder.registerInit(function() {
- this._initProtocols();
- });
- // 导入导出
- kity.extendClass(Minder, {
- _initProtocols: function(options) {
- var protocols = this._protocols = {};
- var pool = KityMinder._protocols;
- for (var name in pool) {
- if (pool.hasOwnProperty(name))
- protocols[name] = pool[name](this);
- protocols[name].name = name;
- }
- },
- getProtocol: function(name) {
- return this._protocols[name] || null;
- },
- getSupportedProtocols: function() {
- var protocols = this._protocols;
- return Utils.keys(protocols).map(function(name) {
- return protocols[name];
- });
- },
- exportJson: function() {
- /* 导出 node 上整棵树的数据为 JSON */
- function exportNode(node) {
- var exported = {};
- exported.data = node.getData();
- var childNodes = node.getChildren();
- if (childNodes.length) {
- exported.children = [];
- for (var i = 0; i < childNodes.length; i++) {
- exported.children.push(exportNode(childNodes[i]));
- }
- }
- return exported;
- }
- var json = exportNode(this.getRoot());
- json.template = this.getTemplate();
- json.theme = this.getTheme();
- json.version = KityMinder.version;
- return json;
- },
- importJson: function(json, params) {
- function importNode(node, json, km) {
- var data = json.data;
- node.data = {};
- for (var field in data) {
- node.setData(field, data[field]);
- }
- node.setData('text', data.text || km.getLang(DEFAULT_TEXT[node.getType()]));
- var childrenTreeData = json.children || [];
- for (var i = 0; i < childrenTreeData.length; i++) {
- var childNode = km.createNode(null, node);
- importNode(childNode, childrenTreeData[i], km);
- }
- return node;
- }
- if (!json) return;
-
- this._fire(new MinderEvent('preimport', params, false));
- // 删除当前所有节点
- while (this._root.getChildren().length) {
- this.removeNode(this._root.getChildren()[0]);
- }
- json = KityMinder.compatibility(json);
- importNode(this._root, json, this);
- this.setTemplate(json.template || 'default');
- this.setTheme(json.theme || null);
- this.refresh();
- this.fire('import', params);
- this._firePharse({
- type: 'contentchange'
- });
- this._interactChange();
- },
- exportData: function(protocolName, options) {
- var json, protocol;
- json = this.exportJson();
- // 指定了协议进行导出,需要检测协议是否支持
- if (protocolName) {
- protocol = this.getProtocol(protocolName);
- if (!protocol || !protocol.encode) {
- return Promise.reject(new Error('Not supported protocol:' + protocolName));
- }
- }
- // 导出前抛个事件
- this._fire(new MinderEvent('beforeexport', {
- json: json,
- protocolName: protocolName,
- protocol: protocol
- }));
- if (protocol) {
- return Promise.resolve(protocol.encode(json, this, options));
- } else {
- return Promise.resolve(json);
- }
- },
- importData: function(local, protocolName) {
- var json, protocol;
- var minder = this;
- // 指定了协议进行导入,需要检测协议是否支持
- if (protocolName) {
- protocol = this.getProtocol(protocolName);
- if (!protocol || !protocol.decode) {
- return Promise.reject(new Error('Not supported protocol:' + protocolName));
- }
- }
- var params = {
- local: local,
- protocolName: protocolName,
- protocol: protocol
- };
- // 导入前抛事件
- this._fire(new MinderEvent('beforeimport', params));
- return new Promise(function(resolve, reject) {
- resolve(protocol ? protocol.decode(local) : local);
- }).then(function(json) {
- minder.importJson(json, params);
- return json;
- });
- }
- });
- /**
- * @fileOverview
- *
- *
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- Minder.registerInit(function(options) {
- if (options.readOnly) {
- this.setDisabled();
- }
- });
- kity.extendClass(Minder, {
- disable: function() {
- var me = this;
- //禁用命令
- me.bkqueryCommandState = me.queryCommandState;
- me.bkqueryCommandValue = me.queryCommandValue;
- me.queryCommandState = function(type) {
- var cmd = this._getCommand(type);
- if (cmd && cmd.enableReadOnly) {
- return me.bkqueryCommandState.apply(me, arguments);
- }
- return -1;
- };
- me.queryCommandValue = function(type) {
- var cmd = this._getCommand(type);
- if (cmd && cmd.enableReadOnly) {
- return me.bkqueryCommandValue.apply(me, arguments);
- }
- return null;
- };
- this.setStatus('readonly');
- me._interactChange();
- },
- enable: function() {
- var me = this;
- if (me.bkqueryCommandState) {
- me.queryCommandState = me.bkqueryCommandState;
- delete me.bkqueryCommandState;
- }
- if (me.bkqueryCommandValue) {
- me.queryCommandValue = me.bkqueryCommandValue;
- delete me.bkqueryCommandValue;
- }
- this.setStatus('normal');
- me._interactChange();
- }
- });
- /**
- * 布局支持池子管理
- */
- Utils.extend(KityMinder, {
- _layout: {},
- registerLayout: function(name, layout) {
- KityMinder._layout[name] = layout;
- if (!KityMinder._defaultLayout) {
- KityMinder._defaultLayout = name;
- }
- },
- getLayoutList: function() {
- return this._layout;
- },
- getLayoutInstance: function(name) {
- var LayoutClass = KityMinder._layout[name];
- if (!LayoutClass) throw new Error('Missing Layout: ' + name);
- var layout = new LayoutClass();
- return layout;
- }
- });
- /**
- * MinderNode 上的布局支持
- */
- kity.extendClass(MinderNode, {
- /**
- * 获得当前节点的布局名称
- *
- * @return {String}
- */
- getLayout: function() {
- var layout = this.getData('layout');
- layout = layout || (this.isRoot() ? KityMinder._defaultLayout : this.parent.getLayout());
- return layout;
- },
- setLayout: function(name) {
- if (name) {
- if (name == 'inherit') {
- this.setData('layout');
- } else {
- this.setData('layout', name);
- }
- }
- return this;
- },
- layout: function(name, duration) {
- this.setLayout(name).getMinder().layout(duration);
- return this;
- },
- getLayoutInstance: function() {
- return KityMinder.getLayoutInstance(this.getLayout());
- },
- getOrderHint: function(refer) {
- return this.parent.getLayoutInstance().getOrderHint(this);
- },
- getExpandPosition: function() {
- return this.getLayoutInstance().getExpandPosition();
- },
- /**
- * 获取当前节点相对于父节点的布局变换
- */
- getLayoutTransform: function() {
- return this._layoutTransform || new kity.Matrix();
- },
- /**
- * 第一轮布局计算后,获得的全局布局位置
- *
- * @return {[type]} [description]
- */
- getGlobalLayoutTransformPreview: function() {
- var pMatrix = this.parent ? this.parent.getLayoutTransform() : new kity.Matrix();
- var matrix = this.getLayoutTransform();
- var offset = this.getLayoutOffset();
- if (offset) {
- matrix.translate(offset.x, offset.y);
- }
- return pMatrix.merge(matrix);
- },
- getLayoutPointPreview: function() {
- return this.getGlobalLayoutTransformPreview().transformPoint(new kity.Point());
- },
- /**
- * 获取节点相对于全局的布局变换
- */
- getGlobalLayoutTransform: function() {
- if (this._globalLayoutTransform) {
- return this._globalLayoutTransform;
- } else if (this.parent) {
- return this.parent.getGlobalLayoutTransform();
- } else {
- return new kity.Matrix();
- }
- },
- /**
- * 设置当前节点相对于父节点的布局变换
- */
- setLayoutTransform: function(matrix) {
- this._layoutTransform = matrix;
- return this;
- },
- /**
- * 设置当前节点相对于全局的布局变换(冗余优化)
- */
- setGlobalLayoutTransform: function(matrix) {
- this.getRenderContainer().setMatrix(this._globalLayoutTransform = matrix);
- return this;
- },
- setVertexIn: function(p) {
- this._vertexIn = p;
- },
- setVertexOut: function(p) {
- this._vertexOut = p;
- },
- getVertexIn: function() {
- return this._vertexIn || new kity.Point();
- },
- getVertexOut: function() {
- return this._vertexOut || new kity.Point();
- },
- getLayoutVertexIn: function() {
- return this.getGlobalLayoutTransform().transformPoint(this.getVertexIn());
- },
- getLayoutVertexOut: function() {
- return this.getGlobalLayoutTransform().transformPoint(this.getVertexOut());
- },
- setLayoutVectorIn: function(v) {
- this._layoutVectorIn = v;
- return this;
- },
- setLayoutVectorOut: function(v) {
- this._layoutVectorOut = v;
- return this;
- },
- getLayoutVectorIn: function() {
- return this._layoutVectorIn || new kity.Vector();
- },
- getLayoutVectorOut: function() {
- return this._layoutVectorOut || new kity.Vector();
- },
- getLayoutBox: function() {
- var matrix = this.getGlobalLayoutTransform();
- return matrix.transformBox(this.getContentBox());
- },
- getLayoutPoint: function() {
- var matrix = this.getGlobalLayoutTransform();
- return matrix.transformPoint(new kity.Point());
- },
- getLayoutOffset: function() {
- if (!this.parent) return new kity.Point();
- // 影响当前节点位置的是父节点的布局
- var data = this.getData('layout_' + this.parent.getLayout() + '_offset');
- if (data) return new kity.Point(data.x, data.y);
- return new kity.Point();
- },
- setLayoutOffset: function(p) {
- if (!this.parent) return this;
- if (p && !this.hasLayoutOffset()) {
- var m = this.getLayoutTransform().m;
- p = p.offset(m.e, m.f);
- this.setLayoutTransform(null);
- }
- this.setData('layout_' + this.parent.getLayout() + '_offset', p ? {
- x: p.x,
- y: p.y
- } : null);
- return this;
- },
- hasLayoutOffset: function() {
- return !!this.getData('layout_' + this.parent.getLayout() + '_offset');
- },
- resetLayoutOffset: function() {
- return this.setLayoutOffset(null);
- },
- getLayoutRoot: function() {
- if (this.isLayoutRoot()) {
- return this;
- }
- return this.parent.getLayoutRoot();
- },
- isLayoutRoot: function() {
- return this.getData('layout') || this.isRoot();
- }
- });
- Minder.registerInit(function(options) {
- this.refresh();
- });
- kity.extendClass(Minder, {
- layout: function(duration) {
- this.getRoot().traverse(function(node) {
- // clear last results
- node.setLayoutTransform(null);
- });
- function layoutNode(node, round) {
- // layout all children first
- // 剪枝:收起的节点无需计算
- if (node.isExpanded() || true) {
- node.children.forEach(function(child) {
- layoutNode(child, round);
- });
- }
- var layout = node.getLayoutInstance();
- var childrenInFlow = node.getChildren().filter(function(child) {
- return !child.hasLayoutOffset();
- });
- layout.doLayout(node, childrenInFlow, round);
- }
- // 第一轮布局
- layoutNode(this.getRoot(), 1);
- // 第二轮布局
- layoutNode(this.getRoot(), 2);
- duration = duration ? 300 : 0;
- var minder = this;
- this.applyLayoutResult(this.getRoot(), duration).then(function() {
- minder.fire('layoutallfinish');
- });
- return this.fire('layout');
- },
- refresh: function(duration) {
- this.getRoot().renderTree();
- this.layout(duration).fire('contentchange')._interactChange();
- return this;
- },
- applyLayoutResult: function(root, duration) {
- root = root || this.getRoot();
- var me = this;
- var deffered = {};
- var promise = new Promise(function(resolve, reject) {
- deffered.resolve = resolve;
- deffered.reject = reject;
- });
- var complex = root.getComplex();
- function consume() {
- if (!--complex) {
- deffered.resolve();
- }
- }
- // 节点复杂度大于 100,关闭动画
- if (complex > 200) duration = 0;
- function applyMatrix(node, matrix) {
- node.setGlobalLayoutTransform(matrix);
- me.fire('layoutapply', {
- node: node,
- matrix: matrix
- });
- }
- function apply(node, pMatrix) {
- var matrix = node.getLayoutTransform().merge(pMatrix);
- var lastMatrix = node.getGlobalLayoutTransform() || new kity.Matrix();
- var offset = node.getLayoutOffset();
- matrix.translate(offset.x, offset.y);
- matrix.m.e = Math.round(matrix.m.e);
- matrix.m.f = Math.round(matrix.m.f);
- // 如果当前有动画,停止动画
- if (node._layoutTimeline) {
- node._layoutTimeline.stop();
- node._layoutTimeline = null;
- }
- // 如果要求以动画形式来更新,创建动画
- if (duration) {
- node._layoutTimeline = new kity.Animator(lastMatrix, matrix, applyMatrix)
- .start(node, duration, 'ease')
- .on('finish', function() {
- //可能性能低的时候会丢帧,手动添加一帧
- setTimeout(function() {
- applyMatrix(node, matrix);
- me.fire('layoutfinish', {
- node: node,
- matrix: matrix
- });
- consume();
- }, 150);
- });
- }
- // 否则直接更新
- else {
- applyMatrix(node, matrix);
- me.fire('layoutfinish', {
- node: node,
- matrix: matrix
- });
- consume();
- }
- for (var i = 0; i < node.children.length; i++) {
- apply(node.children[i], matrix);
- }
- }
- apply(root, root.parent ? root.parent.getGlobalLayoutTransform() : new kity.Matrix());
- return promise;
- },
- });
- /**
- * @class Layout 布局基类,具体布局需要从该类派生
- */
- var Layout = kity.createClass('Layout', {
- /**
- * @abstract
- *
- * 子类需要实现的布局算法,该算法输入一个节点,排布该节点的子节点(相对父节点的变换)
- *
- * @param {MinderNode} node 需要布局的节点
- *
- * @example
- *
- * doLayout: function(node) {
- * var children = node.getChildren();
- * // layout calculation
- * children[i].setLayoutTransform(new kity.Matrix().translate(x, y));
- * }
- */
- doLayout: function(node) {
- throw new Error('Not Implement: Layout.doLayout()');
- },
- /**
- * 对齐指定的节点
- *
- * @param {Array<MinderNode>} nodes 要对齐的节点
- * @param {string} border 对齐边界,允许取值 left, right, top, bottom
- *
- */
- align: function(nodes, border, offset) {
- var me = this;
- offset = offset || 0;
- nodes.forEach(function(node) {
- var tbox = me.getTreeBox([node]);
- var matrix = node.getLayoutTransform();
- switch (border) {
- case 'left':
- return matrix.translate(offset - tbox.left, 0);
- case 'right':
- return matrix.translate(offset - tbox.right, 0);
- case 'top':
- return matrix.translate(0, offset - tbox.top);
- case 'bottom':
- return matrix.translate(0, offset - tbox.bottom);
- }
- });
- },
- stack: function(nodes, axis, distance) {
- var me = this;
- var position = 0;
- distance = distance || function(node, next, axis) {
- return node.getStyle({
- x: 'margin-right',
- y: 'margin-bottom'
- }[axis]) + next.getStyle({
- x: 'margin-left',
- y: 'margin-top'
- }[axis]);
- };
- nodes.forEach(function(node, index, nodes) {
- var tbox = me.getTreeBox([node]);
- var size = {
- x: tbox.width,
- y: tbox.height
- }[axis];
- var offset = {
- x: tbox.left,
- y: tbox.top
- }[axis];
- var matrix = node.getLayoutTransform();
- if (axis == 'x') {
- matrix.translate(position - offset, 0);
- } else {
- matrix.translate(0, position - offset);
- }
- position += size;
- if (nodes[index + 1])
- position += distance(node, nodes[index + 1], axis);
- });
- return position;
- },
- move: function(nodes, dx, dy) {
- nodes.forEach(function(node) {
- node.getLayoutTransform().translate(dx, dy);
- });
- },
- /**
- * 工具方法:获取给点的节点所占的布局区域
- *
- * @param {MinderNode[]} nodes 需要计算的节点
- *
- * @return {Box} 计算结果
- */
- getBranchBox: function(nodes) {
- var box = new kity.Box();
- var i, node, matrix, contentBox;
- for (i = 0; i < nodes.length; i++) {
- node = nodes[i];
- matrix = node.getLayoutTransform();
- contentBox = node.getContentBox();
- box = box.merge(matrix.transformBox(contentBox));
- }
- return box;
- },
- /**
- * 工具方法:计算给定的节点的子树所占的布局区域
- *
- * @param {MinderNode} nodes 需要计算的节点
- *
- * @return {Box} 计算的结果
- */
- getTreeBox: function(nodes) {
- var i, node, matrix, treeBox;
- var g = KityMinder.Geometry;
- var box = {
- x: 0,
- y: 0,
- height: 0,
- width: 0
- };
- if (!(nodes instanceof Array)) nodes = [nodes];
- for (i = 0; i < nodes.length; i++) {
- node = nodes[i];
- matrix = node.getLayoutTransform();
- treeBox = node.getContentBox();
- if (node.isExpanded() && node.children.length) {
- treeBox = g.mergeBox(treeBox, this.getTreeBox(node.children));
- }
- box = g.mergeBox(box, matrix.transformBox(treeBox));
- }
- return box;
- },
- getOrderHint: function(node) {
- return [];
- }
- });
- var LayoutCommand = kity.createClass('LayoutCommand', {
- base: Command,
- execute: function(minder, name) {
- var nodes = minder.getSelectedNodes();
- nodes.forEach(function(node) {
- node.layout(name);
- });
- },
- queryValue: function(minder) {
- var node = minder.getSelectedNode();
- if (node) {
- return node.getData('layout');
- }
- },
- queryState: function(minder) {
- return minder.getSelectedNode() ? 0 : -1;
- }
- });
- var ResetLayoutCommand = kity.createClass('ResetLayoutCommand', {
- base: Command,
- execute: function(minder, name) {
- var nodes = minder.getSelectedNodes();
- if (!nodes.length) nodes = [minder.getRoot()];
- nodes.forEach(function(node) {
- node.traverse(function(child) {
- child.resetLayoutOffset();
- if (!child.isRoot()) {
- child.setData('layout', null);
- }
- });
- });
- minder.layout(300);
- },
- enableReadOnly: true
- });
- KityMinder.registerModule('LayoutModule', {
- commands: {
- 'layout': LayoutCommand,
- 'resetlayout': ResetLayoutCommand
- },
- contextmenu: [{
- command: 'resetlayout'
- }, {
- divider: true
- }],
- commandShortcutKeys: {
- 'resetlayout': 'Ctrl+Shift+L'
- }
- });
- var cssLikeValueMatcher = {
- left: function(value) {
- return 3 in value && value[3] ||
- 1 in value && value[1] ||
- value[0];
- },
- right: function(value) {
- return 1 in value && value[1] || value[0];
- },
- top: function(value) {
- return value[0];
- },
- bottom: function(value) {
- return 2 in value && value[2] || value[0];
- }
- };
- Utils.extend(KityMinder, {
- _themes: {},
- /**
- * 注册一个主题
- *
- * @param {String} name 主题的名称
- * @param {Plain} theme 主题的样式描述
- *
- * @example
- * KityMinder.registerTheme('default', {
- * 'root-color': 'red',
- * 'root-stroke': 'none',
- * 'root-padding': [10, 20]
- * });
- */
- registerTheme: function(name, theme) {
- KityMinder._themes[name] = theme;
- },
- getThemeList: function() {
- return KityMinder._themes;
- }
- });
- kity.extendClass(Minder, {
- /**
- * 切换脑图实例上的主题
- * @param {String} name 要使用的主题的名称
- */
- useTheme: function(name) {
- this.setTheme(name);
- this.refresh(800);
- return true;
- },
- setTheme: function(name) {
- this._theme = name || null;
- this.getRenderTarget().style.background = this.getStyle('background');
- this.fire('themechange', {
- theme: name
- });
- },
- /**
- * 获取脑图实例上的当前主题
- * @return {[type]} [description]
- */
- getTheme: function(node) {
- return this._theme || this.getOptions('defaultTheme');
- },
- getThemeItems: function(node) {
- var theme = this.getTheme(node);
- return KityMinder._themes[this.getTheme(node)];
- },
- /**
- * 获得脑图实例上的样式
- * @param {String} item 样式名称
- */
- getStyle: function(item, node) {
- var items = this.getThemeItems(node);
- var segment, dir, selector, value, matcher;
- if (item in items) return items[item];
- // 尝试匹配 CSS 数组形式的值
- // 比如 item 为 'pading-left'
- // theme 里有 {'padding': [10, 20]} 的定义,则可以返回 20
- segment = item.split('-');
- if (segment.length < 2) return null;
- dir = segment.pop();
- item = segment.join('-');
- if (item in items) {
- value = items[item];
- if (Utils.isArray(value) && (matcher = cssLikeValueMatcher[dir])) {
- return matcher(value);
- }
- if (!isNaN(value)) return value;
- }
- return null;
- },
- /**
- * 获取指定节点的样式
- * @param {String} name 样式名称,可以不加节点类型的前缀
- */
- getNodeStyle: function(node, name) {
- var value = this.getStyle(node.getType() + '-' + name, node);
- return value !== null ? value : this.getStyle(name, node);
- }
- });
- kity.extendClass(MinderNode, {
- getStyle: function(name) {
- return this.getMinder().getNodeStyle(this, name);
- }
- });
- KityMinder.registerModule('Theme', {
- defaultOptions: {
- defaultTheme: 'fresh-blue'
- },
- commands: {
- 'theme': kity.createClass('ThemeCommand', {
- base: Command,
- execute: function(km, name) {
- return km.useTheme(name);
- },
- queryValue: function(km) {
- return km.getTheme() || 'default';
- }
- })
- }
- });
- Minder.registerInit(function() {
- this.setTheme();
- });
- Utils.extend(KityMinder, {
-
- compatibility: function(json) {
- var version = json.version || '1.1.3';
- function traverse(node, fn) {
- fn(node);
- if (node.children) node.children.forEach(function(child) {
- traverse(child, fn);
- });
- }
- /* 脑图数据升级 */
- function c_120_130(json) {
- traverse(json, function(node) {
- var data = node.data;
- delete data.layout_bottom_offset;
- delete data.layout_default_offset;
- delete data.layout_filetree_offset;
- });
- }
- /**
- * 脑图数据升级
- * v1.1.3 => v1.2.0
- * */
- function c_113_120(json) {
- // 原本的布局风格
- var ocs = json.data.currentstyle;
- delete json.data.currentstyle;
- // 为 1.2 选择模板,同时保留老版本文件的皮肤
- if (ocs == 'bottom') {
- json.template = 'structure';
- json.theme = 'snow';
- } else if (ocs == 'default') {
- json.template = 'default';
- json.theme = 'classic';
- }
- traverse(json, function(node) {
- var data = node.data;
- // 升级优先级、进度图标
- if ('PriorityIcon' in data) {
- data.priority = data.PriorityIcon;
- delete data.PriorityIcon;
- }
- if ('ProgressIcon' in data) {
- data.progress = 1 + ((data.ProgressIcon - 1) << 1);
- delete data.ProgressIcon;
- }
- // 删除过时属性
- delete data.point;
- delete data.layout;
- });
- }
- switch (version) {
- case '1.1.3':
- c_113_120(json);
- case '1.2.0':
- case '1.2.1':
- c_120_130(json);
- }
- return json;
- }
- });
- var Renderer = KityMinder.Renderer = kity.createClass('Renderer', {
- constructor: function(node) {
- this.node = node;
- },
- create: function(node) {
- throw new Error('Not implement: Renderer.create()');
- },
- shouldRender: function(node) {
- return true;
- },
- watchChange: function(data) {
- var changed;
- if (this.watchingData === undefined) {
- changed = true;
- } else if (this.watchingData != data) {
- changed = true;
- } else {
- changed = false;
- }
- this.watchingData = data;
- },
- shouldDraw: function(node) {
- return true;
- },
- update: function(shape, node, box) {
- if (this.shouldDraw()) this.draw(shape, node);
- return this.place(shape, node, box);
- },
- draw: function(shape, node) {
- throw new Error('Not implement: Renderer.draw()');
- },
- place: function(shape, node, box) {
- throw new Error('Not implement: Renderer.place()');
- },
- getRenderShape: function() {
- return this._renderShape || null;
- },
- setRenderShape: function(shape) {
- this._renderShape = shape;
- }
- });
- kity.extendClass(Minder, (function() {
- function createRendererForNode(node, registered) {
- var renderers = [];
- ['center', 'left', 'right', 'top', 'bottom', 'outline', 'outside'].forEach(function(section) {
- var before = 'before' + section;
- var after = 'after' + section;
- if (registered[before]) {
- renderers = renderers.concat(registered[before]);
- }
- if (registered[section]) {
- renderers = renderers.concat(registered[section]);
- }
- if (registered[after]) {
- renderers = renderers.concat(registered[after]);
- }
- });
- node._renderers = renderers.map(function(Renderer) {
- return new Renderer(node);
- });
- }
- return {
- renderNodeBatch: function(nodes) {
- var rendererClasses = this._rendererClasses;
- var lastBoxes = [];
- var rendererCount = 0;
- var i, j, renderer, node;
- if (!nodes.length) return;
- for (j = 0; j < nodes.length; j++) {
- node = nodes[j];
- if (!node._renderers) {
- createRendererForNode(node, rendererClasses);
- }
- node._contentBox = new kity.Box();
- this.fire('beforerender', {
- node: node
- });
- }
- // 所有节点渲染器数量是一致的
- rendererCount = nodes[0]._renderers.length;
- for (i = 0; i < rendererCount; i++) {
- // 获取延迟盒子数据
- for (j = 0; j < nodes.length; j++) {
- if (typeof(lastBoxes[j]) == 'function') {
- lastBoxes[j] = lastBoxes[j]();
- }
- if (!(lastBoxes[j] instanceof kity.Box)) {
- lastBoxes[j] = new kity.Box(lastBoxes[j]);
- }
- }
- for (j = 0; j < nodes.length; j++) {
- node = nodes[j];
- renderer = node._renderers[i];
- // 合并盒子
- if (lastBoxes[j]) {
- node._contentBox = node._contentBox.merge(lastBoxes[j]);
- }
- // 判断当前上下文是否应该渲染
- if (renderer.shouldRender(node)) {
- // 应该渲染,但是渲染图形没创建过,需要创建
- if (!renderer.getRenderShape()) {
- renderer.setRenderShape(renderer.create(node));
- if (renderer.bringToBack) {
- node.getRenderContainer().prependShape(renderer.getRenderShape());
- } else {
- node.getRenderContainer().appendShape(renderer.getRenderShape());
- }
- }
- // 强制让渲染图形显示
- renderer.getRenderShape().setVisible(true);
- // 更新渲染图形
- lastBoxes[j] = renderer.update(renderer.getRenderShape(), node, node._contentBox);
- }
- // 如果不应该渲染,但是渲染图形创建过了,需要隐藏起来
- else if (renderer.getRenderShape()) {
- renderer.getRenderShape().setVisible(false);
- lastBoxes[j] = null;
- }
- }
- }
- for (j = 0; j < nodes.length; j++) {
- this.fire('noderender', {
- node: nodes[j]
- });
- }
- },
- renderNode: function(node) {
- var rendererClasses = this._rendererClasses;
- var g = KityMinder.Geometry;
- var i, latestBox, renderer;
- if (!node._renderers) {
- createRendererForNode(node, rendererClasses);
- }
- this.fire('beforerender', {
- node: node
- });
- node._contentBox = new kity.Box();
- node._renderers.forEach(function(renderer) {
- // 判断当前上下文是否应该渲染
- if (renderer.shouldRender(node)) {
- // 应该渲染,但是渲染图形没创建过,需要创建
- if (!renderer.getRenderShape()) {
- renderer.setRenderShape(renderer.create(node));
- if (renderer.bringToBack) {
- node.getRenderContainer().prependShape(renderer.getRenderShape());
- } else {
- node.getRenderContainer().appendShape(renderer.getRenderShape());
- }
- }
- // 强制让渲染图形显示
- renderer.getRenderShape().setVisible(true);
- // 更新渲染图形
- latestBox = renderer.update(renderer.getRenderShape(), node, node._contentBox);
- if (typeof(latestBox) == 'function') latestBox = latestBox();
- // 合并渲染区域
- if (latestBox) {
- node._contentBox = node._contentBox.merge(latestBox);
- }
- }
- // 如果不应该渲染,但是渲染图形创建过了,需要隐藏起来
- else if (renderer.getRenderShape()) {
- renderer.getRenderShape().setVisible(false);
- }
- });
- this.fire('noderender', {
- node: node
- });
- }
- };
- })());
- kity.extendClass(MinderNode, {
- render: function() {
- if (!this.attached) return;
- this.getMinder().renderNode(this);
- return this;
- },
- renderTree: function() {
- if (!this.attached) return;
- var list = [];
- this.traverse(function(node) {
- list.push(node);
- });
- this.getMinder().renderNodeBatch(list);
- return this;
- },
- getRenderer: function(type) {
- var rs = this._renderers;
- for (var i = 0; i < rs.length; i++) {
- if (rs[i].getType() == type) return rs[i];
- }
- return null;
- },
- getContentBox: function() {
- //if (!this._contentBox) this.render();
- return this.parent && this.parent.isCollapsed() ? new kity.Box() : (this._contentBox || new kity.Box());
- }
- });
- /* global Renderer: true */
- utils.extend(KityMinder, {
- _connectProviders: {},
- _defaultConnectProvider: function(node, parent, connection) {
- connection.setPathData([
- 'M', parent.getLayoutVertexOut(),
- 'L', node.getLayoutVertexIn()
- ]);
- },
- registerConnectProvider: function(name, provider) {
- KityMinder._connectProviders[name] = provider;
- },
- getConnectProvider: function(name) {
- return KityMinder._connectProviders[name] || KityMinder._defaultConnectProvider;
- }
- });
- kity.extendClass(MinderNode, {
- getConnectProvider: function() {
- return KityMinder.getConnectProvider(this.getConnect());
- },
- getConnect: function() {
- return null;
- },
- getConnection: function() {
- return this._connection || null;
- }
- });
- kity.extendClass(Minder, {
- getConnectContainer: function() {
- return this._connectContainer;
- },
- createConnect: function(node) {
- if (node.isRoot()) return;
- var connection = new kity.Path();
- node._connection = connection;
- this._connectContainer.addShape(connection);
- this.updateConnect(node);
- },
- removeConnect: function(node) {
- var me = this;
- node.traverse(function(node) {
- me._connectContainer.removeShape(node._connection);
- node._connection = null;
- });
- },
- updateConnect: function(node) {
- var connection = node._connection;
- var parent = node.parent;
- if (!parent || !connection) return;
- if (parent.isCollapsed()) {
- connection.setVisible(false);
- return;
- }
- connection.setVisible(true);
- var provider = node.getConnectProvider();
- var strokeColor = node.getStyle('connect-color') || 'white',
- strokeWidth = node.getStyle('connect-width') || 2;
- connection.stroke(strokeColor, strokeWidth);
- provider(node, parent, connection, strokeWidth, strokeColor);
- if (strokeWidth % 2 === 0) {
- connection.setTranslate(0.5, 0.5);
- } else {
- connection.setTranslate(0, 0);
- }
- }
- });
- KityMinder.registerModule('Connect', {
- init: function() {
- this._connectContainer = new kity.Group().setId(KityMinder.uuid('minder_connect_group'));
- this.getRenderContainer().prependShape(this._connectContainer);
- },
- events: {
- 'nodeattach': function(e) {
- this.createConnect(e.node);
- },
- 'nodedetach': function(e) {
- this.removeConnect(e.node);
- },
- 'layoutapply layoutfinish noderender': function(e) {
- this.updateConnect(e.node);
- }
- }
- });
- utils.extend(KityMinder, {
- _templates: {},
- registerTemplate: function(name, supports) {
- KityMinder._templates[name] = supports;
- },
- getTemplateList: function() {
- return KityMinder._templates;
- }
- });
- kity.extendClass(Minder, (function() {
- var originGetTheme = Minder.prototype.getTheme;
- return {
- useTemplate: function(name, duration) {
- this.setTemplate(name);
- this.refresh(duration || 800);
- },
- getTemplate: function() {
- return this._template || 'default';
- },
- setTemplate: function(name) {
- this._template = name || null;
- },
- getTemplateSupport: function(method) {
- var supports = KityMinder._templates[this.getTemplate()];
- return supports && supports[method];
- },
- getTheme: function(node) {
- var support = this.getTemplateSupport('getTheme') || originGetTheme;
- return support.call(this, node);
- }
- };
- })());
- kity.extendClass(MinderNode, (function() {
- var originGetLayout = MinderNode.prototype.getLayout;
- var originGetConnect = MinderNode.prototype.getConnect;
- return {
- getLayout: function() {
- var support = this.getMinder().getTemplateSupport('getLayout') || originGetLayout;
- return support.call(this, this);
- },
- getConnect: function() {
- var support = this.getMinder().getTemplateSupport('getConnect') || originGetConnect;
- return support.call(this, this);
- }
- };
- })());
- KityMinder.registerModule('TemplateModule', {
- commands: {
- 'template': kity.createClass('TemplateCommand', {
- base: Command,
- execute: function(minder, name) {
- minder.useTemplate(name);
- minder.execCommand('camera');
- },
- queryValue: function(minder) {
- return minder.getTemplate() || 'default';
- }
- })
- }
- });
- //添加多语言模块
- kity.extendClass( Minder, {
- getLang: function ( path ) {
- var lang = KM.LANG[ this.getOptions( 'lang' ) ];
- if ( !lang ) {
- throw Error( "not import language file" );
- }
- path = ( path || "" ).split( "." );
- for ( var i = 0, ci; ci = path[ i++ ]; ) {
- lang = lang[ ci ];
- if ( !lang ) break;
- }
- if (typeof(lang) == 'string') {
- var args = arguments;
- return lang.replace(/\{(\d+)\}/ig, function(match, gindex) {
- return args[+gindex + 1] != undefined && args[+gindex + 1].toString() || match;
- });
- }
- return lang;
- }
- } );
- //这里只放不是由模块产生的默认参数
- KM.defaultOptions = {
- zIndex : 1000,
- lang:'zh-cn',
- readyOnly:false
- };
- kity.extendClass( Minder, function(){
- var ROOTKEY = 'kityminder_preference';
- //创建存储机制
- var LocalStorage = ( function () {
- var storage = window.localStorage,
- LOCAL_FILE = "localStorage";
- return {
- saveLocalData: function ( key, data ) {
- if ( storage && data) {
- storage.setItem( key, data );
- return true;
- }
- return false;
- },
- getLocalData: function ( key ) {
- if ( storage ) {
- return storage.getItem( key );
- }
- return null;
- },
- removeItem: function ( key ) {
- if (storage) storage.removeItem( key );
- }
- };
- } )();
- return {
- setPreferences: function(key,value){
- var obj = {};
- if ( Utils.isString( key ) ) {
- obj[ key ] = value;
- } else {
- obj = key;
- }
- var data = LocalStorage.getLocalData(ROOTKEY);
- if(data){
- data = JSON.parse(data);
- utils.extend(data, obj);
- }else{
- data = obj;
- }
- LocalStorage.saveLocalData(ROOTKEY,JSON.stringify(data));
- },
- getPreferences: function(key){
- var data = LocalStorage.getLocalData(ROOTKEY);
- if(data){
- data = JSON.parse(data);
- return key ? data[key] : data;
- }
- return {};
- },
- resetPreferences: function(pres){
- var str = pres ? JSON.stringify(pres) : '';
- LocalStorage.saveLocalData(str);
- }
- };
- }() );
- var keymap = KityMinder.keymap = (function(origin) {
- var ret = {};
- for (var key in origin) {
- if (origin.hasOwnProperty(key)) {
- ret[key] = origin[key];
- ret[key.toLowerCase()] = origin[key];
- }
- }
- var aKeyCode = 65;
- var aCharCode = 'a'.charCodeAt(0);
- // letters
- 'abcdefghijklmnopqrstuvwxyz'.split('').forEach(function(letter) {
- ret[letter] = aKeyCode + (letter.charCodeAt(0) - aCharCode);
- });
- // numbers
- var n = 9;
- do {
- ret[n.toString()] = n + 48;
- } while(--n);
- return ret;
- })({
- 'Backspace': 8,
- 'Tab': 9,
- 'Enter': 13,
- 'Shift': 16,
- 'Control': 17,
- 'Alt': 18,
- 'CapsLock': 20,
- 'Esc': 27,
- 'Spacebar': 32,
- 'PageUp': 33,
- 'PageDown': 34,
- 'End': 35,
- 'Home': 36,
- 'Insert': 45,
- 'Left': 37,
- 'Up': 38,
- 'Right': 39,
- 'Down': 40,
- 'direction': {
- 37: 1,
- 38: 1,
- 39: 1,
- 40: 1
- },
- 'Del': 46,
- 'NumLock': 144,
- 'Cmd': 91,
- 'CmdFF': 224,
- 'F1': 112,
- 'F2': 113,
- 'F3': 114,
- 'F4': 115,
- 'F5': 116,
- 'F6': 117,
- 'F7': 118,
- 'F8': 119,
- 'F9': 120,
- 'F10': 121,
- 'F11': 122,
- 'F12': 123,
- '`': 192,
- '=': 187,
- '-': 189,
- '/': 191,
- '.': 190,
- controlKeys: {
- 16: 1,
- 17: 1,
- 18: 1,
- 20: 1,
- 91: 1,
- 224: 1
- },
- 'notContentChange': {
- 13: 1,
- 9: 1,
- 33: 1,
- 34: 1,
- 35: 1,
- 36: 1,
- 16: 1,
- 17: 1,
- 18: 1,
- 20: 1,
- 91: 1,
- //上下左右
- 37: 1,
- 38: 1,
- 39: 1,
- 40: 1,
- 113: 1,
- 114: 1,
- 115: 1,
- 144: 1,
- 27: 1
- },
- 'isSelectedNodeKey': {
- //上下左右
- 37: 1,
- 38: 1,
- 39: 1,
- 40: 1,
- 13: 1,
- 9: 1
- }
- });
- /* global Layout:true */
- KityMinder.registerLayout('mind', kity.createClass({
- base: Layout,
- doLayout: function(node, children) {
- var layout = this;
- var half = Math.ceil(node.children.length / 2);
- var right = [];
- var left = [];
- children.forEach(function(child) {
- if (child.getIndex() < half) right.push(child);
- else left.push(child);
- });
- var leftLayout = KityMinder.getLayoutInstance('left');
- var rightLayout = KityMinder.getLayoutInstance('right');
- leftLayout.doLayout(node, left);
- rightLayout.doLayout(node, right);
- var box = node.getContentBox();
- node.setVertexOut(new kity.Point(box.cx, box.cy));
- node.setLayoutVectorOut(new kity.Vector(0, 0));
- },
- getOrderHint: function(node) {
- var hint = [];
- var box = node.getLayoutBox();
- var offset = 5;
- hint.push({
- type: 'up',
- node: node,
- area: {
- x: box.x,
- y: box.top - node.getStyle('margin-top') - offset,
- width: box.width,
- height: node.getStyle('margin-top')
- },
- path: ['M', box.x, box.top - offset, 'L', box.right, box.top - offset]
- });
- hint.push({
- type: 'down',
- node: node,
- area: {
- x: box.x,
- y: box.bottom + offset,
- width: box.width,
- height: node.getStyle('margin-bottom')
- },
- path: ['M', box.x, box.bottom + offset, 'L', box.right, box.bottom + offset]
- });
- return hint;
- }
- }));
- /* global Layout:true */
- [-1, 1].forEach(function (dir) {
- var name = 'filetree-' + (dir > 0 ? 'down' : 'up');
- KityMinder.registerLayout(name, kity.createClass({
- base: Layout,
- doLayout: function(parent, children, round) {
- var pBox = parent.getContentBox();
- var indent = 20;
- parent.setVertexOut(new kity.Point(pBox.left + indent, dir > 0 ? pBox.bottom : pBox.top));
- parent.setLayoutVectorOut(new kity.Vector(0, dir));
- if (!children.length) return;
- children.forEach(function(child) {
- var cbox = child.getContentBox();
- child.setLayoutTransform(new kity.Matrix());
- child.setVertexIn(new kity.Point(cbox.left, cbox.cy));
- child.setLayoutVectorIn(new kity.Vector(1, 0));
- });
- this.align(children, 'left');
- this.stack(children, 'y');
- var xAdjust = 0;
- xAdjust += pBox.left;
- xAdjust += indent;
- xAdjust += children[0].getStyle('margin-left');
- var yAdjust = 0;
- if (dir > 0) {
- yAdjust += pBox.bottom;
- yAdjust += parent.getStyle('margin-bottom');
- yAdjust += children[0].getStyle('margin-top');
- } else {
- yAdjust -= this.getTreeBox(children).bottom;
- yAdjust += pBox.top;
- yAdjust -= parent.getStyle('margin-top');
- yAdjust -= children[0].getStyle('margin-bottom');
- }
- this.move(children, xAdjust, yAdjust);
- },
- getOrderHint: function(node) {
- var hint = [];
- var box = node.getLayoutBox();
- var offset = node.getLevel() > 1 ? 3 : 5;
- hint.push({
- type: 'up',
- node: node,
- area: {
- x: box.x,
- y: box.top - node.getStyle('margin-top') - offset,
- width: box.width,
- height: node.getStyle('margin-top')
- },
- path: ['M', box.x, box.top - offset, 'L', box.right, box.top - offset]
- });
- hint.push({
- type: 'down',
- node: node,
- area: {
- x: box.x,
- y: box.bottom + offset,
- width: box.width,
- height: node.getStyle('margin-bottom')
- },
- path: ['M', box.x, box.bottom + offset, 'L', box.right, box.bottom + offset]
- });
- return hint;
- }
- }));
- });
- /* global Layout:true */
- var layouts = ['left', 'right', 'top', 'bottom'];
- layouts.forEach(function(name) {
- var axis = (name == 'left' || name == 'right') ? 'x' : 'y';
- var dir = (name == 'left' || name == 'top') ? -1 : 1;
- var oppsite = {
- 'left': 'right',
- 'right': 'left',
- 'top': 'bottom',
- 'bottom': 'top',
- 'x': 'y',
- 'y': 'x'
- };
- function getOrderHint(node) {
- var hint = [];
- var box = node.getLayoutBox();
- var offset = 5;
- if (axis == 'x') {
- hint.push({
- type: 'up',
- node: node,
- area: {
- x: box.x,
- y: box.top - node.getStyle('margin-top') - offset,
- width: box.width,
- height: node.getStyle('margin-top')
- },
- path: ['M', box.x, box.top - offset, 'L', box.right, box.top - offset]
- });
- hint.push({
- type: 'down',
- node: node,
- area: {
- x: box.x,
- y: box.bottom + offset,
- width: box.width,
- height: node.getStyle('margin-bottom')
- },
- path: ['M', box.x, box.bottom + offset, 'L', box.right, box.bottom + offset]
- });
- } else {
- hint.push({
- type: 'up',
- node: node,
- area: {
- x: box.left - node.getStyle('margin-left') - offset,
- y: box.top,
- width: node.getStyle('margin-left'),
- height: box.height
- },
- path: ['M', box.left - offset, box.top, 'L', box.left - offset, box.bottom]
- });
- hint.push({
- type: 'down',
- node: node,
- area: {
- x: box.right + offset,
- y: box.top,
- width: node.getStyle('margin-right'),
- height: box.height
- },
- path: ['M', box.right + offset, box.top, 'L', box.right + offset, box.bottom]
- });
- }
- return hint;
- }
- KityMinder.registerLayout(name, kity.createClass({
- base: Layout,
- doLayout: function(parent, children) {
- var pbox = parent.getContentBox();
- if (axis == 'x') {
- parent.setVertexOut(new kity.Point(pbox[name], pbox.cy));
- parent.setLayoutVectorOut(new kity.Vector(dir, 0));
- } else {
- parent.setVertexOut(new kity.Point(pbox.cx, pbox[name]));
- parent.setLayoutVectorOut(new kity.Vector(0, dir));
- }
- if (!children.length) {
- return false;
- }
- children.forEach(function(child) {
- var cbox = child.getContentBox();
- child.setLayoutTransform(new kity.Matrix());
- if (axis == 'x') {
- child.setVertexIn(new kity.Point(cbox[oppsite[name]], cbox.cy));
- child.setLayoutVectorIn(new kity.Vector(dir, 0));
- } else {
- child.setVertexIn(new kity.Point(cbox.cx, cbox[oppsite[name]]));
- child.setLayoutVectorIn(new kity.Vector(0, dir));
- }
- });
- this.align(children, oppsite[name]);
- this.stack(children, oppsite[axis]);
- var bbox = this.getBranchBox(children);
- var xAdjust, yAdjust;
- if (axis == 'x') {
- xAdjust = pbox[name];
- xAdjust += dir * parent.getStyle('margin-' + name);
- xAdjust += dir * children[0].getStyle('margin-' + oppsite[name]);
- yAdjust = pbox.bottom;
- yAdjust -= pbox.height / 2;
- yAdjust -= bbox.height / 2;
- yAdjust -= bbox.y;
- } else {
- xAdjust = pbox.right;
- xAdjust -= pbox.width / 2;
- xAdjust -= bbox.width / 2;
- xAdjust -= bbox.x;
- yAdjust = pbox[name];
- yAdjust += dir * parent.getStyle('margin-' + name);
- yAdjust += dir * children[0].getStyle('margin-' + oppsite[name]);
- }
- this.move(children, xAdjust, yAdjust);
- },
- getOrderHint: getOrderHint
- }));
- });
- /**
- * @fileOverview
- *
- * 鱼骨图主骨架布局
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- /* global Layout:true */
- KityMinder.registerLayout('fish-bone-master', kity.createClass('FishBoneMasterLayout', {
- base: Layout,
- doLayout: function(parent, children, round) {
- var upPart = [],
- downPart = [];
- var child = children[0];
- var pBox = parent.getContentBox();
- parent.setVertexOut(new kity.Point(pBox.right, pBox.cy));
- parent.setLayoutVectorOut(new kity.Vector(1, 0));
- if (!child) return;
- var cBox = child.getContentBox();
- var pMarginRight = parent.getStyle('margin-right');
- var cMarginLeft = child.getStyle('margin-left');
- var cMarginTop = child.getStyle('margin-top');
- var cMarginBottom = child.getStyle('margin-bottom');
- children.forEach(function(child, index) {
- child.setLayoutTransform(new kity.Matrix());
- var cBox = child.getContentBox();
- if (index % 2) {
- downPart.push(child);
- child.setVertexIn(new kity.Point(cBox.left, cBox.top));
- child.setLayoutVectorIn(new kity.Vector(1, 1));
- }
- else {
- upPart.push(child);
- child.setVertexIn(new kity.Point(cBox.left, cBox.bottom));
- child.setLayoutVectorIn(new kity.Vector(1, -1));
- }
- });
- this.stack(upPart, 'x');
- this.stack(downPart, 'x');
- this.align(upPart, 'bottom');
- this.align(downPart, 'top');
- var xAdjust = pBox.right + pMarginRight + cMarginLeft;
- var yAdjustUp = pBox.cy - cMarginBottom - parent.getStyle('margin-top');
- var yAdjustDown = pBox.cy + cMarginTop + parent.getStyle('margin-bottom');
- this.move(upPart, xAdjust, yAdjustUp);
- this.move(downPart, xAdjust + cMarginLeft, yAdjustDown);
- // children.forEach(function(child, index) {
- // var matrix = child.getLayoutTransform();
- // var dx, dy;
- // dx = matrix.getMatrix().e;
- // dy = matrix.getMatrix().f;
- // matrix.translate(-dx, -dy);
- // matrix.rotate(index % 2 ? 45 : -45);
- // matrix.translate(dx, dy);
- // });
- }
- }));
- /**
- * @fileOverview
- *
- *
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- /* global Layout: true */
- KityMinder.registerLayout('fish-bone-slave', kity.createClass('FishBoneSlaveLayout', {
- base: Layout,
- doLayout: function (parent, children, round) {
- var layout = this;
- var abs = Math.abs;
- var GOLD_CUT = 1 - 0.618;
- var pBox = parent.getContentBox();
- var vi = parent.getLayoutVectorIn();
- parent.setLayoutVectorOut(vi);
- var goldX = pBox.left + pBox.width * GOLD_CUT;
- var pout = new kity.Point(goldX, vi.y > 0 ? pBox.bottom : pBox.top);
- parent.setVertexOut(pout);
- var child = children[0];
- if (!child) return;
- var cBox = child.getContentBox();
- children.forEach(function(child, index) {
- child.setLayoutTransform(new kity.Matrix());
- child.setLayoutVectorIn(new kity.Vector(1, 0));
- child.setVertexIn(new kity.Point(cBox.left, cBox.cy));
- });
- this.stack(children, 'y');
- this.align(children, 'left');
- var xAdjust = 0, yAdjust = 0;
-
- xAdjust += pout.x;
- if (parent.getLayoutVectorOut().y < 0) {
- yAdjust -= this.getTreeBox(children).bottom;
- yAdjust += parent.getContentBox().top;
- yAdjust -= parent.getStyle('margin-top');
- yAdjust -= child.getStyle('margin-bottom');
- } else {
- yAdjust += parent.getContentBox().bottom;
- yAdjust += parent.getStyle('margin-bottom');
- yAdjust += child.getStyle('margin-top');
- }
- this.move(children, xAdjust, yAdjust);
- if (round == 2) {
- children.forEach(function(child) {
- var m = child.getLayoutTransform();
- var cbox = child.getContentBox();
- var pin = m.transformPoint(new kity.Point(cbox.left, 0));
- layout.move([child], abs(pin.y - pout.y), 0);
- });
- }
- }
- }));
- /**
- * @fileOverview
- *
- * 天盘模板
- *
- * @author: along
- * @copyright: bpd729@163.com, 2015
- */
- KityMinder.registerLayout('tianpan', kity.createClass({
- base: Layout,
- doLayout: function (parent, children) {
- if (children.length == 0) return;
- var layout = this;
- var pbox = parent.getContentBox();
- var x, y,box;
- var _theta = 5;
- var _r = Math.max(pbox.width, 50);
- children.forEach(function (child, index) {
- child.setLayoutTransform(new kity.Matrix());
- box = layout.getTreeBox(child);
- _r = Math.max(Math.max(box.width, box.height), _r);
- })
- _r = _r / 1.5 / Math.PI;
- children.forEach(function (child, index) {
- x = _r * (Math.cos(_theta) + Math.sin(_theta) * _theta);
- y = _r * (Math.sin(_theta) - Math.cos(_theta) * _theta);
- _theta += (0.9 - index * 0.02);
- child.setLayoutVectorIn(new kity.Vector(1, 0));
- child.setVertexIn(new kity.Point(pbox.cx, pbox.cy));
- child.setLayoutTransform(new kity.Matrix());
- layout.move([child], x, y);
- });
- },
- getOrderHint: function (node) {
- var hint = [];
- var box = node.getLayoutBox();
- var offset = 5;
- hint.push({
- type: 'up',
- node: node,
- area: {
- x: box.x,
- y: box.top - node.getStyle('margin-top') - offset,
- width: box.width,
- height: node.getStyle('margin-top')
- },
- path: ['M', box.x, box.top - offset, 'L', box.right, box.top - offset]
- });
- hint.push({
- type: 'down',
- node: node,
- area: {
- x: box.x,
- y: box.bottom + offset,
- width: box.width,
- height: node.getStyle('margin-bottom')
- },
- path: ['M', box.x, box.bottom + offset, 'L', box.right, box.bottom + offset]
- });
- return hint;
- }
- }));
- /**
- * @fileOverview
- *
- * 提供折线相连的方法
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerConnectProvider('bezier', function(node, parent, connection) {
- // 连线起点和终点
- var po = parent.getLayoutVertexOut(),
- pi = node.getLayoutVertexIn();
- // 连线矢量和方向
- var v = parent.getLayoutVectorOut().normalize();
- var r = Math.round;
- var abs = Math.abs;
- var pathData = [];
- pathData.push('M', r(po.x), r(po.y));
- if (abs(v.x) > abs(v.y)) {
- // x - direction
- var hx = (pi.x + po.x) / 2;
- pathData.push('C', hx, po.y, hx, pi.y, pi.x, pi.y);
- } else {
- // y - direction
- var hy = (pi.y + po.y) / 2;
- pathData.push('C', po.x, hy, pi.x, hy, pi.x, pi.y);
- }
- connection.setMarker(null);
- connection.setPathData(pathData);
- });
- /**
- * @fileOverview
- *
- * 提供折线相连的方法
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerConnectProvider('poly', function(node, parent, connection, width) {
- // 连线起点和终点
- var po = parent.getLayoutVertexOut(),
- pi = node.getLayoutVertexIn();
- // 连线矢量和方向
- var v = parent.getLayoutVectorOut().normalize();
- var r = Math.round;
- var abs = Math.abs;
- var pathData = [];
- pathData.push('M', r(po.x), r(po.y));
- switch (true) {
- case abs(v.x) > abs(v.y) && v.x < 0:
- // left
- pathData.push('h', -parent.getStyle('margin-left'));
- pathData.push('v', pi.y - po.y);
- pathData.push('H', pi.x);
- break;
- case abs(v.x) > abs(v.y) && v.x >= 0:
- // right
- pathData.push('h', parent.getStyle('margin-right'));
- pathData.push('v', pi.y - po.y);
- pathData.push('H', pi.x);
- break;
- case abs(v.x) <= abs(v.y) && v.y < 0:
- // top
- pathData.push('v', -parent.getStyle('margin-top'));
- pathData.push('h', pi.x - po.x);
- pathData.push('V', pi.y);
- break;
- case abs(v.x) <= abs(v.y) && v.y >= 0:
- // bottom
- pathData.push('v', parent.getStyle('margin-bottom'));
- pathData.push('h', pi.x - po.x);
- pathData.push('V', pi.y);
- break;
- }
- connection.setMarker(null);
- connection.setPathData(pathData);
- });
- /**
- * @fileOverview
- *
- * 圆弧连线
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- var connectMarker = new kity.Marker().pipe(function() {
- var r = 7;
- var dot = new kity.Circle(r - 1);
- this.addShape(dot);
- this.setRef(r - 1, 0).setViewBox(-r, -r, r + r, r + r).setWidth(r).setHeight(r);
- this.dot = dot;
- this.node.setAttribute('markerUnits', 'userSpaceOnUse');
- });
- KityMinder.registerConnectProvider('arc', function(node, parent, connection, width, color) {
- var box = node.getLayoutBox(),
- pBox = parent.getLayoutBox();
- var start, end, vector;
- var abs = Math.abs;
- var pathData = [];
- var side = box.x > pBox.x ? 'right' : 'left';
- node.getMinder().getPaper().addResource(connectMarker);
- start = new kity.Point(pBox.cx, pBox.cy);
- end = side == 'left' ?
- new kity.Point(box.right + 2, box.cy) :
- new kity.Point(box.left - 2, box.cy);
- vector = kity.Vector.fromPoints(start, end);
- pathData.push('M', start);
- pathData.push('A', abs(vector.x), abs(vector.y), 0, 0, (vector.x * vector.y > 0 ? 0 : 1), end);
- connection.setMarker(connectMarker);
- connectMarker.dot.fill(color);
- connection.setPathData(pathData);
- });
- /**
- * @fileOverview
- *
- * 下划线连线
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerConnectProvider('under', function(node, parent, connection, width, color) {
- var box = node.getLayoutBox(),
- pBox = parent.getLayoutBox();
- var start, end, vector;
- var abs = Math.abs;
- var pathData = [];
- var side = box.x > pBox.x ? 'right' : 'left';
- var radius = node.getStyle('connect-radius');
- var underY = box.bottom + 3;
- var startY = parent.getType() == 'sub' ? pBox.bottom + 3 : pBox.cy;
- var p1, p2, p3, mx;
- if (side == 'right') {
- p1 = new kity.Point(pBox.right, startY);
- p2 = new kity.Point(box.left - 10, underY);
- p3 = new kity.Point(box.right, underY);
- } else {
- p1 = new kity.Point(pBox.left, startY);
- p2 = new kity.Point(box.right + 10, underY);
- p3 = new kity.Point(box.left, underY);
- }
- mx = (p1.x + p2.x) / 2;
- pathData.push('M', p1);
- pathData.push('C', mx, p1.y, mx, p2.y, p2);
- pathData.push('L', p3);
- connection.setMarker(null);
- connection.setPathData(pathData);
- });
- /**
- * @fileOverview
- *
- * "L" 连线
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerConnectProvider('l', function(node, parent, connection) {
- var po = parent.getLayoutVertexOut();
- var pi = node.getLayoutVertexIn();
- var vo = parent.getLayoutVectorOut();
- var pathData = [];
- var r = Math.round,
- abs = Math.abs;
- pathData.push('M', po.round());
- if (abs(vo.x) > abs(vo.y)) {
- pathData.push('H', r(pi.x));
- } else {
- pathData.push('V', pi.y);
- }
- pathData.push('L', pi);
- connection.setPathData(pathData);
- });
- /**
- * @fileOverview
- *
- * 鱼骨头主干连线
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerConnectProvider('fish-bone-master', function(node, parent, connection) {
- var pout = parent.getLayoutVertexOut(),
- pin = node.getLayoutVertexIn();
- var abs = Math.abs;
- var dy = abs(pout.y - pin.y),
- dx = abs(pout.x - pin.x);
- var pathData = [];
- pathData.push('M', pout.x, pout.y);
- pathData.push('h', dx - dy);
- pathData.push('L', pin.x, pin.y);
- connection.setMarker(null);
- connection.setPathData(pathData);
- });
- /**
- *
- * 圆弧连线
- *
- * @author: along
- * @copyright: bpd729@163.com , 2015
- */
- var connectMarker = new kity.Marker().pipe(function () {
- var r = 7;
- var dot = new kity.Circle(r - 1);
- this.addShape(dot);
- this.setRef(r - 1, 0).setViewBox(-r, -r, r + r, r + r).setWidth(r).setHeight(r);
- this.dot = dot;
- this.node.setAttribute('markerUnits', 'userSpaceOnUse');
- });
- KityMinder.registerConnectProvider('arc_tp', function (node, parent, connection, width, color) {
- var end_box = node.getLayoutBox(),
- start_box = parent.getLayoutBox();
- if (node.getIndex() > 0) {
- var index = node.getIndex();
- start_box = parent.getChildren()[index - 1].getLayoutBox();
- }
- var start, end, vector;
- var abs = Math.abs;
- var pathData = [];
- var side = end_box.x > start_box.x ? 'right' : 'left';
- node.getMinder().getPaper().addResource(connectMarker);
- start = new kity.Point(start_box.cx, start_box.cy);
- end = new kity.Point(end_box.cx, end_box.cy);
- var jl = Math.sqrt(Math.abs(start.x - end.x) * Math.abs(start.x - end.x) + Math.abs(start.y - end.y) * Math.abs(start.y - end.y)); //两圆中心点距离
- jl = node.getIndex() == 0 ? jl * 0.4 : jl;
- vector = kity.Vector.fromPoints(start, end);
- pathData.push('M', start);
- pathData.push('A', jl, jl, 0, 0, 1, end);
- connection.setMarker(connectMarker);
- connectMarker.dot.fill(color);
- connection.setPathData(pathData);
- });
- ['classic', 'classic-compact'].forEach(function(name) {
- var compact = name == 'classic-compact';
- KityMinder.registerTheme(name, {
- 'background': '#3A4144 url(ui/theme/default/images/grid.png) repeat',
- 'root-color': '#430',
- 'root-background': '#e9df98',
- 'root-stroke': '#e9df98',
- 'root-font-size': 24,
- 'root-padding': compact ? [10, 25] : [15, 25],
- 'root-margin': compact ? [15, 25] : [30, 100],
- 'root-radius': 30,
- 'root-space': 10,
- 'root-shadow': 'rgba(0, 0, 0, .25)',
- 'main-color': '#333',
- 'main-background': '#a4c5c0',
- 'main-stroke': '#a4c5c0',
- 'main-font-size': 16,
- 'main-padding': compact ? [5, 15] : [6, 20],
- 'main-margin': compact ? [5, 10] : 20,
- 'main-radius': 10,
- 'main-space': 5,
- 'main-shadow': 'rgba(0, 0, 0, .25)',
- 'sub-color': 'white',
- 'sub-background': 'transparent',
- 'sub-stroke': 'none',
- 'sub-font-size': 12,
- 'sub-padding': [5, 10],
- 'sub-margin': compact ? [5, 10] : [15, 20],
- 'sub-tree-margin': 30,
- 'sub-radius': 5,
- 'sub-space': 5,
- 'connect-color': 'white',
- 'connect-width': 2,
- 'main-connect-width': 3,
- 'connect-radius': 5,
- 'selected-background': 'rgb(254, 219, 0)',
- 'selected-stroke': 'rgb(254, 219, 0)',
- 'selected-color': 'black',
- 'marquee-background': 'rgba(255,255,255,.3)',
- 'marquee-stroke': 'white',
- 'drop-hint-color': 'yellow',
- 'sub-drop-hint-width': 2,
- 'main-drop-hint-width': 4,
- 'root-drop-hint-width': 4,
- 'order-hint-area-color': 'rgba(0, 255, 0, .5)',
- 'order-hint-path-color': '#0f0',
- 'order-hint-path-width': 1,
- 'text-selection-color': 'rgb(27,171,255)',
- 'line-height':1.5
- });
- });
- ['snow', 'snow-compact'].forEach(function(name) {
- var compact = name == 'snow-compact';
- KityMinder.registerTheme(name, {
- 'background': '#3A4144 url(ui/theme/default/images/grid.png) repeat',
- 'root-color': '#430',
- 'root-background': '#e9df98',
- 'root-stroke': '#e9df98',
- 'root-font-size': 24,
- 'root-padding': compact ? [5, 10] : [15, 25],
- 'root-margin': compact ? 15 : 30,
- 'root-radius': 5,
- 'root-space': 10,
- 'root-shadow': 'rgba(0, 0, 0, .25)',
- 'main-color': '#333',
- 'main-background': '#a4c5c0',
- 'main-stroke': '#a4c5c0',
- 'main-font-size': 16,
- 'main-padding': compact ? [4, 10] : [6, 20],
- 'main-margin': compact ? [5, 10] : [20, 40],
- 'main-radius': 5,
- 'main-space': 5,
- 'main-shadow': 'rgba(0, 0, 0, .25)',
- 'sub-color': 'black',
- 'sub-background': 'white',
- 'sub-stroke': 'white',
- 'sub-font-size': 12,
- 'sub-padding': [5, 10],
- 'sub-margin': compact ? [5, 10] : [10, 20],
- 'sub-radius': 5,
- 'sub-space': 5,
- 'connect-color': 'white',
- 'connect-width': 2,
- 'main-connect-width': 3,
- 'connect-radius': 5,
- 'selected-background': 'rgb(254, 219, 0)',
- 'selected-stroke': 'rgb(254, 219, 0)',
- 'marquee-background': 'rgba(255,255,255,.3)',
- 'marquee-stroke': 'white',
- 'drop-hint-color': 'yellow',
- 'drop-hint-width': 4,
- 'order-hint-area-color': 'rgba(0, 255, 0, .5)',
- 'order-hint-path-color': '#0f0',
- 'order-hint-path-width': 1,
- 'text-selection-color': 'rgb(27,171,255)',
- 'line-height':1.5
- });
- });
- (function() {
- function hsl(h, s, l) {
- return kity.Color.createHSL(h, s, l);
- }
- function generate(h, compat) {
- return {
- 'background': '#fbfbfb',
- 'root-color': 'white',
- 'root-background': hsl(h, 37, 60),
- 'root-stroke': hsl(h, 37, 60),
- 'root-font-size': 16,
- 'root-padding': compat ? [6, 12] : [12, 24],
- 'root-margin': compat ? 10 : [30, 100],
- 'root-radius': 5,
- 'root-space': 10,
- 'main-color': 'black',
- 'main-background': hsl(h, 33, 95),
- 'main-stroke': hsl(h, 37, 60),
- 'main-stroke-width': 1,
- 'main-font-size': 14,
- 'main-padding': [6, 20],
- 'main-margin': compat ? 8 : 20,
- 'main-radius': 3,
- 'main-space': 5,
- 'sub-color': 'black',
- 'sub-background': 'transparent',
- 'sub-stroke': 'none',
- 'sub-font-size': 12,
- 'sub-padding': compat ? [3, 5] : [5, 10],
- 'sub-margin': compat ? [4, 8] : [15, 20],
- 'sub-radius': 5,
- 'sub-space': 5,
- 'connect-color': hsl(h, 37, 60),
- 'connect-width': 1,
- 'connect-radius': 5,
- 'selected-stroke': hsl(h, 26, 30),
- 'selected-stroke-width': '3',
- 'marquee-background': hsl(h, 100, 80).set('a', 0.1),
- 'marquee-stroke': hsl(h, 37, 60),
- 'drop-hint-color': hsl(h, 26, 35),
- 'drop-hint-width': 5,
- 'order-hint-area-color': hsl(h, 100, 30).set('a', 0.5),
- 'order-hint-path-color': hsl(h, 100, 25),
- 'order-hint-path-width': 1,
- 'text-selection-color': hsl(h, 100, 20),
- 'line-height':1.5
- };
- }
- var plans = {
- red: 0,
- soil: 25,
- green: 122,
- blue: 204,
- purple: 246,
- pink: 334
- };
- var name;
- for (name in plans) {
- KityMinder.registerTheme('fresh-' + name, generate(plans[name]));
- KityMinder.registerTheme('fresh-' + name + '-compat', generate(plans[name], true));
- }
- })();
- KityMinder.registerTheme('fish', {
- 'background': '#3A4144 url(ui/theme/default/images/grid.png) repeat',
- 'root-color': '#430',
- 'root-background': '#e9df98',
- 'root-stroke': '#e9df98',
- 'root-font-size': 24,
- 'root-padding': [35, 35],
- 'root-margin': 30,
- 'root-radius': 100,
- 'root-space': 10,
- 'root-shadow': 'rgba(0, 0, 0, .25)',
- 'main-color': '#333',
- 'main-background': '#a4c5c0',
- 'main-stroke': '#a4c5c0',
- 'main-font-size': 16,
- 'main-padding': [6, 20],
- 'main-margin': [20, 20],
- 'main-radius': 5,
- 'main-space': 5,
- 'main-shadow': 'rgba(0, 0, 0, .25)',
- 'sub-color': 'black',
- 'sub-background': 'white',
- 'sub-stroke': 'white',
- 'sub-font-size': 12,
- 'sub-padding': [5, 10],
- 'sub-margin': [10],
- 'sub-radius': 5,
- 'sub-space': 5,
- 'connect-color': 'white',
- 'connect-width': 3,
- 'main-connect-width': 3,
- 'connect-radius': 5,
- 'selected-background': 'rgb(254, 219, 0)',
- 'selected-stroke': 'rgb(254, 219, 0)',
- 'marquee-background': 'rgba(255,255,255,.3)',
- 'marquee-stroke': 'white',
- 'drop-hint-color': 'yellow',
- 'drop-hint-width': 4,
- 'order-hint-area-color': 'rgba(0, 255, 0, .5)',
- 'order-hint-path-color': '#0f0',
- 'order-hint-path-width': 1,
- 'text-selection-color': 'rgb(27,171,255)',
- 'line-height':1.5
- });
- KityMinder.registerTheme('wire', {
- 'background': 'black',
- 'color': '#999',
- 'stroke': 'none',
- 'padding': 10,
- 'margin': 20,
- 'font-size': 14,
- 'connect-color': '#999',
- 'connect-width': 1,
- 'selected-background': '#999',
- 'selected-color': 'black',
- 'marquee-background': 'rgba(255,255,255,.3)',
- 'marquee-stroke': 'white',
- 'drop-hint-color': 'yellow',
- 'sub-drop-hint-width': 2,
- 'main-drop-hint-width': 4,
- 'root-drop-hint-width': 4,
- 'order-hint-area-color': 'rgba(0, 255, 0, .5)',
- 'order-hint-path-color': '#0f0',
- 'order-hint-path-width': 1,
- 'text-selection-color': 'rgb(27,171,255)',
- 'line-height':1.5
- });
- ['tianpan', 'tianpan-compact'].forEach(function (name) {
- var compact = name == 'tianpan-compact';
- KityMinder.registerTheme(name, {
- 'background': '#3A4144 url(ui/theme/default/images/grid.png) repeat',
- 'root-color': '#430',
- 'root-background': '#e9df98',
- 'root-stroke': '#e9df98',
- 'root-font-size': 25,
- 'root-padding': compact ? 15 : 20,
- 'root-margin': compact ? [15, 25] : 100,
- 'root-radius': 30,
- 'root-space': 10,
- 'root-shadow': 'rgba(0, 0, 0, .25)',
- 'root-shape': 'circle',
- 'main-color': '#333',
- 'main-background': '#a4c5c0',
- 'main-stroke': '#a4c5c0',
- 'main-font-size': 15,
- 'main-padding': compact ? 10 : 12,
- 'main-margin': compact ? 10 : 12,
- 'main-radius': 10,
- 'main-space': 5,
- 'main-shadow': 'rgba(0, 0, 0, .25)',
- 'main-shape': 'circle',
- 'sub-color': '#333',
- 'sub-background': '#99ca6a',
- 'sub-stroke': '#a4c5c0',
- 'sub-font-size': 13,
- 'sub-padding': 5,
- 'sub-margin': compact ? 6 : 10,
- 'sub-tree-margin': 30,
- 'sub-radius': 5,
- 'sub-space': 5,
- 'sub-shadow': 'rgba(0, 0, 0, .25)',
- 'sub-shape': 'circle',
- 'connect-color': 'white',
- 'connect-width': 2,
- 'main-connect-width': 3,
- 'connect-radius': 5,
- 'selected-background': 'rgb(254, 219, 0)',
- 'selected-stroke': 'rgb(254, 219, 0)',
- 'selected-color': 'black',
- 'marquee-background': 'rgba(255,255,255,.3)',
- 'marquee-stroke': 'white',
- 'drop-hint-color': 'yellow',
- 'sub-drop-hint-width': 2,
- 'main-drop-hint-width': 4,
- 'root-drop-hint-width': 4,
- 'order-hint-area-color': 'rgba(0, 255, 0, .5)',
- 'order-hint-path-color': '#0f0',
- 'order-hint-path-width': 1,
- 'text-selection-color': 'rgb(27,171,255)',
- 'line-height': 1.4
- });
- });
- /**
- * @fileOverview
- *
- * 默认模板 - 脑图模板
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerTemplate('default', {
- getLayout: function(node) {
- if (node.getData('layout')) return node.getData('layout');
- var level = node.getLevel();
- // 根节点
- if (level === 0) {
- return 'mind';
- }
- // 一级节点
- if (level === 1) {
- return node.getLayoutPointPreview().x > 0 ? 'right': 'left';
- }
- return node.parent.getLayout();
- },
- getConnect: function(node) {
- if (node.getLevel() == 1) return 'arc';
- return 'under';
- }
- });
- /**
- * @fileOverview
- *
- * 组织结构图模板
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerTemplate('structure', {
- getLayout: function(node) {
- return node.getData('layout') || 'bottom';
- },
- getConnect: function(node) {
- return 'poly';
- }
- });
- /**
- * @fileOverview
- *
- * 文件夹模板
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerTemplate('filetree', {
- getLayout: function(node) {
- if (node.getData('layout')) return node.getData('layout');
- if (node.isRoot()) return 'bottom';
- return 'filetree-down';
- },
- getConnect: function(node) {
- if (node.getLevel() == 1) {
- return 'poly';
- }
- return 'l';
- }
- });
- /**
- * @fileOverview
- *
- * 往右布局结构模板
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerTemplate('right', {
- getLayout: function(node) {
- return node.getData('layout') || 'right';
- },
- getConnect: function(node) {
- if (node.getLevel() == 1) return 'arc';
- return 'bezier';
- }
- });
- /**
- * @fileOverview
- *
- * 默认模板 - 鱼骨头模板
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerTemplate('fish-bone', {
- getLayout: function(node) {
- if (node.getData('layout')) return node.getData('layout');
- var level = node.getLevel();
- // 根节点
- if (level === 0) {
- return 'fish-bone-master';
- }
- // 一级节点
- if (level === 1) {
- return 'fish-bone-slave';
- }
- return node.getLayoutPointPreview().y > 0 ? 'filetree-up': 'filetree-down';
- },
- getConnect: function(node) {
- switch (node.getLevel()) {
- case 1: return 'fish-bone-master';
- case 2: return 'line';
- default: return 'l';
- }
- }
- });
- /**
- * @fileOverview
- *
- * 天盘模板
- *
- * @author: along
- * @copyright: bpd729@163.com, 2015
- */
- KityMinder.registerTemplate('tianpan', {
- getLayout: function (node) {
- if (node.getData('layout')) return node.getData('layout');
- var level = node.getLevel();
- // 根节点
- if (level === 0) {
- return 'tianpan';
- }
- return node.parent.getLayout();
- },
- getConnect: function (node) {
- return 'arc_tp';
- }
- });
- var AppendChildCommand = kity.createClass('AppendChildCommand', {
- base: Command,
- execute: function(km, text) {
- var parent = km.getSelectedNode();
- if (!parent) {
- return null;
- }
- text = text || km.getLang('topic');
- parent.expand();
- var node = km.createNode(text, parent);
- km.select(node, true);
- node.render();
- km.layout(600);
- },
- queryState: function(km) {
- var selectedNode = km.getSelectedNode();
- return selectedNode ? 0 : -1;
- }
- });
- var AppendSiblingCommand = kity.createClass('AppendSiblingCommand', {
- base: Command,
- execute: function(km, text) {
- var sibling = km.getSelectedNode();
- var parent = sibling.parent;
- if (!parent) {
- return km.execCommand('AppendChildNode', text);
- }
- text = text || km.getLang('topic');
- var node = km.createNode(text, parent, sibling.getIndex() + 1);
- km.select(node, true);
- node.render();
- km.layout(600);
- },
- queryState: function(km) {
- var selectedNode = km.getSelectedNode();
- return selectedNode ? 0 : -1;
- }
- });
- var RemoveNodeCommand = kity.createClass('RemoverNodeCommand', {
- base: Command,
- execute: function(km, text) {
- var nodes = km.getSelectedNodes();
- var ancestor = MinderNode.getCommonAncestor.apply(null, nodes);
- nodes.forEach(function(node) {
- if (!node.isRoot()) km.removeNode(node);
- });
- km.select(ancestor || km.getRoot(), true);
- km.layout(600);
- },
- queryState: function(km) {
- var selectedNode = km.getSelectedNode();
- return selectedNode ? 0 : -1;
- }
- });
- var EditNodeCommand = kity.createClass('EditNodeCommand', {
- base: Command,
- execute: function(km) {
- var selectedNode = km.getSelectedNode();
- if (!selectedNode) {
- return null;
- }
- km.select(selectedNode, true);
- km.textEditNode(selectedNode);
- },
- queryState: function(km) {
- var selectedNode = km.getSelectedNode();
- if (!selectedNode) {
- return -1;
- }
- else {
- return 0;
- }
- },
- isNeedUndo: function() {
- return false;
- }
- });
- var $importDialog;
- var $exportDialog;
- var ImportTextNode = kity.createClass('ImportTextNode', {
- base: Command,
- execute: function(km, text) {
- if (!$importDialog) {
- var plainProtocol = km.getProtocol('plain');
- var height = 400;
- $importDialog = new FUI.Dialog({
- width: 600,
- height: height,
- prompt: true,
- caption: km.getLang('ui.importtextnode')
- }).appendTo(document.getElementById('content-wrapper'));
- var $dialogBody = $($importDialog.getBodyElement());
- $dialogBody.html([
- '<textarea style="width: 100%; height: ' + (height - 130) + 'px"></textarea>'
- ].join(''));
- var $editor = $dialogBody.find('textarea');
- var $ok = $importDialog.getButton(0);
- var $errorMsg = $('<span class="validate-error"></span>');
- var rootNode;
- function check(value) {
- var error;
- if (!value) {
- error = '内容不能为空';
- }
- else {
- try {
- rootNode = plainProtocol.decode(value, true);
- }
- catch (ex) {
- error = '文本格式解析错误. ' + ex.message;
- }
- }
- if (error) {
- $editor.addClass('validate-error');
- $errorMsg.text(error);
- $ok.disable();
- }
- else {
- $editor.removeClass('validate-error');
- $errorMsg.text('');
- $ok.enable();
- }
- }
- $editor.after($errorMsg);
- $editor.on('input', function() {
- check($editor.val());
- });
- $editor.on('keydown keyup', function(e) {
- if (e.keyCode === 9 && e.type === 'keydown') {
- e.preventDefault();
- var s = this.selectionStart;
- this.value = this.value.substring(0, this.selectionStart) + '\t' +
- this.value.substring(this.selectionEnd);
- this.selectionEnd = s + 1;
- }
- if (e.keyCode === 13 && !e.shiftKey) {
- return;
- }
- e.stopPropagation();
- });
- $importDialog.on('open', function() {
- check($editor.val());
- setTimeout(function() {
- $editor[0].focus();
- }, 10);
- });
- $importDialog.on('ok', function() {
- var _selectedNodes = [];
- function appendChild(parent, child, index) {
- if (!parent || !child) {
- return;
- }
- var kmNode = km.createNode(child.data.text, parent);
- if (child.children) {
- child.children.forEach(function(item) {
- appendChild(kmNode, item);
- });
- }
- kmNode.render();
- return kmNode;
- }
- var selectedNode = km.getSelectedNode();
- if (rootNode && rootNode.children && selectedNode) {
- selectedNode.expand();
- rootNode.children.forEach(function(child) {
- _selectedNodes.push(appendChild(selectedNode, child));
- });
- }
- km.select(_selectedNodes, true);
- km.layout(300);
- $editor.val('');
- _selectedNodes = null;
- rootNode = null;
- });
- }
- $importDialog.open();
- },
- queryState: function(km) {
- var selectedNode = km.getSelectedNode();
- return selectedNode ? 0 : -1;
- }
- });
- var ExportTextNode = kity.createClass('ExportTextNode', {
- base: Command,
- execute: function(km, text) {
- if (!$exportDialog) {
- var plainProtocol = km.getProtocol('plain');
- var height = 400;
- $exportDialog = new FUI.Dialog({
- width: 600,
- height: height,
- prompt: true,
- caption: km.getLang('ui.exporttextnode')
- }).appendTo(document.getElementById('content-wrapper'));
- var $dialogBody = $($exportDialog.getBodyElement());
- $dialogBody.html([
- '<textarea style="width: 100%; height: ' + (height - 130) + 'px"></textarea>'
- ].join(''));
- var $editor = $dialogBody.find('textarea');
- $editor.on('keydown keyup', function(e) {
- if (e.keyCode === 9 && e.type === 'keydown') {
- e.preventDefault();
- var s = this.selectionStart;
- this.value = this.value.substring(0, this.selectionStart) + '\t' +
- this.value.substring(this.selectionEnd);
- this.selectionEnd = s + 1;
- }
- if (e.keyCode === 13 && !e.shiftKey) {
- return;
- }
- e.stopPropagation();
- });
- $exportDialog.on('open', function() {
- $editor.val(plainProtocol.encode(km.getSelectedNode()));
- setTimeout(function() {
- $editor[0].focus();
- }, 10);
- });
- }
- $exportDialog.open();
- },
- queryState: function(km) {
- var selectedNode = km.getSelectedNode();
- return selectedNode ? 0 : -1;
- }
- });
- KityMinder.registerModule('NodeModule', function() {
- return {
- commands: {
- 'AppendChildNode': AppendChildCommand,
- 'AppendSiblingNode': AppendSiblingCommand,
- 'ImportTextNode': ImportTextNode,
- 'ExportTextNode': ExportTextNode,
- 'RemoveNode': RemoveNodeCommand,
- 'EditNode': EditNodeCommand
- },
- 'contextmenu': [{
- command: 'appendsiblingnode'
- }, {
- command: 'appendchildnode'
- }, {
- command: 'editnode'
- }, {
- command: 'removenode'
- }, {
- command: 'importtextnode'
- }, {
- command: 'exporttextnode'
- }, {
- divider: 1
- }],
- 'commandShortcutKeys': {
- 'appendsiblingnode': 'normal::Enter',
- 'appendchildnode': 'normal::Insert|Tab',
- 'editnode': 'normal::F2',
- 'removenode': 'normal::Del|Backspace'
- }
- };
- });
- /* global Renderer: true */
- var FONT_ADJUST = {
- '微软雅黑,Microsoft YaHei': -0.15,
- 'arial black,avant garde': -0.17,
- 'default': -0.15
- };
- var TextRenderer = KityMinder.TextRenderer = kity.createClass('TextRenderer', {
- base: Renderer,
- create: function() {
- return new kity.Group().setId(KityMinder.uuid('node_text'));
- },
- update: function(textGroup, node) {
- function s(name) {
- return node.getData(name) || node.getStyle(name);
- }
- var textArr = node.getText(true);
- var lineHeight = node.getStyle('line-height');
- var fontSize = s('font-size');
- var fontFamily = s('font-family') || 'default';
- var height = (lineHeight * fontSize) * textArr.length - (lineHeight - 1) * fontSize;
- var yStart = -height / 2;
- var adjust = FONT_ADJUST[fontFamily] || 0;
- textGroup.setTranslate(0, adjust * fontSize);
- var rBox = new kity.Box(),
- r = Math.round;
- this.setTextStyle(node, textGroup);
- var textLength = textArr.length;
- var textGroupLength = textGroup.getItems().length;
- if(textLength < textGroupLength){
- for( var i = textLength,ci;ci = textGroup.getItem(i);){
- textGroup.removeItem(i);
- }
- }else if(textLength > textGroupLength){
- var length = textLength - textGroupLength;
- for(var i = 0;i < length;i++){
- var textShape = new kity.Text()
- .setAttr('text-rendering', 'inherit');
- if (kity.Browser.ie) {
- textShape.setVerticalAlign('top');
- } else {
- textShape.setAttr('dominant-baseline', 'text-before-edge');
- }
- textGroup.addItem(textShape);
- }
- }
- for (var i = 0, text, textShape;
- (text = textArr[i], textShape = textGroup.getItem(i)); i++) {
- textShape.setContent(text);
- }
- this.setTextStyle(node, textGroup);
- var textHash = node.getText() + [s('font-size'), s('font-name'), s('font-weight'), s('font-style')].join('/');
- if (node._currentTextHash == textHash && node._currentTextGroupBox) return node._currentTextGroupBox;
- node._currentTextHash = textHash;
- return function() {
- textGroup.eachItem(function(i, textShape) {
- var y = yStart + i * fontSize * lineHeight;
- textShape.setY(y);
- rBox = rBox.merge(new kity.Box(0, y, textShape.getBoundaryBox().width || 1, fontSize));
- });
- //为了让文字在圆中垂直居中
- var w = 0;
- var shape = node.getStyle('shape');
- if(shape && shape=='circle'){
- w = Math.max(rBox.width,rBox.height)/2-rBox.height/2;
- }
- var nBox = new kity.Box(r(rBox.x), r(rBox.y-w), r(rBox.width), r(rBox.height));
- node._currentTextGroupBox = nBox;
- return nBox;
- };
- },
- setTextStyle: function(node, text) {
- var hooks = TextRenderer._styleHooks;
- hooks.forEach(function(hook) {
- hook(node, text);
- });
- }
- });
- utils.extend(TextRenderer, {
- _styleHooks: [],
- registerStyleHook: function(fn) {
- TextRenderer._styleHooks.push(fn);
- }
- });
- kity.extendClass(MinderNode, {
- getTextGroup: function() {
- return this.getRenderer('TextRenderer').getRenderShape();
- }
- });
- KityMinder.registerModule('text', {
- 'renderers': {
- center: TextRenderer
- }
- });
- /* global Renderer: true */
- KityMinder.registerModule('Expand', function() {
- var minder = this;
- var EXPAND_STATE_DATA = 'expandState',
- STATE_EXPAND = 'expand',
- STATE_COLLAPSE = 'collapse';
- // 将展开的操作和状态读取接口拓展到 MinderNode 上
- kity.extendClass(MinderNode, {
- /**
- * 展开节点
- * @param {Policy} policy 展开的策略,默认为 KEEP_STATE
- */
- expand: function() {
- this.setData(EXPAND_STATE_DATA, STATE_EXPAND);
- return this;
- },
- /**
- * 收起节点
- */
- collapse: function() {
- this.setData(EXPAND_STATE_DATA, STATE_COLLAPSE);
- return this;
- },
- /**
- * 判断节点当前的状态是否为展开
- */
- isExpanded: function() {
- var expanded = this.getData(EXPAND_STATE_DATA) !== STATE_COLLAPSE;
- return expanded && (this.isRoot() || this.parent.isExpanded());
- },
- /**
- * 判断节点当前的状态是否为收起
- */
- isCollapsed: function() {
- return !this.isExpanded();
- }
- });
- var ExpandCommand = kity.createClass('ExpandCommand', {
- base: Command,
- execute: function(km, justParents) {
- var node = km.getSelectedNode();
- if (!node) return;
- if (justParents) {
- node = node.parent;
- }
- while(node.parent) {
- node.expand();
- node = node.parent;
- }
- node.renderTree();
- km.layout(100);
- },
- queryState: function(km) {
- return km.getSelectedNode() ? 0 : -1;
- }
- });
- var ExpandToLevelCommand = kity.createClass('ExpandToLevelCommand', {
- base: Command,
- execute: function(km, level) {
- km.getRoot().traverse(function(node) {
- if (node.getLevel() < level) node.expand();
- if (node.getLevel() == level) node.collapse();
- });
- km.refresh(100);
- },
- enableReadOnly: true
- });
- var Expander = kity.createClass('Expander', {
- base: kity.Group,
- constructor: function(node) {
- this.callBase();
- this.radius = 6;
- this.outline = new kity.Circle(this.radius).stroke('gray').fill('white');
- this.sign = new kity.Path().stroke('gray');
- this.addShapes([this.outline, this.sign]);
- this.initEvent(node);
- this.setId(KityMinder.uuid('node_expander'));
- this.setStyle('cursor', 'pointer');
- },
- initEvent: function(node) {
- this.on('mousedown', function(e) {
- if (node.isExpanded()) {
- node.collapse();
- } else {
- node.expand();
- }
- node.renderTree().getMinder().layout(100);
- node.getMinder().fire('contentchange');
- e.stopPropagation();
- e.preventDefault();
- });
- this.on('dblclick click mouseup', function(e) {
- e.stopPropagation();
- e.preventDefault();
- });
- },
- setState: function(state) {
- if (state == 'hide') {
- this.setVisible(false);
- return;
- }
- this.setVisible(true);
- var pathData = ['M', 1.5 - this.radius, 0, 'L', this.radius - 1.5, 0];
- if (state == STATE_COLLAPSE) {
- pathData.push(['M', 0, 1.5 - this.radius, 'L', 0, this.radius - 1.5]);
- }
- this.sign.setPathData(pathData);
- }
- });
- var ExpanderRenderer = kity.createClass('ExpanderRenderer', {
- base: Renderer,
- create: function(node) {
- if (node.isRoot()) return;
- this.expander = new Expander(node);
- node.getRenderContainer().prependShape(this.expander);
- node.expanderRenderer = this;
- this.node = node;
- return this.expander;
- },
- shouldRender: function(node) {
- return !node.isRoot();
- },
- update: function(expander, node, box) {
- if (!node.parent) return;
- var visible = node.parent.isExpanded();
- expander.setState(visible && node.children.length ? node.getData(EXPAND_STATE_DATA) : 'hide');
- var vector = node.getLayoutVectorIn().normalize(expander.radius + node.getStyle('stroke-width'));
- var position = node.getVertexIn().offset(vector.reverse());
- this.expander.setTranslate(position);
- }
- });
- return {
- commands: {
- 'expand': ExpandCommand,
- 'expandtolevel': ExpandToLevelCommand
- },
- events: {
- 'layoutapply': function(e) {
- var r = e.node.getRenderer('ExpanderRenderer');
- if (r.getRenderShape()) {
- r.update(r.getRenderShape(), e.node);
- }
- },
- 'beforerender': function(e) {
- var node = e.node;
- var visible = !node.parent || node.parent.isExpanded();
- var minder = this;
- node.getRenderContainer().setVisible(visible);
- if (!visible) e.stopPropagation();
- },
- 'normal.keydown': function(e) {
- if (this.getStatus() == 'textedit') return;
- if (e.originEvent.keyCode == keymap['/']) {
- var node = this.getSelectedNode();
- if (!node || node == this.getRoot()) return;
- var expanded = node.isExpanded();
- this.getSelectedNodes().forEach(function(node) {
- if (expanded) node.collapse();
- else node.expand();
- node.renderTree();
- });
- this.layout(100);
- this.fire('contentchange');
- e.preventDefault();
- e.stopPropagationImmediately();
- }
- if (e.isShortcutKey('Alt+`')) {
- this.execCommand('expandtolevel', 9999);
- }
- for (var i = 1; i < 6; i++) {
- if (e.isShortcutKey('Alt+' + i)) {
- this.execCommand('expandtolevel', i);
- }
- }
- }
- },
- renderers: {
- outside: ExpanderRenderer
- },
- contextmenu: [{
- command: 'expandtoleaf',
- query: function() {
- return !minder.getSelectedNode();
- },
- fn: function(minder) {
- minder.execCommand('expandtolevel', 9999);
- }
- }, {
- command: 'expandtolevel1',
- query: function() {
- return !minder.getSelectedNode();
- },
- fn: function(minder) {
- minder.execCommand('expandtolevel', 1);
- }
- }, {
- command: 'expandtolevel2',
- query: function() {
- return !minder.getSelectedNode();
- },
- fn: function(minder) {
- minder.execCommand('expandtolevel', 2);
- }
- },{
- command: 'expandtolevel3',
- query: function() {
- return !minder.getSelectedNode();
- },
- fn: function(minder) {
- minder.execCommand('expandtolevel', 3);
- }
- }, {
- divider: true
- }]
- };
- });
- /* global Renderer: true */
- var OutlineRenderer = kity.createClass('OutlineRenderer', {
- base: Renderer,
- create: function(node) {
- var outline = new kity.Rect()
- .setId(KityMinder.uuid('node_outline'));
- this.bringToBack = true;
- return outline;
- },
- update: function(outline, node, box) {
- //增加圆形update、待更好解决方案
- var shape = node.getStyle('shape');
- if(shape){
- if(shape=='circle'){
- return updateCircle(outline, node, box);
- }
- }
- var paddingLeft = node.getStyle('padding-left'),
- paddingRight = node.getStyle('padding-right'),
- paddingTop = node.getStyle('padding-top'),
- paddingBottom = node.getStyle('padding-bottom');
- var outlineBox = {
- x: box.x - paddingLeft,
- y: box.y - paddingTop,
- width: box.width + paddingLeft + paddingRight,
- height: box.height + paddingTop + paddingBottom
- };
- var prefix = node.isSelected() ? 'selected-' : '';
- outline
- .setPosition(outlineBox.x, outlineBox.y)
- .setSize(outlineBox.width, outlineBox.height)
- .setRadius(node.getStyle('radius'))
- .fill(node.getData('background') || node.getStyle(prefix + 'background') || node.getStyle('background'))
- .stroke(node.getStyle(prefix + 'stroke' || node.getStyle('stroke')),
- node.getStyle(prefix + 'stroke-width'));
- return new kity.Box(outlineBox);
- }
- });
- //圆
- function updateCircle(outline, node, box){
- var paddingLeft = node.getStyle('padding-left'),
- paddingRight = node.getStyle('padding-right'),
- paddingTop = node.getStyle('padding-top'),
- paddingBottom = node.getStyle('padding-bottom');
- var width= Math.max(box.width,box.height);
- var outlineBox = {
- x: box.x - paddingLeft,
- y: box.y - paddingTop,
- width: width + paddingLeft + paddingRight,
- height: width + paddingTop + paddingBottom
- };
- var prefix = node.isSelected() ? 'selected-' : '';
- width= Math.max(outlineBox.width,outlineBox.height);
- outline
- .setPosition(outlineBox.x, outlineBox.y)
- .setSize(width, width)
- .setRadius(width/2)
- .fill(node.getData('background') || node.getStyle(prefix + 'background') || node.getStyle('background'))
- .stroke(node.getStyle(prefix + 'stroke' || node.getStyle('stroke')),
- node.getStyle(prefix + 'stroke-width'));
- return new kity.Box(outlineBox);
- }
- var ShadowRenderer = kity.createClass('ShadowRenderer', {
- base: Renderer,
- create: function(node) {
- this.bringToBack = true;
- return new kity.Rect();
- },
- shouldRender: function(node) {
- return node.getStyle('shadow');
- },
- update: function(shadow, node, box) {
- shadow.setPosition(box.x + 4, box.y + 5)
- .fill(node.getStyle('shadow'));
- var shape = node.getStyle('shape');
- if(!shape){
- shadow.setSize(box.width, box.height)
- shadow.setRadius(node.getStyle('radius'));
- }else if(shape=='circle'){
- var width= Math.max(box.width,box.height);
- shadow.setSize(width, width)
- shadow.setRadius(width/2);
- }
- }
- });
- var marker = new kity.Marker();
- marker.setWidth(10);
- marker.setHeight(12);
- marker.setRef(0, 0);
- marker.setViewBox(-6, -4, 8, 10);
- marker.addShape(new kity.Path().setPathData('M-5-3l5,3,-5,3').stroke('#33ffff'));
- var wireframeOption = /wire/.test(window.location.href);
- var WireframeRenderer = kity.createClass('WireframeRenderer', {
- base: Renderer,
- create: function() {
- var wireframe = new kity.Group();
- var oxy = this.oxy = new kity.Path()
- .stroke('#f6f')
- .setPathData('M0,-50L0,50M-50,0L50,0');
- var box = this.wireframe = new kity.Rect()
- .stroke('lightgreen');
- var vectorIn = this.vectorIn = new kity.Path()
- .stroke('#66ffff');
- var vectorOut = this.vectorOut = new kity.Path()
- .stroke('#66ffff');
- vectorIn.setMarker(marker, 'end');
- vectorOut.setMarker(marker, 'end');
- return wireframe.addShapes([oxy, box, vectorIn, vectorOut]);
- },
- shouldRender: function() {
- return wireframeOption;
- },
- update: function(created, node, box) {
- this.wireframe
- .setPosition(box.x, box.y)
- .setSize(box.width, box.height);
- var pin = node.getVertexIn();
- var pout = node.getVertexOut();
- var vin = node.getLayoutVectorIn().normalize(30);
- var vout = node.getLayoutVectorOut().normalize(30);
- this.vectorIn.setPathData(['M', pin.offset(vin.reverse()), 'L', pin]);
- this.vectorOut.setPathData(['M', pout, 'l', vout]);
- }
- });
- KityMinder.registerModule('OutlineModule', function() {
- return {
- events: (!wireframeOption ? null : {
- 'ready': function() {
- this.getPaper().addResource(marker);
- },
- 'layoutallfinish': function() {
- this.getRoot().traverse(function(node) {
- node.getRenderer('WireframeRenderer').update(null, node, node.getContentBox());
- });
- }
- }),
- renderers: {
- outline: OutlineRenderer,
- outside: [ShadowRenderer, WireframeRenderer]
- }
- };
- });
- KityMinder.Geometry = (function() {
- var g = {};
- var min = Math.min,
- max = Math.max,
- abs = Math.abs;
- var own = Object.prototype.hasOwnProperty;
- g.isNumberInRange = function(number, range) {
- return number > range[0] && number < range[1];
- };
- g.getDistance = function(p1, p2) {
- return kity.Vector.fromPoints(p1, p2).length();
- };
- function wrapBox(box) {
- box.width = box.right - box.left;
- box.height = box.bottom - box.top;
- box.x = box.left;
- box.y = box.top;
- box.cx = box.x + box.width / 2;
- box.cy = box.y + box.height / 2;
- return box;
- }
- function uniformBox(box) {
- // duck check
- if ('x' in box) {
- box.left = box.x;
- box.right = box.x + box.width;
- box.top = box.y;
- box.bottom = box.y + box.height;
- }
- }
- g.wrapBox = wrapBox;
- g.getBox = function(p1, p2) {
- return wrapBox({
- left: min(p1.x, p2.x),
- right: max(p1.x, p2.x),
- top: min(p1.y, p2.y),
- bottom: max(p1.y, p2.y)
- });
- };
- g.mergeBox = function(b1, b2) {
- uniformBox(b1);
- uniformBox(b2);
- return wrapBox({
- left: min(b1.left, b2.left),
- right: max(b1.right, b2.right),
- top: min(b1.top, b2.top),
- bottom: max(b1.bottom, b2.bottom)
- });
- };
- g.getBoxRange = function(box) {
- return {
- x: [box.left, box.right],
- y: [box.top, box.bottom]
- };
- };
- g.getBoxVertex = function(box) {
- return {
- leftTop: {
- x: box.left,
- y: box.top
- },
- rightTop: {
- x: box.right,
- y: box.top
- },
- leftBottom: {
- x: box.left,
- y: box.bottom
- },
- rightBottom: {
- x: box.right,
- y: box.bottom
- }
- };
- };
- g.isPointInsideBox = function(p, b) {
- uniformBox(b);
- var ranges = g.getBoxRange(b);
- return g.isNumberInRange(p.x, ranges.x) && g.isNumberInRange(p.y, ranges.y);
- };
- g.getIntersectBox = function(b1, b2) {
- uniformBox(b1);
- uniformBox(b2);
- var minx = max(b1.left, b2.left),
- miny = max(b1.top, b2.top),
- maxx = min(b1.right, b2.right),
- maxy = min(b1.bottom, b2.bottom);
- return minx < maxx && miny < maxy ? wrapBox({
- left: minx,
- right: maxx,
- top: miny,
- bottom: maxy
- }) : null;
- };
- g.snapToSharp = function(unknown) {
- if (utils.isNumber(unknown)) {
- return (unknown | 0) + 0.5;
- }
- if (utils.isArray(unknown)) {
- return unknown.map(g.snapToSharp);
- }
- ['x', 'y', 'left', 'top', 'right', 'bottom'].forEach(function(n) {
- if (own.call(unknown, n)) {
- unknown[n] = g.snapToSharp(unknown[n]);
- }
- });
- return unknown;
- };
- g.expandBox = function(box, sizeX, sizeY) {
- if (sizeY === undefined) {
- sizeY = sizeX;
- }
- return wrapBox({
- left: box.left - sizeX,
- top: box.top - sizeY,
- right: box.right + sizeX,
- bottom: box.bottom + sizeY
- });
- };
- return g;
- })();
- KityMinder.registerModule("HistoryModule", function() {
- var km = this;
- var Scene = kity.createClass('Scene', {
- constructor: function(root,inputStatus) {
- this.data = root.clone();
- this.inputStatus = inputStatus;
- },
- getData: function() {
- return this.data;
- },
- cloneData: function() {
- return this.getData().clone();
- },
- equals: function(scene) {
- return this.getData().equals(scene.getData());
- },
- isInputStatus:function(){
- return this.inputStatus;
- },
- setInputStatus:function(status){
- this.inputStatus = status;
- }
- });
- var HistoryManager = kity.createClass('HistoryManager', {
- constructor: function(km) {
- this.list = [];
- this.index = 0;
- this.hasUndo = false;
- this.hasRedo = false;
- this.km = km;
- },
- undo: function() {
- if (this.hasUndo) {
- var currentScene = this.list[this.index];
- //如果是输入文字时的保存,直接回复当前场景
- if(currentScene && currentScene.isInputStatus()){
- this.saveScene();
- this.restore(--this.index);
- currentScene.setInputStatus(false);
- return;
- }
- if(this.list.length == 1){
- this.restore(0);
- return;
- }
- if (!this.list[this.index - 1] && this.list.length == 1) {
- this.reset();
- return;
- }
- while (this.list[this.index].equals(this.list[this.index - 1])) {
- this.index--;
- if (this.index === 0) {
- return this.restore(0);
- }
- }
- this.restore(--this.index);
- }
- },
- redo: function() {
- if (this.hasRedo) {
- while (this.list[this.index].equals(this.list[this.index + 1])) {
- this.index++;
- if (this.index == this.list.length - 1) {
- return this.restore(this.index);
- }
- }
- this.restore(++this.index);
- }
- },
- partialRenewal: function(target) {
- var selectedNodes = [];
- function compareNode(source, target) {
- if (source.getText() != target.getText()) {
- return false;
- }
- if (utils.compareObject(source.getData(), target.getData()) === false) {
- return false;
- }
- if (utils.compareObject(source.getTmpData(), target.getTmpData()) === false) {
- return false;
- }
- return true;
- }
- function appendChildNode(parent, child) {
- if (child.isSelected()) {
- selectedNodes.push(child);
- }
- km.appendNode(child, parent);
- child.render();
- var children = utils.cloneArr(child.children);
- for (var i = 0, ci; ci = children[i++];) {
- appendChildNode(child, ci);
- }
- }
- function traverseNode(srcNode, tagNode) {
- if (compareNode(srcNode, tagNode) === false) {
- srcNode.setValue(tagNode);
- }
- //todo,这里有性能问题,变成全部render了
- srcNode.render();
- if (srcNode.isSelected()) {
- selectedNodes.push(srcNode);
- }
- for (var i = 0, j = 0, si, tj;
- (si = srcNode.children[i], tj = tagNode.children[j], si || tj); i++, j++) {
- if (si && !tj) {
- i--;
- km.removeNode(si);
- } else if (!si && tj) {
- j--;
- appendChildNode(srcNode, tj);
- } else {
- traverseNode(si, tj);
- }
- }
- }
- traverseNode(km.getRoot(), target);
- km.layout(200);
- km.select(selectedNodes,true);
- selectedNodes = [];
- },
- restore: function(index) {
- index = index === undefined ? this.index : index;
- var scene = this.list[index];
- this.partialRenewal(scene.cloneData());
- this.update();
- this.km.fire('restoreScene');
- this.km.fire('contentChange');
- },
- getScene: function(inputStatus) {
- return new Scene(this.km.getRoot(),inputStatus);
- },
- saveScene: function(inputStatus) {
- var currentScene = this.getScene(inputStatus);
- var lastScene = this.list[this.index];
- if (lastScene && lastScene.equals(currentScene)) {
- if(inputStatus){
- lastScene.setInputStatus(true);
- this.update();
- }
- return;
- }
- this.list = this.list.slice(0, this.index + 1);
- this.list.push(currentScene);
- //如果大于最大数量了,就把最前的剔除
- if (this.list.length > this.km.getOptions('maxUndoCount')) {
- this.list.shift();
- }
- this.index = this.list.length - 1;
- //跟新undo/redo状态
- this.update();
- },
- update: function() {
- this.hasRedo = !!this.list[this.index + 1];
- this.hasUndo = !!this.list[this.index - 1];
- var currentScene = this.list[this.index];
- if(currentScene && currentScene.isInputStatus()){
- this.hasUndo = true;
- }
- },
- reset: function() {
- this.list = [];
- this.index = 0;
- this.hasUndo = false;
- this.hasRedo = false;
- }
- });
- //为km实例添加history管理
- this.historyManager = new HistoryManager(this);
- return {
- defaultOptions: {
- maxUndoCount: 20,
- maxInputCount: 20
- },
- "commands": {
- "undo": kity.createClass("UndoCommand", {
- base: Command,
- execute: function(km) {
- km.historyManager.undo();
- },
- queryState: function(km) {
- return km.historyManager.hasUndo ? 0 : -1;
- },
- isNeedUndo: function() {
- return false;
- }
- }),
- "redo": kity.createClass("RedoCommand", {
- base: Command,
- execute: function(km) {
- km.historyManager.redo();
- },
- queryState: function(km) {
- return km.historyManager.hasRedo ? 0 : -1;
- },
- isNeedUndo: function() {
- return false;
- }
- })
- },
- commandShortcutKeys: {
- "undo": "ctrl+z", //undo
- "redo": "ctrl+y" //redo
- },
- "events": {
- "saveScene": function(e) {
- this.historyManager.saveScene(e.inputStatus);
- },
- "import": function() {
- this.historyManager.reset();
- }
- }
- };
- });
- KityMinder.registerModule('ProgressModule', function() {
- var minder = this;
- var PROGRESS_DATA = 'progress';
- // Designed by Akikonata
- var BG_COLOR = '#FFED83';
- var PIE_COLOR = '#43BC00';
- var SHADOW_PATH = 'M10,3c4.418,0,8,3.582,8,8h1c0-5.523-3.477-10-9-10S1,5.477,1,11h1C2,6.582,5.582,3,10,3z';
- var SHADOW_COLOR = '#8E8E8E';
- var FRAME_PATH = 'M10,0C4.477,0,0,4.477,0,10c0,5.523,4.477,10,10,10s10-4.477,10-10C20,4.477,15.523,0,10,0zM10,18c-4.418,0-8-3.582-8-8s3.582-8,8-8s8,3.582,8,8S14.418,18,10,18z';
- var FRAME_GRAD = new kity.LinearGradient().pipe(function(g) {
- g.setStartPosition(0, 0);
- g.setEndPosition(0, 1);
- g.addStop(0, '#fff');
- g.addStop(1, '#ccc');
- });
- var CHECK_PATH = 'M15.812,7.896l-6.75,6.75l-4.5-4.5L6.25,8.459l2.812,2.803l5.062-5.053L15.812,7.896z';
- var CHECK_COLOR = '#EEE';
- minder.getPaper().addResource(FRAME_GRAD);
- // 进度图标的图形
- var ProgressIcon = kity.createClass('ProgressIcon', {
- base: kity.Group,
- constructor: function(value) {
- this.callBase();
- this.setSize(20);
- this.create();
- this.setValue(value);
- this.setId(KityMinder.uuid('node_progress'));
- this.translate(0.5, 0.5);
- },
- setSize: function(size) {
- this.width = this.height = size;
- },
- create: function() {
- var bg, pie, shadow, frame, check;
- bg = new kity.Circle(9)
- .fill(BG_COLOR);
- pie = new kity.Pie(9, 0)
- .fill(PIE_COLOR);
- shadow = new kity.Path()
- .setPathData(SHADOW_PATH)
- .setTranslate(-10, -10)
- .fill(SHADOW_COLOR);
- frame = new kity.Path()
- .setTranslate(-10, -10)
- .setPathData(FRAME_PATH)
- .fill(FRAME_GRAD);
- check = new kity.Path()
- .setTranslate(-10, -10)
- .setPathData(CHECK_PATH)
- .fill(CHECK_COLOR);
- this.addShapes([bg, pie, shadow, check, frame]);
- this.pie = pie;
- this.check = check;
- },
- setValue: function(value) {
- this.pie.setAngle(-360 * (value - 1) / 8);
- this.check.setVisible(value == 9);
- }
- });
- var ProgressCommand = kity.createClass('ProgressCommand', {
- base: Command,
- execute: function(km, value) {
- var nodes = km.getSelectedNodes();
- for (var i = 0; i < nodes.length; i++) {
- nodes[i].setData(PROGRESS_DATA, value || null).render();
- }
- km.layout();
- },
- queryValue: function(km) {
- var nodes = km.getSelectedNodes();
- var val;
- for (var i = 0; i < nodes.length; i++) {
- val = nodes[i].getData(PROGRESS_DATA);
- if (val) break;
- }
- return val|| null;
- },
- queryState: function(km) {
- return km.getSelectedNodes().length ? 0 : -1;
- }
- });
- return {
- 'commands': {
- 'progress': ProgressCommand
- },
- 'renderers': {
- left: kity.createClass('ProgressRenderer', {
- base: KityMinder.Renderer,
- create: function(node) {
- return new ProgressIcon();
- },
- shouldRender: function(node) {
- return node.getData(PROGRESS_DATA);
- },
- update: function(icon, node, box) {
- var data = node.getData(PROGRESS_DATA);
- var spaceLeft = node.getStyle('space-left');
- var x, y;
- icon.setValue(data);
- x = box.left - icon.width - spaceLeft;
- y = -icon.height / 2;
- icon.setTranslate(x + icon.width / 2, y + icon.height / 2);
- return new kity.Box(x, y, icon.width, icon.height);
- }
- })
- }
- };
- });
- KityMinder.registerModule('PriorityModule', function() {
- var minder = this;
- // Designed by Akikonata
- // [MASK, BACK]
- var PRIORITY_COLORS = [null,
- ['#FF1200', '#840023'], // 1 - red
- ['#0074FF', '#01467F'], // 2 - blue
- ['#00AF00', '#006300'], // 3 - green
- ['#FF962E', '#B25000'], // 4 - orange
- ['#A464FF', '#4720C4'], // 5 - purple
- ['#A3A3A3', '#515151'], // 6,7,8,9 - gray
- ['#A3A3A3', '#515151'],
- ['#A3A3A3', '#515151'],
- ['#A3A3A3', '#515151'],
- ]; // hue from 1 to 5
- var BACK_PATH = 'M0,13c0,3.866,3.134,7,7,7h6c3.866,0,7-3.134,7-7V7H0V13z';
- var MASK_PATH = 'M20,10c0,3.866-3.134,7-7,7H7c-3.866,0-7-3.134-7-7V7c0-3.866,3.134-7,7-7h6c3.866,0,7,3.134,7,7V10z';
- var PRIORITY_DATA = 'priority';
- // 进度图标的图形
- var PriorityIcon = kity.createClass('PriorityIcon', {
- base: kity.Group,
- constructor: function() {
- this.callBase();
- this.setSize(20);
- this.create();
- this.setId(KityMinder.uuid('node_priority'));
- },
- setSize: function(size) {
- this.width = this.height = size;
- },
- create: function() {
- var white, back, mask, number; // 4 layer
- white = new kity.Path().setPathData(MASK_PATH).fill('white');
- back = new kity.Path().setPathData(BACK_PATH).setTranslate(0.5, 0.5);
- mask = new kity.Path().setPathData(MASK_PATH).setOpacity(0.8).setTranslate(0.5, 0.5);
- number = new kity.Text()
- .setX(this.width / 2 - 0.5).setY(this.height / 2 - 1.5)
- .setTextAnchor('middle')
- .setVerticalAlign('middle')
- .setFontItalic(true)
- .setFontSize(14)
- .fill('white');
- this.addShapes([back, mask, number]);
- this.mask = mask;
- this.back = back;
- this.number = number;
- },
- setValue: function(value) {
- var back = this.back,
- mask = this.mask,
- number = this.number;
- var color = PRIORITY_COLORS[value];
- if (color) {
- back.fill(color[1]);
- mask.fill(color[0]);
- }
- number.setContent(value);
- }
- });
- // 提供的命令
- var PriorityCommand = kity.createClass('SetPriorityCommand', {
- base: Command,
- execute: function(km, value) {
- var nodes = km.getSelectedNodes();
- for (var i = 0; i < nodes.length; i++) {
- nodes[i].setData(PRIORITY_DATA, value || null).render();
- }
- km.layout();
- },
- queryValue: function(km) {
- var nodes = km.getSelectedNodes();
- var val;
- for (var i = 0; i < nodes.length; i++) {
- val = nodes[i].getData(PRIORITY_DATA);
- if (val) break;
- }
- return val || null;
- },
- queryState: function(km) {
- return km.getSelectedNodes().length ? 0 : -1;
- }
- });
- return {
- 'commands': {
- 'priority': PriorityCommand,
- },
- 'renderers': {
- left: kity.createClass('PriorityRenderer', {
- base: KityMinder.Renderer,
- create: function(node) {
- return new PriorityIcon();
- },
- shouldRender: function(node) {
- return node.getData(PRIORITY_DATA);
- },
- update: function(icon, node, box) {
- var data = node.getData(PRIORITY_DATA);
- var spaceLeft = node.getStyle('space-left'),
- x, y;
- icon.setValue(data);
- x = box.left - icon.width - spaceLeft;
- y = -icon.height / 2;
- icon.setTranslate(x, y);
- return new kity.Box({
- x: x,
- y: y,
- width: icon.width,
- height: icon.height
- });
- }
- })
- }
- };
- });
- KityMinder.registerModule('image', function() {
- function loadImageSize(url, callback) {
- var img = document.createElement('img');
- img.onload = function() {
- callback(img.width, img.height);
- };
- img.onerror = function() {
- callback(null);
- };
- img.src = url;
- }
- function fitImageSize(width, height, maxWidth, maxHeight) {
- var ratio = width / height,
- fitRatio = maxWidth / maxHeight;
- // 宽高比大于最大尺寸的宽高比,以宽度为标准适应
- if (width > maxWidth && ratio > fitRatio) {
- width = maxWidth;
- height = width / ratio;
- } else if (height > maxHeight) {
- height = maxHeight;
- width = height * ratio;
- }
- return {
- width: width | 0,
- height: height | 0
- };
- }
- var ImageCommand = kity.createClass('ImageCommand', {
- base: Command,
- execute: function(km, url, title) {
- var nodes = km.getSelectedNodes();
- loadImageSize(url, function(width, height) {
- if (!width) return;
- utils.each(nodes, function(i, n) {
- var size = fitImageSize(
- width, height,
- km.getOptions('maxImageWidth'),
- km.getOptions('maxImageHeight'));
- n.setData('image', url);
- n.setData('imageTitle', title);
- n.setData('imageSize', size);
- n.render();
- });
- km.fire("saveScene");
- km.layout(300);
- });
- },
- queryState: function(km) {
- var nodes = km.getSelectedNodes(),
- result = 0;
- if (nodes.length === 0) {
- return -1;
- }
- utils.each(nodes, function(i, n) {
- if (n && n.getData('image')) {
- result = 0;
- return false;
- }
- });
- return result;
- },
- queryValue: function(km) {
- var node = km.getSelectedNode();
- return {
- url: node.getData('image'),
- title: node.getData('imageTitle')
- };
- }
- });
- var RemoveImageCommand = kity.createClass('RemoveImageCommand', {
- base: Command,
- execute: function(km) {
- var nodes = km.getSelectedNodes();
- utils.each(nodes, function(i, n) {
- n.setData('image').render();
- });
- km.layout(300);
- },
- queryState: function(km) {
- var nodes = km.getSelectedNodes();
- if (nodes.length === 0) {
- return -1;
- }
- var image = false;
- utils.each(nodes, function(i, n) {
- if (n.getData('image')) {
- image = true;
- return false;
- }
- });
- if (image) {
- return 0;
- }
- return -1;
- }
- });
- var ImageRenderer = kity.createClass('ImageRenderer', {
- base: KityMinder.Renderer,
- create: function(node) {
- return new kity.Image(node.getData('image'));
- },
- shouldRender: function(node) {
- return node.getData('image');
- },
- update: function(image, node, box) {
- var url = node.getData('image');
- var title = node.getData('imageTitle');
- var size = node.getData('imageSize');
- var spaceTop = node.getStyle('space-top');
- if (!size) return;
- if (title) {
- image.node.setAttributeNS('http://www.w3.org/1999/xlink', 'title', title);
- }
- var x = box.cx - size.width / 2;
- var y = box.y - size.height - spaceTop;
- image
- .setUrl(url)
- .setX(x | 0)
- .setY(y | 0)
- .setWidth(size.width | 0)
- .setHeight(size.height | 0);
- return new kity.Box(x | 0, y | 0, size.width | 0, size.height | 0);
- }
- });
- return {
- 'defaultOptions': {
- 'maxImageWidth': 200,
- 'maxImageHeight': 200
- },
- 'commands': {
- 'image': ImageCommand,
- 'removeimage': RemoveImageCommand
- },
- 'renderers': {
- 'top': ImageRenderer
- }
- };
- });
- KityMinder.registerModule('Resource', function() {
- // String Hash
- // https://github.com/drostie/sha3-js/edit/master/blake32.min.js
- var blake32=(function(){var k,g,r,l,m,o,p,q,t,w,x;x=4*(1<<30);k=[0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19];m=[0x243F6A88,0x85A308D3,0x13198A2E,0x03707344,0xA4093822,0x299F31D0,0x082EFA98,0xEC4E6C89,0x452821E6,0x38D01377,0xBE5466CF,0x34E90C6C,0xC0AC29B7,0xC97C50DD,0x3F84D5B5,0xB5470917];w=function(i){if(i<0){i+=x}return("00000000"+i.toString(16)).slice(-8)};o=[[16,50,84,118,152,186,220,254],[174,132,249,109,193,32,123,53],[139,12,37,223,234,99,23,73],[151,19,205,235,98,165,4,143],[9,117,66,250,30,203,134,211],[194,166,176,56,212,87,239,145],[92,241,222,164,112,54,41,184],[189,231,28,147,5,79,104,162],[246,158,59,128,44,125,65,90],[42,72,103,81,191,233,195,13]];p=function(a,b,n){var s=q[a]^q[b];q[a]=(s>>>n)|(s<<(32-n))};g=function(i,a,b,c,d){var u=l+o[r][i]%16,v=l+(o[r][i]>>4);a%=4;b=4+b%4;c=8+c%4;d=12+d%4;q[a]+=q[b]+(t[u]^m[v%16]);p(d,a,16);q[c]+=q[d];p(b,c,12);q[a]+=q[b]+(t[v]^m[u%16]);p(d,a,8);q[c]+=q[d];p(b,c,7)};return function(a,b){if(!(b instanceof Array&&b.length===4)){b=[0,0,0,0]}var c,d,e,L,f,h,j,i;d=k.slice(0);c=m.slice(0,8);for(r=0;r<4;r+=1){c[r]^=b[r]}e=a.length*16;f=(e%512>446||e%512===0)?0:e;if(e%512===432){a+="\u8001"}else{a+="\u8000";while(a.length%32!==27){a+="\u0000"}a+="\u0001"}t=[];for(i=0;i<a.length;i+=2){t.push(a.charCodeAt(i)*65536+a.charCodeAt(i+1))}t.push(0);t.push(e);h=t.length-16;j=0;for(l=0;l<t.length;l+=16){j+=512;L=(l===h)?f:Math.min(e,j);q=d.concat(c);q[12]^=L;q[13]^=L;for(r=0;r<10;r+=1){for(i=0;i<8;i+=1){if(i<4){g(i,i,i,i,i)}else{g(i,i,i+1,i+2,i+3)}}}for(i=0;i<8;i+=1){d[i]^=b[i%4]^q[i]^q[i+8]}}return d.map(w).join("")}}());
- /**
- * 自动使用的颜色序列
- */
- var RESOURCE_COLOR_SERIES = [51, 303, 75, 200, 157, 0, 26, 254].map(function(h) {
- return kity.Color.createHSL(h, 100, 85);
- });
- /**
- * 在 Minder 上拓展一些关于资源的支持接口
- */
- kity.extendClass(Minder, {
-
- /**
- * 获取字符串的哈希值
- *
- * @param {String} str
- * @return {Number} hashCode
- */
- getHashCode: function(str) {
- str = blake32(str);
- var hash = 1315423911, i, ch;
- for (i = str.length - 1; i >= 0; i--) {
- ch = str.charCodeAt(i);
- hash ^= ((hash << 5) + ch + (hash >> 2));
- }
- return (hash & 0x7FFFFFFF);
- },
- /**
- * 获取脑图中某个资源对应的颜色
- *
- * 如果存在同名资源,则返回已经分配给该资源的颜色,否则分配给该资源一个颜色,并且返回
- *
- * 如果资源数超过颜色序列数量,返回哈希颜色
- *
- * @param {String} resource 资源名称
- * @return {Color}
- */
- getResourceColor: function(resource) {
- var colorMapping = this._getResourceColorIndexMapping();
- var nextIndex;
- if (!colorMapping.hasOwnProperty(resource)) {
- // 找不到找下个可用索引
- nextIndex = this._getNextResourceColorIndex();
- colorMapping[resource] = nextIndex;
- }
- // 资源过多,找不到可用索引颜色,统一返回哈希函数得到的颜色
- return RESOURCE_COLOR_SERIES[colorMapping[resource]] || kity.Color.createHSL(Math.floor(this.getHashCode(resource) / 0x7FFFFFFF * 359), 100, 85);
- },
- /**
- * 获得已使用的资源的列表
- *
- * @return {Array}
- */
- getUsedResource: function() {
- var mapping = this._getResourceColorIndexMapping();
- var used = [],
- resource;
- for (resource in mapping) {
- if (mapping.hasOwnProperty(resource)) {
- used.push(resource);
- }
- }
- return used;
- },
- /**
- * 获取脑图下一个可用的资源颜色索引
- *
- * @return {int}
- */
- _getNextResourceColorIndex: function() {
- // 获取现有颜色映射
- // resource => color_index
- var colorMapping = this._getResourceColorIndexMapping();
- var resource, used, i;
- used = [];
- // 抽取已经使用的值到 used 数组
- for (resource in colorMapping) {
- if (colorMapping.hasOwnProperty(resource)) {
- used.push(colorMapping[resource]);
- }
- }
- // 枚举所有的可用值,如果还没被使用,返回
- for (i = 0; i < RESOURCE_COLOR_SERIES.length; i++) {
- if (!~used.indexOf(i)) return i;
- }
- // 没有可用的颜色了
- return -1;
- },
- // 获取现有颜色映射
- // resource => color_index
- _getResourceColorIndexMapping: function() {
- return this._resourceColorMapping || (this._resourceColorMapping = {});
- }
- });
- /**
- * @class 设置资源的命令
- *
- * @example
- *
- * // 设置选中节点资源为 "张三"
- * minder.execCommand('resource', ['张三']);
- *
- * // 添加资源 "李四" 到选中节点
- * var resource = minder.queryCommandValue();
- * resource.push('李四');
- * minder.execCommand('resource', resource);
- *
- * // 清除选中节点的资源
- * minder.execCommand('resource', null);
- */
- var ResourceCommand = kity.createClass('ResourceCommand', {
- base: Command,
- execute: function(minder, resource) {
- var nodes = minder.getSelectedNodes();
- if (typeof(resource) == 'string') {
- resource = [resource];
- }
- nodes.forEach(function(node) {
- node.setData('resource', resource).render();
- });
- minder.layout(200);
- },
- queryValue: function(minder) {
- var nodes = minder.getSelectedNodes();
- var resource = [];
- nodes.forEach(function(node) {
- var nodeResource = node.getData('resource');
- if (!nodeResource) return;
- nodeResource.forEach(function(name) {
- if (!~resource.indexOf(name)) {
- resource.push(name);
- }
- });
- });
- return resource;
- },
- queryState: function(km) {
- return km.getSelectedNode() ? 0 : -1;
- }
- });
- /**
- * @class 资源的覆盖图形
- *
- * 该类为一个资源以指定的颜色渲染一个动态的覆盖图形
- */
- var ResourceOverlay = kity.createClass('ResourceOverlay', {
- base: kity.Group,
- constructor: function() {
- this.callBase();
- var text, rect;
- rect = this.rect = new kity.Rect().setRadius(4);
- text = this.text = new kity.Text()
- .setFontSize(12)
- .setVerticalAlign('middle');
- this.addShapes([rect, text]);
- },
- setValue: function(resourceName, color) {
- var paddingX = 8,
- paddingY = 4,
- borderRadius = 4;
- var text, box, rect;
- text = this.text;
- if (resourceName == this.lastResourceName) {
- box = this.lastBox;
- } else {
- text.setContent(resourceName);
- box = text.getBoundaryBox();
- this.lastResourceName = resourceName;
- this.lastBox = box;
- }
- text.setX(paddingX).fill(color.dec('l', 70));
- rect = this.rect;
- rect.setPosition(0, box.y - paddingY);
- this.width = Math.round(box.width + paddingX * 2);
- this.height = Math.round(box.height + paddingY * 2);
- rect.setSize(this.width, this.height);
- rect.fill(color);
- }
- });
- /**
- * @class 资源渲染器
- */
- var ResourceRenderer = kity.createClass('ResourceRenderer', {
- base: KityMinder.Renderer,
- create: function(node) {
- this.overlays = [];
- return new kity.Group();
- },
- shouldRender: function(node) {
- return node.getData('resource') && node.getData('resource').length;
- },
- update: function(container, node, box) {
- var spaceRight = node.getStyle('space-right');
- var overlays = this.overlays;
- var resource = node.getData('resource');
- var minder = node.getMinder();
- var i, overlay, x;
- x = 0;
- for (i = 0; i < resource.length; i++) {
- x += spaceRight;
- overlay = overlays[i];
- if (!overlay) {
- overlay = new ResourceOverlay();
- overlays.push(overlay);
- container.addShape(overlay);
- }
- overlay.setVisible(true);
- overlay.setValue(resource[i], minder.getResourceColor(resource[i]));
- overlay.setTranslate(x, -1);
- x += overlay.width;
- }
- while ((overlay = overlays[i++])) overlay.setVisible(false);
- container.setTranslate(box.right, 0);
- return new kity.Box({
- x: box.right,
- y: Math.round(-overlays[0].height / 2),
- width: x,
- height: overlays[0].height
- });
- }
- });
- return {
- commands: {
- 'resource': ResourceCommand
- },
- renderers: {
- right: ResourceRenderer
- }
- };
- });
- /**
- * @fileOverview
- *
- * 支持节点详细信息(HTML)格式
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerModule('NoteModule', function() {
- var NOTE_PATH = 'M9,9H3V8h6L9,9L9,9z M9,7H3V6h6V7z M9,5H3V4h6V5z M8.5,11H2V2h8v7.5 M9,12l2-2V1H1v11';
- var NoteCommand = kity.createClass('NoteCommand', {
- base: Command,
- execute: function(minder, note) {
- var node = minder.getSelectedNode();
- node.setData('note', note);
- node.render();
- node.getMinder().layout(300);
- },
- queryState: function(minder) {
- return minder.getSelectedNodes().length === 1 ? 0 : -1;
- },
- queryValue: function(minder) {
- var node = minder.getSelectedNode();
- return node && node.getData('note');
- }
- });
- var NoteIcon = kity.createClass('NoteIcon', {
- base: kity.Group,
- constructor: function() {
- this.callBase();
- this.width = 16;
- this.height = 17;
- this.rect = new kity.Rect(16, 17, 0.5, -8.5, 2).fill('transparent');
- this.path = new kity.Path().setPathData(NOTE_PATH).setTranslate(2.5, -6.5);
- this.addShapes([this.rect, this.path]);
- this.on('mouseover', function() {
- this.rect.fill('rgba(255, 255, 200, .8)');
- }).on('mouseout', function() {
- this.rect.fill('transparent');
- });
- this.setStyle('cursor', 'pointer');
- }
- });
- var NoteIconRenderer = kity.createClass('NoteIconRenderer', {
- base: KityMinder.Renderer,
- create: function(node) {
- var icon = new NoteIcon();
- icon.on('mousedown', function(e) {
- e.preventDefault();
- node.getMinder().fire('editnoterequest');
- });
- icon.on('mouseover', function() {
- node.getMinder().fire('shownoterequest', {node: node, icon: icon});
- });
- icon.on('mouseout', function() {
- node.getMinder().fire('hidenoterequest', {node: node, icon: icon});
- });
- return icon;
- },
- shouldRender: function(node) {
- return node.getData('note');
- },
- update: function(icon, node, box) {
- var x = box.right + node.getStyle('space-left');
- var y = box.cy;
- icon.path.fill(node.getStyle('color'));
- icon.setTranslate(x, y);
- return new kity.Box(x, Math.round(y - icon.height / 2), icon.width, icon.height);
- }
- });
- return {
- renderers: {
- right: NoteIconRenderer
- },
- commands: {
- 'note': NoteCommand
- }
- };
- });
- var ViewDragger = kity.createClass("ViewDragger", {
- constructor: function(minder) {
- this._minder = minder;
- this._enabled = false;
- this._bind();
- var me = this;
- this._minder.getViewDragger = function() {
- return me;
- };
- },
- isEnabled: function() {
- return this._enabled;
- },
- setEnabled: function(value) {
- var paper = this._minder.getPaper();
- paper.setStyle('cursor', value ? 'pointer' : 'default');
- paper.setStyle('cursor', value ? '-webkit-grab' : 'default');
- this._enabled = value;
- },
- move: function(offset, duration) {
- var minder = this._minder;
- var targetPosition = this.getMovement().offset(offset);
- this.moveTo(targetPosition, duration);
- },
- moveTo: function(position, duration) {
- if (duration) {
- var dragger = this;
- if (this._moveTimeline) this._moveTimeline.stop();
- this._moveTimeline = this._minder.getRenderContainer().animate(new kity.Animator(
- this.getMovement(),
- position,
- function(target, value) {
- dragger.moveTo(value);
- }
- ), duration, 'easeOutCubic');
- this._moveTimeline.on('finish', function() {
- dragger._moveTimeline = null;
- });
- return this;
- }
- this._minder.getRenderContainer().setTranslate(position.round());
- this._minder.fire('viewchange');
- },
- getMovement: function() {
- var translate = this._minder.getRenderContainer().transform.translate;
- return translate ? translate[0] : new kity.Point();
- },
- getView: function() {
- var minder = this._minder;
- var c = {
- width: minder.getRenderTarget().clientWidth,
- height: minder.getRenderTarget().clientHeight
- };
- var m = this.getMovement();
- var box = new kity.Box(0, 0, c.width, c.height);
- var viewMatrix = minder.getPaper().getViewPortMatrix();
- return viewMatrix.inverse().translate(-m.x, -m.y).transformBox(box);
- },
- _bind: function() {
- var dragger = this,
- isTempDrag = false,
- lastPosition = null,
- currentPosition = null;
- function dragEnd(e) {
- if (!lastPosition) return;
-
- lastPosition = null;
- e.stopPropagation();
- // 临时拖动需要还原状态
- if (isTempDrag) {
- dragger.setEnabled(false);
- isTempDrag = false;
- if (dragger._minder.getStatus() == 'hand')
- dragger._minder.rollbackStatus();
- }
- var paper = dragger._minder.getPaper();
- paper.setStyle('cursor', dragger._minder.getStatus() == 'hand' ? '-webkit-grab' : 'default');
- }
- this._minder.on('normal.mousedown normal.touchstart ' +
- 'inputready.mousedown inputready.touchstart ' +
- 'readonly.mousedown readonly.touchstart', function(e) {
- if (e.originEvent.button == 2) {
- e.originEvent.preventDefault(); // 阻止中键拉动
- }
- // 点击未选中的根节点临时开启
- if (e.getTargetNode() == this.getRoot() || e.originEvent.button == 2 || e.originEvent.altKey) {
- lastPosition = e.getPosition();
- isTempDrag = true;
- }
- })
- .on('normal.mousemove normal.touchmove ' +
- 'readonly.mousemove readonly.touchmove ' +
- 'inputready.mousemove inputready.touchmove', function(e) {
- if (e.type == 'touchmove') {
- e.preventDefault(); // 阻止浏览器的后退事件
- }
- if (!isTempDrag) return;
- var offset = kity.Vector.fromPoints(lastPosition, e.getPosition());
- if (offset.length() > 10) {
- this.setStatus('hand', true);
- var paper = dragger._minder.getPaper();
- paper.setStyle('cursor', '-webkit-grabbing');
- }
- })
- .on('hand.beforemousedown hand.beforetouchstart', function(e) {
- // 已经被用户打开拖放模式
- if (dragger.isEnabled()) {
- lastPosition = e.getPosition();
- e.stopPropagation();
- var paper = dragger._minder.getPaper();
- paper.setStyle('cursor', '-webkit-grabbing');
- }
- })
- .on('hand.beforemousemove hand.beforetouchmove', function(e) {
- if (lastPosition) {
- currentPosition = e.getPosition();
- // 当前偏移加上历史偏移
- var offset = kity.Vector.fromPoints(lastPosition, currentPosition);
- dragger.move(offset);
- e.stopPropagation();
- e.preventDefault();
- e.originEvent.preventDefault();
- lastPosition = currentPosition;
- }
- })
- .on('mouseup touchend', dragEnd);
- window.addEventListener('mouseup', dragEnd);
- this._minder.on('contextmenu', function(e) {
- e.preventDefault();
- });
- }
- });
- KityMinder.registerModule('View', function() {
- var km = this;
- var ToggleHandCommand = kity.createClass('ToggleHandCommand', {
- base: Command,
- execute: function(minder) {
- if (minder.getStatus() != 'hand') {
- minder.setStatus('hand', true);
- } else {
- minder.rollbackStatus();
- }
- this.setContentChanged(false);
- },
- queryState: function(minder) {
- return minder.getStatus() == 'hand' ? 1 : 0;
- },
- enableReadOnly: true
- });
- var CameraCommand = kity.createClass('CameraCommand', {
- base: Command,
- execute: function(km, focusNode, duration) {
- focusNode = focusNode || km.getRoot();
- var viewport = km.getPaper().getViewPort();
- var offset = focusNode.getRenderContainer().getRenderBox('view');
- var dx = viewport.center.x - offset.x - offset.width / 2,
- dy = viewport.center.y - offset.y;
- var dragger = km._viewDragger;
- dragger.move(new kity.Point(dx, dy), duration);
- this.setContentChanged(false);
- },
- enableReadOnly: true
- });
- var MoveCommand = kity.createClass('MoveCommand', {
- base: Command,
- execute: function(km, dir, duration) {
- var dragger = km._viewDragger;
- var size = km._lastClientSize;
- switch (dir) {
- case 'up':
- dragger.move(new kity.Point(0, size.height / 2), duration);
- break;
- case 'down':
- dragger.move(new kity.Point(0, -size.height / 2), duration);
- break;
- case 'left':
- dragger.move(new kity.Point(size.width / 2, 0), duration);
- break;
- case 'right':
- dragger.move(new kity.Point(-size.width / 2, 0), duration);
- break;
- }
- },
- enableReadOnly: true
- });
- return {
- init: function() {
- this._viewDragger = new ViewDragger(this);
- },
- commands: {
- 'hand': ToggleHandCommand,
- 'camera': CameraCommand,
- 'move': MoveCommand
- },
- events: {
- keydown: function(e) {
- var minder = this;
- ['up', 'down', 'left', 'right'].forEach(function(name) {
- if (e.isShortcutKey('ctrl+' + name) && minder.getStatus() != 'textedit') {
- minder.removeAllSelectedNodes();
- minder.execCommand('move', name, 100);
- e.preventDefault();
- }
- });
- if (e.isShortcutKey('ctrl+enter')) {
- minder.execCommand('camera', minder.getRoot(), 100);
- }
- },
- statuschange: function(e) {
- this._viewDragger.setEnabled(e.currentStatus == 'hand');
- },
- mousewheel: function(e) {
- var dx, dy;
- e = e.originEvent;
- if (e.ctrlKey || e.shiftKey) return;
- if ('wheelDeltaX' in e) {
- dx = e.wheelDeltaX || 0;
- dy = e.wheelDeltaY || 0;
- } else {
- dx = 0;
- dy = e.wheelDelta;
- }
- this._viewDragger.move({
- x: dx / 2.5,
- y: dy / 2.5
- });
- e.preventDefault();
- },
- 'normal.dblclick readonly.dblclick': function(e) {
- if (e.kityEvent.targetShape instanceof kity.Paper) {
- this.execCommand('camera', this.getRoot(), 800);
- }
- },
- ready: function() {
- this.execCommand('camera', null, 0);
- this._lastClientSize = {
- width: this.getRenderTarget().clientWidth,
- height: this.getRenderTarget().clientHeight
- };
- },
- resize: function(e) {
- var a = {
- width: this.getRenderTarget().clientWidth,
- height: this.getRenderTarget().clientHeight
- },
- b = this._lastClientSize;
- this._viewDragger.move(
- new kity.Point((a.width - b.width) / 2 | 0, (a.height - b.height) / 2 | 0));
- this._lastClientSize = a;
- },
- 'selectionchange layoutallfinish': function(e) {
- var selected = this.getSelectedNode();
- if (!selected) return;
- var dragger = this._viewDragger;
- var view = dragger.getView();
- var focus = selected.getLayoutBox();
- var space = 50;
- var dx = 0, dy = 0;
- if (focus.right > view.right) {
- dx += view.right - focus.right - space;
- }
- else if (focus.left < view.left) {
- dx += view.left - focus.left + space;
- }
- if (focus.bottom > view.bottom) {
- dy += view.bottom - focus.bottom - space;
- }
- if (focus.top < view.top) {
- dy += view.top - focus.top + space;
- }
-
- if (dx || dy) dragger.move(new kity.Point(dx, dy), 100);
- }
- }
- };
- });
- var GM = KityMinder.Geometry;
- // 矩形的变形动画定义
- var MoveToParentCommand = kity.createClass('MoveToParentCommand', {
- base: Command,
- execute: function(minder, nodes, parent) {
- var node;
- for (var i = nodes.length - 1; i >= 0; i--) {
- node = nodes[i];
- if (node.parent) {
- node.parent.removeChild(node);
- parent.appendChild(node);
- node.render();
- }
- }
- parent.expand();
- minder.select(nodes, true);
- }
- });
- var DropHinter = kity.createClass('DropHinter', {
- base: kity.Group,
- constructor: function() {
- this.callBase();
- this.rect = new kity.Rect();
- this.addShape(this.rect);
- },
- render: function(target) {
- this.setVisible(!!target);
- if (target) {
- this.rect
- .setBox(target.getLayoutBox())
- .setRadius(target.getStyle('radius') || 0)
- .stroke(
- target.getStyle('drop-hint-color') || 'yellow',
- target.getStyle('drop-hint-width') || 2
- );
- this.bringTop();
- }
- }
- });
- var OrderHinter = kity.createClass('OrderHinter', {
- base: kity.Group,
- constructor: function() {
- this.callBase();
- this.area = new kity.Rect();
- this.path = new kity.Path();
- this.addShapes([this.area, this.path]);
- },
- render: function(hint) {
- this.setVisible(!!hint);
- if (hint) {
- this.area.setBox(hint.area);
- this.area.fill(hint.node.getStyle('order-hint-area-color') || 'rgba(0, 255, 0, .5)');
- this.path.setPathData(hint.path);
- this.path.stroke(
- hint.node.getStyle('order-hint-path-color') || '#0f0',
- hint.node.getStyle('order-hint-path-width') || 1);
- }
- }
- });
- // 对拖动对象的一个替代盒子,控制整个拖放的逻辑,包括:
- // 1. 从节点列表计算出拖动部分
- // 2. 计算可以 drop 的节点,产生 drop 交互提示
- var TreeDragger = kity.createClass('TreeDragger', {
- constructor: function(minder) {
- this._minder = minder;
- this._dropHinter = new DropHinter();
- this._orderHinter = new OrderHinter();
- minder.getRenderContainer().addShapes([this._dropHinter, this._orderHinter]);
- },
- dragStart: function(position) {
- // 只记录开始位置,不马上开启拖放模式
- // 这个位置同时是拖放范围收缩时的焦点位置(中心)
- this._startPosition = position;
- },
- dragMove: function(position) {
- // 启动拖放模式需要最小的移动距离
- var DRAG_MOVE_THRESHOLD = 10;
- if (!this._startPosition) return;
- var movement = kity.Vector.fromPoints(this._dragPosition || this._startPosition, position);
- var minder = this._minder;
- this._dragPosition = position;
- if (!this._dragMode) {
- // 判断拖放模式是否该启动
- if (GM.getDistance(this._dragPosition, this._startPosition) < DRAG_MOVE_THRESHOLD) {
- return;
- }
- if (!this._enterDragMode()) {
- return;
- }
- }
- for (var i = 0; i < this._dragSources.length; i++) {
- this._dragSources[i].setLayoutOffset(this._dragSources[i].getLayoutOffset().offset(movement));
- minder.applyLayoutResult(this._dragSources[i]);
- }
-
- if (!this._dropTest()) {
- this._orderTest();
- } else {
- this._renderOrderHint(this._orderSucceedHint = null);
- }
- },
- dragEnd: function() {
- this._startPosition = null;
- this._dragPosition = null;
- if (!this._dragMode) {
- return;
- }
- this._fadeDragSources(1);
- if (this._dropSucceedTarget) {
- this._dragSources.forEach(function(source) {
- source.setLayoutOffset(null);
- });
-
- this._minder.layout(-1);
- this._minder.execCommand('movetoparent', this._dragSources, this._dropSucceedTarget);
- } else if (this._orderSucceedHint) {
- var hint = this._orderSucceedHint;
- var index = hint.node.getIndex();
- var sourceIndexes = this._dragSources.map(function(source) {
- // 顺便干掉布局偏移
- source.setLayoutOffset(null);
- return source.getIndex();
- });
- var maxIndex = Math.max.apply(Math, sourceIndexes);
- var minIndex = Math.min.apply(Math, sourceIndexes);
- if (index < minIndex && hint.type == 'down') index++;
- if (index > maxIndex && hint.type == 'up') index--;
- hint.node.setLayoutOffset(null);
- this._minder.execCommand('arrange', this._dragSources, index);
- this._renderOrderHint(null);
- } else {
- this._minder.fire('savescene');
- }
- this._minder.layout(300);
- this._leaveDragMode();
- this._minder.fire('contentchange');
- },
- // 进入拖放模式:
- // 1. 计算拖放源和允许的拖放目标
- // 2. 标记已启动
- _enterDragMode: function() {
- this._calcDragSources();
- if (!this._dragSources.length) {
- this._startPosition = null;
- return false;
- }
- this._fadeDragSources(0.5);
- this._calcDropTargets();
- this._calcOrderHints();
- this._dragMode = true;
- this._minder.setStatus('dragtree');
- return true;
- },
- // 从选中的节点计算拖放源
- // 并不是所有选中的节点都作为拖放源,如果选中节点中存在 A 和 B,
- // 并且 A 是 B 的祖先,则 B 不作为拖放源
- //
- // 计算过程:
- // 1. 将节点按照树高排序,排序后只可能是前面节点是后面节点的祖先
- // 2. 从后往前枚举排序的结果,如果发现枚举目标之前存在其祖先,
- // 则排除枚举目标作为拖放源,否则加入拖放源
- _calcDragSources: function() {
- this._dragSources = this._minder.getSelectedAncestors();
- },
- _fadeDragSources: function(opacity) {
- var minder = this._minder;
- this._dragSources.forEach(function(source) {
- source.getRenderContainer().setOpacity(opacity, 200);
- source.traverse(function(node) {
- if (opacity < 1) {
- minder.detachNode(node);
- } else {
- minder.attachNode(node);
- }
- }, true);
- });
- },
- // 计算拖放目标可以释放的节点列表(释放意味着成为其子树),存在这条限制规则:
- // - 不能拖放到拖放目标的子树上(允许拖放到自身,因为多选的情况下可以把其它节点加入)
- //
- // 1. 加入当前节点(初始为根节点)到允许列表
- // 2. 对于当前节点的每一个子节点:
- // (1) 如果是拖放目标的其中一个节点,忽略(整棵子树被剪枝)
- // (2) 如果不是拖放目标之一,以当前子节点为当前节点,回到 1 计算
- // 3. 返回允许列表
- //
- _calcDropTargets: function() {
- function findAvailableParents(nodes, root) {
- var availables = [],
- i;
- availables.push(root);
- root.getChildren().forEach(function(test) {
- for (i = 0; i < nodes.length; i++) {
- if (nodes[i] == test) return;
- }
- availables = availables.concat(findAvailableParents(nodes, test));
- });
- return availables;
- }
- this._dropTargets = findAvailableParents(this._dragSources, this._minder.getRoot());
- this._dropTargetBoxes = this._dropTargets.map(function(source) {
- return source.getLayoutBox();
- });
- },
- _calcOrderHints: function() {
- var sources = this._dragSources;
- var ancestor = MinderNode.getCommonAncestor(sources);
- // 只有一个元素选中,公共祖先是其父
- if (ancestor == sources[0]) ancestor = sources[0].parent;
- if (sources.length === 0 || ancestor != sources[0].parent) {
- this._orderHints = [];
- return;
- }
- var siblings = ancestor.children;
- this._orderHints = siblings.reduce(function(hint, sibling) {
- if (sources.indexOf(sibling) == -1) {
- hint = hint.concat(sibling.getOrderHint());
- }
- return hint;
- }, []);
- },
- _leaveDragMode: function() {
- this._dragMode = false;
- this._dropSucceedTarget = null;
- this._orderSucceedHint = null;
- this._renderDropHint(null);
- this._renderOrderHint(null);
- this._minder.rollbackStatus();
- },
- _drawForDragMode: function() {
- this._text.setContent(this._dragSources.length + ' items');
- this._text.setPosition(this._startPosition.x, this._startPosition.y + 5);
- this._minder.getRenderContainer().addShape(this);
- },
- _boxTest: function(targets, targetBoxMapper, judge) {
- var sourceBoxes = this._dragSources.map(function(source) {
- return source.getLayoutBox();
- });
- var i, j, target, sourceBox, targetBox;
- judge = judge || function(intersectBox, sourceBox, targetBox) {
- return intersectBox;
- };
- for (i = 0; i < targets.length; i++) {
- target = targets[i];
- targetBox = targetBoxMapper.call(this, target, i);
- for (j = 0; j < sourceBoxes.length; j++) {
- sourceBox = sourceBoxes[j];
- var intersectBox = GM.getIntersectBox(sourceBox, targetBox);
- if (judge(intersectBox, sourceBox, targetBox)) {
- return target;
- }
- }
- }
- return null;
- },
- _dropTest: function() {
- this._dropSucceedTarget = this._boxTest(this._dropTargets, function(target, i) {
- return this._dropTargetBoxes[i];
- }, function(intersectBox, sourceBox, targetBox) {
- function area(box) {
- return box.width * box.height;
- }
- if (!intersectBox) return false;
- // 面积判断
- if (area(intersectBox) > 0.5 * Math.min(area(sourceBox), area(targetBox))) return true;
- if (intersectBox.width + 1 >= Math.min(sourceBox.width, targetBox.width)) return true;
- if (intersectBox.height + 1 >= Math.min(sourceBox.height, targetBox.height)) return true;
- return false;
- });
- this._renderDropHint(this._dropSucceedTarget);
- return !!this._dropSucceedTarget;
- },
- _orderTest: function() {
- this._orderSucceedHint = this._boxTest(this._orderHints, function(hint) {
- return hint.area;
- });
- this._renderOrderHint(this._orderSucceedHint);
- return !!this._orderSucceedHint;
- },
- _renderDropHint: function(target) {
- this._dropHinter.render(target);
- },
- _renderOrderHint: function(hint) {
- this._orderHinter.render(hint);
- },
- preventDragMove: function() {
- this._startPosition = null;
- }
- });
- KityMinder.registerModule('DragTree', function() {
- var dragger;
- return {
- init: function() {
- dragger = new TreeDragger(this);
- window.addEventListener('mouseup', function() {
- dragger.dragEnd();
- });
- },
- events: {
- 'normal.mousedown inputready.mousedown': function(e) {
- // 单选中根节点也不触发拖拽
- if (e.originEvent.button) return;
- if (e.getTargetNode() && e.getTargetNode() != this.getRoot()) {
- dragger.dragStart(e.getPosition(this.getRenderContainer()));
- }
- },
- 'normal.mousemove dragtree.mousemove': function(e) {
- dragger.dragMove(e.getPosition(this.getRenderContainer()));
- },
- 'normal.mouseup dragtree.beforemouseup': function(e) {
- dragger.dragEnd();
- //e.stopPropagation();
- e.preventDefault();
- },
- 'statuschange': function(e) {
- if (e.lastStatus == 'textedit' && e.currentStatus == 'normal') {
- dragger.preventDragMove();
- }
- }
- },
- commands: {
- 'movetoparent': MoveToParentCommand
- }
- };
- });
- KityMinder.registerModule('KeyboardModule', function() {
- var min = Math.min,
- max = Math.max,
- abs = Math.abs,
- sqrt = Math.sqrt,
- exp = Math.exp;
- function buildPositionNetwork(root) {
- var pointIndexes = [],
- p;
- root.traverse(function(node) {
- p = node.getLayoutBox();
- // bugfix: 不应导航到收起的节点(判断其尺寸是否存在)
- if (p.width && p.height) {
- pointIndexes.push({
- left: p.x,
- top: p.y,
- right: p.x + p.width,
- bottom: p.y + p.height,
- width: p.width,
- height: p.height,
- node: node,
- text: node.getText()
- });
- }
- });
- for (var i = 0; i < pointIndexes.length; i++) {
- findClosestPointsFor(pointIndexes, i);
- }
- }
- // 这是金泉的点子,赞!
- // 求两个不相交矩形的最近距离
- function getCoefedDistance(box1, box2) {
- var xMin, xMax, yMin, yMax, xDist, yDist, dist, cx, cy;
- xMin = min(box1.left, box2.left);
- xMax = max(box1.right, box2.right);
- yMin = min(box1.top, box2.top);
- yMax = max(box1.bottom, box2.bottom);
- xDist = xMax - xMin - box1.width - box2.width;
- yDist = yMax - yMin - box1.height - box2.height;
- if (xDist < 0) dist = yDist;
- else if (yDist < 0) dist = xDist;
- else dist = sqrt(xDist * xDist + yDist * yDist);
- return {
- cx: dist,
- cy: dist
- };
- }
- function findClosestPointsFor(pointIndexes, iFind) {
- var find = pointIndexes[iFind];
- var most = {},
- quad;
- var current, dist;
- for (var i = 0; i < pointIndexes.length; i++) {
- if (i == iFind) continue;
- current = pointIndexes[i];
- dist = getCoefedDistance(current, find);
- // left check
- if (current.right < find.left) {
- if (!most.left || dist.cx < most.left.dist) {
- most.left = {
- dist: dist.cx,
- node: current.node
- };
- }
- }
- // right check
- if (current.left > find.right) {
- if (!most.right || dist.cx < most.right.dist) {
- most.right = {
- dist: dist.cx,
- node: current.node
- };
- }
- }
- // top check
- if (current.bottom < find.top) {
- if (!most.top || dist.cy < most.top.dist) {
- most.top = {
- dist: dist.cy,
- node: current.node
- };
- }
- }
- // bottom check
- if (current.top > find.bottom) {
- if (!most.down || dist.cy < most.down.dist) {
- most.down = {
- dist: dist.cy,
- node: current.node
- };
- }
- }
- }
- find.node._nearestNodes = {
- right: most.right && most.right.node || null,
- top: most.top && most.top.node || null,
- left: most.left && most.left.node || null,
- down: most.down && most.down.node || null
- };
- }
- function navigateTo(km, direction) {
- var referNode = km.getSelectedNode();
- if (!referNode) {
- km.select(km.getRoot());
- buildPositionNetwork(km.getRoot());
- return;
- }
- if (!referNode._nearestNodes) {
- buildPositionNetwork(km.getRoot());
- }
- var nextNode = referNode._nearestNodes[direction];
- if (nextNode) {
- km.select(nextNode, true);
- }
- }
- var NavigateToParentCommand = kity.createClass({
- base: Command,
- execute: function(km) {
- var node = km.getSelectedNode();
- if (node && node.parent) {
- km.select(node.parent, true);
- }
- this.setContentChanged(false);
- },
- queryState: function(km) {
- return km.getSelectedNode() ? 0 : -1;
- },
- enableReadOnly: true
- });
- // 稀释用
- var lastFrame;
- return {
- 'commands': {
- 'navparent': NavigateToParentCommand
- },
- 'commandShortcutKeys': {
- 'navparent': 'shift+tab'
- },
- 'events': {
- 'layoutallfinish': function() {
- var root = this.getRoot();
- buildPositionNetwork(root);
- },
- 'normal.keydown readonly.keydown': function(e) {
- var minder = this;
- ['left', 'right', 'up', 'down'].forEach(function(key) {
- if (e.isShortcutKey(key)) {
- navigateTo(minder, key == 'up' ? 'top' : key);
- }
- });
- },
- 'normal.keyup': function(e) {
- if (browser.ipad) {
- var keys = KityMinder.keymap;
- var node = e.getTargetNode();
- var lang = this.getLang();
- if (this.receiver) this.receiver.keydownNode = node;
- var keyEvent = e.originEvent;
- if (keyEvent.altKey || keyEvent.ctrlKey || keyEvent.metaKey || keyEvent.shiftKey) return;
- switch (keyEvent.keyCode) {
- case keys.Enter:
- this.execCommand('AppendSiblingNode', lang.topic);
- e.preventDefault();
- break;
- case keys.Backspace:
- case keys.Del:
- e.preventDefault();
- this.execCommand('RemoveNode');
- break;
- }
- }
- }
- }
- };
- });
- KityMinder.registerModule('Select', function() {
- var minder = this;
- var rc = minder.getRenderContainer();
- var g = KityMinder.Geometry;
- // 在实例上渲染框选矩形、计算框选范围的对象
- var marqueeActivator = (function() {
- // 记录选区的开始位置(mousedown的位置)
- var startPosition = null;
- // 选区的图形
- var marqueeShape = new kity.Path();
- // 标记是否已经启动框选状态
- // 并不是 mousedown 发生之后就启动框选状态,而是检测到移动了一定的距离(MARQUEE_MODE_THRESHOLD)之后
- var marqueeMode = false;
- var MARQUEE_MODE_THRESHOLD = 10;
- return {
- selectStart: function(e) {
- // 只接受左键
- if (e.originEvent.button || e.originEvent.altKey) return;
- // 清理不正确状态
- if (startPosition) {
- return this.selectEnd();
- }
- startPosition = g.snapToSharp(e.getPosition(rc));
- },
- selectMove: function(e) {
- if (minder.getStatus() == 'textedit') {
- return;
- }
- if (!startPosition) return;
- var p1 = startPosition,
- p2 = e.getPosition(rc);
- // 检测是否要进入选区模式
- if (!marqueeMode) {
- // 距离没达到阈值,退出
- if (g.getDistance(p1, p2) < MARQUEE_MODE_THRESHOLD) {
- return;
- }
- // 已经达到阈值,记录下来并且重置选区形状
- marqueeMode = true;
- rc.addShape(marqueeShape);
- marqueeShape
- .fill(minder.getStyle('marquee-background'))
- .stroke(minder.getStyle('marquee-stroke')).setOpacity(0.8).getDrawer().clear();
- }
- var marquee = g.getBox(p1, p2),
- selectedNodes = [];
- // 使其犀利
- marquee.left = Math.round(marquee.left);
- marquee.top = Math.round(marquee.top);
- marquee.right = Math.round(marquee.right);
- marquee.bottom = Math.round(marquee.bottom);
- // 选区形状更新
- marqueeShape.getDrawer().pipe(function() {
- this.clear();
- this.moveTo(marquee.left, marquee.top);
- this.lineTo(marquee.right, marquee.top);
- this.lineTo(marquee.right, marquee.bottom);
- this.lineTo(marquee.left, marquee.bottom);
- this.close();
- });
- // 计算选中范围
- minder.getRoot().traverse(function(node) {
- var renderBox = node.getLayoutBox();
- if (g.getIntersectBox(renderBox, marquee)) {
- selectedNodes.push(node);
- }
- });
- // 应用选中范围
- minder.select(selectedNodes, true);
- // 清除多余的东西
- window.getSelection().removeAllRanges();
- },
- selectEnd: function(e) {
- if (startPosition) {
- startPosition = null;
- }
- if (marqueeMode) {
- marqueeShape.fadeOut(200, 'ease', 0, function() {
- if (marqueeShape.remove) marqueeShape.remove();
- });
- marqueeMode = false;
- }
- }
- };
- })();
- var lastDownNode = null, lastDownPosition = null;
- return {
- 'init': function() {
- window.addEventListener('mouseup', function() {
- marqueeActivator.selectEnd();
- });
- },
- 'events': {
- 'mousedown': function(e) {
- var downNode = e.getTargetNode();
- // 没有点中节点:
- // 清除选中状态,并且标记选区开始位置
- if (!downNode) {
- this.removeAllSelectedNodes();
- marqueeActivator.selectStart(e);
- this.setStatus('normal');
- }
- // 点中了节点,并且按了 shift 键:
- // 被点中的节点切换选中状态
- else if (e.originEvent.shiftKey) {
- this.toggleSelect(downNode);
- }
- // 点中的节点没有被选择:
- // 单选点中的节点
- else if (!downNode.isSelected()) {
- this.select(downNode, true);
- }
- // 点中的节点被选中了,并且不是单选:
- // 完成整个点击之后需要使其变为单选。
- // 不能马上变为单选,因为可能是需要拖动选中的多个节点
- else if (!this.isSingleSelect()) {
- lastDownNode = downNode;
- lastDownPosition = e.getPosition(this.getRenderContainer());
- }
- },
- 'mousemove': marqueeActivator.selectMove,
- 'mouseup': function(e) {
- var upNode = e.getTargetNode();
- // 如果 mouseup 发生在 lastDownNode 外,是无需理会的
- if (upNode && upNode == lastDownNode) {
- var upPosition = e.getPosition(this.getRenderContainer());
- var movement = kity.Vector.fromPoints(lastDownPosition, upPosition);
- if (movement.length() < 1) this.select(lastDownNode, true);
- lastDownNode = null;
- }
- // 清理一下选择状态
- marqueeActivator.selectEnd(e);
- },
- //全选操作
- 'normal.keydown inputready.keydown':function(e){
- if ( e.isShortcutKey('ctrl+a') ){
- var selectedNodes = [];
- this.getRoot().traverse(function(node){
- selectedNodes.push(node);
- });
- this.select(selectedNodes,true);
- e.preventDefault();
- }
- }
- }
- };
- });
- KityMinder.registerModule('basestylemodule', function() {
- var km = this;
- function getNodeDataOrStyle(node, name) {
- return node.getData(name) || node.getStyle(name);
- }
- KityMinder.TextRenderer.registerStyleHook(function(node, textGroup) {
- var fontWeight = getNodeDataOrStyle(node,'font-weight');
- var fontStyle = getNodeDataOrStyle(node, 'font-style');
- var styleHash = [fontWeight, fontStyle].join('/');
- textGroup.eachItem(function(index,item){
- item.setFont({
- 'weight': fontWeight,
- 'style': fontStyle
- });
- });
- });
- return {
- 'commands': {
- 'bold': kity.createClass('boldCommand', {
- base: Command,
- execute: function(km) {
- var nodes = km.getSelectedNodes();
- if (this.queryState('bold') == 1) {
- utils.each(nodes, function(i, n) {
- n.setData('font-weight').render();
- });
- } else {
- utils.each(nodes, function(i, n) {
- n.setData('font-weight', 'bold').render();
- });
- }
- km.layout();
- },
- queryState: function() {
- var nodes = km.getSelectedNodes(),
- result = 0;
- if (nodes.length === 0) {
- return -1;
- }
- utils.each(nodes, function(i, n) {
- if (n && n.getData('font-weight')) {
- result = 1;
- return false;
- }
- });
- return result;
- }
- }),
- 'italic': kity.createClass('italicCommand', {
- base: Command,
- execute: function(km) {
- var nodes = km.getSelectedNodes();
- if (this.queryState('italic') == 1) {
- utils.each(nodes, function(i, n) {
- n.setData('font-style').render();
- });
- } else {
- utils.each(nodes, function(i, n) {
- n.setData('font-style', 'italic').render();
- });
- }
- km.layout();
- },
- queryState: function() {
- var nodes = km.getSelectedNodes(),
- result = 0;
- if (nodes.length === 0) {
- return -1;
- }
- utils.each(nodes, function(i, n) {
- if (n && n.getData('font-style')) {
- result = 1;
- return false;
- }
- });
- return result;
- }
- })
- },
- commandShortcutKeys: {
- 'bold': 'ctrl+b', //bold
- 'italic': 'ctrl+i' //italic
- }
- };
- });
- KityMinder.registerModule("fontmodule", function() {
- function getNodeDataOrStyle(node, name) {
- return node.getData(name) || node.getStyle(name);
- }
- KityMinder.TextRenderer.registerStyleHook(function(node, textGroup) {
- var dataColor = node.getData('color');
- var selectedColor = node.getStyle('selected-color');
- var styleColor = node.getStyle('color');
- var foreColor = dataColor || (node.isSelected() && selectedColor ? selectedColor : styleColor);
- var fontFamily = getNodeDataOrStyle(node, 'font-family');
- var fontSize = getNodeDataOrStyle(node, 'font-size');
- var fontHash = [fontFamily, fontSize].join('/');
-
- textGroup.fill(foreColor);
- node.setTmpData('fore-color', foreColor.toString());
- textGroup.eachItem(function(index,item){
- item.setFont({
- 'family': fontFamily,
- 'size': fontSize
- });
- });
- node.setTmpData('font-hash', fontHash);
- });
- return {
- defaultOptions: {
- 'fontfamily': [{
- name: '宋体',
- val: '宋体,SimSun'
- }, {
- name: '微软雅黑',
- val: '微软雅黑,Microsoft YaHei'
- }, {
- name: '楷体',
- val: '楷体,楷体_GB2312,SimKai'
- }, {
- name: '黑体',
- val: '黑体, SimHei'
- }, {
- name: '隶书',
- val: '隶书, SimLi'
- }, {
- name: 'Andale Mono',
- val: 'andale mono'
- }, {
- name: 'Arial',
- val: 'arial,helvetica,sans-serif'
- }, {
- name: 'arialBlack',
- val: 'arial black,avant garde'
- }, {
- name: 'Comic Sans Ms',
- val: 'comic sans ms'
- }, {
- name: 'Impact',
- val: 'impact,chicago'
- }, {
- name: 'Times New Roman',
- val: 'times new roman'
- }, {
- name: 'Sans-Serif',
- val: 'sans-serif'
- }],
- 'fontsize': [10, 12, 16, 18, 24, 32, 48]
- },
- "commands": {
- "forecolor": kity.createClass("fontcolorCommand", {
- base: Command,
- execute: function(km, color) {
- var nodes = km.getSelectedNodes();
- utils.each(nodes, function(i, n) {
- n.setData('color', color);
- n.render();
- });
- },
- queryState: function(km) {
- return km.getSelectedNodes().length == 0 ? -1 : 0
- },
- queryValue: function(km) {
- if (km.getSelectedNodes().length == 1) {
- return km.getSelectedNodes()[0].getData('color');
- }
- return 'mixed';
- }
- }),
- "background": kity.createClass("backgroudCommand", {
- base: Command,
- execute: function(km, color) {
- var nodes = km.getSelectedNodes();
- utils.each(nodes, function(i, n) {
- n.setData('background', color);
- n.render();
- });
- },
- queryState: function(km) {
- return km.getSelectedNodes().length == 0 ? -1 : 0
- },
- queryValue: function(km) {
- if (km.getSelectedNodes().length == 1) {
- return km.getSelectedNodes()[0].getData('background');
- }
- return 'mixed';
- }
- }),
- "fontfamily": kity.createClass("fontfamilyCommand", {
- base: Command,
- execute: function(km, family) {
- var nodes = km.getSelectedNodes();
- utils.each(nodes, function(i, n) {
- n.setData('font-family', family);
- n.render();
- km.layout();
- });
- },
- queryState: function(km) {
- return km.getSelectedNodes().length === 0 ? -1 : 0
- },
- queryValue: function(km) {
- var node = km.getSelectedNode();
- if (node) return node.getData('font-family');
- return null;
- }
- }),
- "fontsize": kity.createClass("fontsizeCommand", {
- base: Command,
- execute: function(km, size) {
- var nodes = km.getSelectedNodes();
- utils.each(nodes, function(i, n) {
- n.setData('font-size', size);
- n.render();
- km.layout(300);
- });
- },
- queryState: function(km) {
- return km.getSelectedNodes().length == 0 ? -1 : 0
- },
- queryValue: function(km) {
- var node = km.getSelectedNode();
- if (node) return node.getData('font-size');
- return null;
- }
- })
- }
- };
- });
- KityMinder.registerModule('Zoom', function() {
- var me = this;
- var timeline;
- me.setDefaultOptions('zoom', [10, 20, 30, 50, 80, 100, 120, 150, 200]);
- function setTextRendering() {
- var value = me._zoomValue >= 100 ? 'optimize-speed' : 'geometricPrecision';
- me.getRenderContainer().setAttr('text-rendering', value);
- }
- function fixPaperCTM(paper) {
- var node = paper.shapeNode;
- var ctm = node.getCTM();
- var matrix = new kity.Matrix(ctm.a, ctm.b, ctm.c, ctm.d, (ctm.e | 0) + 0.5, (ctm.f | 0) + 0.5);
- node.setAttribute('transform', 'matrix(' + matrix.toString() + ')');
- }
- kity.extendClass(Minder, {
- zoom: function(value) {
- var paper = this.getPaper();
- var viewport = paper.getViewPort();
- viewport.zoom = value / 100;
- viewport.center = {
- x: viewport.center.x,
- y: viewport.center.y
- };
- paper.setViewPort(viewport);
- if (value == 100) fixPaperCTM(paper);
- },
- getZoomValue: function() {
- return this._zoomValue;
- }
- });
- function zoomMinder(minder, value) {
- var paper = minder.getPaper();
- var viewport = paper.getViewPort();
- if (!value) return;
- setTextRendering();
- if (minder.getRoot().getComplex() > 200) {
- minder._zoomValue = value;
- minder.zoom(value);
- minder.fire('viewchange');
- } else {
- var animator = new kity.Animator({
- beginValue: minder._zoomValue,
- finishValue: value,
- setter: function(target, value) {
- target.zoom(value);
- }
- });
- minder._zoomValue = value;
- if (timeline) {
- timeline.pause();
- }
- timeline = animator.start(minder, 300, 'easeInOutSine');
- timeline.on('finish', function() {
- minder.fire('viewchange');
- });
- }
- minder.fire('zoom', { zoom: value });
- }
- var ZoomCommand = kity.createClass('Zoom', {
- base: Command,
- execute: zoomMinder,
- queryValue: function(minder) {
- return minder._zoomValue;
- }
- });
- var ZoomInCommand = kity.createClass('ZoomInCommand', {
- base: Command,
- execute: function(minder) {
- zoomMinder(minder, this.nextValue(minder));
- },
- queryState: function(minder) {
- return +!this.nextValue(minder);
- },
- nextValue: function(minder) {
- var stack = minder.getOptions('zoom'),
- i;
- for (i = 0; i < stack.length; i++) {
- if (stack[i] > minder._zoomValue) return stack[i];
- }
- return 0;
- },
- enableReadOnly: true
- });
- var ZoomOutCommand = kity.createClass('ZoomOutCommand', {
- base: Command,
- execute: function(minder) {
- zoomMinder(minder, this.nextValue(minder));
- },
- queryState: function(minder) {
- return +!this.nextValue(minder);
- },
- nextValue: function(minder) {
- var stack = minder.getOptions('zoom'),
- i;
- for (i = stack.length - 1; i >= 0; i--) {
- if (stack[i] < minder._zoomValue) return stack[i];
- }
- return 0;
- },
- enableReadOnly: true
- });
- return {
- init: function() {
- this._zoomValue = 100;
- setTextRendering();
- },
- commands: {
- 'zoom-in': ZoomInCommand,
- 'zoom-out': ZoomOutCommand,
- 'zoom': ZoomCommand
- },
- events: {
- 'normal.mousewheel readonly.mousewheel': function(e) {
- if (!e.originEvent.ctrlKey && !e.originEvent.metaKey) return;
- var delta = e.originEvent.wheelDelta;
- var me = this;
- if (!kity.Browser.mac) {
- delta = -delta;
- }
- // 稀释
- if (Math.abs(delta) > 100) {
- clearTimeout(this._wheelZoomTimeout);
- } else {
- return;
- }
- this._wheelZoomTimeout = setTimeout(function() {
- var value;
- var lastValue = me.getPaper()._zoom || 1;
- if (delta < 0) {
- me.execCommand('zoom-in');
- } else if (delta > 0) {
- me.execCommand('zoom-out');
- }
- }, 100);
- e.originEvent.preventDefault();
- }
- },
- commandShortcutKeys: {
- 'zoom-in': 'ctrl+=',
- 'zoom-out': 'ctrl+-'
- }
- };
- });
- KityMinder.registerModule("hyperlink", function() {
- var linkShapePath = "M16.614,10.224h-1.278c-1.668,0-3.07-1.07-3.599-2.556h4.877c0.707,0,1.278-0.571,1.278-1.278V3.834 c0-0.707-0.571-1.278-1.278-1.278h-4.877C12.266,1.071,13.668,0,15.336,0h1.278c2.116,0,3.834,1.716,3.834,3.834V6.39 C20.448,8.508,18.73,10.224,16.614,10.224z M5.112,5.112c0-0.707,0.573-1.278,1.278-1.278h7.668c0.707,0,1.278,0.571,1.278,1.278 S14.765,6.39,14.058,6.39H6.39C5.685,6.39,5.112,5.819,5.112,5.112z M2.556,3.834V6.39c0,0.707,0.573,1.278,1.278,1.278h4.877 c-0.528,1.486-1.932,2.556-3.599,2.556H3.834C1.716,10.224,0,8.508,0,6.39V3.834C0,1.716,1.716,0,3.834,0h1.278 c1.667,0,3.071,1.071,3.599,2.556H3.834C3.129,2.556,2.556,3.127,2.556,3.834z";
- return {
- "commands": {
- "hyperlink": kity.createClass("hyperlink", {
- base: Command,
- execute: function(km, url, title) {
- var nodes = km.getSelectedNodes();
- utils.each(nodes, function(i, n) {
- n.setData('hyperlink', url);
- n.setData('hyperlinkTitle', title);
- n.render();
- });
- km.layout();
- },
- queryState: function(km) {
- var nodes = km.getSelectedNodes(),
- result = 0;
- if (nodes.length === 0) {
- return -1;
- }
- utils.each(nodes, function(i, n) {
- if (n && n.getData('hyperlink')) {
- result = 0;
- return false;
- }
- });
- return result;
- },
- queryValue: function(km) {
- var node = km.getSelectedNode();
- return {
- url: node.getData('hyperlink'),
- title: node.getData('hyperlinkTitle')
- };
- }
- }),
- "unhyperlink": kity.createClass("hyperlink", {
- base: Command,
- execute: function(km) {
- var nodes = km.getSelectedNodes();
- utils.each(nodes, function(i, n) {
- n.setData('hyperlink');
- n.render();
- });
- km.layout();
- },
- queryState: function(km) {
- var nodes = km.getSelectedNodes();
- if (nodes.length === 0) {
- return -1;
- }
- var link = false;
- utils.each(nodes, function(i, n) {
- if (n.getData('hyperlink')) {
- link = true;
- return false;
- }
- });
- if (link) {
- return 0;
- }
- return -1;
- }
- })
- },
- 'renderers': {
- right: kity.createClass('hyperlinkrender', {
- base: KityMinder.Renderer,
- create: function() {
- var link = new kity.HyperLink();
- var linkshape = new kity.Path();
- var outline = new kity.Rect(24, 22, -2, -6, 4).fill('rgba(255, 255, 255, 0)');
- linkshape.setPathData(linkShapePath).fill('#666');
- link.addShape(outline);
- link.addShape(linkshape);
- link.setTarget('_blank');
- link.setStyle('cursor', 'pointer');
- link.on('mouseover', function() {
- outline.fill('rgba(255, 255, 200, .8)');
- }).on('mouseout', function() {
- outline.fill('rgba(255, 255, 255, 0)');
- });
- return link;
- },
- shouldRender: function(node) {
- return node.getData('hyperlink');
- },
- update: function(link, node, box) {
- var href = node.getData('hyperlink');
- link.setHref(href);
- var title = node.getData('hyperlinkTitle');
- if (title) {
- title = [title, '(', href, ')'].join('');
- } else {
- title = href;
- }
- link.node.setAttributeNS('http://www.w3.org/1999/xlink', 'title', title);
- var spaceRight = node.getStyle('space-right');
- link.setTranslate(box.right + spaceRight + 2, -5);
- return new kity.Box({
- x: box.right + spaceRight,
- y: -11,
- width: 24,
- height: 22
- });
- }
- })
- }
- };
- });
- KityMinder.registerProtocol('plain', function(minder) {
- var LINE_ENDING = '\r',
- LINE_ENDING_SPLITER = /\r\n|\r|\n/,
- TAB_CHAR = '\t';
- function repeat(s, n) {
- var result = '';
- while (n--) result += s;
- return result;
- }
- function encode(json, level) {
- var local = '';
- level = level || 0;
- local += repeat(TAB_CHAR, level);
- local += json.data.text + LINE_ENDING;
- if (json.children) {
- json.children.forEach(function(child) {
- local += encode(child, level + 1);
- });
- }
- return local;
- }
- function isEmpty(line) {
- return !/\S/.test(line);
- }
- function getLevel(line) {
- var level = 0;
- while (line.charAt(level) === TAB_CHAR) level++;
- return level;
- }
- function getNode(line) {
- return {
- data: {
- text: line.replace(new RegExp('^' + TAB_CHAR + '*'), '')
- }
- };
- }
- /**
- * 文本解码
- *
- * @param {string} local 文本内容
- * @param {=boolean} root 自动根节点
- * @return {Object} 返回解析后节点
- */
- function decode(local, root) {
- var json,
- offset,
- parentMap = {},
- lines = local.split(LINE_ENDING_SPLITER),
- line, level, node;
- function addChild(parent, child) {
- var children = parent.children || (parent.children = []);
- children.push(child);
- }
- if (root) {
- parentMap[0] = json = getNode('root');
- offset = 1;
- } else {
- offset = 0;
- }
- for (var i = 0; i < lines.length; i++) {
- line = lines[i];
- if (isEmpty(line)) continue;
- level = getLevel(line) + offset;
- node = getNode(line);
- if (level === 0) {
- if (json) {
- throw new Error('Invalid local format');
- }
- json = node;
- } else {
- if (!parentMap[level - 1]) {
- throw new Error('Invalid local format');
- }
- addChild(parentMap[level - 1], node);
- }
- parentMap[level] = node;
- }
- return json;
- }
- return {
- fileDescription: '大纲文本',
- fileExtension: '.txt',
- mineType: 'text/plain',
- dataType: 'text',
- encode: function(json) {
- return encode(json, 0);
- },
- decode: function(local, root) {
- return decode(local, root);
- },
- recognizePriority: -1
- };
- });
- /**
- * @fileOverview
- *
- * Markdown 格式导入导出支持
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerProtocol('markdown', function() {
- var LINE_ENDING_SPLITER = /\r\n|\r|\n/;
- var EMPTY_LINE = '';
- var NOTE_MARK_START = '<!--Note-->';
- var NOTE_MARK_CLOSE = '<!--/Note-->';
- function encode(json) {
- return _build(json, 1).join('\n');
- }
- function _build(node, level) {
- var lines = [];
- level = level || 1;
- var sharps = _generateHeaderSharp(level);
- lines.push(sharps + ' ' + node.data.text);
- lines.push(EMPTY_LINE);
-
- var note = node.data.note;
- if (note) {
- var hasSharp = /^#/.test(note);
- if (hasSharp) {
- lines.push(NOTE_MARK_START);
- note = note.replace(/^#+/gm, function($0) {
- return sharps + $0;
- });
- }
- lines.push(note);
- if (hasSharp) {
- lines.push(NOTE_MARK_CLOSE);
- }
- lines.push(EMPTY_LINE);
- }
- if (node.children) node.children.forEach(function(child) {
- lines = lines.concat(_build(child, level + 1));
- });
- return lines;
- }
- function _generateHeaderSharp(level) {
- var sharps = '';
- while(level--) sharps += '#';
- return sharps;
- }
- function decode(markdown) {
- var json,
- parentMap = {},
- lines, line, lineInfo, level, node, parent, noteProgress, codeBlock;
- // 一级标题转换 `{title}\n===` => `# {title}`
- markdown = markdown.replace(/^(.+)\n={3,}/, function($0, $1) {
- return '# ' + $1;
- });
- lines = markdown.split(LINE_ENDING_SPLITER);
- // 按行分析
- for (var i = 0; i < lines.length; i++) {
- line = lines[i];
- lineInfo = _resolveLine(line);
- // 备注标记处理
- if (lineInfo.noteClose) {
- noteProgress = false;
- continue;
- } else if (lineInfo.noteStart) {
- noteProgress = true;
- continue;
- }
- // 代码块处理
- codeBlock = lineInfo.codeBlock ? !codeBlock : codeBlock;
- // 备注条件:备注标签中,非标题定义,或标题越位
- if (noteProgress || codeBlock || !lineInfo.level || lineInfo.level > level + 1) {
- if (node) _pushNote(node, line);
- continue;
- }
- // 标题处理
- level = lineInfo.level;
- node = _initNode(lineInfo.content, parentMap[level - 1]);
- parentMap[level] = node;
- }
- _cleanUp(parentMap[1]);
- return parentMap[1];
- }
- function _initNode(text, parent) {
- var node = {
- data: {
- text: text,
- note: ''
- }
- };
- if (parent) {
- if (parent.children) parent.children.push(node);
- else parent.children = [node];
- }
- return node;
- }
- function _pushNote(node, line) {
- node.data.note += line + '\n';
- }
- function _isEmpty(line) {
- return !/\S/.test(line);
- }
- function _resolveLine(line) {
- var match = /^(#+)?\s*(.*)$/.exec(line);
- return {
- level: match[1] && match[1].length || null,
- content: match[2],
- noteStart: line == NOTE_MARK_START,
- noteClose: line == NOTE_MARK_CLOSE,
- codeBlock: /^\s*```/.test(line)
- };
- }
- function _cleanUp(node) {
- if (!/\S/.test(node.data.note)) {
- node.data.note = null;
- delete node.data.note;
- } else {
- var notes = node.data.note.split('\n');
- while(notes.length && !/\S/.test(notes[0])) notes.shift();
- while(notes.length && !/\S/.test(notes[notes.length - 1])) notes.pop();
- node.data.note = notes.join('\n');
- }
- if (node.children) node.children.forEach(_cleanUp);
- }
- return {
- fileDescription: 'Markdown/GFM 格式',
- fileExtension: '.md',
- mineType: 'text/markdown',
- dataType: 'text',
- encode: function(json) {
- return encode(json);
- },
- decode: function(markdown) {
- return decode(markdown);
- },
- recognizePriority: -1
- };
- });
- KityMinder.registerProtocol('json', function(minder) {
- return {
- fileDescription: 'KityMinder 格式',
- fileExtension: '.km',
- dataType: 'text',
- mineType: 'application/json',
- encode: function(json) {
- return JSON.stringify(json);
- },
- decode: function(local) {
- return JSON.parse(local);
- }
- };
- });
- if (!kity.Browser.ie) {
- KityMinder.registerProtocol('png', function(minder) {
- var DomURL = window.URL || window.webkitURL || window;
- function loadImage(url, callback) {
- return new Promise(function(resolve, reject) {
- var image = document.createElement('img');
- image.onload = function() {
- resolve(this);
- };
- image.onerror = function(err) {
- reject(err);
- };
- image.crossOrigin = '';
- image.src = url;
- });
- }
- function getSVGInfo() {
- var paper = minder.getPaper(),
- paperTransform,
- domContainer = paper.container,
- svgXml,
- $svg,
- renderContainer = minder.getRenderContainer(),
- renderBox = renderContainer.getRenderBox(),
- width = renderBox.width + 1,
- height = renderBox.height + 1,
- blob, svgUrl, img;
- // 保存原始变换,并且移动到合适的位置
- paperTransform = paper.shapeNode.getAttribute('transform');
- paper.shapeNode.setAttribute('transform', 'translate(0.5, 0.5)');
- renderContainer.translate(-renderBox.x, -renderBox.y);
- // 获取当前的 XML 代码
- svgXml = paper.container.innerHTML;
- // 回复原始变换及位置
- renderContainer.translate(renderBox.x, renderBox.y);
- paper.shapeNode.setAttribute('transform', paperTransform);
- // 过滤内容
- $svg = $(svgXml).filter('svg');
- $svg.attr({
- width: renderBox.width + 1,
- height: renderBox.height + 1,
- style: 'font-family: Arial, "Microsoft Yahei","Heiti SC";'
- });
- svgXml = $('<div></div>').append($svg).html();
- // Dummy IE
- svgXml = svgXml.replace(' xmlns="http://www.w3.org/2000/svg" xmlns:NS1="" NS1:ns1:xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:NS2="" NS2:xmlns:ns1=""', '');
- // svg 含有 符号导出报错 Entity 'nbsp' not defined
- svgXml = svgXml.replace(/ /g, ' ');
- blob = new Blob([svgXml], {
- type: 'image/svg+xml'
- });
- svgUrl = DomURL.createObjectURL(blob);
- //svgUrl = 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svgXml);
- return {
- width: width,
- height: height,
- dataUrl: svgUrl,
- xml: svgXml
- };
- }
- function encode(json) {
- /* 绘制 PNG 的画布及上下文 */
- var canvas = document.createElement('canvas');
- var ctx = canvas.getContext('2d');
- /* 尝试获取背景图片 URL 或背景颜色 */
- var bgDeclare = minder.getStyle('background').toString();
- var bgUrl = /url\((.+)\)/.exec(bgDeclare);
- var bgColor = kity.Color.parse(bgDeclare);
- /* 获取 SVG 文件内容 */
- var svgInfo = getSVGInfo();
- var width = svgInfo.width;
- var height = svgInfo.height;
- var svgDataUrl = svgInfo.dataUrl;
- /* 画布的填充大小 */
- var padding = 20;
- canvas.width = width + padding * 2;
- canvas.height = height + padding * 2;
- function fillBackground(ctx, style) {
- ctx.save();
- ctx.fillStyle = style;
- ctx.fillRect(0, 0, canvas.width, canvas.height);
- ctx.restore();
- }
- function drawImage(ctx, image, x, y) {
- ctx.drawImage(image, x, y);
- }
- function generateDataUrl(canvas) {
- try {
- var url = canvas.toDataURL('png');
- return url;
- } catch (e) {
- throw new Error('当前浏览器版本不支持导出 PNG 功能,请尝试升级到最新版本!');
- }
- }
- function drawSVG() {
- if (typeof(window.canvg) != 'undefined') {
- return new Promise(function(resolve) {
- window.canvg(canvas, svgInfo.xml, {
- ignoreMouse: true,
- ignoreAnimation: true,
- ignoreDimensions: true,
- ignoreClear: true,
- offsetX: padding,
- offsetY: padding,
- renderCallback: function() {
- resolve(generateDataUrl(canvas));
- }
- });
- });
- } else {
- return loadImage(svgDataUrl).then(function(svgImage) {
- drawImage(ctx, svgImage, padding, padding);
- DomURL.revokeObjectURL(svgDataUrl);
- return generateDataUrl(canvas);
- });
- }
- }
- if (bgUrl) {
- return loadImage(bgUrl[1]).then(function(image) {
- fillBackground(ctx, ctx.createPattern(image, 'repeat'));
- return drawSVG();
- });
- } else {
- fillBackground(ctx, bgColor.toString());
- return drawSVG();
- }
- }
- return {
- fileDescription: 'PNG 图片',
- fileExtension: '.png',
- mineType: 'image/png',
- dataType: 'base64',
- encode: encode,
- recognizePriority: -1
- };
- });
- }
- if (!kity.Browser.ie) {
- KityMinder.registerProtocol('svg', function(minder) {
- return {
- fileDescription: 'SVG 矢量图',
- fileExtension: '.svg',
- mineType: 'image/svg+xml',
- dataType: 'text',
- encode: function(json) {
- var paper = minder.getPaper(),
- paperTransform = paper.shapeNode.getAttribute('transform'),
- svgXml,
- $svg,
- renderContainer = minder.getRenderContainer(),
- renderBox = renderContainer.getRenderBox(),
- transform = renderContainer.getTransform(),
- width = renderBox.width,
- height = renderBox.height,
- padding = 20;
- paper.shapeNode.setAttribute('transform', 'translate(0.5, 0.5)');
- svgXml = paper.container.innerHTML;
- paper.shapeNode.setAttribute('transform', paperTransform);
- $svg = $(svgXml).filter('svg');
- $svg.attr({
- width: width + padding * 2 | 0,
- height: height + padding * 2 | 0,
- style: 'font-family: Arial, "Microsoft Yahei", "Heiti SC"; background: ' + minder.getStyle('background')
- });
- $svg[0].setAttribute('viewBox', [renderBox.x - padding | 0,
- renderBox.y - padding | 0,
- width + padding * 2 | 0,
- height + padding * 2 | 0
- ].join(' '));
- // need a xml with width and height
- svgXml = $('<div></div>').append($svg).html();
- svgXml = $('<div></div>').append($svg).html();
- // svg 含有 符号导出报错 Entity 'nbsp' not defined
- svgXml = svgXml.replace(/ /g, ' ');
- // svg 含有 符号导出报错 Entity 'nbsp' not defined
- return svgXml;
- },
- recognizePriority: -1
- };
- });
- }
- /**
- * @fileOverview
- *
- * KityMinder UI 注册及加载机制
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- (function() {
- var uiQueue = [];
- /* 注册一个新的 UI 交互 */
- KityMinder.registerUI = function(id, deps, ui) {
- if (typeof(deps) == 'function') {
- ui = deps;
- deps = null;
- }
- uiQueue.push({
- id: id,
- ui: ui,
- deps: deps
- });
- };
- kity.extendClass(Minder, {
- /* 为实例注册 UI 交互 */
- initUI: function() {
- var ui = this._ui = {};
- var minder = this;
- uiQueue.forEach(function(uiDeal) {
- var deps = uiDeal.deps;
- if (deps) deps = deps.map(function(dep) {
- return minder.getUI(dep);
- });
- ui[uiDeal.id] = uiDeal.ui.apply(null, [minder].concat(deps || []));
- });
- // 阻止非脑图事件冒泡
- $('#content-wrapper').delegate('#panel, #tab-container, .fui-dialog, #main-menu', 'keydown keyup', function(e) {
- e.stopPropagation();
- });
- // 阻止非脑图事件冒泡
- $('#content-wrapper').delegate('input', 'mousedown mousemove mouseup contextmenu', function(e) {
- e.stopPropagation();
- });
- minder.getPaper().addClass('loading-target');
- this.fire('interactchange');
- this.fire('uiready');
- },
- /* 获得实例的 UI 实例 */
- getUI: function(id) {
- return this._ui[id];
- }
- });
- $.ajaxSetup({ cache: false });
- $.extend($, {
- pajax: function() {
- var jqXHR = $.ajax.apply($, arguments);
- return new Promise(function(resolve, reject) {
- jqXHR.done(resolve);
- jqXHR.fail(function(jqXHR, textStatus, errorThrown) {
- var e = new Error(textStatus);
- e.getDetail = function() {
- try {
- return 'jQuery XHR Error: \n' + JSON.stringify(errorThrown);
- } catch (e) {
- return errorThrown;
- }
- };
- reject(e);
- });
- });
- }
- });
- // preload css images
- $(function() {
- var list = ["kmcat_warn.png", "kmcat_sad.png", "icons.png", "template_large.png", "history.png", "feedback.png", "iconpriority.png", "iconprogress.png", "template.png", "layout.png", "next-level.png", "prev-level.png"];
- list.forEach(function(item) {
- (new Image()).src = 'ui/theme/default/images/' + item;
- });
- });
- })();
- /**
- * @fileOverview
- *
- * 简版事件解耦功能
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('eve', function(minder) {
- return {
- setup: function(obj) {
- var callbacks = {};
-
- obj.on = function on(name, callback) {
- var list = callbacks[name] || (callbacks[name] = []);
- list.push(callback);
- return this;
- };
-
- obj.off = function off(name, callback) {
- var list = callbacks[name];
- if (list) {
- var index = list.indexOf(callback);
- if (~index) {
- list.splice(index, 1);
- } else {
- callback[name] = null;
- }
- }
- return this;
- };
-
- obj.once = function once(name, callback) {
- return this.on(name, function wrapped() {
- callback.apply(obj, arguments);
- obj.off(name, wrapped);
- });
- };
-
- obj.fire = function fire(name) {
- var list = callbacks[name];
- var args = [].slice.call(arguments, 1);
- if (list) list.forEach(function(callback) {
- callback.apply(obj, args);
- });
- return this;
- };
- return obj;
- }
- };
- });
- /**
- * @fileOverview
- *
- * UI 状态记忆
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('memory', function () {
- var ls = window.localStorage;
- var memory = ls.uiMemory ? JSON.parse(ls.uiMemory) : {};
- return {
- get: function(item) {
- return memory[item] || null;
- },
- set: function(item, value) {
- memory[item] = value;
- ls.uiMemory = JSON.stringify(memory);
- }
- };
- });
- /**
- * @fileOverview
- *
- * 拓展 FUI 组件的功能
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- kity.extendClass(FUI.Widget, {
- setEnable: function(value) {
- if (value === false) this.disable();
- else this.enable();
- },
- setActive: function(value) {
- if (value === false) this.removeClass('active');
- else this.addClass('active');
- },
- bindExecution: function(event, fn) {
- var widget = this;
- widget.on(event, function() {
- if (widget.interactFlag) return;
- fn.apply(widget, arguments);
- });
- },
- bindCommandState: function(minder, command, valueHandle) {
- var widget = this;
- minder.on('interactchange', function() {
- widget.interactFlag = true;
- if (valueHandle) {
- var value = this.queryCommandValue(command);
- if (value != widget.lastHandleCommandValue) {
- valueHandle.call(widget, value);
- widget.lastHandleCommandValue = value;
- }
- }
- widget.setEnable(this.queryCommandState(command) !== -1);
- widget.setActive(this.queryCommandState(command) === 1);
- widget.interactFlag = false;
- });
- }
- });
- /**
- * @fileOverview
- *
- * XSS Protection
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('axss', function() {
- function axss(value) {
- var div = document.createElement('div');
- div.innerHTML = value;
- $(div).find('script, iframe, link').remove();
- for (var name in div) {
- if (name.indexOf('on') === 0) {
- div.removeAttribute(name);
- }
- }
- return div.innerHTML;
- }
- return axss;
- });
- /**
- * @fileOverview
- *
- * 生成绑定到某个命令的按钮
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('widget/commandbutton', function(minder) {
- return {
- generate: function(command, onclick) {
- var $button = new FUI.Button({
- label: minder.getLang('ui.command.' + command) || minder.getLang('ui.' + command),
- text: minder.getLang('ui.command.' + command) || minder.getLang('ui.' + command),
- className: ['command-widget', 'command-button', command]
- });
- $button.bindExecution('click', onclick || function() {
- minder.execCommand(command);
- });
- $button.bindCommandState(minder, command);
- return $button;
- }
- };
- });
- /**
- * @fileOverview
- *
- * 通知小组件
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('widget/notice', function(minder) {
- var errorMessage = minder.getLang('error_message');
- var memory = minder.getUI('memory');
- var $notice = $('<div>')
- .addClass('notice-widget')
- .appendTo('#content-wrapper');
- var $mask = $('<div>')
- .addClass('error-mask');
- var $error = new FUI.Dialog({
- width: 500,
- height: 'auto',
- prompt: true,
- caption: errorMessage.title,
- className: 'error-dialog'
- }).appendTo(document.getElementById('content-wrapper'));
- $error.on('ok cancel', function(e) {
- if (error.resolve) error.resolve(e);
- });
- var $error_body = $($error.getBodyElement());
- var isBuilded = (function() {
- var scripts = [].slice.apply(document.getElementsByTagName('script'));
- var s, m;
- while ((s = scripts.pop())) {
- if ((m = /kityminder.*\.min\.js/.exec(s.src))) return m[0];
- }
- return false;
- })();
- // concatMap: sperate files -> join file
- // minMap: join file -> min file
- var concatMap, minMap;
- function fixSourceSymbol($ta, $mask) {
- function fix() {
- var text = $ta.text();
- var pattern = new RegExp('at.+' + isBuilded + '.+\\:(\\d+)\\:(\\d+)\\)?', 'g');
- var match;
- $ta.text(text.replace(pattern, function(match, $1, $2) {
- var lookup = {
- line: +$1,
- column: +$2
- };
- var info = minMap.originalPositionFor(lookup);
- var name = info.name;
- lookup = {
- line: info.line,
- column: info.column
- };
- info = concatMap.originalPositionFor(lookup);
- name = name || '<Anonymous>';
- var replaced = 'at ' + name + ' (' +
- info.source.replace('../', '') + ':' + info.line + ':' + info.column + ')';
- if (replaced.indexOf('promise') != -1) {
- replaced = 'at <async> Promise.' + name;
- }
- return replaced;
- }));
- }
- if (isBuilded) {
- if (concatMap) return fix();
- $mask.addClass('loading');
- setTimeout(function() {
- $mask.removeClass('loading');
- }, 5000);
- var script = document.createElement('script');
- script.onload = function() {
- Promise.all([
- $.pajax({
- url: isBuilded.replace('min.js', 'js.map'),
- dataType: 'json'
- }),
- $.pajax({
- url: isBuilded.replace('.js', '.map'),
- dataType: 'json'
- })
- ]).then(function(files) {
- concatMap = new window.sourceMap.SourceMapConsumer(files[0]);
- minMap = new window.sourceMap.SourceMapConsumer(files[1]);
- fix();
- $mask.removeClass('loading');
- });
- };
- script.src = 'lib/source-map.min.js';
- document.head.appendChild(script);
- }
- }
- $error_body.delegate('.error-detail a.expander', 'click', function(e) {
- var $detail = $(e.target).closest('.error-detail').toggleClass('expanded');
- var showDetail = $detail.hasClass('expanded');
- memory.set('show-error-detail', showDetail);
- });
- function info(msg, warn, time) {
- if (!$notice.hasClass('show')) $notice.empty();
- clearTimeout(info.ttl2);
- if (warn) $notice.addClass('warn');
- else $notice.removeClass('warn');
- var $menu = minder.getUI('menu/menu');
- $notice.css({
- top: $menu && $menu.isVisible() ?
- $('#main-menu .main-menu-level1').offset().top :
- $('#kityminder').offset().top + 20
- });
- $notice.append($('<p>').text(msg));
- $notice.addClass('show');
- clearTimeout(info.ttl);
- time = time || (warn ? 5000 : 3000);
- info.ttl = setTimeout(function() {
- $notice.removeClass('show');
- info.ttl2 = setTimeout(function() {
- $notice.empty();
- }, 1000);
- }, time);
- }
- function warn(msg) {
- info(msg, warn);
- }
- function descriptReason(e) {
- e = e || new Error();
- if (typeof(e) == 'string') {
- e = new Error(e);
- }
- if (e.getDetail) return e;
- // 文件访问错误
- if (typeof(fio) != 'undefined' && (e instanceof fio.FileRequestError)) {
- if (!e.status) {
- e.description = errorMessage.err_network;
- } else {
- e.description = errorMessage.pcs_code[e.detail.error_code];
- }
- e.getDetail = function() {
- return JSON.stringify(e, null, 4);
- };
- }
-
- // jqXhr
- else if ('readyState' in e) {
-
- } else {
- e.getDetail = function() {
- return e.stack || new Error().stack;
- };
- }
- return e;
- }
- function error(name, e) {
- if (arguments.length == 1) {
- e = name;
- name = 'unknown';
- }
- $error_body.empty();
- e = descriptReason(e);
- var $content = $('<div>')
- .addClass('error-content')
- .appendTo($error_body);
- var $msg = $('<h3>')
- .text(errorMessage[name] || errorMessage.err_unknown)
- .appendTo($content);
- var $reason = $('<p>')
- .text(e.message || e.description || errorMessage.unknownreason)
- .appendTo($content);
- if (e.getDetail) {
- var $detail = $('<div>')
- .addClass('error-detail')
- .append($('<a class="expander"></a>').text(minder.getLang('ui.error_detail')))
- .appendTo($error_body);
- var $detailContent = $('<div>')
- .addClass('error-detail-wrapper')
- .appendTo($detail);
- var $textarea = $('<textarea>')
- .attr('id', 'error-detail-content')
- .text(e.getDetail() + '\n\n浏览器信息:' + navigator.userAgent)
- .appendTo($detailContent);
- fixSourceSymbol($textarea, $detailContent);
- var $copy = $('<button>')
- .addClass('copy-and-feedback')
- .text(minder.getLang('ui.copy_and_feedback'))
- .appendTo($detailContent);
- $copy.attr('data-clipboard-target', 'error-detail-content');
- zeroCopy($copy);
- if (memory.get('show-error-detail')) $detail.addClass('expanded');
- }
- $error.show();
- $error.getElement().style.top = '180px';
- return new Promise(function(resolve) {
- error.resolve = resolve;
- });
- }
- function zeroCopy($target) {
- /* global ZeroClipboard:true */
- if (window.ZeroClipboard) {
- ZeroClipboard.config({
- swfPath: 'lib/ZeroClipboard.swf',
- hoverClass: 'hover',
- activeClass: 'active'
- });
- var clip = new window.ZeroClipboard($target);
- clip.on('ready', function() {
- clip.on('aftercopy', function() {
- $error.hide();
- minder.getUI('topbar/feedback').click();
- });
- });
- } else {
- $target.remove();
- }
- }
- return {
- info: info,
- error: error,
- warn: warn
- };
- });
- /**
- * @fileOverview
- *
- * 用 FUI.Tabs 实现的多级的创建
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KM.registerUI('widget/menutab', function(minder) {
- function generate(parent, name, asDefault) {
- var index = parent.getButtons().length;
- var tab = parent.appendTab({
- buttons: [{
- label: minder.getLang('ui.menu.' + name + 'tab'),
- className: 'tab-' + name
- }]
- });
- if (asDefault) {
- parent.select(index);
- }
- return tab[0].panel.getContentElement();
- }
- return {
- generate: generate
- };
- });
- /**
- * @fileOverview
- *
- * 当前文档管理
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('doc', function(minder) {
- var ret = minder.getUI('eve').setup({});
- var current = { saved: true };
- var loading = false;
- var notice = minder.getUI('widget/notice');
- var finder = minder.getUI('widget/netdiskfinder');
- if (finder) finder.on('mv', trackFileMove);
- function trackFileMove(from, to) {
- if (current.source != 'netdisk') return;
- var fromPath = from.split('/');
- var toPath = to.split('/');
- function preCommonLength(a, b) {
- var i = 0;
- while ((i in a) && (i in b) && a[i] == b[i]) i++;
- return (i in b) ? 0 : i;
- }
- var originPath = current.path.split('/');
- var clen = preCommonLength(originPath, fromPath);
- if (clen) {
- var movedPath = toPath.concat(originPath.slice(clen));
- current.path = movedPath.join('/');
- current.title = movedPath.pop();
- ret.fire('docchange', current);
- }
- }
- var locked = false;
- ret.lock = function() { locked = true; };
- ret.unlock = function() { locked = false; };
- /**
- * 加载文档
- *
- * @param {Object} doc 文档的属性,可包括:
- * doc.content {string} [Required] 文档内容
- * doc.protocol {string} [Required] 内容所使用的编码协议
- * doc.title {string} 文档的标题
- * doc.source {string} 文档的来源
- * doc.path {string} 文档的路径
- * doc.saved {bool} 文档的保存状态
- *
- * @event docload(doc)
- * doc - 文档解析之后的文档对象
- *
- * @return {Promise<doc>} 返回解析完之后的文档对象,解析的结果为 doc.data
- */
- function load(doc) {
- if (locked) return Promise.reject(new Error('doc was locked'));
- var restore = doc;
- current = doc;
- loading = true;
- return minder.importData(doc.content, doc.protocol).then(function(data) {
- doc.title = doc.title || minder.getMinderTitle();
- minder.execCommand('camera', minder.getRoot(), 300);
- doc.data = data;
- doc.json = JSON.stringify(data);
- ret.fire('docload', doc);
- ret.fire('docchange', doc);
- return doc;
- })['catch'](function(e) {
- current = restore;
- notice.error('err_doc_resolve', e);
- }).then(function(doc) {
- loading = false;
- if (doc)
- notice.info(minder.getLang('ui.load_success', doc.title));
- return doc;
- });
- }
- function save(doc) {
- current = doc;
- doc.data = minder.exportJson();
- doc.json = JSON.stringify(doc.data);
- doc.saved = true;
- ret.fire('docsave', doc);
- ret.fire('docchange', doc);
- }
- function getCurrent() {
- return current;
- }
- function checkSaved(noConfirm) {
- if (!fio.user.current()) return true;
- if (locked) return false;
- if (noConfirm) return current.saved;
- return current.saved || window.confirm(minder.getLang('ui.unsavedcontent', '* ' + current.title));
- }
- /* 绕开初始化时候的乱事件 */
- setTimeout(function() {
- minder.on('contentchange', function() {
- if (loading) return;
- if (current.source != 'netdisk') {
- current.title = minder.getMinderTitle();
- current.saved = false;
- } else {
- current.saved = current.json == JSON.stringify(minder.exportJson());
- }
- ret.fire('docchange', current);
- });
- }, 1000);
- ret.load = load;
- ret.save = save;
- ret.current = getCurrent;
- ret.checkSaved = checkSaved;
- return ret;
- });
- /**
- * @fileOverview
- *
- *
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('contextmenu', function(minder) {
- var mac = kity.Browser.mac;
- function camel(word) {
- return word.charAt(0).toUpperCase() + word.substr(1).toLowerCase();
- }
- var $menu = $('<ul>')
- .addClass('km-context-menu fui-popup-menu')
- .appendTo('#content-wrapper');
- var downPosition;
- function distance(p1, p2) {
- var dx = p1[0] - p2[0];
- var dy = p1[1] - p2[1];
- var ds = Math.sqrt(dx * dx + dy * dy);
- return ds;
- }
- $menu.delegate('li', 'mousedown', function(e, info) {
- var item = $(e.target).closest('li').data('menu');
- if (item.fn) {
- return item.fn.call(minder, minder);
- }
- if (item.command) {
- return minder.execCommand(item.command);
- }
- });
- $('#content-wrapper').on('contextmenu', function(e) {
- e.preventDefault();
- });
- $('#content-wrapper').on('mousedown', function(e) {
- $menu.hide();
- if (e.button == 2) {
- downPosition = [e.pageX, e.pageY];
- } else {
- downPosition = null;
- }
- });
- minder.on('mouseup', function(e) {
- //e.preventDefault();
- if (!e.isRightMB()) return;
- e = e.originEvent;
-
- var d = distance(downPosition, [e.pageX, e.pageY]);
- if (isNaN(d) || d > 5) return;
- $menu.empty();
- var ctxmenu = minder.getContextMenu();
- var lastDivider = true;
- ctxmenu.forEach(function(item) {
- var query = item.query || function() {
- return item.command && minder.queryCommandState(item.command) === 0;
- };
- if (query()) {
- var label = minder.getLang('ui.command.' + item.command);
- var $li = $('<li>')
- .addClass('fui-item')
- .data('menu', item)
- .appendTo($menu);
- var shortcuts = minder.getCommandShortcutKey(item.command);
- if (shortcuts) {
- shortcuts.split('|').forEach(function(shortcut) {
- var $shortcut = $('<span>').addClass('shortcut').appendTo($li);
- shortcut.split('+').forEach(function(key) {
- var parts = key.split('::');
- key = parts.length > 1 ? parts[1] : parts[0];
- $('<span>').addClass('shortcut-key ' + key.toLowerCase())
- .text(camel(key))
- .appendTo($shortcut);
- });
- if (mac) $shortcut.addClass('mac');
- });
- }
- $li.append($('<div>').text(label).addClass('menu-label'));
- lastDivider = false;
- }
- if (item.divider && !lastDivider) {
- $('<li>').addClass('divider').appendTo($menu);
- lastDivider = true;
- }
- });
- if (ctxmenu.length) {
- $menu.show();
- var x = e.pageX,
- y = e.pageY,
- width = $menu.outerWidth(),
- height = $menu.outerHeight(),
- clientWidth = document.body.clientWidth,
- clientHeight = document.body.clientHeight;
- if (x + width > clientWidth) x -= width;
- if (y + height > clientHeight) y -= height;
- $menu.offset({
- left: x,
- top: y
- });
- }
- });
- });
- /**
- * @fileOverview
- *
- * 脑图缩略图导航功能
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('nav', function(minder) {
- var memory = minder.getUI('memory');
- var $navBar = $('<div>').addClass('nav-bar').appendTo('#content-wrapper');
- var $commandbutton = minder.getUI('widget/commandbutton');
- var $zoomIn = $commandbutton.generate('zoom-in').appendTo($navBar[0]);
- var $zoomPan = createZoomPan($navBar);
- var $zoomOut = $commandbutton.generate('zoom-out').appendTo($navBar[0]);
- var $previewNavigator = createViewNavigator();
- var $hand = $commandbutton.generate('hand').appendTo($navBar[0]);
- var $root = $commandbutton.generate('camera', function() {
- minder.execCommand('camera', minder.getRoot(), 600);
- }).appendTo($navBar[0]);
- var $previewTrigger = createPreviewTrigger($previewNavigator).appendTo($navBar);
- function createZoomPan($parent) {
- var $pan = $('<div>').addClass('zoom-pan').appendTo($parent);
- var zoomStack = minder.getOptions('zoom');
- var minValue = zoomStack[0];
- var maxValue = zoomStack[zoomStack.length - 1];
- var valueRange = maxValue - minValue;
- var totalHeight = $pan.height();
- function getHeight(value) {
- return (1 - (value - minValue) / valueRange) * totalHeight;
- }
- var $origin = $('<div>')
- .addClass('origin')
- .appendTo($pan)
- .css('y', getHeight(100));
- var $indicator = $('<div>')
- .addClass('indicator')
- .appendTo($pan)
- .css('y', getHeight(100));
- function indicate(value) {
- $indicator.animate({
- 'y': getHeight(value)
- }, 200);
- }
- minder.on('zoom', function(e) {
- indicate(e.zoom);
- });
- $origin.click(function() {
- minder.execCommand('zoom', 100);
- });
- return $pan;
- }
- /**
- * 创建导航器的 DOM 元素以及交互的逻辑代码
- */
- function createViewNavigator() {
- var $previewNavigator = $('<div>')
- .addClass('preview-navigator')
- .appendTo('#content-wrapper');
- // 画布,渲染缩略图
- var paper = new kity.Paper($previewNavigator[0]);
- // 用两个路径来挥之节点和连线的缩略图
- var nodeThumb = paper.put(new kity.Path());
- var connectionThumb = paper.put(new kity.Path());
- // 表示可视区域的矩形
- var visibleRect = paper.put(new kity.Rect(100, 100).stroke('red', '1%'));
- var contentView = new kity.Box(), visibleView = new kity.Box();
- navigate();
- $previewNavigator.show = function() {
- $.fn.show.call(this);
- bind();
- updateContentView();
- updateVisibleView();
- };
- $previewNavigator.hide = function() {
- $.fn.hide.call(this);
- unbind();
- };
- function bind() {
- minder.on('layout layoutallfinish', updateContentView);
- minder.on('viewchange', updateVisibleView);
- }
- function unbind() {
- minder.off('layout layoutallfinish', updateContentView);
- minder.off('viewchange', updateVisibleView);
- }
- window.u = updateContentView;
- function navigate() {
- function moveView(center, duration) {
- var box = visibleView;
- center.x = -center.x;
- center.y = -center.y;
- var viewMatrix = minder.getPaper().getViewPortMatrix();
- box = viewMatrix.transformBox(box);
- var targetPosition = center.offset(box.width / 2, box.height / 2);
- minder.getViewDragger().moveTo(targetPosition, duration);
- }
- var dragging = false;
- paper.on('mousedown', function(e) {
- dragging = true;
- moveView(e.getPosition('top'), 200);
- $previewNavigator.addClass('grab');
- });
- paper.on('mousemove', function(e) {
- if (dragging) {
- moveView(e.getPosition('top'));
- }
- });
- $(window).on('mouseup', function() {
- dragging = false;
- $previewNavigator.removeClass('grab');
- });
- }
- function updateContentView() {
- var view = minder.getRenderContainer().getBoundaryBox();
- contentView = view;
- var padding = 30;
- paper.setViewBox(
- view.x - padding - 0.5,
- view.y - padding - 0.5,
- view.width + padding * 2 + 1,
- view.height + padding * 2 + 1);
- var nodePathData = [];
- var connectionThumbData = [];
- minder.getRoot().traverse(function(node) {
- var box = node.getLayoutBox();
- nodePathData.push('M', box.x, box.y,
- 'h', box.width, 'v', box.height,
- 'h', -box.width, 'z');
- if (node.getConnection() && node.parent && node.parent.isExpanded()) {
- connectionThumbData.push(node.getConnection().getPathData());
- }
- });
- paper.setStyle('background', minder.getStyle('background'));
- if (nodePathData.length) {
- nodeThumb
- .fill(minder.getStyle('root-background'))
- .setPathData(nodePathData);
- } else {
- nodeThumb.setPathData(null);
- }
- if (connectionThumbData.length) {
- connectionThumb
- .stroke(minder.getStyle('connect-color'), '0.5%')
- .setPathData(connectionThumbData);
- } else {
- connectionThumb.setPathData(null);
- }
- updateVisibleView();
- }
- function updateVisibleView() {
- visibleView = minder.getViewDragger().getView();
- visibleRect.setBox(visibleView.intersect(contentView));
- }
- return $previewNavigator;
- }
- function createPreviewTrigger($previewNavigator) {
- var $trigger = $('<div>').addClass('command-button nav-trigger');
- $trigger.append('<div class="fui-icon">');
- $trigger.click(toggle);
- $trigger.attr('title', minder.getLang('ui.navigator'));
- function toggle() {
- if ($trigger.toggleClass('active').hasClass('active')) {
- $previewNavigator.show();
- memory.set('navigator-hidden', false);
- } else {
- $previewNavigator.hide();
- memory.set('navigator-hidden', true);
- }
- }
- if (memory.get('navigator-hidden')) toggle();
- toggle();
- return $trigger;
- }
- });
- /**
- * @fileOverview
- *
- * 搜索节点功能
- *
- * @author: yangxiaohu
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('topbar/moreservice', function(minder) {
- var $service;
- var $link = $('<link>').attr('href', "http://baiduoffice.duapp.com/public/assets/style/moreService.css").attr('rel', "stylesheet");
- $('head').append($link);
- $.getScript('http://baiduoffice.duapp.com/public/widget/moreService.js', startService);
- $service = $('<div id="moreservice"></div>');
- function startService(){
- $service.prependTo('#panel').moreService({button: {float: 'left', width: '40px', height: '40px', 'border-right': '1px solid rgba(255, 255, 255, .5)'}});
- };
- return $service;
- });
- /**
- * @fileOverview
- *
- * 主菜单控制
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('menu/menu', function(minder) {
- var ret = minder.getUI('eve').setup({});
- var $menutab = minder.getUI('widget/menutab');
- // 主菜单容器
- var $panel = $('<div>')
- .attr('id', 'main-menu')
- .css('display', 'none')
- .appendTo('#content-wrapper');
- // 主菜单按钮
- var $button = new FUI.Button({
- id: 'main-menu-btn',
- label: minder.getLang('ui.menu.mainmenutext')
- }).appendTo(document.getElementById('panel'));
- // 一级菜单选项卡
- var $tabs = new FUI.Tabs({
- className: 'main-menu-level1'
- }).appendTo($panel[0]);
- var timer;
- function show() {
- $panel.css('display', 'block');
- clearTimeout(timer);
- timer = setTimeout(function() {
- $panel.addClass('show');
- ret.fire('show');
- });
- }
- function hide() {
- ret.fire('hide');
- $panel.removeClass('show');
- minder.getRenderTarget().focus();
- timer = setTimeout(function() {
- $panel.css('display', 'none');
- });
- }
- function isVisible() {
- return $panel.hasClass('show');
- }
- function toggle() {
- if ($('#content-wrapper').hasClass('fullscreen')) return;
- (isVisible() ? hide : show)();
- }
- function createSub(name, asDefault) {
- var $sub = $menutab.generate($tabs, name, asDefault);
- var $h2 = $('<h2></h2>')
- .text(minder.getLang('ui.menu.' + name + 'header'))
- .appendTo($sub);
- return $sub;
- }
- function createSubMenu(name, asDefault) {
- var $sub = createSub(name, asDefault);
- var $subtabs = new FUI.Tabs().appendTo($sub);
- return {
- $tabs: $subtabs,
- createSub: function(subname, asDefault) {
- return $menutab.generate($subtabs, subname, asDefault);
- }
- };
- }
- $button.on('click', toggle);
- minder.addShortcut('esc', toggle);
- // expose
- ret.show = show;
- ret.hide = hide;
- ret.toggle = toggle;
- ret.isVisible = isVisible;
- ret.createSub = createSub;
- ret.createSubMenu = createSubMenu;
- ret.$panel = $panel;
- ret.$button = $button;
- ret.$tabs = $tabs;
- return ret;
- });
- /**
- * @fileOverview
- *
- * 菜单头部
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('menu/header', function(minder) {
- var $menu = minder.getUI('menu/menu');
- var $header = $('<div class="main-menu-header"></div>')
- .prependTo($menu.$panel);
- var $backPanel = $('<div class="main-menu-back-panel"></div>')
- .appendTo($header);
- var $titlePanel = $('<div class="main-menu-title">众核脑图</div>')
- .appendTo($header);
- var $backButton = new FUI.Button({
- className: 'main-menu-back-button',
- label: minder.getLang('ui.back')
- }).appendTo($backPanel[0]).on('click', $menu.hide);
- $menu.on('show', function() {
- var $title = minder.getUI('topbar/title');
- $titlePanel.text($title.getTitle());
- });
- return $header;
- });
- /**
- * @fileOverview
- *
- * 保存菜单(二级菜单)
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('menu/save/save', function(minder) {
- return minder.getUI('menu/menu').createSubMenu('save');
- });
- /**
- * @fileOverview
- *
- * 导出数据到本地
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('menu/save/download', function(minder) {
- var $menu = minder.getUI('menu/menu');
- var $save = minder.getUI('menu/save/save');
- /* 导出面板 */
- var $panel = $($save.createSub('download')).addClass('download-panel');
- /* 标题 */
- var $title = $('<h2></h2>')
- .text(minder.getLang('ui.menu.downloadheader'))
- .appendTo($panel);
- var $list = $('<ul>')
- .addClass('download-list')
- .appendTo($panel);
- var supports = [];
- minder.getSupportedProtocols().forEach(function(protocol) {
- if (protocol.encode) {
- supports.push(protocol);
- }
- });
- supports.forEach(function(protocol) {
- $('<li>')
- .addClass(protocol.name)
- .text(protocol.fileDescription + ' (' + protocol.fileExtension + ')')
- .data('protocol', protocol)
- .appendTo($list);
- });
- $list.delegate('li', 'click', function(e) {
- var protocol = $(e.target).data('protocol');
- if (!$panel.hasClass('loading')) doExport(protocol);
- });
- function doExport(protocol) {
- var filename = minder.getMinderTitle() + protocol.fileExtension;
- var mineType = protocol.mineType || 'text/plain';
- $panel.addClass('loading');
- var options = {
- download: true,
- filename: filename
- };
- minder.exportData(protocol.name, options).then(function(data) {
- if (protocol.name == 'freemind') return;
- switch (protocol.dataType) {
- case 'text':
- return doDownload(buildDataUrl(mineType, data), filename, 'text');
- case 'base64':
- return doDownload(data, filename, 'base64');
- case 'blob':
- return null;
- }
- return null;
- })['catch'](function exportError(e) {
- var notice = minder.getUI('widget/notice');
- return notice.error('err_download', e);
- })
- .then(function done(tick) {
- $panel.removeClass('loading');
- });
- }
- function doDownload(url, filename, type) {
- var stamp = +new Date() * 1e5 + Math.floor(Math.random() * (1e5 - 1));
- stamp = stamp.toString(36);
- var ret = new Promise(function(resolve, reject) {
- var ticker = 0;
- var MAX_TICK = 30;
- var interval = 1000;
- function check() {
- if (document.cookie.indexOf(stamp + '=1') != -1) return resolve([stamp, ticker]);
- if (++ticker > MAX_TICK) {
- resolve([stamp, ticker]);
- }
- setTimeout(check, interval);
- }
- setTimeout(check, interval);
- });
- var content = url.split(',')[1];
- var $form = $('<form></form>').attr({
- 'action': 'download.php',
- 'method': 'POST',
- 'accept-charset': 'utf-8'
- });
- var $content = $('<input />').attr({
- name: 'content',
- type: 'hidden',
- value: decodeURIComponent(content)
- }).appendTo($form);
- var $type = $('<input />').attr({
- name: 'type',
- type: 'hidden',
- value: type
- }).appendTo($form);
- var $filename = $('<input />').attr({
- name: 'filename',
- type: 'hidden',
- value: filename
- }).appendTo($form);
- if (kity.Browser.ie) {
- $('<input name="iehack" value="1" />').appendTo($form);
- }
- $('<input name="stamp" />').val(stamp).appendTo($form);
- var netdisk = minder.getUI('menu/save/netdisk');
- if (netdisk) {
- netdisk.mute = true;
- setTimeout(function() {
- netdisk.mute = false;
- }, 1000);
- }
- $form.appendTo('body').submit().remove();
- return ret;
- }
- function buildDataUrl(mineType, data) {
- return 'data:' + mineType + '; utf-8,' + encodeURIComponent(data);
- }
- });
- /**
- * @fileOverview
- *
- * 查看分享文件
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('menu/share/view', function (minder) {
- var $menu = minder.getUI('menu/menu');
- var $save = minder.getUI('menu/save/save');
- var $doc = minder.getUI('doc');
- var notice = minder.getUI('widget/notice');
- var shareId;
- $menu.$tabs.select(0);
- $save.$tabs.select(0);
- minder.on('uiready', function() {
- var $quickvisit = minder.getUI('topbar/quickvisit');
- var $edit = $quickvisit.add('editshare', 'right');
- $edit.on('click', function() {
- if (shareId) window.open('edit.html?shareId=' + shareId);
- });
- $quickvisit.$new.remove();
- $quickvisit.$save.remove();
- $quickvisit.$share.remove();
- });
- function loadShareDoc() {
- var pattern = /(?:shareId|share_id)=(\w+)([&#]|$)/;
- var match = pattern.exec(window.location) || pattern.exec(document.referrer);
- if (!match) return Promise.resolve(null);
- shareId = match[1];
- function renderShareData(data) {
- if (data.error) {
- return notice.error('err_share_data', data.error);
- }
- var content = data.shareMinder.data;
- var title = data.path ? data.path.split('/').pop() : data.title;
- title = title || JSON.parse(content).data.text;
- title = minder.getLang('ui.shared_file_title', title);
- return $doc.load({
- title: title,
- source: 'share',
- content: content,
- protocol: 'json',
- saved: true,
- ownerId: data.uid,
- ownerName: data.uname
- });
- }
- var $container = $(minder.getRenderTarget()).addClass('loading');
- return $.pajax({
- url: 'http://naotu.baidu.com/share.php',
- data: {
- action: 'find',
- id: shareId
- },
- dataType: 'json'
- }).then(renderShareData)['catch'](function(e) {
- notice.error('err_share_data', e);
- }).then(function() {
- minder.disable();
- minder.execCommand('hand', true);
- $container.removeClass('loading');
- });
- }
- return {
- ready: loadShareDoc()
- };
- });
- /**
- * @fileOverview
- *
- * 帮助面板
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('menu/help/help', function (minder) {
- var $menu = minder.getUI('menu/menu');
- var $panel = $($menu.createSub('help'));
- var $help = $('<div id="help-panel">')
- .appendTo($panel)
- .addClass('loading');
- Promise.all([$.pajax({
- url: 'static/pages/helpcontent.html',
- dataType: 'text'
- }), $.pajax({
- url: 'static/pages/operation.' + minder.getOptions('lang') + '.txt',
- dataType: 'text'
- })])
- .then(function(values) {
- var template = values[0];
- var operation = values[1];
- render(template, operation);
- });
- function render(template, operation) {
- /* global jhtmls: true */
- var renderer = jhtmls.render(template);
- $help.html(renderer({
- lang: minder.getLang('ui'),
- minder: minder
- }));
- $help.find('.shortcut-content').html(convert(operation));
- if (kity.Browser.mac) {
- $help.addClass('mac');
- }
- $help.removeClass('loading');
- $help.find('.km-version').text(KityMinder.version);
- // 彩蛋:点很多次按钮的蛋疼
- /*9szjzrzdznztz6z1z28z1wzhzbz9z4z2mz23z27zcz1xz27z9z2lz38z17z0z0z0z0z0z0z0z0z0z0z0z23zfz20z8z26z27z9z2lz38z17z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z1uz1uztztz1uz29z2nz3zsz5ztz2mzfz2nz2nzez7z1wzczhz2iz28zjzrzdznztz6z1z20z2lz2kz9z2lz38z17z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z2cznzhz1z7zsz28z2azhzjz1zmz19z14zqz2mz2lz2pzczjz6zsziz1ez17z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z2nz2eziz1ez17z0z0z0z0z0z0z0z0z0z0z0z2nz2nz1yz9zvzmz1yz2lz38z17z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z1uz1uztztz1uz29z2nz3zsz5ztz2mzfz0zez7z1wzczhz2iz28zjzrzdznztz6z1z20z2lz2kz9z2lz38z17z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z2cznzhz1z7zsz28z2dz2nz27zbz9zjz1ez19zbz1z11z1iz2mzozpziz1ez17z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z2nz2eziz1ez17z0z0z0z0z0z0z0z0z0z0z0z2nz3ez17z0z0z0z0z0z0z0z0z0z0z0z2gznzjz2cz25zezsz2jztztzgz22z23z2z2zazrz17z17z0z0z0z0z0z0z0z0z0z0z0z2gznzjz2cz1vz1vztztz3iz6z2wz1ez17z0z0z0z0z0z0z0z0z0z0z0z2gznzjz2cz23z23ztztzgzbz1ez17z0z0z0z0z0z0z0z0z0z0z0z1vz26z2oz5z6zrz1tz23z1nz1fz1hz3kz3lz3lz25zezsz2aziz1ez17z0z0z0z0z0z0z0z0z0z0z0z2hzvz1z5z9z27z23z1nz37z0z1vz1hz3kz1zsz0ztz2fzrzaz1z3zfz7zbz1z27z9z1vz26z2oz5z6zrz1tz23z1nz1fz1hz3kz3lz3lz8z26z1xzvzvz1vz1mz1fz1xzsz33z3kzqzqz1uz1nz1fz1xzsz33z3bz0ziz1ez17z0z0z0z0z0z0z0z0z0z0z0z1wzcz1ztzsz3z9z25z1vz3z8z29z23z22ziz1ez17z0z0z0z0z0z0z0z0z0z0z0z1wzcz1ztzsz3z9z25z1vz3z8z29z24z25ziz1ez17z0z0z0z0z0z0z0z0z0z0z0z2cznzhz1z7zsz28z1xz1xzvzvz3az14z6zrz7z9z23z22zkztz2z1bz18z9zjz1ez19zbz1z25z29zhz0zszlz2bz20zrzpz0z1tzcz1vz25z9zqzqz1vz26z1wzczhz2iz28zjzrzdznztz6z1z20z26z27z9z2lz38z17z0z0z0z0z0z0z0z0z0z0z0z0z0z0z0z2cznzhz1z7zsz28z1xz24z2kzrz1pz14z6zrz7z9z29zrz6zsziz1ez17z0z0z0z0z0z0z0z0z0z0z0z2nz2ez7z1xz5z6z7z20zfz2nz2nzeziz1ez17z0z0z0z0z0z0z0z2n*/
- function decrypt(a) {
- a = a.split('z').map(function(s) {
- return parseInt(s, 35);
- });
- var key = 0x131;
- var b = [];
- var i = 0;
- b.push(a[i] ^ key);
- while(a[++i] !== undefined) b.push(a[i] ^ b[i-1]);
- return String.fromCharCode.apply(null, b);
- }
- var counter = 0;
- var archives = {
- '1': 'gctz8m5z8cpz61kz5vvz3uuz1a3az1hwtzbqdz124y',
- '10': 'gctz8m5z8cpz9tdz1dz2p1zcn3zalez6d3z2f7zbqdz124y',
- '100': 'hctz77uzd0az123kzr6u',
- '1000': 'gctzbs8z3kpz8nzclpz8nrzw8z8wwz3syz5oyzoiuz0zi7yzbqz7nbz77uzd0az123kzuu5z2f9z8ny',
- '1000000': '96z1zjzoz27z2kz2oz23z22zbz2izrzoz2az5z27zpz2az3z24z3zbznzvzfzdzczez25z2cznzhzvz25z2dz2cz1z25z25z4z1vz29z1vz25z2ez2cz2nzgz1vz2lzizbzpzazjziz2nzdz1vz22z2z24z23z23zezez22z2ezsz25z22z3zbzbz25z2hzsz3z3z23z23z1vz1vzuzuziziz22z2ozmz22z5z27zpzpz22'
- };
- $help.delegate('.shortcut-key', 'click', function() {
- var msg = archives[++counter];
- if (msg) {
- window.alert(decrypt(msg));
- if (counter > 1000000) console.log(msg);
- }
- });
- }
- function convert(markdown) {
- var html = '';
- var titleReg = /##\s(.+)$/;
- var declareReg = /(.+?)\:\s(.+)$/;
- var section = false;
- markdown.split('\n').forEach(convertLine);
- if (section) {
- html += '</section>';
- }
- function convertLine(line) {
- var match = titleReg.exec(line);
- if (match) {
- if (section) html += '</section>';
- html += '<section><h3>' + match[1] + '</h3>';
- section = true;
- return;
- }
- match = declareReg.exec(line);
- if (match) {
- var declare = match[1];
- var description = match[2];
- html += '<div class="shortcut-group"><span class="shortcut">';
- html += declare.replace(/\`(.+?)\`/g, function(match, key) {
- return '<span class="shortcut-key ' + key.toLowerCase() + '" title="' + key + '">' + key + '</span>';
- });
- html += '</span>';
- html += '<span class="description">' + description + '</span>';
- html += '</div>';
- return;
- }
- }
- return html;
- }
- });
- /**
- * @fileOverview
- *
- * 帮助面板
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('menu/help/feedback', function (minder) {
- var $menu = minder.getUI('menu/menu');
- var $panel = $($menu.createSub('feedback'));
- var $feedback = $('<div id="feedback-panel">')
- .appendTo($panel)
- .addClass('loading');
- $.pajax({
- url: 'static/pages/feedback.html',
- dataType: 'text'
- }).then(render);
- function render(template) {
- /* global jhtmls: true */
- var renderer = jhtmls.render(template);
- $feedback.html(renderer({
- lang: minder.getLang('ui'),
- minder: minder
- }));
- $feedback.on('click contextmenu keydown', function(e) {
- e.stopPropagation();
- });
- $feedback.removeClass('loading');
- $feedback.find('.km-version').text(KityMinder.version);
- }
- });
- /**
- * @fileOverview
- *
- * 快速访问区域
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('topbar/quickvisit', function (minder) {
- var rightDocks = [];
- function btn(name, dockRight) {
- var $btn = $('<a class="quick-visit-button"></a>')
- .text(minder.getLang('ui.quickvisit.' + name))
- .attr('title', minder.getLang('ui.quickvisit.' + name))
- .addClass(name);
- if (dockRight) rightDocks.push($btn);
- else $btn.appendTo('#panel');
- return $btn;
- }
- var $new = btn('new'),
- $save = btn('save'),
- $share = btn('share');
- var ret = {
- $new: $new,
- $save: $save,
- $share: $share
- };
- minder.on('uiready', function quickVisit() {
- while (rightDocks.length) $('#panel #search').after(rightDocks.shift());
- function quickNew() {
- var $doc = minder.getUI('doc');
- if (!$doc.checkSaved()) return;
- $doc.load({
- content: {
- template: 'default',
- version: KityMinder.version,
- data: {
- text: minder.getLang('maintopic')
- }
- },
- saved: true
- });
- }
- function quickSave() {
- minder.getUI('menu/save/netdisk').quickSave();
- }
- function quickShare() {
- var $menu = minder.getUI('menu/menu');
- $menu.$tabs.select(3);
- $menu.show();
- }
- $new.click(quickNew);
- $save.click(quickSave);
- $share.click(quickShare);
- minder.addShortcut('ctrl+alt+n', quickNew);
- minder.addShortcut('ctrl+s', quickSave);
- minder.addShortcut('ctrl+alt+s', quickShare);
- minder.addShortcut('ctrl+shift+s', function() {
- var $menu = minder.getUI('menu/menu');
- $menu.$tabs.select(2);
- $menu.show();
- });
- ret.ready = true;
- ret.quickNew = quickNew;
- ret.quickSave = quickSave;
- ret.quickShare = quickShare;
- });
- ret.add = btn;
- return ret;
- });
- /**
- * @fileOverview
- *
- * 快速反馈按钮
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('topbar/feedback', function(minder) {
- var $quickvisit = minder.getUI('topbar/quickvisit');
- var $feedback = $quickvisit.add('feedback', 'right');
- function quickFeedback() {
- var $menu = minder.getUI('menu/menu');
- $menu.$tabs.select(5);
- $menu.show();
- }
- $feedback.click(quickFeedback);
- minder.addShortcut('f1', quickFeedback);
- return $feedback;
- });
- /**
- * @fileOverview
- *
- * 搜索节点功能
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('topbar/search', function(minder) {
- var $search = $('<div id="search"><input type="search" /></div>').appendTo('#panel');
- var $input = $search.find('input');
- minder.addShortcut('ctrl+f', function() {
- $input[0].focus();
- $input[0].select();
- });
- $input.on('keydown', function(e) {
- if (e.keyCode == 13) {
- doSearch($input.val());
- }
- if (e.keyCode == 27) {
- $input[0].blur();
- }
- });
- var nodeSequence;
- minder.on('contentchange', makeNodeSequence);
- function makeNodeSequence() {
- nodeSequence = [];
- minder.getRoot().traverse(function(node) {
- nodeSequence.push(node);
- });
- }
- function doSearch(keyword) {
- if (!/\S/.exec(keyword)) {
- $input[0].focus();
- $input[0].select();
- return;
- }
- keyword = keyword.toLowerCase();
- var newSearch = doSearch.lastKeyword != keyword;
- doSearch.lastKeyword = keyword;
- var startIndex = newSearch ? 0 : doSearch.lastIndex + 1 || 0;
- var endIndex = startIndex + nodeSequence.length - 1;
- for (var i = startIndex; i <= endIndex; i++) {
- var node = nodeSequence[i % nodeSequence.length];
- var text = node.getText().toLowerCase();
- if (text.indexOf(keyword) != -1) {
- setSearchResult(node);
- doSearch.lastIndex = i;
- break;
- }
- var note = node.getData('note');
- if (note && note.indexOf(keyword) != -1) {
- setSearchResult(node, keyword);
- doSearch.lastIndex = i;
- break;
- }
- }
- function setSearchResult(node, previewKeyword) {
- var $notepreview = minder.getUI('ribbon/idea/notepreview');
- if ($notepreview) {
- $notepreview.hide();
- }
- minder.execCommand('camera', node, 50);
- setTimeout(function() {
- minder.select(node, true);
- if (!node.isExpanded()) minder.execCommand('expand', true);
- if (previewKeyword) {
- if ($notepreview) {
- $notepreview.preview(node, previewKeyword);
- }
- }
- }, 60);
- }
- }
- return $search;
- });
- /**
- * @fileOverview
- *
- * 显示并更新脑图文件的标题
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- KityMinder.registerUI('topbar/title', function(minder) {
- var $title = $('<h1>').appendTo('#panel');
- var $doc = minder.getUI('doc');
- var finder = minder.getUI('widget/netdiskfinder');
- var notice = minder.getUI('widget/notice');
- var renameEnabled = false;
- var renameMode = false;
- $doc.on('docchange', update);
- $title.on('click', rename);
- function rename() {
- if (!renameEnabled || renameMode) return;
- var doc = $doc.current();
- var $input = $('<input>').width($title.find('.title-content').width());
- var oldFilename = doc.title;
- var oldPath = doc.path;
- $input.val(oldFilename);
- setTimeout(function() {
- $input[0].select();
- });
- $title.addClass('rename-mode');
- $title.empty();
- $title.append($input);
- renameMode = true;
- $input.on('keydown', function(e) {
- if (e.keyCode == 13) confirm();
- else if (e.keyCode == 27) {
- cancel();
- e.stopPropagation();
- }
- }).on('blur', cancel);
- function exit() {
- setTimeout(function() {
- renameMode = false;
- });
- }
- function cancel() {
- update();
- exit();
- }
- function confirm() {
- var newFilename = $input.val();
- var oldFilenameInfo = fio.file.anlysisPath(oldFilename);
- var newFilenameInfo = fio.file.anlysisPath(newFilename);
- if (!newFilenameInfo.name.length) return cancel();
- newFilename = newFilenameInfo.name + oldFilenameInfo.extension;
- var newPath = fio.file.anlysisPath(oldPath).parentPath + newFilename;
- if (newPath == oldPath) return cancel();
- $title.addClass('loading');
- fio.file.move({
- path: oldPath,
- newPath: newPath
- }).then(function() {
- doc.path = newPath;
- doc.title = newFilename;
- finder.fire('mv', oldPath, newPath);
- notice.info(minder.getLang('ui.rename_success', newFilename));
- })['catch'](function(e) {
- notice.error('err_rename', e);
- }).then(function() {
- $title.removeClass('loading');
- update();
- exit();
- });
- }
- }
- function enableRename(enabled) {
- renameEnabled = enabled;
- if (enabled) $title.addClass('rename-enabled');
- else $title.removeClass('rename-enabled');
- }
- function update() {
- var doc = $doc.current();
- function setTitle(title) {
- if (setTitle.lastValue == title) return;
- title = title || minder.getLang('ui.untitleddoc');
- $title.empty().append($('<span class="title-content"></span>').text(title));
- document.title = title ? title + ' - 众核脑图' : '众核脑图';
- setTitle.lastValue = title;
- }
- if (doc.saved) {
- setTitle(doc.title);
- } else {
- setTitle('* ' + doc.title);
- }
- enableRename(doc.source == 'netdisk' && doc.saved);
- }
- update();
- return {
- $title: $title,
- getTitle: function() {
- return $doc.current().title;
- }
- };
- });
- /**
- * @fileOverview
- *
- * 节点笔记支持
- *
- * @author: techird
- * @copyright: Baidu FEX, 2014
- */
- /* global marked: true */
- KityMinder.registerUI('ribbon/idea/notepreview', function(minder) {
- var axss = minder.getUI('axss');
- marked.setOptions({
- gfm: true,
- breaks: true
- });
- var $previewer = $('<div id="note-previewer"></div>').appendTo('#content-wrapper');
- var visible = false;
- var selectedNode = null;
- var previewTimer;
- minder.on('shownoterequest', function(e) {
- previewTimer = setTimeout(function() {
- preview(e.node);
- }, 300);
- });
- minder.on('hidenoterequest', function() {
- clearTimeout(previewTimer);
- });
- var previewLive = false;
- $('#kityminder').on('mousedown mousewheel DOMMouseScroll', function() {
- if (!previewLive) return;
- $previewer.fadeOut();
- previewLive = false;
- });
- $previewer.hide();
- function preview(node, keyword) {
- var icon = node.getRenderer('NoteIconRenderer').getRenderShape();
- var b = icon.getRenderBox('screen');
- var note = node.getData('note');
- $previewer[0].scrollTop = 0;
- var html = marked(note);
- if (keyword) {
- html = html.replace(new RegExp('(' + keyword + ')', 'ig'), '<span class="highlight">$1</span>');
- }
- $previewer.html(axss(html));
- var cw = $('#content-wrapper').width();
- var ch = $('#content-wrapper').height();
- var pw = $previewer.outerWidth();
- var ph = $previewer.outerHeight();
- var x = b.cx - pw / 2;
- var y = b.bottom + 10;
- if (x < 0) x = 10;
- if (x + pw > cw) x = cw - pw - 10;
- if (y + ph > ch) y = b.top - ph - 10;
- $previewer.css({
- left: Math.round(x),
- top: Math.round(y)
- });
- $previewer.show();
- var view = $previewer[0].querySelector('.highlight');
- if (view) {
- view.scrollIntoView();
- }
- previewLive = true;
- }
- $previewer.delegate('a', 'click', function(e) {
- var $a = $(e.target).closest('a');
- var href = $a.prop('href');
- if (window.confirm(minder.getLang('ui.redirect', href))) {
- window.open(href, '_blank');
- }
- e.preventDefault();
- });
- return {
- preview: preview,
- hide: function() {
- $previewer.hide();
- }
- };
- });
- })(window)
- //# sourceMappingURL=kityminder.share.js.map
|