tiny_mce_prototype_src.js 421 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755
  1. (function(win) {
  2. var whiteSpaceRe = /^\s*|\s*$/g,
  3. undefined, isRegExpBroken = 'B'.replace(/A(.)|B/, '$1') === '$1';
  4. var tinymce = {
  5. majorVersion : '3',
  6. minorVersion : '4.7',
  7. releaseDate : '2011-11-03',
  8. _init : function() {
  9. var t = this, d = document, na = navigator, ua = na.userAgent, i, nl, n, base, p, v;
  10. t.isOpera = win.opera && opera.buildNumber;
  11. t.isWebKit = /WebKit/.test(ua);
  12. t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName);
  13. t.isIE6 = t.isIE && /MSIE [56]/.test(ua);
  14. t.isIE7 = t.isIE && /MSIE [7]/.test(ua);
  15. t.isIE8 = t.isIE && /MSIE [8]/.test(ua);
  16. t.isIE9 = t.isIE && /MSIE [9]/.test(ua);
  17. t.isGecko = !t.isWebKit && /Gecko/.test(ua);
  18. t.isMac = ua.indexOf('Mac') != -1;
  19. t.isAir = /adobeair/i.test(ua);
  20. t.isIDevice = /(iPad|iPhone)/.test(ua);
  21. t.isIOS5 = t.isIDevice && ua.match(/AppleWebKit\/(\d*)/)[1]>=534;
  22. // TinyMCE .NET webcontrol might be setting the values for TinyMCE
  23. if (win.tinyMCEPreInit) {
  24. t.suffix = tinyMCEPreInit.suffix;
  25. t.baseURL = tinyMCEPreInit.base;
  26. t.query = tinyMCEPreInit.query;
  27. return;
  28. }
  29. // Get suffix and base
  30. t.suffix = '';
  31. // If base element found, add that infront of baseURL
  32. nl = d.getElementsByTagName('base');
  33. for (i=0; i<nl.length; i++) {
  34. if (v = nl[i].href) {
  35. // Host only value like http://site.com or http://site.com:8008
  36. if (/^https?:\/\/[^\/]+$/.test(v))
  37. v += '/';
  38. base = v ? v.match(/.*\//)[0] : ''; // Get only directory
  39. }
  40. }
  41. function getBase(n) {
  42. if (n.src && /tiny_mce(|_gzip|_jquery|_prototype|_full)(_dev|_src)?.js/.test(n.src)) {
  43. if (/_(src|dev)\.js/g.test(n.src))
  44. t.suffix = '_src';
  45. if ((p = n.src.indexOf('?')) != -1)
  46. t.query = n.src.substring(p + 1);
  47. t.baseURL = n.src.substring(0, n.src.lastIndexOf('/'));
  48. // If path to script is relative and a base href was found add that one infront
  49. // the src property will always be an absolute one on non IE browsers and IE 8
  50. // so this logic will basically only be executed on older IE versions
  51. if (base && t.baseURL.indexOf('://') == -1 && t.baseURL.indexOf('/') !== 0)
  52. t.baseURL = base + t.baseURL;
  53. return t.baseURL;
  54. }
  55. return null;
  56. };
  57. // Check document
  58. nl = d.getElementsByTagName('script');
  59. for (i=0; i<nl.length; i++) {
  60. if (getBase(nl[i]))
  61. return;
  62. }
  63. // Check head
  64. n = d.getElementsByTagName('head')[0];
  65. if (n) {
  66. nl = n.getElementsByTagName('script');
  67. for (i=0; i<nl.length; i++) {
  68. if (getBase(nl[i]))
  69. return;
  70. }
  71. }
  72. return;
  73. },
  74. is : function(o, t) {
  75. if (!t)
  76. return o !== undefined;
  77. if (t == 'array' && (o.hasOwnProperty && o instanceof Array))
  78. return true;
  79. return typeof(o) == t;
  80. },
  81. makeMap : function(items, delim, map) {
  82. var i;
  83. items = items || [];
  84. delim = delim || ',';
  85. if (typeof(items) == "string")
  86. items = items.split(delim);
  87. map = map || {};
  88. i = items.length;
  89. while (i--)
  90. map[items[i]] = {};
  91. return map;
  92. },
  93. each : function(o, cb, s) {
  94. var n, l;
  95. if (!o)
  96. return 0;
  97. s = s || o;
  98. if (o.length !== undefined) {
  99. // Indexed arrays, needed for Safari
  100. for (n=0, l = o.length; n < l; n++) {
  101. if (cb.call(s, o[n], n, o) === false)
  102. return 0;
  103. }
  104. } else {
  105. // Hashtables
  106. for (n in o) {
  107. if (o.hasOwnProperty(n)) {
  108. if (cb.call(s, o[n], n, o) === false)
  109. return 0;
  110. }
  111. }
  112. }
  113. return 1;
  114. },
  115. map : function(a, f) {
  116. var o = [];
  117. tinymce.each(a, function(v) {
  118. o.push(f(v));
  119. });
  120. return o;
  121. },
  122. grep : function(a, f) {
  123. var o = [];
  124. tinymce.each(a, function(v) {
  125. if (!f || f(v))
  126. o.push(v);
  127. });
  128. return o;
  129. },
  130. inArray : function(a, v) {
  131. var i, l;
  132. if (a) {
  133. for (i = 0, l = a.length; i < l; i++) {
  134. if (a[i] === v)
  135. return i;
  136. }
  137. }
  138. return -1;
  139. },
  140. extend : function(o, e) {
  141. var i, l, a = arguments;
  142. for (i = 1, l = a.length; i < l; i++) {
  143. e = a[i];
  144. tinymce.each(e, function(v, n) {
  145. if (v !== undefined)
  146. o[n] = v;
  147. });
  148. }
  149. return o;
  150. },
  151. trim : function(s) {
  152. return (s ? '' + s : '').replace(whiteSpaceRe, '');
  153. },
  154. create : function(s, p, root) {
  155. var t = this, sp, ns, cn, scn, c, de = 0;
  156. // Parse : <prefix> <class>:<super class>
  157. s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s);
  158. cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name
  159. // Create namespace for new class
  160. ns = t.createNS(s[3].replace(/\.\w+$/, ''), root);
  161. // Class already exists
  162. if (ns[cn])
  163. return;
  164. // Make pure static class
  165. if (s[2] == 'static') {
  166. ns[cn] = p;
  167. if (this.onCreate)
  168. this.onCreate(s[2], s[3], ns[cn]);
  169. return;
  170. }
  171. // Create default constructor
  172. if (!p[cn]) {
  173. p[cn] = function() {};
  174. de = 1;
  175. }
  176. // Add constructor and methods
  177. ns[cn] = p[cn];
  178. t.extend(ns[cn].prototype, p);
  179. // Extend
  180. if (s[5]) {
  181. sp = t.resolve(s[5]).prototype;
  182. scn = s[5].match(/\.(\w+)$/i)[1]; // Class name
  183. // Extend constructor
  184. c = ns[cn];
  185. if (de) {
  186. // Add passthrough constructor
  187. ns[cn] = function() {
  188. return sp[scn].apply(this, arguments);
  189. };
  190. } else {
  191. // Add inherit constructor
  192. ns[cn] = function() {
  193. this.parent = sp[scn];
  194. return c.apply(this, arguments);
  195. };
  196. }
  197. ns[cn].prototype[cn] = ns[cn];
  198. // Add super methods
  199. t.each(sp, function(f, n) {
  200. ns[cn].prototype[n] = sp[n];
  201. });
  202. // Add overridden methods
  203. t.each(p, function(f, n) {
  204. // Extend methods if needed
  205. if (sp[n]) {
  206. ns[cn].prototype[n] = function() {
  207. this.parent = sp[n];
  208. return f.apply(this, arguments);
  209. };
  210. } else {
  211. if (n != cn)
  212. ns[cn].prototype[n] = f;
  213. }
  214. });
  215. }
  216. // Add static methods
  217. t.each(p['static'], function(f, n) {
  218. ns[cn][n] = f;
  219. });
  220. if (this.onCreate)
  221. this.onCreate(s[2], s[3], ns[cn].prototype);
  222. },
  223. walk : function(o, f, n, s) {
  224. s = s || this;
  225. if (o) {
  226. if (n)
  227. o = o[n];
  228. tinymce.each(o, function(o, i) {
  229. if (f.call(s, o, i, n) === false)
  230. return false;
  231. tinymce.walk(o, f, n, s);
  232. });
  233. }
  234. },
  235. createNS : function(n, o) {
  236. var i, v;
  237. o = o || win;
  238. n = n.split('.');
  239. for (i=0; i<n.length; i++) {
  240. v = n[i];
  241. if (!o[v])
  242. o[v] = {};
  243. o = o[v];
  244. }
  245. return o;
  246. },
  247. resolve : function(n, o) {
  248. var i, l;
  249. o = o || win;
  250. n = n.split('.');
  251. for (i = 0, l = n.length; i < l; i++) {
  252. o = o[n[i]];
  253. if (!o)
  254. break;
  255. }
  256. return o;
  257. },
  258. addUnload : function(f, s) {
  259. var t = this;
  260. f = {func : f, scope : s || this};
  261. if (!t.unloads) {
  262. function unload() {
  263. var li = t.unloads, o, n;
  264. if (li) {
  265. // Call unload handlers
  266. for (n in li) {
  267. o = li[n];
  268. if (o && o.func)
  269. o.func.call(o.scope, 1); // Send in one arg to distinct unload and user destroy
  270. }
  271. // Detach unload function
  272. if (win.detachEvent) {
  273. win.detachEvent('onbeforeunload', fakeUnload);
  274. win.detachEvent('onunload', unload);
  275. } else if (win.removeEventListener)
  276. win.removeEventListener('unload', unload, false);
  277. // Destroy references
  278. t.unloads = o = li = w = unload = 0;
  279. // Run garbarge collector on IE
  280. if (win.CollectGarbage)
  281. CollectGarbage();
  282. }
  283. };
  284. function fakeUnload() {
  285. var d = document;
  286. // Is there things still loading, then do some magic
  287. if (d.readyState == 'interactive') {
  288. function stop() {
  289. // Prevent memory leak
  290. d.detachEvent('onstop', stop);
  291. // Call unload handler
  292. if (unload)
  293. unload();
  294. d = 0;
  295. };
  296. // Fire unload when the currently loading page is stopped
  297. if (d)
  298. d.attachEvent('onstop', stop);
  299. // Remove onstop listener after a while to prevent the unload function
  300. // to execute if the user presses cancel in an onbeforeunload
  301. // confirm dialog and then presses the browser stop button
  302. win.setTimeout(function() {
  303. if (d)
  304. d.detachEvent('onstop', stop);
  305. }, 0);
  306. }
  307. };
  308. // Attach unload handler
  309. if (win.attachEvent) {
  310. win.attachEvent('onunload', unload);
  311. win.attachEvent('onbeforeunload', fakeUnload);
  312. } else if (win.addEventListener)
  313. win.addEventListener('unload', unload, false);
  314. // Setup initial unload handler array
  315. t.unloads = [f];
  316. } else
  317. t.unloads.push(f);
  318. return f;
  319. },
  320. removeUnload : function(f) {
  321. var u = this.unloads, r = null;
  322. tinymce.each(u, function(o, i) {
  323. if (o && o.func == f) {
  324. u.splice(i, 1);
  325. r = f;
  326. return false;
  327. }
  328. });
  329. return r;
  330. },
  331. explode : function(s, d) {
  332. return s ? tinymce.map(s.split(d || ','), tinymce.trim) : s;
  333. },
  334. _addVer : function(u) {
  335. var v;
  336. if (!this.query)
  337. return u;
  338. v = (u.indexOf('?') == -1 ? '?' : '&') + this.query;
  339. if (u.indexOf('#') == -1)
  340. return u + v;
  341. return u.replace('#', v + '#');
  342. },
  343. // Fix function for IE 9 where regexps isn't working correctly
  344. // Todo: remove me once MS fixes the bug
  345. _replace : function(find, replace, str) {
  346. // On IE9 we have to fake $x replacement
  347. if (isRegExpBroken) {
  348. return str.replace(find, function() {
  349. var val = replace, args = arguments, i;
  350. for (i = 0; i < args.length - 2; i++) {
  351. if (args[i] === undefined) {
  352. val = val.replace(new RegExp('\\$' + i, 'g'), '');
  353. } else {
  354. val = val.replace(new RegExp('\\$' + i, 'g'), args[i]);
  355. }
  356. }
  357. return val;
  358. });
  359. }
  360. return str.replace(find, replace);
  361. }
  362. };
  363. // Initialize the API
  364. tinymce._init();
  365. // Expose tinymce namespace to the global namespace (window)
  366. win.tinymce = win.tinyMCE = tinymce;
  367. // Describe the different namespaces
  368. })(window);
  369. (function() {
  370. if (!window.Prototype)
  371. return alert("Load prototype first!");
  372. // Patch in core NS functions
  373. tinymce.extend(tinymce, {
  374. trim : function(s) {return s ? s.strip() : '';},
  375. inArray : function(a, v) {return a && a.indexOf ? a.indexOf(v) : -1;}
  376. });
  377. // Patch in functions in various clases
  378. // Add a "#ifndefjquery" statement around each core API function you add below
  379. var patches = {
  380. 'tinymce.util.JSON' : {
  381. /*serialize : function(o) {
  382. return o.toJSON();
  383. }*/
  384. },
  385. };
  386. // Patch functions after a class is created
  387. tinymce.onCreate = function(ty, c, p) {
  388. tinymce.extend(p, patches[c]);
  389. };
  390. })();
  391. tinymce.create('tinymce.util.Dispatcher', {
  392. scope : null,
  393. listeners : null,
  394. Dispatcher : function(s) {
  395. this.scope = s || this;
  396. this.listeners = [];
  397. },
  398. add : function(cb, s) {
  399. this.listeners.push({cb : cb, scope : s || this.scope});
  400. return cb;
  401. },
  402. addToTop : function(cb, s) {
  403. this.listeners.unshift({cb : cb, scope : s || this.scope});
  404. return cb;
  405. },
  406. remove : function(cb) {
  407. var l = this.listeners, o = null;
  408. tinymce.each(l, function(c, i) {
  409. if (cb == c.cb) {
  410. o = cb;
  411. l.splice(i, 1);
  412. return false;
  413. }
  414. });
  415. return o;
  416. },
  417. dispatch : function() {
  418. var s, a = arguments, i, li = this.listeners, c;
  419. // Needs to be a real loop since the listener count might change while looping
  420. // And this is also more efficient
  421. for (i = 0; i<li.length; i++) {
  422. c = li[i];
  423. s = c.cb.apply(c.scope, a);
  424. if (s === false)
  425. break;
  426. }
  427. return s;
  428. }
  429. });
  430. (function() {
  431. var each = tinymce.each;
  432. tinymce.create('tinymce.util.URI', {
  433. URI : function(u, s) {
  434. var t = this, o, a, b, base_url;
  435. // Trim whitespace
  436. u = tinymce.trim(u);
  437. // Default settings
  438. s = t.settings = s || {};
  439. // Strange app protocol that isn't http/https or local anchor
  440. // For example: mailto,skype,tel etc.
  441. if (/^([\w\-]+):([^\/]{2})/i.test(u) || /^\s*#/.test(u)) {
  442. t.source = u;
  443. return;
  444. }
  445. // Absolute path with no host, fake host and protocol
  446. if (u.indexOf('/') === 0 && u.indexOf('//') !== 0)
  447. u = (s.base_uri ? s.base_uri.protocol || 'http' : 'http') + '://mce_host' + u;
  448. // Relative path http:// or protocol relative //path
  449. if (!/^[\w-]*:?\/\//.test(u)) {
  450. base_url = s.base_uri ? s.base_uri.path : new tinymce.util.URI(location.href).directory;
  451. u = ((s.base_uri && s.base_uri.protocol) || 'http') + '://mce_host' + t.toAbsPath(base_url, u);
  452. }
  453. // Parse URL (Credits goes to Steave, http://blog.stevenlevithan.com/archives/parseuri)
  454. u = u.replace(/@@/g, '(mce_at)'); // Zope 3 workaround, they use @@something
  455. u = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(u);
  456. each(["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], function(v, i) {
  457. var s = u[i];
  458. // Zope 3 workaround, they use @@something
  459. if (s)
  460. s = s.replace(/\(mce_at\)/g, '@@');
  461. t[v] = s;
  462. });
  463. if (b = s.base_uri) {
  464. if (!t.protocol)
  465. t.protocol = b.protocol;
  466. if (!t.userInfo)
  467. t.userInfo = b.userInfo;
  468. if (!t.port && t.host == 'mce_host')
  469. t.port = b.port;
  470. if (!t.host || t.host == 'mce_host')
  471. t.host = b.host;
  472. t.source = '';
  473. }
  474. //t.path = t.path || '/';
  475. },
  476. setPath : function(p) {
  477. var t = this;
  478. p = /^(.*?)\/?(\w+)?$/.exec(p);
  479. // Update path parts
  480. t.path = p[0];
  481. t.directory = p[1];
  482. t.file = p[2];
  483. // Rebuild source
  484. t.source = '';
  485. t.getURI();
  486. },
  487. toRelative : function(u) {
  488. var t = this, o;
  489. if (u === "./")
  490. return u;
  491. u = new tinymce.util.URI(u, {base_uri : t});
  492. // Not on same domain/port or protocol
  493. if ((u.host != 'mce_host' && t.host != u.host && u.host) || t.port != u.port || t.protocol != u.protocol)
  494. return u.getURI();
  495. o = t.toRelPath(t.path, u.path);
  496. // Add query
  497. if (u.query)
  498. o += '?' + u.query;
  499. // Add anchor
  500. if (u.anchor)
  501. o += '#' + u.anchor;
  502. return o;
  503. },
  504. toAbsolute : function(u, nh) {
  505. var u = new tinymce.util.URI(u, {base_uri : this});
  506. return u.getURI(this.host == u.host && this.protocol == u.protocol ? nh : 0);
  507. },
  508. toRelPath : function(base, path) {
  509. var items, bp = 0, out = '', i, l;
  510. // Split the paths
  511. base = base.substring(0, base.lastIndexOf('/'));
  512. base = base.split('/');
  513. items = path.split('/');
  514. if (base.length >= items.length) {
  515. for (i = 0, l = base.length; i < l; i++) {
  516. if (i >= items.length || base[i] != items[i]) {
  517. bp = i + 1;
  518. break;
  519. }
  520. }
  521. }
  522. if (base.length < items.length) {
  523. for (i = 0, l = items.length; i < l; i++) {
  524. if (i >= base.length || base[i] != items[i]) {
  525. bp = i + 1;
  526. break;
  527. }
  528. }
  529. }
  530. if (bp == 1)
  531. return path;
  532. for (i = 0, l = base.length - (bp - 1); i < l; i++)
  533. out += "../";
  534. for (i = bp - 1, l = items.length; i < l; i++) {
  535. if (i != bp - 1)
  536. out += "/" + items[i];
  537. else
  538. out += items[i];
  539. }
  540. return out;
  541. },
  542. toAbsPath : function(base, path) {
  543. var i, nb = 0, o = [], tr, outPath;
  544. // Split paths
  545. tr = /\/$/.test(path) ? '/' : '';
  546. base = base.split('/');
  547. path = path.split('/');
  548. // Remove empty chunks
  549. each(base, function(k) {
  550. if (k)
  551. o.push(k);
  552. });
  553. base = o;
  554. // Merge relURLParts chunks
  555. for (i = path.length - 1, o = []; i >= 0; i--) {
  556. // Ignore empty or .
  557. if (path[i].length == 0 || path[i] == ".")
  558. continue;
  559. // Is parent
  560. if (path[i] == '..') {
  561. nb++;
  562. continue;
  563. }
  564. // Move up
  565. if (nb > 0) {
  566. nb--;
  567. continue;
  568. }
  569. o.push(path[i]);
  570. }
  571. i = base.length - nb;
  572. // If /a/b/c or /
  573. if (i <= 0)
  574. outPath = o.reverse().join('/');
  575. else
  576. outPath = base.slice(0, i).join('/') + '/' + o.reverse().join('/');
  577. // Add front / if it's needed
  578. if (outPath.indexOf('/') !== 0)
  579. outPath = '/' + outPath;
  580. // Add traling / if it's needed
  581. if (tr && outPath.lastIndexOf('/') !== outPath.length - 1)
  582. outPath += tr;
  583. return outPath;
  584. },
  585. getURI : function(nh) {
  586. var s, t = this;
  587. // Rebuild source
  588. if (!t.source || nh) {
  589. s = '';
  590. if (!nh) {
  591. if (t.protocol)
  592. s += t.protocol + '://';
  593. if (t.userInfo)
  594. s += t.userInfo + '@';
  595. if (t.host)
  596. s += t.host;
  597. if (t.port)
  598. s += ':' + t.port;
  599. }
  600. if (t.path)
  601. s += t.path;
  602. if (t.query)
  603. s += '?' + t.query;
  604. if (t.anchor)
  605. s += '#' + t.anchor;
  606. t.source = s;
  607. }
  608. return t.source;
  609. }
  610. });
  611. })();
  612. (function() {
  613. var each = tinymce.each;
  614. tinymce.create('static tinymce.util.Cookie', {
  615. getHash : function(n) {
  616. var v = this.get(n), h;
  617. if (v) {
  618. each(v.split('&'), function(v) {
  619. v = v.split('=');
  620. h = h || {};
  621. h[unescape(v[0])] = unescape(v[1]);
  622. });
  623. }
  624. return h;
  625. },
  626. setHash : function(n, v, e, p, d, s) {
  627. var o = '';
  628. each(v, function(v, k) {
  629. o += (!o ? '' : '&') + escape(k) + '=' + escape(v);
  630. });
  631. this.set(n, o, e, p, d, s);
  632. },
  633. get : function(n) {
  634. var c = document.cookie, e, p = n + "=", b;
  635. // Strict mode
  636. if (!c)
  637. return;
  638. b = c.indexOf("; " + p);
  639. if (b == -1) {
  640. b = c.indexOf(p);
  641. if (b != 0)
  642. return null;
  643. } else
  644. b += 2;
  645. e = c.indexOf(";", b);
  646. if (e == -1)
  647. e = c.length;
  648. return unescape(c.substring(b + p.length, e));
  649. },
  650. set : function(n, v, e, p, d, s) {
  651. document.cookie = n + "=" + escape(v) +
  652. ((e) ? "; expires=" + e.toGMTString() : "") +
  653. ((p) ? "; path=" + escape(p) : "") +
  654. ((d) ? "; domain=" + d : "") +
  655. ((s) ? "; secure" : "");
  656. },
  657. remove : function(n, p) {
  658. var d = new Date();
  659. d.setTime(d.getTime() - 1000);
  660. this.set(n, '', d, p, d);
  661. }
  662. });
  663. })();
  664. (function() {
  665. function serialize(o, quote) {
  666. var i, v, t;
  667. quote = quote || '"';
  668. if (o == null)
  669. return 'null';
  670. t = typeof o;
  671. if (t == 'string') {
  672. v = '\bb\tt\nn\ff\rr\""\'\'\\\\';
  673. return quote + o.replace(/([\u0080-\uFFFF\x00-\x1f\"\'\\])/g, function(a, b) {
  674. // Make sure single quotes never get encoded inside double quotes for JSON compatibility
  675. if (quote === '"' && a === "'")
  676. return a;
  677. i = v.indexOf(b);
  678. if (i + 1)
  679. return '\\' + v.charAt(i + 1);
  680. a = b.charCodeAt().toString(16);
  681. return '\\u' + '0000'.substring(a.length) + a;
  682. }) + quote;
  683. }
  684. if (t == 'object') {
  685. if (o.hasOwnProperty && o instanceof Array) {
  686. for (i=0, v = '['; i<o.length; i++)
  687. v += (i > 0 ? ',' : '') + serialize(o[i], quote);
  688. return v + ']';
  689. }
  690. v = '{';
  691. for (i in o) {
  692. if (o.hasOwnProperty(i)) {
  693. v += typeof o[i] != 'function' ? (v.length > 1 ? ',' + quote : quote) + i + quote +':' + serialize(o[i], quote) : '';
  694. }
  695. }
  696. return v + '}';
  697. }
  698. return '' + o;
  699. };
  700. tinymce.util.JSON = {
  701. serialize: serialize,
  702. parse: function(s) {
  703. try {
  704. return eval('(' + s + ')');
  705. } catch (ex) {
  706. // Ignore
  707. }
  708. }
  709. };
  710. })();
  711. tinymce.create('static tinymce.util.XHR', {
  712. send : function(o) {
  713. var x, t, w = window, c = 0;
  714. // Default settings
  715. o.scope = o.scope || this;
  716. o.success_scope = o.success_scope || o.scope;
  717. o.error_scope = o.error_scope || o.scope;
  718. o.async = o.async === false ? false : true;
  719. o.data = o.data || '';
  720. function get(s) {
  721. x = 0;
  722. try {
  723. x = new ActiveXObject(s);
  724. } catch (ex) {
  725. }
  726. return x;
  727. };
  728. x = w.XMLHttpRequest ? new XMLHttpRequest() : get('Microsoft.XMLHTTP') || get('Msxml2.XMLHTTP');
  729. if (x) {
  730. if (x.overrideMimeType)
  731. x.overrideMimeType(o.content_type);
  732. x.open(o.type || (o.data ? 'POST' : 'GET'), o.url, o.async);
  733. if (o.content_type)
  734. x.setRequestHeader('Content-Type', o.content_type);
  735. x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  736. x.send(o.data);
  737. function ready() {
  738. if (!o.async || x.readyState == 4 || c++ > 10000) {
  739. if (o.success && c < 10000 && x.status == 200)
  740. o.success.call(o.success_scope, '' + x.responseText, x, o);
  741. else if (o.error)
  742. o.error.call(o.error_scope, c > 10000 ? 'TIMED_OUT' : 'GENERAL', x, o);
  743. x = null;
  744. } else
  745. w.setTimeout(ready, 10);
  746. };
  747. // Syncronous request
  748. if (!o.async)
  749. return ready();
  750. // Wait for response, onReadyStateChange can not be used since it leaks memory in IE
  751. t = w.setTimeout(ready, 10);
  752. }
  753. }
  754. });
  755. (function() {
  756. var extend = tinymce.extend, JSON = tinymce.util.JSON, XHR = tinymce.util.XHR;
  757. tinymce.create('tinymce.util.JSONRequest', {
  758. JSONRequest : function(s) {
  759. this.settings = extend({
  760. }, s);
  761. this.count = 0;
  762. },
  763. send : function(o) {
  764. var ecb = o.error, scb = o.success;
  765. o = extend(this.settings, o);
  766. o.success = function(c, x) {
  767. c = JSON.parse(c);
  768. if (typeof(c) == 'undefined') {
  769. c = {
  770. error : 'JSON Parse error.'
  771. };
  772. }
  773. if (c.error)
  774. ecb.call(o.error_scope || o.scope, c.error, x);
  775. else
  776. scb.call(o.success_scope || o.scope, c.result);
  777. };
  778. o.error = function(ty, x) {
  779. if (ecb)
  780. ecb.call(o.error_scope || o.scope, ty, x);
  781. };
  782. o.data = JSON.serialize({
  783. id : o.id || 'c' + (this.count++),
  784. method : o.method,
  785. params : o.params
  786. });
  787. // JSON content type for Ruby on rails. Bug: #1883287
  788. o.content_type = 'application/json';
  789. XHR.send(o);
  790. },
  791. 'static' : {
  792. sendRPC : function(o) {
  793. return new tinymce.util.JSONRequest().send(o);
  794. }
  795. }
  796. });
  797. }());
  798. (function(tinymce){
  799. tinymce.VK = {
  800. DELETE: 46,
  801. BACKSPACE: 8,
  802. ENTER: 13,
  803. TAB: 9,
  804. SPACEBAR: 32,
  805. UP: 38,
  806. DOWN: 40
  807. }
  808. })(tinymce);
  809. (function(tinymce) {
  810. var VK = tinymce.VK, BACKSPACE = VK.BACKSPACE, DELETE = VK.DELETE;
  811. function cleanupStylesWhenDeleting(ed) {
  812. var dom = ed.dom, selection = ed.selection;
  813. ed.onKeyDown.add(function(ed, e) {
  814. var rng, blockElm, node, clonedSpan, isDelete;
  815. isDelete = e.keyCode == DELETE;
  816. if (isDelete || e.keyCode == BACKSPACE) {
  817. e.preventDefault();
  818. rng = selection.getRng();
  819. // Find root block
  820. blockElm = dom.getParent(rng.startContainer, dom.isBlock);
  821. // On delete clone the root span of the next block element
  822. if (isDelete)
  823. blockElm = dom.getNext(blockElm, dom.isBlock);
  824. // Locate root span element and clone it since it would otherwise get merged by the "apple-style-span" on delete/backspace
  825. if (blockElm) {
  826. node = blockElm.firstChild;
  827. // Ignore empty text nodes
  828. while (node && node.nodeType == 3 && node.nodeValue.length == 0)
  829. node = node.nextSibling;
  830. if (node && node.nodeName === 'SPAN') {
  831. clonedSpan = node.cloneNode(false);
  832. }
  833. }
  834. // Do the backspace/delete actiopn
  835. ed.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null);
  836. // Find all odd apple-style-spans
  837. blockElm = dom.getParent(rng.startContainer, dom.isBlock);
  838. tinymce.each(dom.select('span.Apple-style-span,font.Apple-style-span', blockElm), function(span) {
  839. var bm = selection.getBookmark();
  840. if (clonedSpan) {
  841. dom.replace(clonedSpan.cloneNode(false), span, true);
  842. } else {
  843. dom.remove(span, true);
  844. }
  845. // Restore the selection
  846. selection.moveToBookmark(bm);
  847. });
  848. }
  849. });
  850. };
  851. function emptyEditorWhenDeleting(ed) {
  852. ed.onKeyUp.add(function(ed, e) {
  853. var keyCode = e.keyCode;
  854. if (keyCode == DELETE || keyCode == BACKSPACE) {
  855. if (ed.dom.isEmpty(ed.getBody())) {
  856. ed.setContent('', {format : 'raw'});
  857. ed.nodeChanged();
  858. return;
  859. }
  860. }
  861. });
  862. };
  863. function inputMethodFocus(ed) {
  864. ed.dom.bind(ed.getDoc(), 'focusin', function() {
  865. ed.selection.setRng(ed.selection.getRng());
  866. });
  867. };
  868. function removeHrOnBackspace(ed) {
  869. ed.onKeyDown.add(function(ed, e) {
  870. if (e.keyCode === BACKSPACE) {
  871. if (ed.selection.isCollapsed() && ed.selection.getRng(true).startOffset === 0) {
  872. var node = ed.selection.getNode();
  873. var previousSibling = node.previousSibling;
  874. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "hr") {
  875. ed.dom.remove(previousSibling);
  876. tinymce.dom.Event.cancel(e);
  877. }
  878. }
  879. }
  880. })
  881. }
  882. function focusBody(ed) {
  883. // Fix for a focus bug in FF 3.x where the body element
  884. // wouldn't get proper focus if the user clicked on the HTML element
  885. if (!Range.prototype.getClientRects) { // Detect getClientRects got introduced in FF 4
  886. ed.onMouseDown.add(function(ed, e) {
  887. if (e.target.nodeName === "HTML") {
  888. var body = ed.getBody();
  889. // Blur the body it's focused but not correctly focused
  890. body.blur();
  891. // Refocus the body after a little while
  892. setTimeout(function() {
  893. body.focus();
  894. }, 0);
  895. }
  896. });
  897. }
  898. };
  899. function selectControlElements(ed) {
  900. ed.onClick.add(function(ed, e) {
  901. e = e.target;
  902. // Workaround for bug, http://bugs.webkit.org/show_bug.cgi?id=12250
  903. // WebKit can't even do simple things like selecting an image
  904. // Needs tobe the setBaseAndExtend or it will fail to select floated images
  905. if (/^(IMG|HR)$/.test(e.nodeName))
  906. ed.selection.getSel().setBaseAndExtent(e, 0, e, 1);
  907. if (e.nodeName == 'A' && ed.dom.hasClass(e, 'mceItemAnchor'))
  908. ed.selection.select(e);
  909. ed.nodeChanged();
  910. });
  911. };
  912. function selectionChangeNodeChanged(ed) {
  913. var lastRng, selectionTimer;
  914. ed.dom.bind(ed.getDoc(), 'selectionchange', function() {
  915. if (selectionTimer) {
  916. clearTimeout(selectionTimer);
  917. selectionTimer = 0;
  918. }
  919. selectionTimer = window.setTimeout(function() {
  920. var rng = ed.selection.getRng();
  921. // Compare the ranges to see if it was a real change or not
  922. if (!lastRng || !tinymce.dom.RangeUtils.compareRanges(rng, lastRng)) {
  923. ed.nodeChanged();
  924. lastRng = rng;
  925. }
  926. }, 50);
  927. });
  928. }
  929. function ensureBodyHasRoleApplication(ed) {
  930. document.body.setAttribute("role", "application");
  931. }
  932. tinymce.create('tinymce.util.Quirks', {
  933. Quirks: function(ed) {
  934. // WebKit
  935. if (tinymce.isWebKit) {
  936. cleanupStylesWhenDeleting(ed);
  937. emptyEditorWhenDeleting(ed);
  938. inputMethodFocus(ed);
  939. selectControlElements(ed);
  940. // iOS
  941. if (tinymce.isIDevice) {
  942. selectionChangeNodeChanged(ed);
  943. }
  944. }
  945. // IE
  946. if (tinymce.isIE) {
  947. removeHrOnBackspace(ed);
  948. emptyEditorWhenDeleting(ed);
  949. ensureBodyHasRoleApplication(ed);
  950. }
  951. // Gecko
  952. if (tinymce.isGecko) {
  953. removeHrOnBackspace(ed);
  954. focusBody(ed);
  955. }
  956. }
  957. });
  958. })(tinymce);
  959. (function(tinymce) {
  960. var namedEntities, baseEntities, reverseEntities,
  961. attrsCharsRegExp = /[&<>\"\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  962. textCharsRegExp = /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  963. rawCharsRegExp = /[<>&\"\']/g,
  964. entityRegExp = /&(#x|#)?([\w]+);/g,
  965. asciiMap = {
  966. 128 : "\u20AC", 130 : "\u201A", 131 : "\u0192", 132 : "\u201E", 133 : "\u2026", 134 : "\u2020",
  967. 135 : "\u2021", 136 : "\u02C6", 137 : "\u2030", 138 : "\u0160", 139 : "\u2039", 140 : "\u0152",
  968. 142 : "\u017D", 145 : "\u2018", 146 : "\u2019", 147 : "\u201C", 148 : "\u201D", 149 : "\u2022",
  969. 150 : "\u2013", 151 : "\u2014", 152 : "\u02DC", 153 : "\u2122", 154 : "\u0161", 155 : "\u203A",
  970. 156 : "\u0153", 158 : "\u017E", 159 : "\u0178"
  971. };
  972. // Raw entities
  973. baseEntities = {
  974. '\"' : '&quot;', // Needs to be escaped since the YUI compressor would otherwise break the code
  975. "'" : '&#39;',
  976. '<' : '&lt;',
  977. '>' : '&gt;',
  978. '&' : '&amp;'
  979. };
  980. // Reverse lookup table for raw entities
  981. reverseEntities = {
  982. '&lt;' : '<',
  983. '&gt;' : '>',
  984. '&amp;' : '&',
  985. '&quot;' : '"',
  986. '&apos;' : "'"
  987. };
  988. // Decodes text by using the browser
  989. function nativeDecode(text) {
  990. var elm;
  991. elm = document.createElement("div");
  992. elm.innerHTML = text;
  993. return elm.textContent || elm.innerText || text;
  994. };
  995. // Build a two way lookup table for the entities
  996. function buildEntitiesLookup(items, radix) {
  997. var i, chr, entity, lookup = {};
  998. if (items) {
  999. items = items.split(',');
  1000. radix = radix || 10;
  1001. // Build entities lookup table
  1002. for (i = 0; i < items.length; i += 2) {
  1003. chr = String.fromCharCode(parseInt(items[i], radix));
  1004. // Only add non base entities
  1005. if (!baseEntities[chr]) {
  1006. entity = '&' + items[i + 1] + ';';
  1007. lookup[chr] = entity;
  1008. lookup[entity] = chr;
  1009. }
  1010. }
  1011. return lookup;
  1012. }
  1013. };
  1014. // Unpack entities lookup where the numbers are in radix 32 to reduce the size
  1015. namedEntities = buildEntitiesLookup(
  1016. '50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' +
  1017. '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' +
  1018. '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' +
  1019. '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' +
  1020. '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' +
  1021. '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' +
  1022. '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' +
  1023. '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' +
  1024. '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' +
  1025. '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' +
  1026. 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' +
  1027. 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' +
  1028. 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' +
  1029. 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' +
  1030. 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' +
  1031. '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' +
  1032. '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' +
  1033. '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' +
  1034. '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' +
  1035. '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' +
  1036. 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' +
  1037. 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' +
  1038. 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' +
  1039. '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' +
  1040. '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro'
  1041. , 32);
  1042. tinymce.html = tinymce.html || {};
  1043. tinymce.html.Entities = {
  1044. encodeRaw : function(text, attr) {
  1045. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1046. return baseEntities[chr] || chr;
  1047. });
  1048. },
  1049. encodeAllRaw : function(text) {
  1050. return ('' + text).replace(rawCharsRegExp, function(chr) {
  1051. return baseEntities[chr] || chr;
  1052. });
  1053. },
  1054. encodeNumeric : function(text, attr) {
  1055. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1056. // Multi byte sequence convert it to a single entity
  1057. if (chr.length > 1)
  1058. return '&#' + (((chr.charCodeAt(0) - 0xD800) * 0x400) + (chr.charCodeAt(1) - 0xDC00) + 0x10000) + ';';
  1059. return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
  1060. });
  1061. },
  1062. encodeNamed : function(text, attr, entities) {
  1063. entities = entities || namedEntities;
  1064. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1065. return baseEntities[chr] || entities[chr] || chr;
  1066. });
  1067. },
  1068. getEncodeFunc : function(name, entities) {
  1069. var Entities = tinymce.html.Entities;
  1070. entities = buildEntitiesLookup(entities) || namedEntities;
  1071. function encodeNamedAndNumeric(text, attr) {
  1072. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1073. return baseEntities[chr] || entities[chr] || '&#' + chr.charCodeAt(0) + ';' || chr;
  1074. });
  1075. };
  1076. function encodeCustomNamed(text, attr) {
  1077. return Entities.encodeNamed(text, attr, entities);
  1078. };
  1079. // Replace + with , to be compatible with previous TinyMCE versions
  1080. name = tinymce.makeMap(name.replace(/\+/g, ','));
  1081. // Named and numeric encoder
  1082. if (name.named && name.numeric)
  1083. return encodeNamedAndNumeric;
  1084. // Named encoder
  1085. if (name.named) {
  1086. // Custom names
  1087. if (entities)
  1088. return encodeCustomNamed;
  1089. return Entities.encodeNamed;
  1090. }
  1091. // Numeric
  1092. if (name.numeric)
  1093. return Entities.encodeNumeric;
  1094. // Raw encoder
  1095. return Entities.encodeRaw;
  1096. },
  1097. decode : function(text) {
  1098. return text.replace(entityRegExp, function(all, numeric, value) {
  1099. if (numeric) {
  1100. value = parseInt(value, numeric.length === 2 ? 16 : 10);
  1101. // Support upper UTF
  1102. if (value > 0xFFFF) {
  1103. value -= 0x10000;
  1104. return String.fromCharCode(0xD800 + (value >> 10), 0xDC00 + (value & 0x3FF));
  1105. } else
  1106. return asciiMap[value] || String.fromCharCode(value);
  1107. }
  1108. return reverseEntities[all] || namedEntities[all] || nativeDecode(all);
  1109. });
  1110. }
  1111. };
  1112. })(tinymce);
  1113. tinymce.html.Styles = function(settings, schema) {
  1114. var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi,
  1115. urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi,
  1116. styleRegExp = /\s*([^:]+):\s*([^;]+);?/g,
  1117. trimRightRegExp = /\s+$/,
  1118. urlColorRegExp = /rgb/,
  1119. undef, i, encodingLookup = {}, encodingItems;
  1120. settings = settings || {};
  1121. encodingItems = '\\" \\\' \\; \\: ; : \uFEFF'.split(' ');
  1122. for (i = 0; i < encodingItems.length; i++) {
  1123. encodingLookup[encodingItems[i]] = '\uFEFF' + i;
  1124. encodingLookup['\uFEFF' + i] = encodingItems[i];
  1125. }
  1126. function toHex(match, r, g, b) {
  1127. function hex(val) {
  1128. val = parseInt(val).toString(16);
  1129. return val.length > 1 ? val : '0' + val; // 0 -> 00
  1130. };
  1131. return '#' + hex(r) + hex(g) + hex(b);
  1132. };
  1133. return {
  1134. toHex : function(color) {
  1135. return color.replace(rgbRegExp, toHex);
  1136. },
  1137. parse : function(css) {
  1138. var styles = {}, matches, name, value, isEncoded, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope || this;
  1139. function compress(prefix, suffix) {
  1140. var top, right, bottom, left;
  1141. // Get values and check it it needs compressing
  1142. top = styles[prefix + '-top' + suffix];
  1143. if (!top)
  1144. return;
  1145. right = styles[prefix + '-right' + suffix];
  1146. if (top != right)
  1147. return;
  1148. bottom = styles[prefix + '-bottom' + suffix];
  1149. if (right != bottom)
  1150. return;
  1151. left = styles[prefix + '-left' + suffix];
  1152. if (bottom != left)
  1153. return;
  1154. // Compress
  1155. styles[prefix + suffix] = left;
  1156. delete styles[prefix + '-top' + suffix];
  1157. delete styles[prefix + '-right' + suffix];
  1158. delete styles[prefix + '-bottom' + suffix];
  1159. delete styles[prefix + '-left' + suffix];
  1160. };
  1161. function canCompress(key) {
  1162. var value = styles[key], i;
  1163. if (!value || value.indexOf(' ') < 0)
  1164. return;
  1165. value = value.split(' ');
  1166. i = value.length;
  1167. while (i--) {
  1168. if (value[i] !== value[0])
  1169. return false;
  1170. }
  1171. styles[key] = value[0];
  1172. return true;
  1173. };
  1174. function compress2(target, a, b, c) {
  1175. if (!canCompress(a))
  1176. return;
  1177. if (!canCompress(b))
  1178. return;
  1179. if (!canCompress(c))
  1180. return;
  1181. // Compress
  1182. styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
  1183. delete styles[a];
  1184. delete styles[b];
  1185. delete styles[c];
  1186. };
  1187. // Encodes the specified string by replacing all \" \' ; : with _<num>
  1188. function encode(str) {
  1189. isEncoded = true;
  1190. return encodingLookup[str];
  1191. };
  1192. // Decodes the specified string by replacing all _<num> with it's original value \" \' etc
  1193. // It will also decode the \" \' if keep_slashes is set to fale or omitted
  1194. function decode(str, keep_slashes) {
  1195. if (isEncoded) {
  1196. str = str.replace(/\uFEFF[0-9]/g, function(str) {
  1197. return encodingLookup[str];
  1198. });
  1199. }
  1200. if (!keep_slashes)
  1201. str = str.replace(/\\([\'\";:])/g, "$1");
  1202. return str;
  1203. }
  1204. if (css) {
  1205. // Encode \" \' % and ; and : inside strings so they don't interfere with the style parsing
  1206. css = css.replace(/\\[\"\';:\uFEFF]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, function(str) {
  1207. return str.replace(/[;:]/g, encode);
  1208. });
  1209. // Parse styles
  1210. while (matches = styleRegExp.exec(css)) {
  1211. name = matches[1].replace(trimRightRegExp, '').toLowerCase();
  1212. value = matches[2].replace(trimRightRegExp, '');
  1213. if (name && value.length > 0) {
  1214. // Opera will produce 700 instead of bold in their style values
  1215. if (name === 'font-weight' && value === '700')
  1216. value = 'bold';
  1217. else if (name === 'color' || name === 'background-color') // Lowercase colors like RED
  1218. value = value.toLowerCase();
  1219. // Convert RGB colors to HEX
  1220. value = value.replace(rgbRegExp, toHex);
  1221. // Convert URLs and force them into url('value') format
  1222. value = value.replace(urlOrStrRegExp, function(match, url, url2, url3, str, str2) {
  1223. str = str || str2;
  1224. if (str) {
  1225. str = decode(str);
  1226. // Force strings into single quote format
  1227. return "'" + str.replace(/\'/g, "\\'") + "'";
  1228. }
  1229. url = decode(url || url2 || url3);
  1230. // Convert the URL to relative/absolute depending on config
  1231. if (urlConverter)
  1232. url = urlConverter.call(urlConverterScope, url, 'style');
  1233. // Output new URL format
  1234. return "url('" + url.replace(/\'/g, "\\'") + "')";
  1235. });
  1236. styles[name] = isEncoded ? decode(value, true) : value;
  1237. }
  1238. styleRegExp.lastIndex = matches.index + matches[0].length;
  1239. }
  1240. // Compress the styles to reduce it's size for example IE will expand styles
  1241. compress("border", "");
  1242. compress("border", "-width");
  1243. compress("border", "-color");
  1244. compress("border", "-style");
  1245. compress("padding", "");
  1246. compress("margin", "");
  1247. compress2('border', 'border-width', 'border-style', 'border-color');
  1248. // Remove pointless border, IE produces these
  1249. if (styles.border === 'medium none')
  1250. delete styles.border;
  1251. }
  1252. return styles;
  1253. },
  1254. serialize : function(styles, element_name) {
  1255. var css = '', name, value;
  1256. function serializeStyles(name) {
  1257. var styleList, i, l, value;
  1258. styleList = schema.styles[name];
  1259. if (styleList) {
  1260. for (i = 0, l = styleList.length; i < l; i++) {
  1261. name = styleList[i];
  1262. value = styles[name];
  1263. if (value !== undef && value.length > 0)
  1264. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  1265. }
  1266. }
  1267. };
  1268. // Serialize styles according to schema
  1269. if (element_name && schema && schema.styles) {
  1270. // Serialize global styles and element specific styles
  1271. serializeStyles('*');
  1272. serializeStyles(element_name);
  1273. } else {
  1274. // Output the styles in the order they are inside the object
  1275. for (name in styles) {
  1276. value = styles[name];
  1277. if (value !== undef && value.length > 0)
  1278. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  1279. }
  1280. }
  1281. return css;
  1282. }
  1283. };
  1284. };
  1285. (function(tinymce) {
  1286. var transitional = {}, boolAttrMap, blockElementsMap, shortEndedElementsMap, nonEmptyElementsMap, customElementsMap = {},
  1287. defaultWhiteSpaceElementsMap, selfClosingElementsMap, makeMap = tinymce.makeMap, each = tinymce.each;
  1288. function split(str, delim) {
  1289. return str.split(delim || ',');
  1290. };
  1291. function unpack(lookup, data) {
  1292. var key, elements = {};
  1293. function replace(value) {
  1294. return value.replace(/[A-Z]+/g, function(key) {
  1295. return replace(lookup[key]);
  1296. });
  1297. };
  1298. // Unpack lookup
  1299. for (key in lookup) {
  1300. if (lookup.hasOwnProperty(key))
  1301. lookup[key] = replace(lookup[key]);
  1302. }
  1303. // Unpack and parse data into object map
  1304. replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]\[([^\]]*)\]/g, function(str, name, attributes, children) {
  1305. attributes = split(attributes, '|');
  1306. elements[name] = {
  1307. attributes : makeMap(attributes),
  1308. attributesOrder : attributes,
  1309. children : makeMap(children, '|', {'#comment' : {}})
  1310. }
  1311. });
  1312. return elements;
  1313. };
  1314. // Build a lookup table for block elements both lowercase and uppercase
  1315. blockElementsMap = 'h1,h2,h3,h4,h5,h6,hr,p,div,address,pre,form,table,tbody,thead,tfoot,' +
  1316. 'th,tr,td,li,ol,ul,caption,blockquote,center,dl,dt,dd,dir,fieldset,' +
  1317. 'noscript,menu,isindex,samp,header,footer,article,section,hgroup';
  1318. blockElementsMap = makeMap(blockElementsMap, ',', makeMap(blockElementsMap.toUpperCase()));
  1319. // This is the XHTML 1.0 transitional elements with it's attributes and children packed to reduce it's size
  1320. transitional = unpack({
  1321. Z : 'H|K|N|O|P',
  1322. Y : 'X|form|R|Q',
  1323. ZG : 'E|span|width|align|char|charoff|valign',
  1324. X : 'p|T|div|U|W|isindex|fieldset|table',
  1325. ZF : 'E|align|char|charoff|valign',
  1326. W : 'pre|hr|blockquote|address|center|noframes',
  1327. ZE : 'abbr|axis|headers|scope|rowspan|colspan|align|char|charoff|valign|nowrap|bgcolor|width|height',
  1328. ZD : '[E][S]',
  1329. U : 'ul|ol|dl|menu|dir',
  1330. ZC : 'p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q',
  1331. T : 'h1|h2|h3|h4|h5|h6',
  1332. ZB : 'X|S|Q',
  1333. S : 'R|P',
  1334. ZA : 'a|G|J|M|O|P',
  1335. R : 'a|H|K|N|O',
  1336. Q : 'noscript|P',
  1337. P : 'ins|del|script',
  1338. O : 'input|select|textarea|label|button',
  1339. N : 'M|L',
  1340. M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym',
  1341. L : 'sub|sup',
  1342. K : 'J|I',
  1343. J : 'tt|i|b|u|s|strike',
  1344. I : 'big|small|font|basefont',
  1345. H : 'G|F',
  1346. G : 'br|span|bdo',
  1347. F : 'object|applet|img|map|iframe',
  1348. E : 'A|B|C',
  1349. D : 'accesskey|tabindex|onfocus|onblur',
  1350. C : 'onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
  1351. B : 'lang|xml:lang|dir',
  1352. A : 'id|class|style|title'
  1353. }, 'script[id|charset|type|language|src|defer|xml:space][]' +
  1354. 'style[B|id|type|media|title|xml:space][]' +
  1355. 'object[E|declare|classid|codebase|data|type|codetype|archive|standby|width|height|usemap|name|tabindex|align|border|hspace|vspace][#|param|Y]' +
  1356. 'param[id|name|value|valuetype|type][]' +
  1357. 'p[E|align][#|S]' +
  1358. 'a[E|D|charset|type|name|href|hreflang|rel|rev|shape|coords|target][#|Z]' +
  1359. 'br[A|clear][]' +
  1360. 'span[E][#|S]' +
  1361. 'bdo[A|C|B][#|S]' +
  1362. 'applet[A|codebase|archive|code|object|alt|name|width|height|align|hspace|vspace][#|param|Y]' +
  1363. 'h1[E|align][#|S]' +
  1364. 'img[E|src|alt|name|longdesc|width|height|usemap|ismap|align|border|hspace|vspace][]' +
  1365. 'map[B|C|A|name][X|form|Q|area]' +
  1366. 'h2[E|align][#|S]' +
  1367. 'iframe[A|longdesc|name|src|frameborder|marginwidth|marginheight|scrolling|align|width|height][#|Y]' +
  1368. 'h3[E|align][#|S]' +
  1369. 'tt[E][#|S]' +
  1370. 'i[E][#|S]' +
  1371. 'b[E][#|S]' +
  1372. 'u[E][#|S]' +
  1373. 's[E][#|S]' +
  1374. 'strike[E][#|S]' +
  1375. 'big[E][#|S]' +
  1376. 'small[E][#|S]' +
  1377. 'font[A|B|size|color|face][#|S]' +
  1378. 'basefont[id|size|color|face][]' +
  1379. 'em[E][#|S]' +
  1380. 'strong[E][#|S]' +
  1381. 'dfn[E][#|S]' +
  1382. 'code[E][#|S]' +
  1383. 'q[E|cite][#|S]' +
  1384. 'samp[E][#|S]' +
  1385. 'kbd[E][#|S]' +
  1386. 'var[E][#|S]' +
  1387. 'cite[E][#|S]' +
  1388. 'abbr[E][#|S]' +
  1389. 'acronym[E][#|S]' +
  1390. 'sub[E][#|S]' +
  1391. 'sup[E][#|S]' +
  1392. 'input[E|D|type|name|value|checked|disabled|readonly|size|maxlength|src|alt|usemap|onselect|onchange|accept|align][]' +
  1393. 'select[E|name|size|multiple|disabled|tabindex|onfocus|onblur|onchange][optgroup|option]' +
  1394. 'optgroup[E|disabled|label][option]' +
  1395. 'option[E|selected|disabled|label|value][]' +
  1396. 'textarea[E|D|name|rows|cols|disabled|readonly|onselect|onchange][]' +
  1397. 'label[E|for|accesskey|onfocus|onblur][#|S]' +
  1398. 'button[E|D|name|value|type|disabled][#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' +
  1399. 'h4[E|align][#|S]' +
  1400. 'ins[E|cite|datetime][#|Y]' +
  1401. 'h5[E|align][#|S]' +
  1402. 'del[E|cite|datetime][#|Y]' +
  1403. 'h6[E|align][#|S]' +
  1404. 'div[E|align][#|Y]' +
  1405. 'ul[E|type|compact][li]' +
  1406. 'li[E|type|value][#|Y]' +
  1407. 'ol[E|type|compact|start][li]' +
  1408. 'dl[E|compact][dt|dd]' +
  1409. 'dt[E][#|S]' +
  1410. 'dd[E][#|Y]' +
  1411. 'menu[E|compact][li]' +
  1412. 'dir[E|compact][li]' +
  1413. 'pre[E|width|xml:space][#|ZA]' +
  1414. 'hr[E|align|noshade|size|width][]' +
  1415. 'blockquote[E|cite][#|Y]' +
  1416. 'address[E][#|S|p]' +
  1417. 'center[E][#|Y]' +
  1418. 'noframes[E][#|Y]' +
  1419. 'isindex[A|B|prompt][]' +
  1420. 'fieldset[E][#|legend|Y]' +
  1421. 'legend[E|accesskey|align][#|S]' +
  1422. 'table[E|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor][caption|col|colgroup|thead|tfoot|tbody|tr]' +
  1423. 'caption[E|align][#|S]' +
  1424. 'col[ZG][]' +
  1425. 'colgroup[ZG][col]' +
  1426. 'thead[ZF][tr]' +
  1427. 'tr[ZF|bgcolor][th|td]' +
  1428. 'th[E|ZE][#|Y]' +
  1429. 'form[E|action|method|name|enctype|onsubmit|onreset|accept|accept-charset|target][#|X|R|Q]' +
  1430. 'noscript[E][#|Y]' +
  1431. 'td[E|ZE][#|Y]' +
  1432. 'tfoot[ZF][tr]' +
  1433. 'tbody[ZF][tr]' +
  1434. 'area[E|D|shape|coords|href|nohref|alt|target][]' +
  1435. 'base[id|href|target][]' +
  1436. 'body[E|onload|onunload|background|bgcolor|text|link|vlink|alink][#|Y]'
  1437. );
  1438. boolAttrMap = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected,autoplay,loop,controls');
  1439. shortEndedElementsMap = makeMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed,source');
  1440. nonEmptyElementsMap = tinymce.extend(makeMap('td,th,iframe,video,audio,object'), shortEndedElementsMap);
  1441. defaultWhiteSpaceElementsMap = makeMap('pre,script,style,textarea');
  1442. selfClosingElementsMap = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr');
  1443. tinymce.html.Schema = function(settings) {
  1444. var self = this, elements = {}, children = {}, patternElements = [], validStyles, whiteSpaceElementsMap;
  1445. settings = settings || {};
  1446. // Allow all elements and attributes if verify_html is set to false
  1447. if (settings.verify_html === false)
  1448. settings.valid_elements = '*[*]';
  1449. // Build styles list
  1450. if (settings.valid_styles) {
  1451. validStyles = {};
  1452. // Convert styles into a rule list
  1453. each(settings.valid_styles, function(value, key) {
  1454. validStyles[key] = tinymce.explode(value);
  1455. });
  1456. }
  1457. whiteSpaceElementsMap = settings.whitespace_elements ? makeMap(settings.whitespace_elements) : defaultWhiteSpaceElementsMap;
  1458. // Converts a wildcard expression string to a regexp for example *a will become /.*a/.
  1459. function patternToRegExp(str) {
  1460. return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$');
  1461. };
  1462. // Parses the specified valid_elements string and adds to the current rules
  1463. // This function is a bit hard to read since it's heavily optimized for speed
  1464. function addValidElements(valid_elements) {
  1465. var ei, el, ai, al, yl, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder,
  1466. prefix, outputName, globalAttributes, globalAttributesOrder, transElement, key, childKey, value,
  1467. elementRuleRegExp = /^([#+-])?([^\[\/]+)(?:\/([^\[]+))?(?:\[([^\]]+)\])?$/,
  1468. attrRuleRegExp = /^([!\-])?(\w+::\w+|[^=:<]+)?(?:([=:<])(.*))?$/,
  1469. hasPatternsRegExp = /[*?+]/;
  1470. if (valid_elements) {
  1471. // Split valid elements into an array with rules
  1472. valid_elements = split(valid_elements);
  1473. if (elements['@']) {
  1474. globalAttributes = elements['@'].attributes;
  1475. globalAttributesOrder = elements['@'].attributesOrder;
  1476. }
  1477. // Loop all rules
  1478. for (ei = 0, el = valid_elements.length; ei < el; ei++) {
  1479. // Parse element rule
  1480. matches = elementRuleRegExp.exec(valid_elements[ei]);
  1481. if (matches) {
  1482. // Setup local names for matches
  1483. prefix = matches[1];
  1484. elementName = matches[2];
  1485. outputName = matches[3];
  1486. attrData = matches[4];
  1487. // Create new attributes and attributesOrder
  1488. attributes = {};
  1489. attributesOrder = [];
  1490. // Create the new element
  1491. element = {
  1492. attributes : attributes,
  1493. attributesOrder : attributesOrder
  1494. };
  1495. // Padd empty elements prefix
  1496. if (prefix === '#')
  1497. element.paddEmpty = true;
  1498. // Remove empty elements prefix
  1499. if (prefix === '-')
  1500. element.removeEmpty = true;
  1501. // Copy attributes from global rule into current rule
  1502. if (globalAttributes) {
  1503. for (key in globalAttributes)
  1504. attributes[key] = globalAttributes[key];
  1505. attributesOrder.push.apply(attributesOrder, globalAttributesOrder);
  1506. }
  1507. // Attributes defined
  1508. if (attrData) {
  1509. attrData = split(attrData, '|');
  1510. for (ai = 0, al = attrData.length; ai < al; ai++) {
  1511. matches = attrRuleRegExp.exec(attrData[ai]);
  1512. if (matches) {
  1513. attr = {};
  1514. attrType = matches[1];
  1515. attrName = matches[2].replace(/::/g, ':');
  1516. prefix = matches[3];
  1517. value = matches[4];
  1518. // Required
  1519. if (attrType === '!') {
  1520. element.attributesRequired = element.attributesRequired || [];
  1521. element.attributesRequired.push(attrName);
  1522. attr.required = true;
  1523. }
  1524. // Denied from global
  1525. if (attrType === '-') {
  1526. delete attributes[attrName];
  1527. attributesOrder.splice(tinymce.inArray(attributesOrder, attrName), 1);
  1528. continue;
  1529. }
  1530. // Default value
  1531. if (prefix) {
  1532. // Default value
  1533. if (prefix === '=') {
  1534. element.attributesDefault = element.attributesDefault || [];
  1535. element.attributesDefault.push({name: attrName, value: value});
  1536. attr.defaultValue = value;
  1537. }
  1538. // Forced value
  1539. if (prefix === ':') {
  1540. element.attributesForced = element.attributesForced || [];
  1541. element.attributesForced.push({name: attrName, value: value});
  1542. attr.forcedValue = value;
  1543. }
  1544. // Required values
  1545. if (prefix === '<')
  1546. attr.validValues = makeMap(value, '?');
  1547. }
  1548. // Check for attribute patterns
  1549. if (hasPatternsRegExp.test(attrName)) {
  1550. element.attributePatterns = element.attributePatterns || [];
  1551. attr.pattern = patternToRegExp(attrName);
  1552. element.attributePatterns.push(attr);
  1553. } else {
  1554. // Add attribute to order list if it doesn't already exist
  1555. if (!attributes[attrName])
  1556. attributesOrder.push(attrName);
  1557. attributes[attrName] = attr;
  1558. }
  1559. }
  1560. }
  1561. }
  1562. // Global rule, store away these for later usage
  1563. if (!globalAttributes && elementName == '@') {
  1564. globalAttributes = attributes;
  1565. globalAttributesOrder = attributesOrder;
  1566. }
  1567. // Handle substitute elements such as b/strong
  1568. if (outputName) {
  1569. element.outputName = elementName;
  1570. elements[outputName] = element;
  1571. }
  1572. // Add pattern or exact element
  1573. if (hasPatternsRegExp.test(elementName)) {
  1574. element.pattern = patternToRegExp(elementName);
  1575. patternElements.push(element);
  1576. } else
  1577. elements[elementName] = element;
  1578. }
  1579. }
  1580. }
  1581. };
  1582. function setValidElements(valid_elements) {
  1583. elements = {};
  1584. patternElements = [];
  1585. addValidElements(valid_elements);
  1586. each(transitional, function(element, name) {
  1587. children[name] = element.children;
  1588. });
  1589. };
  1590. // Adds custom non HTML elements to the schema
  1591. function addCustomElements(custom_elements) {
  1592. var customElementRegExp = /^(~)?(.+)$/;
  1593. if (custom_elements) {
  1594. each(split(custom_elements), function(rule) {
  1595. var matches = customElementRegExp.exec(rule),
  1596. inline = matches[1] === '~',
  1597. cloneName = inline ? 'span' : 'div',
  1598. name = matches[2];
  1599. children[name] = children[cloneName];
  1600. customElementsMap[name] = cloneName;
  1601. // If it's not marked as inline then add it to valid block elements
  1602. if (!inline)
  1603. blockElementsMap[name] = {};
  1604. // Add custom elements at span/div positions
  1605. each(children, function(element, child) {
  1606. if (element[cloneName])
  1607. element[name] = element[cloneName];
  1608. });
  1609. });
  1610. }
  1611. };
  1612. // Adds valid children to the schema object
  1613. function addValidChildren(valid_children) {
  1614. var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/;
  1615. if (valid_children) {
  1616. each(split(valid_children), function(rule) {
  1617. var matches = childRuleRegExp.exec(rule), parent, prefix;
  1618. if (matches) {
  1619. prefix = matches[1];
  1620. // Add/remove items from default
  1621. if (prefix)
  1622. parent = children[matches[2]];
  1623. else
  1624. parent = children[matches[2]] = {'#comment' : {}};
  1625. parent = children[matches[2]];
  1626. each(split(matches[3], '|'), function(child) {
  1627. if (prefix === '-')
  1628. delete parent[child];
  1629. else
  1630. parent[child] = {};
  1631. });
  1632. }
  1633. });
  1634. }
  1635. };
  1636. function getElementRule(name) {
  1637. var element = elements[name], i;
  1638. // Exact match found
  1639. if (element)
  1640. return element;
  1641. // No exact match then try the patterns
  1642. i = patternElements.length;
  1643. while (i--) {
  1644. element = patternElements[i];
  1645. if (element.pattern.test(name))
  1646. return element;
  1647. }
  1648. };
  1649. if (!settings.valid_elements) {
  1650. // No valid elements defined then clone the elements from the transitional spec
  1651. each(transitional, function(element, name) {
  1652. elements[name] = {
  1653. attributes : element.attributes,
  1654. attributesOrder : element.attributesOrder
  1655. };
  1656. children[name] = element.children;
  1657. });
  1658. // Switch these
  1659. each(split('strong/b,em/i'), function(item) {
  1660. item = split(item, '/');
  1661. elements[item[1]].outputName = item[0];
  1662. });
  1663. // Add default alt attribute for images
  1664. elements.img.attributesDefault = [{name: 'alt', value: ''}];
  1665. // Remove these if they are empty by default
  1666. each(split('ol,ul,sub,sup,blockquote,span,font,a,table,tbody,tr'), function(name) {
  1667. elements[name].removeEmpty = true;
  1668. });
  1669. // Padd these by default
  1670. each(split('p,h1,h2,h3,h4,h5,h6,th,td,pre,div,address,caption'), function(name) {
  1671. elements[name].paddEmpty = true;
  1672. });
  1673. } else
  1674. setValidElements(settings.valid_elements);
  1675. addCustomElements(settings.custom_elements);
  1676. addValidChildren(settings.valid_children);
  1677. addValidElements(settings.extended_valid_elements);
  1678. // Todo: Remove this when we fix list handling to be valid
  1679. addValidChildren('+ol[ul|ol],+ul[ul|ol]');
  1680. // If the user didn't allow span only allow internal spans
  1681. if (!getElementRule('span'))
  1682. addValidElements('span[!data-mce-type|*]');
  1683. // Delete invalid elements
  1684. if (settings.invalid_elements) {
  1685. tinymce.each(tinymce.explode(settings.invalid_elements), function(item) {
  1686. if (elements[item])
  1687. delete elements[item];
  1688. });
  1689. }
  1690. self.children = children;
  1691. self.styles = validStyles;
  1692. self.getBoolAttrs = function() {
  1693. return boolAttrMap;
  1694. };
  1695. self.getBlockElements = function() {
  1696. return blockElementsMap;
  1697. };
  1698. self.getShortEndedElements = function() {
  1699. return shortEndedElementsMap;
  1700. };
  1701. self.getSelfClosingElements = function() {
  1702. return selfClosingElementsMap;
  1703. };
  1704. self.getNonEmptyElements = function() {
  1705. return nonEmptyElementsMap;
  1706. };
  1707. self.getWhiteSpaceElements = function() {
  1708. return whiteSpaceElementsMap;
  1709. };
  1710. self.isValidChild = function(name, child) {
  1711. var parent = children[name];
  1712. return !!(parent && parent[child]);
  1713. };
  1714. self.getElementRule = getElementRule;
  1715. self.getCustomElements = function() {
  1716. return customElementsMap;
  1717. };
  1718. self.addValidElements = addValidElements;
  1719. self.setValidElements = setValidElements;
  1720. self.addCustomElements = addCustomElements;
  1721. self.addValidChildren = addValidChildren;
  1722. };
  1723. // Expose boolMap and blockElementMap as static properties for usage in DOMUtils
  1724. tinymce.html.Schema.boolAttrMap = boolAttrMap;
  1725. tinymce.html.Schema.blockElementsMap = blockElementsMap;
  1726. })(tinymce);
  1727. (function(tinymce) {
  1728. tinymce.html.SaxParser = function(settings, schema) {
  1729. var self = this, noop = function() {};
  1730. settings = settings || {};
  1731. self.schema = schema = schema || new tinymce.html.Schema();
  1732. if (settings.fix_self_closing !== false)
  1733. settings.fix_self_closing = true;
  1734. // Add handler functions from settings and setup default handlers
  1735. tinymce.each('comment cdata text start end pi doctype'.split(' '), function(name) {
  1736. if (name)
  1737. self[name] = settings[name] || noop;
  1738. });
  1739. self.parse = function(html) {
  1740. var self = this, matches, index = 0, value, endRegExp, stack = [], attrList, i, text, name, isInternalElement, removeInternalElements,
  1741. shortEndedElements, fillAttrsMap, isShortEnded, validate, elementRule, isValidElement, attr, attribsValue, invalidPrefixRegExp,
  1742. validAttributesMap, validAttributePatterns, attributesRequired, attributesDefault, attributesForced, selfClosing,
  1743. tokenRegExp, attrRegExp, specialElements, attrValue, idCount = 0, decode = tinymce.html.Entities.decode, fixSelfClosing, isIE;
  1744. function processEndTag(name) {
  1745. var pos, i;
  1746. // Find position of parent of the same type
  1747. pos = stack.length;
  1748. while (pos--) {
  1749. if (stack[pos].name === name)
  1750. break;
  1751. }
  1752. // Found parent
  1753. if (pos >= 0) {
  1754. // Close all the open elements
  1755. for (i = stack.length - 1; i >= pos; i--) {
  1756. name = stack[i];
  1757. if (name.valid)
  1758. self.end(name.name);
  1759. }
  1760. // Remove the open elements from the stack
  1761. stack.length = pos;
  1762. }
  1763. };
  1764. // Precompile RegExps and map objects
  1765. tokenRegExp = new RegExp('<(?:' +
  1766. '(?:!--([\\w\\W]*?)-->)|' + // Comment
  1767. '(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|' + // CDATA
  1768. '(?:!DOCTYPE([\\w\\W]*?)>)|' + // DOCTYPE
  1769. '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' + // PI
  1770. '(?:\\/([^>]+)>)|' + // End element
  1771. '(?:([^\\s\\/<>]+)((?:\\s+[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*|\\/)>)' + // Start element
  1772. ')', 'g');
  1773. attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:\\.|[^\"])*)\")|(?:\'((?:\\.|[^\'])*)\')|([^>\s]+)))?/g;
  1774. specialElements = {
  1775. 'script' : /<\/script[^>]*>/gi,
  1776. 'style' : /<\/style[^>]*>/gi,
  1777. 'noscript' : /<\/noscript[^>]*>/gi
  1778. };
  1779. // Setup lookup tables for empty elements and boolean attributes
  1780. shortEndedElements = schema.getShortEndedElements();
  1781. selfClosing = schema.getSelfClosingElements();
  1782. fillAttrsMap = schema.getBoolAttrs();
  1783. validate = settings.validate;
  1784. removeInternalElements = settings.remove_internals;
  1785. fixSelfClosing = settings.fix_self_closing;
  1786. isIE = tinymce.isIE;
  1787. invalidPrefixRegExp = /^:/;
  1788. while (matches = tokenRegExp.exec(html)) {
  1789. // Text
  1790. if (index < matches.index)
  1791. self.text(decode(html.substr(index, matches.index - index)));
  1792. if (value = matches[6]) { // End element
  1793. value = value.toLowerCase();
  1794. // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
  1795. if (isIE && invalidPrefixRegExp.test(value))
  1796. value = value.substr(1);
  1797. processEndTag(value);
  1798. } else if (value = matches[7]) { // Start element
  1799. value = value.toLowerCase();
  1800. // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
  1801. if (isIE && invalidPrefixRegExp.test(value))
  1802. value = value.substr(1);
  1803. isShortEnded = value in shortEndedElements;
  1804. // Is self closing tag for example an <li> after an open <li>
  1805. if (fixSelfClosing && selfClosing[value] && stack.length > 0 && stack[stack.length - 1].name === value)
  1806. processEndTag(value);
  1807. // Validate element
  1808. if (!validate || (elementRule = schema.getElementRule(value))) {
  1809. isValidElement = true;
  1810. // Grab attributes map and patters when validation is enabled
  1811. if (validate) {
  1812. validAttributesMap = elementRule.attributes;
  1813. validAttributePatterns = elementRule.attributePatterns;
  1814. }
  1815. // Parse attributes
  1816. if (attribsValue = matches[8]) {
  1817. isInternalElement = attribsValue.indexOf('data-mce-type') !== -1; // Check if the element is an internal element
  1818. // If the element has internal attributes then remove it if we are told to do so
  1819. if (isInternalElement && removeInternalElements)
  1820. isValidElement = false;
  1821. attrList = [];
  1822. attrList.map = {};
  1823. attribsValue.replace(attrRegExp, function(match, name, value, val2, val3) {
  1824. var attrRule, i;
  1825. name = name.toLowerCase();
  1826. value = name in fillAttrsMap ? name : decode(value || val2 || val3 || ''); // Handle boolean attribute than value attribute
  1827. // Validate name and value
  1828. if (validate && !isInternalElement && name.indexOf('data-') !== 0) {
  1829. attrRule = validAttributesMap[name];
  1830. // Find rule by pattern matching
  1831. if (!attrRule && validAttributePatterns) {
  1832. i = validAttributePatterns.length;
  1833. while (i--) {
  1834. attrRule = validAttributePatterns[i];
  1835. if (attrRule.pattern.test(name))
  1836. break;
  1837. }
  1838. // No rule matched
  1839. if (i === -1)
  1840. attrRule = null;
  1841. }
  1842. // No attribute rule found
  1843. if (!attrRule)
  1844. return;
  1845. // Validate value
  1846. if (attrRule.validValues && !(value in attrRule.validValues))
  1847. return;
  1848. }
  1849. // Add attribute to list and map
  1850. attrList.map[name] = value;
  1851. attrList.push({
  1852. name: name,
  1853. value: value
  1854. });
  1855. });
  1856. } else {
  1857. attrList = [];
  1858. attrList.map = {};
  1859. }
  1860. // Process attributes if validation is enabled
  1861. if (validate && !isInternalElement) {
  1862. attributesRequired = elementRule.attributesRequired;
  1863. attributesDefault = elementRule.attributesDefault;
  1864. attributesForced = elementRule.attributesForced;
  1865. // Handle forced attributes
  1866. if (attributesForced) {
  1867. i = attributesForced.length;
  1868. while (i--) {
  1869. attr = attributesForced[i];
  1870. name = attr.name;
  1871. attrValue = attr.value;
  1872. if (attrValue === '{$uid}')
  1873. attrValue = 'mce_' + idCount++;
  1874. attrList.map[name] = attrValue;
  1875. attrList.push({name: name, value: attrValue});
  1876. }
  1877. }
  1878. // Handle default attributes
  1879. if (attributesDefault) {
  1880. i = attributesDefault.length;
  1881. while (i--) {
  1882. attr = attributesDefault[i];
  1883. name = attr.name;
  1884. if (!(name in attrList.map)) {
  1885. attrValue = attr.value;
  1886. if (attrValue === '{$uid}')
  1887. attrValue = 'mce_' + idCount++;
  1888. attrList.map[name] = attrValue;
  1889. attrList.push({name: name, value: attrValue});
  1890. }
  1891. }
  1892. }
  1893. // Handle required attributes
  1894. if (attributesRequired) {
  1895. i = attributesRequired.length;
  1896. while (i--) {
  1897. if (attributesRequired[i] in attrList.map)
  1898. break;
  1899. }
  1900. // None of the required attributes where found
  1901. if (i === -1)
  1902. isValidElement = false;
  1903. }
  1904. // Invalidate element if it's marked as bogus
  1905. if (attrList.map['data-mce-bogus'])
  1906. isValidElement = false;
  1907. }
  1908. if (isValidElement)
  1909. self.start(value, attrList, isShortEnded);
  1910. } else
  1911. isValidElement = false;
  1912. // Treat script, noscript and style a bit different since they may include code that looks like elements
  1913. if (endRegExp = specialElements[value]) {
  1914. endRegExp.lastIndex = index = matches.index + matches[0].length;
  1915. if (matches = endRegExp.exec(html)) {
  1916. if (isValidElement)
  1917. text = html.substr(index, matches.index - index);
  1918. index = matches.index + matches[0].length;
  1919. } else {
  1920. text = html.substr(index);
  1921. index = html.length;
  1922. }
  1923. if (isValidElement && text.length > 0)
  1924. self.text(text, true);
  1925. if (isValidElement)
  1926. self.end(value);
  1927. tokenRegExp.lastIndex = index;
  1928. continue;
  1929. }
  1930. // Push value on to stack
  1931. if (!isShortEnded) {
  1932. if (!attribsValue || attribsValue.indexOf('/') != attribsValue.length - 1)
  1933. stack.push({name: value, valid: isValidElement});
  1934. else if (isValidElement)
  1935. self.end(value);
  1936. }
  1937. } else if (value = matches[1]) { // Comment
  1938. self.comment(value);
  1939. } else if (value = matches[2]) { // CDATA
  1940. self.cdata(value);
  1941. } else if (value = matches[3]) { // DOCTYPE
  1942. self.doctype(value);
  1943. } else if (value = matches[4]) { // PI
  1944. self.pi(value, matches[5]);
  1945. }
  1946. index = matches.index + matches[0].length;
  1947. }
  1948. // Text
  1949. if (index < html.length)
  1950. self.text(decode(html.substr(index)));
  1951. // Close any open elements
  1952. for (i = stack.length - 1; i >= 0; i--) {
  1953. value = stack[i];
  1954. if (value.valid)
  1955. self.end(value.name);
  1956. }
  1957. };
  1958. }
  1959. })(tinymce);
  1960. (function(tinymce) {
  1961. var whiteSpaceRegExp = /^[ \t\r\n]*$/, typeLookup = {
  1962. '#text' : 3,
  1963. '#comment' : 8,
  1964. '#cdata' : 4,
  1965. '#pi' : 7,
  1966. '#doctype' : 10,
  1967. '#document-fragment' : 11
  1968. };
  1969. // Walks the tree left/right
  1970. function walk(node, root_node, prev) {
  1971. var sibling, parent, startName = prev ? 'lastChild' : 'firstChild', siblingName = prev ? 'prev' : 'next';
  1972. // Walk into nodes if it has a start
  1973. if (node[startName])
  1974. return node[startName];
  1975. // Return the sibling if it has one
  1976. if (node !== root_node) {
  1977. sibling = node[siblingName];
  1978. if (sibling)
  1979. return sibling;
  1980. // Walk up the parents to look for siblings
  1981. for (parent = node.parent; parent && parent !== root_node; parent = parent.parent) {
  1982. sibling = parent[siblingName];
  1983. if (sibling)
  1984. return sibling;
  1985. }
  1986. }
  1987. };
  1988. function Node(name, type) {
  1989. this.name = name;
  1990. this.type = type;
  1991. if (type === 1) {
  1992. this.attributes = [];
  1993. this.attributes.map = {};
  1994. }
  1995. }
  1996. tinymce.extend(Node.prototype, {
  1997. replace : function(node) {
  1998. var self = this;
  1999. if (node.parent)
  2000. node.remove();
  2001. self.insert(node, self);
  2002. self.remove();
  2003. return self;
  2004. },
  2005. attr : function(name, value) {
  2006. var self = this, attrs, i, undef;
  2007. if (typeof name !== "string") {
  2008. for (i in name)
  2009. self.attr(i, name[i]);
  2010. return self;
  2011. }
  2012. if (attrs = self.attributes) {
  2013. if (value !== undef) {
  2014. // Remove attribute
  2015. if (value === null) {
  2016. if (name in attrs.map) {
  2017. delete attrs.map[name];
  2018. i = attrs.length;
  2019. while (i--) {
  2020. if (attrs[i].name === name) {
  2021. attrs = attrs.splice(i, 1);
  2022. return self;
  2023. }
  2024. }
  2025. }
  2026. return self;
  2027. }
  2028. // Set attribute
  2029. if (name in attrs.map) {
  2030. // Set attribute
  2031. i = attrs.length;
  2032. while (i--) {
  2033. if (attrs[i].name === name) {
  2034. attrs[i].value = value;
  2035. break;
  2036. }
  2037. }
  2038. } else
  2039. attrs.push({name: name, value: value});
  2040. attrs.map[name] = value;
  2041. return self;
  2042. } else {
  2043. return attrs.map[name];
  2044. }
  2045. }
  2046. },
  2047. clone : function() {
  2048. var self = this, clone = new Node(self.name, self.type), i, l, selfAttrs, selfAttr, cloneAttrs;
  2049. // Clone element attributes
  2050. if (selfAttrs = self.attributes) {
  2051. cloneAttrs = [];
  2052. cloneAttrs.map = {};
  2053. for (i = 0, l = selfAttrs.length; i < l; i++) {
  2054. selfAttr = selfAttrs[i];
  2055. // Clone everything except id
  2056. if (selfAttr.name !== 'id') {
  2057. cloneAttrs[cloneAttrs.length] = {name: selfAttr.name, value: selfAttr.value};
  2058. cloneAttrs.map[selfAttr.name] = selfAttr.value;
  2059. }
  2060. }
  2061. clone.attributes = cloneAttrs;
  2062. }
  2063. clone.value = self.value;
  2064. clone.shortEnded = self.shortEnded;
  2065. return clone;
  2066. },
  2067. wrap : function(wrapper) {
  2068. var self = this;
  2069. self.parent.insert(wrapper, self);
  2070. wrapper.append(self);
  2071. return self;
  2072. },
  2073. unwrap : function() {
  2074. var self = this, node, next;
  2075. for (node = self.firstChild; node; ) {
  2076. next = node.next;
  2077. self.insert(node, self, true);
  2078. node = next;
  2079. }
  2080. self.remove();
  2081. },
  2082. remove : function() {
  2083. var self = this, parent = self.parent, next = self.next, prev = self.prev;
  2084. if (parent) {
  2085. if (parent.firstChild === self) {
  2086. parent.firstChild = next;
  2087. if (next)
  2088. next.prev = null;
  2089. } else {
  2090. prev.next = next;
  2091. }
  2092. if (parent.lastChild === self) {
  2093. parent.lastChild = prev;
  2094. if (prev)
  2095. prev.next = null;
  2096. } else {
  2097. next.prev = prev;
  2098. }
  2099. self.parent = self.next = self.prev = null;
  2100. }
  2101. return self;
  2102. },
  2103. append : function(node) {
  2104. var self = this, last;
  2105. if (node.parent)
  2106. node.remove();
  2107. last = self.lastChild;
  2108. if (last) {
  2109. last.next = node;
  2110. node.prev = last;
  2111. self.lastChild = node;
  2112. } else
  2113. self.lastChild = self.firstChild = node;
  2114. node.parent = self;
  2115. return node;
  2116. },
  2117. insert : function(node, ref_node, before) {
  2118. var parent;
  2119. if (node.parent)
  2120. node.remove();
  2121. parent = ref_node.parent || this;
  2122. if (before) {
  2123. if (ref_node === parent.firstChild)
  2124. parent.firstChild = node;
  2125. else
  2126. ref_node.prev.next = node;
  2127. node.prev = ref_node.prev;
  2128. node.next = ref_node;
  2129. ref_node.prev = node;
  2130. } else {
  2131. if (ref_node === parent.lastChild)
  2132. parent.lastChild = node;
  2133. else
  2134. ref_node.next.prev = node;
  2135. node.next = ref_node.next;
  2136. node.prev = ref_node;
  2137. ref_node.next = node;
  2138. }
  2139. node.parent = parent;
  2140. return node;
  2141. },
  2142. getAll : function(name) {
  2143. var self = this, node, collection = [];
  2144. for (node = self.firstChild; node; node = walk(node, self)) {
  2145. if (node.name === name)
  2146. collection.push(node);
  2147. }
  2148. return collection;
  2149. },
  2150. empty : function() {
  2151. var self = this, nodes, i, node;
  2152. // Remove all children
  2153. if (self.firstChild) {
  2154. nodes = [];
  2155. // Collect the children
  2156. for (node = self.firstChild; node; node = walk(node, self))
  2157. nodes.push(node);
  2158. // Remove the children
  2159. i = nodes.length;
  2160. while (i--) {
  2161. node = nodes[i];
  2162. node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;
  2163. }
  2164. }
  2165. self.firstChild = self.lastChild = null;
  2166. return self;
  2167. },
  2168. isEmpty : function(elements) {
  2169. var self = this, node = self.firstChild, i, name;
  2170. if (node) {
  2171. do {
  2172. if (node.type === 1) {
  2173. // Ignore bogus elements
  2174. if (node.attributes.map['data-mce-bogus'])
  2175. continue;
  2176. // Keep empty elements like <img />
  2177. if (elements[node.name])
  2178. return false;
  2179. // Keep elements with data attributes or name attribute like <a name="1"></a>
  2180. i = node.attributes.length;
  2181. while (i--) {
  2182. name = node.attributes[i].name;
  2183. if (name === "name" || name.indexOf('data-') === 0)
  2184. return false;
  2185. }
  2186. }
  2187. // Keep non whitespace text nodes
  2188. if ((node.type === 3 && !whiteSpaceRegExp.test(node.value)))
  2189. return false;
  2190. } while (node = walk(node, self));
  2191. }
  2192. return true;
  2193. },
  2194. walk : function(prev) {
  2195. return walk(this, null, prev);
  2196. }
  2197. });
  2198. tinymce.extend(Node, {
  2199. create : function(name, attrs) {
  2200. var node, attrName;
  2201. // Create node
  2202. node = new Node(name, typeLookup[name] || 1);
  2203. // Add attributes if needed
  2204. if (attrs) {
  2205. for (attrName in attrs)
  2206. node.attr(attrName, attrs[attrName]);
  2207. }
  2208. return node;
  2209. }
  2210. });
  2211. tinymce.html.Node = Node;
  2212. })(tinymce);
  2213. (function(tinymce) {
  2214. var Node = tinymce.html.Node;
  2215. tinymce.html.DomParser = function(settings, schema) {
  2216. var self = this, nodeFilters = {}, attributeFilters = [], matchedNodes = {}, matchedAttributes = {};
  2217. settings = settings || {};
  2218. settings.validate = "validate" in settings ? settings.validate : true;
  2219. settings.root_name = settings.root_name || 'body';
  2220. self.schema = schema = schema || new tinymce.html.Schema();
  2221. function fixInvalidChildren(nodes) {
  2222. var ni, node, parent, parents, newParent, currentNode, tempNode, childNode, i,
  2223. childClone, nonEmptyElements, nonSplitableElements, sibling, nextNode;
  2224. nonSplitableElements = tinymce.makeMap('tr,td,th,tbody,thead,tfoot,table');
  2225. nonEmptyElements = schema.getNonEmptyElements();
  2226. for (ni = 0; ni < nodes.length; ni++) {
  2227. node = nodes[ni];
  2228. // Already removed
  2229. if (!node.parent)
  2230. continue;
  2231. // Get list of all parent nodes until we find a valid parent to stick the child into
  2232. parents = [node];
  2233. for (parent = node.parent; parent && !schema.isValidChild(parent.name, node.name) && !nonSplitableElements[parent.name]; parent = parent.parent)
  2234. parents.push(parent);
  2235. // Found a suitable parent
  2236. if (parent && parents.length > 1) {
  2237. // Reverse the array since it makes looping easier
  2238. parents.reverse();
  2239. // Clone the related parent and insert that after the moved node
  2240. newParent = currentNode = self.filterNode(parents[0].clone());
  2241. // Start cloning and moving children on the left side of the target node
  2242. for (i = 0; i < parents.length - 1; i++) {
  2243. if (schema.isValidChild(currentNode.name, parents[i].name)) {
  2244. tempNode = self.filterNode(parents[i].clone());
  2245. currentNode.append(tempNode);
  2246. } else
  2247. tempNode = currentNode;
  2248. for (childNode = parents[i].firstChild; childNode && childNode != parents[i + 1]; ) {
  2249. nextNode = childNode.next;
  2250. tempNode.append(childNode);
  2251. childNode = nextNode;
  2252. }
  2253. currentNode = tempNode;
  2254. }
  2255. if (!newParent.isEmpty(nonEmptyElements)) {
  2256. parent.insert(newParent, parents[0], true);
  2257. parent.insert(node, newParent);
  2258. } else {
  2259. parent.insert(node, parents[0], true);
  2260. }
  2261. // Check if the element is empty by looking through it's contents and special treatment for <p><br /></p>
  2262. parent = parents[0];
  2263. if (parent.isEmpty(nonEmptyElements) || parent.firstChild === parent.lastChild && parent.firstChild.name === 'br') {
  2264. parent.empty().remove();
  2265. }
  2266. } else if (node.parent) {
  2267. // If it's an LI try to find a UL/OL for it or wrap it
  2268. if (node.name === 'li') {
  2269. sibling = node.prev;
  2270. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  2271. sibling.append(node);
  2272. continue;
  2273. }
  2274. sibling = node.next;
  2275. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  2276. sibling.insert(node, sibling.firstChild, true);
  2277. continue;
  2278. }
  2279. node.wrap(self.filterNode(new Node('ul', 1)));
  2280. continue;
  2281. }
  2282. // Try wrapping the element in a DIV
  2283. if (schema.isValidChild(node.parent.name, 'div') && schema.isValidChild('div', node.name)) {
  2284. node.wrap(self.filterNode(new Node('div', 1)));
  2285. } else {
  2286. // We failed wrapping it, then remove or unwrap it
  2287. if (node.name === 'style' || node.name === 'script')
  2288. node.empty().remove();
  2289. else
  2290. node.unwrap();
  2291. }
  2292. }
  2293. }
  2294. };
  2295. self.filterNode = function(node) {
  2296. var i, name, list;
  2297. // Run element filters
  2298. if (name in nodeFilters) {
  2299. list = matchedNodes[name];
  2300. if (list)
  2301. list.push(node);
  2302. else
  2303. matchedNodes[name] = [node];
  2304. }
  2305. // Run attribute filters
  2306. i = attributeFilters.length;
  2307. while (i--) {
  2308. name = attributeFilters[i].name;
  2309. if (name in node.attributes.map) {
  2310. list = matchedAttributes[name];
  2311. if (list)
  2312. list.push(node);
  2313. else
  2314. matchedAttributes[name] = [node];
  2315. }
  2316. }
  2317. return node;
  2318. };
  2319. self.addNodeFilter = function(name, callback) {
  2320. tinymce.each(tinymce.explode(name), function(name) {
  2321. var list = nodeFilters[name];
  2322. if (!list)
  2323. nodeFilters[name] = list = [];
  2324. list.push(callback);
  2325. });
  2326. };
  2327. self.addAttributeFilter = function(name, callback) {
  2328. tinymce.each(tinymce.explode(name), function(name) {
  2329. var i;
  2330. for (i = 0; i < attributeFilters.length; i++) {
  2331. if (attributeFilters[i].name === name) {
  2332. attributeFilters[i].callbacks.push(callback);
  2333. return;
  2334. }
  2335. }
  2336. attributeFilters.push({name: name, callbacks: [callback]});
  2337. });
  2338. };
  2339. self.parse = function(html, args) {
  2340. var parser, rootNode, node, nodes, i, l, fi, fl, list, name, validate,
  2341. blockElements, startWhiteSpaceRegExp, invalidChildren = [],
  2342. endWhiteSpaceRegExp, allWhiteSpaceRegExp, whiteSpaceElements, children, nonEmptyElements, rootBlockName;
  2343. args = args || {};
  2344. matchedNodes = {};
  2345. matchedAttributes = {};
  2346. blockElements = tinymce.extend(tinymce.makeMap('script,style,head,html,body,title,meta,param'), schema.getBlockElements());
  2347. nonEmptyElements = schema.getNonEmptyElements();
  2348. children = schema.children;
  2349. validate = settings.validate;
  2350. rootBlockName = "forced_root_block" in args ? args.forced_root_block : settings.forced_root_block;
  2351. whiteSpaceElements = schema.getWhiteSpaceElements();
  2352. startWhiteSpaceRegExp = /^[ \t\r\n]+/;
  2353. endWhiteSpaceRegExp = /[ \t\r\n]+$/;
  2354. allWhiteSpaceRegExp = /[ \t\r\n]+/g;
  2355. function addRootBlocks() {
  2356. var node = rootNode.firstChild, next, rootBlockNode;
  2357. while (node) {
  2358. next = node.next;
  2359. if (node.type == 3 || (node.type == 1 && node.name !== 'p' && !blockElements[node.name] && !node.attr('data-mce-type'))) {
  2360. if (!rootBlockNode) {
  2361. // Create a new root block element
  2362. rootBlockNode = createNode(rootBlockName, 1);
  2363. rootNode.insert(rootBlockNode, node);
  2364. rootBlockNode.append(node);
  2365. } else
  2366. rootBlockNode.append(node);
  2367. } else {
  2368. rootBlockNode = null;
  2369. }
  2370. node = next;
  2371. };
  2372. };
  2373. function createNode(name, type) {
  2374. var node = new Node(name, type), list;
  2375. if (name in nodeFilters) {
  2376. list = matchedNodes[name];
  2377. if (list)
  2378. list.push(node);
  2379. else
  2380. matchedNodes[name] = [node];
  2381. }
  2382. return node;
  2383. };
  2384. function removeWhitespaceBefore(node) {
  2385. var textNode, textVal, sibling;
  2386. for (textNode = node.prev; textNode && textNode.type === 3; ) {
  2387. textVal = textNode.value.replace(endWhiteSpaceRegExp, '');
  2388. if (textVal.length > 0) {
  2389. textNode.value = textVal;
  2390. textNode = textNode.prev;
  2391. } else {
  2392. sibling = textNode.prev;
  2393. textNode.remove();
  2394. textNode = sibling;
  2395. }
  2396. }
  2397. };
  2398. parser = new tinymce.html.SaxParser({
  2399. validate : validate,
  2400. fix_self_closing : !validate, // Let the DOM parser handle <li> in <li> or <p> in <p> for better results
  2401. cdata: function(text) {
  2402. node.append(createNode('#cdata', 4)).value = text;
  2403. },
  2404. text: function(text, raw) {
  2405. var textNode;
  2406. // Trim all redundant whitespace on non white space elements
  2407. if (!whiteSpaceElements[node.name]) {
  2408. text = text.replace(allWhiteSpaceRegExp, ' ');
  2409. if (node.lastChild && blockElements[node.lastChild.name])
  2410. text = text.replace(startWhiteSpaceRegExp, '');
  2411. }
  2412. // Do we need to create the node
  2413. if (text.length !== 0) {
  2414. textNode = createNode('#text', 3);
  2415. textNode.raw = !!raw;
  2416. node.append(textNode).value = text;
  2417. }
  2418. },
  2419. comment: function(text) {
  2420. node.append(createNode('#comment', 8)).value = text;
  2421. },
  2422. pi: function(name, text) {
  2423. node.append(createNode(name, 7)).value = text;
  2424. removeWhitespaceBefore(node);
  2425. },
  2426. doctype: function(text) {
  2427. var newNode;
  2428. newNode = node.append(createNode('#doctype', 10));
  2429. newNode.value = text;
  2430. removeWhitespaceBefore(node);
  2431. },
  2432. start: function(name, attrs, empty) {
  2433. var newNode, attrFiltersLen, elementRule, textNode, attrName, text, sibling, parent;
  2434. elementRule = validate ? schema.getElementRule(name) : {};
  2435. if (elementRule) {
  2436. newNode = createNode(elementRule.outputName || name, 1);
  2437. newNode.attributes = attrs;
  2438. newNode.shortEnded = empty;
  2439. node.append(newNode);
  2440. // Check if node is valid child of the parent node is the child is
  2441. // unknown we don't collect it since it's probably a custom element
  2442. parent = children[node.name];
  2443. if (parent && children[newNode.name] && !parent[newNode.name])
  2444. invalidChildren.push(newNode);
  2445. attrFiltersLen = attributeFilters.length;
  2446. while (attrFiltersLen--) {
  2447. attrName = attributeFilters[attrFiltersLen].name;
  2448. if (attrName in attrs.map) {
  2449. list = matchedAttributes[attrName];
  2450. if (list)
  2451. list.push(newNode);
  2452. else
  2453. matchedAttributes[attrName] = [newNode];
  2454. }
  2455. }
  2456. // Trim whitespace before block
  2457. if (blockElements[name])
  2458. removeWhitespaceBefore(newNode);
  2459. // Change current node if the element wasn't empty i.e not <br /> or <img />
  2460. if (!empty)
  2461. node = newNode;
  2462. }
  2463. },
  2464. end: function(name) {
  2465. var textNode, elementRule, text, sibling, tempNode;
  2466. elementRule = validate ? schema.getElementRule(name) : {};
  2467. if (elementRule) {
  2468. if (blockElements[name]) {
  2469. if (!whiteSpaceElements[node.name]) {
  2470. // Trim whitespace at beginning of block
  2471. for (textNode = node.firstChild; textNode && textNode.type === 3; ) {
  2472. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  2473. if (text.length > 0) {
  2474. textNode.value = text;
  2475. textNode = textNode.next;
  2476. } else {
  2477. sibling = textNode.next;
  2478. textNode.remove();
  2479. textNode = sibling;
  2480. }
  2481. }
  2482. // Trim whitespace at end of block
  2483. for (textNode = node.lastChild; textNode && textNode.type === 3; ) {
  2484. text = textNode.value.replace(endWhiteSpaceRegExp, '');
  2485. if (text.length > 0) {
  2486. textNode.value = text;
  2487. textNode = textNode.prev;
  2488. } else {
  2489. sibling = textNode.prev;
  2490. textNode.remove();
  2491. textNode = sibling;
  2492. }
  2493. }
  2494. }
  2495. // Trim start white space
  2496. textNode = node.prev;
  2497. if (textNode && textNode.type === 3) {
  2498. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  2499. if (text.length > 0)
  2500. textNode.value = text;
  2501. else
  2502. textNode.remove();
  2503. }
  2504. }
  2505. // Handle empty nodes
  2506. if (elementRule.removeEmpty || elementRule.paddEmpty) {
  2507. if (node.isEmpty(nonEmptyElements)) {
  2508. if (elementRule.paddEmpty)
  2509. node.empty().append(new Node('#text', '3')).value = '\u00a0';
  2510. else {
  2511. // Leave nodes that have a name like <a name="name">
  2512. if (!node.attributes.map.name) {
  2513. tempNode = node.parent;
  2514. node.empty().remove();
  2515. node = tempNode;
  2516. return;
  2517. }
  2518. }
  2519. }
  2520. }
  2521. node = node.parent;
  2522. }
  2523. }
  2524. }, schema);
  2525. rootNode = node = new Node(args.context || settings.root_name, 11);
  2526. parser.parse(html);
  2527. // Fix invalid children or report invalid children in a contextual parsing
  2528. if (validate && invalidChildren.length) {
  2529. if (!args.context)
  2530. fixInvalidChildren(invalidChildren);
  2531. else
  2532. args.invalid = true;
  2533. }
  2534. // Wrap nodes in the root into block elements if the root is body
  2535. if (rootBlockName && rootNode.name == 'body')
  2536. addRootBlocks();
  2537. // Run filters only when the contents is valid
  2538. if (!args.invalid) {
  2539. // Run node filters
  2540. for (name in matchedNodes) {
  2541. list = nodeFilters[name];
  2542. nodes = matchedNodes[name];
  2543. // Remove already removed children
  2544. fi = nodes.length;
  2545. while (fi--) {
  2546. if (!nodes[fi].parent)
  2547. nodes.splice(fi, 1);
  2548. }
  2549. for (i = 0, l = list.length; i < l; i++)
  2550. list[i](nodes, name, args);
  2551. }
  2552. // Run attribute filters
  2553. for (i = 0, l = attributeFilters.length; i < l; i++) {
  2554. list = attributeFilters[i];
  2555. if (list.name in matchedAttributes) {
  2556. nodes = matchedAttributes[list.name];
  2557. // Remove already removed children
  2558. fi = nodes.length;
  2559. while (fi--) {
  2560. if (!nodes[fi].parent)
  2561. nodes.splice(fi, 1);
  2562. }
  2563. for (fi = 0, fl = list.callbacks.length; fi < fl; fi++)
  2564. list.callbacks[fi](nodes, list.name, args);
  2565. }
  2566. }
  2567. }
  2568. return rootNode;
  2569. };
  2570. // Remove <br> at end of block elements Gecko and WebKit injects BR elements to
  2571. // make it possible to place the caret inside empty blocks. This logic tries to remove
  2572. // these elements and keep br elements that where intended to be there intact
  2573. if (settings.remove_trailing_brs) {
  2574. self.addNodeFilter('br', function(nodes, name) {
  2575. var i, l = nodes.length, node, blockElements = schema.getBlockElements(),
  2576. nonEmptyElements = schema.getNonEmptyElements(), parent, prev, prevName;
  2577. // Remove brs from body element as well
  2578. blockElements.body = 1;
  2579. // Must loop forwards since it will otherwise remove all brs in <p>a<br><br><br></p>
  2580. for (i = 0; i < l; i++) {
  2581. node = nodes[i];
  2582. parent = node.parent;
  2583. if (blockElements[node.parent.name] && node === parent.lastChild) {
  2584. // Loop all nodes to the right of the current node and check for other BR elements
  2585. // excluding bookmarks since they are invisible
  2586. prev = node.prev;
  2587. while (prev) {
  2588. prevName = prev.name;
  2589. // Ignore bookmarks
  2590. if (prevName !== "span" || prev.attr('data-mce-type') !== 'bookmark') {
  2591. // Found a non BR element
  2592. if (prevName !== "br")
  2593. break;
  2594. // Found another br it's a <br><br> structure then don't remove anything
  2595. if (prevName === 'br') {
  2596. node = null;
  2597. break;
  2598. }
  2599. }
  2600. prev = prev.prev;
  2601. }
  2602. if (node) {
  2603. node.remove();
  2604. // Is the parent to be considered empty after we removed the BR
  2605. if (parent.isEmpty(nonEmptyElements)) {
  2606. elementRule = schema.getElementRule(parent.name);
  2607. // Remove or padd the element depending on schema rule
  2608. if (elementRule) {
  2609. if (elementRule.removeEmpty)
  2610. parent.remove();
  2611. else if (elementRule.paddEmpty)
  2612. parent.empty().append(new tinymce.html.Node('#text', 3)).value = '\u00a0';
  2613. }
  2614. }
  2615. }
  2616. }
  2617. }
  2618. });
  2619. }
  2620. }
  2621. })(tinymce);
  2622. tinymce.html.Writer = function(settings) {
  2623. var html = [], indent, indentBefore, indentAfter, encode, htmlOutput;
  2624. settings = settings || {};
  2625. indent = settings.indent;
  2626. indentBefore = tinymce.makeMap(settings.indent_before || '');
  2627. indentAfter = tinymce.makeMap(settings.indent_after || '');
  2628. encode = tinymce.html.Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
  2629. htmlOutput = settings.element_format == "html";
  2630. return {
  2631. start: function(name, attrs, empty) {
  2632. var i, l, attr, value;
  2633. if (indent && indentBefore[name] && html.length > 0) {
  2634. value = html[html.length - 1];
  2635. if (value.length > 0 && value !== '\n')
  2636. html.push('\n');
  2637. }
  2638. html.push('<', name);
  2639. if (attrs) {
  2640. for (i = 0, l = attrs.length; i < l; i++) {
  2641. attr = attrs[i];
  2642. html.push(' ', attr.name, '="', encode(attr.value, true), '"');
  2643. }
  2644. }
  2645. if (!empty || htmlOutput)
  2646. html[html.length] = '>';
  2647. else
  2648. html[html.length] = ' />';
  2649. if (empty && indent && indentAfter[name] && html.length > 0) {
  2650. value = html[html.length - 1];
  2651. if (value.length > 0 && value !== '\n')
  2652. html.push('\n');
  2653. }
  2654. },
  2655. end: function(name) {
  2656. var value;
  2657. /*if (indent && indentBefore[name] && html.length > 0) {
  2658. value = html[html.length - 1];
  2659. if (value.length > 0 && value !== '\n')
  2660. html.push('\n');
  2661. }*/
  2662. html.push('</', name, '>');
  2663. if (indent && indentAfter[name] && html.length > 0) {
  2664. value = html[html.length - 1];
  2665. if (value.length > 0 && value !== '\n')
  2666. html.push('\n');
  2667. }
  2668. },
  2669. text: function(text, raw) {
  2670. if (text.length > 0)
  2671. html[html.length] = raw ? text : encode(text);
  2672. },
  2673. cdata: function(text) {
  2674. html.push('<![CDATA[', text, ']]>');
  2675. },
  2676. comment: function(text) {
  2677. html.push('<!--', text, '-->');
  2678. },
  2679. pi: function(name, text) {
  2680. if (text)
  2681. html.push('<?', name, ' ', text, '?>');
  2682. else
  2683. html.push('<?', name, '?>');
  2684. if (indent)
  2685. html.push('\n');
  2686. },
  2687. doctype: function(text) {
  2688. html.push('<!DOCTYPE', text, '>', indent ? '\n' : '');
  2689. },
  2690. reset: function() {
  2691. html.length = 0;
  2692. },
  2693. getContent: function() {
  2694. return html.join('').replace(/\n$/, '');
  2695. }
  2696. };
  2697. };
  2698. (function(tinymce) {
  2699. tinymce.html.Serializer = function(settings, schema) {
  2700. var self = this, writer = new tinymce.html.Writer(settings);
  2701. settings = settings || {};
  2702. settings.validate = "validate" in settings ? settings.validate : true;
  2703. self.schema = schema = schema || new tinymce.html.Schema();
  2704. self.writer = writer;
  2705. self.serialize = function(node) {
  2706. var handlers, validate;
  2707. validate = settings.validate;
  2708. handlers = {
  2709. // #text
  2710. 3: function(node, raw) {
  2711. writer.text(node.value, node.raw);
  2712. },
  2713. // #comment
  2714. 8: function(node) {
  2715. writer.comment(node.value);
  2716. },
  2717. // Processing instruction
  2718. 7: function(node) {
  2719. writer.pi(node.name, node.value);
  2720. },
  2721. // Doctype
  2722. 10: function(node) {
  2723. writer.doctype(node.value);
  2724. },
  2725. // CDATA
  2726. 4: function(node) {
  2727. writer.cdata(node.value);
  2728. },
  2729. // Document fragment
  2730. 11: function(node) {
  2731. if ((node = node.firstChild)) {
  2732. do {
  2733. walk(node);
  2734. } while (node = node.next);
  2735. }
  2736. }
  2737. };
  2738. writer.reset();
  2739. function walk(node) {
  2740. var handler = handlers[node.type], name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule;
  2741. if (!handler) {
  2742. name = node.name;
  2743. isEmpty = node.shortEnded;
  2744. attrs = node.attributes;
  2745. // Sort attributes
  2746. if (validate && attrs && attrs.length > 1) {
  2747. sortedAttrs = [];
  2748. sortedAttrs.map = {};
  2749. elementRule = schema.getElementRule(node.name);
  2750. for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
  2751. attrName = elementRule.attributesOrder[i];
  2752. if (attrName in attrs.map) {
  2753. attrValue = attrs.map[attrName];
  2754. sortedAttrs.map[attrName] = attrValue;
  2755. sortedAttrs.push({name: attrName, value: attrValue});
  2756. }
  2757. }
  2758. for (i = 0, l = attrs.length; i < l; i++) {
  2759. attrName = attrs[i].name;
  2760. if (!(attrName in sortedAttrs.map)) {
  2761. attrValue = attrs.map[attrName];
  2762. sortedAttrs.map[attrName] = attrValue;
  2763. sortedAttrs.push({name: attrName, value: attrValue});
  2764. }
  2765. }
  2766. attrs = sortedAttrs;
  2767. }
  2768. writer.start(node.name, attrs, isEmpty);
  2769. if (!isEmpty) {
  2770. if ((node = node.firstChild)) {
  2771. do {
  2772. walk(node);
  2773. } while (node = node.next);
  2774. }
  2775. writer.end(name);
  2776. }
  2777. } else
  2778. handler(node);
  2779. }
  2780. // Serialize element and treat all non elements as fragments
  2781. if (node.type == 1 && !settings.inner)
  2782. walk(node);
  2783. else
  2784. handlers[11](node);
  2785. return writer.getContent();
  2786. };
  2787. }
  2788. })(tinymce);
  2789. (function(tinymce) {
  2790. // Shorten names
  2791. var each = tinymce.each,
  2792. is = tinymce.is,
  2793. isWebKit = tinymce.isWebKit,
  2794. isIE = tinymce.isIE,
  2795. Entities = tinymce.html.Entities,
  2796. simpleSelectorRe = /^([a-z0-9],?)+$/i,
  2797. blockElementsMap = tinymce.html.Schema.blockElementsMap,
  2798. whiteSpaceRegExp = /^[ \t\r\n]*$/;
  2799. tinymce.create('tinymce.dom.DOMUtils', {
  2800. doc : null,
  2801. root : null,
  2802. files : null,
  2803. pixelStyles : /^(top|left|bottom|right|width|height|borderWidth)$/,
  2804. props : {
  2805. "for" : "htmlFor",
  2806. "class" : "className",
  2807. className : "className",
  2808. checked : "checked",
  2809. disabled : "disabled",
  2810. maxlength : "maxLength",
  2811. readonly : "readOnly",
  2812. selected : "selected",
  2813. value : "value",
  2814. id : "id",
  2815. name : "name",
  2816. type : "type"
  2817. },
  2818. DOMUtils : function(d, s) {
  2819. var t = this, globalStyle, name;
  2820. t.doc = d;
  2821. t.win = window;
  2822. t.files = {};
  2823. t.cssFlicker = false;
  2824. t.counter = 0;
  2825. t.stdMode = !tinymce.isIE || d.documentMode >= 8;
  2826. t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat" || t.stdMode;
  2827. t.hasOuterHTML = "outerHTML" in d.createElement("a");
  2828. t.settings = s = tinymce.extend({
  2829. keep_values : false,
  2830. hex_colors : 1
  2831. }, s);
  2832. t.schema = s.schema;
  2833. t.styles = new tinymce.html.Styles({
  2834. url_converter : s.url_converter,
  2835. url_converter_scope : s.url_converter_scope
  2836. }, s.schema);
  2837. // Fix IE6SP2 flicker and check it failed for pre SP2
  2838. if (tinymce.isIE6) {
  2839. try {
  2840. d.execCommand('BackgroundImageCache', false, true);
  2841. } catch (e) {
  2842. t.cssFlicker = true;
  2843. }
  2844. }
  2845. if (isIE && s.schema) {
  2846. // Add missing HTML 4/5 elements to IE
  2847. ('abbr article aside audio canvas ' +
  2848. 'details figcaption figure footer ' +
  2849. 'header hgroup mark menu meter nav ' +
  2850. 'output progress section summary ' +
  2851. 'time video').replace(/\w+/g, function(name) {
  2852. d.createElement(name);
  2853. });
  2854. // Create all custom elements
  2855. for (name in s.schema.getCustomElements()) {
  2856. d.createElement(name);
  2857. }
  2858. }
  2859. tinymce.addUnload(t.destroy, t);
  2860. },
  2861. getRoot : function() {
  2862. var t = this, s = t.settings;
  2863. return (s && t.get(s.root_element)) || t.doc.body;
  2864. },
  2865. getViewPort : function(w) {
  2866. var d, b;
  2867. w = !w ? this.win : w;
  2868. d = w.document;
  2869. b = this.boxModel ? d.documentElement : d.body;
  2870. // Returns viewport size excluding scrollbars
  2871. return {
  2872. x : w.pageXOffset || b.scrollLeft,
  2873. y : w.pageYOffset || b.scrollTop,
  2874. w : w.innerWidth || b.clientWidth,
  2875. h : w.innerHeight || b.clientHeight
  2876. };
  2877. },
  2878. getRect : function(e) {
  2879. var p, t = this, sr;
  2880. e = t.get(e);
  2881. p = t.getPos(e);
  2882. sr = t.getSize(e);
  2883. return {
  2884. x : p.x,
  2885. y : p.y,
  2886. w : sr.w,
  2887. h : sr.h
  2888. };
  2889. },
  2890. getSize : function(e) {
  2891. var t = this, w, h;
  2892. e = t.get(e);
  2893. w = t.getStyle(e, 'width');
  2894. h = t.getStyle(e, 'height');
  2895. // Non pixel value, then force offset/clientWidth
  2896. if (w.indexOf('px') === -1)
  2897. w = 0;
  2898. // Non pixel value, then force offset/clientWidth
  2899. if (h.indexOf('px') === -1)
  2900. h = 0;
  2901. return {
  2902. w : parseInt(w) || e.offsetWidth || e.clientWidth,
  2903. h : parseInt(h) || e.offsetHeight || e.clientHeight
  2904. };
  2905. },
  2906. getParent : function(n, f, r) {
  2907. return this.getParents(n, f, r, false);
  2908. },
  2909. getParents : function(n, f, r, c) {
  2910. var t = this, na, se = t.settings, o = [];
  2911. n = t.get(n);
  2912. c = c === undefined;
  2913. if (se.strict_root)
  2914. r = r || t.getRoot();
  2915. // Wrap node name as func
  2916. if (is(f, 'string')) {
  2917. na = f;
  2918. if (f === '*') {
  2919. f = function(n) {return n.nodeType == 1;};
  2920. } else {
  2921. f = function(n) {
  2922. return t.is(n, na);
  2923. };
  2924. }
  2925. }
  2926. while (n) {
  2927. if (n == r || !n.nodeType || n.nodeType === 9)
  2928. break;
  2929. if (!f || f(n)) {
  2930. if (c)
  2931. o.push(n);
  2932. else
  2933. return n;
  2934. }
  2935. n = n.parentNode;
  2936. }
  2937. return c ? o : null;
  2938. },
  2939. get : function(e) {
  2940. var n;
  2941. if (e && this.doc && typeof(e) == 'string') {
  2942. n = e;
  2943. e = this.doc.getElementById(e);
  2944. // IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick
  2945. if (e && e.id !== n)
  2946. return this.doc.getElementsByName(n)[1];
  2947. }
  2948. return e;
  2949. },
  2950. getNext : function(node, selector) {
  2951. return this._findSib(node, selector, 'nextSibling');
  2952. },
  2953. getPrev : function(node, selector) {
  2954. return this._findSib(node, selector, 'previousSibling');
  2955. },
  2956. select : function(pa, s) {
  2957. var t = this;
  2958. return tinymce.dom.Sizzle(pa, t.get(s) || t.get(t.settings.root_element) || t.doc, []);
  2959. },
  2960. is : function(n, selector) {
  2961. var i;
  2962. // If it isn't an array then try to do some simple selectors instead of Sizzle for to boost performance
  2963. if (n.length === undefined) {
  2964. // Simple all selector
  2965. if (selector === '*')
  2966. return n.nodeType == 1;
  2967. // Simple selector just elements
  2968. if (simpleSelectorRe.test(selector)) {
  2969. selector = selector.toLowerCase().split(/,/);
  2970. n = n.nodeName.toLowerCase();
  2971. for (i = selector.length - 1; i >= 0; i--) {
  2972. if (selector[i] == n)
  2973. return true;
  2974. }
  2975. return false;
  2976. }
  2977. }
  2978. return tinymce.dom.Sizzle.matches(selector, n.nodeType ? [n] : n).length > 0;
  2979. },
  2980. add : function(p, n, a, h, c) {
  2981. var t = this;
  2982. return this.run(p, function(p) {
  2983. var e, k;
  2984. e = is(n, 'string') ? t.doc.createElement(n) : n;
  2985. t.setAttribs(e, a);
  2986. if (h) {
  2987. if (h.nodeType)
  2988. e.appendChild(h);
  2989. else
  2990. t.setHTML(e, h);
  2991. }
  2992. return !c ? p.appendChild(e) : e;
  2993. });
  2994. },
  2995. create : function(n, a, h) {
  2996. return this.add(this.doc.createElement(n), n, a, h, 1);
  2997. },
  2998. createHTML : function(n, a, h) {
  2999. var o = '', t = this, k;
  3000. o += '<' + n;
  3001. for (k in a) {
  3002. if (a.hasOwnProperty(k))
  3003. o += ' ' + k + '="' + t.encode(a[k]) + '"';
  3004. }
  3005. // A call to tinymce.is doesn't work for some odd reason on IE9 possible bug inside their JS runtime
  3006. if (typeof(h) != "undefined")
  3007. return o + '>' + h + '</' + n + '>';
  3008. return o + ' />';
  3009. },
  3010. remove : function(node, keep_children) {
  3011. return this.run(node, function(node) {
  3012. var child, parent = node.parentNode;
  3013. if (!parent)
  3014. return null;
  3015. if (keep_children) {
  3016. while (child = node.firstChild) {
  3017. // IE 8 will crash if you don't remove completely empty text nodes
  3018. if (!tinymce.isIE || child.nodeType !== 3 || child.nodeValue)
  3019. parent.insertBefore(child, node);
  3020. else
  3021. node.removeChild(child);
  3022. }
  3023. }
  3024. return parent.removeChild(node);
  3025. });
  3026. },
  3027. setStyle : function(n, na, v) {
  3028. var t = this;
  3029. return t.run(n, function(e) {
  3030. var s, i;
  3031. s = e.style;
  3032. // Camelcase it, if needed
  3033. na = na.replace(/-(\D)/g, function(a, b){
  3034. return b.toUpperCase();
  3035. });
  3036. // Default px suffix on these
  3037. if (t.pixelStyles.test(na) && (tinymce.is(v, 'number') || /^[\-0-9\.]+$/.test(v)))
  3038. v += 'px';
  3039. switch (na) {
  3040. case 'opacity':
  3041. // IE specific opacity
  3042. if (isIE) {
  3043. s.filter = v === '' ? '' : "alpha(opacity=" + (v * 100) + ")";
  3044. if (!n.currentStyle || !n.currentStyle.hasLayout)
  3045. s.display = 'inline-block';
  3046. }
  3047. // Fix for older browsers
  3048. s[na] = s['-moz-opacity'] = s['-khtml-opacity'] = v || '';
  3049. break;
  3050. case 'float':
  3051. isIE ? s.styleFloat = v : s.cssFloat = v;
  3052. break;
  3053. default:
  3054. s[na] = v || '';
  3055. }
  3056. // Force update of the style data
  3057. if (t.settings.update_styles)
  3058. t.setAttrib(e, 'data-mce-style');
  3059. });
  3060. },
  3061. getStyle : function(n, na, c) {
  3062. n = this.get(n);
  3063. if (!n)
  3064. return;
  3065. // Gecko
  3066. if (this.doc.defaultView && c) {
  3067. // Remove camelcase
  3068. na = na.replace(/[A-Z]/g, function(a){
  3069. return '-' + a;
  3070. });
  3071. try {
  3072. return this.doc.defaultView.getComputedStyle(n, null).getPropertyValue(na);
  3073. } catch (ex) {
  3074. // Old safari might fail
  3075. return null;
  3076. }
  3077. }
  3078. // Camelcase it, if needed
  3079. na = na.replace(/-(\D)/g, function(a, b){
  3080. return b.toUpperCase();
  3081. });
  3082. if (na == 'float')
  3083. na = isIE ? 'styleFloat' : 'cssFloat';
  3084. // IE & Opera
  3085. if (n.currentStyle && c)
  3086. return n.currentStyle[na];
  3087. return n.style ? n.style[na] : undefined;
  3088. },
  3089. setStyles : function(e, o) {
  3090. var t = this, s = t.settings, ol;
  3091. ol = s.update_styles;
  3092. s.update_styles = 0;
  3093. each(o, function(v, n) {
  3094. t.setStyle(e, n, v);
  3095. });
  3096. // Update style info
  3097. s.update_styles = ol;
  3098. if (s.update_styles)
  3099. t.setAttrib(e, s.cssText);
  3100. },
  3101. removeAllAttribs: function(e) {
  3102. return this.run(e, function(e) {
  3103. var i, attrs = e.attributes;
  3104. for (i = attrs.length - 1; i >= 0; i--) {
  3105. e.removeAttributeNode(attrs.item(i));
  3106. }
  3107. });
  3108. },
  3109. setAttrib : function(e, n, v) {
  3110. var t = this;
  3111. // Whats the point
  3112. if (!e || !n)
  3113. return;
  3114. // Strict XML mode
  3115. if (t.settings.strict)
  3116. n = n.toLowerCase();
  3117. return this.run(e, function(e) {
  3118. var s = t.settings;
  3119. if (v !== null) {
  3120. switch (n) {
  3121. case "style":
  3122. if (!is(v, 'string')) {
  3123. each(v, function(v, n) {
  3124. t.setStyle(e, n, v);
  3125. });
  3126. return;
  3127. }
  3128. // No mce_style for elements with these since they might get resized by the user
  3129. if (s.keep_values) {
  3130. if (v && !t._isRes(v))
  3131. e.setAttribute('data-mce-style', v, 2);
  3132. else
  3133. e.removeAttribute('data-mce-style', 2);
  3134. }
  3135. e.style.cssText = v;
  3136. break;
  3137. case "class":
  3138. e.className = v || ''; // Fix IE null bug
  3139. break;
  3140. case "src":
  3141. case "href":
  3142. if (s.keep_values) {
  3143. if (s.url_converter)
  3144. v = s.url_converter.call(s.url_converter_scope || t, v, n, e);
  3145. t.setAttrib(e, 'data-mce-' + n, v, 2);
  3146. }
  3147. break;
  3148. case "shape":
  3149. e.setAttribute('data-mce-style', v);
  3150. break;
  3151. }
  3152. }
  3153. if (is(v) && v !== null && v.length !== 0)
  3154. e.setAttribute(n, '' + v, 2);
  3155. else
  3156. e.removeAttribute(n, 2);
  3157. });
  3158. },
  3159. setAttribs : function(e, o) {
  3160. var t = this;
  3161. return this.run(e, function(e) {
  3162. each(o, function(v, n) {
  3163. t.setAttrib(e, n, v);
  3164. });
  3165. });
  3166. },
  3167. getAttrib : function(e, n, dv) {
  3168. var v, t = this, undef;
  3169. e = t.get(e);
  3170. if (!e || e.nodeType !== 1)
  3171. return dv === undef ? false : dv;
  3172. if (!is(dv))
  3173. dv = '';
  3174. // Try the mce variant for these
  3175. if (/^(src|href|style|coords|shape)$/.test(n)) {
  3176. v = e.getAttribute("data-mce-" + n);
  3177. if (v)
  3178. return v;
  3179. }
  3180. if (isIE && t.props[n]) {
  3181. v = e[t.props[n]];
  3182. v = v && v.nodeValue ? v.nodeValue : v;
  3183. }
  3184. if (!v)
  3185. v = e.getAttribute(n, 2);
  3186. // Check boolean attribs
  3187. if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(n)) {
  3188. if (e[t.props[n]] === true && v === '')
  3189. return n;
  3190. return v ? n : '';
  3191. }
  3192. // Inner input elements will override attributes on form elements
  3193. if (e.nodeName === "FORM" && e.getAttributeNode(n))
  3194. return e.getAttributeNode(n).nodeValue;
  3195. if (n === 'style') {
  3196. v = v || e.style.cssText;
  3197. if (v) {
  3198. v = t.serializeStyle(t.parseStyle(v), e.nodeName);
  3199. if (t.settings.keep_values && !t._isRes(v))
  3200. e.setAttribute('data-mce-style', v);
  3201. }
  3202. }
  3203. // Remove Apple and WebKit stuff
  3204. if (isWebKit && n === "class" && v)
  3205. v = v.replace(/(apple|webkit)\-[a-z\-]+/gi, '');
  3206. // Handle IE issues
  3207. if (isIE) {
  3208. switch (n) {
  3209. case 'rowspan':
  3210. case 'colspan':
  3211. // IE returns 1 as default value
  3212. if (v === 1)
  3213. v = '';
  3214. break;
  3215. case 'size':
  3216. // IE returns +0 as default value for size
  3217. if (v === '+0' || v === 20 || v === 0)
  3218. v = '';
  3219. break;
  3220. case 'width':
  3221. case 'height':
  3222. case 'vspace':
  3223. case 'checked':
  3224. case 'disabled':
  3225. case 'readonly':
  3226. if (v === 0)
  3227. v = '';
  3228. break;
  3229. case 'hspace':
  3230. // IE returns -1 as default value
  3231. if (v === -1)
  3232. v = '';
  3233. break;
  3234. case 'maxlength':
  3235. case 'tabindex':
  3236. // IE returns default value
  3237. if (v === 32768 || v === 2147483647 || v === '32768')
  3238. v = '';
  3239. break;
  3240. case 'multiple':
  3241. case 'compact':
  3242. case 'noshade':
  3243. case 'nowrap':
  3244. if (v === 65535)
  3245. return n;
  3246. return dv;
  3247. case 'shape':
  3248. v = v.toLowerCase();
  3249. break;
  3250. default:
  3251. // IE has odd anonymous function for event attributes
  3252. if (n.indexOf('on') === 0 && v)
  3253. v = tinymce._replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1', '' + v);
  3254. }
  3255. }
  3256. return (v !== undef && v !== null && v !== '') ? '' + v : dv;
  3257. },
  3258. getPos : function(n, ro) {
  3259. var t = this, x = 0, y = 0, e, d = t.doc, r;
  3260. n = t.get(n);
  3261. ro = ro || d.body;
  3262. if (n) {
  3263. // Use getBoundingClientRect if it exists since it's faster than looping offset nodes
  3264. if (n.getBoundingClientRect) {
  3265. n = n.getBoundingClientRect();
  3266. e = t.boxModel ? d.documentElement : d.body;
  3267. // Add scroll offsets from documentElement or body since IE with the wrong box model will use d.body and so do WebKit
  3268. // Also remove the body/documentelement clientTop/clientLeft on IE 6, 7 since they offset the position
  3269. x = n.left + (d.documentElement.scrollLeft || d.body.scrollLeft) - e.clientTop;
  3270. y = n.top + (d.documentElement.scrollTop || d.body.scrollTop) - e.clientLeft;
  3271. return {x : x, y : y};
  3272. }
  3273. r = n;
  3274. while (r && r != ro && r.nodeType) {
  3275. x += r.offsetLeft || 0;
  3276. y += r.offsetTop || 0;
  3277. r = r.offsetParent;
  3278. }
  3279. r = n.parentNode;
  3280. while (r && r != ro && r.nodeType) {
  3281. x -= r.scrollLeft || 0;
  3282. y -= r.scrollTop || 0;
  3283. r = r.parentNode;
  3284. }
  3285. }
  3286. return {x : x, y : y};
  3287. },
  3288. parseStyle : function(st) {
  3289. return this.styles.parse(st);
  3290. },
  3291. serializeStyle : function(o, name) {
  3292. return this.styles.serialize(o, name);
  3293. },
  3294. loadCSS : function(u) {
  3295. var t = this, d = t.doc, head;
  3296. if (!u)
  3297. u = '';
  3298. head = t.select('head')[0];
  3299. each(u.split(','), function(u) {
  3300. var link;
  3301. if (t.files[u])
  3302. return;
  3303. t.files[u] = true;
  3304. link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)});
  3305. // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug
  3306. // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading
  3307. // It's ugly but it seems to work fine.
  3308. if (isIE && d.documentMode && d.recalc) {
  3309. link.onload = function() {
  3310. if (d.recalc)
  3311. d.recalc();
  3312. link.onload = null;
  3313. };
  3314. }
  3315. head.appendChild(link);
  3316. });
  3317. },
  3318. addClass : function(e, c) {
  3319. return this.run(e, function(e) {
  3320. var o;
  3321. if (!c)
  3322. return 0;
  3323. if (this.hasClass(e, c))
  3324. return e.className;
  3325. o = this.removeClass(e, c);
  3326. return e.className = (o != '' ? (o + ' ') : '') + c;
  3327. });
  3328. },
  3329. removeClass : function(e, c) {
  3330. var t = this, re;
  3331. return t.run(e, function(e) {
  3332. var v;
  3333. if (t.hasClass(e, c)) {
  3334. if (!re)
  3335. re = new RegExp("(^|\\s+)" + c + "(\\s+|$)", "g");
  3336. v = e.className.replace(re, ' ');
  3337. v = tinymce.trim(v != ' ' ? v : '');
  3338. e.className = v;
  3339. // Empty class attr
  3340. if (!v) {
  3341. e.removeAttribute('class');
  3342. e.removeAttribute('className');
  3343. }
  3344. return v;
  3345. }
  3346. return e.className;
  3347. });
  3348. },
  3349. hasClass : function(n, c) {
  3350. n = this.get(n);
  3351. if (!n || !c)
  3352. return false;
  3353. return (' ' + n.className + ' ').indexOf(' ' + c + ' ') !== -1;
  3354. },
  3355. show : function(e) {
  3356. return this.setStyle(e, 'display', 'block');
  3357. },
  3358. hide : function(e) {
  3359. return this.setStyle(e, 'display', 'none');
  3360. },
  3361. isHidden : function(e) {
  3362. e = this.get(e);
  3363. return !e || e.style.display == 'none' || this.getStyle(e, 'display') == 'none';
  3364. },
  3365. uniqueId : function(p) {
  3366. return (!p ? 'mce_' : p) + (this.counter++);
  3367. },
  3368. setHTML : function(element, html) {
  3369. var self = this;
  3370. return self.run(element, function(element) {
  3371. if (isIE) {
  3372. // Remove all child nodes, IE keeps empty text nodes in DOM
  3373. while (element.firstChild)
  3374. element.removeChild(element.firstChild);
  3375. try {
  3376. // IE will remove comments from the beginning
  3377. // unless you padd the contents with something
  3378. element.innerHTML = '<br />' + html;
  3379. element.removeChild(element.firstChild);
  3380. } catch (ex) {
  3381. // IE sometimes produces an unknown runtime error on innerHTML if it's an block element within a block element for example a div inside a p
  3382. // This seems to fix this problem
  3383. // Create new div with HTML contents and a BR infront to keep comments
  3384. element = self.create('div');
  3385. element.innerHTML = '<br />' + html;
  3386. // Add all children from div to target
  3387. each (element.childNodes, function(node, i) {
  3388. // Skip br element
  3389. if (i)
  3390. element.appendChild(node);
  3391. });
  3392. }
  3393. } else
  3394. element.innerHTML = html;
  3395. return html;
  3396. });
  3397. },
  3398. getOuterHTML : function(elm) {
  3399. var doc, self = this;
  3400. elm = self.get(elm);
  3401. if (!elm)
  3402. return null;
  3403. if (elm.nodeType === 1 && self.hasOuterHTML)
  3404. return elm.outerHTML;
  3405. doc = (elm.ownerDocument || self.doc).createElement("body");
  3406. doc.appendChild(elm.cloneNode(true));
  3407. return doc.innerHTML;
  3408. },
  3409. setOuterHTML : function(e, h, d) {
  3410. var t = this;
  3411. function setHTML(e, h, d) {
  3412. var n, tp;
  3413. tp = d.createElement("body");
  3414. tp.innerHTML = h;
  3415. n = tp.lastChild;
  3416. while (n) {
  3417. t.insertAfter(n.cloneNode(true), e);
  3418. n = n.previousSibling;
  3419. }
  3420. t.remove(e);
  3421. };
  3422. return this.run(e, function(e) {
  3423. e = t.get(e);
  3424. // Only set HTML on elements
  3425. if (e.nodeType == 1) {
  3426. d = d || e.ownerDocument || t.doc;
  3427. if (isIE) {
  3428. try {
  3429. // Try outerHTML for IE it sometimes produces an unknown runtime error
  3430. if (isIE && e.nodeType == 1)
  3431. e.outerHTML = h;
  3432. else
  3433. setHTML(e, h, d);
  3434. } catch (ex) {
  3435. // Fix for unknown runtime error
  3436. setHTML(e, h, d);
  3437. }
  3438. } else
  3439. setHTML(e, h, d);
  3440. }
  3441. });
  3442. },
  3443. decode : Entities.decode,
  3444. encode : Entities.encodeAllRaw,
  3445. insertAfter : function(node, reference_node) {
  3446. reference_node = this.get(reference_node);
  3447. return this.run(node, function(node) {
  3448. var parent, nextSibling;
  3449. parent = reference_node.parentNode;
  3450. nextSibling = reference_node.nextSibling;
  3451. if (nextSibling)
  3452. parent.insertBefore(node, nextSibling);
  3453. else
  3454. parent.appendChild(node);
  3455. return node;
  3456. });
  3457. },
  3458. isBlock : function(node) {
  3459. var type = node.nodeType;
  3460. // If it's a node then check the type and use the nodeName
  3461. if (type)
  3462. return !!(type === 1 && blockElementsMap[node.nodeName]);
  3463. return !!blockElementsMap[node];
  3464. },
  3465. replace : function(n, o, k) {
  3466. var t = this;
  3467. if (is(o, 'array'))
  3468. n = n.cloneNode(true);
  3469. return t.run(o, function(o) {
  3470. if (k) {
  3471. each(tinymce.grep(o.childNodes), function(c) {
  3472. n.appendChild(c);
  3473. });
  3474. }
  3475. return o.parentNode.replaceChild(n, o);
  3476. });
  3477. },
  3478. rename : function(elm, name) {
  3479. var t = this, newElm;
  3480. if (elm.nodeName != name.toUpperCase()) {
  3481. // Rename block element
  3482. newElm = t.create(name);
  3483. // Copy attribs to new block
  3484. each(t.getAttribs(elm), function(attr_node) {
  3485. t.setAttrib(newElm, attr_node.nodeName, t.getAttrib(elm, attr_node.nodeName));
  3486. });
  3487. // Replace block
  3488. t.replace(newElm, elm, 1);
  3489. }
  3490. return newElm || elm;
  3491. },
  3492. findCommonAncestor : function(a, b) {
  3493. var ps = a, pe;
  3494. while (ps) {
  3495. pe = b;
  3496. while (pe && ps != pe)
  3497. pe = pe.parentNode;
  3498. if (ps == pe)
  3499. break;
  3500. ps = ps.parentNode;
  3501. }
  3502. if (!ps && a.ownerDocument)
  3503. return a.ownerDocument.documentElement;
  3504. return ps;
  3505. },
  3506. toHex : function(s) {
  3507. var c = /^\s*rgb\s*?\(\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?\)\s*$/i.exec(s);
  3508. function hex(s) {
  3509. s = parseInt(s).toString(16);
  3510. return s.length > 1 ? s : '0' + s; // 0 -> 00
  3511. };
  3512. if (c) {
  3513. s = '#' + hex(c[1]) + hex(c[2]) + hex(c[3]);
  3514. return s;
  3515. }
  3516. return s;
  3517. },
  3518. getClasses : function() {
  3519. var t = this, cl = [], i, lo = {}, f = t.settings.class_filter, ov;
  3520. if (t.classes)
  3521. return t.classes;
  3522. function addClasses(s) {
  3523. // IE style imports
  3524. each(s.imports, function(r) {
  3525. addClasses(r);
  3526. });
  3527. each(s.cssRules || s.rules, function(r) {
  3528. // Real type or fake it on IE
  3529. switch (r.type || 1) {
  3530. // Rule
  3531. case 1:
  3532. if (r.selectorText) {
  3533. each(r.selectorText.split(','), function(v) {
  3534. v = v.replace(/^\s*|\s*$|^\s\./g, "");
  3535. // Is internal or it doesn't contain a class
  3536. if (/\.mce/.test(v) || !/\.[\w\-]+$/.test(v))
  3537. return;
  3538. // Remove everything but class name
  3539. ov = v;
  3540. v = tinymce._replace(/.*\.([a-z0-9_\-]+).*/i, '$1', v);
  3541. // Filter classes
  3542. if (f && !(v = f(v, ov)))
  3543. return;
  3544. if (!lo[v]) {
  3545. cl.push({'class' : v});
  3546. lo[v] = 1;
  3547. }
  3548. });
  3549. }
  3550. break;
  3551. // Import
  3552. case 3:
  3553. addClasses(r.styleSheet);
  3554. break;
  3555. }
  3556. });
  3557. };
  3558. try {
  3559. each(t.doc.styleSheets, addClasses);
  3560. } catch (ex) {
  3561. // Ignore
  3562. }
  3563. if (cl.length > 0)
  3564. t.classes = cl;
  3565. return cl;
  3566. },
  3567. run : function(e, f, s) {
  3568. var t = this, o;
  3569. if (t.doc && typeof(e) === 'string')
  3570. e = t.get(e);
  3571. if (!e)
  3572. return false;
  3573. s = s || this;
  3574. if (!e.nodeType && (e.length || e.length === 0)) {
  3575. o = [];
  3576. each(e, function(e, i) {
  3577. if (e) {
  3578. if (typeof(e) == 'string')
  3579. e = t.doc.getElementById(e);
  3580. o.push(f.call(s, e, i));
  3581. }
  3582. });
  3583. return o;
  3584. }
  3585. return f.call(s, e);
  3586. },
  3587. getAttribs : function(n) {
  3588. var o;
  3589. n = this.get(n);
  3590. if (!n)
  3591. return [];
  3592. if (isIE) {
  3593. o = [];
  3594. // Object will throw exception in IE
  3595. if (n.nodeName == 'OBJECT')
  3596. return n.attributes;
  3597. // IE doesn't keep the selected attribute if you clone option elements
  3598. if (n.nodeName === 'OPTION' && this.getAttrib(n, 'selected'))
  3599. o.push({specified : 1, nodeName : 'selected'});
  3600. // It's crazy that this is faster in IE but it's because it returns all attributes all the time
  3601. n.cloneNode(false).outerHTML.replace(/<\/?[\w:\-]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=[\w\-]+|>/gi, '').replace(/[\w:\-]+/gi, function(a) {
  3602. o.push({specified : 1, nodeName : a});
  3603. });
  3604. return o;
  3605. }
  3606. return n.attributes;
  3607. },
  3608. isEmpty : function(node, elements) {
  3609. var self = this, i, attributes, type, walker, name, parentNode;
  3610. node = node.firstChild;
  3611. if (node) {
  3612. walker = new tinymce.dom.TreeWalker(node);
  3613. elements = elements || self.schema ? self.schema.getNonEmptyElements() : null;
  3614. do {
  3615. type = node.nodeType;
  3616. if (type === 1) {
  3617. // Ignore bogus elements
  3618. if (node.getAttribute('data-mce-bogus'))
  3619. continue;
  3620. // Keep empty elements like <img />
  3621. name = node.nodeName.toLowerCase();
  3622. if (elements && elements[name]) {
  3623. // Ignore single BR elements in blocks like <p><br /></p>
  3624. parentNode = node.parentNode;
  3625. if (name === 'br' && self.isBlock(parentNode) && parentNode.firstChild === node && parentNode.lastChild === node) {
  3626. continue;
  3627. }
  3628. return false;
  3629. }
  3630. // Keep elements with data-bookmark attributes or name attribute like <a name="1"></a>
  3631. attributes = self.getAttribs(node);
  3632. i = node.attributes.length;
  3633. while (i--) {
  3634. name = node.attributes[i].nodeName;
  3635. if (name === "name" || name === 'data-mce-bookmark')
  3636. return false;
  3637. }
  3638. }
  3639. // Keep non whitespace text nodes
  3640. if ((type === 3 && !whiteSpaceRegExp.test(node.nodeValue)))
  3641. return false;
  3642. } while (node = walker.next());
  3643. }
  3644. return true;
  3645. },
  3646. destroy : function(s) {
  3647. var t = this;
  3648. if (t.events)
  3649. t.events.destroy();
  3650. t.win = t.doc = t.root = t.events = null;
  3651. // Manual destroy then remove unload handler
  3652. if (!s)
  3653. tinymce.removeUnload(t.destroy);
  3654. },
  3655. createRng : function() {
  3656. var d = this.doc;
  3657. return d.createRange ? d.createRange() : new tinymce.dom.Range(this);
  3658. },
  3659. nodeIndex : function(node, normalized) {
  3660. var idx = 0, lastNodeType, lastNode, nodeType;
  3661. if (node) {
  3662. for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) {
  3663. nodeType = node.nodeType;
  3664. // Normalize text nodes
  3665. if (normalized && nodeType == 3) {
  3666. if (nodeType == lastNodeType || !node.nodeValue.length)
  3667. continue;
  3668. }
  3669. idx++;
  3670. lastNodeType = nodeType;
  3671. }
  3672. }
  3673. return idx;
  3674. },
  3675. split : function(pe, e, re) {
  3676. var t = this, r = t.createRng(), bef, aft, pa;
  3677. // W3C valid browsers tend to leave empty nodes to the left/right side of the contents, this makes sense
  3678. // but we don't want that in our code since it serves no purpose for the end user
  3679. // For example if this is chopped:
  3680. // <p>text 1<span><b>CHOP</b></span>text 2</p>
  3681. // would produce:
  3682. // <p>text 1<span></span></p><b>CHOP</b><p><span></span>text 2</p>
  3683. // this function will then trim of empty edges and produce:
  3684. // <p>text 1</p><b>CHOP</b><p>text 2</p>
  3685. function trim(node) {
  3686. var i, children = node.childNodes, type = node.nodeType;
  3687. if (type == 1 && node.getAttribute('data-mce-type') == 'bookmark')
  3688. return;
  3689. for (i = children.length - 1; i >= 0; i--)
  3690. trim(children[i]);
  3691. if (type != 9) {
  3692. // Keep non whitespace text nodes
  3693. if (type == 3 && node.nodeValue.length > 0) {
  3694. // If parent element isn't a block or there isn't any useful contents for example "<p> </p>"
  3695. if (!t.isBlock(node.parentNode) || tinymce.trim(node.nodeValue).length > 0)
  3696. return;
  3697. } else if (type == 1) {
  3698. // If the only child is a bookmark then move it up
  3699. children = node.childNodes;
  3700. if (children.length == 1 && children[0] && children[0].nodeType == 1 && children[0].getAttribute('data-mce-type') == 'bookmark')
  3701. node.parentNode.insertBefore(children[0], node);
  3702. // Keep non empty elements or img, hr etc
  3703. if (children.length || /^(br|hr|input|img)$/i.test(node.nodeName))
  3704. return;
  3705. }
  3706. t.remove(node);
  3707. }
  3708. return node;
  3709. };
  3710. if (pe && e) {
  3711. // Get before chunk
  3712. r.setStart(pe.parentNode, t.nodeIndex(pe));
  3713. r.setEnd(e.parentNode, t.nodeIndex(e));
  3714. bef = r.extractContents();
  3715. // Get after chunk
  3716. r = t.createRng();
  3717. r.setStart(e.parentNode, t.nodeIndex(e) + 1);
  3718. r.setEnd(pe.parentNode, t.nodeIndex(pe) + 1);
  3719. aft = r.extractContents();
  3720. // Insert before chunk
  3721. pa = pe.parentNode;
  3722. pa.insertBefore(trim(bef), pe);
  3723. // Insert middle chunk
  3724. if (re)
  3725. pa.replaceChild(re, e);
  3726. else
  3727. pa.insertBefore(e, pe);
  3728. // Insert after chunk
  3729. pa.insertBefore(trim(aft), pe);
  3730. t.remove(pe);
  3731. return re || e;
  3732. }
  3733. },
  3734. bind : function(target, name, func, scope) {
  3735. var t = this;
  3736. if (!t.events)
  3737. t.events = new tinymce.dom.EventUtils();
  3738. return t.events.add(target, name, func, scope || this);
  3739. },
  3740. unbind : function(target, name, func) {
  3741. var t = this;
  3742. if (!t.events)
  3743. t.events = new tinymce.dom.EventUtils();
  3744. return t.events.remove(target, name, func);
  3745. },
  3746. _findSib : function(node, selector, name) {
  3747. var t = this, f = selector;
  3748. if (node) {
  3749. // If expression make a function of it using is
  3750. if (is(f, 'string')) {
  3751. f = function(node) {
  3752. return t.is(node, selector);
  3753. };
  3754. }
  3755. // Loop all siblings
  3756. for (node = node[name]; node; node = node[name]) {
  3757. if (f(node))
  3758. return node;
  3759. }
  3760. }
  3761. return null;
  3762. },
  3763. _isRes : function(c) {
  3764. // Is live resizble element
  3765. return /^(top|left|bottom|right|width|height)/i.test(c) || /;\s*(top|left|bottom|right|width|height)/i.test(c);
  3766. }
  3767. /*
  3768. walk : function(n, f, s) {
  3769. var d = this.doc, w;
  3770. if (d.createTreeWalker) {
  3771. w = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false);
  3772. while ((n = w.nextNode()) != null)
  3773. f.call(s || this, n);
  3774. } else
  3775. tinymce.walk(n, f, 'childNodes', s);
  3776. }
  3777. */
  3778. /*
  3779. toRGB : function(s) {
  3780. var c = /^\s*?#([0-9A-F]{2})([0-9A-F]{1,2})([0-9A-F]{2})?\s*?$/.exec(s);
  3781. if (c) {
  3782. // #FFF -> #FFFFFF
  3783. if (!is(c[3]))
  3784. c[3] = c[2] = c[1];
  3785. return "rgb(" + parseInt(c[1], 16) + "," + parseInt(c[2], 16) + "," + parseInt(c[3], 16) + ")";
  3786. }
  3787. return s;
  3788. }
  3789. */
  3790. });
  3791. tinymce.DOM = new tinymce.dom.DOMUtils(document, {process_html : 0});
  3792. })(tinymce);
  3793. (function(ns) {
  3794. // Range constructor
  3795. function Range(dom) {
  3796. var t = this,
  3797. doc = dom.doc,
  3798. EXTRACT = 0,
  3799. CLONE = 1,
  3800. DELETE = 2,
  3801. TRUE = true,
  3802. FALSE = false,
  3803. START_OFFSET = 'startOffset',
  3804. START_CONTAINER = 'startContainer',
  3805. END_CONTAINER = 'endContainer',
  3806. END_OFFSET = 'endOffset',
  3807. extend = tinymce.extend,
  3808. nodeIndex = dom.nodeIndex;
  3809. extend(t, {
  3810. // Inital states
  3811. startContainer : doc,
  3812. startOffset : 0,
  3813. endContainer : doc,
  3814. endOffset : 0,
  3815. collapsed : TRUE,
  3816. commonAncestorContainer : doc,
  3817. // Range constants
  3818. START_TO_START : 0,
  3819. START_TO_END : 1,
  3820. END_TO_END : 2,
  3821. END_TO_START : 3,
  3822. // Public methods
  3823. setStart : setStart,
  3824. setEnd : setEnd,
  3825. setStartBefore : setStartBefore,
  3826. setStartAfter : setStartAfter,
  3827. setEndBefore : setEndBefore,
  3828. setEndAfter : setEndAfter,
  3829. collapse : collapse,
  3830. selectNode : selectNode,
  3831. selectNodeContents : selectNodeContents,
  3832. compareBoundaryPoints : compareBoundaryPoints,
  3833. deleteContents : deleteContents,
  3834. extractContents : extractContents,
  3835. cloneContents : cloneContents,
  3836. insertNode : insertNode,
  3837. surroundContents : surroundContents,
  3838. cloneRange : cloneRange
  3839. });
  3840. function setStart(n, o) {
  3841. _setEndPoint(TRUE, n, o);
  3842. };
  3843. function setEnd(n, o) {
  3844. _setEndPoint(FALSE, n, o);
  3845. };
  3846. function setStartBefore(n) {
  3847. setStart(n.parentNode, nodeIndex(n));
  3848. };
  3849. function setStartAfter(n) {
  3850. setStart(n.parentNode, nodeIndex(n) + 1);
  3851. };
  3852. function setEndBefore(n) {
  3853. setEnd(n.parentNode, nodeIndex(n));
  3854. };
  3855. function setEndAfter(n) {
  3856. setEnd(n.parentNode, nodeIndex(n) + 1);
  3857. };
  3858. function collapse(ts) {
  3859. if (ts) {
  3860. t[END_CONTAINER] = t[START_CONTAINER];
  3861. t[END_OFFSET] = t[START_OFFSET];
  3862. } else {
  3863. t[START_CONTAINER] = t[END_CONTAINER];
  3864. t[START_OFFSET] = t[END_OFFSET];
  3865. }
  3866. t.collapsed = TRUE;
  3867. };
  3868. function selectNode(n) {
  3869. setStartBefore(n);
  3870. setEndAfter(n);
  3871. };
  3872. function selectNodeContents(n) {
  3873. setStart(n, 0);
  3874. setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length);
  3875. };
  3876. function compareBoundaryPoints(h, r) {
  3877. var sc = t[START_CONTAINER], so = t[START_OFFSET], ec = t[END_CONTAINER], eo = t[END_OFFSET],
  3878. rsc = r.startContainer, rso = r.startOffset, rec = r.endContainer, reo = r.endOffset;
  3879. // Check START_TO_START
  3880. if (h === 0)
  3881. return _compareBoundaryPoints(sc, so, rsc, rso);
  3882. // Check START_TO_END
  3883. if (h === 1)
  3884. return _compareBoundaryPoints(ec, eo, rsc, rso);
  3885. // Check END_TO_END
  3886. if (h === 2)
  3887. return _compareBoundaryPoints(ec, eo, rec, reo);
  3888. // Check END_TO_START
  3889. if (h === 3)
  3890. return _compareBoundaryPoints(sc, so, rec, reo);
  3891. };
  3892. function deleteContents() {
  3893. _traverse(DELETE);
  3894. };
  3895. function extractContents() {
  3896. return _traverse(EXTRACT);
  3897. };
  3898. function cloneContents() {
  3899. return _traverse(CLONE);
  3900. };
  3901. function insertNode(n) {
  3902. var startContainer = this[START_CONTAINER],
  3903. startOffset = this[START_OFFSET], nn, o;
  3904. // Node is TEXT_NODE or CDATA
  3905. if ((startContainer.nodeType === 3 || startContainer.nodeType === 4) && startContainer.nodeValue) {
  3906. if (!startOffset) {
  3907. // At the start of text
  3908. startContainer.parentNode.insertBefore(n, startContainer);
  3909. } else if (startOffset >= startContainer.nodeValue.length) {
  3910. // At the end of text
  3911. dom.insertAfter(n, startContainer);
  3912. } else {
  3913. // Middle, need to split
  3914. nn = startContainer.splitText(startOffset);
  3915. startContainer.parentNode.insertBefore(n, nn);
  3916. }
  3917. } else {
  3918. // Insert element node
  3919. if (startContainer.childNodes.length > 0)
  3920. o = startContainer.childNodes[startOffset];
  3921. if (o)
  3922. startContainer.insertBefore(n, o);
  3923. else
  3924. startContainer.appendChild(n);
  3925. }
  3926. };
  3927. function surroundContents(n) {
  3928. var f = t.extractContents();
  3929. t.insertNode(n);
  3930. n.appendChild(f);
  3931. t.selectNode(n);
  3932. };
  3933. function cloneRange() {
  3934. return extend(new Range(dom), {
  3935. startContainer : t[START_CONTAINER],
  3936. startOffset : t[START_OFFSET],
  3937. endContainer : t[END_CONTAINER],
  3938. endOffset : t[END_OFFSET],
  3939. collapsed : t.collapsed,
  3940. commonAncestorContainer : t.commonAncestorContainer
  3941. });
  3942. };
  3943. // Private methods
  3944. function _getSelectedNode(container, offset) {
  3945. var child;
  3946. if (container.nodeType == 3 /* TEXT_NODE */)
  3947. return container;
  3948. if (offset < 0)
  3949. return container;
  3950. child = container.firstChild;
  3951. while (child && offset > 0) {
  3952. --offset;
  3953. child = child.nextSibling;
  3954. }
  3955. if (child)
  3956. return child;
  3957. return container;
  3958. };
  3959. function _isCollapsed() {
  3960. return (t[START_CONTAINER] == t[END_CONTAINER] && t[START_OFFSET] == t[END_OFFSET]);
  3961. };
  3962. function _compareBoundaryPoints(containerA, offsetA, containerB, offsetB) {
  3963. var c, offsetC, n, cmnRoot, childA, childB;
  3964. // In the first case the boundary-points have the same container. A is before B
  3965. // if its offset is less than the offset of B, A is equal to B if its offset is
  3966. // equal to the offset of B, and A is after B if its offset is greater than the
  3967. // offset of B.
  3968. if (containerA == containerB) {
  3969. if (offsetA == offsetB)
  3970. return 0; // equal
  3971. if (offsetA < offsetB)
  3972. return -1; // before
  3973. return 1; // after
  3974. }
  3975. // In the second case a child node C of the container of A is an ancestor
  3976. // container of B. In this case, A is before B if the offset of A is less than or
  3977. // equal to the index of the child node C and A is after B otherwise.
  3978. c = containerB;
  3979. while (c && c.parentNode != containerA)
  3980. c = c.parentNode;
  3981. if (c) {
  3982. offsetC = 0;
  3983. n = containerA.firstChild;
  3984. while (n != c && offsetC < offsetA) {
  3985. offsetC++;
  3986. n = n.nextSibling;
  3987. }
  3988. if (offsetA <= offsetC)
  3989. return -1; // before
  3990. return 1; // after
  3991. }
  3992. // In the third case a child node C of the container of B is an ancestor container
  3993. // of A. In this case, A is before B if the index of the child node C is less than
  3994. // the offset of B and A is after B otherwise.
  3995. c = containerA;
  3996. while (c && c.parentNode != containerB) {
  3997. c = c.parentNode;
  3998. }
  3999. if (c) {
  4000. offsetC = 0;
  4001. n = containerB.firstChild;
  4002. while (n != c && offsetC < offsetB) {
  4003. offsetC++;
  4004. n = n.nextSibling;
  4005. }
  4006. if (offsetC < offsetB)
  4007. return -1; // before
  4008. return 1; // after
  4009. }
  4010. // In the fourth case, none of three other cases hold: the containers of A and B
  4011. // are siblings or descendants of sibling nodes. In this case, A is before B if
  4012. // the container of A is before the container of B in a pre-order traversal of the
  4013. // Ranges' context tree and A is after B otherwise.
  4014. cmnRoot = dom.findCommonAncestor(containerA, containerB);
  4015. childA = containerA;
  4016. while (childA && childA.parentNode != cmnRoot)
  4017. childA = childA.parentNode;
  4018. if (!childA)
  4019. childA = cmnRoot;
  4020. childB = containerB;
  4021. while (childB && childB.parentNode != cmnRoot)
  4022. childB = childB.parentNode;
  4023. if (!childB)
  4024. childB = cmnRoot;
  4025. if (childA == childB)
  4026. return 0; // equal
  4027. n = cmnRoot.firstChild;
  4028. while (n) {
  4029. if (n == childA)
  4030. return -1; // before
  4031. if (n == childB)
  4032. return 1; // after
  4033. n = n.nextSibling;
  4034. }
  4035. };
  4036. function _setEndPoint(st, n, o) {
  4037. var ec, sc;
  4038. if (st) {
  4039. t[START_CONTAINER] = n;
  4040. t[START_OFFSET] = o;
  4041. } else {
  4042. t[END_CONTAINER] = n;
  4043. t[END_OFFSET] = o;
  4044. }
  4045. // If one boundary-point of a Range is set to have a root container
  4046. // other than the current one for the Range, the Range is collapsed to
  4047. // the new position. This enforces the restriction that both boundary-
  4048. // points of a Range must have the same root container.
  4049. ec = t[END_CONTAINER];
  4050. while (ec.parentNode)
  4051. ec = ec.parentNode;
  4052. sc = t[START_CONTAINER];
  4053. while (sc.parentNode)
  4054. sc = sc.parentNode;
  4055. if (sc == ec) {
  4056. // The start position of a Range is guaranteed to never be after the
  4057. // end position. To enforce this restriction, if the start is set to
  4058. // be at a position after the end, the Range is collapsed to that
  4059. // position.
  4060. if (_compareBoundaryPoints(t[START_CONTAINER], t[START_OFFSET], t[END_CONTAINER], t[END_OFFSET]) > 0)
  4061. t.collapse(st);
  4062. } else
  4063. t.collapse(st);
  4064. t.collapsed = _isCollapsed();
  4065. t.commonAncestorContainer = dom.findCommonAncestor(t[START_CONTAINER], t[END_CONTAINER]);
  4066. };
  4067. function _traverse(how) {
  4068. var c, endContainerDepth = 0, startContainerDepth = 0, p, depthDiff, startNode, endNode, sp, ep;
  4069. if (t[START_CONTAINER] == t[END_CONTAINER])
  4070. return _traverseSameContainer(how);
  4071. for (c = t[END_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  4072. if (p == t[START_CONTAINER])
  4073. return _traverseCommonStartContainer(c, how);
  4074. ++endContainerDepth;
  4075. }
  4076. for (c = t[START_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  4077. if (p == t[END_CONTAINER])
  4078. return _traverseCommonEndContainer(c, how);
  4079. ++startContainerDepth;
  4080. }
  4081. depthDiff = startContainerDepth - endContainerDepth;
  4082. startNode = t[START_CONTAINER];
  4083. while (depthDiff > 0) {
  4084. startNode = startNode.parentNode;
  4085. depthDiff--;
  4086. }
  4087. endNode = t[END_CONTAINER];
  4088. while (depthDiff < 0) {
  4089. endNode = endNode.parentNode;
  4090. depthDiff++;
  4091. }
  4092. // ascend the ancestor hierarchy until we have a common parent.
  4093. for (sp = startNode.parentNode, ep = endNode.parentNode; sp != ep; sp = sp.parentNode, ep = ep.parentNode) {
  4094. startNode = sp;
  4095. endNode = ep;
  4096. }
  4097. return _traverseCommonAncestors(startNode, endNode, how);
  4098. };
  4099. function _traverseSameContainer(how) {
  4100. var frag, s, sub, n, cnt, sibling, xferNode;
  4101. if (how != DELETE)
  4102. frag = doc.createDocumentFragment();
  4103. // If selection is empty, just return the fragment
  4104. if (t[START_OFFSET] == t[END_OFFSET])
  4105. return frag;
  4106. // Text node needs special case handling
  4107. if (t[START_CONTAINER].nodeType == 3 /* TEXT_NODE */) {
  4108. // get the substring
  4109. s = t[START_CONTAINER].nodeValue;
  4110. sub = s.substring(t[START_OFFSET], t[END_OFFSET]);
  4111. // set the original text node to its new value
  4112. if (how != CLONE) {
  4113. t[START_CONTAINER].deleteData(t[START_OFFSET], t[END_OFFSET] - t[START_OFFSET]);
  4114. // Nothing is partially selected, so collapse to start point
  4115. t.collapse(TRUE);
  4116. }
  4117. if (how == DELETE)
  4118. return;
  4119. frag.appendChild(doc.createTextNode(sub));
  4120. return frag;
  4121. }
  4122. // Copy nodes between the start/end offsets.
  4123. n = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]);
  4124. cnt = t[END_OFFSET] - t[START_OFFSET];
  4125. while (cnt > 0) {
  4126. sibling = n.nextSibling;
  4127. xferNode = _traverseFullySelected(n, how);
  4128. if (frag)
  4129. frag.appendChild( xferNode );
  4130. --cnt;
  4131. n = sibling;
  4132. }
  4133. // Nothing is partially selected, so collapse to start point
  4134. if (how != CLONE)
  4135. t.collapse(TRUE);
  4136. return frag;
  4137. };
  4138. function _traverseCommonStartContainer(endAncestor, how) {
  4139. var frag, n, endIdx, cnt, sibling, xferNode;
  4140. if (how != DELETE)
  4141. frag = doc.createDocumentFragment();
  4142. n = _traverseRightBoundary(endAncestor, how);
  4143. if (frag)
  4144. frag.appendChild(n);
  4145. endIdx = nodeIndex(endAncestor);
  4146. cnt = endIdx - t[START_OFFSET];
  4147. if (cnt <= 0) {
  4148. // Collapse to just before the endAncestor, which
  4149. // is partially selected.
  4150. if (how != CLONE) {
  4151. t.setEndBefore(endAncestor);
  4152. t.collapse(FALSE);
  4153. }
  4154. return frag;
  4155. }
  4156. n = endAncestor.previousSibling;
  4157. while (cnt > 0) {
  4158. sibling = n.previousSibling;
  4159. xferNode = _traverseFullySelected(n, how);
  4160. if (frag)
  4161. frag.insertBefore(xferNode, frag.firstChild);
  4162. --cnt;
  4163. n = sibling;
  4164. }
  4165. // Collapse to just before the endAncestor, which
  4166. // is partially selected.
  4167. if (how != CLONE) {
  4168. t.setEndBefore(endAncestor);
  4169. t.collapse(FALSE);
  4170. }
  4171. return frag;
  4172. };
  4173. function _traverseCommonEndContainer(startAncestor, how) {
  4174. var frag, startIdx, n, cnt, sibling, xferNode;
  4175. if (how != DELETE)
  4176. frag = doc.createDocumentFragment();
  4177. n = _traverseLeftBoundary(startAncestor, how);
  4178. if (frag)
  4179. frag.appendChild(n);
  4180. startIdx = nodeIndex(startAncestor);
  4181. ++startIdx; // Because we already traversed it
  4182. cnt = t[END_OFFSET] - startIdx;
  4183. n = startAncestor.nextSibling;
  4184. while (cnt > 0) {
  4185. sibling = n.nextSibling;
  4186. xferNode = _traverseFullySelected(n, how);
  4187. if (frag)
  4188. frag.appendChild(xferNode);
  4189. --cnt;
  4190. n = sibling;
  4191. }
  4192. if (how != CLONE) {
  4193. t.setStartAfter(startAncestor);
  4194. t.collapse(TRUE);
  4195. }
  4196. return frag;
  4197. };
  4198. function _traverseCommonAncestors(startAncestor, endAncestor, how) {
  4199. var n, frag, commonParent, startOffset, endOffset, cnt, sibling, nextSibling;
  4200. if (how != DELETE)
  4201. frag = doc.createDocumentFragment();
  4202. n = _traverseLeftBoundary(startAncestor, how);
  4203. if (frag)
  4204. frag.appendChild(n);
  4205. commonParent = startAncestor.parentNode;
  4206. startOffset = nodeIndex(startAncestor);
  4207. endOffset = nodeIndex(endAncestor);
  4208. ++startOffset;
  4209. cnt = endOffset - startOffset;
  4210. sibling = startAncestor.nextSibling;
  4211. while (cnt > 0) {
  4212. nextSibling = sibling.nextSibling;
  4213. n = _traverseFullySelected(sibling, how);
  4214. if (frag)
  4215. frag.appendChild(n);
  4216. sibling = nextSibling;
  4217. --cnt;
  4218. }
  4219. n = _traverseRightBoundary(endAncestor, how);
  4220. if (frag)
  4221. frag.appendChild(n);
  4222. if (how != CLONE) {
  4223. t.setStartAfter(startAncestor);
  4224. t.collapse(TRUE);
  4225. }
  4226. return frag;
  4227. };
  4228. function _traverseRightBoundary(root, how) {
  4229. var next = _getSelectedNode(t[END_CONTAINER], t[END_OFFSET] - 1), parent, clonedParent, prevSibling, clonedChild, clonedGrandParent, isFullySelected = next != t[END_CONTAINER];
  4230. if (next == root)
  4231. return _traverseNode(next, isFullySelected, FALSE, how);
  4232. parent = next.parentNode;
  4233. clonedParent = _traverseNode(parent, FALSE, FALSE, how);
  4234. while (parent) {
  4235. while (next) {
  4236. prevSibling = next.previousSibling;
  4237. clonedChild = _traverseNode(next, isFullySelected, FALSE, how);
  4238. if (how != DELETE)
  4239. clonedParent.insertBefore(clonedChild, clonedParent.firstChild);
  4240. isFullySelected = TRUE;
  4241. next = prevSibling;
  4242. }
  4243. if (parent == root)
  4244. return clonedParent;
  4245. next = parent.previousSibling;
  4246. parent = parent.parentNode;
  4247. clonedGrandParent = _traverseNode(parent, FALSE, FALSE, how);
  4248. if (how != DELETE)
  4249. clonedGrandParent.appendChild(clonedParent);
  4250. clonedParent = clonedGrandParent;
  4251. }
  4252. };
  4253. function _traverseLeftBoundary(root, how) {
  4254. var next = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]), isFullySelected = next != t[START_CONTAINER], parent, clonedParent, nextSibling, clonedChild, clonedGrandParent;
  4255. if (next == root)
  4256. return _traverseNode(next, isFullySelected, TRUE, how);
  4257. parent = next.parentNode;
  4258. clonedParent = _traverseNode(parent, FALSE, TRUE, how);
  4259. while (parent) {
  4260. while (next) {
  4261. nextSibling = next.nextSibling;
  4262. clonedChild = _traverseNode(next, isFullySelected, TRUE, how);
  4263. if (how != DELETE)
  4264. clonedParent.appendChild(clonedChild);
  4265. isFullySelected = TRUE;
  4266. next = nextSibling;
  4267. }
  4268. if (parent == root)
  4269. return clonedParent;
  4270. next = parent.nextSibling;
  4271. parent = parent.parentNode;
  4272. clonedGrandParent = _traverseNode(parent, FALSE, TRUE, how);
  4273. if (how != DELETE)
  4274. clonedGrandParent.appendChild(clonedParent);
  4275. clonedParent = clonedGrandParent;
  4276. }
  4277. };
  4278. function _traverseNode(n, isFullySelected, isLeft, how) {
  4279. var txtValue, newNodeValue, oldNodeValue, offset, newNode;
  4280. if (isFullySelected)
  4281. return _traverseFullySelected(n, how);
  4282. if (n.nodeType == 3 /* TEXT_NODE */) {
  4283. txtValue = n.nodeValue;
  4284. if (isLeft) {
  4285. offset = t[START_OFFSET];
  4286. newNodeValue = txtValue.substring(offset);
  4287. oldNodeValue = txtValue.substring(0, offset);
  4288. } else {
  4289. offset = t[END_OFFSET];
  4290. newNodeValue = txtValue.substring(0, offset);
  4291. oldNodeValue = txtValue.substring(offset);
  4292. }
  4293. if (how != CLONE)
  4294. n.nodeValue = oldNodeValue;
  4295. if (how == DELETE)
  4296. return;
  4297. newNode = n.cloneNode(FALSE);
  4298. newNode.nodeValue = newNodeValue;
  4299. return newNode;
  4300. }
  4301. if (how == DELETE)
  4302. return;
  4303. return n.cloneNode(FALSE);
  4304. };
  4305. function _traverseFullySelected(n, how) {
  4306. if (how != DELETE)
  4307. return how == CLONE ? n.cloneNode(TRUE) : n;
  4308. n.parentNode.removeChild(n);
  4309. };
  4310. };
  4311. ns.Range = Range;
  4312. })(tinymce.dom);
  4313. (function() {
  4314. function Selection(selection) {
  4315. var self = this, dom = selection.dom, TRUE = true, FALSE = false;
  4316. function getPosition(rng, start) {
  4317. var checkRng, startIndex = 0, endIndex, inside,
  4318. children, child, offset, index, position = -1, parent;
  4319. // Setup test range, collapse it and get the parent
  4320. checkRng = rng.duplicate();
  4321. checkRng.collapse(start);
  4322. parent = checkRng.parentElement();
  4323. // Check if the selection is within the right document
  4324. if (parent.ownerDocument !== selection.dom.doc)
  4325. return;
  4326. // IE will report non editable elements as it's parent so look for an editable one
  4327. while (parent.contentEditable === "false") {
  4328. parent = parent.parentNode;
  4329. }
  4330. // If parent doesn't have any children then return that we are inside the element
  4331. if (!parent.hasChildNodes()) {
  4332. return {node : parent, inside : 1};
  4333. }
  4334. // Setup node list and endIndex
  4335. children = parent.children;
  4336. endIndex = children.length - 1;
  4337. // Perform a binary search for the position
  4338. while (startIndex <= endIndex) {
  4339. index = Math.floor((startIndex + endIndex) / 2);
  4340. // Move selection to node and compare the ranges
  4341. child = children[index];
  4342. checkRng.moveToElementText(child);
  4343. position = checkRng.compareEndPoints(start ? 'StartToStart' : 'EndToEnd', rng);
  4344. // Before/after or an exact match
  4345. if (position > 0) {
  4346. endIndex = index - 1;
  4347. } else if (position < 0) {
  4348. startIndex = index + 1;
  4349. } else {
  4350. return {node : child};
  4351. }
  4352. }
  4353. // Check if child position is before or we didn't find a position
  4354. if (position < 0) {
  4355. // No element child was found use the parent element and the offset inside that
  4356. if (!child) {
  4357. checkRng.moveToElementText(parent);
  4358. checkRng.collapse(true);
  4359. child = parent;
  4360. inside = true;
  4361. } else
  4362. checkRng.collapse(false);
  4363. checkRng.setEndPoint(start ? 'EndToStart' : 'EndToEnd', rng);
  4364. // Fix for edge case: <div style="width: 100px; height:100px;"><table>..</table>ab|c</div>
  4365. if (checkRng.compareEndPoints(start ? 'StartToStart' : 'StartToEnd', rng) > 0) {
  4366. checkRng = rng.duplicate();
  4367. checkRng.collapse(start);
  4368. offset = -1;
  4369. while (parent == checkRng.parentElement()) {
  4370. if (checkRng.move('character', -1) == 0)
  4371. break;
  4372. offset++;
  4373. }
  4374. }
  4375. offset = offset || checkRng.text.replace('\r\n', ' ').length;
  4376. } else {
  4377. // Child position is after the selection endpoint
  4378. checkRng.collapse(true);
  4379. checkRng.setEndPoint(start ? 'StartToStart' : 'StartToEnd', rng);
  4380. // Get the length of the text to find where the endpoint is relative to it's container
  4381. offset = checkRng.text.replace('\r\n', ' ').length;
  4382. }
  4383. return {node : child, position : position, offset : offset, inside : inside};
  4384. };
  4385. // Returns a W3C DOM compatible range object by using the IE Range API
  4386. function getRange() {
  4387. var ieRange = selection.getRng(), domRange = dom.createRng(), element, collapsed, tmpRange, element2, bookmark, fail;
  4388. // If selection is outside the current document just return an empty range
  4389. element = ieRange.item ? ieRange.item(0) : ieRange.parentElement();
  4390. if (element.ownerDocument != dom.doc)
  4391. return domRange;
  4392. collapsed = selection.isCollapsed();
  4393. // Handle control selection
  4394. if (ieRange.item) {
  4395. domRange.setStart(element.parentNode, dom.nodeIndex(element));
  4396. domRange.setEnd(domRange.startContainer, domRange.startOffset + 1);
  4397. return domRange;
  4398. }
  4399. function findEndPoint(start) {
  4400. var endPoint = getPosition(ieRange, start), container, offset, textNodeOffset = 0, sibling, undef, nodeValue;
  4401. container = endPoint.node;
  4402. offset = endPoint.offset;
  4403. if (endPoint.inside && !container.hasChildNodes()) {
  4404. domRange[start ? 'setStart' : 'setEnd'](container, 0);
  4405. return;
  4406. }
  4407. if (offset === undef) {
  4408. domRange[start ? 'setStartBefore' : 'setEndAfter'](container);
  4409. return;
  4410. }
  4411. if (endPoint.position < 0) {
  4412. sibling = endPoint.inside ? container.firstChild : container.nextSibling;
  4413. if (!sibling) {
  4414. domRange[start ? 'setStartAfter' : 'setEndAfter'](container);
  4415. return;
  4416. }
  4417. if (!offset) {
  4418. if (sibling.nodeType == 3)
  4419. domRange[start ? 'setStart' : 'setEnd'](sibling, 0);
  4420. else
  4421. domRange[start ? 'setStartBefore' : 'setEndBefore'](sibling);
  4422. return;
  4423. }
  4424. // Find the text node and offset
  4425. while (sibling) {
  4426. nodeValue = sibling.nodeValue;
  4427. textNodeOffset += nodeValue.length;
  4428. // We are at or passed the position we where looking for
  4429. if (textNodeOffset >= offset) {
  4430. container = sibling;
  4431. textNodeOffset -= offset;
  4432. textNodeOffset = nodeValue.length - textNodeOffset;
  4433. break;
  4434. }
  4435. sibling = sibling.nextSibling;
  4436. }
  4437. } else {
  4438. // Find the text node and offset
  4439. sibling = container.previousSibling;
  4440. if (!sibling)
  4441. return domRange[start ? 'setStartBefore' : 'setEndBefore'](container);
  4442. // If there isn't any text to loop then use the first position
  4443. if (!offset) {
  4444. if (container.nodeType == 3)
  4445. domRange[start ? 'setStart' : 'setEnd'](sibling, container.nodeValue.length);
  4446. else
  4447. domRange[start ? 'setStartAfter' : 'setEndAfter'](sibling);
  4448. return;
  4449. }
  4450. while (sibling) {
  4451. textNodeOffset += sibling.nodeValue.length;
  4452. // We are at or passed the position we where looking for
  4453. if (textNodeOffset >= offset) {
  4454. container = sibling;
  4455. textNodeOffset -= offset;
  4456. break;
  4457. }
  4458. sibling = sibling.previousSibling;
  4459. }
  4460. }
  4461. domRange[start ? 'setStart' : 'setEnd'](container, textNodeOffset);
  4462. };
  4463. try {
  4464. // Find start point
  4465. findEndPoint(true);
  4466. // Find end point if needed
  4467. if (!collapsed)
  4468. findEndPoint();
  4469. } catch (ex) {
  4470. // IE has a nasty bug where text nodes might throw "invalid argument" when you
  4471. // access the nodeValue or other properties of text nodes. This seems to happend when
  4472. // text nodes are split into two nodes by a delete/backspace call. So lets detect it and try to fix it.
  4473. if (ex.number == -2147024809) {
  4474. // Get the current selection
  4475. bookmark = self.getBookmark(2);
  4476. // Get start element
  4477. tmpRange = ieRange.duplicate();
  4478. tmpRange.collapse(true);
  4479. element = tmpRange.parentElement();
  4480. // Get end element
  4481. if (!collapsed) {
  4482. tmpRange = ieRange.duplicate();
  4483. tmpRange.collapse(false);
  4484. element2 = tmpRange.parentElement();
  4485. element2.innerHTML = element2.innerHTML;
  4486. }
  4487. // Remove the broken elements
  4488. element.innerHTML = element.innerHTML;
  4489. // Restore the selection
  4490. self.moveToBookmark(bookmark);
  4491. // Since the range has moved we need to re-get it
  4492. ieRange = selection.getRng();
  4493. // Find start point
  4494. findEndPoint(true);
  4495. // Find end point if needed
  4496. if (!collapsed)
  4497. findEndPoint();
  4498. } else
  4499. throw ex; // Throw other errors
  4500. }
  4501. return domRange;
  4502. };
  4503. this.getBookmark = function(type) {
  4504. var rng = selection.getRng(), start, end, bookmark = {};
  4505. function getIndexes(node) {
  4506. var node, parent, root, children, i, indexes = [];
  4507. parent = node.parentNode;
  4508. root = dom.getRoot().parentNode;
  4509. while (parent != root && parent.nodeType !== 9) {
  4510. children = parent.children;
  4511. i = children.length;
  4512. while (i--) {
  4513. if (node === children[i]) {
  4514. indexes.push(i);
  4515. break;
  4516. }
  4517. }
  4518. node = parent;
  4519. parent = parent.parentNode;
  4520. }
  4521. return indexes;
  4522. };
  4523. function getBookmarkEndPoint(start) {
  4524. var position;
  4525. position = getPosition(rng, start);
  4526. if (position) {
  4527. return {
  4528. position : position.position,
  4529. offset : position.offset,
  4530. indexes : getIndexes(position.node),
  4531. inside : position.inside
  4532. };
  4533. }
  4534. };
  4535. // Non ubstructive bookmark
  4536. if (type === 2) {
  4537. // Handle text selection
  4538. if (!rng.item) {
  4539. bookmark.start = getBookmarkEndPoint(true);
  4540. if (!selection.isCollapsed())
  4541. bookmark.end = getBookmarkEndPoint();
  4542. } else
  4543. bookmark.start = {ctrl : true, indexes : getIndexes(rng.item(0))};
  4544. }
  4545. return bookmark;
  4546. };
  4547. this.moveToBookmark = function(bookmark) {
  4548. var rng, body = dom.doc.body;
  4549. function resolveIndexes(indexes) {
  4550. var node, i, idx, children;
  4551. node = dom.getRoot();
  4552. for (i = indexes.length - 1; i >= 0; i--) {
  4553. children = node.children;
  4554. idx = indexes[i];
  4555. if (idx <= children.length - 1) {
  4556. node = children[idx];
  4557. }
  4558. }
  4559. return node;
  4560. };
  4561. function setBookmarkEndPoint(start) {
  4562. var endPoint = bookmark[start ? 'start' : 'end'], moveLeft, moveRng, undef;
  4563. if (endPoint) {
  4564. moveLeft = endPoint.position > 0;
  4565. moveRng = body.createTextRange();
  4566. moveRng.moveToElementText(resolveIndexes(endPoint.indexes));
  4567. offset = endPoint.offset;
  4568. if (offset !== undef) {
  4569. moveRng.collapse(endPoint.inside || moveLeft);
  4570. moveRng.moveStart('character', moveLeft ? -offset : offset);
  4571. } else
  4572. moveRng.collapse(start);
  4573. rng.setEndPoint(start ? 'StartToStart' : 'EndToStart', moveRng);
  4574. if (start)
  4575. rng.collapse(true);
  4576. }
  4577. };
  4578. if (bookmark.start) {
  4579. if (bookmark.start.ctrl) {
  4580. rng = body.createControlRange();
  4581. rng.addElement(resolveIndexes(bookmark.start.indexes));
  4582. rng.select();
  4583. } else {
  4584. rng = body.createTextRange();
  4585. setBookmarkEndPoint(true);
  4586. setBookmarkEndPoint();
  4587. rng.select();
  4588. }
  4589. }
  4590. };
  4591. this.addRange = function(rng) {
  4592. var ieRng, ctrlRng, startContainer, startOffset, endContainer, endOffset, doc = selection.dom.doc, body = doc.body;
  4593. function setEndPoint(start) {
  4594. var container, offset, marker, tmpRng, nodes;
  4595. marker = dom.create('a');
  4596. container = start ? startContainer : endContainer;
  4597. offset = start ? startOffset : endOffset;
  4598. tmpRng = ieRng.duplicate();
  4599. if (container == doc || container == doc.documentElement) {
  4600. container = body;
  4601. offset = 0;
  4602. }
  4603. if (container.nodeType == 3) {
  4604. container.parentNode.insertBefore(marker, container);
  4605. tmpRng.moveToElementText(marker);
  4606. tmpRng.moveStart('character', offset);
  4607. dom.remove(marker);
  4608. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  4609. } else {
  4610. nodes = container.childNodes;
  4611. if (nodes.length) {
  4612. if (offset >= nodes.length) {
  4613. dom.insertAfter(marker, nodes[nodes.length - 1]);
  4614. } else {
  4615. container.insertBefore(marker, nodes[offset]);
  4616. }
  4617. tmpRng.moveToElementText(marker);
  4618. } else {
  4619. // Empty node selection for example <div>|</div>
  4620. marker = doc.createTextNode('\uFEFF');
  4621. container.appendChild(marker);
  4622. tmpRng.moveToElementText(marker.parentNode);
  4623. tmpRng.collapse(TRUE);
  4624. }
  4625. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  4626. dom.remove(marker);
  4627. }
  4628. }
  4629. // Setup some shorter versions
  4630. startContainer = rng.startContainer;
  4631. startOffset = rng.startOffset;
  4632. endContainer = rng.endContainer;
  4633. endOffset = rng.endOffset;
  4634. ieRng = body.createTextRange();
  4635. // If single element selection then try making a control selection out of it
  4636. if (startContainer == endContainer && startContainer.nodeType == 1 && startOffset == endOffset - 1) {
  4637. if (startOffset == endOffset - 1) {
  4638. try {
  4639. ctrlRng = body.createControlRange();
  4640. ctrlRng.addElement(startContainer.childNodes[startOffset]);
  4641. ctrlRng.select();
  4642. return;
  4643. } catch (ex) {
  4644. // Ignore
  4645. }
  4646. }
  4647. }
  4648. // Set start/end point of selection
  4649. setEndPoint(true);
  4650. setEndPoint();
  4651. // Select the new range and scroll it into view
  4652. ieRng.select();
  4653. };
  4654. // Expose range method
  4655. this.getRangeAt = getRange;
  4656. };
  4657. // Expose the selection object
  4658. tinymce.dom.TridentSelection = Selection;
  4659. })();
  4660. /*
  4661. * Sizzle CSS Selector Engine - v1.0
  4662. * Copyright 2009, The Dojo Foundation
  4663. * Released under the MIT, BSD, and GPL Licenses.
  4664. * More information: http://sizzlejs.com/
  4665. */
  4666. (function(){
  4667. var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
  4668. done = 0,
  4669. toString = Object.prototype.toString,
  4670. hasDuplicate = false,
  4671. baseHasDuplicate = true;
  4672. // Here we check if the JavaScript engine is using some sort of
  4673. // optimization where it does not always call our comparision
  4674. // function. If that is the case, discard the hasDuplicate value.
  4675. // Thus far that includes Google Chrome.
  4676. [0, 0].sort(function(){
  4677. baseHasDuplicate = false;
  4678. return 0;
  4679. });
  4680. var Sizzle = function(selector, context, results, seed) {
  4681. results = results || [];
  4682. context = context || document;
  4683. var origContext = context;
  4684. if ( context.nodeType !== 1 && context.nodeType !== 9 ) {
  4685. return [];
  4686. }
  4687. if ( !selector || typeof selector !== "string" ) {
  4688. return results;
  4689. }
  4690. var parts = [], m, set, checkSet, extra, prune = true, contextXML = Sizzle.isXML(context),
  4691. soFar = selector, ret, cur, pop, i;
  4692. // Reset the position of the chunker regexp (start from head)
  4693. do {
  4694. chunker.exec("");
  4695. m = chunker.exec(soFar);
  4696. if ( m ) {
  4697. soFar = m[3];
  4698. parts.push( m[1] );
  4699. if ( m[2] ) {
  4700. extra = m[3];
  4701. break;
  4702. }
  4703. }
  4704. } while ( m );
  4705. if ( parts.length > 1 && origPOS.exec( selector ) ) {
  4706. if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
  4707. set = posProcess( parts[0] + parts[1], context );
  4708. } else {
  4709. set = Expr.relative[ parts[0] ] ?
  4710. [ context ] :
  4711. Sizzle( parts.shift(), context );
  4712. while ( parts.length ) {
  4713. selector = parts.shift();
  4714. if ( Expr.relative[ selector ] ) {
  4715. selector += parts.shift();
  4716. }
  4717. set = posProcess( selector, set );
  4718. }
  4719. }
  4720. } else {
  4721. // Take a shortcut and set the context if the root selector is an ID
  4722. // (but not if it'll be faster if the inner selector is an ID)
  4723. if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML &&
  4724. Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) {
  4725. ret = Sizzle.find( parts.shift(), context, contextXML );
  4726. context = ret.expr ? Sizzle.filter( ret.expr, ret.set )[0] : ret.set[0];
  4727. }
  4728. if ( context ) {
  4729. ret = seed ?
  4730. { expr: parts.pop(), set: makeArray(seed) } :
  4731. Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML );
  4732. set = ret.expr ? Sizzle.filter( ret.expr, ret.set ) : ret.set;
  4733. if ( parts.length > 0 ) {
  4734. checkSet = makeArray(set);
  4735. } else {
  4736. prune = false;
  4737. }
  4738. while ( parts.length ) {
  4739. cur = parts.pop();
  4740. pop = cur;
  4741. if ( !Expr.relative[ cur ] ) {
  4742. cur = "";
  4743. } else {
  4744. pop = parts.pop();
  4745. }
  4746. if ( pop == null ) {
  4747. pop = context;
  4748. }
  4749. Expr.relative[ cur ]( checkSet, pop, contextXML );
  4750. }
  4751. } else {
  4752. checkSet = parts = [];
  4753. }
  4754. }
  4755. if ( !checkSet ) {
  4756. checkSet = set;
  4757. }
  4758. if ( !checkSet ) {
  4759. Sizzle.error( cur || selector );
  4760. }
  4761. if ( toString.call(checkSet) === "[object Array]" ) {
  4762. if ( !prune ) {
  4763. results.push.apply( results, checkSet );
  4764. } else if ( context && context.nodeType === 1 ) {
  4765. for ( i = 0; checkSet[i] != null; i++ ) {
  4766. if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && Sizzle.contains(context, checkSet[i])) ) {
  4767. results.push( set[i] );
  4768. }
  4769. }
  4770. } else {
  4771. for ( i = 0; checkSet[i] != null; i++ ) {
  4772. if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
  4773. results.push( set[i] );
  4774. }
  4775. }
  4776. }
  4777. } else {
  4778. makeArray( checkSet, results );
  4779. }
  4780. if ( extra ) {
  4781. Sizzle( extra, origContext, results, seed );
  4782. Sizzle.uniqueSort( results );
  4783. }
  4784. return results;
  4785. };
  4786. Sizzle.uniqueSort = function(results){
  4787. if ( sortOrder ) {
  4788. hasDuplicate = baseHasDuplicate;
  4789. results.sort(sortOrder);
  4790. if ( hasDuplicate ) {
  4791. for ( var i = 1; i < results.length; i++ ) {
  4792. if ( results[i] === results[i-1] ) {
  4793. results.splice(i--, 1);
  4794. }
  4795. }
  4796. }
  4797. }
  4798. return results;
  4799. };
  4800. Sizzle.matches = function(expr, set){
  4801. return Sizzle(expr, null, null, set);
  4802. };
  4803. Sizzle.find = function(expr, context, isXML){
  4804. var set;
  4805. if ( !expr ) {
  4806. return [];
  4807. }
  4808. for ( var i = 0, l = Expr.order.length; i < l; i++ ) {
  4809. var type = Expr.order[i], match;
  4810. if ( (match = Expr.leftMatch[ type ].exec( expr )) ) {
  4811. var left = match[1];
  4812. match.splice(1,1);
  4813. if ( left.substr( left.length - 1 ) !== "\\" ) {
  4814. match[1] = (match[1] || "").replace(/\\/g, "");
  4815. set = Expr.find[ type ]( match, context, isXML );
  4816. if ( set != null ) {
  4817. expr = expr.replace( Expr.match[ type ], "" );
  4818. break;
  4819. }
  4820. }
  4821. }
  4822. }
  4823. if ( !set ) {
  4824. set = context.getElementsByTagName("*");
  4825. }
  4826. return {set: set, expr: expr};
  4827. };
  4828. Sizzle.filter = function(expr, set, inplace, not){
  4829. var old = expr, result = [], curLoop = set, match, anyFound,
  4830. isXMLFilter = set && set[0] && Sizzle.isXML(set[0]);
  4831. while ( expr && set.length ) {
  4832. for ( var type in Expr.filter ) {
  4833. if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {
  4834. var filter = Expr.filter[ type ], found, item, left = match[1];
  4835. anyFound = false;
  4836. match.splice(1,1);
  4837. if ( left.substr( left.length - 1 ) === "\\" ) {
  4838. continue;
  4839. }
  4840. if ( curLoop === result ) {
  4841. result = [];
  4842. }
  4843. if ( Expr.preFilter[ type ] ) {
  4844. match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );
  4845. if ( !match ) {
  4846. anyFound = found = true;
  4847. } else if ( match === true ) {
  4848. continue;
  4849. }
  4850. }
  4851. if ( match ) {
  4852. for ( var i = 0; (item = curLoop[i]) != null; i++ ) {
  4853. if ( item ) {
  4854. found = filter( item, match, i, curLoop );
  4855. var pass = not ^ !!found;
  4856. if ( inplace && found != null ) {
  4857. if ( pass ) {
  4858. anyFound = true;
  4859. } else {
  4860. curLoop[i] = false;
  4861. }
  4862. } else if ( pass ) {
  4863. result.push( item );
  4864. anyFound = true;
  4865. }
  4866. }
  4867. }
  4868. }
  4869. if ( found !== undefined ) {
  4870. if ( !inplace ) {
  4871. curLoop = result;
  4872. }
  4873. expr = expr.replace( Expr.match[ type ], "" );
  4874. if ( !anyFound ) {
  4875. return [];
  4876. }
  4877. break;
  4878. }
  4879. }
  4880. }
  4881. // Improper expression
  4882. if ( expr === old ) {
  4883. if ( anyFound == null ) {
  4884. Sizzle.error( expr );
  4885. } else {
  4886. break;
  4887. }
  4888. }
  4889. old = expr;
  4890. }
  4891. return curLoop;
  4892. };
  4893. Sizzle.error = function( msg ) {
  4894. throw "Syntax error, unrecognized expression: " + msg;
  4895. };
  4896. var Expr = Sizzle.selectors = {
  4897. order: [ "ID", "NAME", "TAG" ],
  4898. match: {
  4899. ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
  4900. CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
  4901. NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,
  4902. ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/,
  4903. TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,
  4904. CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+\-]*)\))?/,
  4905. POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,
  4906. PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/
  4907. },
  4908. leftMatch: {},
  4909. attrMap: {
  4910. "class": "className",
  4911. "for": "htmlFor"
  4912. },
  4913. attrHandle: {
  4914. href: function(elem){
  4915. return elem.getAttribute("href");
  4916. }
  4917. },
  4918. relative: {
  4919. "+": function(checkSet, part){
  4920. var isPartStr = typeof part === "string",
  4921. isTag = isPartStr && !/\W/.test(part),
  4922. isPartStrNotTag = isPartStr && !isTag;
  4923. if ( isTag ) {
  4924. part = part.toLowerCase();
  4925. }
  4926. for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
  4927. if ( (elem = checkSet[i]) ) {
  4928. while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}
  4929. checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ?
  4930. elem || false :
  4931. elem === part;
  4932. }
  4933. }
  4934. if ( isPartStrNotTag ) {
  4935. Sizzle.filter( part, checkSet, true );
  4936. }
  4937. },
  4938. ">": function(checkSet, part){
  4939. var isPartStr = typeof part === "string",
  4940. elem, i = 0, l = checkSet.length;
  4941. if ( isPartStr && !/\W/.test(part) ) {
  4942. part = part.toLowerCase();
  4943. for ( ; i < l; i++ ) {
  4944. elem = checkSet[i];
  4945. if ( elem ) {
  4946. var parent = elem.parentNode;
  4947. checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false;
  4948. }
  4949. }
  4950. } else {
  4951. for ( ; i < l; i++ ) {
  4952. elem = checkSet[i];
  4953. if ( elem ) {
  4954. checkSet[i] = isPartStr ?
  4955. elem.parentNode :
  4956. elem.parentNode === part;
  4957. }
  4958. }
  4959. if ( isPartStr ) {
  4960. Sizzle.filter( part, checkSet, true );
  4961. }
  4962. }
  4963. },
  4964. "": function(checkSet, part, isXML){
  4965. var doneName = done++, checkFn = dirCheck, nodeCheck;
  4966. if ( typeof part === "string" && !/\W/.test(part) ) {
  4967. part = part.toLowerCase();
  4968. nodeCheck = part;
  4969. checkFn = dirNodeCheck;
  4970. }
  4971. checkFn("parentNode", part, doneName, checkSet, nodeCheck, isXML);
  4972. },
  4973. "~": function(checkSet, part, isXML){
  4974. var doneName = done++, checkFn = dirCheck, nodeCheck;
  4975. if ( typeof part === "string" && !/\W/.test(part) ) {
  4976. part = part.toLowerCase();
  4977. nodeCheck = part;
  4978. checkFn = dirNodeCheck;
  4979. }
  4980. checkFn("previousSibling", part, doneName, checkSet, nodeCheck, isXML);
  4981. }
  4982. },
  4983. find: {
  4984. ID: function(match, context, isXML){
  4985. if ( typeof context.getElementById !== "undefined" && !isXML ) {
  4986. var m = context.getElementById(match[1]);
  4987. return m ? [m] : [];
  4988. }
  4989. },
  4990. NAME: function(match, context){
  4991. if ( typeof context.getElementsByName !== "undefined" ) {
  4992. var ret = [], results = context.getElementsByName(match[1]);
  4993. for ( var i = 0, l = results.length; i < l; i++ ) {
  4994. if ( results[i].getAttribute("name") === match[1] ) {
  4995. ret.push( results[i] );
  4996. }
  4997. }
  4998. return ret.length === 0 ? null : ret;
  4999. }
  5000. },
  5001. TAG: function(match, context){
  5002. return context.getElementsByTagName(match[1]);
  5003. }
  5004. },
  5005. preFilter: {
  5006. CLASS: function(match, curLoop, inplace, result, not, isXML){
  5007. match = " " + match[1].replace(/\\/g, "") + " ";
  5008. if ( isXML ) {
  5009. return match;
  5010. }
  5011. for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {
  5012. if ( elem ) {
  5013. if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n]/g, " ").indexOf(match) >= 0) ) {
  5014. if ( !inplace ) {
  5015. result.push( elem );
  5016. }
  5017. } else if ( inplace ) {
  5018. curLoop[i] = false;
  5019. }
  5020. }
  5021. }
  5022. return false;
  5023. },
  5024. ID: function(match){
  5025. return match[1].replace(/\\/g, "");
  5026. },
  5027. TAG: function(match, curLoop){
  5028. return match[1].toLowerCase();
  5029. },
  5030. CHILD: function(match){
  5031. if ( match[1] === "nth" ) {
  5032. // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
  5033. var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
  5034. match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" ||
  5035. !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
  5036. // calculate the numbers (first)n+(last) including if they are negative
  5037. match[2] = (test[1] + (test[2] || 1)) - 0;
  5038. match[3] = test[3] - 0;
  5039. }
  5040. // TODO: Move to normal caching system
  5041. match[0] = done++;
  5042. return match;
  5043. },
  5044. ATTR: function(match, curLoop, inplace, result, not, isXML){
  5045. var name = match[1].replace(/\\/g, "");
  5046. if ( !isXML && Expr.attrMap[name] ) {
  5047. match[1] = Expr.attrMap[name];
  5048. }
  5049. if ( match[2] === "~=" ) {
  5050. match[4] = " " + match[4] + " ";
  5051. }
  5052. return match;
  5053. },
  5054. PSEUDO: function(match, curLoop, inplace, result, not){
  5055. if ( match[1] === "not" ) {
  5056. // If we're dealing with a complex expression, or a simple one
  5057. if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) {
  5058. match[3] = Sizzle(match[3], null, null, curLoop);
  5059. } else {
  5060. var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
  5061. if ( !inplace ) {
  5062. result.push.apply( result, ret );
  5063. }
  5064. return false;
  5065. }
  5066. } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
  5067. return true;
  5068. }
  5069. return match;
  5070. },
  5071. POS: function(match){
  5072. match.unshift( true );
  5073. return match;
  5074. }
  5075. },
  5076. filters: {
  5077. enabled: function(elem){
  5078. return elem.disabled === false && elem.type !== "hidden";
  5079. },
  5080. disabled: function(elem){
  5081. return elem.disabled === true;
  5082. },
  5083. checked: function(elem){
  5084. return elem.checked === true;
  5085. },
  5086. selected: function(elem){
  5087. // Accessing this property makes selected-by-default
  5088. // options in Safari work properly
  5089. elem.parentNode.selectedIndex;
  5090. return elem.selected === true;
  5091. },
  5092. parent: function(elem){
  5093. return !!elem.firstChild;
  5094. },
  5095. empty: function(elem){
  5096. return !elem.firstChild;
  5097. },
  5098. has: function(elem, i, match){
  5099. return !!Sizzle( match[3], elem ).length;
  5100. },
  5101. header: function(elem){
  5102. return (/h\d/i).test( elem.nodeName );
  5103. },
  5104. text: function(elem){
  5105. return "text" === elem.type;
  5106. },
  5107. radio: function(elem){
  5108. return "radio" === elem.type;
  5109. },
  5110. checkbox: function(elem){
  5111. return "checkbox" === elem.type;
  5112. },
  5113. file: function(elem){
  5114. return "file" === elem.type;
  5115. },
  5116. password: function(elem){
  5117. return "password" === elem.type;
  5118. },
  5119. submit: function(elem){
  5120. return "submit" === elem.type;
  5121. },
  5122. image: function(elem){
  5123. return "image" === elem.type;
  5124. },
  5125. reset: function(elem){
  5126. return "reset" === elem.type;
  5127. },
  5128. button: function(elem){
  5129. return "button" === elem.type || elem.nodeName.toLowerCase() === "button";
  5130. },
  5131. input: function(elem){
  5132. return (/input|select|textarea|button/i).test(elem.nodeName);
  5133. }
  5134. },
  5135. setFilters: {
  5136. first: function(elem, i){
  5137. return i === 0;
  5138. },
  5139. last: function(elem, i, match, array){
  5140. return i === array.length - 1;
  5141. },
  5142. even: function(elem, i){
  5143. return i % 2 === 0;
  5144. },
  5145. odd: function(elem, i){
  5146. return i % 2 === 1;
  5147. },
  5148. lt: function(elem, i, match){
  5149. return i < match[3] - 0;
  5150. },
  5151. gt: function(elem, i, match){
  5152. return i > match[3] - 0;
  5153. },
  5154. nth: function(elem, i, match){
  5155. return match[3] - 0 === i;
  5156. },
  5157. eq: function(elem, i, match){
  5158. return match[3] - 0 === i;
  5159. }
  5160. },
  5161. filter: {
  5162. PSEUDO: function(elem, match, i, array){
  5163. var name = match[1], filter = Expr.filters[ name ];
  5164. if ( filter ) {
  5165. return filter( elem, i, match, array );
  5166. } else if ( name === "contains" ) {
  5167. return (elem.textContent || elem.innerText || Sizzle.getText([ elem ]) || "").indexOf(match[3]) >= 0;
  5168. } else if ( name === "not" ) {
  5169. var not = match[3];
  5170. for ( var j = 0, l = not.length; j < l; j++ ) {
  5171. if ( not[j] === elem ) {
  5172. return false;
  5173. }
  5174. }
  5175. return true;
  5176. } else {
  5177. Sizzle.error( "Syntax error, unrecognized expression: " + name );
  5178. }
  5179. },
  5180. CHILD: function(elem, match){
  5181. var type = match[1], node = elem;
  5182. switch (type) {
  5183. case 'only':
  5184. case 'first':
  5185. while ( (node = node.previousSibling) ) {
  5186. if ( node.nodeType === 1 ) {
  5187. return false;
  5188. }
  5189. }
  5190. if ( type === "first" ) {
  5191. return true;
  5192. }
  5193. node = elem;
  5194. case 'last':
  5195. while ( (node = node.nextSibling) ) {
  5196. if ( node.nodeType === 1 ) {
  5197. return false;
  5198. }
  5199. }
  5200. return true;
  5201. case 'nth':
  5202. var first = match[2], last = match[3];
  5203. if ( first === 1 && last === 0 ) {
  5204. return true;
  5205. }
  5206. var doneName = match[0],
  5207. parent = elem.parentNode;
  5208. if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) {
  5209. var count = 0;
  5210. for ( node = parent.firstChild; node; node = node.nextSibling ) {
  5211. if ( node.nodeType === 1 ) {
  5212. node.nodeIndex = ++count;
  5213. }
  5214. }
  5215. parent.sizcache = doneName;
  5216. }
  5217. var diff = elem.nodeIndex - last;
  5218. if ( first === 0 ) {
  5219. return diff === 0;
  5220. } else {
  5221. return ( diff % first === 0 && diff / first >= 0 );
  5222. }
  5223. }
  5224. },
  5225. ID: function(elem, match){
  5226. return elem.nodeType === 1 && elem.getAttribute("id") === match;
  5227. },
  5228. TAG: function(elem, match){
  5229. return (match === "*" && elem.nodeType === 1) || elem.nodeName.toLowerCase() === match;
  5230. },
  5231. CLASS: function(elem, match){
  5232. return (" " + (elem.className || elem.getAttribute("class")) + " ")
  5233. .indexOf( match ) > -1;
  5234. },
  5235. ATTR: function(elem, match){
  5236. var name = match[1],
  5237. result = Expr.attrHandle[ name ] ?
  5238. Expr.attrHandle[ name ]( elem ) :
  5239. elem[ name ] != null ?
  5240. elem[ name ] :
  5241. elem.getAttribute( name ),
  5242. value = result + "",
  5243. type = match[2],
  5244. check = match[4];
  5245. return result == null ?
  5246. type === "!=" :
  5247. type === "=" ?
  5248. value === check :
  5249. type === "*=" ?
  5250. value.indexOf(check) >= 0 :
  5251. type === "~=" ?
  5252. (" " + value + " ").indexOf(check) >= 0 :
  5253. !check ?
  5254. value && result !== false :
  5255. type === "!=" ?
  5256. value !== check :
  5257. type === "^=" ?
  5258. value.indexOf(check) === 0 :
  5259. type === "$=" ?
  5260. value.substr(value.length - check.length) === check :
  5261. type === "|=" ?
  5262. value === check || value.substr(0, check.length + 1) === check + "-" :
  5263. false;
  5264. },
  5265. POS: function(elem, match, i, array){
  5266. var name = match[2], filter = Expr.setFilters[ name ];
  5267. if ( filter ) {
  5268. return filter( elem, i, match, array );
  5269. }
  5270. }
  5271. }
  5272. };
  5273. var origPOS = Expr.match.POS,
  5274. fescape = function(all, num){
  5275. return "\\" + (num - 0 + 1);
  5276. };
  5277. for ( var type in Expr.match ) {
  5278. Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) );
  5279. Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) );
  5280. }
  5281. var makeArray = function(array, results) {
  5282. array = Array.prototype.slice.call( array, 0 );
  5283. if ( results ) {
  5284. results.push.apply( results, array );
  5285. return results;
  5286. }
  5287. return array;
  5288. };
  5289. // Perform a simple check to determine if the browser is capable of
  5290. // converting a NodeList to an array using builtin methods.
  5291. // Also verifies that the returned array holds DOM nodes
  5292. // (which is not the case in the Blackberry browser)
  5293. try {
  5294. Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType;
  5295. // Provide a fallback method if it does not work
  5296. } catch(e){
  5297. makeArray = function(array, results) {
  5298. var ret = results || [], i = 0;
  5299. if ( toString.call(array) === "[object Array]" ) {
  5300. Array.prototype.push.apply( ret, array );
  5301. } else {
  5302. if ( typeof array.length === "number" ) {
  5303. for ( var l = array.length; i < l; i++ ) {
  5304. ret.push( array[i] );
  5305. }
  5306. } else {
  5307. for ( ; array[i]; i++ ) {
  5308. ret.push( array[i] );
  5309. }
  5310. }
  5311. }
  5312. return ret;
  5313. };
  5314. }
  5315. var sortOrder;
  5316. if ( document.documentElement.compareDocumentPosition ) {
  5317. sortOrder = function( a, b ) {
  5318. if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) {
  5319. if ( a == b ) {
  5320. hasDuplicate = true;
  5321. }
  5322. return a.compareDocumentPosition ? -1 : 1;
  5323. }
  5324. var ret = a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1;
  5325. if ( ret === 0 ) {
  5326. hasDuplicate = true;
  5327. }
  5328. return ret;
  5329. };
  5330. } else if ( "sourceIndex" in document.documentElement ) {
  5331. sortOrder = function( a, b ) {
  5332. if ( !a.sourceIndex || !b.sourceIndex ) {
  5333. if ( a == b ) {
  5334. hasDuplicate = true;
  5335. }
  5336. return a.sourceIndex ? -1 : 1;
  5337. }
  5338. var ret = a.sourceIndex - b.sourceIndex;
  5339. if ( ret === 0 ) {
  5340. hasDuplicate = true;
  5341. }
  5342. return ret;
  5343. };
  5344. } else if ( document.createRange ) {
  5345. sortOrder = function( a, b ) {
  5346. if ( !a.ownerDocument || !b.ownerDocument ) {
  5347. if ( a == b ) {
  5348. hasDuplicate = true;
  5349. }
  5350. return a.ownerDocument ? -1 : 1;
  5351. }
  5352. var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange();
  5353. aRange.setStart(a, 0);
  5354. aRange.setEnd(a, 0);
  5355. bRange.setStart(b, 0);
  5356. bRange.setEnd(b, 0);
  5357. var ret = aRange.compareBoundaryPoints(Range.START_TO_END, bRange);
  5358. if ( ret === 0 ) {
  5359. hasDuplicate = true;
  5360. }
  5361. return ret;
  5362. };
  5363. }
  5364. // Utility function for retreiving the text value of an array of DOM nodes
  5365. Sizzle.getText = function( elems ) {
  5366. var ret = "", elem;
  5367. for ( var i = 0; elems[i]; i++ ) {
  5368. elem = elems[i];
  5369. // Get the text from text nodes and CDATA nodes
  5370. if ( elem.nodeType === 3 || elem.nodeType === 4 ) {
  5371. ret += elem.nodeValue;
  5372. // Traverse everything else, except comment nodes
  5373. } else if ( elem.nodeType !== 8 ) {
  5374. ret += Sizzle.getText( elem.childNodes );
  5375. }
  5376. }
  5377. return ret;
  5378. };
  5379. // Check to see if the browser returns elements by name when
  5380. // querying by getElementById (and provide a workaround)
  5381. (function(){
  5382. // We're going to inject a fake input element with a specified name
  5383. var form = document.createElement("div"),
  5384. id = "script" + (new Date()).getTime();
  5385. form.innerHTML = "<a name='" + id + "'/>";
  5386. // Inject it into the root element, check its status, and remove it quickly
  5387. var root = document.documentElement;
  5388. root.insertBefore( form, root.firstChild );
  5389. // The workaround has to do additional checks after a getElementById
  5390. // Which slows things down for other browsers (hence the branching)
  5391. if ( document.getElementById( id ) ) {
  5392. Expr.find.ID = function(match, context, isXML){
  5393. if ( typeof context.getElementById !== "undefined" && !isXML ) {
  5394. var m = context.getElementById(match[1]);
  5395. return m ? m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : [];
  5396. }
  5397. };
  5398. Expr.filter.ID = function(elem, match){
  5399. var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
  5400. return elem.nodeType === 1 && node && node.nodeValue === match;
  5401. };
  5402. }
  5403. root.removeChild( form );
  5404. root = form = null; // release memory in IE
  5405. })();
  5406. (function(){
  5407. // Check to see if the browser returns only elements
  5408. // when doing getElementsByTagName("*")
  5409. // Create a fake element
  5410. var div = document.createElement("div");
  5411. div.appendChild( document.createComment("") );
  5412. // Make sure no comments are found
  5413. if ( div.getElementsByTagName("*").length > 0 ) {
  5414. Expr.find.TAG = function(match, context){
  5415. var results = context.getElementsByTagName(match[1]);
  5416. // Filter out possible comments
  5417. if ( match[1] === "*" ) {
  5418. var tmp = [];
  5419. for ( var i = 0; results[i]; i++ ) {
  5420. if ( results[i].nodeType === 1 ) {
  5421. tmp.push( results[i] );
  5422. }
  5423. }
  5424. results = tmp;
  5425. }
  5426. return results;
  5427. };
  5428. }
  5429. // Check to see if an attribute returns normalized href attributes
  5430. div.innerHTML = "<a href='#'></a>";
  5431. if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&
  5432. div.firstChild.getAttribute("href") !== "#" ) {
  5433. Expr.attrHandle.href = function(elem){
  5434. return elem.getAttribute("href", 2);
  5435. };
  5436. }
  5437. div = null; // release memory in IE
  5438. })();
  5439. if ( document.querySelectorAll ) {
  5440. (function(){
  5441. var oldSizzle = Sizzle, div = document.createElement("div");
  5442. div.innerHTML = "<p class='TEST'></p>";
  5443. // Safari can't handle uppercase or unicode characters when
  5444. // in quirks mode.
  5445. if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
  5446. return;
  5447. }
  5448. Sizzle = function(query, context, extra, seed){
  5449. context = context || document;
  5450. // Only use querySelectorAll on non-XML documents
  5451. // (ID selectors don't work in non-HTML documents)
  5452. if ( !seed && context.nodeType === 9 && !Sizzle.isXML(context) ) {
  5453. try {
  5454. return makeArray( context.querySelectorAll(query), extra );
  5455. } catch(e){}
  5456. }
  5457. return oldSizzle(query, context, extra, seed);
  5458. };
  5459. for ( var prop in oldSizzle ) {
  5460. Sizzle[ prop ] = oldSizzle[ prop ];
  5461. }
  5462. div = null; // release memory in IE
  5463. })();
  5464. }
  5465. (function(){
  5466. var div = document.createElement("div");
  5467. div.innerHTML = "<div class='test e'></div><div class='test'></div>";
  5468. // Opera can't find a second classname (in 9.6)
  5469. // Also, make sure that getElementsByClassName actually exists
  5470. if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) {
  5471. return;
  5472. }
  5473. // Safari caches class attributes, doesn't catch changes (in 3.2)
  5474. div.lastChild.className = "e";
  5475. if ( div.getElementsByClassName("e").length === 1 ) {
  5476. return;
  5477. }
  5478. Expr.order.splice(1, 0, "CLASS");
  5479. Expr.find.CLASS = function(match, context, isXML) {
  5480. if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
  5481. return context.getElementsByClassName(match[1]);
  5482. }
  5483. };
  5484. div = null; // release memory in IE
  5485. })();
  5486. function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  5487. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  5488. var elem = checkSet[i];
  5489. if ( elem ) {
  5490. elem = elem[dir];
  5491. var match = false;
  5492. while ( elem ) {
  5493. if ( elem.sizcache === doneName ) {
  5494. match = checkSet[elem.sizset];
  5495. break;
  5496. }
  5497. if ( elem.nodeType === 1 && !isXML ){
  5498. elem.sizcache = doneName;
  5499. elem.sizset = i;
  5500. }
  5501. if ( elem.nodeName.toLowerCase() === cur ) {
  5502. match = elem;
  5503. break;
  5504. }
  5505. elem = elem[dir];
  5506. }
  5507. checkSet[i] = match;
  5508. }
  5509. }
  5510. }
  5511. function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  5512. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  5513. var elem = checkSet[i];
  5514. if ( elem ) {
  5515. elem = elem[dir];
  5516. var match = false;
  5517. while ( elem ) {
  5518. if ( elem.sizcache === doneName ) {
  5519. match = checkSet[elem.sizset];
  5520. break;
  5521. }
  5522. if ( elem.nodeType === 1 ) {
  5523. if ( !isXML ) {
  5524. elem.sizcache = doneName;
  5525. elem.sizset = i;
  5526. }
  5527. if ( typeof cur !== "string" ) {
  5528. if ( elem === cur ) {
  5529. match = true;
  5530. break;
  5531. }
  5532. } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
  5533. match = elem;
  5534. break;
  5535. }
  5536. }
  5537. elem = elem[dir];
  5538. }
  5539. checkSet[i] = match;
  5540. }
  5541. }
  5542. }
  5543. Sizzle.contains = document.compareDocumentPosition ? function(a, b){
  5544. return !!(a.compareDocumentPosition(b) & 16);
  5545. } : function(a, b){
  5546. return a !== b && (a.contains ? a.contains(b) : true);
  5547. };
  5548. Sizzle.isXML = function(elem){
  5549. // documentElement is verified for cases where it doesn't yet exist
  5550. // (such as loading iframes in IE - #4833)
  5551. var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement;
  5552. return documentElement ? documentElement.nodeName !== "HTML" : false;
  5553. };
  5554. var posProcess = function(selector, context){
  5555. var tmpSet = [], later = "", match,
  5556. root = context.nodeType ? [context] : context;
  5557. // Position selectors must be done after the filter
  5558. // And so must :not(positional) so we move all PSEUDOs to the end
  5559. while ( (match = Expr.match.PSEUDO.exec( selector )) ) {
  5560. later += match[0];
  5561. selector = selector.replace( Expr.match.PSEUDO, "" );
  5562. }
  5563. selector = Expr.relative[selector] ? selector + "*" : selector;
  5564. for ( var i = 0, l = root.length; i < l; i++ ) {
  5565. Sizzle( selector, root[i], tmpSet );
  5566. }
  5567. return Sizzle.filter( later, tmpSet );
  5568. };
  5569. // EXPOSE
  5570. window.tinymce.dom.Sizzle = Sizzle;
  5571. })();
  5572. (function(tinymce) {
  5573. // Shorten names
  5574. var each = tinymce.each, DOM = tinymce.DOM, isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, Event;
  5575. tinymce.create('tinymce.dom.EventUtils', {
  5576. EventUtils : function() {
  5577. this.inits = [];
  5578. this.events = [];
  5579. },
  5580. add : function(o, n, f, s) {
  5581. var cb, t = this, el = t.events, r;
  5582. if (n instanceof Array) {
  5583. r = [];
  5584. each(n, function(n) {
  5585. r.push(t.add(o, n, f, s));
  5586. });
  5587. return r;
  5588. }
  5589. // Handle array
  5590. if (o && o.hasOwnProperty && o instanceof Array) {
  5591. r = [];
  5592. each(o, function(o) {
  5593. o = DOM.get(o);
  5594. r.push(t.add(o, n, f, s));
  5595. });
  5596. return r;
  5597. }
  5598. o = DOM.get(o);
  5599. if (!o)
  5600. return;
  5601. // Setup event callback
  5602. cb = function(e) {
  5603. // Is all events disabled
  5604. if (t.disabled)
  5605. return;
  5606. e = e || window.event;
  5607. // Patch in target, preventDefault and stopPropagation in IE it's W3C valid
  5608. if (e && isIE) {
  5609. if (!e.target)
  5610. e.target = e.srcElement;
  5611. // Patch in preventDefault, stopPropagation methods for W3C compatibility
  5612. tinymce.extend(e, t._stoppers);
  5613. }
  5614. if (!s)
  5615. return f(e);
  5616. return f.call(s, e);
  5617. };
  5618. if (n == 'unload') {
  5619. tinymce.unloads.unshift({func : cb});
  5620. return cb;
  5621. }
  5622. if (n == 'init') {
  5623. if (t.domLoaded)
  5624. cb();
  5625. else
  5626. t.inits.push(cb);
  5627. return cb;
  5628. }
  5629. // Store away listener reference
  5630. el.push({
  5631. obj : o,
  5632. name : n,
  5633. func : f,
  5634. cfunc : cb,
  5635. scope : s
  5636. });
  5637. t._add(o, n, cb);
  5638. return f;
  5639. },
  5640. remove : function(o, n, f) {
  5641. var t = this, a = t.events, s = false, r;
  5642. // Handle array
  5643. if (o && o.hasOwnProperty && o instanceof Array) {
  5644. r = [];
  5645. each(o, function(o) {
  5646. o = DOM.get(o);
  5647. r.push(t.remove(o, n, f));
  5648. });
  5649. return r;
  5650. }
  5651. o = DOM.get(o);
  5652. each(a, function(e, i) {
  5653. if (e.obj == o && e.name == n && (!f || (e.func == f || e.cfunc == f))) {
  5654. a.splice(i, 1);
  5655. t._remove(o, n, e.cfunc);
  5656. s = true;
  5657. return false;
  5658. }
  5659. });
  5660. return s;
  5661. },
  5662. clear : function(o) {
  5663. var t = this, a = t.events, i, e;
  5664. if (o) {
  5665. o = DOM.get(o);
  5666. for (i = a.length - 1; i >= 0; i--) {
  5667. e = a[i];
  5668. if (e.obj === o) {
  5669. t._remove(e.obj, e.name, e.cfunc);
  5670. e.obj = e.cfunc = null;
  5671. a.splice(i, 1);
  5672. }
  5673. }
  5674. }
  5675. },
  5676. cancel : function(e) {
  5677. if (!e)
  5678. return false;
  5679. this.stop(e);
  5680. return this.prevent(e);
  5681. },
  5682. stop : function(e) {
  5683. if (e.stopPropagation)
  5684. e.stopPropagation();
  5685. else
  5686. e.cancelBubble = true;
  5687. return false;
  5688. },
  5689. prevent : function(e) {
  5690. if (e.preventDefault)
  5691. e.preventDefault();
  5692. else
  5693. e.returnValue = false;
  5694. return false;
  5695. },
  5696. destroy : function() {
  5697. var t = this;
  5698. each(t.events, function(e, i) {
  5699. t._remove(e.obj, e.name, e.cfunc);
  5700. e.obj = e.cfunc = null;
  5701. });
  5702. t.events = [];
  5703. t = null;
  5704. },
  5705. _add : function(o, n, f) {
  5706. if (o.attachEvent)
  5707. o.attachEvent('on' + n, f);
  5708. else if (o.addEventListener)
  5709. o.addEventListener(n, f, false);
  5710. else
  5711. o['on' + n] = f;
  5712. },
  5713. _remove : function(o, n, f) {
  5714. if (o) {
  5715. try {
  5716. if (o.detachEvent)
  5717. o.detachEvent('on' + n, f);
  5718. else if (o.removeEventListener)
  5719. o.removeEventListener(n, f, false);
  5720. else
  5721. o['on' + n] = null;
  5722. } catch (ex) {
  5723. // Might fail with permission denined on IE so we just ignore that
  5724. }
  5725. }
  5726. },
  5727. _pageInit : function(win) {
  5728. var t = this;
  5729. // Keep it from running more than once
  5730. if (t.domLoaded)
  5731. return;
  5732. t.domLoaded = true;
  5733. each(t.inits, function(c) {
  5734. c();
  5735. });
  5736. t.inits = [];
  5737. },
  5738. _wait : function(win) {
  5739. var t = this, doc = win.document;
  5740. // No need since the document is already loaded
  5741. if (win.tinyMCE_GZ && tinyMCE_GZ.loaded) {
  5742. t.domLoaded = 1;
  5743. return;
  5744. }
  5745. // Use IE method
  5746. if (doc.attachEvent) {
  5747. doc.attachEvent("onreadystatechange", function() {
  5748. if (doc.readyState === "complete") {
  5749. doc.detachEvent("onreadystatechange", arguments.callee);
  5750. t._pageInit(win);
  5751. }
  5752. });
  5753. if (doc.documentElement.doScroll && win == win.top) {
  5754. (function() {
  5755. if (t.domLoaded)
  5756. return;
  5757. try {
  5758. // If IE is used, use the trick by Diego Perini licensed under MIT by request to the author.
  5759. // http://javascript.nwbox.com/IEContentLoaded/
  5760. doc.documentElement.doScroll("left");
  5761. } catch (ex) {
  5762. setTimeout(arguments.callee, 0);
  5763. return;
  5764. }
  5765. t._pageInit(win);
  5766. })();
  5767. }
  5768. } else if (doc.addEventListener) {
  5769. t._add(win, 'DOMContentLoaded', function() {
  5770. t._pageInit(win);
  5771. });
  5772. }
  5773. t._add(win, 'load', function() {
  5774. t._pageInit(win);
  5775. });
  5776. },
  5777. _stoppers : {
  5778. preventDefault : function() {
  5779. this.returnValue = false;
  5780. },
  5781. stopPropagation : function() {
  5782. this.cancelBubble = true;
  5783. }
  5784. }
  5785. });
  5786. Event = tinymce.dom.Event = new tinymce.dom.EventUtils();
  5787. // Dispatch DOM content loaded event for IE and Safari
  5788. Event._wait(window);
  5789. tinymce.addUnload(function() {
  5790. Event.destroy();
  5791. });
  5792. })(tinymce);
  5793. (function(tinymce) {
  5794. tinymce.dom.Element = function(id, settings) {
  5795. var t = this, dom, el;
  5796. t.settings = settings = settings || {};
  5797. t.id = id;
  5798. t.dom = dom = settings.dom || tinymce.DOM;
  5799. // Only IE leaks DOM references, this is a lot faster
  5800. if (!tinymce.isIE)
  5801. el = dom.get(t.id);
  5802. tinymce.each(
  5803. ('getPos,getRect,getParent,add,setStyle,getStyle,setStyles,' +
  5804. 'setAttrib,setAttribs,getAttrib,addClass,removeClass,' +
  5805. 'hasClass,getOuterHTML,setOuterHTML,remove,show,hide,' +
  5806. 'isHidden,setHTML,get').split(/,/)
  5807. , function(k) {
  5808. t[k] = function() {
  5809. var a = [id], i;
  5810. for (i = 0; i < arguments.length; i++)
  5811. a.push(arguments[i]);
  5812. a = dom[k].apply(dom, a);
  5813. t.update(k);
  5814. return a;
  5815. };
  5816. });
  5817. tinymce.extend(t, {
  5818. on : function(n, f, s) {
  5819. return tinymce.dom.Event.add(t.id, n, f, s);
  5820. },
  5821. getXY : function() {
  5822. return {
  5823. x : parseInt(t.getStyle('left')),
  5824. y : parseInt(t.getStyle('top'))
  5825. };
  5826. },
  5827. getSize : function() {
  5828. var n = dom.get(t.id);
  5829. return {
  5830. w : parseInt(t.getStyle('width') || n.clientWidth),
  5831. h : parseInt(t.getStyle('height') || n.clientHeight)
  5832. };
  5833. },
  5834. moveTo : function(x, y) {
  5835. t.setStyles({left : x, top : y});
  5836. },
  5837. moveBy : function(x, y) {
  5838. var p = t.getXY();
  5839. t.moveTo(p.x + x, p.y + y);
  5840. },
  5841. resizeTo : function(w, h) {
  5842. t.setStyles({width : w, height : h});
  5843. },
  5844. resizeBy : function(w, h) {
  5845. var s = t.getSize();
  5846. t.resizeTo(s.w + w, s.h + h);
  5847. },
  5848. update : function(k) {
  5849. var b;
  5850. if (tinymce.isIE6 && settings.blocker) {
  5851. k = k || '';
  5852. // Ignore getters
  5853. if (k.indexOf('get') === 0 || k.indexOf('has') === 0 || k.indexOf('is') === 0)
  5854. return;
  5855. // Remove blocker on remove
  5856. if (k == 'remove') {
  5857. dom.remove(t.blocker);
  5858. return;
  5859. }
  5860. if (!t.blocker) {
  5861. t.blocker = dom.uniqueId();
  5862. b = dom.add(settings.container || dom.getRoot(), 'iframe', {id : t.blocker, style : 'position:absolute;', frameBorder : 0, src : 'javascript:""'});
  5863. dom.setStyle(b, 'opacity', 0);
  5864. } else
  5865. b = dom.get(t.blocker);
  5866. dom.setStyles(b, {
  5867. left : t.getStyle('left', 1),
  5868. top : t.getStyle('top', 1),
  5869. width : t.getStyle('width', 1),
  5870. height : t.getStyle('height', 1),
  5871. display : t.getStyle('display', 1),
  5872. zIndex : parseInt(t.getStyle('zIndex', 1) || 0) - 1
  5873. });
  5874. }
  5875. }
  5876. });
  5877. };
  5878. })(tinymce);
  5879. (function(tinymce) {
  5880. function trimNl(s) {
  5881. return s.replace(/[\n\r]+/g, '');
  5882. };
  5883. // Shorten names
  5884. var is = tinymce.is, isIE = tinymce.isIE, each = tinymce.each;
  5885. tinymce.create('tinymce.dom.Selection', {
  5886. Selection : function(dom, win, serializer) {
  5887. var t = this;
  5888. t.dom = dom;
  5889. t.win = win;
  5890. t.serializer = serializer;
  5891. // Add events
  5892. each([
  5893. 'onBeforeSetContent',
  5894. 'onBeforeGetContent',
  5895. 'onSetContent',
  5896. 'onGetContent'
  5897. ], function(e) {
  5898. t[e] = new tinymce.util.Dispatcher(t);
  5899. });
  5900. // No W3C Range support
  5901. if (!t.win.getSelection)
  5902. t.tridentSel = new tinymce.dom.TridentSelection(t);
  5903. if (tinymce.isIE && dom.boxModel)
  5904. this._fixIESelection();
  5905. // Prevent leaks
  5906. tinymce.addUnload(t.destroy, t);
  5907. },
  5908. setCursorLocation: function(node, offset) {
  5909. var t = this; var r = t.dom.createRng();
  5910. r.setStart(node, offset);
  5911. r.setEnd(node, offset);
  5912. t.setRng(r);
  5913. t.collapse(false);
  5914. },
  5915. getContent : function(s) {
  5916. var t = this, r = t.getRng(), e = t.dom.create("body"), se = t.getSel(), wb, wa, n;
  5917. s = s || {};
  5918. wb = wa = '';
  5919. s.get = true;
  5920. s.format = s.format || 'html';
  5921. s.forced_root_block = '';
  5922. t.onBeforeGetContent.dispatch(t, s);
  5923. if (s.format == 'text')
  5924. return t.isCollapsed() ? '' : (r.text || (se.toString ? se.toString() : ''));
  5925. if (r.cloneContents) {
  5926. n = r.cloneContents();
  5927. if (n)
  5928. e.appendChild(n);
  5929. } else if (is(r.item) || is(r.htmlText)) {
  5930. // IE will produce invalid markup if elements are present that
  5931. // it doesn't understand like custom elements or HTML5 elements.
  5932. // Adding a BR in front of the contents and then remoiving it seems to fix it though.
  5933. e.innerHTML = '<br>' + (r.item ? r.item(0).outerHTML : r.htmlText);
  5934. e.removeChild(e.firstChild);
  5935. } else
  5936. e.innerHTML = r.toString();
  5937. // Keep whitespace before and after
  5938. if (/^\s/.test(e.innerHTML))
  5939. wb = ' ';
  5940. if (/\s+$/.test(e.innerHTML))
  5941. wa = ' ';
  5942. s.getInner = true;
  5943. s.content = t.isCollapsed() ? '' : wb + t.serializer.serialize(e, s) + wa;
  5944. t.onGetContent.dispatch(t, s);
  5945. return s.content;
  5946. },
  5947. setContent : function(content, args) {
  5948. var self = this, rng = self.getRng(), caretNode, doc = self.win.document, frag, temp;
  5949. args = args || {format : 'html'};
  5950. args.set = true;
  5951. content = args.content = content;
  5952. // Dispatch before set content event
  5953. if (!args.no_events)
  5954. self.onBeforeSetContent.dispatch(self, args);
  5955. content = args.content;
  5956. if (rng.insertNode) {
  5957. // Make caret marker since insertNode places the caret in the beginning of text after insert
  5958. content += '<span id="__caret">_</span>';
  5959. // Delete and insert new node
  5960. if (rng.startContainer == doc && rng.endContainer == doc) {
  5961. // WebKit will fail if the body is empty since the range is then invalid and it can't insert contents
  5962. doc.body.innerHTML = content;
  5963. } else {
  5964. rng.deleteContents();
  5965. if (doc.body.childNodes.length == 0) {
  5966. doc.body.innerHTML = content;
  5967. } else {
  5968. // createContextualFragment doesn't exists in IE 9 DOMRanges
  5969. if (rng.createContextualFragment) {
  5970. rng.insertNode(rng.createContextualFragment(content));
  5971. } else {
  5972. // Fake createContextualFragment call in IE 9
  5973. frag = doc.createDocumentFragment();
  5974. temp = doc.createElement('div');
  5975. frag.appendChild(temp);
  5976. temp.outerHTML = content;
  5977. rng.insertNode(frag);
  5978. }
  5979. }
  5980. }
  5981. // Move to caret marker
  5982. caretNode = self.dom.get('__caret');
  5983. // Make sure we wrap it compleatly, Opera fails with a simple select call
  5984. rng = doc.createRange();
  5985. rng.setStartBefore(caretNode);
  5986. rng.setEndBefore(caretNode);
  5987. self.setRng(rng);
  5988. // Remove the caret position
  5989. self.dom.remove('__caret');
  5990. try {
  5991. self.setRng(rng);
  5992. } catch (ex) {
  5993. // Might fail on Opera for some odd reason
  5994. }
  5995. } else {
  5996. if (rng.item) {
  5997. // Delete content and get caret text selection
  5998. doc.execCommand('Delete', false, null);
  5999. rng = self.getRng();
  6000. }
  6001. // Explorer removes spaces from the beginning of pasted contents
  6002. if (/^\s+/.test(content)) {
  6003. rng.pasteHTML('<span id="__mce_tmp">_</span>' + content);
  6004. self.dom.remove('__mce_tmp');
  6005. } else
  6006. rng.pasteHTML(content);
  6007. }
  6008. // Dispatch set content event
  6009. if (!args.no_events)
  6010. self.onSetContent.dispatch(self, args);
  6011. },
  6012. getStart : function() {
  6013. var rng = this.getRng(), startElement, parentElement, checkRng, node;
  6014. if (rng.duplicate || rng.item) {
  6015. // Control selection, return first item
  6016. if (rng.item)
  6017. return rng.item(0);
  6018. // Get start element
  6019. checkRng = rng.duplicate();
  6020. checkRng.collapse(1);
  6021. startElement = checkRng.parentElement();
  6022. // Check if range parent is inside the start element, then return the inner parent element
  6023. // This will fix issues when a single element is selected, IE would otherwise return the wrong start element
  6024. parentElement = node = rng.parentElement();
  6025. while (node = node.parentNode) {
  6026. if (node == startElement) {
  6027. startElement = parentElement;
  6028. break;
  6029. }
  6030. }
  6031. return startElement;
  6032. } else {
  6033. startElement = rng.startContainer;
  6034. if (startElement.nodeType == 1 && startElement.hasChildNodes())
  6035. startElement = startElement.childNodes[Math.min(startElement.childNodes.length - 1, rng.startOffset)];
  6036. if (startElement && startElement.nodeType == 3)
  6037. return startElement.parentNode;
  6038. return startElement;
  6039. }
  6040. },
  6041. getEnd : function() {
  6042. var t = this, r = t.getRng(), e, eo;
  6043. if (r.duplicate || r.item) {
  6044. if (r.item)
  6045. return r.item(0);
  6046. r = r.duplicate();
  6047. r.collapse(0);
  6048. e = r.parentElement();
  6049. if (e && e.nodeName == 'BODY')
  6050. return e.lastChild || e;
  6051. return e;
  6052. } else {
  6053. e = r.endContainer;
  6054. eo = r.endOffset;
  6055. if (e.nodeType == 1 && e.hasChildNodes())
  6056. e = e.childNodes[eo > 0 ? eo - 1 : eo];
  6057. if (e && e.nodeType == 3)
  6058. return e.parentNode;
  6059. return e;
  6060. }
  6061. },
  6062. getBookmark : function(type, normalized) {
  6063. var t = this, dom = t.dom, rng, rng2, id, collapsed, name, element, index, chr = '\uFEFF', styles;
  6064. function findIndex(name, element) {
  6065. var index = 0;
  6066. each(dom.select(name), function(node, i) {
  6067. if (node == element)
  6068. index = i;
  6069. });
  6070. return index;
  6071. };
  6072. if (type == 2) {
  6073. function getLocation() {
  6074. var rng = t.getRng(true), root = dom.getRoot(), bookmark = {};
  6075. function getPoint(rng, start) {
  6076. var container = rng[start ? 'startContainer' : 'endContainer'],
  6077. offset = rng[start ? 'startOffset' : 'endOffset'], point = [], node, childNodes, after = 0;
  6078. if (container.nodeType == 3) {
  6079. if (normalized) {
  6080. for (node = container.previousSibling; node && node.nodeType == 3; node = node.previousSibling)
  6081. offset += node.nodeValue.length;
  6082. }
  6083. point.push(offset);
  6084. } else {
  6085. childNodes = container.childNodes;
  6086. if (offset >= childNodes.length && childNodes.length) {
  6087. after = 1;
  6088. offset = Math.max(0, childNodes.length - 1);
  6089. }
  6090. point.push(t.dom.nodeIndex(childNodes[offset], normalized) + after);
  6091. }
  6092. for (; container && container != root; container = container.parentNode)
  6093. point.push(t.dom.nodeIndex(container, normalized));
  6094. return point;
  6095. };
  6096. bookmark.start = getPoint(rng, true);
  6097. if (!t.isCollapsed())
  6098. bookmark.end = getPoint(rng);
  6099. return bookmark;
  6100. };
  6101. if (t.tridentSel)
  6102. return t.tridentSel.getBookmark(type);
  6103. return getLocation();
  6104. }
  6105. // Handle simple range
  6106. if (type)
  6107. return {rng : t.getRng()};
  6108. rng = t.getRng();
  6109. id = dom.uniqueId();
  6110. collapsed = tinyMCE.activeEditor.selection.isCollapsed();
  6111. styles = 'overflow:hidden;line-height:0px';
  6112. // Explorer method
  6113. if (rng.duplicate || rng.item) {
  6114. // Text selection
  6115. if (!rng.item) {
  6116. rng2 = rng.duplicate();
  6117. try {
  6118. // Insert start marker
  6119. rng.collapse();
  6120. rng.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_start" style="' + styles + '">' + chr + '</span>');
  6121. // Insert end marker
  6122. if (!collapsed) {
  6123. rng2.collapse(false);
  6124. // Detect the empty space after block elements in IE and move the end back one character <p></p>] becomes <p>]</p>
  6125. rng.moveToElementText(rng2.parentElement());
  6126. if (rng.compareEndPoints('StartToEnd', rng2) == 0)
  6127. rng2.move('character', -1);
  6128. rng2.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_end" style="' + styles + '">' + chr + '</span>');
  6129. }
  6130. } catch (ex) {
  6131. // IE might throw unspecified error so lets ignore it
  6132. return null;
  6133. }
  6134. } else {
  6135. // Control selection
  6136. element = rng.item(0);
  6137. name = element.nodeName;
  6138. return {name : name, index : findIndex(name, element)};
  6139. }
  6140. } else {
  6141. element = t.getNode();
  6142. name = element.nodeName;
  6143. if (name == 'IMG')
  6144. return {name : name, index : findIndex(name, element)};
  6145. // W3C method
  6146. rng2 = rng.cloneRange();
  6147. // Insert end marker
  6148. if (!collapsed) {
  6149. rng2.collapse(false);
  6150. rng2.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_end', style : styles}, chr));
  6151. }
  6152. rng.collapse(true);
  6153. rng.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_start', style : styles}, chr));
  6154. }
  6155. t.moveToBookmark({id : id, keep : 1});
  6156. return {id : id};
  6157. },
  6158. moveToBookmark : function(bookmark) {
  6159. var t = this, dom = t.dom, marker1, marker2, rng, root, startContainer, endContainer, startOffset, endOffset;
  6160. if (bookmark) {
  6161. if (bookmark.start) {
  6162. rng = dom.createRng();
  6163. root = dom.getRoot();
  6164. function setEndPoint(start) {
  6165. var point = bookmark[start ? 'start' : 'end'], i, node, offset, children;
  6166. if (point) {
  6167. offset = point[0];
  6168. // Find container node
  6169. for (node = root, i = point.length - 1; i >= 1; i--) {
  6170. children = node.childNodes;
  6171. if (point[i] > children.length - 1)
  6172. return;
  6173. node = children[point[i]];
  6174. }
  6175. // Move text offset to best suitable location
  6176. if (node.nodeType === 3)
  6177. offset = Math.min(point[0], node.nodeValue.length);
  6178. // Move element offset to best suitable location
  6179. if (node.nodeType === 1)
  6180. offset = Math.min(point[0], node.childNodes.length);
  6181. // Set offset within container node
  6182. if (start)
  6183. rng.setStart(node, offset);
  6184. else
  6185. rng.setEnd(node, offset);
  6186. }
  6187. return true;
  6188. };
  6189. if (t.tridentSel)
  6190. return t.tridentSel.moveToBookmark(bookmark);
  6191. if (setEndPoint(true) && setEndPoint()) {
  6192. t.setRng(rng);
  6193. }
  6194. } else if (bookmark.id) {
  6195. function restoreEndPoint(suffix) {
  6196. var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep;
  6197. if (marker) {
  6198. node = marker.parentNode;
  6199. if (suffix == 'start') {
  6200. if (!keep) {
  6201. idx = dom.nodeIndex(marker);
  6202. } else {
  6203. node = marker.firstChild;
  6204. idx = 1;
  6205. }
  6206. startContainer = endContainer = node;
  6207. startOffset = endOffset = idx;
  6208. } else {
  6209. if (!keep) {
  6210. idx = dom.nodeIndex(marker);
  6211. } else {
  6212. node = marker.firstChild;
  6213. idx = 1;
  6214. }
  6215. endContainer = node;
  6216. endOffset = idx;
  6217. }
  6218. if (!keep) {
  6219. prev = marker.previousSibling;
  6220. next = marker.nextSibling;
  6221. // Remove all marker text nodes
  6222. each(tinymce.grep(marker.childNodes), function(node) {
  6223. if (node.nodeType == 3)
  6224. node.nodeValue = node.nodeValue.replace(/\uFEFF/g, '');
  6225. });
  6226. // Remove marker but keep children if for example contents where inserted into the marker
  6227. // Also remove duplicated instances of the marker for example by a split operation or by WebKit auto split on paste feature
  6228. while (marker = dom.get(bookmark.id + '_' + suffix))
  6229. dom.remove(marker, 1);
  6230. // If siblings are text nodes then merge them unless it's Opera since it some how removes the node
  6231. // and we are sniffing since adding a lot of detection code for a browser with 3% of the market isn't worth the effort. Sorry, Opera but it's just a fact
  6232. if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3 && !tinymce.isOpera) {
  6233. idx = prev.nodeValue.length;
  6234. prev.appendData(next.nodeValue);
  6235. dom.remove(next);
  6236. if (suffix == 'start') {
  6237. startContainer = endContainer = prev;
  6238. startOffset = endOffset = idx;
  6239. } else {
  6240. endContainer = prev;
  6241. endOffset = idx;
  6242. }
  6243. }
  6244. }
  6245. }
  6246. };
  6247. function addBogus(node) {
  6248. // Adds a bogus BR element for empty block elements or just a space on IE since it renders BR elements incorrectly
  6249. if (dom.isBlock(node) && !node.innerHTML)
  6250. node.innerHTML = !isIE ? '<br data-mce-bogus="1" />' : ' ';
  6251. return node;
  6252. };
  6253. // Restore start/end points
  6254. restoreEndPoint('start');
  6255. restoreEndPoint('end');
  6256. if (startContainer) {
  6257. rng = dom.createRng();
  6258. rng.setStart(addBogus(startContainer), startOffset);
  6259. rng.setEnd(addBogus(endContainer), endOffset);
  6260. t.setRng(rng);
  6261. }
  6262. } else if (bookmark.name) {
  6263. t.select(dom.select(bookmark.name)[bookmark.index]);
  6264. } else if (bookmark.rng)
  6265. t.setRng(bookmark.rng);
  6266. }
  6267. },
  6268. select : function(node, content) {
  6269. var t = this, dom = t.dom, rng = dom.createRng(), idx;
  6270. if (node) {
  6271. idx = dom.nodeIndex(node);
  6272. rng.setStart(node.parentNode, idx);
  6273. rng.setEnd(node.parentNode, idx + 1);
  6274. // Find first/last text node or BR element
  6275. if (content) {
  6276. function setPoint(node, start) {
  6277. var walker = new tinymce.dom.TreeWalker(node, node);
  6278. do {
  6279. // Text node
  6280. if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) {
  6281. if (start)
  6282. rng.setStart(node, 0);
  6283. else
  6284. rng.setEnd(node, node.nodeValue.length);
  6285. return;
  6286. }
  6287. // BR element
  6288. if (node.nodeName == 'BR') {
  6289. if (start)
  6290. rng.setStartBefore(node);
  6291. else
  6292. rng.setEndBefore(node);
  6293. return;
  6294. }
  6295. } while (node = (start ? walker.next() : walker.prev()));
  6296. };
  6297. setPoint(node, 1);
  6298. setPoint(node);
  6299. }
  6300. t.setRng(rng);
  6301. }
  6302. return node;
  6303. },
  6304. isCollapsed : function() {
  6305. var t = this, r = t.getRng(), s = t.getSel();
  6306. if (!r || r.item)
  6307. return false;
  6308. if (r.compareEndPoints)
  6309. return r.compareEndPoints('StartToEnd', r) === 0;
  6310. return !s || r.collapsed;
  6311. },
  6312. collapse : function(to_start) {
  6313. var self = this, rng = self.getRng(), node;
  6314. // Control range on IE
  6315. if (rng.item) {
  6316. node = rng.item(0);
  6317. rng = self.win.document.body.createTextRange();
  6318. rng.moveToElementText(node);
  6319. }
  6320. rng.collapse(!!to_start);
  6321. self.setRng(rng);
  6322. },
  6323. getSel : function() {
  6324. var t = this, w = this.win;
  6325. return w.getSelection ? w.getSelection() : w.document.selection;
  6326. },
  6327. getRng : function(w3c) {
  6328. var t = this, s, r, elm, doc = t.win.document;
  6329. // Found tridentSel object then we need to use that one
  6330. if (w3c && t.tridentSel)
  6331. return t.tridentSel.getRangeAt(0);
  6332. try {
  6333. if (s = t.getSel())
  6334. r = s.rangeCount > 0 ? s.getRangeAt(0) : (s.createRange ? s.createRange() : doc.createRange());
  6335. } catch (ex) {
  6336. // IE throws unspecified error here if TinyMCE is placed in a frame/iframe
  6337. }
  6338. // We have W3C ranges and it's IE then fake control selection since IE9 doesn't handle that correctly yet
  6339. if (tinymce.isIE && r && r.setStart && doc.selection.createRange().item) {
  6340. elm = doc.selection.createRange().item(0);
  6341. r = doc.createRange();
  6342. r.setStartBefore(elm);
  6343. r.setEndAfter(elm);
  6344. }
  6345. // No range found then create an empty one
  6346. // This can occur when the editor is placed in a hidden container element on Gecko
  6347. // Or on IE when there was an exception
  6348. if (!r)
  6349. r = doc.createRange ? doc.createRange() : doc.body.createTextRange();
  6350. if (t.selectedRange && t.explicitRange) {
  6351. if (r.compareBoundaryPoints(r.START_TO_START, t.selectedRange) === 0 && r.compareBoundaryPoints(r.END_TO_END, t.selectedRange) === 0) {
  6352. // Safari, Opera and Chrome only ever select text which causes the range to change.
  6353. // This lets us use the originally set range if the selection hasn't been changed by the user.
  6354. r = t.explicitRange;
  6355. } else {
  6356. t.selectedRange = null;
  6357. t.explicitRange = null;
  6358. }
  6359. }
  6360. return r;
  6361. },
  6362. setRng : function(r) {
  6363. var s, t = this;
  6364. if (!t.tridentSel) {
  6365. s = t.getSel();
  6366. if (s) {
  6367. t.explicitRange = r;
  6368. try {
  6369. s.removeAllRanges();
  6370. } catch (ex) {
  6371. // IE9 might throw errors here don't know why
  6372. }
  6373. s.addRange(r);
  6374. t.selectedRange = s.getRangeAt(0);
  6375. }
  6376. } else {
  6377. // Is W3C Range
  6378. if (r.cloneRange) {
  6379. t.tridentSel.addRange(r);
  6380. return;
  6381. }
  6382. // Is IE specific range
  6383. try {
  6384. r.select();
  6385. } catch (ex) {
  6386. // Needed for some odd IE bug #1843306
  6387. }
  6388. }
  6389. },
  6390. setNode : function(n) {
  6391. var t = this;
  6392. t.setContent(t.dom.getOuterHTML(n));
  6393. return n;
  6394. },
  6395. getNode : function() {
  6396. var t = this, rng = t.getRng(), sel = t.getSel(), elm, start = rng.startContainer, end = rng.endContainer;
  6397. // Range maybe lost after the editor is made visible again
  6398. if (!rng)
  6399. return t.dom.getRoot();
  6400. if (rng.setStart) {
  6401. elm = rng.commonAncestorContainer;
  6402. // Handle selection a image or other control like element such as anchors
  6403. if (!rng.collapsed) {
  6404. if (rng.startContainer == rng.endContainer) {
  6405. if (rng.endOffset - rng.startOffset < 2) {
  6406. if (rng.startContainer.hasChildNodes())
  6407. elm = rng.startContainer.childNodes[rng.startOffset];
  6408. }
  6409. }
  6410. // If the anchor node is a element instead of a text node then return this element
  6411. //if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1)
  6412. // return sel.anchorNode.childNodes[sel.anchorOffset];
  6413. // Handle cases where the selection is immediately wrapped around a node and return that node instead of it's parent.
  6414. // This happens when you double click an underlined word in FireFox.
  6415. if (start.nodeType === 3 && end.nodeType === 3) {
  6416. function skipEmptyTextNodes(n, forwards) {
  6417. var orig = n;
  6418. while (n && n.nodeType === 3 && n.length === 0) {
  6419. n = forwards ? n.nextSibling : n.previousSibling;
  6420. }
  6421. return n || orig;
  6422. }
  6423. if (start.length === rng.startOffset) {
  6424. start = skipEmptyTextNodes(start.nextSibling, true);
  6425. } else {
  6426. start = start.parentNode;
  6427. }
  6428. if (rng.endOffset === 0) {
  6429. end = skipEmptyTextNodes(end.previousSibling, false);
  6430. } else {
  6431. end = end.parentNode;
  6432. }
  6433. if (start && start === end)
  6434. return start;
  6435. }
  6436. }
  6437. if (elm && elm.nodeType == 3)
  6438. return elm.parentNode;
  6439. return elm;
  6440. }
  6441. return rng.item ? rng.item(0) : rng.parentElement();
  6442. },
  6443. getSelectedBlocks : function(st, en) {
  6444. var t = this, dom = t.dom, sb, eb, n, bl = [];
  6445. sb = dom.getParent(st || t.getStart(), dom.isBlock);
  6446. eb = dom.getParent(en || t.getEnd(), dom.isBlock);
  6447. if (sb)
  6448. bl.push(sb);
  6449. if (sb && eb && sb != eb) {
  6450. n = sb;
  6451. var walker = new tinymce.dom.TreeWalker(sb, dom.getRoot());
  6452. while ((n = walker.next()) && n != eb) {
  6453. if (dom.isBlock(n))
  6454. bl.push(n);
  6455. }
  6456. }
  6457. if (eb && sb != eb)
  6458. bl.push(eb);
  6459. return bl;
  6460. },
  6461. normalize : function() {
  6462. var self = this, rng, normalized;
  6463. // Normalize only on non IE browsers for now
  6464. if (tinymce.isIE)
  6465. return;
  6466. function normalizeEndPoint(start) {
  6467. var container, offset, walker, dom = self.dom, body = dom.getRoot(), node;
  6468. container = rng[(start ? 'start' : 'end') + 'Container'];
  6469. offset = rng[(start ? 'start' : 'end') + 'Offset'];
  6470. // If the container is a document move it to the body element
  6471. if (container.nodeType === 9) {
  6472. container = container.body;
  6473. offset = 0;
  6474. }
  6475. // If the container is body try move it into the closest text node or position
  6476. // TODO: Add more logic here to handle element selection cases
  6477. if (container === body) {
  6478. // Resolve the index
  6479. if (container.hasChildNodes()) {
  6480. container = container.childNodes[Math.min(!start && offset > 0 ? offset - 1 : offset, container.childNodes.length - 1)];
  6481. offset = 0;
  6482. // Don't walk into elements that doesn't have any child nodes like a IMG
  6483. if (container.hasChildNodes()) {
  6484. // Walk the DOM to find a text node to place the caret at or a BR
  6485. node = container;
  6486. walker = new tinymce.dom.TreeWalker(container, body);
  6487. do {
  6488. // Found a text node use that position
  6489. if (node.nodeType === 3) {
  6490. offset = start ? 0 : node.nodeValue.length - 1;
  6491. container = node;
  6492. break;
  6493. }
  6494. // Found a BR element that we can place the caret before
  6495. if (node.nodeName === 'BR') {
  6496. offset = dom.nodeIndex(node);
  6497. container = node.parentNode;
  6498. break;
  6499. }
  6500. } while (node = (start ? walker.next() : walker.prev()));
  6501. normalized = true;
  6502. }
  6503. }
  6504. }
  6505. // Set endpoint if it was normalized
  6506. if (normalized)
  6507. rng['set' + (start ? 'Start' : 'End')](container, offset);
  6508. };
  6509. rng = self.getRng();
  6510. // Normalize the end points
  6511. normalizeEndPoint(true);
  6512. if (rng.collapsed)
  6513. normalizeEndPoint();
  6514. // Set the selection if it was normalized
  6515. if (normalized) {
  6516. //console.log(self.dom.dumpRng(rng));
  6517. self.setRng(rng);
  6518. }
  6519. },
  6520. destroy : function(s) {
  6521. var t = this;
  6522. t.win = null;
  6523. // Manual destroy then remove unload handler
  6524. if (!s)
  6525. tinymce.removeUnload(t.destroy);
  6526. },
  6527. // IE has an issue where you can't select/move the caret by clicking outside the body if the document is in standards mode
  6528. _fixIESelection : function() {
  6529. var dom = this.dom, doc = dom.doc, body = doc.body, started, startRng, htmlElm;
  6530. // Make HTML element unselectable since we are going to handle selection by hand
  6531. doc.documentElement.unselectable = true;
  6532. // Return range from point or null if it failed
  6533. function rngFromPoint(x, y) {
  6534. var rng = body.createTextRange();
  6535. try {
  6536. rng.moveToPoint(x, y);
  6537. } catch (ex) {
  6538. // IE sometimes throws and exception, so lets just ignore it
  6539. rng = null;
  6540. }
  6541. return rng;
  6542. };
  6543. // Fires while the selection is changing
  6544. function selectionChange(e) {
  6545. var pointRng;
  6546. // Check if the button is down or not
  6547. if (e.button) {
  6548. // Create range from mouse position
  6549. pointRng = rngFromPoint(e.x, e.y);
  6550. if (pointRng) {
  6551. // Check if pointRange is before/after selection then change the endPoint
  6552. if (pointRng.compareEndPoints('StartToStart', startRng) > 0)
  6553. pointRng.setEndPoint('StartToStart', startRng);
  6554. else
  6555. pointRng.setEndPoint('EndToEnd', startRng);
  6556. pointRng.select();
  6557. }
  6558. } else
  6559. endSelection();
  6560. }
  6561. // Removes listeners
  6562. function endSelection() {
  6563. var rng = doc.selection.createRange();
  6564. // If the range is collapsed then use the last start range
  6565. if (startRng && !rng.item && rng.compareEndPoints('StartToEnd', rng) === 0)
  6566. startRng.select();
  6567. dom.unbind(doc, 'mouseup', endSelection);
  6568. dom.unbind(doc, 'mousemove', selectionChange);
  6569. startRng = started = 0;
  6570. };
  6571. // Detect when user selects outside BODY
  6572. dom.bind(doc, ['mousedown', 'contextmenu'], function(e) {
  6573. if (e.target.nodeName === 'HTML') {
  6574. if (started)
  6575. endSelection();
  6576. // Detect vertical scrollbar, since IE will fire a mousedown on the scrollbar and have target set as HTML
  6577. htmlElm = doc.documentElement;
  6578. if (htmlElm.scrollHeight > htmlElm.clientHeight)
  6579. return;
  6580. started = 1;
  6581. // Setup start position
  6582. startRng = rngFromPoint(e.x, e.y);
  6583. if (startRng) {
  6584. // Listen for selection change events
  6585. dom.bind(doc, 'mouseup', endSelection);
  6586. dom.bind(doc, 'mousemove', selectionChange);
  6587. dom.win.focus();
  6588. startRng.select();
  6589. }
  6590. }
  6591. });
  6592. }
  6593. });
  6594. })(tinymce);
  6595. (function(tinymce) {
  6596. tinymce.dom.Serializer = function(settings, dom, schema) {
  6597. var onPreProcess, onPostProcess, isIE = tinymce.isIE, each = tinymce.each, htmlParser;
  6598. // Support the old apply_source_formatting option
  6599. if (!settings.apply_source_formatting)
  6600. settings.indent = false;
  6601. settings.remove_trailing_brs = true;
  6602. // Default DOM and Schema if they are undefined
  6603. dom = dom || tinymce.DOM;
  6604. schema = schema || new tinymce.html.Schema(settings);
  6605. settings.entity_encoding = settings.entity_encoding || 'named';
  6606. onPreProcess = new tinymce.util.Dispatcher(self);
  6607. onPostProcess = new tinymce.util.Dispatcher(self);
  6608. htmlParser = new tinymce.html.DomParser(settings, schema);
  6609. // Convert move data-mce-src, data-mce-href and data-mce-style into nodes or process them if needed
  6610. htmlParser.addAttributeFilter('src,href,style', function(nodes, name) {
  6611. var i = nodes.length, node, value, internalName = 'data-mce-' + name, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope, undef;
  6612. while (i--) {
  6613. node = nodes[i];
  6614. value = node.attributes.map[internalName];
  6615. if (value !== undef) {
  6616. // Set external name to internal value and remove internal
  6617. node.attr(name, value.length > 0 ? value : null);
  6618. node.attr(internalName, null);
  6619. } else {
  6620. // No internal attribute found then convert the value we have in the DOM
  6621. value = node.attributes.map[name];
  6622. if (name === "style")
  6623. value = dom.serializeStyle(dom.parseStyle(value), node.name);
  6624. else if (urlConverter)
  6625. value = urlConverter.call(urlConverterScope, value, name, node.name);
  6626. node.attr(name, value.length > 0 ? value : null);
  6627. }
  6628. }
  6629. });
  6630. // Remove internal classes mceItem<..>
  6631. htmlParser.addAttributeFilter('class', function(nodes, name) {
  6632. var i = nodes.length, node, value;
  6633. while (i--) {
  6634. node = nodes[i];
  6635. value = node.attr('class').replace(/\s*mce(Item\w+|Selected)\s*/g, '');
  6636. node.attr('class', value.length > 0 ? value : null);
  6637. }
  6638. });
  6639. // Remove bookmark elements
  6640. htmlParser.addAttributeFilter('data-mce-type', function(nodes, name, args) {
  6641. var i = nodes.length, node;
  6642. while (i--) {
  6643. node = nodes[i];
  6644. if (node.attributes.map['data-mce-type'] === 'bookmark' && !args.cleanup)
  6645. node.remove();
  6646. }
  6647. });
  6648. // Force script into CDATA sections and remove the mce- prefix also add comments around styles
  6649. htmlParser.addNodeFilter('script,style', function(nodes, name) {
  6650. var i = nodes.length, node, value;
  6651. function trim(value) {
  6652. return value.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n')
  6653. .replace(/^[\r\n]*|[\r\n]*$/g, '')
  6654. .replace(/^\s*(\/\/\s*<!--|\/\/\s*<!\[CDATA\[|<!--|<!\[CDATA\[)[\r\n]*/g, '')
  6655. .replace(/\s*(\/\/\s*\]\]>|\/\/\s*-->|\]\]>|-->|\]\]-->)\s*$/g, '');
  6656. };
  6657. while (i--) {
  6658. node = nodes[i];
  6659. value = node.firstChild ? node.firstChild.value : '';
  6660. if (name === "script") {
  6661. // Remove mce- prefix from script elements
  6662. node.attr('type', (node.attr('type') || 'text/javascript').replace(/^mce\-/, ''));
  6663. if (value.length > 0)
  6664. node.firstChild.value = '// <![CDATA[\n' + trim(value) + '\n// ]]>';
  6665. } else {
  6666. if (value.length > 0)
  6667. node.firstChild.value = '<!--\n' + trim(value) + '\n-->';
  6668. }
  6669. }
  6670. });
  6671. // Convert comments to cdata and handle protected comments
  6672. htmlParser.addNodeFilter('#comment', function(nodes, name) {
  6673. var i = nodes.length, node;
  6674. while (i--) {
  6675. node = nodes[i];
  6676. if (node.value.indexOf('[CDATA[') === 0) {
  6677. node.name = '#cdata';
  6678. node.type = 4;
  6679. node.value = node.value.replace(/^\[CDATA\[|\]\]$/g, '');
  6680. } else if (node.value.indexOf('mce:protected ') === 0) {
  6681. node.name = "#text";
  6682. node.type = 3;
  6683. node.raw = true;
  6684. node.value = unescape(node.value).substr(14);
  6685. }
  6686. }
  6687. });
  6688. htmlParser.addNodeFilter('xml:namespace,input', function(nodes, name) {
  6689. var i = nodes.length, node;
  6690. while (i--) {
  6691. node = nodes[i];
  6692. if (node.type === 7)
  6693. node.remove();
  6694. else if (node.type === 1) {
  6695. if (name === "input" && !("type" in node.attributes.map))
  6696. node.attr('type', 'text');
  6697. }
  6698. }
  6699. });
  6700. // Fix list elements, TODO: Replace this later
  6701. if (settings.fix_list_elements) {
  6702. htmlParser.addNodeFilter('ul,ol', function(nodes, name) {
  6703. var i = nodes.length, node, parentNode;
  6704. while (i--) {
  6705. node = nodes[i];
  6706. parentNode = node.parent;
  6707. if (parentNode.name === 'ul' || parentNode.name === 'ol') {
  6708. if (node.prev && node.prev.name === 'li') {
  6709. node.prev.append(node);
  6710. }
  6711. }
  6712. }
  6713. });
  6714. }
  6715. // Remove internal data attributes
  6716. htmlParser.addAttributeFilter('data-mce-src,data-mce-href,data-mce-style', function(nodes, name) {
  6717. var i = nodes.length;
  6718. while (i--) {
  6719. nodes[i].attr(name, null);
  6720. }
  6721. });
  6722. // Return public methods
  6723. return {
  6724. schema : schema,
  6725. addNodeFilter : htmlParser.addNodeFilter,
  6726. addAttributeFilter : htmlParser.addAttributeFilter,
  6727. onPreProcess : onPreProcess,
  6728. onPostProcess : onPostProcess,
  6729. serialize : function(node, args) {
  6730. var impl, doc, oldDoc, htmlSerializer, content;
  6731. // Explorer won't clone contents of script and style and the
  6732. // selected index of select elements are cleared on a clone operation.
  6733. if (isIE && dom.select('script,style,select,map').length > 0) {
  6734. content = node.innerHTML;
  6735. node = node.cloneNode(false);
  6736. dom.setHTML(node, content);
  6737. } else
  6738. node = node.cloneNode(true);
  6739. // Nodes needs to be attached to something in WebKit/Opera
  6740. // Older builds of Opera crashes if you attach the node to an document created dynamically
  6741. // and since we can't feature detect a crash we need to sniff the acutal build number
  6742. // This fix will make DOM ranges and make Sizzle happy!
  6743. impl = node.ownerDocument.implementation;
  6744. if (impl.createHTMLDocument) {
  6745. // Create an empty HTML document
  6746. doc = impl.createHTMLDocument("");
  6747. // Add the element or it's children if it's a body element to the new document
  6748. each(node.nodeName == 'BODY' ? node.childNodes : [node], function(node) {
  6749. doc.body.appendChild(doc.importNode(node, true));
  6750. });
  6751. // Grab first child or body element for serialization
  6752. if (node.nodeName != 'BODY')
  6753. node = doc.body.firstChild;
  6754. else
  6755. node = doc.body;
  6756. // set the new document in DOMUtils so createElement etc works
  6757. oldDoc = dom.doc;
  6758. dom.doc = doc;
  6759. }
  6760. args = args || {};
  6761. args.format = args.format || 'html';
  6762. // Pre process
  6763. if (!args.no_events) {
  6764. args.node = node;
  6765. onPreProcess.dispatch(self, args);
  6766. }
  6767. // Setup serializer
  6768. htmlSerializer = new tinymce.html.Serializer(settings, schema);
  6769. // Parse and serialize HTML
  6770. args.content = htmlSerializer.serialize(
  6771. htmlParser.parse(args.getInner ? node.innerHTML : tinymce.trim(dom.getOuterHTML(node), args), args)
  6772. );
  6773. // Replace all BOM characters for now until we can find a better solution
  6774. if (!args.cleanup)
  6775. args.content = args.content.replace(/\uFEFF|\u200B/g, '');
  6776. // Post process
  6777. if (!args.no_events)
  6778. onPostProcess.dispatch(self, args);
  6779. // Restore the old document if it was changed
  6780. if (oldDoc)
  6781. dom.doc = oldDoc;
  6782. args.node = null;
  6783. return args.content;
  6784. },
  6785. addRules : function(rules) {
  6786. schema.addValidElements(rules);
  6787. },
  6788. setRules : function(rules) {
  6789. schema.setValidElements(rules);
  6790. }
  6791. };
  6792. };
  6793. })(tinymce);
  6794. (function(tinymce) {
  6795. tinymce.dom.ScriptLoader = function(settings) {
  6796. var QUEUED = 0,
  6797. LOADING = 1,
  6798. LOADED = 2,
  6799. states = {},
  6800. queue = [],
  6801. scriptLoadedCallbacks = {},
  6802. queueLoadedCallbacks = [],
  6803. loading = 0,
  6804. undefined;
  6805. function loadScript(url, callback) {
  6806. var t = this, dom = tinymce.DOM, elm, uri, loc, id;
  6807. // Execute callback when script is loaded
  6808. function done() {
  6809. dom.remove(id);
  6810. if (elm)
  6811. elm.onreadystatechange = elm.onload = elm = null;
  6812. callback();
  6813. };
  6814. function error() {
  6815. // Report the error so it's easier for people to spot loading errors
  6816. if (typeof(console) !== "undefined" && console.log)
  6817. console.log("Failed to load: " + url);
  6818. // We can't mark it as done if there is a load error since
  6819. // A) We don't want to produce 404 errors on the server and
  6820. // B) the onerror event won't fire on all browsers.
  6821. // done();
  6822. };
  6823. id = dom.uniqueId();
  6824. if (tinymce.isIE6) {
  6825. uri = new tinymce.util.URI(url);
  6826. loc = location;
  6827. // If script is from same domain and we
  6828. // use IE 6 then use XHR since it's more reliable
  6829. if (uri.host == loc.hostname && uri.port == loc.port && (uri.protocol + ':') == loc.protocol && uri.protocol.toLowerCase() != 'file') {
  6830. tinymce.util.XHR.send({
  6831. url : tinymce._addVer(uri.getURI()),
  6832. success : function(content) {
  6833. // Create new temp script element
  6834. var script = dom.create('script', {
  6835. type : 'text/javascript'
  6836. });
  6837. // Evaluate script in global scope
  6838. script.text = content;
  6839. document.getElementsByTagName('head')[0].appendChild(script);
  6840. dom.remove(script);
  6841. done();
  6842. },
  6843. error : error
  6844. });
  6845. return;
  6846. }
  6847. }
  6848. // Create new script element
  6849. elm = dom.create('script', {
  6850. id : id,
  6851. type : 'text/javascript',
  6852. src : tinymce._addVer(url)
  6853. });
  6854. // Add onload listener for non IE browsers since IE9
  6855. // fires onload event before the script is parsed and executed
  6856. if (!tinymce.isIE)
  6857. elm.onload = done;
  6858. // Add onerror event will get fired on some browsers but not all of them
  6859. elm.onerror = error;
  6860. // Opera 9.60 doesn't seem to fire the onreadystate event at correctly
  6861. if (!tinymce.isOpera) {
  6862. elm.onreadystatechange = function() {
  6863. var state = elm.readyState;
  6864. // Loaded state is passed on IE 6 however there
  6865. // are known issues with this method but we can't use
  6866. // XHR in a cross domain loading
  6867. if (state == 'complete' || state == 'loaded')
  6868. done();
  6869. };
  6870. }
  6871. // Most browsers support this feature so we report errors
  6872. // for those at least to help users track their missing plugins etc
  6873. // todo: Removed since it produced error if the document is unloaded by navigating away, re-add it as an option
  6874. /*elm.onerror = function() {
  6875. alert('Failed to load: ' + url);
  6876. };*/
  6877. // Add script to document
  6878. (document.getElementsByTagName('head')[0] || document.body).appendChild(elm);
  6879. };
  6880. this.isDone = function(url) {
  6881. return states[url] == LOADED;
  6882. };
  6883. this.markDone = function(url) {
  6884. states[url] = LOADED;
  6885. };
  6886. this.add = this.load = function(url, callback, scope) {
  6887. var item, state = states[url];
  6888. // Add url to load queue
  6889. if (state == undefined) {
  6890. queue.push(url);
  6891. states[url] = QUEUED;
  6892. }
  6893. if (callback) {
  6894. // Store away callback for later execution
  6895. if (!scriptLoadedCallbacks[url])
  6896. scriptLoadedCallbacks[url] = [];
  6897. scriptLoadedCallbacks[url].push({
  6898. func : callback,
  6899. scope : scope || this
  6900. });
  6901. }
  6902. };
  6903. this.loadQueue = function(callback, scope) {
  6904. this.loadScripts(queue, callback, scope);
  6905. };
  6906. this.loadScripts = function(scripts, callback, scope) {
  6907. var loadScripts;
  6908. function execScriptLoadedCallbacks(url) {
  6909. // Execute URL callback functions
  6910. tinymce.each(scriptLoadedCallbacks[url], function(callback) {
  6911. callback.func.call(callback.scope);
  6912. });
  6913. scriptLoadedCallbacks[url] = undefined;
  6914. };
  6915. queueLoadedCallbacks.push({
  6916. func : callback,
  6917. scope : scope || this
  6918. });
  6919. loadScripts = function() {
  6920. var loadingScripts = tinymce.grep(scripts);
  6921. // Current scripts has been handled
  6922. scripts.length = 0;
  6923. // Load scripts that needs to be loaded
  6924. tinymce.each(loadingScripts, function(url) {
  6925. // Script is already loaded then execute script callbacks directly
  6926. if (states[url] == LOADED) {
  6927. execScriptLoadedCallbacks(url);
  6928. return;
  6929. }
  6930. // Is script not loading then start loading it
  6931. if (states[url] != LOADING) {
  6932. states[url] = LOADING;
  6933. loading++;
  6934. loadScript(url, function() {
  6935. states[url] = LOADED;
  6936. loading--;
  6937. execScriptLoadedCallbacks(url);
  6938. // Load more scripts if they where added by the recently loaded script
  6939. loadScripts();
  6940. });
  6941. }
  6942. });
  6943. // No scripts are currently loading then execute all pending queue loaded callbacks
  6944. if (!loading) {
  6945. tinymce.each(queueLoadedCallbacks, function(callback) {
  6946. callback.func.call(callback.scope);
  6947. });
  6948. queueLoadedCallbacks.length = 0;
  6949. }
  6950. };
  6951. loadScripts();
  6952. };
  6953. };
  6954. // Global script loader
  6955. tinymce.ScriptLoader = new tinymce.dom.ScriptLoader();
  6956. })(tinymce);
  6957. tinymce.dom.TreeWalker = function(start_node, root_node) {
  6958. var node = start_node;
  6959. function findSibling(node, start_name, sibling_name, shallow) {
  6960. var sibling, parent;
  6961. if (node) {
  6962. // Walk into nodes if it has a start
  6963. if (!shallow && node[start_name])
  6964. return node[start_name];
  6965. // Return the sibling if it has one
  6966. if (node != root_node) {
  6967. sibling = node[sibling_name];
  6968. if (sibling)
  6969. return sibling;
  6970. // Walk up the parents to look for siblings
  6971. for (parent = node.parentNode; parent && parent != root_node; parent = parent.parentNode) {
  6972. sibling = parent[sibling_name];
  6973. if (sibling)
  6974. return sibling;
  6975. }
  6976. }
  6977. }
  6978. };
  6979. this.current = function() {
  6980. return node;
  6981. };
  6982. this.next = function(shallow) {
  6983. return (node = findSibling(node, 'firstChild', 'nextSibling', shallow));
  6984. };
  6985. this.prev = function(shallow) {
  6986. return (node = findSibling(node, 'lastChild', 'previousSibling', shallow));
  6987. };
  6988. };
  6989. (function(tinymce) {
  6990. tinymce.dom.RangeUtils = function(dom) {
  6991. var INVISIBLE_CHAR = '\uFEFF';
  6992. this.walk = function(rng, callback) {
  6993. var startContainer = rng.startContainer,
  6994. startOffset = rng.startOffset,
  6995. endContainer = rng.endContainer,
  6996. endOffset = rng.endOffset,
  6997. ancestor, startPoint,
  6998. endPoint, node, parent, siblings, nodes;
  6999. // Handle table cell selection the table plugin enables
  7000. // you to fake select table cells and perform formatting actions on them
  7001. nodes = dom.select('td.mceSelected,th.mceSelected');
  7002. if (nodes.length > 0) {
  7003. tinymce.each(nodes, function(node) {
  7004. callback([node]);
  7005. });
  7006. return;
  7007. }
  7008. function exclude(nodes) {
  7009. var node;
  7010. // First node is excluded
  7011. node = nodes[0];
  7012. if (node.nodeType === 3 && node === startContainer && startOffset >= node.nodeValue.length) {
  7013. nodes.splice(0, 1);
  7014. }
  7015. // Last node is excluded
  7016. node = nodes[nodes.length - 1];
  7017. if (endOffset === 0 && nodes.length > 0 && node === endContainer && node.nodeType === 3) {
  7018. nodes.splice(nodes.length - 1, 1);
  7019. }
  7020. return nodes;
  7021. };
  7022. function collectSiblings(node, name, end_node) {
  7023. var siblings = [];
  7024. for (; node && node != end_node; node = node[name])
  7025. siblings.push(node);
  7026. return siblings;
  7027. };
  7028. function findEndPoint(node, root) {
  7029. do {
  7030. if (node.parentNode == root)
  7031. return node;
  7032. node = node.parentNode;
  7033. } while(node);
  7034. };
  7035. function walkBoundary(start_node, end_node, next) {
  7036. var siblingName = next ? 'nextSibling' : 'previousSibling';
  7037. for (node = start_node, parent = node.parentNode; node && node != end_node; node = parent) {
  7038. parent = node.parentNode;
  7039. siblings = collectSiblings(node == start_node ? node : node[siblingName], siblingName);
  7040. if (siblings.length) {
  7041. if (!next)
  7042. siblings.reverse();
  7043. callback(exclude(siblings));
  7044. }
  7045. }
  7046. };
  7047. // If index based start position then resolve it
  7048. if (startContainer.nodeType == 1 && startContainer.hasChildNodes())
  7049. startContainer = startContainer.childNodes[startOffset];
  7050. // If index based end position then resolve it
  7051. if (endContainer.nodeType == 1 && endContainer.hasChildNodes())
  7052. endContainer = endContainer.childNodes[Math.min(endOffset - 1, endContainer.childNodes.length - 1)];
  7053. // Same container
  7054. if (startContainer == endContainer)
  7055. return callback(exclude([startContainer]));
  7056. // Find common ancestor and end points
  7057. ancestor = dom.findCommonAncestor(startContainer, endContainer);
  7058. // Process left side
  7059. for (node = startContainer; node; node = node.parentNode) {
  7060. if (node === endContainer)
  7061. return walkBoundary(startContainer, ancestor, true);
  7062. if (node === ancestor)
  7063. break;
  7064. }
  7065. // Process right side
  7066. for (node = endContainer; node; node = node.parentNode) {
  7067. if (node === startContainer)
  7068. return walkBoundary(endContainer, ancestor);
  7069. if (node === ancestor)
  7070. break;
  7071. }
  7072. // Find start/end point
  7073. startPoint = findEndPoint(startContainer, ancestor) || startContainer;
  7074. endPoint = findEndPoint(endContainer, ancestor) || endContainer;
  7075. // Walk left leaf
  7076. walkBoundary(startContainer, startPoint, true);
  7077. // Walk the middle from start to end point
  7078. siblings = collectSiblings(
  7079. startPoint == startContainer ? startPoint : startPoint.nextSibling,
  7080. 'nextSibling',
  7081. endPoint == endContainer ? endPoint.nextSibling : endPoint
  7082. );
  7083. if (siblings.length)
  7084. callback(exclude(siblings));
  7085. // Walk right leaf
  7086. walkBoundary(endContainer, endPoint);
  7087. };
  7088. this.split = function(rng) {
  7089. var startContainer = rng.startContainer,
  7090. startOffset = rng.startOffset,
  7091. endContainer = rng.endContainer,
  7092. endOffset = rng.endOffset;
  7093. function splitText(node, offset) {
  7094. return node.splitText(offset);
  7095. };
  7096. // Handle single text node
  7097. if (startContainer == endContainer && startContainer.nodeType == 3) {
  7098. if (startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  7099. endContainer = splitText(startContainer, startOffset);
  7100. startContainer = endContainer.previousSibling;
  7101. if (endOffset > startOffset) {
  7102. endOffset = endOffset - startOffset;
  7103. startContainer = endContainer = splitText(endContainer, endOffset).previousSibling;
  7104. endOffset = endContainer.nodeValue.length;
  7105. startOffset = 0;
  7106. } else {
  7107. endOffset = 0;
  7108. }
  7109. }
  7110. } else {
  7111. // Split startContainer text node if needed
  7112. if (startContainer.nodeType == 3 && startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  7113. startContainer = splitText(startContainer, startOffset);
  7114. startOffset = 0;
  7115. }
  7116. // Split endContainer text node if needed
  7117. if (endContainer.nodeType == 3 && endOffset > 0 && endOffset < endContainer.nodeValue.length) {
  7118. endContainer = splitText(endContainer, endOffset).previousSibling;
  7119. endOffset = endContainer.nodeValue.length;
  7120. }
  7121. }
  7122. return {
  7123. startContainer : startContainer,
  7124. startOffset : startOffset,
  7125. endContainer : endContainer,
  7126. endOffset : endOffset
  7127. };
  7128. };
  7129. };
  7130. tinymce.dom.RangeUtils.compareRanges = function(rng1, rng2) {
  7131. if (rng1 && rng2) {
  7132. // Compare native IE ranges
  7133. if (rng1.item || rng1.duplicate) {
  7134. // Both are control ranges and the selected element matches
  7135. if (rng1.item && rng2.item && rng1.item(0) === rng2.item(0))
  7136. return true;
  7137. // Both are text ranges and the range matches
  7138. if (rng1.isEqual && rng2.isEqual && rng2.isEqual(rng1))
  7139. return true;
  7140. } else {
  7141. // Compare w3c ranges
  7142. return rng1.startContainer == rng2.startContainer && rng1.startOffset == rng2.startOffset;
  7143. }
  7144. }
  7145. return false;
  7146. };
  7147. })(tinymce);
  7148. (function(tinymce) {
  7149. var Event = tinymce.dom.Event, each = tinymce.each;
  7150. tinymce.create('tinymce.ui.KeyboardNavigation', {
  7151. KeyboardNavigation: function(settings, dom) {
  7152. var t = this, root = settings.root, items = settings.items,
  7153. enableUpDown = settings.enableUpDown, enableLeftRight = settings.enableLeftRight || !settings.enableUpDown,
  7154. excludeFromTabOrder = settings.excludeFromTabOrder,
  7155. itemFocussed, itemBlurred, rootKeydown, rootFocussed, focussedId;
  7156. dom = dom || tinymce.DOM;
  7157. itemFocussed = function(evt) {
  7158. focussedId = evt.target.id;
  7159. };
  7160. itemBlurred = function(evt) {
  7161. dom.setAttrib(evt.target.id, 'tabindex', '-1');
  7162. };
  7163. rootFocussed = function(evt) {
  7164. var item = dom.get(focussedId);
  7165. dom.setAttrib(item, 'tabindex', '0');
  7166. item.focus();
  7167. };
  7168. t.focus = function() {
  7169. dom.get(focussedId).focus();
  7170. };
  7171. t.destroy = function() {
  7172. each(items, function(item) {
  7173. dom.unbind(dom.get(item.id), 'focus', itemFocussed);
  7174. dom.unbind(dom.get(item.id), 'blur', itemBlurred);
  7175. });
  7176. dom.unbind(dom.get(root), 'focus', rootFocussed);
  7177. dom.unbind(dom.get(root), 'keydown', rootKeydown);
  7178. items = dom = root = t.focus = itemFocussed = itemBlurred = rootKeydown = rootFocussed = null;
  7179. t.destroy = function() {};
  7180. };
  7181. t.moveFocus = function(dir, evt) {
  7182. var idx = -1, controls = t.controls, newFocus;
  7183. if (!focussedId)
  7184. return;
  7185. each(items, function(item, index) {
  7186. if (item.id === focussedId) {
  7187. idx = index;
  7188. return false;
  7189. }
  7190. });
  7191. idx += dir;
  7192. if (idx < 0) {
  7193. idx = items.length - 1;
  7194. } else if (idx >= items.length) {
  7195. idx = 0;
  7196. }
  7197. newFocus = items[idx];
  7198. dom.setAttrib(focussedId, 'tabindex', '-1');
  7199. dom.setAttrib(newFocus.id, 'tabindex', '0');
  7200. dom.get(newFocus.id).focus();
  7201. if (settings.actOnFocus) {
  7202. settings.onAction(newFocus.id);
  7203. }
  7204. if (evt)
  7205. Event.cancel(evt);
  7206. };
  7207. rootKeydown = function(evt) {
  7208. var DOM_VK_LEFT = 37, DOM_VK_RIGHT = 39, DOM_VK_UP = 38, DOM_VK_DOWN = 40, DOM_VK_ESCAPE = 27, DOM_VK_ENTER = 14, DOM_VK_RETURN = 13, DOM_VK_SPACE = 32;
  7209. switch (evt.keyCode) {
  7210. case DOM_VK_LEFT:
  7211. if (enableLeftRight) t.moveFocus(-1);
  7212. break;
  7213. case DOM_VK_RIGHT:
  7214. if (enableLeftRight) t.moveFocus(1);
  7215. break;
  7216. case DOM_VK_UP:
  7217. if (enableUpDown) t.moveFocus(-1);
  7218. break;
  7219. case DOM_VK_DOWN:
  7220. if (enableUpDown) t.moveFocus(1);
  7221. break;
  7222. case DOM_VK_ESCAPE:
  7223. if (settings.onCancel) {
  7224. settings.onCancel();
  7225. Event.cancel(evt);
  7226. }
  7227. break;
  7228. case DOM_VK_ENTER:
  7229. case DOM_VK_RETURN:
  7230. case DOM_VK_SPACE:
  7231. if (settings.onAction) {
  7232. settings.onAction(focussedId);
  7233. Event.cancel(evt);
  7234. }
  7235. break;
  7236. }
  7237. };
  7238. // Set up state and listeners for each item.
  7239. each(items, function(item, idx) {
  7240. var tabindex;
  7241. if (!item.id) {
  7242. item.id = dom.uniqueId('_mce_item_');
  7243. }
  7244. if (excludeFromTabOrder) {
  7245. dom.bind(item.id, 'blur', itemBlurred);
  7246. tabindex = '-1';
  7247. } else {
  7248. tabindex = (idx === 0 ? '0' : '-1');
  7249. }
  7250. dom.setAttrib(item.id, 'tabindex', tabindex);
  7251. dom.bind(dom.get(item.id), 'focus', itemFocussed);
  7252. });
  7253. // Setup initial state for root element.
  7254. if (items[0]){
  7255. focussedId = items[0].id;
  7256. }
  7257. dom.setAttrib(root, 'tabindex', '-1');
  7258. // Setup listeners for root element.
  7259. dom.bind(dom.get(root), 'focus', rootFocussed);
  7260. dom.bind(dom.get(root), 'keydown', rootKeydown);
  7261. }
  7262. });
  7263. })(tinymce);
  7264. (function(tinymce) {
  7265. // Shorten class names
  7266. var DOM = tinymce.DOM, is = tinymce.is;
  7267. tinymce.create('tinymce.ui.Control', {
  7268. Control : function(id, s, editor) {
  7269. this.id = id;
  7270. this.settings = s = s || {};
  7271. this.rendered = false;
  7272. this.onRender = new tinymce.util.Dispatcher(this);
  7273. this.classPrefix = '';
  7274. this.scope = s.scope || this;
  7275. this.disabled = 0;
  7276. this.active = 0;
  7277. this.editor = editor;
  7278. },
  7279. setAriaProperty : function(property, value) {
  7280. var element = DOM.get(this.id + '_aria') || DOM.get(this.id);
  7281. if (element) {
  7282. DOM.setAttrib(element, 'aria-' + property, !!value);
  7283. }
  7284. },
  7285. focus : function() {
  7286. DOM.get(this.id).focus();
  7287. },
  7288. setDisabled : function(s) {
  7289. if (s != this.disabled) {
  7290. this.setAriaProperty('disabled', s);
  7291. this.setState('Disabled', s);
  7292. this.setState('Enabled', !s);
  7293. this.disabled = s;
  7294. }
  7295. },
  7296. isDisabled : function() {
  7297. return this.disabled;
  7298. },
  7299. setActive : function(s) {
  7300. if (s != this.active) {
  7301. this.setState('Active', s);
  7302. this.active = s;
  7303. this.setAriaProperty('pressed', s);
  7304. }
  7305. },
  7306. isActive : function() {
  7307. return this.active;
  7308. },
  7309. setState : function(c, s) {
  7310. var n = DOM.get(this.id);
  7311. c = this.classPrefix + c;
  7312. if (s)
  7313. DOM.addClass(n, c);
  7314. else
  7315. DOM.removeClass(n, c);
  7316. },
  7317. isRendered : function() {
  7318. return this.rendered;
  7319. },
  7320. renderHTML : function() {
  7321. },
  7322. renderTo : function(n) {
  7323. DOM.setHTML(n, this.renderHTML());
  7324. },
  7325. postRender : function() {
  7326. var t = this, b;
  7327. // Set pending states
  7328. if (is(t.disabled)) {
  7329. b = t.disabled;
  7330. t.disabled = -1;
  7331. t.setDisabled(b);
  7332. }
  7333. if (is(t.active)) {
  7334. b = t.active;
  7335. t.active = -1;
  7336. t.setActive(b);
  7337. }
  7338. },
  7339. remove : function() {
  7340. DOM.remove(this.id);
  7341. this.destroy();
  7342. },
  7343. destroy : function() {
  7344. tinymce.dom.Event.clear(this.id);
  7345. }
  7346. });
  7347. })(tinymce);
  7348. tinymce.create('tinymce.ui.Container:tinymce.ui.Control', {
  7349. Container : function(id, s, editor) {
  7350. this.parent(id, s, editor);
  7351. this.controls = [];
  7352. this.lookup = {};
  7353. },
  7354. add : function(c) {
  7355. this.lookup[c.id] = c;
  7356. this.controls.push(c);
  7357. return c;
  7358. },
  7359. get : function(n) {
  7360. return this.lookup[n];
  7361. }
  7362. });
  7363. tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', {
  7364. Separator : function(id, s) {
  7365. this.parent(id, s);
  7366. this.classPrefix = 'mceSeparator';
  7367. this.setDisabled(true);
  7368. },
  7369. renderHTML : function() {
  7370. return tinymce.DOM.createHTML('span', {'class' : this.classPrefix, role : 'separator', 'aria-orientation' : 'vertical', tabindex : '-1'});
  7371. }
  7372. });
  7373. (function(tinymce) {
  7374. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  7375. tinymce.create('tinymce.ui.MenuItem:tinymce.ui.Control', {
  7376. MenuItem : function(id, s) {
  7377. this.parent(id, s);
  7378. this.classPrefix = 'mceMenuItem';
  7379. },
  7380. setSelected : function(s) {
  7381. this.setState('Selected', s);
  7382. this.setAriaProperty('checked', !!s);
  7383. this.selected = s;
  7384. },
  7385. isSelected : function() {
  7386. return this.selected;
  7387. },
  7388. postRender : function() {
  7389. var t = this;
  7390. t.parent();
  7391. // Set pending state
  7392. if (is(t.selected))
  7393. t.setSelected(t.selected);
  7394. }
  7395. });
  7396. })(tinymce);
  7397. (function(tinymce) {
  7398. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  7399. tinymce.create('tinymce.ui.Menu:tinymce.ui.MenuItem', {
  7400. Menu : function(id, s) {
  7401. var t = this;
  7402. t.parent(id, s);
  7403. t.items = {};
  7404. t.collapsed = false;
  7405. t.menuCount = 0;
  7406. t.onAddItem = new tinymce.util.Dispatcher(this);
  7407. },
  7408. expand : function(d) {
  7409. var t = this;
  7410. if (d) {
  7411. walk(t, function(o) {
  7412. if (o.expand)
  7413. o.expand();
  7414. }, 'items', t);
  7415. }
  7416. t.collapsed = false;
  7417. },
  7418. collapse : function(d) {
  7419. var t = this;
  7420. if (d) {
  7421. walk(t, function(o) {
  7422. if (o.collapse)
  7423. o.collapse();
  7424. }, 'items', t);
  7425. }
  7426. t.collapsed = true;
  7427. },
  7428. isCollapsed : function() {
  7429. return this.collapsed;
  7430. },
  7431. add : function(o) {
  7432. if (!o.settings)
  7433. o = new tinymce.ui.MenuItem(o.id || DOM.uniqueId(), o);
  7434. this.onAddItem.dispatch(this, o);
  7435. return this.items[o.id] = o;
  7436. },
  7437. addSeparator : function() {
  7438. return this.add({separator : true});
  7439. },
  7440. addMenu : function(o) {
  7441. if (!o.collapse)
  7442. o = this.createMenu(o);
  7443. this.menuCount++;
  7444. return this.add(o);
  7445. },
  7446. hasMenus : function() {
  7447. return this.menuCount !== 0;
  7448. },
  7449. remove : function(o) {
  7450. delete this.items[o.id];
  7451. },
  7452. removeAll : function() {
  7453. var t = this;
  7454. walk(t, function(o) {
  7455. if (o.removeAll)
  7456. o.removeAll();
  7457. else
  7458. o.remove();
  7459. o.destroy();
  7460. }, 'items', t);
  7461. t.items = {};
  7462. },
  7463. createMenu : function(o) {
  7464. var m = new tinymce.ui.Menu(o.id || DOM.uniqueId(), o);
  7465. m.onAddItem.add(this.onAddItem.dispatch, this.onAddItem);
  7466. return m;
  7467. }
  7468. });
  7469. })(tinymce);
  7470. (function(tinymce) {
  7471. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event, Element = tinymce.dom.Element;
  7472. tinymce.create('tinymce.ui.DropMenu:tinymce.ui.Menu', {
  7473. DropMenu : function(id, s) {
  7474. s = s || {};
  7475. s.container = s.container || DOM.doc.body;
  7476. s.offset_x = s.offset_x || 0;
  7477. s.offset_y = s.offset_y || 0;
  7478. s.vp_offset_x = s.vp_offset_x || 0;
  7479. s.vp_offset_y = s.vp_offset_y || 0;
  7480. if (is(s.icons) && !s.icons)
  7481. s['class'] += ' mceNoIcons';
  7482. this.parent(id, s);
  7483. this.onShowMenu = new tinymce.util.Dispatcher(this);
  7484. this.onHideMenu = new tinymce.util.Dispatcher(this);
  7485. this.classPrefix = 'mceMenu';
  7486. },
  7487. createMenu : function(s) {
  7488. var t = this, cs = t.settings, m;
  7489. s.container = s.container || cs.container;
  7490. s.parent = t;
  7491. s.constrain = s.constrain || cs.constrain;
  7492. s['class'] = s['class'] || cs['class'];
  7493. s.vp_offset_x = s.vp_offset_x || cs.vp_offset_x;
  7494. s.vp_offset_y = s.vp_offset_y || cs.vp_offset_y;
  7495. s.keyboard_focus = cs.keyboard_focus;
  7496. m = new tinymce.ui.DropMenu(s.id || DOM.uniqueId(), s);
  7497. m.onAddItem.add(t.onAddItem.dispatch, t.onAddItem);
  7498. return m;
  7499. },
  7500. focus : function() {
  7501. var t = this;
  7502. if (t.keyboardNav) {
  7503. t.keyboardNav.focus();
  7504. }
  7505. },
  7506. update : function() {
  7507. var t = this, s = t.settings, tb = DOM.get('menu_' + t.id + '_tbl'), co = DOM.get('menu_' + t.id + '_co'), tw, th;
  7508. tw = s.max_width ? Math.min(tb.clientWidth, s.max_width) : tb.clientWidth;
  7509. th = s.max_height ? Math.min(tb.clientHeight, s.max_height) : tb.clientHeight;
  7510. if (!DOM.boxModel)
  7511. t.element.setStyles({width : tw + 2, height : th + 2});
  7512. else
  7513. t.element.setStyles({width : tw, height : th});
  7514. if (s.max_width)
  7515. DOM.setStyle(co, 'width', tw);
  7516. if (s.max_height) {
  7517. DOM.setStyle(co, 'height', th);
  7518. if (tb.clientHeight < s.max_height)
  7519. DOM.setStyle(co, 'overflow', 'hidden');
  7520. }
  7521. },
  7522. showMenu : function(x, y, px) {
  7523. var t = this, s = t.settings, co, vp = DOM.getViewPort(), w, h, mx, my, ot = 2, dm, tb, cp = t.classPrefix;
  7524. t.collapse(1);
  7525. if (t.isMenuVisible)
  7526. return;
  7527. if (!t.rendered) {
  7528. co = DOM.add(t.settings.container, t.renderNode());
  7529. each(t.items, function(o) {
  7530. o.postRender();
  7531. });
  7532. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  7533. } else
  7534. co = DOM.get('menu_' + t.id);
  7535. // Move layer out of sight unless it's Opera since it scrolls to top of page due to an bug
  7536. if (!tinymce.isOpera)
  7537. DOM.setStyles(co, {left : -0xFFFF , top : -0xFFFF});
  7538. DOM.show(co);
  7539. t.update();
  7540. x += s.offset_x || 0;
  7541. y += s.offset_y || 0;
  7542. vp.w -= 4;
  7543. vp.h -= 4;
  7544. // Move inside viewport if not submenu
  7545. if (s.constrain) {
  7546. w = co.clientWidth - ot;
  7547. h = co.clientHeight - ot;
  7548. mx = vp.x + vp.w;
  7549. my = vp.y + vp.h;
  7550. if ((x + s.vp_offset_x + w) > mx)
  7551. x = px ? px - w : Math.max(0, (mx - s.vp_offset_x) - w);
  7552. if ((y + s.vp_offset_y + h) > my)
  7553. y = Math.max(0, (my - s.vp_offset_y) - h);
  7554. }
  7555. DOM.setStyles(co, {left : x , top : y});
  7556. t.element.update();
  7557. t.isMenuVisible = 1;
  7558. t.mouseClickFunc = Event.add(co, 'click', function(e) {
  7559. var m;
  7560. e = e.target;
  7561. if (e && (e = DOM.getParent(e, 'tr')) && !DOM.hasClass(e, cp + 'ItemSub')) {
  7562. m = t.items[e.id];
  7563. if (m.isDisabled())
  7564. return;
  7565. dm = t;
  7566. while (dm) {
  7567. if (dm.hideMenu)
  7568. dm.hideMenu();
  7569. dm = dm.settings.parent;
  7570. }
  7571. if (m.settings.onclick)
  7572. m.settings.onclick(e);
  7573. return Event.cancel(e); // Cancel to fix onbeforeunload problem
  7574. }
  7575. });
  7576. if (t.hasMenus()) {
  7577. t.mouseOverFunc = Event.add(co, 'mouseover', function(e) {
  7578. var m, r, mi;
  7579. e = e.target;
  7580. if (e && (e = DOM.getParent(e, 'tr'))) {
  7581. m = t.items[e.id];
  7582. if (t.lastMenu)
  7583. t.lastMenu.collapse(1);
  7584. if (m.isDisabled())
  7585. return;
  7586. if (e && DOM.hasClass(e, cp + 'ItemSub')) {
  7587. //p = DOM.getPos(s.container);
  7588. r = DOM.getRect(e);
  7589. m.showMenu((r.x + r.w - ot), r.y - ot, r.x);
  7590. t.lastMenu = m;
  7591. DOM.addClass(DOM.get(m.id).firstChild, cp + 'ItemActive');
  7592. }
  7593. }
  7594. });
  7595. }
  7596. Event.add(co, 'keydown', t._keyHandler, t);
  7597. t.onShowMenu.dispatch(t);
  7598. if (s.keyboard_focus) {
  7599. t._setupKeyboardNav();
  7600. }
  7601. },
  7602. hideMenu : function(c) {
  7603. var t = this, co = DOM.get('menu_' + t.id), e;
  7604. if (!t.isMenuVisible)
  7605. return;
  7606. if (t.keyboardNav) t.keyboardNav.destroy();
  7607. Event.remove(co, 'mouseover', t.mouseOverFunc);
  7608. Event.remove(co, 'click', t.mouseClickFunc);
  7609. Event.remove(co, 'keydown', t._keyHandler);
  7610. DOM.hide(co);
  7611. t.isMenuVisible = 0;
  7612. if (!c)
  7613. t.collapse(1);
  7614. if (t.element)
  7615. t.element.hide();
  7616. if (e = DOM.get(t.id))
  7617. DOM.removeClass(e.firstChild, t.classPrefix + 'ItemActive');
  7618. t.onHideMenu.dispatch(t);
  7619. },
  7620. add : function(o) {
  7621. var t = this, co;
  7622. o = t.parent(o);
  7623. if (t.isRendered && (co = DOM.get('menu_' + t.id)))
  7624. t._add(DOM.select('tbody', co)[0], o);
  7625. return o;
  7626. },
  7627. collapse : function(d) {
  7628. this.parent(d);
  7629. this.hideMenu(1);
  7630. },
  7631. remove : function(o) {
  7632. DOM.remove(o.id);
  7633. this.destroy();
  7634. return this.parent(o);
  7635. },
  7636. destroy : function() {
  7637. var t = this, co = DOM.get('menu_' + t.id);
  7638. if (t.keyboardNav) t.keyboardNav.destroy();
  7639. Event.remove(co, 'mouseover', t.mouseOverFunc);
  7640. Event.remove(DOM.select('a', co), 'focus', t.mouseOverFunc);
  7641. Event.remove(co, 'click', t.mouseClickFunc);
  7642. Event.remove(co, 'keydown', t._keyHandler);
  7643. if (t.element)
  7644. t.element.remove();
  7645. DOM.remove(co);
  7646. },
  7647. renderNode : function() {
  7648. var t = this, s = t.settings, n, tb, co, w;
  7649. w = DOM.create('div', {role: 'listbox', id : 'menu_' + t.id, 'class' : s['class'], 'style' : 'position:absolute;left:0;top:0;z-index:200000;outline:0'});
  7650. if (t.settings.parent) {
  7651. DOM.setAttrib(w, 'aria-parent', 'menu_' + t.settings.parent.id);
  7652. }
  7653. co = DOM.add(w, 'div', {role: 'presentation', id : 'menu_' + t.id + '_co', 'class' : t.classPrefix + (s['class'] ? ' ' + s['class'] : '')});
  7654. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  7655. if (s.menu_line)
  7656. DOM.add(co, 'span', {'class' : t.classPrefix + 'Line'});
  7657. // n = DOM.add(co, 'div', {id : 'menu_' + t.id + '_co', 'class' : 'mceMenuContainer'});
  7658. n = DOM.add(co, 'table', {role: 'presentation', id : 'menu_' + t.id + '_tbl', border : 0, cellPadding : 0, cellSpacing : 0});
  7659. tb = DOM.add(n, 'tbody');
  7660. each(t.items, function(o) {
  7661. t._add(tb, o);
  7662. });
  7663. t.rendered = true;
  7664. return w;
  7665. },
  7666. // Internal functions
  7667. _setupKeyboardNav : function(){
  7668. var contextMenu, menuItems, t=this;
  7669. contextMenu = DOM.select('#menu_' + t.id)[0];
  7670. menuItems = DOM.select('a[role=option]', 'menu_' + t.id);
  7671. menuItems.splice(0,0,contextMenu);
  7672. t.keyboardNav = new tinymce.ui.KeyboardNavigation({
  7673. root: 'menu_' + t.id,
  7674. items: menuItems,
  7675. onCancel: function() {
  7676. t.hideMenu();
  7677. },
  7678. enableUpDown: true
  7679. });
  7680. contextMenu.focus();
  7681. },
  7682. _keyHandler : function(evt) {
  7683. var t = this, e;
  7684. switch (evt.keyCode) {
  7685. case 37: // Left
  7686. if (t.settings.parent) {
  7687. t.hideMenu();
  7688. t.settings.parent.focus();
  7689. Event.cancel(evt);
  7690. }
  7691. break;
  7692. case 39: // Right
  7693. if (t.mouseOverFunc)
  7694. t.mouseOverFunc(evt);
  7695. break;
  7696. }
  7697. },
  7698. _add : function(tb, o) {
  7699. var n, s = o.settings, a, ro, it, cp = this.classPrefix, ic;
  7700. if (s.separator) {
  7701. ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'ItemSeparator'});
  7702. DOM.add(ro, 'td', {'class' : cp + 'ItemSeparator'});
  7703. if (n = ro.previousSibling)
  7704. DOM.addClass(n, 'mceLast');
  7705. return;
  7706. }
  7707. n = ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'Item ' + cp + 'ItemEnabled'});
  7708. n = it = DOM.add(n, s.titleItem ? 'th' : 'td');
  7709. n = a = DOM.add(n, 'a', {id: o.id + '_aria', role: s.titleItem ? 'presentation' : 'option', href : 'javascript:;', onclick : "return false;", onmousedown : 'return false;'});
  7710. if (s.parent) {
  7711. DOM.setAttrib(a, 'aria-haspopup', 'true');
  7712. DOM.setAttrib(a, 'aria-owns', 'menu_' + o.id);
  7713. }
  7714. DOM.addClass(it, s['class']);
  7715. // n = DOM.add(n, 'span', {'class' : 'item'});
  7716. ic = DOM.add(n, 'span', {'class' : 'mceIcon' + (s.icon ? ' mce_' + s.icon : '')});
  7717. if (s.icon_src)
  7718. DOM.add(ic, 'img', {src : s.icon_src});
  7719. n = DOM.add(n, s.element || 'span', {'class' : 'mceText', title : o.settings.title}, o.settings.title);
  7720. if (o.settings.style)
  7721. DOM.setAttrib(n, 'style', o.settings.style);
  7722. if (tb.childNodes.length == 1)
  7723. DOM.addClass(ro, 'mceFirst');
  7724. if ((n = ro.previousSibling) && DOM.hasClass(n, cp + 'ItemSeparator'))
  7725. DOM.addClass(ro, 'mceFirst');
  7726. if (o.collapse)
  7727. DOM.addClass(ro, cp + 'ItemSub');
  7728. if (n = ro.previousSibling)
  7729. DOM.removeClass(n, 'mceLast');
  7730. DOM.addClass(ro, 'mceLast');
  7731. }
  7732. });
  7733. })(tinymce);
  7734. (function(tinymce) {
  7735. var DOM = tinymce.DOM;
  7736. tinymce.create('tinymce.ui.Button:tinymce.ui.Control', {
  7737. Button : function(id, s, ed) {
  7738. this.parent(id, s, ed);
  7739. this.classPrefix = 'mceButton';
  7740. },
  7741. renderHTML : function() {
  7742. var cp = this.classPrefix, s = this.settings, h, l;
  7743. l = DOM.encode(s.label || '');
  7744. h = '<a role="button" id="' + this.id + '" href="javascript:;" class="' + cp + ' ' + cp + 'Enabled ' + s['class'] + (l ? ' ' + cp + 'Labeled' : '') +'" onmousedown="return false;" onclick="return false;" aria-labelledby="' + this.id + '_voice" title="' + DOM.encode(s.title) + '">';
  7745. if (s.image && !(this.editor &&this.editor.forcedHighContrastMode) )
  7746. h += '<img class="mceIcon" src="' + s.image + '" alt="' + DOM.encode(s.title) + '" />' + l;
  7747. else
  7748. h += '<span class="mceIcon ' + s['class'] + '"></span>' + (l ? '<span class="' + cp + 'Label">' + l + '</span>' : '');
  7749. h += '<span class="mceVoiceLabel mceIconOnly" style="display: none;" id="' + this.id + '_voice">' + s.title + '</span>';
  7750. h += '</a>';
  7751. return h;
  7752. },
  7753. postRender : function() {
  7754. var t = this, s = t.settings;
  7755. tinymce.dom.Event.add(t.id, 'click', function(e) {
  7756. if (!t.isDisabled())
  7757. return s.onclick.call(s.scope, e);
  7758. });
  7759. }
  7760. });
  7761. })(tinymce);
  7762. (function(tinymce) {
  7763. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher;
  7764. tinymce.create('tinymce.ui.ListBox:tinymce.ui.Control', {
  7765. ListBox : function(id, s, ed) {
  7766. var t = this;
  7767. t.parent(id, s, ed);
  7768. t.items = [];
  7769. t.onChange = new Dispatcher(t);
  7770. t.onPostRender = new Dispatcher(t);
  7771. t.onAdd = new Dispatcher(t);
  7772. t.onRenderMenu = new tinymce.util.Dispatcher(this);
  7773. t.classPrefix = 'mceListBox';
  7774. },
  7775. select : function(va) {
  7776. var t = this, fv, f;
  7777. if (va == undefined)
  7778. return t.selectByIndex(-1);
  7779. // Is string or number make function selector
  7780. if (va && va.call)
  7781. f = va;
  7782. else {
  7783. f = function(v) {
  7784. return v == va;
  7785. };
  7786. }
  7787. // Do we need to do something?
  7788. if (va != t.selectedValue) {
  7789. // Find item
  7790. each(t.items, function(o, i) {
  7791. if (f(o.value)) {
  7792. fv = 1;
  7793. t.selectByIndex(i);
  7794. return false;
  7795. }
  7796. });
  7797. if (!fv)
  7798. t.selectByIndex(-1);
  7799. }
  7800. },
  7801. selectByIndex : function(idx) {
  7802. var t = this, e, o, label;
  7803. if (idx != t.selectedIndex) {
  7804. e = DOM.get(t.id + '_text');
  7805. label = DOM.get(t.id + '_voiceDesc');
  7806. o = t.items[idx];
  7807. if (o) {
  7808. t.selectedValue = o.value;
  7809. t.selectedIndex = idx;
  7810. DOM.setHTML(e, DOM.encode(o.title));
  7811. DOM.setHTML(label, t.settings.title + " - " + o.title);
  7812. DOM.removeClass(e, 'mceTitle');
  7813. DOM.setAttrib(t.id, 'aria-valuenow', o.title);
  7814. } else {
  7815. DOM.setHTML(e, DOM.encode(t.settings.title));
  7816. DOM.setHTML(label, DOM.encode(t.settings.title));
  7817. DOM.addClass(e, 'mceTitle');
  7818. t.selectedValue = t.selectedIndex = null;
  7819. DOM.setAttrib(t.id, 'aria-valuenow', t.settings.title);
  7820. }
  7821. e = 0;
  7822. }
  7823. },
  7824. add : function(n, v, o) {
  7825. var t = this;
  7826. o = o || {};
  7827. o = tinymce.extend(o, {
  7828. title : n,
  7829. value : v
  7830. });
  7831. t.items.push(o);
  7832. t.onAdd.dispatch(t, o);
  7833. },
  7834. getLength : function() {
  7835. return this.items.length;
  7836. },
  7837. renderHTML : function() {
  7838. var h = '', t = this, s = t.settings, cp = t.classPrefix;
  7839. h = '<span role="listbox" aria-haspopup="true" aria-labelledby="' + t.id +'_voiceDesc" aria-describedby="' + t.id + '_voiceDesc"><table role="presentation" tabindex="0" id="' + t.id + '" cellpadding="0" cellspacing="0" class="' + cp + ' ' + cp + 'Enabled' + (s['class'] ? (' ' + s['class']) : '') + '"><tbody><tr>';
  7840. h += '<td>' + DOM.createHTML('span', {id: t.id + '_voiceDesc', 'class': 'voiceLabel', style:'display:none;'}, t.settings.title);
  7841. h += DOM.createHTML('a', {id : t.id + '_text', tabindex : -1, href : 'javascript:;', 'class' : 'mceText', onclick : "return false;", onmousedown : 'return false;'}, DOM.encode(t.settings.title)) + '</td>';
  7842. h += '<td>' + DOM.createHTML('a', {id : t.id + '_open', tabindex : -1, href : 'javascript:;', 'class' : 'mceOpen', onclick : "return false;", onmousedown : 'return false;'}, '<span><span style="display:none;" class="mceIconOnly" aria-hidden="true">\u25BC</span></span>') + '</td>';
  7843. h += '</tr></tbody></table></span>';
  7844. return h;
  7845. },
  7846. showMenu : function() {
  7847. var t = this, p2, e = DOM.get(this.id), m;
  7848. if (t.isDisabled() || t.items.length == 0)
  7849. return;
  7850. if (t.menu && t.menu.isMenuVisible)
  7851. return t.hideMenu();
  7852. if (!t.isMenuRendered) {
  7853. t.renderMenu();
  7854. t.isMenuRendered = true;
  7855. }
  7856. p2 = DOM.getPos(e);
  7857. m = t.menu;
  7858. m.settings.offset_x = p2.x;
  7859. m.settings.offset_y = p2.y;
  7860. m.settings.keyboard_focus = !tinymce.isOpera; // Opera is buggy when it comes to auto focus
  7861. // Select in menu
  7862. if (t.oldID)
  7863. m.items[t.oldID].setSelected(0);
  7864. each(t.items, function(o) {
  7865. if (o.value === t.selectedValue) {
  7866. m.items[o.id].setSelected(1);
  7867. t.oldID = o.id;
  7868. }
  7869. });
  7870. m.showMenu(0, e.clientHeight);
  7871. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  7872. DOM.addClass(t.id, t.classPrefix + 'Selected');
  7873. //DOM.get(t.id + '_text').focus();
  7874. },
  7875. hideMenu : function(e) {
  7876. var t = this;
  7877. if (t.menu && t.menu.isMenuVisible) {
  7878. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  7879. // Prevent double toogles by canceling the mouse click event to the button
  7880. if (e && e.type == "mousedown" && (e.target.id == t.id + '_text' || e.target.id == t.id + '_open'))
  7881. return;
  7882. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  7883. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  7884. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  7885. t.menu.hideMenu();
  7886. }
  7887. }
  7888. },
  7889. renderMenu : function() {
  7890. var t = this, m;
  7891. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  7892. menu_line : 1,
  7893. 'class' : t.classPrefix + 'Menu mceNoIcons',
  7894. max_width : 150,
  7895. max_height : 150
  7896. });
  7897. m.onHideMenu.add(function() {
  7898. t.hideMenu();
  7899. t.focus();
  7900. });
  7901. m.add({
  7902. title : t.settings.title,
  7903. 'class' : 'mceMenuItemTitle',
  7904. onclick : function() {
  7905. if (t.settings.onselect('') !== false)
  7906. t.select(''); // Must be runned after
  7907. }
  7908. });
  7909. each(t.items, function(o) {
  7910. // No value then treat it as a title
  7911. if (o.value === undefined) {
  7912. m.add({
  7913. title : o.title,
  7914. role : "option",
  7915. 'class' : 'mceMenuItemTitle',
  7916. onclick : function() {
  7917. if (t.settings.onselect('') !== false)
  7918. t.select(''); // Must be runned after
  7919. }
  7920. });
  7921. } else {
  7922. o.id = DOM.uniqueId();
  7923. o.role= "option";
  7924. o.onclick = function() {
  7925. if (t.settings.onselect(o.value) !== false)
  7926. t.select(o.value); // Must be runned after
  7927. };
  7928. m.add(o);
  7929. }
  7930. });
  7931. t.onRenderMenu.dispatch(t, m);
  7932. t.menu = m;
  7933. },
  7934. postRender : function() {
  7935. var t = this, cp = t.classPrefix;
  7936. Event.add(t.id, 'click', t.showMenu, t);
  7937. Event.add(t.id, 'keydown', function(evt) {
  7938. if (evt.keyCode == 32) { // Space
  7939. t.showMenu(evt);
  7940. Event.cancel(evt);
  7941. }
  7942. });
  7943. Event.add(t.id, 'focus', function() {
  7944. if (!t._focused) {
  7945. t.keyDownHandler = Event.add(t.id, 'keydown', function(e) {
  7946. if (e.keyCode == 40) {
  7947. t.showMenu();
  7948. Event.cancel(e);
  7949. }
  7950. });
  7951. t.keyPressHandler = Event.add(t.id, 'keypress', function(e) {
  7952. var v;
  7953. if (e.keyCode == 13) {
  7954. // Fake select on enter
  7955. v = t.selectedValue;
  7956. t.selectedValue = null; // Needs to be null to fake change
  7957. Event.cancel(e);
  7958. t.settings.onselect(v);
  7959. }
  7960. });
  7961. }
  7962. t._focused = 1;
  7963. });
  7964. Event.add(t.id, 'blur', function() {
  7965. Event.remove(t.id, 'keydown', t.keyDownHandler);
  7966. Event.remove(t.id, 'keypress', t.keyPressHandler);
  7967. t._focused = 0;
  7968. });
  7969. // Old IE doesn't have hover on all elements
  7970. if (tinymce.isIE6 || !DOM.boxModel) {
  7971. Event.add(t.id, 'mouseover', function() {
  7972. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  7973. DOM.addClass(t.id, cp + 'Hover');
  7974. });
  7975. Event.add(t.id, 'mouseout', function() {
  7976. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  7977. DOM.removeClass(t.id, cp + 'Hover');
  7978. });
  7979. }
  7980. t.onPostRender.dispatch(t, DOM.get(t.id));
  7981. },
  7982. destroy : function() {
  7983. this.parent();
  7984. Event.clear(this.id + '_text');
  7985. Event.clear(this.id + '_open');
  7986. }
  7987. });
  7988. })(tinymce);
  7989. (function(tinymce) {
  7990. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher;
  7991. tinymce.create('tinymce.ui.NativeListBox:tinymce.ui.ListBox', {
  7992. NativeListBox : function(id, s) {
  7993. this.parent(id, s);
  7994. this.classPrefix = 'mceNativeListBox';
  7995. },
  7996. setDisabled : function(s) {
  7997. DOM.get(this.id).disabled = s;
  7998. this.setAriaProperty('disabled', s);
  7999. },
  8000. isDisabled : function() {
  8001. return DOM.get(this.id).disabled;
  8002. },
  8003. select : function(va) {
  8004. var t = this, fv, f;
  8005. if (va == undefined)
  8006. return t.selectByIndex(-1);
  8007. // Is string or number make function selector
  8008. if (va && va.call)
  8009. f = va;
  8010. else {
  8011. f = function(v) {
  8012. return v == va;
  8013. };
  8014. }
  8015. // Do we need to do something?
  8016. if (va != t.selectedValue) {
  8017. // Find item
  8018. each(t.items, function(o, i) {
  8019. if (f(o.value)) {
  8020. fv = 1;
  8021. t.selectByIndex(i);
  8022. return false;
  8023. }
  8024. });
  8025. if (!fv)
  8026. t.selectByIndex(-1);
  8027. }
  8028. },
  8029. selectByIndex : function(idx) {
  8030. DOM.get(this.id).selectedIndex = idx + 1;
  8031. this.selectedValue = this.items[idx] ? this.items[idx].value : null;
  8032. },
  8033. add : function(n, v, a) {
  8034. var o, t = this;
  8035. a = a || {};
  8036. a.value = v;
  8037. if (t.isRendered())
  8038. DOM.add(DOM.get(this.id), 'option', a, n);
  8039. o = {
  8040. title : n,
  8041. value : v,
  8042. attribs : a
  8043. };
  8044. t.items.push(o);
  8045. t.onAdd.dispatch(t, o);
  8046. },
  8047. getLength : function() {
  8048. return this.items.length;
  8049. },
  8050. renderHTML : function() {
  8051. var h, t = this;
  8052. h = DOM.createHTML('option', {value : ''}, '-- ' + t.settings.title + ' --');
  8053. each(t.items, function(it) {
  8054. h += DOM.createHTML('option', {value : it.value}, it.title);
  8055. });
  8056. h = DOM.createHTML('select', {id : t.id, 'class' : 'mceNativeListBox', 'aria-labelledby': t.id + '_aria'}, h);
  8057. h += DOM.createHTML('span', {id : t.id + '_aria', 'style': 'display: none'}, t.settings.title);
  8058. return h;
  8059. },
  8060. postRender : function() {
  8061. var t = this, ch, changeListenerAdded = true;
  8062. t.rendered = true;
  8063. function onChange(e) {
  8064. var v = t.items[e.target.selectedIndex - 1];
  8065. if (v && (v = v.value)) {
  8066. t.onChange.dispatch(t, v);
  8067. if (t.settings.onselect)
  8068. t.settings.onselect(v);
  8069. }
  8070. };
  8071. Event.add(t.id, 'change', onChange);
  8072. // Accessibility keyhandler
  8073. Event.add(t.id, 'keydown', function(e) {
  8074. var bf;
  8075. Event.remove(t.id, 'change', ch);
  8076. changeListenerAdded = false;
  8077. bf = Event.add(t.id, 'blur', function() {
  8078. if (changeListenerAdded) return;
  8079. changeListenerAdded = true;
  8080. Event.add(t.id, 'change', onChange);
  8081. Event.remove(t.id, 'blur', bf);
  8082. });
  8083. //prevent default left and right keys on chrome - so that the keyboard navigation is used.
  8084. if (tinymce.isWebKit && (e.keyCode==37 ||e.keyCode==39)) {
  8085. return Event.prevent(e);
  8086. }
  8087. if (e.keyCode == 13 || e.keyCode == 32) {
  8088. onChange(e);
  8089. return Event.cancel(e);
  8090. }
  8091. });
  8092. t.onPostRender.dispatch(t, DOM.get(t.id));
  8093. }
  8094. });
  8095. })(tinymce);
  8096. (function(tinymce) {
  8097. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  8098. tinymce.create('tinymce.ui.MenuButton:tinymce.ui.Button', {
  8099. MenuButton : function(id, s, ed) {
  8100. this.parent(id, s, ed);
  8101. this.onRenderMenu = new tinymce.util.Dispatcher(this);
  8102. s.menu_container = s.menu_container || DOM.doc.body;
  8103. },
  8104. showMenu : function() {
  8105. var t = this, p1, p2, e = DOM.get(t.id), m;
  8106. if (t.isDisabled())
  8107. return;
  8108. if (!t.isMenuRendered) {
  8109. t.renderMenu();
  8110. t.isMenuRendered = true;
  8111. }
  8112. if (t.isMenuVisible)
  8113. return t.hideMenu();
  8114. p1 = DOM.getPos(t.settings.menu_container);
  8115. p2 = DOM.getPos(e);
  8116. m = t.menu;
  8117. m.settings.offset_x = p2.x;
  8118. m.settings.offset_y = p2.y;
  8119. m.settings.vp_offset_x = p2.x;
  8120. m.settings.vp_offset_y = p2.y;
  8121. m.settings.keyboard_focus = t._focused;
  8122. m.showMenu(0, e.clientHeight);
  8123. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  8124. t.setState('Selected', 1);
  8125. t.isMenuVisible = 1;
  8126. },
  8127. renderMenu : function() {
  8128. var t = this, m;
  8129. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  8130. menu_line : 1,
  8131. 'class' : this.classPrefix + 'Menu',
  8132. icons : t.settings.icons
  8133. });
  8134. m.onHideMenu.add(function() {
  8135. t.hideMenu();
  8136. t.focus();
  8137. });
  8138. t.onRenderMenu.dispatch(t, m);
  8139. t.menu = m;
  8140. },
  8141. hideMenu : function(e) {
  8142. var t = this;
  8143. // Prevent double toogles by canceling the mouse click event to the button
  8144. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id || e.id === t.id + '_open';}))
  8145. return;
  8146. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  8147. t.setState('Selected', 0);
  8148. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  8149. if (t.menu)
  8150. t.menu.hideMenu();
  8151. }
  8152. t.isMenuVisible = 0;
  8153. },
  8154. postRender : function() {
  8155. var t = this, s = t.settings;
  8156. Event.add(t.id, 'click', function() {
  8157. if (!t.isDisabled()) {
  8158. if (s.onclick)
  8159. s.onclick(t.value);
  8160. t.showMenu();
  8161. }
  8162. });
  8163. }
  8164. });
  8165. })(tinymce);
  8166. (function(tinymce) {
  8167. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  8168. tinymce.create('tinymce.ui.SplitButton:tinymce.ui.MenuButton', {
  8169. SplitButton : function(id, s, ed) {
  8170. this.parent(id, s, ed);
  8171. this.classPrefix = 'mceSplitButton';
  8172. },
  8173. renderHTML : function() {
  8174. var h, t = this, s = t.settings, h1;
  8175. h = '<tbody><tr>';
  8176. if (s.image)
  8177. h1 = DOM.createHTML('img ', {src : s.image, role: 'presentation', 'class' : 'mceAction ' + s['class']});
  8178. else
  8179. h1 = DOM.createHTML('span', {'class' : 'mceAction ' + s['class']}, '');
  8180. h1 += DOM.createHTML('span', {'class': 'mceVoiceLabel mceIconOnly', id: t.id + '_voice', style: 'display:none;'}, s.title);
  8181. h += '<td >' + DOM.createHTML('a', {role: 'button', id : t.id + '_action', tabindex: '-1', href : 'javascript:;', 'class' : 'mceAction ' + s['class'], onclick : "return false;", onmousedown : 'return false;', title : s.title}, h1) + '</td>';
  8182. h1 = DOM.createHTML('span', {'class' : 'mceOpen ' + s['class']}, '<span style="display:none;" class="mceIconOnly" aria-hidden="true">\u25BC</span>');
  8183. h += '<td >' + DOM.createHTML('a', {role: 'button', id : t.id + '_open', tabindex: '-1', href : 'javascript:;', 'class' : 'mceOpen ' + s['class'], onclick : "return false;", onmousedown : 'return false;', title : s.title}, h1) + '</td>';
  8184. h += '</tr></tbody>';
  8185. h = DOM.createHTML('table', { role: 'presentation', 'class' : 'mceSplitButton mceSplitButtonEnabled ' + s['class'], cellpadding : '0', cellspacing : '0', title : s.title}, h);
  8186. return DOM.createHTML('div', {id : t.id, role: 'button', tabindex: '0', 'aria-labelledby': t.id + '_voice', 'aria-haspopup': 'true'}, h);
  8187. },
  8188. postRender : function() {
  8189. var t = this, s = t.settings, activate;
  8190. if (s.onclick) {
  8191. activate = function(evt) {
  8192. if (!t.isDisabled()) {
  8193. s.onclick(t.value);
  8194. Event.cancel(evt);
  8195. }
  8196. };
  8197. Event.add(t.id + '_action', 'click', activate);
  8198. Event.add(t.id, ['click', 'keydown'], function(evt) {
  8199. var DOM_VK_SPACE = 32, DOM_VK_ENTER = 14, DOM_VK_RETURN = 13, DOM_VK_UP = 38, DOM_VK_DOWN = 40;
  8200. if ((evt.keyCode === 32 || evt.keyCode === 13 || evt.keyCode === 14) && !evt.altKey && !evt.ctrlKey && !evt.metaKey) {
  8201. activate();
  8202. Event.cancel(evt);
  8203. } else if (evt.type === 'click' || evt.keyCode === DOM_VK_DOWN) {
  8204. t.showMenu();
  8205. Event.cancel(evt);
  8206. }
  8207. });
  8208. }
  8209. Event.add(t.id + '_open', 'click', function (evt) {
  8210. t.showMenu();
  8211. Event.cancel(evt);
  8212. });
  8213. Event.add([t.id, t.id + '_open'], 'focus', function() {t._focused = 1;});
  8214. Event.add([t.id, t.id + '_open'], 'blur', function() {t._focused = 0;});
  8215. // Old IE doesn't have hover on all elements
  8216. if (tinymce.isIE6 || !DOM.boxModel) {
  8217. Event.add(t.id, 'mouseover', function() {
  8218. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  8219. DOM.addClass(t.id, 'mceSplitButtonHover');
  8220. });
  8221. Event.add(t.id, 'mouseout', function() {
  8222. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  8223. DOM.removeClass(t.id, 'mceSplitButtonHover');
  8224. });
  8225. }
  8226. },
  8227. destroy : function() {
  8228. this.parent();
  8229. Event.clear(this.id + '_action');
  8230. Event.clear(this.id + '_open');
  8231. Event.clear(this.id);
  8232. }
  8233. });
  8234. })(tinymce);
  8235. (function(tinymce) {
  8236. var DOM = tinymce.DOM, Event = tinymce.dom.Event, is = tinymce.is, each = tinymce.each;
  8237. tinymce.create('tinymce.ui.ColorSplitButton:tinymce.ui.SplitButton', {
  8238. ColorSplitButton : function(id, s, ed) {
  8239. var t = this;
  8240. t.parent(id, s, ed);
  8241. t.settings = s = tinymce.extend({
  8242. colors : '000000,993300,333300,003300,003366,000080,333399,333333,800000,FF6600,808000,008000,008080,0000FF,666699,808080,FF0000,FF9900,99CC00,339966,33CCCC,3366FF,800080,999999,FF00FF,FFCC00,FFFF00,00FF00,00FFFF,00CCFF,993366,C0C0C0,FF99CC,FFCC99,FFFF99,CCFFCC,CCFFFF,99CCFF,CC99FF,FFFFFF',
  8243. grid_width : 8,
  8244. default_color : '#888888'
  8245. }, t.settings);
  8246. t.onShowMenu = new tinymce.util.Dispatcher(t);
  8247. t.onHideMenu = new tinymce.util.Dispatcher(t);
  8248. t.value = s.default_color;
  8249. },
  8250. showMenu : function() {
  8251. var t = this, r, p, e, p2;
  8252. if (t.isDisabled())
  8253. return;
  8254. if (!t.isMenuRendered) {
  8255. t.renderMenu();
  8256. t.isMenuRendered = true;
  8257. }
  8258. if (t.isMenuVisible)
  8259. return t.hideMenu();
  8260. e = DOM.get(t.id);
  8261. DOM.show(t.id + '_menu');
  8262. DOM.addClass(e, 'mceSplitButtonSelected');
  8263. p2 = DOM.getPos(e);
  8264. DOM.setStyles(t.id + '_menu', {
  8265. left : p2.x,
  8266. top : p2.y + e.clientHeight,
  8267. zIndex : 200000
  8268. });
  8269. e = 0;
  8270. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  8271. t.onShowMenu.dispatch(t);
  8272. if (t._focused) {
  8273. t._keyHandler = Event.add(t.id + '_menu', 'keydown', function(e) {
  8274. if (e.keyCode == 27)
  8275. t.hideMenu();
  8276. });
  8277. DOM.select('a', t.id + '_menu')[0].focus(); // Select first link
  8278. }
  8279. t.isMenuVisible = 1;
  8280. },
  8281. hideMenu : function(e) {
  8282. var t = this;
  8283. if (t.isMenuVisible) {
  8284. // Prevent double toogles by canceling the mouse click event to the button
  8285. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id + '_open';}))
  8286. return;
  8287. if (!e || !DOM.getParent(e.target, '.mceSplitButtonMenu')) {
  8288. DOM.removeClass(t.id, 'mceSplitButtonSelected');
  8289. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  8290. Event.remove(t.id + '_menu', 'keydown', t._keyHandler);
  8291. DOM.hide(t.id + '_menu');
  8292. }
  8293. t.isMenuVisible = 0;
  8294. t.onHideMenu.dispatch();
  8295. }
  8296. },
  8297. renderMenu : function() {
  8298. var t = this, m, i = 0, s = t.settings, n, tb, tr, w, context;
  8299. w = DOM.add(s.menu_container, 'div', {role: 'listbox', id : t.id + '_menu', 'class' : s['menu_class'] + ' ' + s['class'], style : 'position:absolute;left:0;top:-1000px;'});
  8300. m = DOM.add(w, 'div', {'class' : s['class'] + ' mceSplitButtonMenu'});
  8301. DOM.add(m, 'span', {'class' : 'mceMenuLine'});
  8302. n = DOM.add(m, 'table', {role: 'presentation', 'class' : 'mceColorSplitMenu'});
  8303. tb = DOM.add(n, 'tbody');
  8304. // Generate color grid
  8305. i = 0;
  8306. each(is(s.colors, 'array') ? s.colors : s.colors.split(','), function(c) {
  8307. c = c.replace(/^#/, '');
  8308. if (!i--) {
  8309. tr = DOM.add(tb, 'tr');
  8310. i = s.grid_width - 1;
  8311. }
  8312. n = DOM.add(tr, 'td');
  8313. n = DOM.add(n, 'a', {
  8314. role : 'option',
  8315. href : 'javascript:;',
  8316. style : {
  8317. backgroundColor : '#' + c
  8318. },
  8319. 'title': t.editor.getLang('colors.' + c, c),
  8320. 'data-mce-color' : '#' + c
  8321. });
  8322. if (t.editor.forcedHighContrastMode) {
  8323. n = DOM.add(n, 'canvas', { width: 16, height: 16, 'aria-hidden': 'true' });
  8324. if (n.getContext && (context = n.getContext("2d"))) {
  8325. context.fillStyle = '#' + c;
  8326. context.fillRect(0, 0, 16, 16);
  8327. } else {
  8328. // No point leaving a canvas element around if it's not supported for drawing on anyway.
  8329. DOM.remove(n);
  8330. }
  8331. }
  8332. });
  8333. if (s.more_colors_func) {
  8334. n = DOM.add(tb, 'tr');
  8335. n = DOM.add(n, 'td', {colspan : s.grid_width, 'class' : 'mceMoreColors'});
  8336. n = DOM.add(n, 'a', {role: 'option', id : t.id + '_more', href : 'javascript:;', onclick : 'return false;', 'class' : 'mceMoreColors'}, s.more_colors_title);
  8337. Event.add(n, 'click', function(e) {
  8338. s.more_colors_func.call(s.more_colors_scope || this);
  8339. return Event.cancel(e); // Cancel to fix onbeforeunload problem
  8340. });
  8341. }
  8342. DOM.addClass(m, 'mceColorSplitMenu');
  8343. new tinymce.ui.KeyboardNavigation({
  8344. root: t.id + '_menu',
  8345. items: DOM.select('a', t.id + '_menu'),
  8346. onCancel: function() {
  8347. t.hideMenu();
  8348. t.focus();
  8349. }
  8350. });
  8351. // Prevent IE from scrolling and hindering click to occur #4019
  8352. Event.add(t.id + '_menu', 'mousedown', function(e) {return Event.cancel(e);});
  8353. Event.add(t.id + '_menu', 'click', function(e) {
  8354. var c;
  8355. e = DOM.getParent(e.target, 'a', tb);
  8356. if (e && e.nodeName.toLowerCase() == 'a' && (c = e.getAttribute('data-mce-color')))
  8357. t.setColor(c);
  8358. return Event.cancel(e); // Prevent IE auto save warning
  8359. });
  8360. return w;
  8361. },
  8362. setColor : function(c) {
  8363. this.displayColor(c);
  8364. this.hideMenu();
  8365. this.settings.onselect(c);
  8366. },
  8367. displayColor : function(c) {
  8368. var t = this;
  8369. DOM.setStyle(t.id + '_preview', 'backgroundColor', c);
  8370. t.value = c;
  8371. },
  8372. postRender : function() {
  8373. var t = this, id = t.id;
  8374. t.parent();
  8375. DOM.add(id + '_action', 'div', {id : id + '_preview', 'class' : 'mceColorPreview'});
  8376. DOM.setStyle(t.id + '_preview', 'backgroundColor', t.value);
  8377. },
  8378. destroy : function() {
  8379. this.parent();
  8380. Event.clear(this.id + '_menu');
  8381. Event.clear(this.id + '_more');
  8382. DOM.remove(this.id + '_menu');
  8383. }
  8384. });
  8385. })(tinymce);
  8386. (function(tinymce) {
  8387. // Shorten class names
  8388. var dom = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event;
  8389. tinymce.create('tinymce.ui.ToolbarGroup:tinymce.ui.Container', {
  8390. renderHTML : function() {
  8391. var t = this, h = [], controls = t.controls, each = tinymce.each, settings = t.settings;
  8392. h.push('<div id="' + t.id + '" role="group" aria-labelledby="' + t.id + '_voice">');
  8393. //TODO: ACC test this out - adding a role = application for getting the landmarks working well.
  8394. h.push("<span role='application'>");
  8395. h.push('<span id="' + t.id + '_voice" class="mceVoiceLabel" style="display:none;">' + dom.encode(settings.name) + '</span>');
  8396. each(controls, function(toolbar) {
  8397. h.push(toolbar.renderHTML());
  8398. });
  8399. h.push("</span>");
  8400. h.push('</div>');
  8401. return h.join('');
  8402. },
  8403. focus : function() {
  8404. var t = this;
  8405. dom.get(t.id).focus();
  8406. },
  8407. postRender : function() {
  8408. var t = this, items = [];
  8409. each(t.controls, function(toolbar) {
  8410. each (toolbar.controls, function(control) {
  8411. if (control.id) {
  8412. items.push(control);
  8413. }
  8414. });
  8415. });
  8416. t.keyNav = new tinymce.ui.KeyboardNavigation({
  8417. root: t.id,
  8418. items: items,
  8419. onCancel: function() {
  8420. //Move focus if webkit so that navigation back will read the item.
  8421. if (tinymce.isWebKit) {
  8422. dom.get(t.editor.id+"_ifr").focus();
  8423. }
  8424. t.editor.focus();
  8425. },
  8426. excludeFromTabOrder: !t.settings.tab_focus_toolbar
  8427. });
  8428. },
  8429. destroy : function() {
  8430. var self = this;
  8431. self.parent();
  8432. self.keyNav.destroy();
  8433. Event.clear(self.id);
  8434. }
  8435. });
  8436. })(tinymce);
  8437. (function(tinymce) {
  8438. // Shorten class names
  8439. var dom = tinymce.DOM, each = tinymce.each;
  8440. tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', {
  8441. renderHTML : function() {
  8442. var t = this, h = '', c, co, s = t.settings, i, pr, nx, cl;
  8443. cl = t.controls;
  8444. for (i=0; i<cl.length; i++) {
  8445. // Get current control, prev control, next control and if the control is a list box or not
  8446. co = cl[i];
  8447. pr = cl[i - 1];
  8448. nx = cl[i + 1];
  8449. // Add toolbar start
  8450. if (i === 0) {
  8451. c = 'mceToolbarStart';
  8452. if (co.Button)
  8453. c += ' mceToolbarStartButton';
  8454. else if (co.SplitButton)
  8455. c += ' mceToolbarStartSplitButton';
  8456. else if (co.ListBox)
  8457. c += ' mceToolbarStartListBox';
  8458. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  8459. }
  8460. // Add toolbar end before list box and after the previous button
  8461. // This is to fix the o2k7 editor skins
  8462. if (pr && co.ListBox) {
  8463. if (pr.Button || pr.SplitButton)
  8464. h += dom.createHTML('td', {'class' : 'mceToolbarEnd'}, dom.createHTML('span', null, '<!-- IE -->'));
  8465. }
  8466. // Render control HTML
  8467. // IE 8 quick fix, needed to propertly generate a hit area for anchors
  8468. if (dom.stdMode)
  8469. h += '<td style="position: relative">' + co.renderHTML() + '</td>';
  8470. else
  8471. h += '<td>' + co.renderHTML() + '</td>';
  8472. // Add toolbar start after list box and before the next button
  8473. // This is to fix the o2k7 editor skins
  8474. if (nx && co.ListBox) {
  8475. if (nx.Button || nx.SplitButton)
  8476. h += dom.createHTML('td', {'class' : 'mceToolbarStart'}, dom.createHTML('span', null, '<!-- IE -->'));
  8477. }
  8478. }
  8479. c = 'mceToolbarEnd';
  8480. if (co.Button)
  8481. c += ' mceToolbarEndButton';
  8482. else if (co.SplitButton)
  8483. c += ' mceToolbarEndSplitButton';
  8484. else if (co.ListBox)
  8485. c += ' mceToolbarEndListBox';
  8486. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  8487. return dom.createHTML('table', {id : t.id, 'class' : 'mceToolbar' + (s['class'] ? ' ' + s['class'] : ''), cellpadding : '0', cellspacing : '0', align : t.settings.align || '', role: 'presentation', tabindex: '-1'}, '<tbody><tr>' + h + '</tr></tbody>');
  8488. }
  8489. });
  8490. })(tinymce);
  8491. (function(tinymce) {
  8492. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each;
  8493. tinymce.create('tinymce.AddOnManager', {
  8494. AddOnManager : function() {
  8495. var self = this;
  8496. self.items = [];
  8497. self.urls = {};
  8498. self.lookup = {};
  8499. self.onAdd = new Dispatcher(self);
  8500. },
  8501. get : function(n) {
  8502. if (this.lookup[n]) {
  8503. return this.lookup[n].instance;
  8504. } else {
  8505. return undefined;
  8506. }
  8507. },
  8508. dependencies : function(n) {
  8509. var result;
  8510. if (this.lookup[n]) {
  8511. result = this.lookup[n].dependencies;
  8512. }
  8513. return result || [];
  8514. },
  8515. requireLangPack : function(n) {
  8516. var s = tinymce.settings;
  8517. if (s && s.language && s.language_load !== false)
  8518. tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js');
  8519. },
  8520. add : function(id, o, dependencies) {
  8521. this.items.push(o);
  8522. this.lookup[id] = {instance:o, dependencies:dependencies};
  8523. this.onAdd.dispatch(this, id, o);
  8524. return o;
  8525. },
  8526. createUrl: function(baseUrl, dep) {
  8527. if (typeof dep === "object") {
  8528. return dep
  8529. } else {
  8530. return {prefix: baseUrl.prefix, resource: dep, suffix: baseUrl.suffix};
  8531. }
  8532. },
  8533. addComponents: function(pluginName, scripts) {
  8534. var pluginUrl = this.urls[pluginName];
  8535. tinymce.each(scripts, function(script){
  8536. tinymce.ScriptLoader.add(pluginUrl+"/"+script);
  8537. });
  8538. },
  8539. load : function(n, u, cb, s) {
  8540. var t = this, url = u;
  8541. function loadDependencies() {
  8542. var dependencies = t.dependencies(n);
  8543. tinymce.each(dependencies, function(dep) {
  8544. var newUrl = t.createUrl(u, dep);
  8545. t.load(newUrl.resource, newUrl, undefined, undefined);
  8546. });
  8547. if (cb) {
  8548. if (s) {
  8549. cb.call(s);
  8550. } else {
  8551. cb.call(tinymce.ScriptLoader);
  8552. }
  8553. }
  8554. }
  8555. if (t.urls[n])
  8556. return;
  8557. if (typeof u === "object")
  8558. url = u.prefix + u.resource + u.suffix;
  8559. if (url.indexOf('/') != 0 && url.indexOf('://') == -1)
  8560. url = tinymce.baseURL + '/' + url;
  8561. t.urls[n] = url.substring(0, url.lastIndexOf('/'));
  8562. if (t.lookup[n]) {
  8563. loadDependencies();
  8564. } else {
  8565. tinymce.ScriptLoader.add(url, loadDependencies, s);
  8566. }
  8567. }
  8568. });
  8569. // Create plugin and theme managers
  8570. tinymce.PluginManager = new tinymce.AddOnManager();
  8571. tinymce.ThemeManager = new tinymce.AddOnManager();
  8572. }(tinymce));
  8573. (function(tinymce) {
  8574. // Shorten names
  8575. var each = tinymce.each, extend = tinymce.extend,
  8576. DOM = tinymce.DOM, Event = tinymce.dom.Event,
  8577. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  8578. explode = tinymce.explode,
  8579. Dispatcher = tinymce.util.Dispatcher, undefined, instanceCounter = 0;
  8580. // Setup some URLs where the editor API is located and where the document is
  8581. tinymce.documentBaseURL = window.location.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
  8582. if (!/[\/\\]$/.test(tinymce.documentBaseURL))
  8583. tinymce.documentBaseURL += '/';
  8584. tinymce.baseURL = new tinymce.util.URI(tinymce.documentBaseURL).toAbsolute(tinymce.baseURL);
  8585. tinymce.baseURI = new tinymce.util.URI(tinymce.baseURL);
  8586. // Add before unload listener
  8587. // This was required since IE was leaking memory if you added and removed beforeunload listeners
  8588. // with attachEvent/detatchEvent so this only adds one listener and instances can the attach to the onBeforeUnload event
  8589. tinymce.onBeforeUnload = new Dispatcher(tinymce);
  8590. // Must be on window or IE will leak if the editor is placed in frame or iframe
  8591. Event.add(window, 'beforeunload', function(e) {
  8592. tinymce.onBeforeUnload.dispatch(tinymce, e);
  8593. });
  8594. tinymce.onAddEditor = new Dispatcher(tinymce);
  8595. tinymce.onRemoveEditor = new Dispatcher(tinymce);
  8596. tinymce.EditorManager = extend(tinymce, {
  8597. editors : [],
  8598. i18n : {},
  8599. activeEditor : null,
  8600. init : function(s) {
  8601. var t = this, pl, sl = tinymce.ScriptLoader, e, el = [], ed;
  8602. function execCallback(se, n, s) {
  8603. var f = se[n];
  8604. if (!f)
  8605. return;
  8606. if (tinymce.is(f, 'string')) {
  8607. s = f.replace(/\.\w+$/, '');
  8608. s = s ? tinymce.resolve(s) : 0;
  8609. f = tinymce.resolve(f);
  8610. }
  8611. return f.apply(s || this, Array.prototype.slice.call(arguments, 2));
  8612. };
  8613. s = extend({
  8614. theme : "simple",
  8615. language : "en"
  8616. }, s);
  8617. t.settings = s;
  8618. // Legacy call
  8619. Event.add(document, 'init', function() {
  8620. var l, co;
  8621. execCallback(s, 'onpageload');
  8622. switch (s.mode) {
  8623. case "exact":
  8624. l = s.elements || '';
  8625. if(l.length > 0) {
  8626. each(explode(l), function(v) {
  8627. if (DOM.get(v)) {
  8628. ed = new tinymce.Editor(v, s);
  8629. el.push(ed);
  8630. ed.render(1);
  8631. } else {
  8632. each(document.forms, function(f) {
  8633. each(f.elements, function(e) {
  8634. if (e.name === v) {
  8635. v = 'mce_editor_' + instanceCounter++;
  8636. DOM.setAttrib(e, 'id', v);
  8637. ed = new tinymce.Editor(v, s);
  8638. el.push(ed);
  8639. ed.render(1);
  8640. }
  8641. });
  8642. });
  8643. }
  8644. });
  8645. }
  8646. break;
  8647. case "textareas":
  8648. case "specific_textareas":
  8649. function hasClass(n, c) {
  8650. return c.constructor === RegExp ? c.test(n.className) : DOM.hasClass(n, c);
  8651. };
  8652. each(DOM.select('textarea'), function(v) {
  8653. if (s.editor_deselector && hasClass(v, s.editor_deselector))
  8654. return;
  8655. if (!s.editor_selector || hasClass(v, s.editor_selector)) {
  8656. // Can we use the name
  8657. e = DOM.get(v.name);
  8658. if (!v.id && !e)
  8659. v.id = v.name;
  8660. // Generate unique name if missing or already exists
  8661. if (!v.id || t.get(v.id))
  8662. v.id = DOM.uniqueId();
  8663. ed = new tinymce.Editor(v.id, s);
  8664. el.push(ed);
  8665. ed.render(1);
  8666. }
  8667. });
  8668. break;
  8669. }
  8670. // Call onInit when all editors are initialized
  8671. if (s.oninit) {
  8672. l = co = 0;
  8673. each(el, function(ed) {
  8674. co++;
  8675. if (!ed.initialized) {
  8676. // Wait for it
  8677. ed.onInit.add(function() {
  8678. l++;
  8679. // All done
  8680. if (l == co)
  8681. execCallback(s, 'oninit');
  8682. });
  8683. } else
  8684. l++;
  8685. // All done
  8686. if (l == co)
  8687. execCallback(s, 'oninit');
  8688. });
  8689. }
  8690. });
  8691. },
  8692. get : function(id) {
  8693. if (id === undefined)
  8694. return this.editors;
  8695. return this.editors[id];
  8696. },
  8697. getInstanceById : function(id) {
  8698. return this.get(id);
  8699. },
  8700. add : function(editor) {
  8701. var self = this, editors = self.editors;
  8702. // Add named and index editor instance
  8703. editors[editor.id] = editor;
  8704. editors.push(editor);
  8705. self._setActive(editor);
  8706. self.onAddEditor.dispatch(self, editor);
  8707. return editor;
  8708. },
  8709. remove : function(editor) {
  8710. var t = this, i, editors = t.editors;
  8711. // Not in the collection
  8712. if (!editors[editor.id])
  8713. return null;
  8714. delete editors[editor.id];
  8715. for (i = 0; i < editors.length; i++) {
  8716. if (editors[i] == editor) {
  8717. editors.splice(i, 1);
  8718. break;
  8719. }
  8720. }
  8721. // Select another editor since the active one was removed
  8722. if (t.activeEditor == editor)
  8723. t._setActive(editors[0]);
  8724. editor.destroy();
  8725. t.onRemoveEditor.dispatch(t, editor);
  8726. return editor;
  8727. },
  8728. execCommand : function(c, u, v) {
  8729. var t = this, ed = t.get(v), w;
  8730. // Manager commands
  8731. switch (c) {
  8732. case "mceFocus":
  8733. ed.focus();
  8734. return true;
  8735. case "mceAddEditor":
  8736. case "mceAddControl":
  8737. if (!t.get(v))
  8738. new tinymce.Editor(v, t.settings).render();
  8739. return true;
  8740. case "mceAddFrameControl":
  8741. w = v.window;
  8742. // Add tinyMCE global instance and tinymce namespace to specified window
  8743. w.tinyMCE = tinyMCE;
  8744. w.tinymce = tinymce;
  8745. tinymce.DOM.doc = w.document;
  8746. tinymce.DOM.win = w;
  8747. ed = new tinymce.Editor(v.element_id, v);
  8748. ed.render();
  8749. // Fix IE memory leaks
  8750. if (tinymce.isIE) {
  8751. function clr() {
  8752. ed.destroy();
  8753. w.detachEvent('onunload', clr);
  8754. w = w.tinyMCE = w.tinymce = null; // IE leak
  8755. };
  8756. w.attachEvent('onunload', clr);
  8757. }
  8758. v.page_window = null;
  8759. return true;
  8760. case "mceRemoveEditor":
  8761. case "mceRemoveControl":
  8762. if (ed)
  8763. ed.remove();
  8764. return true;
  8765. case 'mceToggleEditor':
  8766. if (!ed) {
  8767. t.execCommand('mceAddControl', 0, v);
  8768. return true;
  8769. }
  8770. if (ed.isHidden())
  8771. ed.show();
  8772. else
  8773. ed.hide();
  8774. return true;
  8775. }
  8776. // Run command on active editor
  8777. if (t.activeEditor)
  8778. return t.activeEditor.execCommand(c, u, v);
  8779. return false;
  8780. },
  8781. execInstanceCommand : function(id, c, u, v) {
  8782. var ed = this.get(id);
  8783. if (ed)
  8784. return ed.execCommand(c, u, v);
  8785. return false;
  8786. },
  8787. triggerSave : function() {
  8788. each(this.editors, function(e) {
  8789. e.save();
  8790. });
  8791. },
  8792. addI18n : function(p, o) {
  8793. var lo, i18n = this.i18n;
  8794. if (!tinymce.is(p, 'string')) {
  8795. each(p, function(o, lc) {
  8796. each(o, function(o, g) {
  8797. each(o, function(o, k) {
  8798. if (g === 'common')
  8799. i18n[lc + '.' + k] = o;
  8800. else
  8801. i18n[lc + '.' + g + '.' + k] = o;
  8802. });
  8803. });
  8804. });
  8805. } else {
  8806. each(o, function(o, k) {
  8807. i18n[p + '.' + k] = o;
  8808. });
  8809. }
  8810. },
  8811. // Private methods
  8812. _setActive : function(editor) {
  8813. this.selectedInstance = this.activeEditor = editor;
  8814. }
  8815. });
  8816. })(tinymce);
  8817. (function(tinymce) {
  8818. // Shorten these names
  8819. var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend,
  8820. Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isGecko = tinymce.isGecko,
  8821. isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, is = tinymce.is,
  8822. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  8823. inArray = tinymce.inArray, grep = tinymce.grep, explode = tinymce.explode;
  8824. tinymce.create('tinymce.Editor', {
  8825. Editor : function(id, s) {
  8826. var t = this;
  8827. t.id = t.editorId = id;
  8828. t.execCommands = {};
  8829. t.queryStateCommands = {};
  8830. t.queryValueCommands = {};
  8831. t.isNotDirty = false;
  8832. t.plugins = {};
  8833. // Add events to the editor
  8834. each([
  8835. 'onPreInit',
  8836. 'onBeforeRenderUI',
  8837. 'onPostRender',
  8838. 'onInit',
  8839. 'onRemove',
  8840. 'onActivate',
  8841. 'onDeactivate',
  8842. 'onClick',
  8843. 'onEvent',
  8844. 'onMouseUp',
  8845. 'onMouseDown',
  8846. 'onDblClick',
  8847. 'onKeyDown',
  8848. 'onKeyUp',
  8849. 'onKeyPress',
  8850. 'onContextMenu',
  8851. 'onSubmit',
  8852. 'onReset',
  8853. 'onPaste',
  8854. 'onPreProcess',
  8855. 'onPostProcess',
  8856. 'onBeforeSetContent',
  8857. 'onBeforeGetContent',
  8858. 'onSetContent',
  8859. 'onGetContent',
  8860. 'onLoadContent',
  8861. 'onSaveContent',
  8862. 'onNodeChange',
  8863. 'onChange',
  8864. 'onBeforeExecCommand',
  8865. 'onExecCommand',
  8866. 'onUndo',
  8867. 'onRedo',
  8868. 'onVisualAid',
  8869. 'onSetProgressState'
  8870. ], function(e) {
  8871. t[e] = new Dispatcher(t);
  8872. });
  8873. t.settings = s = extend({
  8874. id : id,
  8875. language : 'en',
  8876. docs_language : 'en',
  8877. theme : 'simple',
  8878. skin : 'default',
  8879. delta_width : 0,
  8880. delta_height : 0,
  8881. popup_css : '',
  8882. plugins : '',
  8883. document_base_url : tinymce.documentBaseURL,
  8884. add_form_submit_trigger : 1,
  8885. submit_patch : 1,
  8886. add_unload_trigger : 1,
  8887. convert_urls : 1,
  8888. relative_urls : 1,
  8889. remove_script_host : 1,
  8890. table_inline_editing : 0,
  8891. object_resizing : 1,
  8892. cleanup : 1,
  8893. accessibility_focus : 1,
  8894. custom_shortcuts : 1,
  8895. custom_undo_redo_keyboard_shortcuts : 1,
  8896. custom_undo_redo_restore_selection : 1,
  8897. custom_undo_redo : 1,
  8898. doctype : tinymce.isIE6 ? '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' : '<!DOCTYPE>', // Use old doctype on IE 6 to avoid horizontal scroll
  8899. visual_table_class : 'mceItemTable',
  8900. visual : 1,
  8901. font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large',
  8902. font_size_legacy_values : 'xx-small,small,medium,large,x-large,xx-large,300%', // See: http://www.w3.org/TR/CSS2/fonts.html#propdef-font-size
  8903. apply_source_formatting : 1,
  8904. directionality : 'ltr',
  8905. forced_root_block : 'p',
  8906. hidden_input : 1,
  8907. padd_empty_editor : 1,
  8908. render_ui : 1,
  8909. init_theme : 1,
  8910. force_p_newlines : 1,
  8911. indentation : '30px',
  8912. keep_styles : 1,
  8913. fix_table_elements : 1,
  8914. inline_styles : 1,
  8915. convert_fonts_to_spans : true,
  8916. indent : 'simple',
  8917. indent_before : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr',
  8918. indent_after : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr',
  8919. validate : true,
  8920. entity_encoding : 'named',
  8921. url_converter : t.convertURL,
  8922. url_converter_scope : t,
  8923. ie7_compat : true
  8924. }, s);
  8925. t.documentBaseURI = new tinymce.util.URI(s.document_base_url || tinymce.documentBaseURL, {
  8926. base_uri : tinyMCE.baseURI
  8927. });
  8928. t.baseURI = tinymce.baseURI;
  8929. t.contentCSS = [];
  8930. // Call setup
  8931. t.execCallback('setup', t);
  8932. },
  8933. render : function(nst) {
  8934. var t = this, s = t.settings, id = t.id, sl = tinymce.ScriptLoader;
  8935. // Page is not loaded yet, wait for it
  8936. if (!Event.domLoaded) {
  8937. Event.add(document, 'init', function() {
  8938. t.render();
  8939. });
  8940. return;
  8941. }
  8942. tinyMCE.settings = s;
  8943. // Element not found, then skip initialization
  8944. if (!t.getElement())
  8945. return;
  8946. // Is a iPad/iPhone and not on iOS5, then skip initialization. We need to sniff
  8947. // here since the browser says it has contentEditable support but there is no visible
  8948. // caret We will remove this check ones Apple implements full contentEditable support
  8949. if (tinymce.isIDevice && !tinymce.isIOS5)
  8950. return;
  8951. // Add hidden input for non input elements inside form elements
  8952. if (!/TEXTAREA|INPUT/i.test(t.getElement().nodeName) && s.hidden_input && DOM.getParent(id, 'form'))
  8953. DOM.insertAfter(DOM.create('input', {type : 'hidden', name : id}), id);
  8954. if (tinymce.WindowManager)
  8955. t.windowManager = new tinymce.WindowManager(t);
  8956. if (s.encoding == 'xml') {
  8957. t.onGetContent.add(function(ed, o) {
  8958. if (o.save)
  8959. o.content = DOM.encode(o.content);
  8960. });
  8961. }
  8962. if (s.add_form_submit_trigger) {
  8963. t.onSubmit.addToTop(function() {
  8964. if (t.initialized) {
  8965. t.save();
  8966. t.isNotDirty = 1;
  8967. }
  8968. });
  8969. }
  8970. if (s.add_unload_trigger) {
  8971. t._beforeUnload = tinyMCE.onBeforeUnload.add(function() {
  8972. if (t.initialized && !t.destroyed && !t.isHidden())
  8973. t.save({format : 'raw', no_events : true});
  8974. });
  8975. }
  8976. tinymce.addUnload(t.destroy, t);
  8977. if (s.submit_patch) {
  8978. t.onBeforeRenderUI.add(function() {
  8979. var n = t.getElement().form;
  8980. if (!n)
  8981. return;
  8982. // Already patched
  8983. if (n._mceOldSubmit)
  8984. return;
  8985. // Check page uses id="submit" or name="submit" for it's submit button
  8986. if (!n.submit.nodeType && !n.submit.length) {
  8987. t.formElement = n;
  8988. n._mceOldSubmit = n.submit;
  8989. n.submit = function() {
  8990. // Save all instances
  8991. tinymce.triggerSave();
  8992. t.isNotDirty = 1;
  8993. return t.formElement._mceOldSubmit(t.formElement);
  8994. };
  8995. }
  8996. n = null;
  8997. });
  8998. }
  8999. // Load scripts
  9000. function loadScripts() {
  9001. if (s.language && s.language_load !== false)
  9002. sl.add(tinymce.baseURL + '/langs/' + s.language + '.js');
  9003. if (s.theme && s.theme.charAt(0) != '-' && !ThemeManager.urls[s.theme])
  9004. ThemeManager.load(s.theme, 'themes/' + s.theme + '/editor_template' + tinymce.suffix + '.js');
  9005. each(explode(s.plugins), function(p) {
  9006. if (p &&!PluginManager.urls[p]) {
  9007. if (p.charAt(0) == '-') {
  9008. p = p.substr(1, p.length);
  9009. var dependencies = PluginManager.dependencies(p);
  9010. each(dependencies, function(dep) {
  9011. var defaultSettings = {prefix:'plugins/', resource: dep, suffix:'/editor_plugin' + tinymce.suffix + '.js'};
  9012. var dep = PluginManager.createUrl(defaultSettings, dep);
  9013. PluginManager.load(dep.resource, dep);
  9014. });
  9015. } else {
  9016. // Skip safari plugin, since it is removed as of 3.3b1
  9017. if (p == 'safari') {
  9018. return;
  9019. }
  9020. PluginManager.load(p, {prefix:'plugins/', resource: p, suffix:'/editor_plugin' + tinymce.suffix + '.js'});
  9021. }
  9022. }
  9023. });
  9024. // Init when que is loaded
  9025. sl.loadQueue(function() {
  9026. if (!t.removed)
  9027. t.init();
  9028. });
  9029. };
  9030. loadScripts();
  9031. },
  9032. init : function() {
  9033. var n, t = this, s = t.settings, w, h, e = t.getElement(), o, ti, u, bi, bc, re, i, initializedPlugins = [];
  9034. tinymce.add(t);
  9035. s.aria_label = s.aria_label || DOM.getAttrib(e, 'aria-label', t.getLang('aria.rich_text_area'));
  9036. if (s.theme) {
  9037. s.theme = s.theme.replace(/-/, '');
  9038. o = ThemeManager.get(s.theme);
  9039. t.theme = new o();
  9040. if (t.theme.init && s.init_theme)
  9041. t.theme.init(t, ThemeManager.urls[s.theme] || tinymce.documentBaseURL.replace(/\/$/, ''));
  9042. }
  9043. function initPlugin(p) {
  9044. var c = PluginManager.get(p), u = PluginManager.urls[p] || tinymce.documentBaseURL.replace(/\/$/, ''), po;
  9045. if (c && tinymce.inArray(initializedPlugins,p) === -1) {
  9046. each(PluginManager.dependencies(p), function(dep){
  9047. initPlugin(dep);
  9048. });
  9049. po = new c(t, u);
  9050. t.plugins[p] = po;
  9051. if (po.init) {
  9052. po.init(t, u);
  9053. initializedPlugins.push(p);
  9054. }
  9055. }
  9056. }
  9057. // Create all plugins
  9058. each(explode(s.plugins.replace(/\-/g, '')), initPlugin);
  9059. // Setup popup CSS path(s)
  9060. if (s.popup_css !== false) {
  9061. if (s.popup_css)
  9062. s.popup_css = t.documentBaseURI.toAbsolute(s.popup_css);
  9063. else
  9064. s.popup_css = t.baseURI.toAbsolute("themes/" + s.theme + "/skins/" + s.skin + "/dialog.css");
  9065. }
  9066. if (s.popup_css_add)
  9067. s.popup_css += ',' + t.documentBaseURI.toAbsolute(s.popup_css_add);
  9068. t.controlManager = new tinymce.ControlManager(t);
  9069. if (s.custom_undo_redo) {
  9070. t.onBeforeExecCommand.add(function(ed, cmd, ui, val, a) {
  9071. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo))
  9072. t.undoManager.beforeChange();
  9073. });
  9074. t.onExecCommand.add(function(ed, cmd, ui, val, a) {
  9075. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo))
  9076. t.undoManager.add();
  9077. });
  9078. }
  9079. t.onExecCommand.add(function(ed, c) {
  9080. // Don't refresh the select lists until caret move
  9081. if (!/^(FontName|FontSize)$/.test(c))
  9082. t.nodeChanged();
  9083. });
  9084. // Remove ghost selections on images and tables in Gecko
  9085. if (isGecko) {
  9086. function repaint(a, o) {
  9087. if (!o || !o.initial)
  9088. t.execCommand('mceRepaint');
  9089. };
  9090. t.onUndo.add(repaint);
  9091. t.onRedo.add(repaint);
  9092. t.onSetContent.add(repaint);
  9093. }
  9094. // Enables users to override the control factory
  9095. t.onBeforeRenderUI.dispatch(t, t.controlManager);
  9096. // Measure box
  9097. if (s.render_ui) {
  9098. w = s.width || e.style.width || e.offsetWidth;
  9099. h = s.height || e.style.height || e.offsetHeight;
  9100. t.orgDisplay = e.style.display;
  9101. re = /^[0-9\.]+(|px)$/i;
  9102. if (re.test('' + w))
  9103. w = Math.max(parseInt(w) + (o.deltaWidth || 0), 100);
  9104. if (re.test('' + h))
  9105. h = Math.max(parseInt(h) + (o.deltaHeight || 0), 100);
  9106. // Render UI
  9107. o = t.theme.renderUI({
  9108. targetNode : e,
  9109. width : w,
  9110. height : h,
  9111. deltaWidth : s.delta_width,
  9112. deltaHeight : s.delta_height
  9113. });
  9114. t.editorContainer = o.editorContainer;
  9115. }
  9116. // User specified a document.domain value
  9117. if (document.domain && location.hostname != document.domain)
  9118. tinymce.relaxedDomain = document.domain;
  9119. // Resize editor
  9120. DOM.setStyles(o.sizeContainer || o.editorContainer, {
  9121. width : w,
  9122. height : h
  9123. });
  9124. // Load specified content CSS last
  9125. if (s.content_css) {
  9126. tinymce.each(explode(s.content_css), function(u) {
  9127. t.contentCSS.push(t.documentBaseURI.toAbsolute(u));
  9128. });
  9129. }
  9130. h = (o.iframeHeight || h) + (typeof(h) == 'number' ? (o.deltaHeight || 0) : '');
  9131. if (h < 100)
  9132. h = 100;
  9133. t.iframeHTML = s.doctype + '<html><head xmlns="http://www.w3.org/1999/xhtml">';
  9134. // We only need to override paths if we have to
  9135. // IE has a bug where it remove site absolute urls to relative ones if this is specified
  9136. if (s.document_base_url != tinymce.documentBaseURL)
  9137. t.iframeHTML += '<base href="' + t.documentBaseURI.getURI() + '" />';
  9138. // IE8 doesn't support carets behind images setting ie7_compat would force IE8+ to run in IE7 compat mode.
  9139. if (s.ie7_compat)
  9140. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=7" />';
  9141. else
  9142. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=edge" />';
  9143. t.iframeHTML += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
  9144. // Load the CSS by injecting them into the HTML this will reduce "flicker"
  9145. for (i = 0; i < t.contentCSS.length; i++) {
  9146. t.iframeHTML += '<link type="text/css" rel="stylesheet" href="' + t.contentCSS[i] + '" />';
  9147. }
  9148. bi = s.body_id || 'tinymce';
  9149. if (bi.indexOf('=') != -1) {
  9150. bi = t.getParam('body_id', '', 'hash');
  9151. bi = bi[t.id] || bi;
  9152. }
  9153. bc = s.body_class || '';
  9154. if (bc.indexOf('=') != -1) {
  9155. bc = t.getParam('body_class', '', 'hash');
  9156. bc = bc[t.id] || '';
  9157. }
  9158. t.iframeHTML += '</head><body id="' + bi + '" class="mceContentBody ' + bc + '"><br></body></html>';
  9159. // Domain relaxing enabled, then set document domain
  9160. if (tinymce.relaxedDomain && (isIE || (tinymce.isOpera && parseFloat(opera.version()) < 11))) {
  9161. // We need to write the contents here in IE since multiple writes messes up refresh button and back button
  9162. u = 'javascript:(function(){document.open();document.domain="' + document.domain + '";var ed = window.parent.tinyMCE.get("' + t.id + '");document.write(ed.iframeHTML);document.close();ed.setupIframe();})()';
  9163. }
  9164. // Create iframe
  9165. // TODO: ACC add the appropriate description on this.
  9166. n = DOM.add(o.iframeContainer, 'iframe', {
  9167. id : t.id + "_ifr",
  9168. src : u || 'javascript:""', // Workaround for HTTPS warning in IE6/7
  9169. frameBorder : '0',
  9170. allowTransparency : "true",
  9171. title : s.aria_label,
  9172. style : {
  9173. width : '100%',
  9174. height : h,
  9175. display : 'block' // Important for Gecko to render the iframe correctly
  9176. }
  9177. });
  9178. t.contentAreaContainer = o.iframeContainer;
  9179. DOM.get(o.editorContainer).style.display = t.orgDisplay;
  9180. DOM.get(t.id).style.display = 'none';
  9181. DOM.setAttrib(t.id, 'aria-hidden', true);
  9182. if (!tinymce.relaxedDomain || !u)
  9183. t.setupIframe();
  9184. e = n = o = null; // Cleanup
  9185. },
  9186. setupIframe : function() {
  9187. var t = this, s = t.settings, e = DOM.get(t.id), d = t.getDoc(), h, b;
  9188. // Setup iframe body
  9189. if (!isIE || !tinymce.relaxedDomain) {
  9190. d.open();
  9191. d.write(t.iframeHTML);
  9192. d.close();
  9193. if (tinymce.relaxedDomain)
  9194. d.domain = tinymce.relaxedDomain;
  9195. }
  9196. // It will not steal focus while setting contentEditable
  9197. b = t.getBody();
  9198. b.disabled = true;
  9199. if (!s.readonly)
  9200. b.contentEditable = true;
  9201. b.disabled = false;
  9202. t.schema = new tinymce.html.Schema(s);
  9203. t.dom = new tinymce.dom.DOMUtils(t.getDoc(), {
  9204. keep_values : true,
  9205. url_converter : t.convertURL,
  9206. url_converter_scope : t,
  9207. hex_colors : s.force_hex_style_colors,
  9208. class_filter : s.class_filter,
  9209. update_styles : 1,
  9210. fix_ie_paragraphs : 1,
  9211. schema : t.schema
  9212. });
  9213. t.parser = new tinymce.html.DomParser(s, t.schema);
  9214. // Force anchor names closed, unless the setting "allow_html_in_named_anchor" is explicitly included.
  9215. if (!t.settings.allow_html_in_named_anchor) {
  9216. t.parser.addAttributeFilter('name', function(nodes, name) {
  9217. var i = nodes.length, sibling, prevSibling, parent, node;
  9218. while (i--) {
  9219. node = nodes[i];
  9220. if (node.name === 'a' && node.firstChild) {
  9221. parent = node.parent;
  9222. // Move children after current node
  9223. sibling = node.lastChild;
  9224. do {
  9225. prevSibling = sibling.prev;
  9226. parent.insert(sibling, node);
  9227. sibling = prevSibling;
  9228. } while (sibling);
  9229. }
  9230. }
  9231. });
  9232. }
  9233. // Convert src and href into data-mce-src, data-mce-href and data-mce-style
  9234. t.parser.addAttributeFilter('src,href,style', function(nodes, name) {
  9235. var i = nodes.length, node, dom = t.dom, value, internalName;
  9236. while (i--) {
  9237. node = nodes[i];
  9238. value = node.attr(name);
  9239. internalName = 'data-mce-' + name;
  9240. // Add internal attribute if we need to we don't on a refresh of the document
  9241. if (!node.attributes.map[internalName]) {
  9242. if (name === "style")
  9243. node.attr(internalName, dom.serializeStyle(dom.parseStyle(value), node.name));
  9244. else
  9245. node.attr(internalName, t.convertURL(value, name, node.name));
  9246. }
  9247. }
  9248. });
  9249. // Keep scripts from executing
  9250. t.parser.addNodeFilter('script', function(nodes, name) {
  9251. var i = nodes.length, node;
  9252. while (i--) {
  9253. node = nodes[i];
  9254. node.attr('type', 'mce-' + (node.attr('type') || 'text/javascript'));
  9255. }
  9256. });
  9257. t.parser.addNodeFilter('#cdata', function(nodes, name) {
  9258. var i = nodes.length, node;
  9259. while (i--) {
  9260. node = nodes[i];
  9261. node.type = 8;
  9262. node.name = '#comment';
  9263. node.value = '[CDATA[' + node.value + ']]';
  9264. }
  9265. });
  9266. t.parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function(nodes, name) {
  9267. var i = nodes.length, node, nonEmptyElements = t.schema.getNonEmptyElements();
  9268. while (i--) {
  9269. node = nodes[i];
  9270. if (node.isEmpty(nonEmptyElements))
  9271. node.empty().append(new tinymce.html.Node('br', 1)).shortEnded = true;
  9272. }
  9273. });
  9274. t.serializer = new tinymce.dom.Serializer(s, t.dom, t.schema);
  9275. t.selection = new tinymce.dom.Selection(t.dom, t.getWin(), t.serializer);
  9276. t.formatter = new tinymce.Formatter(this);
  9277. // Register default formats
  9278. t.formatter.register({
  9279. alignleft : [
  9280. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}},
  9281. {selector : 'img,table', collapsed : false, styles : {'float' : 'left'}}
  9282. ],
  9283. aligncenter : [
  9284. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}},
  9285. {selector : 'img', collapsed : false, styles : {display : 'block', marginLeft : 'auto', marginRight : 'auto'}},
  9286. {selector : 'table', collapsed : false, styles : {marginLeft : 'auto', marginRight : 'auto'}}
  9287. ],
  9288. alignright : [
  9289. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}},
  9290. {selector : 'img,table', collapsed : false, styles : {'float' : 'right'}}
  9291. ],
  9292. alignfull : [
  9293. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'justify'}}
  9294. ],
  9295. bold : [
  9296. {inline : 'strong', remove : 'all'},
  9297. {inline : 'span', styles : {fontWeight : 'bold'}},
  9298. {inline : 'b', remove : 'all'}
  9299. ],
  9300. italic : [
  9301. {inline : 'em', remove : 'all'},
  9302. {inline : 'span', styles : {fontStyle : 'italic'}},
  9303. {inline : 'i', remove : 'all'}
  9304. ],
  9305. underline : [
  9306. {inline : 'span', styles : {textDecoration : 'underline'}, exact : true},
  9307. {inline : 'u', remove : 'all'}
  9308. ],
  9309. strikethrough : [
  9310. {inline : 'span', styles : {textDecoration : 'line-through'}, exact : true},
  9311. {inline : 'strike', remove : 'all'}
  9312. ],
  9313. forecolor : {inline : 'span', styles : {color : '%value'}, wrap_links : false},
  9314. hilitecolor : {inline : 'span', styles : {backgroundColor : '%value'}, wrap_links : false},
  9315. fontname : {inline : 'span', styles : {fontFamily : '%value'}},
  9316. fontsize : {inline : 'span', styles : {fontSize : '%value'}},
  9317. fontsize_class : {inline : 'span', attributes : {'class' : '%value'}},
  9318. blockquote : {block : 'blockquote', wrapper : 1, remove : 'all'},
  9319. subscript : {inline : 'sub'},
  9320. superscript : {inline : 'sup'},
  9321. link : {inline : 'a', selector : 'a', remove : 'all', split : true, deep : true,
  9322. onmatch : function(node) {
  9323. return true;
  9324. },
  9325. onformat : function(elm, fmt, vars) {
  9326. each(vars, function(value, key) {
  9327. t.dom.setAttrib(elm, key, value);
  9328. });
  9329. }
  9330. },
  9331. removeformat : [
  9332. {selector : 'b,strong,em,i,font,u,strike', remove : 'all', split : true, expand : false, block_expand : true, deep : true},
  9333. {selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true},
  9334. {selector : '*', attributes : ['style', 'class'], split : false, expand : false, deep : true}
  9335. ]
  9336. });
  9337. // Register default block formats
  9338. each('p h1 h2 h3 h4 h5 h6 div address pre div code dt dd samp'.split(/\s/), function(name) {
  9339. t.formatter.register(name, {block : name, remove : 'all'});
  9340. });
  9341. // Register user defined formats
  9342. t.formatter.register(t.settings.formats);
  9343. t.undoManager = new tinymce.UndoManager(t);
  9344. // Pass through
  9345. t.undoManager.onAdd.add(function(um, l) {
  9346. if (um.hasUndo())
  9347. return t.onChange.dispatch(t, l, um);
  9348. });
  9349. t.undoManager.onUndo.add(function(um, l) {
  9350. return t.onUndo.dispatch(t, l, um);
  9351. });
  9352. t.undoManager.onRedo.add(function(um, l) {
  9353. return t.onRedo.dispatch(t, l, um);
  9354. });
  9355. t.forceBlocks = new tinymce.ForceBlocks(t, {
  9356. forced_root_block : s.forced_root_block
  9357. });
  9358. t.editorCommands = new tinymce.EditorCommands(t);
  9359. // Pass through
  9360. t.serializer.onPreProcess.add(function(se, o) {
  9361. return t.onPreProcess.dispatch(t, o, se);
  9362. });
  9363. t.serializer.onPostProcess.add(function(se, o) {
  9364. return t.onPostProcess.dispatch(t, o, se);
  9365. });
  9366. t.onPreInit.dispatch(t);
  9367. if (!s.gecko_spellcheck)
  9368. t.getBody().spellcheck = 0;
  9369. if (!s.readonly)
  9370. t._addEvents();
  9371. t.controlManager.onPostRender.dispatch(t, t.controlManager);
  9372. t.onPostRender.dispatch(t);
  9373. t.quirks = new tinymce.util.Quirks(this);
  9374. if (s.directionality)
  9375. t.getBody().dir = s.directionality;
  9376. if (s.nowrap)
  9377. t.getBody().style.whiteSpace = "nowrap";
  9378. if (s.handle_node_change_callback) {
  9379. t.onNodeChange.add(function(ed, cm, n) {
  9380. t.execCallback('handle_node_change_callback', t.id, n, -1, -1, true, t.selection.isCollapsed());
  9381. });
  9382. }
  9383. if (s.save_callback) {
  9384. t.onSaveContent.add(function(ed, o) {
  9385. var h = t.execCallback('save_callback', t.id, o.content, t.getBody());
  9386. if (h)
  9387. o.content = h;
  9388. });
  9389. }
  9390. if (s.onchange_callback) {
  9391. t.onChange.add(function(ed, l) {
  9392. t.execCallback('onchange_callback', t, l);
  9393. });
  9394. }
  9395. if (s.protect) {
  9396. t.onBeforeSetContent.add(function(ed, o) {
  9397. if (s.protect) {
  9398. each(s.protect, function(pattern) {
  9399. o.content = o.content.replace(pattern, function(str) {
  9400. return '<!--mce:protected ' + escape(str) + '-->';
  9401. });
  9402. });
  9403. }
  9404. });
  9405. }
  9406. if (s.convert_newlines_to_brs) {
  9407. t.onBeforeSetContent.add(function(ed, o) {
  9408. if (o.initial)
  9409. o.content = o.content.replace(/\r?\n/g, '<br />');
  9410. });
  9411. }
  9412. if (s.preformatted) {
  9413. t.onPostProcess.add(function(ed, o) {
  9414. o.content = o.content.replace(/^\s*<pre.*?>/, '');
  9415. o.content = o.content.replace(/<\/pre>\s*$/, '');
  9416. if (o.set)
  9417. o.content = '<pre class="mceItemHidden">' + o.content + '</pre>';
  9418. });
  9419. }
  9420. if (s.verify_css_classes) {
  9421. t.serializer.attribValueFilter = function(n, v) {
  9422. var s, cl;
  9423. if (n == 'class') {
  9424. // Build regexp for classes
  9425. if (!t.classesRE) {
  9426. cl = t.dom.getClasses();
  9427. if (cl.length > 0) {
  9428. s = '';
  9429. each (cl, function(o) {
  9430. s += (s ? '|' : '') + o['class'];
  9431. });
  9432. t.classesRE = new RegExp('(' + s + ')', 'gi');
  9433. }
  9434. }
  9435. return !t.classesRE || /(\bmceItem\w+\b|\bmceTemp\w+\b)/g.test(v) || t.classesRE.test(v) ? v : '';
  9436. }
  9437. return v;
  9438. };
  9439. }
  9440. if (s.cleanup_callback) {
  9441. t.onBeforeSetContent.add(function(ed, o) {
  9442. o.content = t.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  9443. });
  9444. t.onPreProcess.add(function(ed, o) {
  9445. if (o.set)
  9446. t.execCallback('cleanup_callback', 'insert_to_editor_dom', o.node, o);
  9447. if (o.get)
  9448. t.execCallback('cleanup_callback', 'get_from_editor_dom', o.node, o);
  9449. });
  9450. t.onPostProcess.add(function(ed, o) {
  9451. if (o.set)
  9452. o.content = t.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  9453. if (o.get)
  9454. o.content = t.execCallback('cleanup_callback', 'get_from_editor', o.content, o);
  9455. });
  9456. }
  9457. if (s.save_callback) {
  9458. t.onGetContent.add(function(ed, o) {
  9459. if (o.save)
  9460. o.content = t.execCallback('save_callback', t.id, o.content, t.getBody());
  9461. });
  9462. }
  9463. if (s.handle_event_callback) {
  9464. t.onEvent.add(function(ed, e, o) {
  9465. if (t.execCallback('handle_event_callback', e, ed, o) === false)
  9466. Event.cancel(e);
  9467. });
  9468. }
  9469. // Add visual aids when new contents is added
  9470. t.onSetContent.add(function() {
  9471. t.addVisual(t.getBody());
  9472. });
  9473. // Remove empty contents
  9474. if (s.padd_empty_editor) {
  9475. t.onPostProcess.add(function(ed, o) {
  9476. o.content = o.content.replace(/^(<p[^>]*>(&nbsp;|&#160;|\s|\u00a0|)<\/p>[\r\n]*|<br \/>[\r\n]*)$/, '');
  9477. });
  9478. }
  9479. if (isGecko) {
  9480. // Fix gecko link bug, when a link is placed at the end of block elements there is
  9481. // no way to move the caret behind the link. This fix adds a bogus br element after the link
  9482. function fixLinks(ed, o) {
  9483. each(ed.dom.select('a'), function(n) {
  9484. var pn = n.parentNode;
  9485. if (ed.dom.isBlock(pn) && pn.lastChild === n)
  9486. ed.dom.add(pn, 'br', {'data-mce-bogus' : 1});
  9487. });
  9488. };
  9489. t.onExecCommand.add(function(ed, cmd) {
  9490. if (cmd === 'CreateLink')
  9491. fixLinks(ed);
  9492. });
  9493. t.onSetContent.add(t.selection.onSetContent.add(fixLinks));
  9494. }
  9495. t.load({initial : true, format : 'html'});
  9496. t.startContent = t.getContent({format : 'raw'});
  9497. t.undoManager.add();
  9498. t.initialized = true;
  9499. t.onInit.dispatch(t);
  9500. t.execCallback('setupcontent_callback', t.id, t.getBody(), t.getDoc());
  9501. t.execCallback('init_instance_callback', t);
  9502. t.focus(true);
  9503. t.nodeChanged({initial : 1});
  9504. // Load specified content CSS last
  9505. each(t.contentCSS, function(u) {
  9506. t.dom.loadCSS(u);
  9507. });
  9508. // Handle auto focus
  9509. if (s.auto_focus) {
  9510. setTimeout(function () {
  9511. var ed = tinymce.get(s.auto_focus);
  9512. ed.selection.select(ed.getBody(), 1);
  9513. ed.selection.collapse(1);
  9514. ed.getBody().focus();
  9515. ed.getWin().focus();
  9516. }, 100);
  9517. }
  9518. e = null;
  9519. },
  9520. focus : function(sf) {
  9521. var oed, t = this, selection = t.selection, ce = t.settings.content_editable, ieRng, controlElm, doc = t.getDoc();
  9522. if (!sf) {
  9523. // Get selected control element
  9524. ieRng = selection.getRng();
  9525. if (ieRng.item) {
  9526. controlElm = ieRng.item(0);
  9527. }
  9528. t._refreshContentEditable();
  9529. selection.normalize();
  9530. // Is not content editable
  9531. if (!ce)
  9532. t.getWin().focus();
  9533. // Focus the body as well since it's contentEditable
  9534. if (tinymce.isGecko) {
  9535. t.getBody().focus();
  9536. }
  9537. // Restore selected control element
  9538. // This is needed when for example an image is selected within a
  9539. // layer a call to focus will then remove the control selection
  9540. if (controlElm && controlElm.ownerDocument == doc) {
  9541. ieRng = doc.body.createControlRange();
  9542. ieRng.addElement(controlElm);
  9543. ieRng.select();
  9544. }
  9545. }
  9546. if (tinymce.activeEditor != t) {
  9547. if ((oed = tinymce.activeEditor) != null)
  9548. oed.onDeactivate.dispatch(oed, t);
  9549. t.onActivate.dispatch(t, oed);
  9550. }
  9551. tinymce._setActive(t);
  9552. },
  9553. execCallback : function(n) {
  9554. var t = this, f = t.settings[n], s;
  9555. if (!f)
  9556. return;
  9557. // Look through lookup
  9558. if (t.callbackLookup && (s = t.callbackLookup[n])) {
  9559. f = s.func;
  9560. s = s.scope;
  9561. }
  9562. if (is(f, 'string')) {
  9563. s = f.replace(/\.\w+$/, '');
  9564. s = s ? tinymce.resolve(s) : 0;
  9565. f = tinymce.resolve(f);
  9566. t.callbackLookup = t.callbackLookup || {};
  9567. t.callbackLookup[n] = {func : f, scope : s};
  9568. }
  9569. return f.apply(s || t, Array.prototype.slice.call(arguments, 1));
  9570. },
  9571. translate : function(s) {
  9572. var c = this.settings.language || 'en', i18n = tinymce.i18n;
  9573. if (!s)
  9574. return '';
  9575. return i18n[c + '.' + s] || s.replace(/{\#([^}]+)\}/g, function(a, b) {
  9576. return i18n[c + '.' + b] || '{#' + b + '}';
  9577. });
  9578. },
  9579. getLang : function(n, dv) {
  9580. return tinymce.i18n[(this.settings.language || 'en') + '.' + n] || (is(dv) ? dv : '{#' + n + '}');
  9581. },
  9582. getParam : function(n, dv, ty) {
  9583. var tr = tinymce.trim, v = is(this.settings[n]) ? this.settings[n] : dv, o;
  9584. if (ty === 'hash') {
  9585. o = {};
  9586. if (is(v, 'string')) {
  9587. each(v.indexOf('=') > 0 ? v.split(/[;,](?![^=;,]*(?:[;,]|$))/) : v.split(','), function(v) {
  9588. v = v.split('=');
  9589. if (v.length > 1)
  9590. o[tr(v[0])] = tr(v[1]);
  9591. else
  9592. o[tr(v[0])] = tr(v);
  9593. });
  9594. } else
  9595. o = v;
  9596. return o;
  9597. }
  9598. return v;
  9599. },
  9600. nodeChanged : function(o) {
  9601. var t = this, s = t.selection, n = s.getStart() || t.getBody();
  9602. // Fix for bug #1896577 it seems that this can not be fired while the editor is loading
  9603. if (t.initialized) {
  9604. o = o || {};
  9605. n = isIE && n.ownerDocument != t.getDoc() ? t.getBody() : n; // Fix for IE initial state
  9606. // Get parents and add them to object
  9607. o.parents = [];
  9608. t.dom.getParent(n, function(node) {
  9609. if (node.nodeName == 'BODY')
  9610. return true;
  9611. o.parents.push(node);
  9612. });
  9613. t.onNodeChange.dispatch(
  9614. t,
  9615. o ? o.controlManager || t.controlManager : t.controlManager,
  9616. n,
  9617. s.isCollapsed(),
  9618. o
  9619. );
  9620. }
  9621. },
  9622. addButton : function(n, s) {
  9623. var t = this;
  9624. t.buttons = t.buttons || {};
  9625. t.buttons[n] = s;
  9626. },
  9627. addCommand : function(name, callback, scope) {
  9628. this.execCommands[name] = {func : callback, scope : scope || this};
  9629. },
  9630. addQueryStateHandler : function(name, callback, scope) {
  9631. this.queryStateCommands[name] = {func : callback, scope : scope || this};
  9632. },
  9633. addQueryValueHandler : function(name, callback, scope) {
  9634. this.queryValueCommands[name] = {func : callback, scope : scope || this};
  9635. },
  9636. addShortcut : function(pa, desc, cmd_func, sc) {
  9637. var t = this, c;
  9638. if (!t.settings.custom_shortcuts)
  9639. return false;
  9640. t.shortcuts = t.shortcuts || {};
  9641. if (is(cmd_func, 'string')) {
  9642. c = cmd_func;
  9643. cmd_func = function() {
  9644. t.execCommand(c, false, null);
  9645. };
  9646. }
  9647. if (is(cmd_func, 'object')) {
  9648. c = cmd_func;
  9649. cmd_func = function() {
  9650. t.execCommand(c[0], c[1], c[2]);
  9651. };
  9652. }
  9653. each(explode(pa), function(pa) {
  9654. var o = {
  9655. func : cmd_func,
  9656. scope : sc || this,
  9657. desc : desc,
  9658. alt : false,
  9659. ctrl : false,
  9660. shift : false
  9661. };
  9662. each(explode(pa, '+'), function(v) {
  9663. switch (v) {
  9664. case 'alt':
  9665. case 'ctrl':
  9666. case 'shift':
  9667. o[v] = true;
  9668. break;
  9669. default:
  9670. o.charCode = v.charCodeAt(0);
  9671. o.keyCode = v.toUpperCase().charCodeAt(0);
  9672. }
  9673. });
  9674. t.shortcuts[(o.ctrl ? 'ctrl' : '') + ',' + (o.alt ? 'alt' : '') + ',' + (o.shift ? 'shift' : '') + ',' + o.keyCode] = o;
  9675. });
  9676. return true;
  9677. },
  9678. execCommand : function(cmd, ui, val, a) {
  9679. var t = this, s = 0, o, st;
  9680. if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint|SelectAll)$/.test(cmd) && (!a || !a.skip_focus))
  9681. t.focus();
  9682. o = {};
  9683. t.onBeforeExecCommand.dispatch(t, cmd, ui, val, o);
  9684. if (o.terminate)
  9685. return false;
  9686. // Command callback
  9687. if (t.execCallback('execcommand_callback', t.id, t.selection.getNode(), cmd, ui, val)) {
  9688. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9689. return true;
  9690. }
  9691. // Registred commands
  9692. if (o = t.execCommands[cmd]) {
  9693. st = o.func.call(o.scope, ui, val);
  9694. // Fall through on true
  9695. if (st !== true) {
  9696. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9697. return st;
  9698. }
  9699. }
  9700. // Plugin commands
  9701. each(t.plugins, function(p) {
  9702. if (p.execCommand && p.execCommand(cmd, ui, val)) {
  9703. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9704. s = 1;
  9705. return false;
  9706. }
  9707. });
  9708. if (s)
  9709. return true;
  9710. // Theme commands
  9711. if (t.theme && t.theme.execCommand && t.theme.execCommand(cmd, ui, val)) {
  9712. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9713. return true;
  9714. }
  9715. // Editor commands
  9716. if (t.editorCommands.execCommand(cmd, ui, val)) {
  9717. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9718. return true;
  9719. }
  9720. // Browser commands
  9721. t.getDoc().execCommand(cmd, ui, val);
  9722. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  9723. },
  9724. queryCommandState : function(cmd) {
  9725. var t = this, o, s;
  9726. // Is hidden then return undefined
  9727. if (t._isHidden())
  9728. return;
  9729. // Registred commands
  9730. if (o = t.queryStateCommands[cmd]) {
  9731. s = o.func.call(o.scope);
  9732. // Fall though on true
  9733. if (s !== true)
  9734. return s;
  9735. }
  9736. // Registred commands
  9737. o = t.editorCommands.queryCommandState(cmd);
  9738. if (o !== -1)
  9739. return o;
  9740. // Browser commands
  9741. try {
  9742. return this.getDoc().queryCommandState(cmd);
  9743. } catch (ex) {
  9744. // Fails sometimes see bug: 1896577
  9745. }
  9746. },
  9747. queryCommandValue : function(c) {
  9748. var t = this, o, s;
  9749. // Is hidden then return undefined
  9750. if (t._isHidden())
  9751. return;
  9752. // Registred commands
  9753. if (o = t.queryValueCommands[c]) {
  9754. s = o.func.call(o.scope);
  9755. // Fall though on true
  9756. if (s !== true)
  9757. return s;
  9758. }
  9759. // Registred commands
  9760. o = t.editorCommands.queryCommandValue(c);
  9761. if (is(o))
  9762. return o;
  9763. // Browser commands
  9764. try {
  9765. return this.getDoc().queryCommandValue(c);
  9766. } catch (ex) {
  9767. // Fails sometimes see bug: 1896577
  9768. }
  9769. },
  9770. show : function() {
  9771. var t = this;
  9772. DOM.show(t.getContainer());
  9773. DOM.hide(t.id);
  9774. t.load();
  9775. },
  9776. hide : function() {
  9777. var t = this, d = t.getDoc();
  9778. // Fixed bug where IE has a blinking cursor left from the editor
  9779. if (isIE && d)
  9780. d.execCommand('SelectAll');
  9781. // We must save before we hide so Safari doesn't crash
  9782. t.save();
  9783. DOM.hide(t.getContainer());
  9784. DOM.setStyle(t.id, 'display', t.orgDisplay);
  9785. },
  9786. isHidden : function() {
  9787. return !DOM.isHidden(this.id);
  9788. },
  9789. setProgressState : function(b, ti, o) {
  9790. this.onSetProgressState.dispatch(this, b, ti, o);
  9791. return b;
  9792. },
  9793. load : function(o) {
  9794. var t = this, e = t.getElement(), h;
  9795. if (e) {
  9796. o = o || {};
  9797. o.load = true;
  9798. // Double encode existing entities in the value
  9799. h = t.setContent(is(e.value) ? e.value : e.innerHTML, o);
  9800. o.element = e;
  9801. if (!o.no_events)
  9802. t.onLoadContent.dispatch(t, o);
  9803. o.element = e = null;
  9804. return h;
  9805. }
  9806. },
  9807. save : function(o) {
  9808. var t = this, e = t.getElement(), h, f;
  9809. if (!e || !t.initialized)
  9810. return;
  9811. o = o || {};
  9812. o.save = true;
  9813. // Add undo level will trigger onchange event
  9814. if (!o.no_events) {
  9815. t.undoManager.typing = false;
  9816. t.undoManager.add();
  9817. }
  9818. o.element = e;
  9819. h = o.content = t.getContent(o);
  9820. if (!o.no_events)
  9821. t.onSaveContent.dispatch(t, o);
  9822. h = o.content;
  9823. if (!/TEXTAREA|INPUT/i.test(e.nodeName)) {
  9824. e.innerHTML = h;
  9825. // Update hidden form element
  9826. if (f = DOM.getParent(t.id, 'form')) {
  9827. each(f.elements, function(e) {
  9828. if (e.name == t.id) {
  9829. e.value = h;
  9830. return false;
  9831. }
  9832. });
  9833. }
  9834. } else
  9835. e.value = h;
  9836. o.element = e = null;
  9837. return h;
  9838. },
  9839. setContent : function(content, args) {
  9840. var self = this, rootNode, body = self.getBody(), forcedRootBlockName;
  9841. // Setup args object
  9842. args = args || {};
  9843. args.format = args.format || 'html';
  9844. args.set = true;
  9845. args.content = content;
  9846. // Do preprocessing
  9847. if (!args.no_events)
  9848. self.onBeforeSetContent.dispatch(self, args);
  9849. content = args.content;
  9850. // Padd empty content in Gecko and Safari. Commands will otherwise fail on the content
  9851. // It will also be impossible to place the caret in the editor unless there is a BR element present
  9852. if (!tinymce.isIE && (content.length === 0 || /^\s+$/.test(content))) {
  9853. forcedRootBlockName = self.settings.forced_root_block;
  9854. if (forcedRootBlockName)
  9855. content = '<' + forcedRootBlockName + '><br data-mce-bogus="1"></' + forcedRootBlockName + '>';
  9856. else
  9857. content = '<br data-mce-bogus="1">';
  9858. body.innerHTML = content;
  9859. self.selection.select(body, true);
  9860. self.selection.collapse(true);
  9861. return;
  9862. }
  9863. // Parse and serialize the html
  9864. if (args.format !== 'raw') {
  9865. content = new tinymce.html.Serializer({}, self.schema).serialize(
  9866. self.parser.parse(content)
  9867. );
  9868. }
  9869. // Set the new cleaned contents to the editor
  9870. args.content = tinymce.trim(content);
  9871. self.dom.setHTML(body, args.content);
  9872. // Do post processing
  9873. if (!args.no_events)
  9874. self.onSetContent.dispatch(self, args);
  9875. self.selection.normalize();
  9876. return args.content;
  9877. },
  9878. getContent : function(args) {
  9879. var self = this, content;
  9880. // Setup args object
  9881. args = args || {};
  9882. args.format = args.format || 'html';
  9883. args.get = true;
  9884. // Do preprocessing
  9885. if (!args.no_events)
  9886. self.onBeforeGetContent.dispatch(self, args);
  9887. // Get raw contents or by default the cleaned contents
  9888. if (args.format == 'raw')
  9889. content = self.getBody().innerHTML;
  9890. else
  9891. content = self.serializer.serialize(self.getBody(), args);
  9892. args.content = tinymce.trim(content);
  9893. // Do post processing
  9894. if (!args.no_events)
  9895. self.onGetContent.dispatch(self, args);
  9896. return args.content;
  9897. },
  9898. isDirty : function() {
  9899. var self = this;
  9900. return tinymce.trim(self.startContent) != tinymce.trim(self.getContent({format : 'raw', no_events : 1})) && !self.isNotDirty;
  9901. },
  9902. getContainer : function() {
  9903. var t = this;
  9904. if (!t.container)
  9905. t.container = DOM.get(t.editorContainer || t.id + '_parent');
  9906. return t.container;
  9907. },
  9908. getContentAreaContainer : function() {
  9909. return this.contentAreaContainer;
  9910. },
  9911. getElement : function() {
  9912. return DOM.get(this.settings.content_element || this.id);
  9913. },
  9914. getWin : function() {
  9915. var t = this, e;
  9916. if (!t.contentWindow) {
  9917. e = DOM.get(t.id + "_ifr");
  9918. if (e)
  9919. t.contentWindow = e.contentWindow;
  9920. }
  9921. return t.contentWindow;
  9922. },
  9923. getDoc : function() {
  9924. var t = this, w;
  9925. if (!t.contentDocument) {
  9926. w = t.getWin();
  9927. if (w)
  9928. t.contentDocument = w.document;
  9929. }
  9930. return t.contentDocument;
  9931. },
  9932. getBody : function() {
  9933. return this.bodyElement || this.getDoc().body;
  9934. },
  9935. convertURL : function(u, n, e) {
  9936. var t = this, s = t.settings;
  9937. // Use callback instead
  9938. if (s.urlconverter_callback)
  9939. return t.execCallback('urlconverter_callback', u, e, true, n);
  9940. // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs
  9941. if (!s.convert_urls || (e && e.nodeName == 'LINK') || u.indexOf('file:') === 0)
  9942. return u;
  9943. // Convert to relative
  9944. if (s.relative_urls)
  9945. return t.documentBaseURI.toRelative(u);
  9946. // Convert to absolute
  9947. u = t.documentBaseURI.toAbsolute(u, s.remove_script_host);
  9948. return u;
  9949. },
  9950. addVisual : function(e) {
  9951. var t = this, s = t.settings;
  9952. e = e || t.getBody();
  9953. if (!is(t.hasVisual))
  9954. t.hasVisual = s.visual;
  9955. each(t.dom.select('table,a', e), function(e) {
  9956. var v;
  9957. switch (e.nodeName) {
  9958. case 'TABLE':
  9959. v = t.dom.getAttrib(e, 'border');
  9960. if (!v || v == '0') {
  9961. if (t.hasVisual)
  9962. t.dom.addClass(e, s.visual_table_class);
  9963. else
  9964. t.dom.removeClass(e, s.visual_table_class);
  9965. }
  9966. return;
  9967. case 'A':
  9968. v = t.dom.getAttrib(e, 'name');
  9969. if (v) {
  9970. if (t.hasVisual)
  9971. t.dom.addClass(e, 'mceItemAnchor');
  9972. else
  9973. t.dom.removeClass(e, 'mceItemAnchor');
  9974. }
  9975. return;
  9976. }
  9977. });
  9978. t.onVisualAid.dispatch(t, e, t.hasVisual);
  9979. },
  9980. remove : function() {
  9981. var t = this, e = t.getContainer();
  9982. t.removed = 1; // Cancels post remove event execution
  9983. t.hide();
  9984. t.execCallback('remove_instance_callback', t);
  9985. t.onRemove.dispatch(t);
  9986. // Clear all execCommand listeners this is required to avoid errors if the editor was removed inside another command
  9987. t.onExecCommand.listeners = [];
  9988. tinymce.remove(t);
  9989. DOM.remove(e);
  9990. },
  9991. destroy : function(s) {
  9992. var t = this;
  9993. // One time is enough
  9994. if (t.destroyed)
  9995. return;
  9996. if (!s) {
  9997. tinymce.removeUnload(t.destroy);
  9998. tinyMCE.onBeforeUnload.remove(t._beforeUnload);
  9999. // Manual destroy
  10000. if (t.theme && t.theme.destroy)
  10001. t.theme.destroy();
  10002. // Destroy controls, selection and dom
  10003. t.controlManager.destroy();
  10004. t.selection.destroy();
  10005. t.dom.destroy();
  10006. // Remove all events
  10007. // Don't clear the window or document if content editable
  10008. // is enabled since other instances might still be present
  10009. if (!t.settings.content_editable) {
  10010. Event.clear(t.getWin());
  10011. Event.clear(t.getDoc());
  10012. }
  10013. Event.clear(t.getBody());
  10014. Event.clear(t.formElement);
  10015. }
  10016. if (t.formElement) {
  10017. t.formElement.submit = t.formElement._mceOldSubmit;
  10018. t.formElement._mceOldSubmit = null;
  10019. }
  10020. t.contentAreaContainer = t.formElement = t.container = t.settings.content_element = t.bodyElement = t.contentDocument = t.contentWindow = null;
  10021. if (t.selection)
  10022. t.selection = t.selection.win = t.selection.dom = t.selection.dom.doc = null;
  10023. t.destroyed = 1;
  10024. },
  10025. // Internal functions
  10026. _addEvents : function() {
  10027. // 'focus', 'blur', 'dblclick', 'beforedeactivate', submit, reset
  10028. var t = this, i, s = t.settings, dom = t.dom, lo = {
  10029. mouseup : 'onMouseUp',
  10030. mousedown : 'onMouseDown',
  10031. click : 'onClick',
  10032. keyup : 'onKeyUp',
  10033. keydown : 'onKeyDown',
  10034. keypress : 'onKeyPress',
  10035. submit : 'onSubmit',
  10036. reset : 'onReset',
  10037. contextmenu : 'onContextMenu',
  10038. dblclick : 'onDblClick',
  10039. paste : 'onPaste' // Doesn't work in all browsers yet
  10040. };
  10041. function eventHandler(e, o) {
  10042. var ty = e.type;
  10043. // Don't fire events when it's removed
  10044. if (t.removed)
  10045. return;
  10046. // Generic event handler
  10047. if (t.onEvent.dispatch(t, e, o) !== false) {
  10048. // Specific event handler
  10049. t[lo[e.fakeType || e.type]].dispatch(t, e, o);
  10050. }
  10051. };
  10052. // Add DOM events
  10053. each(lo, function(v, k) {
  10054. switch (k) {
  10055. case 'contextmenu':
  10056. dom.bind(t.getDoc(), k, eventHandler);
  10057. break;
  10058. case 'paste':
  10059. dom.bind(t.getBody(), k, function(e) {
  10060. eventHandler(e);
  10061. });
  10062. break;
  10063. case 'submit':
  10064. case 'reset':
  10065. dom.bind(t.getElement().form || DOM.getParent(t.id, 'form'), k, eventHandler);
  10066. break;
  10067. default:
  10068. dom.bind(s.content_editable ? t.getBody() : t.getDoc(), k, eventHandler);
  10069. }
  10070. });
  10071. dom.bind(s.content_editable ? t.getBody() : (isGecko ? t.getDoc() : t.getWin()), 'focus', function(e) {
  10072. t.focus(true);
  10073. });
  10074. // Fixes bug where a specified document_base_uri could result in broken images
  10075. // This will also fix drag drop of images in Gecko
  10076. if (tinymce.isGecko) {
  10077. dom.bind(t.getDoc(), 'DOMNodeInserted', function(e) {
  10078. var v;
  10079. e = e.target;
  10080. if (e.nodeType === 1 && e.nodeName === 'IMG' && (v = e.getAttribute('data-mce-src')))
  10081. e.src = t.documentBaseURI.toAbsolute(v);
  10082. });
  10083. }
  10084. // Set various midas options in Gecko
  10085. if (isGecko) {
  10086. function setOpts() {
  10087. var t = this, d = t.getDoc(), s = t.settings;
  10088. if (isGecko && !s.readonly) {
  10089. t._refreshContentEditable();
  10090. try {
  10091. // Try new Gecko method
  10092. d.execCommand("styleWithCSS", 0, false);
  10093. } catch (ex) {
  10094. // Use old method
  10095. if (!t._isHidden())
  10096. try {d.execCommand("useCSS", 0, true);} catch (ex) {}
  10097. }
  10098. if (!s.table_inline_editing)
  10099. try {d.execCommand('enableInlineTableEditing', false, false);} catch (ex) {}
  10100. if (!s.object_resizing)
  10101. try {d.execCommand('enableObjectResizing', false, false);} catch (ex) {}
  10102. }
  10103. };
  10104. t.onBeforeExecCommand.add(setOpts);
  10105. t.onMouseDown.add(setOpts);
  10106. }
  10107. // Add node change handlers
  10108. t.onMouseUp.add(t.nodeChanged);
  10109. //t.onClick.add(t.nodeChanged);
  10110. t.onKeyUp.add(function(ed, e) {
  10111. var c = e.keyCode;
  10112. if ((c >= 33 && c <= 36) || (c >= 37 && c <= 40) || c == 13 || c == 45 || c == 46 || c == 8 || (tinymce.isMac && (c == 91 || c == 93)) || e.ctrlKey)
  10113. t.nodeChanged();
  10114. });
  10115. // Add block quote deletion handler
  10116. t.onKeyDown.add(function(ed, e) {
  10117. // Was the BACKSPACE key pressed?
  10118. if (e.keyCode != 8)
  10119. return;
  10120. var n = ed.selection.getRng().startContainer;
  10121. var offset = ed.selection.getRng().startOffset;
  10122. while (n && n.nodeType && n.nodeType != 1 && n.parentNode)
  10123. n = n.parentNode;
  10124. // Is the cursor at the beginning of a blockquote?
  10125. if (n && n.parentNode && n.parentNode.tagName === 'BLOCKQUOTE' && n.parentNode.firstChild == n && offset == 0) {
  10126. // Remove the blockquote
  10127. ed.formatter.toggle('blockquote', null, n.parentNode);
  10128. // Move the caret to the beginning of n
  10129. var rng = ed.selection.getRng();
  10130. rng.setStart(n, 0);
  10131. rng.setEnd(n, 0);
  10132. ed.selection.setRng(rng);
  10133. ed.selection.collapse(false);
  10134. }
  10135. });
  10136. // Add reset handler
  10137. t.onReset.add(function() {
  10138. t.setContent(t.startContent, {format : 'raw'});
  10139. });
  10140. // Add shortcuts
  10141. if (s.custom_shortcuts) {
  10142. if (s.custom_undo_redo_keyboard_shortcuts) {
  10143. t.addShortcut('ctrl+z', t.getLang('undo_desc'), 'Undo');
  10144. t.addShortcut('ctrl+y', t.getLang('redo_desc'), 'Redo');
  10145. }
  10146. // Add default shortcuts for gecko
  10147. t.addShortcut('ctrl+b', t.getLang('bold_desc'), 'Bold');
  10148. t.addShortcut('ctrl+i', t.getLang('italic_desc'), 'Italic');
  10149. t.addShortcut('ctrl+u', t.getLang('underline_desc'), 'Underline');
  10150. // BlockFormat shortcuts keys
  10151. for (i=1; i<=6; i++)
  10152. t.addShortcut('ctrl+' + i, '', ['FormatBlock', false, 'h' + i]);
  10153. t.addShortcut('ctrl+7', '', ['FormatBlock', false, 'p']);
  10154. t.addShortcut('ctrl+8', '', ['FormatBlock', false, 'div']);
  10155. t.addShortcut('ctrl+9', '', ['FormatBlock', false, 'address']);
  10156. function find(e) {
  10157. var v = null;
  10158. if (!e.altKey && !e.ctrlKey && !e.metaKey)
  10159. return v;
  10160. each(t.shortcuts, function(o) {
  10161. if (tinymce.isMac && o.ctrl != e.metaKey)
  10162. return;
  10163. else if (!tinymce.isMac && o.ctrl != e.ctrlKey)
  10164. return;
  10165. if (o.alt != e.altKey)
  10166. return;
  10167. if (o.shift != e.shiftKey)
  10168. return;
  10169. if (e.keyCode == o.keyCode || (e.charCode && e.charCode == o.charCode)) {
  10170. v = o;
  10171. return false;
  10172. }
  10173. });
  10174. return v;
  10175. };
  10176. t.onKeyUp.add(function(ed, e) {
  10177. var o = find(e);
  10178. if (o)
  10179. return Event.cancel(e);
  10180. });
  10181. t.onKeyPress.add(function(ed, e) {
  10182. var o = find(e);
  10183. if (o)
  10184. return Event.cancel(e);
  10185. });
  10186. t.onKeyDown.add(function(ed, e) {
  10187. var o = find(e);
  10188. if (o) {
  10189. o.func.call(o.scope);
  10190. return Event.cancel(e);
  10191. }
  10192. });
  10193. }
  10194. if (tinymce.isIE) {
  10195. // Fix so resize will only update the width and height attributes not the styles of an image
  10196. // It will also block mceItemNoResize items
  10197. dom.bind(t.getDoc(), 'controlselect', function(e) {
  10198. var re = t.resizeInfo, cb;
  10199. e = e.target;
  10200. // Don't do this action for non image elements
  10201. if (e.nodeName !== 'IMG')
  10202. return;
  10203. if (re)
  10204. dom.unbind(re.node, re.ev, re.cb);
  10205. if (!dom.hasClass(e, 'mceItemNoResize')) {
  10206. ev = 'resizeend';
  10207. cb = dom.bind(e, ev, function(e) {
  10208. var v;
  10209. e = e.target;
  10210. if (v = dom.getStyle(e, 'width')) {
  10211. dom.setAttrib(e, 'width', v.replace(/[^0-9%]+/g, ''));
  10212. dom.setStyle(e, 'width', '');
  10213. }
  10214. if (v = dom.getStyle(e, 'height')) {
  10215. dom.setAttrib(e, 'height', v.replace(/[^0-9%]+/g, ''));
  10216. dom.setStyle(e, 'height', '');
  10217. }
  10218. });
  10219. } else {
  10220. ev = 'resizestart';
  10221. cb = dom.bind(e, 'resizestart', Event.cancel, Event);
  10222. }
  10223. re = t.resizeInfo = {
  10224. node : e,
  10225. ev : ev,
  10226. cb : cb
  10227. };
  10228. });
  10229. }
  10230. if (tinymce.isOpera) {
  10231. t.onClick.add(function(ed, e) {
  10232. Event.prevent(e);
  10233. });
  10234. }
  10235. // Add custom undo/redo handlers
  10236. if (s.custom_undo_redo) {
  10237. function addUndo() {
  10238. t.undoManager.typing = false;
  10239. t.undoManager.add();
  10240. };
  10241. dom.bind(t.getDoc(), 'focusout', function(e) {
  10242. if (!t.removed && t.undoManager.typing)
  10243. addUndo();
  10244. });
  10245. // Add undo level when contents is drag/dropped within the editor
  10246. t.dom.bind(t.dom.getRoot(), 'dragend', function(e) {
  10247. addUndo();
  10248. });
  10249. t.onKeyUp.add(function(ed, e) {
  10250. var keyCode = e.keyCode;
  10251. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 13 || keyCode == 45 || e.ctrlKey)
  10252. addUndo();
  10253. });
  10254. t.onKeyDown.add(function(ed, e) {
  10255. var keyCode = e.keyCode, sel;
  10256. if (keyCode == 8) {
  10257. sel = t.getDoc().selection;
  10258. // Fix IE control + backspace browser bug
  10259. if (sel && sel.createRange && sel.createRange().item) {
  10260. t.undoManager.beforeChange();
  10261. ed.dom.remove(sel.createRange().item(0));
  10262. addUndo();
  10263. return Event.cancel(e);
  10264. }
  10265. }
  10266. // Is caracter positon keys left,right,up,down,home,end,pgdown,pgup,enter
  10267. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 13 || keyCode == 45) {
  10268. // Add position before enter key is pressed, used by IE since it still uses the default browser behavior
  10269. // Todo: Remove this once we normalize enter behavior on IE
  10270. if (tinymce.isIE && keyCode == 13)
  10271. t.undoManager.beforeChange();
  10272. if (t.undoManager.typing)
  10273. addUndo();
  10274. return;
  10275. }
  10276. // If key isn't shift,ctrl,alt,capslock,metakey
  10277. if ((keyCode < 16 || keyCode > 20) && keyCode != 224 && keyCode != 91 && !t.undoManager.typing) {
  10278. t.undoManager.beforeChange();
  10279. t.undoManager.typing = true;
  10280. t.undoManager.add();
  10281. }
  10282. });
  10283. t.onMouseDown.add(function() {
  10284. if (t.undoManager.typing)
  10285. addUndo();
  10286. });
  10287. }
  10288. // Bug fix for FireFox keeping styles from end of selection instead of start.
  10289. if (tinymce.isGecko) {
  10290. function getAttributeApplyFunction() {
  10291. var template = t.dom.getAttribs(t.selection.getStart().cloneNode(false));
  10292. return function() {
  10293. var target = t.selection.getStart();
  10294. if (target !== t.getBody()) {
  10295. t.dom.setAttrib(target, "style", null);
  10296. each(template, function(attr) {
  10297. target.setAttributeNode(attr.cloneNode(true));
  10298. });
  10299. }
  10300. };
  10301. }
  10302. function isSelectionAcrossElements() {
  10303. var s = t.selection;
  10304. return !s.isCollapsed() && s.getStart() != s.getEnd();
  10305. }
  10306. t.onKeyPress.add(function(ed, e) {
  10307. var applyAttributes;
  10308. if ((e.keyCode == 8 || e.keyCode == 46) && isSelectionAcrossElements()) {
  10309. applyAttributes = getAttributeApplyFunction();
  10310. t.getDoc().execCommand('delete', false, null);
  10311. applyAttributes();
  10312. return Event.cancel(e);
  10313. }
  10314. });
  10315. t.dom.bind(t.getDoc(), 'cut', function(e) {
  10316. var applyAttributes;
  10317. if (isSelectionAcrossElements()) {
  10318. applyAttributes = getAttributeApplyFunction();
  10319. t.onKeyUp.addToTop(Event.cancel, Event);
  10320. setTimeout(function() {
  10321. applyAttributes();
  10322. t.onKeyUp.remove(Event.cancel, Event);
  10323. }, 0);
  10324. }
  10325. });
  10326. }
  10327. },
  10328. _refreshContentEditable : function() {
  10329. var self = this, body, parent;
  10330. // Check if the editor was hidden and the re-initalize contentEditable mode by removing and adding the body again
  10331. if (self._isHidden()) {
  10332. body = self.getBody();
  10333. parent = body.parentNode;
  10334. parent.removeChild(body);
  10335. parent.appendChild(body);
  10336. body.focus();
  10337. }
  10338. },
  10339. _isHidden : function() {
  10340. var s;
  10341. if (!isGecko)
  10342. return 0;
  10343. // Weird, wheres that cursor selection?
  10344. s = this.selection.getSel();
  10345. return (!s || !s.rangeCount || s.rangeCount == 0);
  10346. }
  10347. });
  10348. })(tinymce);
  10349. (function(tinymce) {
  10350. // Added for compression purposes
  10351. var each = tinymce.each, undefined, TRUE = true, FALSE = false;
  10352. tinymce.EditorCommands = function(editor) {
  10353. var dom = editor.dom,
  10354. selection = editor.selection,
  10355. commands = {state: {}, exec : {}, value : {}},
  10356. settings = editor.settings,
  10357. formatter = editor.formatter,
  10358. bookmark;
  10359. function execCommand(command, ui, value) {
  10360. var func;
  10361. command = command.toLowerCase();
  10362. if (func = commands.exec[command]) {
  10363. func(command, ui, value);
  10364. return TRUE;
  10365. }
  10366. return FALSE;
  10367. };
  10368. function queryCommandState(command) {
  10369. var func;
  10370. command = command.toLowerCase();
  10371. if (func = commands.state[command])
  10372. return func(command);
  10373. return -1;
  10374. };
  10375. function queryCommandValue(command) {
  10376. var func;
  10377. command = command.toLowerCase();
  10378. if (func = commands.value[command])
  10379. return func(command);
  10380. return FALSE;
  10381. };
  10382. function addCommands(command_list, type) {
  10383. type = type || 'exec';
  10384. each(command_list, function(callback, command) {
  10385. each(command.toLowerCase().split(','), function(command) {
  10386. commands[type][command] = callback;
  10387. });
  10388. });
  10389. };
  10390. // Expose public methods
  10391. tinymce.extend(this, {
  10392. execCommand : execCommand,
  10393. queryCommandState : queryCommandState,
  10394. queryCommandValue : queryCommandValue,
  10395. addCommands : addCommands
  10396. });
  10397. // Private methods
  10398. function execNativeCommand(command, ui, value) {
  10399. if (ui === undefined)
  10400. ui = FALSE;
  10401. if (value === undefined)
  10402. value = null;
  10403. return editor.getDoc().execCommand(command, ui, value);
  10404. };
  10405. function isFormatMatch(name) {
  10406. return formatter.match(name);
  10407. };
  10408. function toggleFormat(name, value) {
  10409. formatter.toggle(name, value ? {value : value} : undefined);
  10410. };
  10411. function storeSelection(type) {
  10412. bookmark = selection.getBookmark(type);
  10413. };
  10414. function restoreSelection() {
  10415. selection.moveToBookmark(bookmark);
  10416. };
  10417. // Add execCommand overrides
  10418. addCommands({
  10419. // Ignore these, added for compatibility
  10420. 'mceResetDesignMode,mceBeginUndoLevel' : function() {},
  10421. // Add undo manager logic
  10422. 'mceEndUndoLevel,mceAddUndoLevel' : function() {
  10423. editor.undoManager.add();
  10424. },
  10425. 'Cut,Copy,Paste' : function(command) {
  10426. var doc = editor.getDoc(), failed;
  10427. // Try executing the native command
  10428. try {
  10429. execNativeCommand(command);
  10430. } catch (ex) {
  10431. // Command failed
  10432. failed = TRUE;
  10433. }
  10434. // Present alert message about clipboard access not being available
  10435. if (failed || !doc.queryCommandSupported(command)) {
  10436. if (tinymce.isGecko) {
  10437. editor.windowManager.confirm(editor.getLang('clipboard_msg'), function(state) {
  10438. if (state)
  10439. open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', '_blank');
  10440. });
  10441. } else
  10442. editor.windowManager.alert(editor.getLang('clipboard_no_support'));
  10443. }
  10444. },
  10445. // Override unlink command
  10446. unlink : function(command) {
  10447. if (selection.isCollapsed())
  10448. selection.select(selection.getNode());
  10449. execNativeCommand(command);
  10450. selection.collapse(FALSE);
  10451. },
  10452. // Override justify commands to use the text formatter engine
  10453. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  10454. var align = command.substring(7);
  10455. // Remove all other alignments first
  10456. each('left,center,right,full'.split(','), function(name) {
  10457. if (align != name)
  10458. formatter.remove('align' + name);
  10459. });
  10460. toggleFormat('align' + align);
  10461. execCommand('mceRepaint');
  10462. },
  10463. // Override list commands to fix WebKit bug
  10464. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  10465. var listElm, listParent;
  10466. execNativeCommand(command);
  10467. // WebKit produces lists within block elements so we need to split them
  10468. // we will replace the native list creation logic to custom logic later on
  10469. // TODO: Remove this when the list creation logic is removed
  10470. listElm = dom.getParent(selection.getNode(), 'ol,ul');
  10471. if (listElm) {
  10472. listParent = listElm.parentNode;
  10473. // If list is within a text block then split that block
  10474. if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) {
  10475. storeSelection();
  10476. dom.split(listParent, listElm);
  10477. restoreSelection();
  10478. }
  10479. }
  10480. },
  10481. // Override commands to use the text formatter engine
  10482. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  10483. toggleFormat(command);
  10484. },
  10485. // Override commands to use the text formatter engine
  10486. 'ForeColor,HiliteColor,FontName' : function(command, ui, value) {
  10487. toggleFormat(command, value);
  10488. },
  10489. FontSize : function(command, ui, value) {
  10490. var fontClasses, fontSizes;
  10491. // Convert font size 1-7 to styles
  10492. if (value >= 1 && value <= 7) {
  10493. fontSizes = tinymce.explode(settings.font_size_style_values);
  10494. fontClasses = tinymce.explode(settings.font_size_classes);
  10495. if (fontClasses)
  10496. value = fontClasses[value - 1] || value;
  10497. else
  10498. value = fontSizes[value - 1] || value;
  10499. }
  10500. toggleFormat(command, value);
  10501. },
  10502. RemoveFormat : function(command) {
  10503. formatter.remove(command);
  10504. },
  10505. mceBlockQuote : function(command) {
  10506. toggleFormat('blockquote');
  10507. },
  10508. FormatBlock : function(command, ui, value) {
  10509. return toggleFormat(value || 'p');
  10510. },
  10511. mceCleanup : function() {
  10512. var bookmark = selection.getBookmark();
  10513. editor.setContent(editor.getContent({cleanup : TRUE}), {cleanup : TRUE});
  10514. selection.moveToBookmark(bookmark);
  10515. },
  10516. mceRemoveNode : function(command, ui, value) {
  10517. var node = value || selection.getNode();
  10518. // Make sure that the body node isn't removed
  10519. if (node != editor.getBody()) {
  10520. storeSelection();
  10521. editor.dom.remove(node, TRUE);
  10522. restoreSelection();
  10523. }
  10524. },
  10525. mceSelectNodeDepth : function(command, ui, value) {
  10526. var counter = 0;
  10527. dom.getParent(selection.getNode(), function(node) {
  10528. if (node.nodeType == 1 && counter++ == value) {
  10529. selection.select(node);
  10530. return FALSE;
  10531. }
  10532. }, editor.getBody());
  10533. },
  10534. mceSelectNode : function(command, ui, value) {
  10535. selection.select(value);
  10536. },
  10537. mceInsertContent : function(command, ui, value) {
  10538. var parser, serializer, parentNode, rootNode, fragment, args,
  10539. marker, nodeRect, viewPortRect, rng, node, node2, bookmarkHtml, viewportBodyElement;
  10540. // Setup parser and serializer
  10541. parser = editor.parser;
  10542. serializer = new tinymce.html.Serializer({}, editor.schema);
  10543. bookmarkHtml = '<span id="mce_marker" data-mce-type="bookmark">\uFEFF</span>';
  10544. // Run beforeSetContent handlers on the HTML to be inserted
  10545. args = {content: value, format: 'html'};
  10546. selection.onBeforeSetContent.dispatch(selection, args);
  10547. value = args.content;
  10548. // Add caret at end of contents if it's missing
  10549. if (value.indexOf('{$caret}') == -1)
  10550. value += '{$caret}';
  10551. // Replace the caret marker with a span bookmark element
  10552. value = value.replace(/\{\$caret\}/, bookmarkHtml);
  10553. // Insert node maker where we will insert the new HTML and get it's parent
  10554. if (!selection.isCollapsed())
  10555. editor.getDoc().execCommand('Delete', false, null);
  10556. parentNode = selection.getNode();
  10557. // Parse the fragment within the context of the parent node
  10558. args = {context : parentNode.nodeName.toLowerCase()};
  10559. fragment = parser.parse(value, args);
  10560. // Move the caret to a more suitable location
  10561. node = fragment.lastChild;
  10562. if (node.attr('id') == 'mce_marker') {
  10563. marker = node;
  10564. for (node = node.prev; node; node = node.walk(true)) {
  10565. if (node.type == 3 || !dom.isBlock(node.name)) {
  10566. node.parent.insert(marker, node, node.name === 'br');
  10567. break;
  10568. }
  10569. }
  10570. }
  10571. // If parser says valid we can insert the contents into that parent
  10572. if (!args.invalid) {
  10573. value = serializer.serialize(fragment);
  10574. // Check if parent is empty or only has one BR element then set the innerHTML of that parent
  10575. node = parentNode.firstChild;
  10576. node2 = parentNode.lastChild;
  10577. if (!node || (node === node2 && node.nodeName === 'BR'))
  10578. dom.setHTML(parentNode, value);
  10579. else
  10580. selection.setContent(value);
  10581. } else {
  10582. // If the fragment was invalid within that context then we need
  10583. // to parse and process the parent it's inserted into
  10584. // Insert bookmark node and get the parent
  10585. selection.setContent(bookmarkHtml);
  10586. parentNode = editor.selection.getNode();
  10587. rootNode = editor.getBody();
  10588. // Opera will return the document node when selection is in root
  10589. if (parentNode.nodeType == 9)
  10590. parentNode = node = rootNode;
  10591. else
  10592. node = parentNode;
  10593. // Find the ancestor just before the root element
  10594. while (node !== rootNode) {
  10595. parentNode = node;
  10596. node = node.parentNode;
  10597. }
  10598. // Get the outer/inner HTML depending on if we are in the root and parser and serialize that
  10599. value = parentNode == rootNode ? rootNode.innerHTML : dom.getOuterHTML(parentNode);
  10600. value = serializer.serialize(
  10601. parser.parse(
  10602. // Need to replace by using a function since $ in the contents would otherwise be a problem
  10603. value.replace(/<span (id="mce_marker"|id=mce_marker).+?<\/span>/i, function() {
  10604. return serializer.serialize(fragment);
  10605. })
  10606. )
  10607. );
  10608. // Set the inner/outer HTML depending on if we are in the root or not
  10609. if (parentNode == rootNode)
  10610. dom.setHTML(rootNode, value);
  10611. else
  10612. dom.setOuterHTML(parentNode, value);
  10613. }
  10614. marker = dom.get('mce_marker');
  10615. // Scroll range into view scrollIntoView on element can't be used since it will scroll the main view port as well
  10616. nodeRect = dom.getRect(marker);
  10617. viewPortRect = dom.getViewPort(editor.getWin());
  10618. // Check if node is out side the viewport if it is then scroll to it
  10619. if ((nodeRect.y + nodeRect.h > viewPortRect.y + viewPortRect.h || nodeRect.y < viewPortRect.y) ||
  10620. (nodeRect.x > viewPortRect.x + viewPortRect.w || nodeRect.x < viewPortRect.x)) {
  10621. viewportBodyElement = tinymce.isIE ? editor.getDoc().documentElement : editor.getBody();
  10622. viewportBodyElement.scrollLeft = nodeRect.x;
  10623. viewportBodyElement.scrollTop = nodeRect.y - viewPortRect.h + 25;
  10624. }
  10625. // Move selection before marker and remove it
  10626. rng = dom.createRng();
  10627. // If previous sibling is a text node set the selection to the end of that node
  10628. node = marker.previousSibling;
  10629. if (node && node.nodeType == 3) {
  10630. rng.setStart(node, node.nodeValue.length);
  10631. } else {
  10632. // If the previous sibling isn't a text node or doesn't exist set the selection before the marker node
  10633. rng.setStartBefore(marker);
  10634. rng.setEndBefore(marker);
  10635. }
  10636. // Remove the marker node and set the new range
  10637. dom.remove(marker);
  10638. selection.setRng(rng);
  10639. // Dispatch after event and add any visual elements needed
  10640. selection.onSetContent.dispatch(selection, args);
  10641. editor.addVisual();
  10642. },
  10643. mceInsertRawHTML : function(command, ui, value) {
  10644. selection.setContent('tiny_mce_marker');
  10645. editor.setContent(editor.getContent().replace(/tiny_mce_marker/g, function() { return value }));
  10646. },
  10647. mceSetContent : function(command, ui, value) {
  10648. editor.setContent(value);
  10649. },
  10650. 'Indent,Outdent' : function(command) {
  10651. var intentValue, indentUnit, value;
  10652. // Setup indent level
  10653. intentValue = settings.indentation;
  10654. indentUnit = /[a-z%]+$/i.exec(intentValue);
  10655. intentValue = parseInt(intentValue);
  10656. if (!queryCommandState('InsertUnorderedList') && !queryCommandState('InsertOrderedList')) {
  10657. each(selection.getSelectedBlocks(), function(element) {
  10658. if (command == 'outdent') {
  10659. value = Math.max(0, parseInt(element.style.paddingLeft || 0) - intentValue);
  10660. dom.setStyle(element, 'paddingLeft', value ? value + indentUnit : '');
  10661. } else
  10662. dom.setStyle(element, 'paddingLeft', (parseInt(element.style.paddingLeft || 0) + intentValue) + indentUnit);
  10663. });
  10664. } else
  10665. execNativeCommand(command);
  10666. },
  10667. mceRepaint : function() {
  10668. var bookmark;
  10669. if (tinymce.isGecko) {
  10670. try {
  10671. storeSelection(TRUE);
  10672. if (selection.getSel())
  10673. selection.getSel().selectAllChildren(editor.getBody());
  10674. selection.collapse(TRUE);
  10675. restoreSelection();
  10676. } catch (ex) {
  10677. // Ignore
  10678. }
  10679. }
  10680. },
  10681. mceToggleFormat : function(command, ui, value) {
  10682. formatter.toggle(value);
  10683. },
  10684. InsertHorizontalRule : function() {
  10685. editor.execCommand('mceInsertContent', false, '<hr />');
  10686. },
  10687. mceToggleVisualAid : function() {
  10688. editor.hasVisual = !editor.hasVisual;
  10689. editor.addVisual();
  10690. },
  10691. mceReplaceContent : function(command, ui, value) {
  10692. editor.execCommand('mceInsertContent', false, value.replace(/\{\$selection\}/g, selection.getContent({format : 'text'})));
  10693. },
  10694. mceInsertLink : function(command, ui, value) {
  10695. var anchor;
  10696. if (typeof(value) == 'string')
  10697. value = {href : value};
  10698. anchor = dom.getParent(selection.getNode(), 'a');
  10699. // Spaces are never valid in URLs and it's a very common mistake for people to make so we fix it here.
  10700. value.href = value.href.replace(' ', '%20');
  10701. // Remove existing links if there could be child links or that the href isn't specified
  10702. if (!anchor || !value.href) {
  10703. formatter.remove('link');
  10704. }
  10705. // Apply new link to selection
  10706. if (value.href) {
  10707. formatter.apply('link', value, anchor);
  10708. }
  10709. },
  10710. selectAll : function() {
  10711. var root = dom.getRoot(), rng = dom.createRng();
  10712. rng.setStart(root, 0);
  10713. rng.setEnd(root, root.childNodes.length);
  10714. editor.selection.setRng(rng);
  10715. }
  10716. });
  10717. // Add queryCommandState overrides
  10718. addCommands({
  10719. // Override justify commands
  10720. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  10721. return isFormatMatch('align' + command.substring(7));
  10722. },
  10723. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  10724. return isFormatMatch(command);
  10725. },
  10726. mceBlockQuote : function() {
  10727. return isFormatMatch('blockquote');
  10728. },
  10729. Outdent : function() {
  10730. var node;
  10731. if (settings.inline_styles) {
  10732. if ((node = dom.getParent(selection.getStart(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  10733. return TRUE;
  10734. if ((node = dom.getParent(selection.getEnd(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  10735. return TRUE;
  10736. }
  10737. return queryCommandState('InsertUnorderedList') || queryCommandState('InsertOrderedList') || (!settings.inline_styles && !!dom.getParent(selection.getNode(), 'BLOCKQUOTE'));
  10738. },
  10739. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  10740. return dom.getParent(selection.getNode(), command == 'insertunorderedlist' ? 'UL' : 'OL');
  10741. }
  10742. }, 'state');
  10743. // Add queryCommandValue overrides
  10744. addCommands({
  10745. 'FontSize,FontName' : function(command) {
  10746. var value = 0, parent;
  10747. if (parent = dom.getParent(selection.getNode(), 'span')) {
  10748. if (command == 'fontsize')
  10749. value = parent.style.fontSize;
  10750. else
  10751. value = parent.style.fontFamily.replace(/, /g, ',').replace(/[\'\"]/g, '').toLowerCase();
  10752. }
  10753. return value;
  10754. }
  10755. }, 'value');
  10756. // Add undo manager logic
  10757. if (settings.custom_undo_redo) {
  10758. addCommands({
  10759. Undo : function() {
  10760. editor.undoManager.undo();
  10761. },
  10762. Redo : function() {
  10763. editor.undoManager.redo();
  10764. }
  10765. });
  10766. }
  10767. };
  10768. })(tinymce);
  10769. (function(tinymce) {
  10770. var Dispatcher = tinymce.util.Dispatcher;
  10771. tinymce.UndoManager = function(editor) {
  10772. var self, index = 0, data = [], beforeBookmark;
  10773. function getContent() {
  10774. return tinymce.trim(editor.getContent({format : 'raw', no_events : 1}));
  10775. };
  10776. return self = {
  10777. typing : false,
  10778. onAdd : new Dispatcher(self),
  10779. onUndo : new Dispatcher(self),
  10780. onRedo : new Dispatcher(self),
  10781. beforeChange : function() {
  10782. beforeBookmark = editor.selection.getBookmark(2, true);
  10783. },
  10784. add : function(level) {
  10785. var i, settings = editor.settings, lastLevel;
  10786. level = level || {};
  10787. level.content = getContent();
  10788. // Add undo level if needed
  10789. lastLevel = data[index];
  10790. if (lastLevel && lastLevel.content == level.content)
  10791. return null;
  10792. // Set before bookmark on previous level
  10793. if (data[index])
  10794. data[index].beforeBookmark = beforeBookmark;
  10795. // Time to compress
  10796. if (settings.custom_undo_redo_levels) {
  10797. if (data.length > settings.custom_undo_redo_levels) {
  10798. for (i = 0; i < data.length - 1; i++)
  10799. data[i] = data[i + 1];
  10800. data.length--;
  10801. index = data.length;
  10802. }
  10803. }
  10804. // Get a non intrusive normalized bookmark
  10805. level.bookmark = editor.selection.getBookmark(2, true);
  10806. // Crop array if needed
  10807. if (index < data.length - 1)
  10808. data.length = index + 1;
  10809. data.push(level);
  10810. index = data.length - 1;
  10811. self.onAdd.dispatch(self, level);
  10812. editor.isNotDirty = 0;
  10813. return level;
  10814. },
  10815. undo : function() {
  10816. var level, i;
  10817. if (self.typing) {
  10818. self.add();
  10819. self.typing = false;
  10820. }
  10821. if (index > 0) {
  10822. level = data[--index];
  10823. editor.setContent(level.content, {format : 'raw'});
  10824. editor.selection.moveToBookmark(level.beforeBookmark);
  10825. self.onUndo.dispatch(self, level);
  10826. }
  10827. return level;
  10828. },
  10829. redo : function() {
  10830. var level;
  10831. if (index < data.length - 1) {
  10832. level = data[++index];
  10833. editor.setContent(level.content, {format : 'raw'});
  10834. editor.selection.moveToBookmark(level.bookmark);
  10835. self.onRedo.dispatch(self, level);
  10836. }
  10837. return level;
  10838. },
  10839. clear : function() {
  10840. data = [];
  10841. index = 0;
  10842. self.typing = false;
  10843. },
  10844. hasUndo : function() {
  10845. return index > 0 || this.typing;
  10846. },
  10847. hasRedo : function() {
  10848. return index < data.length - 1 && !this.typing;
  10849. }
  10850. };
  10851. };
  10852. })(tinymce);
  10853. (function(tinymce) {
  10854. // Shorten names
  10855. var Event = tinymce.dom.Event,
  10856. isIE = tinymce.isIE,
  10857. isGecko = tinymce.isGecko,
  10858. isOpera = tinymce.isOpera,
  10859. each = tinymce.each,
  10860. extend = tinymce.extend,
  10861. TRUE = true,
  10862. FALSE = false;
  10863. function cloneFormats(node) {
  10864. var clone, temp, inner;
  10865. do {
  10866. if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(node.nodeName)) {
  10867. if (clone) {
  10868. temp = node.cloneNode(false);
  10869. temp.appendChild(clone);
  10870. clone = temp;
  10871. } else {
  10872. clone = inner = node.cloneNode(false);
  10873. }
  10874. clone.removeAttribute('id');
  10875. }
  10876. } while (node = node.parentNode);
  10877. if (clone)
  10878. return {wrapper : clone, inner : inner};
  10879. };
  10880. // Checks if the selection/caret is at the end of the specified block element
  10881. function isAtEnd(rng, par) {
  10882. var rng2 = par.ownerDocument.createRange();
  10883. rng2.setStart(rng.endContainer, rng.endOffset);
  10884. rng2.setEndAfter(par);
  10885. // Get number of characters to the right of the cursor if it's zero then we are at the end and need to merge the next block element
  10886. return rng2.cloneContents().textContent.length == 0;
  10887. };
  10888. function splitList(selection, dom, li) {
  10889. var listBlock, block;
  10890. if (dom.isEmpty(li)) {
  10891. listBlock = dom.getParent(li, 'ul,ol');
  10892. if (!dom.getParent(listBlock.parentNode, 'ul,ol')) {
  10893. dom.split(listBlock, li);
  10894. block = dom.create('p', 0, '<br data-mce-bogus="1" />');
  10895. dom.replace(block, li);
  10896. selection.select(block, 1);
  10897. }
  10898. return FALSE;
  10899. }
  10900. return TRUE;
  10901. };
  10902. tinymce.create('tinymce.ForceBlocks', {
  10903. ForceBlocks : function(ed) {
  10904. var t = this, s = ed.settings, elm;
  10905. t.editor = ed;
  10906. t.dom = ed.dom;
  10907. elm = (s.forced_root_block || 'p').toLowerCase();
  10908. s.element = elm.toUpperCase();
  10909. ed.onPreInit.add(t.setup, t);
  10910. },
  10911. setup : function() {
  10912. var t = this, ed = t.editor, s = ed.settings, dom = ed.dom, selection = ed.selection, blockElements = ed.schema.getBlockElements();
  10913. // Force root blocks
  10914. if (s.forced_root_block) {
  10915. function addRootBlocks() {
  10916. var node = selection.getStart(), rootNode = ed.getBody(), rng, startContainer, startOffset, endContainer, endOffset, rootBlockNode, tempNode, offset = -0xFFFFFF;
  10917. if (!node || node.nodeType !== 1)
  10918. return;
  10919. // Check if node is wrapped in block
  10920. while (node != rootNode) {
  10921. if (blockElements[node.nodeName])
  10922. return;
  10923. node = node.parentNode;
  10924. }
  10925. // Get current selection
  10926. rng = selection.getRng();
  10927. if (rng.setStart) {
  10928. startContainer = rng.startContainer;
  10929. startOffset = rng.startOffset;
  10930. endContainer = rng.endContainer;
  10931. endOffset = rng.endOffset;
  10932. } else {
  10933. // Force control range into text range
  10934. if (rng.item) {
  10935. rng = ed.getDoc().body.createTextRange();
  10936. rng.moveToElementText(rng.item(0));
  10937. }
  10938. tmpRng = rng.duplicate();
  10939. tmpRng.collapse(true);
  10940. startOffset = tmpRng.move('character', offset) * -1;
  10941. if (!tmpRng.collapsed) {
  10942. tmpRng = rng.duplicate();
  10943. tmpRng.collapse(false);
  10944. endOffset = (tmpRng.move('character', offset) * -1) - startOffset;
  10945. }
  10946. }
  10947. // Wrap non block elements and text nodes
  10948. for (node = rootNode.firstChild; node; node) {
  10949. if (node.nodeType === 3 || (node.nodeType == 1 && !blockElements[node.nodeName])) {
  10950. if (!rootBlockNode) {
  10951. rootBlockNode = dom.create(s.forced_root_block);
  10952. node.parentNode.insertBefore(rootBlockNode, node);
  10953. }
  10954. tempNode = node;
  10955. node = node.nextSibling;
  10956. rootBlockNode.appendChild(tempNode);
  10957. } else {
  10958. rootBlockNode = null;
  10959. node = node.nextSibling;
  10960. }
  10961. }
  10962. if (rng.setStart) {
  10963. rng.setStart(startContainer, startOffset);
  10964. rng.setEnd(endContainer, endOffset);
  10965. selection.setRng(rng);
  10966. } else {
  10967. try {
  10968. rng = ed.getDoc().body.createTextRange();
  10969. rng.moveToElementText(rootNode);
  10970. rng.collapse(true);
  10971. rng.moveStart('character', startOffset);
  10972. if (endOffset > 0)
  10973. rng.moveEnd('character', endOffset);
  10974. rng.select();
  10975. } catch (ex) {
  10976. // Ignore
  10977. }
  10978. }
  10979. ed.nodeChanged();
  10980. };
  10981. ed.onKeyUp.add(addRootBlocks);
  10982. ed.onClick.add(addRootBlocks);
  10983. }
  10984. if (s.force_br_newlines) {
  10985. // Force IE to produce BRs on enter
  10986. if (isIE) {
  10987. ed.onKeyPress.add(function(ed, e) {
  10988. var n;
  10989. if (e.keyCode == 13 && selection.getNode().nodeName != 'LI') {
  10990. selection.setContent('<br id="__" /> ', {format : 'raw'});
  10991. n = dom.get('__');
  10992. n.removeAttribute('id');
  10993. selection.select(n);
  10994. selection.collapse();
  10995. return Event.cancel(e);
  10996. }
  10997. });
  10998. }
  10999. }
  11000. if (s.force_p_newlines) {
  11001. if (!isIE) {
  11002. ed.onKeyPress.add(function(ed, e) {
  11003. if (e.keyCode == 13 && !e.shiftKey && !t.insertPara(e))
  11004. Event.cancel(e);
  11005. });
  11006. } else {
  11007. // Ungly hack to for IE to preserve the formatting when you press
  11008. // enter at the end of a block element with formatted contents
  11009. // This logic overrides the browsers default logic with
  11010. // custom logic that enables us to control the output
  11011. tinymce.addUnload(function() {
  11012. t._previousFormats = 0; // Fix IE leak
  11013. });
  11014. ed.onKeyPress.add(function(ed, e) {
  11015. t._previousFormats = 0;
  11016. // Clone the current formats, this will later be applied to the new block contents
  11017. if (e.keyCode == 13 && !e.shiftKey && ed.selection.isCollapsed() && s.keep_styles)
  11018. t._previousFormats = cloneFormats(ed.selection.getStart());
  11019. });
  11020. ed.onKeyUp.add(function(ed, e) {
  11021. // Let IE break the element and the wrap the new caret location in the previous formats
  11022. if (e.keyCode == 13 && !e.shiftKey) {
  11023. var parent = ed.selection.getStart(), fmt = t._previousFormats;
  11024. // Parent is an empty block
  11025. if (!parent.hasChildNodes() && fmt) {
  11026. parent = dom.getParent(parent, dom.isBlock);
  11027. if (parent && parent.nodeName != 'LI') {
  11028. parent.innerHTML = '';
  11029. if (t._previousFormats) {
  11030. parent.appendChild(fmt.wrapper);
  11031. fmt.inner.innerHTML = '\uFEFF';
  11032. } else
  11033. parent.innerHTML = '\uFEFF';
  11034. selection.select(parent, 1);
  11035. selection.collapse(true);
  11036. ed.getDoc().execCommand('Delete', false, null);
  11037. t._previousFormats = 0;
  11038. }
  11039. }
  11040. }
  11041. });
  11042. }
  11043. if (isGecko) {
  11044. ed.onKeyDown.add(function(ed, e) {
  11045. if ((e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey)
  11046. t.backspaceDelete(e, e.keyCode == 8);
  11047. });
  11048. }
  11049. }
  11050. // Workaround for missing shift+enter support, http://bugs.webkit.org/show_bug.cgi?id=16973
  11051. if (tinymce.isWebKit) {
  11052. function insertBr(ed) {
  11053. var rng = selection.getRng(), br, div = dom.create('div', null, ' '), divYPos, vpHeight = dom.getViewPort(ed.getWin()).h;
  11054. // Insert BR element
  11055. rng.insertNode(br = dom.create('br'));
  11056. // Place caret after BR
  11057. rng.setStartAfter(br);
  11058. rng.setEndAfter(br);
  11059. selection.setRng(rng);
  11060. // Could not place caret after BR then insert an nbsp entity and move the caret
  11061. if (selection.getSel().focusNode == br.previousSibling) {
  11062. selection.select(dom.insertAfter(dom.doc.createTextNode('\u00a0'), br));
  11063. selection.collapse(TRUE);
  11064. }
  11065. // Create a temporary DIV after the BR and get the position as it
  11066. // seems like getPos() returns 0 for text nodes and BR elements.
  11067. dom.insertAfter(div, br);
  11068. divYPos = dom.getPos(div).y;
  11069. dom.remove(div);
  11070. // Scroll to new position, scrollIntoView can't be used due to bug: http://bugs.webkit.org/show_bug.cgi?id=16117
  11071. if (divYPos > vpHeight) // It is not necessary to scroll if the DIV is inside the view port.
  11072. ed.getWin().scrollTo(0, divYPos);
  11073. };
  11074. ed.onKeyPress.add(function(ed, e) {
  11075. if (e.keyCode == 13 && (e.shiftKey || (s.force_br_newlines && !dom.getParent(selection.getNode(), 'h1,h2,h3,h4,h5,h6,ol,ul')))) {
  11076. insertBr(ed);
  11077. Event.cancel(e);
  11078. }
  11079. });
  11080. }
  11081. // IE specific fixes
  11082. if (isIE) {
  11083. // Replaces IE:s auto generated paragraphs with the specified element name
  11084. if (s.element != 'P') {
  11085. ed.onKeyPress.add(function(ed, e) {
  11086. t.lastElm = selection.getNode().nodeName;
  11087. });
  11088. ed.onKeyUp.add(function(ed, e) {
  11089. var bl, n = selection.getNode(), b = ed.getBody();
  11090. if (b.childNodes.length === 1 && n.nodeName == 'P') {
  11091. n = dom.rename(n, s.element);
  11092. selection.select(n);
  11093. selection.collapse();
  11094. ed.nodeChanged();
  11095. } else if (e.keyCode == 13 && !e.shiftKey && t.lastElm != 'P') {
  11096. bl = dom.getParent(n, 'p');
  11097. if (bl) {
  11098. dom.rename(bl, s.element);
  11099. ed.nodeChanged();
  11100. }
  11101. }
  11102. });
  11103. }
  11104. }
  11105. },
  11106. getParentBlock : function(n) {
  11107. var d = this.dom;
  11108. return d.getParent(n, d.isBlock);
  11109. },
  11110. insertPara : function(e) {
  11111. var t = this, ed = t.editor, dom = ed.dom, d = ed.getDoc(), se = ed.settings, s = ed.selection.getSel(), r = s.getRangeAt(0), b = d.body;
  11112. var rb, ra, dir, sn, so, en, eo, sb, eb, bn, bef, aft, sc, ec, n, vp = dom.getViewPort(ed.getWin()), y, ch, car;
  11113. ed.undoManager.beforeChange();
  11114. // If root blocks are forced then use Operas default behavior since it's really good
  11115. // Removed due to bug: #1853816
  11116. // if (se.forced_root_block && isOpera)
  11117. // return TRUE;
  11118. // Setup before range
  11119. rb = d.createRange();
  11120. // If is before the first block element and in body, then move it into first block element
  11121. rb.setStart(s.anchorNode, s.anchorOffset);
  11122. rb.collapse(TRUE);
  11123. // Setup after range
  11124. ra = d.createRange();
  11125. // If is before the first block element and in body, then move it into first block element
  11126. ra.setStart(s.focusNode, s.focusOffset);
  11127. ra.collapse(TRUE);
  11128. // Setup start/end points
  11129. dir = rb.compareBoundaryPoints(rb.START_TO_END, ra) < 0;
  11130. sn = dir ? s.anchorNode : s.focusNode;
  11131. so = dir ? s.anchorOffset : s.focusOffset;
  11132. en = dir ? s.focusNode : s.anchorNode;
  11133. eo = dir ? s.focusOffset : s.anchorOffset;
  11134. // If selection is in empty table cell
  11135. if (sn === en && /^(TD|TH)$/.test(sn.nodeName)) {
  11136. if (sn.firstChild.nodeName == 'BR')
  11137. dom.remove(sn.firstChild); // Remove BR
  11138. // Create two new block elements
  11139. if (sn.childNodes.length == 0) {
  11140. ed.dom.add(sn, se.element, null, '<br />');
  11141. aft = ed.dom.add(sn, se.element, null, '<br />');
  11142. } else {
  11143. n = sn.innerHTML;
  11144. sn.innerHTML = '';
  11145. ed.dom.add(sn, se.element, null, n);
  11146. aft = ed.dom.add(sn, se.element, null, '<br />');
  11147. }
  11148. // Move caret into the last one
  11149. r = d.createRange();
  11150. r.selectNodeContents(aft);
  11151. r.collapse(1);
  11152. ed.selection.setRng(r);
  11153. return FALSE;
  11154. }
  11155. // If the caret is in an invalid location in FF we need to move it into the first block
  11156. if (sn == b && en == b && b.firstChild && ed.dom.isBlock(b.firstChild)) {
  11157. sn = en = sn.firstChild;
  11158. so = eo = 0;
  11159. rb = d.createRange();
  11160. rb.setStart(sn, 0);
  11161. ra = d.createRange();
  11162. ra.setStart(en, 0);
  11163. }
  11164. // If the body is totally empty add a BR element this might happen on webkit
  11165. if (!d.body.hasChildNodes()) {
  11166. d.body.appendChild(dom.create('br'));
  11167. }
  11168. // Never use body as start or end node
  11169. sn = sn.nodeName == "HTML" ? d.body : sn; // Fix for Opera bug: https://bugs.opera.com/show_bug.cgi?id=273224&comments=yes
  11170. sn = sn.nodeName == "BODY" ? sn.firstChild : sn;
  11171. en = en.nodeName == "HTML" ? d.body : en; // Fix for Opera bug: https://bugs.opera.com/show_bug.cgi?id=273224&comments=yes
  11172. en = en.nodeName == "BODY" ? en.firstChild : en;
  11173. // Get start and end blocks
  11174. sb = t.getParentBlock(sn);
  11175. eb = t.getParentBlock(en);
  11176. bn = sb ? sb.nodeName : se.element; // Get block name to create
  11177. // Return inside list use default browser behavior
  11178. if (n = t.dom.getParent(sb, 'li,pre')) {
  11179. if (n.nodeName == 'LI')
  11180. return splitList(ed.selection, t.dom, n);
  11181. return TRUE;
  11182. }
  11183. // If caption or absolute layers then always generate new blocks within
  11184. if (sb && (sb.nodeName == 'CAPTION' || /absolute|relative|fixed/gi.test(dom.getStyle(sb, 'position', 1)))) {
  11185. bn = se.element;
  11186. sb = null;
  11187. }
  11188. // If caption or absolute layers then always generate new blocks within
  11189. if (eb && (eb.nodeName == 'CAPTION' || /absolute|relative|fixed/gi.test(dom.getStyle(sb, 'position', 1)))) {
  11190. bn = se.element;
  11191. eb = null;
  11192. }
  11193. // Use P instead
  11194. if (/(TD|TABLE|TH|CAPTION)/.test(bn) || (sb && bn == "DIV" && /left|right/gi.test(dom.getStyle(sb, 'float', 1)))) {
  11195. bn = se.element;
  11196. sb = eb = null;
  11197. }
  11198. // Setup new before and after blocks
  11199. bef = (sb && sb.nodeName == bn) ? sb.cloneNode(0) : ed.dom.create(bn);
  11200. aft = (eb && eb.nodeName == bn) ? eb.cloneNode(0) : ed.dom.create(bn);
  11201. // Remove id from after clone
  11202. aft.removeAttribute('id');
  11203. // Is header and cursor is at the end, then force paragraph under
  11204. if (/^(H[1-6])$/.test(bn) && isAtEnd(r, sb))
  11205. aft = ed.dom.create(se.element);
  11206. // Find start chop node
  11207. n = sc = sn;
  11208. do {
  11209. if (n == b || n.nodeType == 9 || t.dom.isBlock(n) || /(TD|TABLE|TH|CAPTION)/.test(n.nodeName))
  11210. break;
  11211. sc = n;
  11212. } while ((n = n.previousSibling ? n.previousSibling : n.parentNode));
  11213. // Find end chop node
  11214. n = ec = en;
  11215. do {
  11216. if (n == b || n.nodeType == 9 || t.dom.isBlock(n) || /(TD|TABLE|TH|CAPTION)/.test(n.nodeName))
  11217. break;
  11218. ec = n;
  11219. } while ((n = n.nextSibling ? n.nextSibling : n.parentNode));
  11220. // Place first chop part into before block element
  11221. if (sc.nodeName == bn)
  11222. rb.setStart(sc, 0);
  11223. else
  11224. rb.setStartBefore(sc);
  11225. rb.setEnd(sn, so);
  11226. bef.appendChild(rb.cloneContents() || d.createTextNode('')); // Empty text node needed for Safari
  11227. // Place secnd chop part within new block element
  11228. try {
  11229. ra.setEndAfter(ec);
  11230. } catch(ex) {
  11231. //console.debug(s.focusNode, s.focusOffset);
  11232. }
  11233. ra.setStart(en, eo);
  11234. aft.appendChild(ra.cloneContents() || d.createTextNode('')); // Empty text node needed for Safari
  11235. // Create range around everything
  11236. r = d.createRange();
  11237. if (!sc.previousSibling && sc.parentNode.nodeName == bn) {
  11238. r.setStartBefore(sc.parentNode);
  11239. } else {
  11240. if (rb.startContainer.nodeName == bn && rb.startOffset == 0)
  11241. r.setStartBefore(rb.startContainer);
  11242. else
  11243. r.setStart(rb.startContainer, rb.startOffset);
  11244. }
  11245. if (!ec.nextSibling && ec.parentNode.nodeName == bn)
  11246. r.setEndAfter(ec.parentNode);
  11247. else
  11248. r.setEnd(ra.endContainer, ra.endOffset);
  11249. // Delete and replace it with new block elements
  11250. r.deleteContents();
  11251. if (isOpera)
  11252. ed.getWin().scrollTo(0, vp.y);
  11253. // Never wrap blocks in blocks
  11254. if (bef.firstChild && bef.firstChild.nodeName == bn)
  11255. bef.innerHTML = bef.firstChild.innerHTML;
  11256. if (aft.firstChild && aft.firstChild.nodeName == bn)
  11257. aft.innerHTML = aft.firstChild.innerHTML;
  11258. function appendStyles(e, en) {
  11259. var nl = [], nn, n, i;
  11260. e.innerHTML = '';
  11261. // Make clones of style elements
  11262. if (se.keep_styles) {
  11263. n = en;
  11264. do {
  11265. // We only want style specific elements
  11266. if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(n.nodeName)) {
  11267. nn = n.cloneNode(FALSE);
  11268. dom.setAttrib(nn, 'id', ''); // Remove ID since it needs to be unique
  11269. nl.push(nn);
  11270. }
  11271. } while (n = n.parentNode);
  11272. }
  11273. // Append style elements to aft
  11274. if (nl.length > 0) {
  11275. for (i = nl.length - 1, nn = e; i >= 0; i--)
  11276. nn = nn.appendChild(nl[i]);
  11277. // Padd most inner style element
  11278. nl[0].innerHTML = isOpera ? '\u00a0' : '<br />'; // Extra space for Opera so that the caret can move there
  11279. return nl[0]; // Move caret to most inner element
  11280. } else
  11281. e.innerHTML = isOpera ? '\u00a0' : '<br />'; // Extra space for Opera so that the caret can move there
  11282. };
  11283. // Padd empty blocks
  11284. if (dom.isEmpty(bef))
  11285. appendStyles(bef, sn);
  11286. // Fill empty afterblook with current style
  11287. if (dom.isEmpty(aft))
  11288. car = appendStyles(aft, en);
  11289. // Opera needs this one backwards for older versions
  11290. if (isOpera && parseFloat(opera.version()) < 9.5) {
  11291. r.insertNode(bef);
  11292. r.insertNode(aft);
  11293. } else {
  11294. r.insertNode(aft);
  11295. r.insertNode(bef);
  11296. }
  11297. // Normalize
  11298. aft.normalize();
  11299. bef.normalize();
  11300. // Move cursor and scroll into view
  11301. ed.selection.select(aft, true);
  11302. ed.selection.collapse(true);
  11303. // scrollIntoView seems to scroll the parent window in most browsers now including FF 3.0b4 so it's time to stop using it and do it our selfs
  11304. y = ed.dom.getPos(aft).y;
  11305. //ch = aft.clientHeight;
  11306. // Is element within viewport
  11307. if (y < vp.y || y + 25 > vp.y + vp.h) {
  11308. ed.getWin().scrollTo(0, y < vp.y ? y : y - vp.h + 25); // Needs to be hardcoded to roughly one line of text if a huge text block is broken into two blocks
  11309. /*console.debug(
  11310. 'Element: y=' + y + ', h=' + ch + ', ' +
  11311. 'Viewport: y=' + vp.y + ", h=" + vp.h + ', bottom=' + (vp.y + vp.h)
  11312. );*/
  11313. }
  11314. ed.undoManager.add();
  11315. return FALSE;
  11316. },
  11317. backspaceDelete : function(e, bs) {
  11318. var t = this, ed = t.editor, b = ed.getBody(), dom = ed.dom, n, se = ed.selection, r = se.getRng(), sc = r.startContainer, n, w, tn, walker;
  11319. // Delete when caret is behind a element doesn't work correctly on Gecko see #3011651
  11320. if (!bs && r.collapsed && sc.nodeType == 1 && r.startOffset == sc.childNodes.length) {
  11321. walker = new tinymce.dom.TreeWalker(sc.lastChild, sc);
  11322. // Walk the dom backwards until we find a text node
  11323. for (n = sc.lastChild; n; n = walker.prev()) {
  11324. if (n.nodeType == 3) {
  11325. r.setStart(n, n.nodeValue.length);
  11326. r.collapse(true);
  11327. se.setRng(r);
  11328. return;
  11329. }
  11330. }
  11331. }
  11332. // The caret sometimes gets stuck in Gecko if you delete empty paragraphs
  11333. // This workaround removes the element by hand and moves the caret to the previous element
  11334. if (sc && ed.dom.isBlock(sc) && !/^(TD|TH)$/.test(sc.nodeName) && bs) {
  11335. if (sc.childNodes.length == 0 || (sc.childNodes.length == 1 && sc.firstChild.nodeName == 'BR')) {
  11336. // Find previous block element
  11337. n = sc;
  11338. while ((n = n.previousSibling) && !ed.dom.isBlock(n)) ;
  11339. if (n) {
  11340. if (sc != b.firstChild) {
  11341. // Find last text node
  11342. w = ed.dom.doc.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, FALSE);
  11343. while (tn = w.nextNode())
  11344. n = tn;
  11345. // Place caret at the end of last text node
  11346. r = ed.getDoc().createRange();
  11347. r.setStart(n, n.nodeValue ? n.nodeValue.length : 0);
  11348. r.setEnd(n, n.nodeValue ? n.nodeValue.length : 0);
  11349. se.setRng(r);
  11350. // Remove the target container
  11351. ed.dom.remove(sc);
  11352. }
  11353. return Event.cancel(e);
  11354. }
  11355. }
  11356. }
  11357. }
  11358. });
  11359. })(tinymce);
  11360. (function(tinymce) {
  11361. // Shorten names
  11362. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, extend = tinymce.extend;
  11363. tinymce.create('tinymce.ControlManager', {
  11364. ControlManager : function(ed, s) {
  11365. var t = this, i;
  11366. s = s || {};
  11367. t.editor = ed;
  11368. t.controls = {};
  11369. t.onAdd = new tinymce.util.Dispatcher(t);
  11370. t.onPostRender = new tinymce.util.Dispatcher(t);
  11371. t.prefix = s.prefix || ed.id + '_';
  11372. t._cls = {};
  11373. t.onPostRender.add(function() {
  11374. each(t.controls, function(c) {
  11375. c.postRender();
  11376. });
  11377. });
  11378. },
  11379. get : function(id) {
  11380. return this.controls[this.prefix + id] || this.controls[id];
  11381. },
  11382. setActive : function(id, s) {
  11383. var c = null;
  11384. if (c = this.get(id))
  11385. c.setActive(s);
  11386. return c;
  11387. },
  11388. setDisabled : function(id, s) {
  11389. var c = null;
  11390. if (c = this.get(id))
  11391. c.setDisabled(s);
  11392. return c;
  11393. },
  11394. add : function(c) {
  11395. var t = this;
  11396. if (c) {
  11397. t.controls[c.id] = c;
  11398. t.onAdd.dispatch(c, t);
  11399. }
  11400. return c;
  11401. },
  11402. createControl : function(n) {
  11403. var c, t = this, ed = t.editor;
  11404. each(ed.plugins, function(p) {
  11405. if (p.createControl) {
  11406. c = p.createControl(n, t);
  11407. if (c)
  11408. return false;
  11409. }
  11410. });
  11411. switch (n) {
  11412. case "|":
  11413. case "separator":
  11414. return t.createSeparator();
  11415. }
  11416. if (!c && ed.buttons && (c = ed.buttons[n]))
  11417. return t.createButton(n, c);
  11418. return t.add(c);
  11419. },
  11420. createDropMenu : function(id, s, cc) {
  11421. var t = this, ed = t.editor, c, bm, v, cls;
  11422. s = extend({
  11423. 'class' : 'mceDropDown',
  11424. constrain : ed.settings.constrain_menus
  11425. }, s);
  11426. s['class'] = s['class'] + ' ' + ed.getParam('skin') + 'Skin';
  11427. if (v = ed.getParam('skin_variant'))
  11428. s['class'] += ' ' + ed.getParam('skin') + 'Skin' + v.substring(0, 1).toUpperCase() + v.substring(1);
  11429. id = t.prefix + id;
  11430. cls = cc || t._cls.dropmenu || tinymce.ui.DropMenu;
  11431. c = t.controls[id] = new cls(id, s);
  11432. c.onAddItem.add(function(c, o) {
  11433. var s = o.settings;
  11434. s.title = ed.getLang(s.title, s.title);
  11435. if (!s.onclick) {
  11436. s.onclick = function(v) {
  11437. if (s.cmd)
  11438. ed.execCommand(s.cmd, s.ui || false, s.value);
  11439. };
  11440. }
  11441. });
  11442. ed.onRemove.add(function() {
  11443. c.destroy();
  11444. });
  11445. // Fix for bug #1897785, #1898007
  11446. if (tinymce.isIE) {
  11447. c.onShowMenu.add(function() {
  11448. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  11449. ed.focus();
  11450. bm = ed.selection.getBookmark(1);
  11451. });
  11452. c.onHideMenu.add(function() {
  11453. if (bm) {
  11454. ed.selection.moveToBookmark(bm);
  11455. bm = 0;
  11456. }
  11457. });
  11458. }
  11459. return t.add(c);
  11460. },
  11461. createListBox : function(id, s, cc) {
  11462. var t = this, ed = t.editor, cmd, c, cls;
  11463. if (t.get(id))
  11464. return null;
  11465. s.title = ed.translate(s.title);
  11466. s.scope = s.scope || ed;
  11467. if (!s.onselect) {
  11468. s.onselect = function(v) {
  11469. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11470. };
  11471. }
  11472. s = extend({
  11473. title : s.title,
  11474. 'class' : 'mce_' + id,
  11475. scope : s.scope,
  11476. control_manager : t
  11477. }, s);
  11478. id = t.prefix + id;
  11479. function useNativeListForAccessibility(ed) {
  11480. return ed.settings.use_accessible_selects && !tinymce.isGecko
  11481. }
  11482. if (ed.settings.use_native_selects || useNativeListForAccessibility(ed))
  11483. c = new tinymce.ui.NativeListBox(id, s);
  11484. else {
  11485. cls = cc || t._cls.listbox || tinymce.ui.ListBox;
  11486. c = new cls(id, s, ed);
  11487. }
  11488. t.controls[id] = c;
  11489. // Fix focus problem in Safari
  11490. if (tinymce.isWebKit) {
  11491. c.onPostRender.add(function(c, n) {
  11492. // Store bookmark on mousedown
  11493. Event.add(n, 'mousedown', function() {
  11494. ed.bookmark = ed.selection.getBookmark(1);
  11495. });
  11496. // Restore on focus, since it might be lost
  11497. Event.add(n, 'focus', function() {
  11498. ed.selection.moveToBookmark(ed.bookmark);
  11499. ed.bookmark = null;
  11500. });
  11501. });
  11502. }
  11503. if (c.hideMenu)
  11504. ed.onMouseDown.add(c.hideMenu, c);
  11505. return t.add(c);
  11506. },
  11507. createButton : function(id, s, cc) {
  11508. var t = this, ed = t.editor, o, c, cls;
  11509. if (t.get(id))
  11510. return null;
  11511. s.title = ed.translate(s.title);
  11512. s.label = ed.translate(s.label);
  11513. s.scope = s.scope || ed;
  11514. if (!s.onclick && !s.menu_button) {
  11515. s.onclick = function() {
  11516. ed.execCommand(s.cmd, s.ui || false, s.value);
  11517. };
  11518. }
  11519. s = extend({
  11520. title : s.title,
  11521. 'class' : 'mce_' + id,
  11522. unavailable_prefix : ed.getLang('unavailable', ''),
  11523. scope : s.scope,
  11524. control_manager : t
  11525. }, s);
  11526. id = t.prefix + id;
  11527. if (s.menu_button) {
  11528. cls = cc || t._cls.menubutton || tinymce.ui.MenuButton;
  11529. c = new cls(id, s, ed);
  11530. ed.onMouseDown.add(c.hideMenu, c);
  11531. } else {
  11532. cls = t._cls.button || tinymce.ui.Button;
  11533. c = new cls(id, s, ed);
  11534. }
  11535. return t.add(c);
  11536. },
  11537. createMenuButton : function(id, s, cc) {
  11538. s = s || {};
  11539. s.menu_button = 1;
  11540. return this.createButton(id, s, cc);
  11541. },
  11542. createSplitButton : function(id, s, cc) {
  11543. var t = this, ed = t.editor, cmd, c, cls;
  11544. if (t.get(id))
  11545. return null;
  11546. s.title = ed.translate(s.title);
  11547. s.scope = s.scope || ed;
  11548. if (!s.onclick) {
  11549. s.onclick = function(v) {
  11550. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11551. };
  11552. }
  11553. if (!s.onselect) {
  11554. s.onselect = function(v) {
  11555. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11556. };
  11557. }
  11558. s = extend({
  11559. title : s.title,
  11560. 'class' : 'mce_' + id,
  11561. scope : s.scope,
  11562. control_manager : t
  11563. }, s);
  11564. id = t.prefix + id;
  11565. cls = cc || t._cls.splitbutton || tinymce.ui.SplitButton;
  11566. c = t.add(new cls(id, s, ed));
  11567. ed.onMouseDown.add(c.hideMenu, c);
  11568. return c;
  11569. },
  11570. createColorSplitButton : function(id, s, cc) {
  11571. var t = this, ed = t.editor, cmd, c, cls, bm;
  11572. if (t.get(id))
  11573. return null;
  11574. s.title = ed.translate(s.title);
  11575. s.scope = s.scope || ed;
  11576. if (!s.onclick) {
  11577. s.onclick = function(v) {
  11578. if (tinymce.isIE)
  11579. bm = ed.selection.getBookmark(1);
  11580. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11581. };
  11582. }
  11583. if (!s.onselect) {
  11584. s.onselect = function(v) {
  11585. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11586. };
  11587. }
  11588. s = extend({
  11589. title : s.title,
  11590. 'class' : 'mce_' + id,
  11591. 'menu_class' : ed.getParam('skin') + 'Skin',
  11592. scope : s.scope,
  11593. more_colors_title : ed.getLang('more_colors')
  11594. }, s);
  11595. id = t.prefix + id;
  11596. cls = cc || t._cls.colorsplitbutton || tinymce.ui.ColorSplitButton;
  11597. c = new cls(id, s, ed);
  11598. ed.onMouseDown.add(c.hideMenu, c);
  11599. // Remove the menu element when the editor is removed
  11600. ed.onRemove.add(function() {
  11601. c.destroy();
  11602. });
  11603. // Fix for bug #1897785, #1898007
  11604. if (tinymce.isIE) {
  11605. c.onShowMenu.add(function() {
  11606. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  11607. ed.focus();
  11608. bm = ed.selection.getBookmark(1);
  11609. });
  11610. c.onHideMenu.add(function() {
  11611. if (bm) {
  11612. ed.selection.moveToBookmark(bm);
  11613. bm = 0;
  11614. }
  11615. });
  11616. }
  11617. return t.add(c);
  11618. },
  11619. createToolbar : function(id, s, cc) {
  11620. var c, t = this, cls;
  11621. id = t.prefix + id;
  11622. cls = cc || t._cls.toolbar || tinymce.ui.Toolbar;
  11623. c = new cls(id, s, t.editor);
  11624. if (t.get(id))
  11625. return null;
  11626. return t.add(c);
  11627. },
  11628. createToolbarGroup : function(id, s, cc) {
  11629. var c, t = this, cls;
  11630. id = t.prefix + id;
  11631. cls = cc || this._cls.toolbarGroup || tinymce.ui.ToolbarGroup;
  11632. c = new cls(id, s, t.editor);
  11633. if (t.get(id))
  11634. return null;
  11635. return t.add(c);
  11636. },
  11637. createSeparator : function(cc) {
  11638. var cls = cc || this._cls.separator || tinymce.ui.Separator;
  11639. return new cls();
  11640. },
  11641. setControlType : function(n, c) {
  11642. return this._cls[n.toLowerCase()] = c;
  11643. },
  11644. destroy : function() {
  11645. each(this.controls, function(c) {
  11646. c.destroy();
  11647. });
  11648. this.controls = null;
  11649. }
  11650. });
  11651. })(tinymce);
  11652. (function(tinymce) {
  11653. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isIE = tinymce.isIE, isOpera = tinymce.isOpera;
  11654. tinymce.create('tinymce.WindowManager', {
  11655. WindowManager : function(ed) {
  11656. var t = this;
  11657. t.editor = ed;
  11658. t.onOpen = new Dispatcher(t);
  11659. t.onClose = new Dispatcher(t);
  11660. t.params = {};
  11661. t.features = {};
  11662. },
  11663. open : function(s, p) {
  11664. var t = this, f = '', x, y, mo = t.editor.settings.dialog_type == 'modal', w, sw, sh, vp = tinymce.DOM.getViewPort(), u;
  11665. // Default some options
  11666. s = s || {};
  11667. p = p || {};
  11668. sw = isOpera ? vp.w : screen.width; // Opera uses windows inside the Opera window
  11669. sh = isOpera ? vp.h : screen.height;
  11670. s.name = s.name || 'mc_' + new Date().getTime();
  11671. s.width = parseInt(s.width || 320);
  11672. s.height = parseInt(s.height || 240);
  11673. s.resizable = true;
  11674. s.left = s.left || parseInt(sw / 2.0) - (s.width / 2.0);
  11675. s.top = s.top || parseInt(sh / 2.0) - (s.height / 2.0);
  11676. p.inline = false;
  11677. p.mce_width = s.width;
  11678. p.mce_height = s.height;
  11679. p.mce_auto_focus = s.auto_focus;
  11680. if (mo) {
  11681. if (isIE) {
  11682. s.center = true;
  11683. s.help = false;
  11684. s.dialogWidth = s.width + 'px';
  11685. s.dialogHeight = s.height + 'px';
  11686. s.scroll = s.scrollbars || false;
  11687. }
  11688. }
  11689. // Build features string
  11690. each(s, function(v, k) {
  11691. if (tinymce.is(v, 'boolean'))
  11692. v = v ? 'yes' : 'no';
  11693. if (!/^(name|url)$/.test(k)) {
  11694. if (isIE && mo)
  11695. f += (f ? ';' : '') + k + ':' + v;
  11696. else
  11697. f += (f ? ',' : '') + k + '=' + v;
  11698. }
  11699. });
  11700. t.features = s;
  11701. t.params = p;
  11702. t.onOpen.dispatch(t, s, p);
  11703. u = s.url || s.file;
  11704. u = tinymce._addVer(u);
  11705. try {
  11706. if (isIE && mo) {
  11707. w = 1;
  11708. window.showModalDialog(u, window, f);
  11709. } else
  11710. w = window.open(u, s.name, f);
  11711. } catch (ex) {
  11712. // Ignore
  11713. }
  11714. if (!w)
  11715. alert(t.editor.getLang('popup_blocked'));
  11716. },
  11717. close : function(w) {
  11718. w.close();
  11719. this.onClose.dispatch(this);
  11720. },
  11721. createInstance : function(cl, a, b, c, d, e) {
  11722. var f = tinymce.resolve(cl);
  11723. return new f(a, b, c, d, e);
  11724. },
  11725. confirm : function(t, cb, s, w) {
  11726. w = w || window;
  11727. cb.call(s || this, w.confirm(this._decode(this.editor.getLang(t, t))));
  11728. },
  11729. alert : function(tx, cb, s, w) {
  11730. var t = this;
  11731. w = w || window;
  11732. w.alert(t._decode(t.editor.getLang(tx, tx)));
  11733. if (cb)
  11734. cb.call(s || t);
  11735. },
  11736. resizeBy : function(dw, dh, win) {
  11737. win.resizeBy(dw, dh);
  11738. },
  11739. // Internal functions
  11740. _decode : function(s) {
  11741. return tinymce.DOM.decode(s).replace(/\\n/g, '\n');
  11742. }
  11743. });
  11744. }(tinymce));
  11745. (function(tinymce) {
  11746. tinymce.Formatter = function(ed) {
  11747. var formats = {},
  11748. each = tinymce.each,
  11749. dom = ed.dom,
  11750. selection = ed.selection,
  11751. TreeWalker = tinymce.dom.TreeWalker,
  11752. rangeUtils = new tinymce.dom.RangeUtils(dom),
  11753. isValid = ed.schema.isValidChild,
  11754. isBlock = dom.isBlock,
  11755. forcedRootBlock = ed.settings.forced_root_block,
  11756. nodeIndex = dom.nodeIndex,
  11757. INVISIBLE_CHAR = '\uFEFF',
  11758. MCE_ATTR_RE = /^(src|href|style)$/,
  11759. FALSE = false,
  11760. TRUE = true,
  11761. undefined;
  11762. function isArray(obj) {
  11763. return obj instanceof Array;
  11764. };
  11765. function getParents(node, selector) {
  11766. return dom.getParents(node, selector, dom.getRoot());
  11767. };
  11768. function isCaretNode(node) {
  11769. return node.nodeType === 1 && (node.face === 'mceinline' || node.style.fontFamily === 'mceinline');
  11770. };
  11771. // Public functions
  11772. function get(name) {
  11773. return name ? formats[name] : formats;
  11774. };
  11775. function register(name, format) {
  11776. if (name) {
  11777. if (typeof(name) !== 'string') {
  11778. each(name, function(format, name) {
  11779. register(name, format);
  11780. });
  11781. } else {
  11782. // Force format into array and add it to internal collection
  11783. format = format.length ? format : [format];
  11784. each(format, function(format) {
  11785. // Set deep to false by default on selector formats this to avoid removing
  11786. // alignment on images inside paragraphs when alignment is changed on paragraphs
  11787. if (format.deep === undefined)
  11788. format.deep = !format.selector;
  11789. // Default to true
  11790. if (format.split === undefined)
  11791. format.split = !format.selector || format.inline;
  11792. // Default to true
  11793. if (format.remove === undefined && format.selector && !format.inline)
  11794. format.remove = 'none';
  11795. // Mark format as a mixed format inline + block level
  11796. if (format.selector && format.inline) {
  11797. format.mixed = true;
  11798. format.block_expand = true;
  11799. }
  11800. // Split classes if needed
  11801. if (typeof(format.classes) === 'string')
  11802. format.classes = format.classes.split(/\s+/);
  11803. });
  11804. formats[name] = format;
  11805. }
  11806. }
  11807. };
  11808. var getTextDecoration = function(node) {
  11809. var decoration;
  11810. ed.dom.getParent(node, function(n) {
  11811. decoration = ed.dom.getStyle(n, 'text-decoration');
  11812. return decoration && decoration !== 'none';
  11813. });
  11814. return decoration;
  11815. };
  11816. var processUnderlineAndColor = function(node) {
  11817. var textDecoration;
  11818. if (node.nodeType === 1 && node.parentNode && node.parentNode.nodeType === 1) {
  11819. textDecoration = getTextDecoration(node.parentNode);
  11820. if (ed.dom.getStyle(node, 'color') && textDecoration) {
  11821. ed.dom.setStyle(node, 'text-decoration', textDecoration);
  11822. } else if (ed.dom.getStyle(node, 'textdecoration') === textDecoration) {
  11823. ed.dom.setStyle(node, 'text-decoration', null);
  11824. }
  11825. }
  11826. };
  11827. function apply(name, vars, node) {
  11828. var formatList = get(name), format = formatList[0], bookmark, rng, i, isCollapsed = selection.isCollapsed();
  11829. function moveStart(rng) {
  11830. var container = rng.startContainer,
  11831. offset = rng.startOffset,
  11832. walker, node;
  11833. // Move startContainer/startOffset in to a suitable node
  11834. if (container.nodeType == 1 || container.nodeValue === "") {
  11835. container = container.nodeType == 1 ? container.childNodes[offset] : container;
  11836. // Might fail if the offset is behind the last element in it's container
  11837. if (container) {
  11838. walker = new TreeWalker(container, container.parentNode);
  11839. for (node = walker.current(); node; node = walker.next()) {
  11840. if (node.nodeType == 3 && !isWhiteSpaceNode(node)) {
  11841. rng.setStart(node, 0);
  11842. break;
  11843. }
  11844. }
  11845. }
  11846. }
  11847. return rng;
  11848. };
  11849. function setElementFormat(elm, fmt) {
  11850. fmt = fmt || format;
  11851. if (elm) {
  11852. if (fmt.onformat) {
  11853. fmt.onformat(elm, fmt, vars, node);
  11854. }
  11855. each(fmt.styles, function(value, name) {
  11856. dom.setStyle(elm, name, replaceVars(value, vars));
  11857. });
  11858. each(fmt.attributes, function(value, name) {
  11859. dom.setAttrib(elm, name, replaceVars(value, vars));
  11860. });
  11861. each(fmt.classes, function(value) {
  11862. value = replaceVars(value, vars);
  11863. if (!dom.hasClass(elm, value))
  11864. dom.addClass(elm, value);
  11865. });
  11866. }
  11867. };
  11868. function adjustSelectionToVisibleSelection() {
  11869. function findSelectionEnd(start, end) {
  11870. var walker = new TreeWalker(end);
  11871. for (node = walker.current(); node; node = walker.prev()) {
  11872. if (node.childNodes.length > 1 || node == start) {
  11873. return node;
  11874. }
  11875. }
  11876. };
  11877. // Adjust selection so that a end container with a end offset of zero is not included in the selection
  11878. // as this isn't visible to the user.
  11879. var rng = ed.selection.getRng();
  11880. var start = rng.startContainer;
  11881. var end = rng.endContainer;
  11882. if (start != end && rng.endOffset == 0) {
  11883. var newEnd = findSelectionEnd(start, end);
  11884. var endOffset = newEnd.nodeType == 3 ? newEnd.length : newEnd.childNodes.length;
  11885. rng.setEnd(newEnd, endOffset);
  11886. }
  11887. return rng;
  11888. }
  11889. function applyStyleToList(node, bookmark, wrapElm, newWrappers, process){
  11890. var nodes = [], listIndex = -1, list, startIndex = -1, endIndex = -1, currentWrapElm;
  11891. // find the index of the first child list.
  11892. each(node.childNodes, function(n, index) {
  11893. if (n.nodeName === "UL" || n.nodeName === "OL") {
  11894. listIndex = index;
  11895. list = n;
  11896. return false;
  11897. }
  11898. });
  11899. // get the index of the bookmarks
  11900. each(node.childNodes, function(n, index) {
  11901. if (n.nodeName === "SPAN" && dom.getAttrib(n, "data-mce-type") == "bookmark") {
  11902. if (n.id == bookmark.id + "_start") {
  11903. startIndex = index;
  11904. } else if (n.id == bookmark.id + "_end") {
  11905. endIndex = index;
  11906. }
  11907. }
  11908. });
  11909. // if the selection spans across an embedded list, or there isn't an embedded list - handle processing normally
  11910. if (listIndex <= 0 || (startIndex < listIndex && endIndex > listIndex)) {
  11911. each(tinymce.grep(node.childNodes), process);
  11912. return 0;
  11913. } else {
  11914. currentWrapElm = wrapElm.cloneNode(FALSE);
  11915. // create a list of the nodes on the same side of the list as the selection
  11916. each(tinymce.grep(node.childNodes), function(n, index) {
  11917. if ((startIndex < listIndex && index < listIndex) || (startIndex > listIndex && index > listIndex)) {
  11918. nodes.push(n);
  11919. n.parentNode.removeChild(n);
  11920. }
  11921. });
  11922. // insert the wrapping element either before or after the list.
  11923. if (startIndex < listIndex) {
  11924. node.insertBefore(currentWrapElm, list);
  11925. } else if (startIndex > listIndex) {
  11926. node.insertBefore(currentWrapElm, list.nextSibling);
  11927. }
  11928. // add the new nodes to the list.
  11929. newWrappers.push(currentWrapElm);
  11930. each(nodes, function(node) {
  11931. currentWrapElm.appendChild(node);
  11932. });
  11933. return currentWrapElm;
  11934. }
  11935. };
  11936. function applyRngStyle(rng, bookmark, node_specific) {
  11937. var newWrappers = [], wrapName, wrapElm;
  11938. // Setup wrapper element
  11939. wrapName = format.inline || format.block;
  11940. wrapElm = dom.create(wrapName);
  11941. setElementFormat(wrapElm);
  11942. rangeUtils.walk(rng, function(nodes) {
  11943. var currentWrapElm;
  11944. function process(node) {
  11945. var nodeName = node.nodeName.toLowerCase(), parentName = node.parentNode.nodeName.toLowerCase(), found;
  11946. // Stop wrapping on br elements
  11947. if (isEq(nodeName, 'br')) {
  11948. currentWrapElm = 0;
  11949. // Remove any br elements when we wrap things
  11950. if (format.block)
  11951. dom.remove(node);
  11952. return;
  11953. }
  11954. // If node is wrapper type
  11955. if (format.wrapper && matchNode(node, name, vars)) {
  11956. currentWrapElm = 0;
  11957. return;
  11958. }
  11959. // Can we rename the block
  11960. if (format.block && !format.wrapper && isTextBlock(nodeName)) {
  11961. node = dom.rename(node, wrapName);
  11962. setElementFormat(node);
  11963. newWrappers.push(node);
  11964. currentWrapElm = 0;
  11965. return;
  11966. }
  11967. // Handle selector patterns
  11968. if (format.selector) {
  11969. // Look for matching formats
  11970. each(formatList, function(format) {
  11971. // Check collapsed state if it exists
  11972. if ('collapsed' in format && format.collapsed !== isCollapsed) {
  11973. return;
  11974. }
  11975. if (dom.is(node, format.selector) && !isCaretNode(node)) {
  11976. setElementFormat(node, format);
  11977. found = true;
  11978. }
  11979. });
  11980. // Continue processing if a selector match wasn't found and a inline element is defined
  11981. if (!format.inline || found) {
  11982. currentWrapElm = 0;
  11983. return;
  11984. }
  11985. }
  11986. // Is it valid to wrap this item
  11987. if (isValid(wrapName, nodeName) && isValid(parentName, wrapName) &&
  11988. !(!node_specific && node.nodeType === 3 && node.nodeValue.length === 1 && node.nodeValue.charCodeAt(0) === 65279) && node.id !== '_mce_caret') {
  11989. // Start wrapping
  11990. if (!currentWrapElm) {
  11991. // Wrap the node
  11992. currentWrapElm = wrapElm.cloneNode(FALSE);
  11993. node.parentNode.insertBefore(currentWrapElm, node);
  11994. newWrappers.push(currentWrapElm);
  11995. }
  11996. currentWrapElm.appendChild(node);
  11997. } else if (nodeName == 'li' && bookmark) {
  11998. // Start wrapping - if we are in a list node and have a bookmark, then we will always begin by wrapping in a new element.
  11999. currentWrapElm = applyStyleToList(node, bookmark, wrapElm, newWrappers, process);
  12000. } else {
  12001. // Start a new wrapper for possible children
  12002. currentWrapElm = 0;
  12003. each(tinymce.grep(node.childNodes), process);
  12004. // End the last wrapper
  12005. currentWrapElm = 0;
  12006. }
  12007. };
  12008. // Process siblings from range
  12009. each(nodes, process);
  12010. });
  12011. // Wrap links inside as well, for example color inside a link when the wrapper is around the link
  12012. if (format.wrap_links === false) {
  12013. each(newWrappers, function(node) {
  12014. function process(node) {
  12015. var i, currentWrapElm, children;
  12016. if (node.nodeName === 'A') {
  12017. currentWrapElm = wrapElm.cloneNode(FALSE);
  12018. newWrappers.push(currentWrapElm);
  12019. children = tinymce.grep(node.childNodes);
  12020. for (i = 0; i < children.length; i++)
  12021. currentWrapElm.appendChild(children[i]);
  12022. node.appendChild(currentWrapElm);
  12023. }
  12024. each(tinymce.grep(node.childNodes), process);
  12025. };
  12026. process(node);
  12027. });
  12028. }
  12029. // Cleanup
  12030. each(newWrappers, function(node) {
  12031. var childCount;
  12032. function getChildCount(node) {
  12033. var count = 0;
  12034. each(node.childNodes, function(node) {
  12035. if (!isWhiteSpaceNode(node) && !isBookmarkNode(node))
  12036. count++;
  12037. });
  12038. return count;
  12039. };
  12040. function mergeStyles(node) {
  12041. var child, clone;
  12042. each(node.childNodes, function(node) {
  12043. if (node.nodeType == 1 && !isBookmarkNode(node) && !isCaretNode(node)) {
  12044. child = node;
  12045. return FALSE; // break loop
  12046. }
  12047. });
  12048. // If child was found and of the same type as the current node
  12049. if (child && matchName(child, format)) {
  12050. clone = child.cloneNode(FALSE);
  12051. setElementFormat(clone);
  12052. dom.replace(clone, node, TRUE);
  12053. dom.remove(child, 1);
  12054. }
  12055. return clone || node;
  12056. };
  12057. childCount = getChildCount(node);
  12058. // Remove empty nodes but only if there is multiple wrappers and they are not block
  12059. // elements so never remove single <h1></h1> since that would remove the currrent empty block element where the caret is at
  12060. if ((newWrappers.length > 1 || !isBlock(node)) && childCount === 0) {
  12061. dom.remove(node, 1);
  12062. return;
  12063. }
  12064. if (format.inline || format.wrapper) {
  12065. // Merges the current node with it's children of similar type to reduce the number of elements
  12066. if (!format.exact && childCount === 1)
  12067. node = mergeStyles(node);
  12068. // Remove/merge children
  12069. each(formatList, function(format) {
  12070. // Merge all children of similar type will move styles from child to parent
  12071. // this: <span style="color:red"><b><span style="color:red; font-size:10px">text</span></b></span>
  12072. // will become: <span style="color:red"><b><span style="font-size:10px">text</span></b></span>
  12073. each(dom.select(format.inline, node), function(child) {
  12074. var parent;
  12075. // When wrap_links is set to false we don't want
  12076. // to remove the format on children within links
  12077. if (format.wrap_links === false) {
  12078. parent = child.parentNode;
  12079. do {
  12080. if (parent.nodeName === 'A')
  12081. return;
  12082. } while (parent = parent.parentNode);
  12083. }
  12084. removeFormat(format, vars, child, format.exact ? child : null);
  12085. });
  12086. });
  12087. // Remove child if direct parent is of same type
  12088. if (matchNode(node.parentNode, name, vars)) {
  12089. dom.remove(node, 1);
  12090. node = 0;
  12091. return TRUE;
  12092. }
  12093. // Look for parent with similar style format
  12094. if (format.merge_with_parents) {
  12095. dom.getParent(node.parentNode, function(parent) {
  12096. if (matchNode(parent, name, vars)) {
  12097. dom.remove(node, 1);
  12098. node = 0;
  12099. return TRUE;
  12100. }
  12101. });
  12102. }
  12103. // Merge next and previous siblings if they are similar <b>text</b><b>text</b> becomes <b>texttext</b>
  12104. if (node && format.merge_siblings !== false) {
  12105. node = mergeSiblings(getNonWhiteSpaceSibling(node), node);
  12106. node = mergeSiblings(node, getNonWhiteSpaceSibling(node, TRUE));
  12107. }
  12108. }
  12109. });
  12110. };
  12111. if (format) {
  12112. if (node) {
  12113. if (node.nodeType) {
  12114. rng = dom.createRng();
  12115. rng.setStartBefore(node);
  12116. rng.setEndAfter(node);
  12117. applyRngStyle(expandRng(rng, formatList), null, true);
  12118. } else {
  12119. applyRngStyle(node, null, true);
  12120. }
  12121. } else {
  12122. if (!isCollapsed || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  12123. // Obtain selection node before selection is unselected by applyRngStyle()
  12124. var curSelNode = ed.selection.getNode();
  12125. // Apply formatting to selection
  12126. ed.selection.setRng(adjustSelectionToVisibleSelection());
  12127. bookmark = selection.getBookmark();
  12128. applyRngStyle(expandRng(selection.getRng(TRUE), formatList), bookmark);
  12129. // Colored nodes should be underlined so that the color of the underline matches the text color.
  12130. if (format.styles && (format.styles.color || format.styles.textDecoration)) {
  12131. tinymce.walk(curSelNode, processUnderlineAndColor, 'childNodes');
  12132. processUnderlineAndColor(curSelNode);
  12133. }
  12134. selection.moveToBookmark(bookmark);
  12135. selection.setRng(moveStart(selection.getRng(TRUE)));
  12136. ed.nodeChanged();
  12137. } else
  12138. performCaretAction('apply', name, vars);
  12139. }
  12140. }
  12141. };
  12142. function remove(name, vars, node) {
  12143. var formatList = get(name), format = formatList[0], bookmark, i, rng;
  12144. function moveStart(rng) {
  12145. var container = rng.startContainer,
  12146. offset = rng.startOffset,
  12147. walker, node, nodes, tmpNode;
  12148. // Convert text node into index if possible
  12149. if (container.nodeType == 3 && offset >= container.nodeValue.length - 1) {
  12150. container = container.parentNode;
  12151. offset = nodeIndex(container) + 1;
  12152. }
  12153. // Move startContainer/startOffset in to a suitable node
  12154. if (container.nodeType == 1) {
  12155. nodes = container.childNodes;
  12156. container = nodes[Math.min(offset, nodes.length - 1)];
  12157. walker = new TreeWalker(container);
  12158. // If offset is at end of the parent node walk to the next one
  12159. if (offset > nodes.length - 1)
  12160. walker.next();
  12161. for (node = walker.current(); node; node = walker.next()) {
  12162. if (node.nodeType == 3 && !isWhiteSpaceNode(node)) {
  12163. // IE has a "neat" feature where it moves the start node into the closest element
  12164. // we can avoid this by inserting an element before it and then remove it after we set the selection
  12165. tmpNode = dom.create('a', null, INVISIBLE_CHAR);
  12166. node.parentNode.insertBefore(tmpNode, node);
  12167. // Set selection and remove tmpNode
  12168. rng.setStart(node, 0);
  12169. selection.setRng(rng);
  12170. dom.remove(tmpNode);
  12171. return;
  12172. }
  12173. }
  12174. }
  12175. };
  12176. // Merges the styles for each node
  12177. function process(node) {
  12178. var children, i, l;
  12179. // Grab the children first since the nodelist might be changed
  12180. children = tinymce.grep(node.childNodes);
  12181. // Process current node
  12182. for (i = 0, l = formatList.length; i < l; i++) {
  12183. if (removeFormat(formatList[i], vars, node, node))
  12184. break;
  12185. }
  12186. // Process the children
  12187. if (format.deep) {
  12188. for (i = 0, l = children.length; i < l; i++)
  12189. process(children[i]);
  12190. }
  12191. };
  12192. function findFormatRoot(container) {
  12193. var formatRoot;
  12194. // Find format root
  12195. each(getParents(container.parentNode).reverse(), function(parent) {
  12196. var format;
  12197. // Find format root element
  12198. if (!formatRoot && parent.id != '_start' && parent.id != '_end') {
  12199. // Is the node matching the format we are looking for
  12200. format = matchNode(parent, name, vars);
  12201. if (format && format.split !== false)
  12202. formatRoot = parent;
  12203. }
  12204. });
  12205. return formatRoot;
  12206. };
  12207. function wrapAndSplit(format_root, container, target, split) {
  12208. var parent, clone, lastClone, firstClone, i, formatRootParent;
  12209. // Format root found then clone formats and split it
  12210. if (format_root) {
  12211. formatRootParent = format_root.parentNode;
  12212. for (parent = container.parentNode; parent && parent != formatRootParent; parent = parent.parentNode) {
  12213. clone = parent.cloneNode(FALSE);
  12214. for (i = 0; i < formatList.length; i++) {
  12215. if (removeFormat(formatList[i], vars, clone, clone)) {
  12216. clone = 0;
  12217. break;
  12218. }
  12219. }
  12220. // Build wrapper node
  12221. if (clone) {
  12222. if (lastClone)
  12223. clone.appendChild(lastClone);
  12224. if (!firstClone)
  12225. firstClone = clone;
  12226. lastClone = clone;
  12227. }
  12228. }
  12229. // Never split block elements if the format is mixed
  12230. if (split && (!format.mixed || !isBlock(format_root)))
  12231. container = dom.split(format_root, container);
  12232. // Wrap container in cloned formats
  12233. if (lastClone) {
  12234. target.parentNode.insertBefore(lastClone, target);
  12235. firstClone.appendChild(target);
  12236. }
  12237. }
  12238. return container;
  12239. };
  12240. function splitToFormatRoot(container) {
  12241. return wrapAndSplit(findFormatRoot(container), container, container, true);
  12242. };
  12243. function unwrap(start) {
  12244. var node = dom.get(start ? '_start' : '_end'),
  12245. out = node[start ? 'firstChild' : 'lastChild'];
  12246. // If the end is placed within the start the result will be removed
  12247. // So this checks if the out node is a bookmark node if it is it
  12248. // checks for another more suitable node
  12249. if (isBookmarkNode(out))
  12250. out = out[start ? 'firstChild' : 'lastChild'];
  12251. dom.remove(node, true);
  12252. return out;
  12253. };
  12254. function removeRngStyle(rng) {
  12255. var startContainer, endContainer;
  12256. rng = expandRng(rng, formatList, TRUE);
  12257. if (format.split) {
  12258. startContainer = getContainer(rng, TRUE);
  12259. endContainer = getContainer(rng);
  12260. if (startContainer != endContainer) {
  12261. // Wrap start/end nodes in span element since these might be cloned/moved
  12262. startContainer = wrap(startContainer, 'span', {id : '_start', 'data-mce-type' : 'bookmark'});
  12263. endContainer = wrap(endContainer, 'span', {id : '_end', 'data-mce-type' : 'bookmark'});
  12264. // Split start/end
  12265. splitToFormatRoot(startContainer);
  12266. splitToFormatRoot(endContainer);
  12267. // Unwrap start/end to get real elements again
  12268. startContainer = unwrap(TRUE);
  12269. endContainer = unwrap();
  12270. } else
  12271. startContainer = endContainer = splitToFormatRoot(startContainer);
  12272. // Update range positions since they might have changed after the split operations
  12273. rng.startContainer = startContainer.parentNode;
  12274. rng.startOffset = nodeIndex(startContainer);
  12275. rng.endContainer = endContainer.parentNode;
  12276. rng.endOffset = nodeIndex(endContainer) + 1;
  12277. }
  12278. // Remove items between start/end
  12279. rangeUtils.walk(rng, function(nodes) {
  12280. each(nodes, function(node) {
  12281. process(node);
  12282. // Remove parent span if it only contains text-decoration: underline, yet a parent node is also underlined.
  12283. if (node.nodeType === 1 && ed.dom.getStyle(node, 'text-decoration') === 'underline' && node.parentNode && getTextDecoration(node.parentNode) === 'underline') {
  12284. removeFormat({'deep': false, 'exact': true, 'inline': 'span', 'styles': {'textDecoration' : 'underline'}}, null, node);
  12285. }
  12286. });
  12287. });
  12288. };
  12289. // Handle node
  12290. if (node) {
  12291. if (node.nodeType) {
  12292. rng = dom.createRng();
  12293. rng.setStartBefore(node);
  12294. rng.setEndAfter(node);
  12295. removeRngStyle(rng);
  12296. } else {
  12297. removeRngStyle(node);
  12298. }
  12299. return;
  12300. }
  12301. if (!selection.isCollapsed() || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  12302. bookmark = selection.getBookmark();
  12303. removeRngStyle(selection.getRng(TRUE));
  12304. selection.moveToBookmark(bookmark);
  12305. // Check if start element still has formatting then we are at: "<b>text|</b>text" and need to move the start into the next text node
  12306. if (format.inline && match(name, vars, selection.getStart())) {
  12307. moveStart(selection.getRng(true));
  12308. }
  12309. ed.nodeChanged();
  12310. } else
  12311. performCaretAction('remove', name, vars);
  12312. // When you remove formatting from a table cell in WebKit (cell, not the contents of a cell) there is a rendering issue with column width
  12313. if (tinymce.isWebKit) {
  12314. ed.execCommand('mceCleanup');
  12315. }
  12316. };
  12317. function toggle(name, vars, node) {
  12318. var fmt = get(name);
  12319. if (match(name, vars, node) && (!('toggle' in fmt[0]) || fmt[0]['toggle']))
  12320. remove(name, vars, node);
  12321. else
  12322. apply(name, vars, node);
  12323. };
  12324. function matchNode(node, name, vars, similar) {
  12325. var formatList = get(name), format, i, classes;
  12326. function matchItems(node, format, item_name) {
  12327. var key, value, items = format[item_name], i;
  12328. // Custom match
  12329. if (format.onmatch) {
  12330. return format.onmatch(node, format, item_name);
  12331. }
  12332. // Check all items
  12333. if (items) {
  12334. // Non indexed object
  12335. if (items.length === undefined) {
  12336. for (key in items) {
  12337. if (items.hasOwnProperty(key)) {
  12338. if (item_name === 'attributes')
  12339. value = dom.getAttrib(node, key);
  12340. else
  12341. value = getStyle(node, key);
  12342. if (similar && !value && !format.exact)
  12343. return;
  12344. if ((!similar || format.exact) && !isEq(value, replaceVars(items[key], vars)))
  12345. return;
  12346. }
  12347. }
  12348. } else {
  12349. // Only one match needed for indexed arrays
  12350. for (i = 0; i < items.length; i++) {
  12351. if (item_name === 'attributes' ? dom.getAttrib(node, items[i]) : getStyle(node, items[i]))
  12352. return format;
  12353. }
  12354. }
  12355. }
  12356. return format;
  12357. };
  12358. if (formatList && node) {
  12359. // Check each format in list
  12360. for (i = 0; i < formatList.length; i++) {
  12361. format = formatList[i];
  12362. // Name name, attributes, styles and classes
  12363. if (matchName(node, format) && matchItems(node, format, 'attributes') && matchItems(node, format, 'styles')) {
  12364. // Match classes
  12365. if (classes = format.classes) {
  12366. for (i = 0; i < classes.length; i++) {
  12367. if (!dom.hasClass(node, classes[i]))
  12368. return;
  12369. }
  12370. }
  12371. return format;
  12372. }
  12373. }
  12374. }
  12375. };
  12376. function match(name, vars, node) {
  12377. var startNode;
  12378. function matchParents(node) {
  12379. // Find first node with similar format settings
  12380. node = dom.getParent(node, function(node) {
  12381. return !!matchNode(node, name, vars, true);
  12382. });
  12383. // Do an exact check on the similar format element
  12384. return matchNode(node, name, vars);
  12385. };
  12386. // Check specified node
  12387. if (node)
  12388. return matchParents(node);
  12389. // Check selected node
  12390. node = selection.getNode();
  12391. if (matchParents(node))
  12392. return TRUE;
  12393. // Check start node if it's different
  12394. startNode = selection.getStart();
  12395. if (startNode != node) {
  12396. if (matchParents(startNode))
  12397. return TRUE;
  12398. }
  12399. return FALSE;
  12400. };
  12401. function matchAll(names, vars) {
  12402. var startElement, matchedFormatNames = [], checkedMap = {}, i, ni, name;
  12403. // Check start of selection for formats
  12404. startElement = selection.getStart();
  12405. dom.getParent(startElement, function(node) {
  12406. var i, name;
  12407. for (i = 0; i < names.length; i++) {
  12408. name = names[i];
  12409. if (!checkedMap[name] && matchNode(node, name, vars)) {
  12410. checkedMap[name] = true;
  12411. matchedFormatNames.push(name);
  12412. }
  12413. }
  12414. });
  12415. return matchedFormatNames;
  12416. };
  12417. function canApply(name) {
  12418. var formatList = get(name), startNode, parents, i, x, selector;
  12419. if (formatList) {
  12420. startNode = selection.getStart();
  12421. parents = getParents(startNode);
  12422. for (x = formatList.length - 1; x >= 0; x--) {
  12423. selector = formatList[x].selector;
  12424. // Format is not selector based, then always return TRUE
  12425. if (!selector)
  12426. return TRUE;
  12427. for (i = parents.length - 1; i >= 0; i--) {
  12428. if (dom.is(parents[i], selector))
  12429. return TRUE;
  12430. }
  12431. }
  12432. }
  12433. return FALSE;
  12434. };
  12435. // Expose to public
  12436. tinymce.extend(this, {
  12437. get : get,
  12438. register : register,
  12439. apply : apply,
  12440. remove : remove,
  12441. toggle : toggle,
  12442. match : match,
  12443. matchAll : matchAll,
  12444. matchNode : matchNode,
  12445. canApply : canApply
  12446. });
  12447. // Private functions
  12448. function matchName(node, format) {
  12449. // Check for inline match
  12450. if (isEq(node, format.inline))
  12451. return TRUE;
  12452. // Check for block match
  12453. if (isEq(node, format.block))
  12454. return TRUE;
  12455. // Check for selector match
  12456. if (format.selector)
  12457. return dom.is(node, format.selector);
  12458. };
  12459. function isEq(str1, str2) {
  12460. str1 = str1 || '';
  12461. str2 = str2 || '';
  12462. str1 = '' + (str1.nodeName || str1);
  12463. str2 = '' + (str2.nodeName || str2);
  12464. return str1.toLowerCase() == str2.toLowerCase();
  12465. };
  12466. function getStyle(node, name) {
  12467. var styleVal = dom.getStyle(node, name);
  12468. // Force the format to hex
  12469. if (name == 'color' || name == 'backgroundColor')
  12470. styleVal = dom.toHex(styleVal);
  12471. // Opera will return bold as 700
  12472. if (name == 'fontWeight' && styleVal == 700)
  12473. styleVal = 'bold';
  12474. return '' + styleVal;
  12475. };
  12476. function replaceVars(value, vars) {
  12477. if (typeof(value) != "string")
  12478. value = value(vars);
  12479. else if (vars) {
  12480. value = value.replace(/%(\w+)/g, function(str, name) {
  12481. return vars[name] || str;
  12482. });
  12483. }
  12484. return value;
  12485. };
  12486. function isWhiteSpaceNode(node) {
  12487. return node && node.nodeType === 3 && /^([\t \r\n]+|)$/.test(node.nodeValue);
  12488. };
  12489. function wrap(node, name, attrs) {
  12490. var wrapper = dom.create(name, attrs);
  12491. node.parentNode.insertBefore(wrapper, node);
  12492. wrapper.appendChild(node);
  12493. return wrapper;
  12494. };
  12495. function expandRng(rng, format, remove) {
  12496. var startContainer = rng.startContainer,
  12497. startOffset = rng.startOffset,
  12498. endContainer = rng.endContainer,
  12499. endOffset = rng.endOffset, sibling, lastIdx, leaf, endPoint;
  12500. // This function walks up the tree if there is no siblings before/after the node
  12501. function findParentContainer(start) {
  12502. var container, parent, child, sibling, siblingName;
  12503. container = parent = start ? startContainer : endContainer;
  12504. siblingName = start ? 'previousSibling' : 'nextSibling';
  12505. root = dom.getRoot();
  12506. // If it's a text node and the offset is inside the text
  12507. if (container.nodeType == 3 && !isWhiteSpaceNode(container)) {
  12508. if (start ? startOffset > 0 : endOffset < container.nodeValue.length) {
  12509. return container;
  12510. }
  12511. }
  12512. for (;;) {
  12513. // Stop expanding on block elements or root depending on format
  12514. if (parent == root || (!format[0].block_expand && isBlock(parent)))
  12515. return parent;
  12516. // Walk left/right
  12517. for (sibling = parent[siblingName]; sibling; sibling = sibling[siblingName]) {
  12518. if (!isBookmarkNode(sibling) && !isWhiteSpaceNode(sibling)) {
  12519. return parent;
  12520. }
  12521. }
  12522. // Check if we can move up are we at root level or body level
  12523. parent = parent.parentNode;
  12524. }
  12525. return container;
  12526. };
  12527. // This function walks down the tree to find the leaf at the selection.
  12528. // The offset is also returned as if node initially a leaf, the offset may be in the middle of the text node.
  12529. function findLeaf(node, offset) {
  12530. if (offset === undefined)
  12531. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  12532. while (node && node.hasChildNodes()) {
  12533. node = node.childNodes[offset];
  12534. if (node)
  12535. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  12536. }
  12537. return { node: node, offset: offset };
  12538. }
  12539. // If index based start position then resolve it
  12540. if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) {
  12541. lastIdx = startContainer.childNodes.length - 1;
  12542. startContainer = startContainer.childNodes[startOffset > lastIdx ? lastIdx : startOffset];
  12543. if (startContainer.nodeType == 3)
  12544. startOffset = 0;
  12545. }
  12546. // If index based end position then resolve it
  12547. if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) {
  12548. lastIdx = endContainer.childNodes.length - 1;
  12549. endContainer = endContainer.childNodes[endOffset > lastIdx ? lastIdx : endOffset - 1];
  12550. if (endContainer.nodeType == 3)
  12551. endOffset = endContainer.nodeValue.length;
  12552. }
  12553. // Exclude bookmark nodes if possible
  12554. if (isBookmarkNode(startContainer.parentNode) || isBookmarkNode(startContainer)) {
  12555. startContainer = isBookmarkNode(startContainer) ? startContainer : startContainer.parentNode;
  12556. startContainer = startContainer.nextSibling || startContainer;
  12557. if (startContainer.nodeType == 3)
  12558. startOffset = 0;
  12559. }
  12560. if (isBookmarkNode(endContainer.parentNode) || isBookmarkNode(endContainer)) {
  12561. endContainer = isBookmarkNode(endContainer) ? endContainer : endContainer.parentNode;
  12562. endContainer = endContainer.previousSibling || endContainer;
  12563. if (endContainer.nodeType == 3)
  12564. endOffset = endContainer.length;
  12565. }
  12566. if (format[0].inline) {
  12567. if (rng.collapsed) {
  12568. function findWordEndPoint(container, offset, start) {
  12569. var walker, node, pos, lastTextNode;
  12570. function findSpace(node, offset) {
  12571. var pos, pos2, str = node.nodeValue;
  12572. if (typeof(offset) == "undefined") {
  12573. offset = start ? str.length : 0;
  12574. }
  12575. if (start) {
  12576. pos = str.lastIndexOf(' ', offset);
  12577. pos2 = str.lastIndexOf('\u00a0', offset);
  12578. pos = pos > pos2 ? pos : pos2;
  12579. // Include the space on remove to avoid tag soup
  12580. if (pos !== -1 && !remove) {
  12581. pos++;
  12582. }
  12583. } else {
  12584. pos = str.indexOf(' ', offset);
  12585. pos2 = str.indexOf('\u00a0', offset);
  12586. pos = pos !== -1 && (pos2 === -1 || pos < pos2) ? pos : pos2;
  12587. }
  12588. return pos;
  12589. };
  12590. if (container.nodeType === 3) {
  12591. pos = findSpace(container, offset);
  12592. if (pos !== -1) {
  12593. return {container : container, offset : pos};
  12594. }
  12595. lastTextNode = container;
  12596. }
  12597. // Walk the nodes inside the block
  12598. walker = new TreeWalker(container, dom.getParent(container, isBlock) || ed.getBody());
  12599. while (node = walker[start ? 'prev' : 'next']()) {
  12600. if (node.nodeType === 3) {
  12601. lastTextNode = node;
  12602. pos = findSpace(node);
  12603. if (pos !== -1) {
  12604. return {container : node, offset : pos};
  12605. }
  12606. } else if (isBlock(node)) {
  12607. break;
  12608. }
  12609. }
  12610. if (lastTextNode) {
  12611. if (start) {
  12612. offset = 0;
  12613. } else {
  12614. offset = lastTextNode.length;
  12615. }
  12616. return {container: lastTextNode, offset: offset};
  12617. }
  12618. }
  12619. // Expand left to closest word boundery
  12620. endPoint = findWordEndPoint(startContainer, startOffset, true);
  12621. if (endPoint) {
  12622. startContainer = endPoint.container;
  12623. startOffset = endPoint.offset;
  12624. }
  12625. // Expand right to closest word boundery
  12626. endPoint = findWordEndPoint(endContainer, endOffset);
  12627. if (endPoint) {
  12628. endContainer = endPoint.container;
  12629. endOffset = endPoint.offset;
  12630. }
  12631. }
  12632. // Avoid applying formatting to a trailing space.
  12633. leaf = findLeaf(endContainer, endOffset);
  12634. if (leaf.node) {
  12635. while (leaf.node && leaf.offset === 0 && leaf.node.previousSibling)
  12636. leaf = findLeaf(leaf.node.previousSibling);
  12637. if (leaf.node && leaf.offset > 0 && leaf.node.nodeType === 3 &&
  12638. leaf.node.nodeValue.charAt(leaf.offset - 1) === ' ') {
  12639. if (leaf.offset > 1) {
  12640. endContainer = leaf.node;
  12641. endContainer.splitText(leaf.offset - 1);
  12642. } else if (leaf.node.previousSibling) {
  12643. // TODO: Figure out why this is in here
  12644. //endContainer = leaf.node.previousSibling;
  12645. }
  12646. }
  12647. }
  12648. }
  12649. // Move start/end point up the tree if the leaves are sharp and if we are in different containers
  12650. // Example * becomes !: !<p><b><i>*text</i><i>text*</i></b></p>!
  12651. // This will reduce the number of wrapper elements that needs to be created
  12652. // Move start point up the tree
  12653. if (format[0].inline || format[0].block_expand) {
  12654. if (!format[0].inline || (startContainer.nodeType != 3 || startOffset === 0)) {
  12655. startContainer = findParentContainer(true);
  12656. }
  12657. if (!format[0].inline || (endContainer.nodeType != 3 || endOffset === endContainer.nodeValue.length)) {
  12658. endContainer = findParentContainer();
  12659. }
  12660. }
  12661. // Expand start/end container to matching selector
  12662. if (format[0].selector && format[0].expand !== FALSE && !format[0].inline) {
  12663. function findSelectorEndPoint(container, sibling_name) {
  12664. var parents, i, y, curFormat;
  12665. if (container.nodeType == 3 && container.nodeValue.length == 0 && container[sibling_name])
  12666. container = container[sibling_name];
  12667. parents = getParents(container);
  12668. for (i = 0; i < parents.length; i++) {
  12669. for (y = 0; y < format.length; y++) {
  12670. curFormat = format[y];
  12671. // If collapsed state is set then skip formats that doesn't match that
  12672. if ("collapsed" in curFormat && curFormat.collapsed !== rng.collapsed)
  12673. continue;
  12674. if (dom.is(parents[i], curFormat.selector))
  12675. return parents[i];
  12676. }
  12677. }
  12678. return container;
  12679. };
  12680. // Find new startContainer/endContainer if there is better one
  12681. startContainer = findSelectorEndPoint(startContainer, 'previousSibling');
  12682. endContainer = findSelectorEndPoint(endContainer, 'nextSibling');
  12683. }
  12684. // Expand start/end container to matching block element or text node
  12685. if (format[0].block || format[0].selector) {
  12686. function findBlockEndPoint(container, sibling_name, sibling_name2) {
  12687. var node;
  12688. // Expand to block of similar type
  12689. if (!format[0].wrapper)
  12690. node = dom.getParent(container, format[0].block);
  12691. // Expand to first wrappable block element or any block element
  12692. if (!node)
  12693. node = dom.getParent(container.nodeType == 3 ? container.parentNode : container, isBlock);
  12694. // Exclude inner lists from wrapping
  12695. if (node && format[0].wrapper)
  12696. node = getParents(node, 'ul,ol').reverse()[0] || node;
  12697. // Didn't find a block element look for first/last wrappable element
  12698. if (!node) {
  12699. node = container;
  12700. while (node[sibling_name] && !isBlock(node[sibling_name])) {
  12701. node = node[sibling_name];
  12702. // Break on BR but include it will be removed later on
  12703. // we can't remove it now since we need to check if it can be wrapped
  12704. if (isEq(node, 'br'))
  12705. break;
  12706. }
  12707. }
  12708. return node || container;
  12709. };
  12710. // Find new startContainer/endContainer if there is better one
  12711. startContainer = findBlockEndPoint(startContainer, 'previousSibling');
  12712. endContainer = findBlockEndPoint(endContainer, 'nextSibling');
  12713. // Non block element then try to expand up the leaf
  12714. if (format[0].block) {
  12715. if (!isBlock(startContainer))
  12716. startContainer = findParentContainer(true);
  12717. if (!isBlock(endContainer))
  12718. endContainer = findParentContainer();
  12719. }
  12720. }
  12721. // Setup index for startContainer
  12722. if (startContainer.nodeType == 1) {
  12723. startOffset = nodeIndex(startContainer);
  12724. startContainer = startContainer.parentNode;
  12725. }
  12726. // Setup index for endContainer
  12727. if (endContainer.nodeType == 1) {
  12728. endOffset = nodeIndex(endContainer) + 1;
  12729. endContainer = endContainer.parentNode;
  12730. }
  12731. // Return new range like object
  12732. return {
  12733. startContainer : startContainer,
  12734. startOffset : startOffset,
  12735. endContainer : endContainer,
  12736. endOffset : endOffset
  12737. };
  12738. }
  12739. function removeFormat(format, vars, node, compare_node) {
  12740. var i, attrs, stylesModified;
  12741. // Check if node matches format
  12742. if (!matchName(node, format))
  12743. return FALSE;
  12744. // Should we compare with format attribs and styles
  12745. if (format.remove != 'all') {
  12746. // Remove styles
  12747. each(format.styles, function(value, name) {
  12748. value = replaceVars(value, vars);
  12749. // Indexed array
  12750. if (typeof(name) === 'number') {
  12751. name = value;
  12752. compare_node = 0;
  12753. }
  12754. if (!compare_node || isEq(getStyle(compare_node, name), value))
  12755. dom.setStyle(node, name, '');
  12756. stylesModified = 1;
  12757. });
  12758. // Remove style attribute if it's empty
  12759. if (stylesModified && dom.getAttrib(node, 'style') == '') {
  12760. node.removeAttribute('style');
  12761. node.removeAttribute('data-mce-style');
  12762. }
  12763. // Remove attributes
  12764. each(format.attributes, function(value, name) {
  12765. var valueOut;
  12766. value = replaceVars(value, vars);
  12767. // Indexed array
  12768. if (typeof(name) === 'number') {
  12769. name = value;
  12770. compare_node = 0;
  12771. }
  12772. if (!compare_node || isEq(dom.getAttrib(compare_node, name), value)) {
  12773. // Keep internal classes
  12774. if (name == 'class') {
  12775. value = dom.getAttrib(node, name);
  12776. if (value) {
  12777. // Build new class value where everything is removed except the internal prefixed classes
  12778. valueOut = '';
  12779. each(value.split(/\s+/), function(cls) {
  12780. if (/mce\w+/.test(cls))
  12781. valueOut += (valueOut ? ' ' : '') + cls;
  12782. });
  12783. // We got some internal classes left
  12784. if (valueOut) {
  12785. dom.setAttrib(node, name, valueOut);
  12786. return;
  12787. }
  12788. }
  12789. }
  12790. // IE6 has a bug where the attribute doesn't get removed correctly
  12791. if (name == "class")
  12792. node.removeAttribute('className');
  12793. // Remove mce prefixed attributes
  12794. if (MCE_ATTR_RE.test(name))
  12795. node.removeAttribute('data-mce-' + name);
  12796. node.removeAttribute(name);
  12797. }
  12798. });
  12799. // Remove classes
  12800. each(format.classes, function(value) {
  12801. value = replaceVars(value, vars);
  12802. if (!compare_node || dom.hasClass(compare_node, value))
  12803. dom.removeClass(node, value);
  12804. });
  12805. // Check for non internal attributes
  12806. attrs = dom.getAttribs(node);
  12807. for (i = 0; i < attrs.length; i++) {
  12808. if (attrs[i].nodeName.indexOf('_') !== 0)
  12809. return FALSE;
  12810. }
  12811. }
  12812. // Remove the inline child if it's empty for example <b> or <span>
  12813. if (format.remove != 'none') {
  12814. removeNode(node, format);
  12815. return TRUE;
  12816. }
  12817. };
  12818. function removeNode(node, format) {
  12819. var parentNode = node.parentNode, rootBlockElm;
  12820. if (format.block) {
  12821. if (!forcedRootBlock) {
  12822. function find(node, next, inc) {
  12823. node = getNonWhiteSpaceSibling(node, next, inc);
  12824. return !node || (node.nodeName == 'BR' || isBlock(node));
  12825. };
  12826. // Append BR elements if needed before we remove the block
  12827. if (isBlock(node) && !isBlock(parentNode)) {
  12828. if (!find(node, FALSE) && !find(node.firstChild, TRUE, 1))
  12829. node.insertBefore(dom.create('br'), node.firstChild);
  12830. if (!find(node, TRUE) && !find(node.lastChild, FALSE, 1))
  12831. node.appendChild(dom.create('br'));
  12832. }
  12833. } else {
  12834. // Wrap the block in a forcedRootBlock if we are at the root of document
  12835. if (parentNode == dom.getRoot()) {
  12836. if (!format.list_block || !isEq(node, format.list_block)) {
  12837. each(tinymce.grep(node.childNodes), function(node) {
  12838. if (isValid(forcedRootBlock, node.nodeName.toLowerCase())) {
  12839. if (!rootBlockElm)
  12840. rootBlockElm = wrap(node, forcedRootBlock);
  12841. else
  12842. rootBlockElm.appendChild(node);
  12843. } else
  12844. rootBlockElm = 0;
  12845. });
  12846. }
  12847. }
  12848. }
  12849. }
  12850. // Never remove nodes that isn't the specified inline element if a selector is specified too
  12851. if (format.selector && format.inline && !isEq(format.inline, node))
  12852. return;
  12853. dom.remove(node, 1);
  12854. };
  12855. function getNonWhiteSpaceSibling(node, next, inc) {
  12856. if (node) {
  12857. next = next ? 'nextSibling' : 'previousSibling';
  12858. for (node = inc ? node : node[next]; node; node = node[next]) {
  12859. if (node.nodeType == 1 || !isWhiteSpaceNode(node))
  12860. return node;
  12861. }
  12862. }
  12863. };
  12864. function isBookmarkNode(node) {
  12865. return node && node.nodeType == 1 && node.getAttribute('data-mce-type') == 'bookmark';
  12866. };
  12867. function mergeSiblings(prev, next) {
  12868. var marker, sibling, tmpSibling;
  12869. function compareElements(node1, node2) {
  12870. // Not the same name
  12871. if (node1.nodeName != node2.nodeName)
  12872. return FALSE;
  12873. function getAttribs(node) {
  12874. var attribs = {};
  12875. each(dom.getAttribs(node), function(attr) {
  12876. var name = attr.nodeName.toLowerCase();
  12877. // Don't compare internal attributes or style
  12878. if (name.indexOf('_') !== 0 && name !== 'style')
  12879. attribs[name] = dom.getAttrib(node, name);
  12880. });
  12881. return attribs;
  12882. };
  12883. function compareObjects(obj1, obj2) {
  12884. var value, name;
  12885. for (name in obj1) {
  12886. // Obj1 has item obj2 doesn't have
  12887. if (obj1.hasOwnProperty(name)) {
  12888. value = obj2[name];
  12889. // Obj2 doesn't have obj1 item
  12890. if (value === undefined)
  12891. return FALSE;
  12892. // Obj2 item has a different value
  12893. if (obj1[name] != value)
  12894. return FALSE;
  12895. // Delete similar value
  12896. delete obj2[name];
  12897. }
  12898. }
  12899. // Check if obj 2 has something obj 1 doesn't have
  12900. for (name in obj2) {
  12901. // Obj2 has item obj1 doesn't have
  12902. if (obj2.hasOwnProperty(name))
  12903. return FALSE;
  12904. }
  12905. return TRUE;
  12906. };
  12907. // Attribs are not the same
  12908. if (!compareObjects(getAttribs(node1), getAttribs(node2)))
  12909. return FALSE;
  12910. // Styles are not the same
  12911. if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style'))))
  12912. return FALSE;
  12913. return TRUE;
  12914. };
  12915. // Check if next/prev exists and that they are elements
  12916. if (prev && next) {
  12917. function findElementSibling(node, sibling_name) {
  12918. for (sibling = node; sibling; sibling = sibling[sibling_name]) {
  12919. if (sibling.nodeType == 3 && sibling.nodeValue.length !== 0)
  12920. return node;
  12921. if (sibling.nodeType == 1 && !isBookmarkNode(sibling))
  12922. return sibling;
  12923. }
  12924. return node;
  12925. };
  12926. // If previous sibling is empty then jump over it
  12927. prev = findElementSibling(prev, 'previousSibling');
  12928. next = findElementSibling(next, 'nextSibling');
  12929. // Compare next and previous nodes
  12930. if (compareElements(prev, next)) {
  12931. // Append nodes between
  12932. for (sibling = prev.nextSibling; sibling && sibling != next;) {
  12933. tmpSibling = sibling;
  12934. sibling = sibling.nextSibling;
  12935. prev.appendChild(tmpSibling);
  12936. }
  12937. // Remove next node
  12938. dom.remove(next);
  12939. // Move children into prev node
  12940. each(tinymce.grep(next.childNodes), function(node) {
  12941. prev.appendChild(node);
  12942. });
  12943. return prev;
  12944. }
  12945. }
  12946. return next;
  12947. };
  12948. function isTextBlock(name) {
  12949. return /^(h[1-6]|p|div|pre|address|dl|dt|dd)$/.test(name);
  12950. };
  12951. function getContainer(rng, start) {
  12952. var container, offset, lastIdx, walker;
  12953. container = rng[start ? 'startContainer' : 'endContainer'];
  12954. offset = rng[start ? 'startOffset' : 'endOffset'];
  12955. if (container.nodeType == 1) {
  12956. lastIdx = container.childNodes.length - 1;
  12957. if (!start && offset)
  12958. offset--;
  12959. container = container.childNodes[offset > lastIdx ? lastIdx : offset];
  12960. }
  12961. // If start text node is excluded then walk to the next node
  12962. if (container.nodeType === 3 && start && offset >= container.nodeValue.length) {
  12963. container = new TreeWalker(container, ed.getBody()).next() || container;
  12964. }
  12965. // If end text node is excluded then walk to the previous node
  12966. if (container.nodeType === 3 && !start && offset == 0) {
  12967. container = new TreeWalker(container, ed.getBody()).prev() || container;
  12968. }
  12969. return container;
  12970. };
  12971. function performCaretAction(type, name, vars) {
  12972. var invisibleChar, caretContainerId = '_mce_caret', debug = ed.settings.caret_debug;
  12973. // Setup invisible character use zero width space on Gecko since it doesn't change the heigt of the container
  12974. invisibleChar = tinymce.isGecko ? '\u200B' : INVISIBLE_CHAR;
  12975. // Creates a caret container bogus element
  12976. function createCaretContainer(fill) {
  12977. var caretContainer = dom.create('span', {id: caretContainerId, 'data-mce-bogus': true, style: debug ? 'color:red' : ''});
  12978. if (fill) {
  12979. caretContainer.appendChild(ed.getDoc().createTextNode(invisibleChar));
  12980. }
  12981. return caretContainer;
  12982. };
  12983. function isCaretContainerEmpty(node, nodes) {
  12984. while (node) {
  12985. if ((node.nodeType === 3 && node.nodeValue !== invisibleChar) || node.childNodes.length > 1) {
  12986. return false;
  12987. }
  12988. // Collect nodes
  12989. if (nodes && node.nodeType === 1) {
  12990. nodes.push(node);
  12991. }
  12992. node = node.firstChild;
  12993. }
  12994. return true;
  12995. };
  12996. // Returns any parent caret container element
  12997. function getParentCaretContainer(node) {
  12998. while (node) {
  12999. if (node.id === caretContainerId) {
  13000. return node;
  13001. }
  13002. node = node.parentNode;
  13003. }
  13004. };
  13005. // Finds the first text node in the specified node
  13006. function findFirstTextNode(node) {
  13007. var walker;
  13008. if (node) {
  13009. walker = new TreeWalker(node, node);
  13010. for (node = walker.current(); node; node = walker.next()) {
  13011. if (node.nodeType === 3) {
  13012. return node;
  13013. }
  13014. }
  13015. }
  13016. };
  13017. // Removes the caret container for the specified node or all on the current document
  13018. function removeCaretContainer(node, move_caret) {
  13019. var child, rng;
  13020. if (!node) {
  13021. node = getParentCaretContainer(selection.getStart());
  13022. if (!node) {
  13023. while (node = dom.get(caretContainerId)) {
  13024. removeCaretContainer(node, false);
  13025. }
  13026. }
  13027. } else {
  13028. rng = selection.getRng(true);
  13029. if (isCaretContainerEmpty(node)) {
  13030. if (move_caret !== false) {
  13031. rng.setStartBefore(node);
  13032. rng.setEndBefore(node);
  13033. }
  13034. dom.remove(node);
  13035. } else {
  13036. child = findFirstTextNode(node);
  13037. child = child.deleteData(0, 1);
  13038. dom.remove(node, 1);
  13039. }
  13040. selection.setRng(rng);
  13041. }
  13042. };
  13043. // Applies formatting to the caret postion
  13044. function applyCaretFormat() {
  13045. var rng, caretContainer, textNode, offset, bookmark, container, text;
  13046. rng = selection.getRng(true);
  13047. offset = rng.startOffset;
  13048. container = rng.startContainer;
  13049. text = container.nodeValue;
  13050. caretContainer = getParentCaretContainer(selection.getStart());
  13051. if (caretContainer) {
  13052. textNode = findFirstTextNode(caretContainer);
  13053. }
  13054. // Expand to word is caret is in the middle of a text node and the char before/after is a alpha numeric character
  13055. if (text && offset > 0 && offset < text.length && /\w/.test(text.charAt(offset)) && /\w/.test(text.charAt(offset - 1))) {
  13056. // Get bookmark of caret position
  13057. bookmark = selection.getBookmark();
  13058. // Collapse bookmark range (WebKit)
  13059. rng.collapse(true);
  13060. // Expand the range to the closest word and split it at those points
  13061. rng = expandRng(rng, get(name));
  13062. rng = rangeUtils.split(rng);
  13063. // Apply the format to the range
  13064. apply(name, vars, rng);
  13065. // Move selection back to caret position
  13066. selection.moveToBookmark(bookmark);
  13067. } else {
  13068. if (!caretContainer || textNode.nodeValue !== invisibleChar) {
  13069. caretContainer = createCaretContainer(true);
  13070. textNode = caretContainer.firstChild;
  13071. rng.insertNode(caretContainer);
  13072. offset = 1;
  13073. apply(name, vars, caretContainer);
  13074. } else {
  13075. apply(name, vars, caretContainer);
  13076. }
  13077. // Move selection to text node
  13078. selection.setCursorLocation(textNode, offset);
  13079. }
  13080. };
  13081. function removeCaretFormat() {
  13082. var rng = selection.getRng(true), container, offset, bookmark,
  13083. hasContentAfter, node, formatNode, parents = [], i, caretContainer;
  13084. container = rng.startContainer;
  13085. offset = rng.startOffset;
  13086. node = container;
  13087. if (container.nodeType == 3) {
  13088. if (offset != container.nodeValue.length || container.nodeValue === invisibleChar) {
  13089. hasContentAfter = true;
  13090. }
  13091. node = node.parentNode;
  13092. }
  13093. while (node) {
  13094. if (matchNode(node, name, vars)) {
  13095. formatNode = node;
  13096. break;
  13097. }
  13098. if (node.nextSibling) {
  13099. hasContentAfter = true;
  13100. }
  13101. parents.push(node);
  13102. node = node.parentNode;
  13103. }
  13104. // Node doesn't have the specified format
  13105. if (!formatNode) {
  13106. return;
  13107. }
  13108. // Is there contents after the caret then remove the format on the element
  13109. if (hasContentAfter) {
  13110. // Get bookmark of caret position
  13111. bookmark = selection.getBookmark();
  13112. // Collapse bookmark range (WebKit)
  13113. rng.collapse(true);
  13114. // Expand the range to the closest word and split it at those points
  13115. rng = expandRng(rng, get(name), true);
  13116. rng = rangeUtils.split(rng);
  13117. // Remove the format from the range
  13118. remove(name, vars, rng);
  13119. // Move selection back to caret position
  13120. selection.moveToBookmark(bookmark);
  13121. } else {
  13122. caretContainer = createCaretContainer();
  13123. node = caretContainer;
  13124. for (i = parents.length - 1; i >= 0; i--) {
  13125. node.appendChild(parents[i].cloneNode(false));
  13126. node = node.firstChild;
  13127. }
  13128. // Insert invisible character into inner most format element
  13129. node.appendChild(dom.doc.createTextNode(invisibleChar));
  13130. node = node.firstChild;
  13131. // Insert caret container after the formated node
  13132. dom.insertAfter(caretContainer, formatNode);
  13133. // Move selection to text node
  13134. selection.setCursorLocation(node, 1);
  13135. }
  13136. };
  13137. // Mark current caret container elements as bogus when getting the contents so we don't end up with empty elements
  13138. ed.onBeforeGetContent.addToTop(function() {
  13139. var nodes = [], i;
  13140. if (isCaretContainerEmpty(getParentCaretContainer(selection.getStart()), nodes)) {
  13141. // Mark children
  13142. i = nodes.length;
  13143. while (i--) {
  13144. dom.setAttrib(nodes[i], 'data-mce-bogus', '1');
  13145. }
  13146. }
  13147. });
  13148. // Remove caret container on mouse up and on key up
  13149. tinymce.each('onMouseUp onKeyUp'.split(' '), function(name) {
  13150. ed[name].addToTop(function() {
  13151. removeCaretContainer();
  13152. });
  13153. });
  13154. // Remove caret container on keydown and it's a backspace, enter or left/right arrow keys
  13155. ed.onKeyDown.addToTop(function(ed, e) {
  13156. var keyCode = e.keyCode;
  13157. if (keyCode == 8 || keyCode == 37 || keyCode == 39) {
  13158. removeCaretContainer(getParentCaretContainer(selection.getStart()));
  13159. }
  13160. });
  13161. // Do apply or remove caret format
  13162. if (type == "apply") {
  13163. applyCaretFormat();
  13164. } else {
  13165. removeCaretFormat();
  13166. }
  13167. };
  13168. };
  13169. })(tinymce);
  13170. tinymce.onAddEditor.add(function(tinymce, ed) {
  13171. var filters, fontSizes, dom, settings = ed.settings;
  13172. if (settings.inline_styles) {
  13173. fontSizes = tinymce.explode(settings.font_size_legacy_values);
  13174. function replaceWithSpan(node, styles) {
  13175. tinymce.each(styles, function(value, name) {
  13176. if (value)
  13177. dom.setStyle(node, name, value);
  13178. });
  13179. dom.rename(node, 'span');
  13180. };
  13181. filters = {
  13182. font : function(dom, node) {
  13183. replaceWithSpan(node, {
  13184. backgroundColor : node.style.backgroundColor,
  13185. color : node.color,
  13186. fontFamily : node.face,
  13187. fontSize : fontSizes[parseInt(node.size) - 1]
  13188. });
  13189. },
  13190. u : function(dom, node) {
  13191. replaceWithSpan(node, {
  13192. textDecoration : 'underline'
  13193. });
  13194. },
  13195. strike : function(dom, node) {
  13196. replaceWithSpan(node, {
  13197. textDecoration : 'line-through'
  13198. });
  13199. }
  13200. };
  13201. function convert(editor, params) {
  13202. dom = editor.dom;
  13203. if (settings.convert_fonts_to_spans) {
  13204. tinymce.each(dom.select('font,u,strike', params.node), function(node) {
  13205. filters[node.nodeName.toLowerCase()](ed.dom, node);
  13206. });
  13207. }
  13208. };
  13209. ed.onPreProcess.add(convert);
  13210. ed.onSetContent.add(convert);
  13211. ed.onInit.add(function() {
  13212. ed.selection.onSetContent.add(convert);
  13213. });
  13214. }
  13215. });