tiny_mce_jquery_src.js 400 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905
  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. trim : function(s) {
  116. return (s ? '' + s : '').replace(whiteSpaceRe, '');
  117. },
  118. create : function(s, p, root) {
  119. var t = this, sp, ns, cn, scn, c, de = 0;
  120. // Parse : <prefix> <class>:<super class>
  121. s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s);
  122. cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name
  123. // Create namespace for new class
  124. ns = t.createNS(s[3].replace(/\.\w+$/, ''), root);
  125. // Class already exists
  126. if (ns[cn])
  127. return;
  128. // Make pure static class
  129. if (s[2] == 'static') {
  130. ns[cn] = p;
  131. if (this.onCreate)
  132. this.onCreate(s[2], s[3], ns[cn]);
  133. return;
  134. }
  135. // Create default constructor
  136. if (!p[cn]) {
  137. p[cn] = function() {};
  138. de = 1;
  139. }
  140. // Add constructor and methods
  141. ns[cn] = p[cn];
  142. t.extend(ns[cn].prototype, p);
  143. // Extend
  144. if (s[5]) {
  145. sp = t.resolve(s[5]).prototype;
  146. scn = s[5].match(/\.(\w+)$/i)[1]; // Class name
  147. // Extend constructor
  148. c = ns[cn];
  149. if (de) {
  150. // Add passthrough constructor
  151. ns[cn] = function() {
  152. return sp[scn].apply(this, arguments);
  153. };
  154. } else {
  155. // Add inherit constructor
  156. ns[cn] = function() {
  157. this.parent = sp[scn];
  158. return c.apply(this, arguments);
  159. };
  160. }
  161. ns[cn].prototype[cn] = ns[cn];
  162. // Add super methods
  163. t.each(sp, function(f, n) {
  164. ns[cn].prototype[n] = sp[n];
  165. });
  166. // Add overridden methods
  167. t.each(p, function(f, n) {
  168. // Extend methods if needed
  169. if (sp[n]) {
  170. ns[cn].prototype[n] = function() {
  171. this.parent = sp[n];
  172. return f.apply(this, arguments);
  173. };
  174. } else {
  175. if (n != cn)
  176. ns[cn].prototype[n] = f;
  177. }
  178. });
  179. }
  180. // Add static methods
  181. t.each(p['static'], function(f, n) {
  182. ns[cn][n] = f;
  183. });
  184. if (this.onCreate)
  185. this.onCreate(s[2], s[3], ns[cn].prototype);
  186. },
  187. walk : function(o, f, n, s) {
  188. s = s || this;
  189. if (o) {
  190. if (n)
  191. o = o[n];
  192. tinymce.each(o, function(o, i) {
  193. if (f.call(s, o, i, n) === false)
  194. return false;
  195. tinymce.walk(o, f, n, s);
  196. });
  197. }
  198. },
  199. createNS : function(n, o) {
  200. var i, v;
  201. o = o || win;
  202. n = n.split('.');
  203. for (i=0; i<n.length; i++) {
  204. v = n[i];
  205. if (!o[v])
  206. o[v] = {};
  207. o = o[v];
  208. }
  209. return o;
  210. },
  211. resolve : function(n, o) {
  212. var i, l;
  213. o = o || win;
  214. n = n.split('.');
  215. for (i = 0, l = n.length; i < l; i++) {
  216. o = o[n[i]];
  217. if (!o)
  218. break;
  219. }
  220. return o;
  221. },
  222. addUnload : function(f, s) {
  223. var t = this;
  224. f = {func : f, scope : s || this};
  225. if (!t.unloads) {
  226. function unload() {
  227. var li = t.unloads, o, n;
  228. if (li) {
  229. // Call unload handlers
  230. for (n in li) {
  231. o = li[n];
  232. if (o && o.func)
  233. o.func.call(o.scope, 1); // Send in one arg to distinct unload and user destroy
  234. }
  235. // Detach unload function
  236. if (win.detachEvent) {
  237. win.detachEvent('onbeforeunload', fakeUnload);
  238. win.detachEvent('onunload', unload);
  239. } else if (win.removeEventListener)
  240. win.removeEventListener('unload', unload, false);
  241. // Destroy references
  242. t.unloads = o = li = w = unload = 0;
  243. // Run garbarge collector on IE
  244. if (win.CollectGarbage)
  245. CollectGarbage();
  246. }
  247. };
  248. function fakeUnload() {
  249. var d = document;
  250. // Is there things still loading, then do some magic
  251. if (d.readyState == 'interactive') {
  252. function stop() {
  253. // Prevent memory leak
  254. d.detachEvent('onstop', stop);
  255. // Call unload handler
  256. if (unload)
  257. unload();
  258. d = 0;
  259. };
  260. // Fire unload when the currently loading page is stopped
  261. if (d)
  262. d.attachEvent('onstop', stop);
  263. // Remove onstop listener after a while to prevent the unload function
  264. // to execute if the user presses cancel in an onbeforeunload
  265. // confirm dialog and then presses the browser stop button
  266. win.setTimeout(function() {
  267. if (d)
  268. d.detachEvent('onstop', stop);
  269. }, 0);
  270. }
  271. };
  272. // Attach unload handler
  273. if (win.attachEvent) {
  274. win.attachEvent('onunload', unload);
  275. win.attachEvent('onbeforeunload', fakeUnload);
  276. } else if (win.addEventListener)
  277. win.addEventListener('unload', unload, false);
  278. // Setup initial unload handler array
  279. t.unloads = [f];
  280. } else
  281. t.unloads.push(f);
  282. return f;
  283. },
  284. removeUnload : function(f) {
  285. var u = this.unloads, r = null;
  286. tinymce.each(u, function(o, i) {
  287. if (o && o.func == f) {
  288. u.splice(i, 1);
  289. r = f;
  290. return false;
  291. }
  292. });
  293. return r;
  294. },
  295. explode : function(s, d) {
  296. return s ? tinymce.map(s.split(d || ','), tinymce.trim) : s;
  297. },
  298. _addVer : function(u) {
  299. var v;
  300. if (!this.query)
  301. return u;
  302. v = (u.indexOf('?') == -1 ? '?' : '&') + this.query;
  303. if (u.indexOf('#') == -1)
  304. return u + v;
  305. return u.replace('#', v + '#');
  306. },
  307. // Fix function for IE 9 where regexps isn't working correctly
  308. // Todo: remove me once MS fixes the bug
  309. _replace : function(find, replace, str) {
  310. // On IE9 we have to fake $x replacement
  311. if (isRegExpBroken) {
  312. return str.replace(find, function() {
  313. var val = replace, args = arguments, i;
  314. for (i = 0; i < args.length - 2; i++) {
  315. if (args[i] === undefined) {
  316. val = val.replace(new RegExp('\\$' + i, 'g'), '');
  317. } else {
  318. val = val.replace(new RegExp('\\$' + i, 'g'), args[i]);
  319. }
  320. }
  321. return val;
  322. });
  323. }
  324. return str.replace(find, replace);
  325. }
  326. };
  327. // Initialize the API
  328. tinymce._init();
  329. // Expose tinymce namespace to the global namespace (window)
  330. win.tinymce = win.tinyMCE = tinymce;
  331. // Describe the different namespaces
  332. })(window);
  333. (function($, tinymce) {
  334. var is = tinymce.is, attrRegExp = /^(href|src|style)$/i, undefined;
  335. // jQuery is undefined
  336. if (!$ && window.console) {
  337. return console.log("Load jQuery first!");
  338. }
  339. // Stick jQuery into the tinymce namespace
  340. tinymce.$ = $;
  341. // Setup adapter
  342. tinymce.adapter = {
  343. patchEditor : function(editor) {
  344. var fn = $.fn;
  345. // Adapt the css function to make sure that the data-mce-style
  346. // attribute gets updated with the new style information
  347. function css(name, value) {
  348. var self = this;
  349. // Remove data-mce-style when set operation occurs
  350. if (value)
  351. self.removeAttr('data-mce-style');
  352. return fn.css.apply(self, arguments);
  353. };
  354. // Apapt the attr function to make sure that it uses the data-mce- prefixed variants
  355. function attr(name, value) {
  356. var self = this;
  357. // Update/retrive data-mce- attribute variants
  358. if (attrRegExp.test(name)) {
  359. if (value !== undefined) {
  360. // Use TinyMCE behavior when setting the specifc attributes
  361. self.each(function(i, node) {
  362. editor.dom.setAttrib(node, name, value);
  363. });
  364. return self;
  365. } else
  366. return self.attr('data-mce-' + name);
  367. }
  368. // Default behavior
  369. return fn.attr.apply(self, arguments);
  370. };
  371. function htmlPatchFunc(func) {
  372. // Returns a modified function that processes
  373. // the HTML before executing the action this makes sure
  374. // that href/src etc gets moved into the data-mce- variants
  375. return function(content) {
  376. if (content)
  377. content = editor.dom.processHTML(content);
  378. return func.call(this, content);
  379. };
  380. };
  381. // Patch various jQuery functions to handle tinymce specific attribute and content behavior
  382. // we don't patch the jQuery.fn directly since it will most likely break compatibility
  383. // with other jQuery logic on the page. Only instances created by TinyMCE should be patched.
  384. function patch(jq) {
  385. // Patch some functions, only patch the object once
  386. if (jq.css !== css) {
  387. // Patch css/attr to use the data-mce- prefixed attribute variants
  388. jq.css = css;
  389. jq.attr = attr;
  390. // Patch HTML functions to use the DOMUtils.processHTML filter logic
  391. jq.html = htmlPatchFunc(fn.html);
  392. jq.append = htmlPatchFunc(fn.append);
  393. jq.prepend = htmlPatchFunc(fn.prepend);
  394. jq.after = htmlPatchFunc(fn.after);
  395. jq.before = htmlPatchFunc(fn.before);
  396. jq.replaceWith = htmlPatchFunc(fn.replaceWith);
  397. jq.tinymce = editor;
  398. // Each pushed jQuery instance needs to be patched
  399. // as well for example when traversing the DOM
  400. jq.pushStack = function() {
  401. return patch(fn.pushStack.apply(this, arguments));
  402. };
  403. }
  404. return jq;
  405. };
  406. // Add a $ function on each editor instance this one is scoped for the editor document object
  407. // this way you can do chaining like this tinymce.get(0).$('p').append('text').css('color', 'red');
  408. editor.$ = function(selector, scope) {
  409. var doc = editor.getDoc();
  410. return patch($(selector || doc, doc || scope));
  411. };
  412. }
  413. };
  414. // Patch in core NS functions
  415. tinymce.extend = $.extend;
  416. tinymce.extend(tinymce, {
  417. map : $.map,
  418. grep : function(a, f) {return $.grep(a, f || function(){return 1;});},
  419. inArray : function(a, v) {return $.inArray(v, a || []);}
  420. /* Didn't iterate stylesheets
  421. each : function(o, cb, s) {
  422. if (!o)
  423. return 0;
  424. var r = 1;
  425. $.each(o, function(nr, el){
  426. if (cb.call(s, el, nr, o) === false) {
  427. r = 0;
  428. return false;
  429. }
  430. });
  431. return r;
  432. }*/
  433. });
  434. // Patch in functions in various clases
  435. // Add a "#ifndefjquery" statement around each core API function you add below
  436. var patches = {
  437. 'tinymce.dom.DOMUtils' : {
  438. /*
  439. addClass : function(e, c) {
  440. if (is(e, 'array') && is(e[0], 'string'))
  441. e = e.join(',#');
  442. return (e && $(is(e, 'string') ? '#' + e : e)
  443. .addClass(c)
  444. .attr('class')) || false;
  445. },
  446. hasClass : function(n, c) {
  447. return $(is(n, 'string') ? '#' + n : n).hasClass(c);
  448. },
  449. removeClass : function(e, c) {
  450. if (!e)
  451. return false;
  452. var r = [];
  453. $(is(e, 'string') ? '#' + e : e)
  454. .removeClass(c)
  455. .each(function(){
  456. r.push(this.className);
  457. });
  458. return r.length == 1 ? r[0] : r;
  459. },
  460. */
  461. select : function(pattern, scope) {
  462. var t = this;
  463. return $.find(pattern, t.get(scope) || t.get(t.settings.root_element) || t.doc, []);
  464. },
  465. is : function(n, patt) {
  466. return $(this.get(n)).is(patt);
  467. }
  468. /*
  469. show : function(e) {
  470. if (is(e, 'array') && is(e[0], 'string'))
  471. e = e.join(',#');
  472. $(is(e, 'string') ? '#' + e : e).css('display', 'block');
  473. },
  474. hide : function(e) {
  475. if (is(e, 'array') && is(e[0], 'string'))
  476. e = e.join(',#');
  477. $(is(e, 'string') ? '#' + e : e).css('display', 'none');
  478. },
  479. isHidden : function(e) {
  480. return $(is(e, 'string') ? '#' + e : e).is(':hidden');
  481. },
  482. insertAfter : function(n, e) {
  483. return $(is(e, 'string') ? '#' + e : e).after(n);
  484. },
  485. replace : function(o, n, k) {
  486. n = $(is(n, 'string') ? '#' + n : n);
  487. if (k)
  488. n.children().appendTo(o);
  489. n.replaceWith(o);
  490. },
  491. setStyle : function(n, na, v) {
  492. if (is(n, 'array') && is(n[0], 'string'))
  493. n = n.join(',#');
  494. $(is(n, 'string') ? '#' + n : n).css(na, v);
  495. },
  496. getStyle : function(n, na, c) {
  497. return $(is(n, 'string') ? '#' + n : n).css(na);
  498. },
  499. setStyles : function(e, o) {
  500. if (is(e, 'array') && is(e[0], 'string'))
  501. e = e.join(',#');
  502. $(is(e, 'string') ? '#' + e : e).css(o);
  503. },
  504. setAttrib : function(e, n, v) {
  505. var t = this, s = t.settings;
  506. if (is(e, 'array') && is(e[0], 'string'))
  507. e = e.join(',#');
  508. e = $(is(e, 'string') ? '#' + e : e);
  509. switch (n) {
  510. case "style":
  511. e.each(function(i, v){
  512. if (s.keep_values)
  513. $(v).attr('data-mce-style', v);
  514. v.style.cssText = v;
  515. });
  516. break;
  517. case "class":
  518. e.each(function(){
  519. this.className = v;
  520. });
  521. break;
  522. case "src":
  523. case "href":
  524. e.each(function(i, v){
  525. if (s.keep_values) {
  526. if (s.url_converter)
  527. v = s.url_converter.call(s.url_converter_scope || t, v, n, v);
  528. t.setAttrib(v, 'data-mce-' + n, v);
  529. }
  530. });
  531. break;
  532. }
  533. if (v !== null && v.length !== 0)
  534. e.attr(n, '' + v);
  535. else
  536. e.removeAttr(n);
  537. },
  538. setAttribs : function(e, o) {
  539. var t = this;
  540. $.each(o, function(n, v){
  541. t.setAttrib(e,n,v);
  542. });
  543. }
  544. */
  545. }
  546. /*
  547. 'tinymce.dom.Event' : {
  548. add : function (o, n, f, s) {
  549. var lo, cb;
  550. cb = function(e) {
  551. e.target = e.target || this;
  552. f.call(s || this, e);
  553. };
  554. if (is(o, 'array') && is(o[0], 'string'))
  555. o = o.join(',#');
  556. o = $(is(o, 'string') ? '#' + o : o);
  557. if (n == 'init') {
  558. o.ready(cb, s);
  559. } else {
  560. if (s) {
  561. o.bind(n, s, cb);
  562. } else {
  563. o.bind(n, cb);
  564. }
  565. }
  566. lo = this._jqLookup || (this._jqLookup = []);
  567. lo.push({func : f, cfunc : cb});
  568. return cb;
  569. },
  570. remove : function(o, n, f) {
  571. // Find cfunc
  572. $(this._jqLookup).each(function() {
  573. if (this.func === f)
  574. f = this.cfunc;
  575. });
  576. if (is(o, 'array') && is(o[0], 'string'))
  577. o = o.join(',#');
  578. $(is(o, 'string') ? '#' + o : o).unbind(n,f);
  579. return true;
  580. }
  581. }
  582. */
  583. };
  584. // Patch functions after a class is created
  585. tinymce.onCreate = function(ty, c, p) {
  586. tinymce.extend(p, patches[c]);
  587. };
  588. })(window.jQuery, tinymce);
  589. tinymce.create('tinymce.util.Dispatcher', {
  590. scope : null,
  591. listeners : null,
  592. Dispatcher : function(s) {
  593. this.scope = s || this;
  594. this.listeners = [];
  595. },
  596. add : function(cb, s) {
  597. this.listeners.push({cb : cb, scope : s || this.scope});
  598. return cb;
  599. },
  600. addToTop : function(cb, s) {
  601. this.listeners.unshift({cb : cb, scope : s || this.scope});
  602. return cb;
  603. },
  604. remove : function(cb) {
  605. var l = this.listeners, o = null;
  606. tinymce.each(l, function(c, i) {
  607. if (cb == c.cb) {
  608. o = cb;
  609. l.splice(i, 1);
  610. return false;
  611. }
  612. });
  613. return o;
  614. },
  615. dispatch : function() {
  616. var s, a = arguments, i, li = this.listeners, c;
  617. // Needs to be a real loop since the listener count might change while looping
  618. // And this is also more efficient
  619. for (i = 0; i<li.length; i++) {
  620. c = li[i];
  621. s = c.cb.apply(c.scope, a);
  622. if (s === false)
  623. break;
  624. }
  625. return s;
  626. }
  627. });
  628. (function() {
  629. var each = tinymce.each;
  630. tinymce.create('tinymce.util.URI', {
  631. URI : function(u, s) {
  632. var t = this, o, a, b, base_url;
  633. // Trim whitespace
  634. u = tinymce.trim(u);
  635. // Default settings
  636. s = t.settings = s || {};
  637. // Strange app protocol that isn't http/https or local anchor
  638. // For example: mailto,skype,tel etc.
  639. if (/^([\w\-]+):([^\/]{2})/i.test(u) || /^\s*#/.test(u)) {
  640. t.source = u;
  641. return;
  642. }
  643. // Absolute path with no host, fake host and protocol
  644. if (u.indexOf('/') === 0 && u.indexOf('//') !== 0)
  645. u = (s.base_uri ? s.base_uri.protocol || 'http' : 'http') + '://mce_host' + u;
  646. // Relative path http:// or protocol relative //path
  647. if (!/^[\w-]*:?\/\//.test(u)) {
  648. base_url = s.base_uri ? s.base_uri.path : new tinymce.util.URI(location.href).directory;
  649. u = ((s.base_uri && s.base_uri.protocol) || 'http') + '://mce_host' + t.toAbsPath(base_url, u);
  650. }
  651. // Parse URL (Credits goes to Steave, http://blog.stevenlevithan.com/archives/parseuri)
  652. u = u.replace(/@@/g, '(mce_at)'); // Zope 3 workaround, they use @@something
  653. u = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(u);
  654. each(["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], function(v, i) {
  655. var s = u[i];
  656. // Zope 3 workaround, they use @@something
  657. if (s)
  658. s = s.replace(/\(mce_at\)/g, '@@');
  659. t[v] = s;
  660. });
  661. if (b = s.base_uri) {
  662. if (!t.protocol)
  663. t.protocol = b.protocol;
  664. if (!t.userInfo)
  665. t.userInfo = b.userInfo;
  666. if (!t.port && t.host == 'mce_host')
  667. t.port = b.port;
  668. if (!t.host || t.host == 'mce_host')
  669. t.host = b.host;
  670. t.source = '';
  671. }
  672. //t.path = t.path || '/';
  673. },
  674. setPath : function(p) {
  675. var t = this;
  676. p = /^(.*?)\/?(\w+)?$/.exec(p);
  677. // Update path parts
  678. t.path = p[0];
  679. t.directory = p[1];
  680. t.file = p[2];
  681. // Rebuild source
  682. t.source = '';
  683. t.getURI();
  684. },
  685. toRelative : function(u) {
  686. var t = this, o;
  687. if (u === "./")
  688. return u;
  689. u = new tinymce.util.URI(u, {base_uri : t});
  690. // Not on same domain/port or protocol
  691. if ((u.host != 'mce_host' && t.host != u.host && u.host) || t.port != u.port || t.protocol != u.protocol)
  692. return u.getURI();
  693. o = t.toRelPath(t.path, u.path);
  694. // Add query
  695. if (u.query)
  696. o += '?' + u.query;
  697. // Add anchor
  698. if (u.anchor)
  699. o += '#' + u.anchor;
  700. return o;
  701. },
  702. toAbsolute : function(u, nh) {
  703. var u = new tinymce.util.URI(u, {base_uri : this});
  704. return u.getURI(this.host == u.host && this.protocol == u.protocol ? nh : 0);
  705. },
  706. toRelPath : function(base, path) {
  707. var items, bp = 0, out = '', i, l;
  708. // Split the paths
  709. base = base.substring(0, base.lastIndexOf('/'));
  710. base = base.split('/');
  711. items = path.split('/');
  712. if (base.length >= items.length) {
  713. for (i = 0, l = base.length; i < l; i++) {
  714. if (i >= items.length || base[i] != items[i]) {
  715. bp = i + 1;
  716. break;
  717. }
  718. }
  719. }
  720. if (base.length < items.length) {
  721. for (i = 0, l = items.length; i < l; i++) {
  722. if (i >= base.length || base[i] != items[i]) {
  723. bp = i + 1;
  724. break;
  725. }
  726. }
  727. }
  728. if (bp == 1)
  729. return path;
  730. for (i = 0, l = base.length - (bp - 1); i < l; i++)
  731. out += "../";
  732. for (i = bp - 1, l = items.length; i < l; i++) {
  733. if (i != bp - 1)
  734. out += "/" + items[i];
  735. else
  736. out += items[i];
  737. }
  738. return out;
  739. },
  740. toAbsPath : function(base, path) {
  741. var i, nb = 0, o = [], tr, outPath;
  742. // Split paths
  743. tr = /\/$/.test(path) ? '/' : '';
  744. base = base.split('/');
  745. path = path.split('/');
  746. // Remove empty chunks
  747. each(base, function(k) {
  748. if (k)
  749. o.push(k);
  750. });
  751. base = o;
  752. // Merge relURLParts chunks
  753. for (i = path.length - 1, o = []; i >= 0; i--) {
  754. // Ignore empty or .
  755. if (path[i].length == 0 || path[i] == ".")
  756. continue;
  757. // Is parent
  758. if (path[i] == '..') {
  759. nb++;
  760. continue;
  761. }
  762. // Move up
  763. if (nb > 0) {
  764. nb--;
  765. continue;
  766. }
  767. o.push(path[i]);
  768. }
  769. i = base.length - nb;
  770. // If /a/b/c or /
  771. if (i <= 0)
  772. outPath = o.reverse().join('/');
  773. else
  774. outPath = base.slice(0, i).join('/') + '/' + o.reverse().join('/');
  775. // Add front / if it's needed
  776. if (outPath.indexOf('/') !== 0)
  777. outPath = '/' + outPath;
  778. // Add traling / if it's needed
  779. if (tr && outPath.lastIndexOf('/') !== outPath.length - 1)
  780. outPath += tr;
  781. return outPath;
  782. },
  783. getURI : function(nh) {
  784. var s, t = this;
  785. // Rebuild source
  786. if (!t.source || nh) {
  787. s = '';
  788. if (!nh) {
  789. if (t.protocol)
  790. s += t.protocol + '://';
  791. if (t.userInfo)
  792. s += t.userInfo + '@';
  793. if (t.host)
  794. s += t.host;
  795. if (t.port)
  796. s += ':' + t.port;
  797. }
  798. if (t.path)
  799. s += t.path;
  800. if (t.query)
  801. s += '?' + t.query;
  802. if (t.anchor)
  803. s += '#' + t.anchor;
  804. t.source = s;
  805. }
  806. return t.source;
  807. }
  808. });
  809. })();
  810. (function() {
  811. var each = tinymce.each;
  812. tinymce.create('static tinymce.util.Cookie', {
  813. getHash : function(n) {
  814. var v = this.get(n), h;
  815. if (v) {
  816. each(v.split('&'), function(v) {
  817. v = v.split('=');
  818. h = h || {};
  819. h[unescape(v[0])] = unescape(v[1]);
  820. });
  821. }
  822. return h;
  823. },
  824. setHash : function(n, v, e, p, d, s) {
  825. var o = '';
  826. each(v, function(v, k) {
  827. o += (!o ? '' : '&') + escape(k) + '=' + escape(v);
  828. });
  829. this.set(n, o, e, p, d, s);
  830. },
  831. get : function(n) {
  832. var c = document.cookie, e, p = n + "=", b;
  833. // Strict mode
  834. if (!c)
  835. return;
  836. b = c.indexOf("; " + p);
  837. if (b == -1) {
  838. b = c.indexOf(p);
  839. if (b != 0)
  840. return null;
  841. } else
  842. b += 2;
  843. e = c.indexOf(";", b);
  844. if (e == -1)
  845. e = c.length;
  846. return unescape(c.substring(b + p.length, e));
  847. },
  848. set : function(n, v, e, p, d, s) {
  849. document.cookie = n + "=" + escape(v) +
  850. ((e) ? "; expires=" + e.toGMTString() : "") +
  851. ((p) ? "; path=" + escape(p) : "") +
  852. ((d) ? "; domain=" + d : "") +
  853. ((s) ? "; secure" : "");
  854. },
  855. remove : function(n, p) {
  856. var d = new Date();
  857. d.setTime(d.getTime() - 1000);
  858. this.set(n, '', d, p, d);
  859. }
  860. });
  861. })();
  862. (function() {
  863. function serialize(o, quote) {
  864. var i, v, t;
  865. quote = quote || '"';
  866. if (o == null)
  867. return 'null';
  868. t = typeof o;
  869. if (t == 'string') {
  870. v = '\bb\tt\nn\ff\rr\""\'\'\\\\';
  871. return quote + o.replace(/([\u0080-\uFFFF\x00-\x1f\"\'\\])/g, function(a, b) {
  872. // Make sure single quotes never get encoded inside double quotes for JSON compatibility
  873. if (quote === '"' && a === "'")
  874. return a;
  875. i = v.indexOf(b);
  876. if (i + 1)
  877. return '\\' + v.charAt(i + 1);
  878. a = b.charCodeAt().toString(16);
  879. return '\\u' + '0000'.substring(a.length) + a;
  880. }) + quote;
  881. }
  882. if (t == 'object') {
  883. if (o.hasOwnProperty && o instanceof Array) {
  884. for (i=0, v = '['; i<o.length; i++)
  885. v += (i > 0 ? ',' : '') + serialize(o[i], quote);
  886. return v + ']';
  887. }
  888. v = '{';
  889. for (i in o) {
  890. if (o.hasOwnProperty(i)) {
  891. v += typeof o[i] != 'function' ? (v.length > 1 ? ',' + quote : quote) + i + quote +':' + serialize(o[i], quote) : '';
  892. }
  893. }
  894. return v + '}';
  895. }
  896. return '' + o;
  897. };
  898. tinymce.util.JSON = {
  899. serialize: serialize,
  900. parse: function(s) {
  901. try {
  902. return eval('(' + s + ')');
  903. } catch (ex) {
  904. // Ignore
  905. }
  906. }
  907. };
  908. })();
  909. tinymce.create('static tinymce.util.XHR', {
  910. send : function(o) {
  911. var x, t, w = window, c = 0;
  912. // Default settings
  913. o.scope = o.scope || this;
  914. o.success_scope = o.success_scope || o.scope;
  915. o.error_scope = o.error_scope || o.scope;
  916. o.async = o.async === false ? false : true;
  917. o.data = o.data || '';
  918. function get(s) {
  919. x = 0;
  920. try {
  921. x = new ActiveXObject(s);
  922. } catch (ex) {
  923. }
  924. return x;
  925. };
  926. x = w.XMLHttpRequest ? new XMLHttpRequest() : get('Microsoft.XMLHTTP') || get('Msxml2.XMLHTTP');
  927. if (x) {
  928. if (x.overrideMimeType)
  929. x.overrideMimeType(o.content_type);
  930. x.open(o.type || (o.data ? 'POST' : 'GET'), o.url, o.async);
  931. if (o.content_type)
  932. x.setRequestHeader('Content-Type', o.content_type);
  933. x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  934. x.send(o.data);
  935. function ready() {
  936. if (!o.async || x.readyState == 4 || c++ > 10000) {
  937. if (o.success && c < 10000 && x.status == 200)
  938. o.success.call(o.success_scope, '' + x.responseText, x, o);
  939. else if (o.error)
  940. o.error.call(o.error_scope, c > 10000 ? 'TIMED_OUT' : 'GENERAL', x, o);
  941. x = null;
  942. } else
  943. w.setTimeout(ready, 10);
  944. };
  945. // Syncronous request
  946. if (!o.async)
  947. return ready();
  948. // Wait for response, onReadyStateChange can not be used since it leaks memory in IE
  949. t = w.setTimeout(ready, 10);
  950. }
  951. }
  952. });
  953. (function() {
  954. var extend = tinymce.extend, JSON = tinymce.util.JSON, XHR = tinymce.util.XHR;
  955. tinymce.create('tinymce.util.JSONRequest', {
  956. JSONRequest : function(s) {
  957. this.settings = extend({
  958. }, s);
  959. this.count = 0;
  960. },
  961. send : function(o) {
  962. var ecb = o.error, scb = o.success;
  963. o = extend(this.settings, o);
  964. o.success = function(c, x) {
  965. c = JSON.parse(c);
  966. if (typeof(c) == 'undefined') {
  967. c = {
  968. error : 'JSON Parse error.'
  969. };
  970. }
  971. if (c.error)
  972. ecb.call(o.error_scope || o.scope, c.error, x);
  973. else
  974. scb.call(o.success_scope || o.scope, c.result);
  975. };
  976. o.error = function(ty, x) {
  977. if (ecb)
  978. ecb.call(o.error_scope || o.scope, ty, x);
  979. };
  980. o.data = JSON.serialize({
  981. id : o.id || 'c' + (this.count++),
  982. method : o.method,
  983. params : o.params
  984. });
  985. // JSON content type for Ruby on rails. Bug: #1883287
  986. o.content_type = 'application/json';
  987. XHR.send(o);
  988. },
  989. 'static' : {
  990. sendRPC : function(o) {
  991. return new tinymce.util.JSONRequest().send(o);
  992. }
  993. }
  994. });
  995. }());
  996. (function(tinymce){
  997. tinymce.VK = {
  998. DELETE: 46,
  999. BACKSPACE: 8,
  1000. ENTER: 13,
  1001. TAB: 9,
  1002. SPACEBAR: 32,
  1003. UP: 38,
  1004. DOWN: 40
  1005. }
  1006. })(tinymce);
  1007. (function(tinymce) {
  1008. var VK = tinymce.VK, BACKSPACE = VK.BACKSPACE, DELETE = VK.DELETE;
  1009. function cleanupStylesWhenDeleting(ed) {
  1010. var dom = ed.dom, selection = ed.selection;
  1011. ed.onKeyDown.add(function(ed, e) {
  1012. var rng, blockElm, node, clonedSpan, isDelete;
  1013. isDelete = e.keyCode == DELETE;
  1014. if (isDelete || e.keyCode == BACKSPACE) {
  1015. e.preventDefault();
  1016. rng = selection.getRng();
  1017. // Find root block
  1018. blockElm = dom.getParent(rng.startContainer, dom.isBlock);
  1019. // On delete clone the root span of the next block element
  1020. if (isDelete)
  1021. blockElm = dom.getNext(blockElm, dom.isBlock);
  1022. // Locate root span element and clone it since it would otherwise get merged by the "apple-style-span" on delete/backspace
  1023. if (blockElm) {
  1024. node = blockElm.firstChild;
  1025. // Ignore empty text nodes
  1026. while (node && node.nodeType == 3 && node.nodeValue.length == 0)
  1027. node = node.nextSibling;
  1028. if (node && node.nodeName === 'SPAN') {
  1029. clonedSpan = node.cloneNode(false);
  1030. }
  1031. }
  1032. // Do the backspace/delete actiopn
  1033. ed.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null);
  1034. // Find all odd apple-style-spans
  1035. blockElm = dom.getParent(rng.startContainer, dom.isBlock);
  1036. tinymce.each(dom.select('span.Apple-style-span,font.Apple-style-span', blockElm), function(span) {
  1037. var bm = selection.getBookmark();
  1038. if (clonedSpan) {
  1039. dom.replace(clonedSpan.cloneNode(false), span, true);
  1040. } else {
  1041. dom.remove(span, true);
  1042. }
  1043. // Restore the selection
  1044. selection.moveToBookmark(bm);
  1045. });
  1046. }
  1047. });
  1048. };
  1049. function emptyEditorWhenDeleting(ed) {
  1050. ed.onKeyUp.add(function(ed, e) {
  1051. var keyCode = e.keyCode;
  1052. if (keyCode == DELETE || keyCode == BACKSPACE) {
  1053. if (ed.dom.isEmpty(ed.getBody())) {
  1054. ed.setContent('', {format : 'raw'});
  1055. ed.nodeChanged();
  1056. return;
  1057. }
  1058. }
  1059. });
  1060. };
  1061. function inputMethodFocus(ed) {
  1062. ed.dom.bind(ed.getDoc(), 'focusin', function() {
  1063. ed.selection.setRng(ed.selection.getRng());
  1064. });
  1065. };
  1066. function removeHrOnBackspace(ed) {
  1067. ed.onKeyDown.add(function(ed, e) {
  1068. if (e.keyCode === BACKSPACE) {
  1069. if (ed.selection.isCollapsed() && ed.selection.getRng(true).startOffset === 0) {
  1070. var node = ed.selection.getNode();
  1071. var previousSibling = node.previousSibling;
  1072. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "hr") {
  1073. ed.dom.remove(previousSibling);
  1074. tinymce.dom.Event.cancel(e);
  1075. }
  1076. }
  1077. }
  1078. })
  1079. }
  1080. function focusBody(ed) {
  1081. // Fix for a focus bug in FF 3.x where the body element
  1082. // wouldn't get proper focus if the user clicked on the HTML element
  1083. if (!Range.prototype.getClientRects) { // Detect getClientRects got introduced in FF 4
  1084. ed.onMouseDown.add(function(ed, e) {
  1085. if (e.target.nodeName === "HTML") {
  1086. var body = ed.getBody();
  1087. // Blur the body it's focused but not correctly focused
  1088. body.blur();
  1089. // Refocus the body after a little while
  1090. setTimeout(function() {
  1091. body.focus();
  1092. }, 0);
  1093. }
  1094. });
  1095. }
  1096. };
  1097. function selectControlElements(ed) {
  1098. ed.onClick.add(function(ed, e) {
  1099. e = e.target;
  1100. // Workaround for bug, http://bugs.webkit.org/show_bug.cgi?id=12250
  1101. // WebKit can't even do simple things like selecting an image
  1102. // Needs tobe the setBaseAndExtend or it will fail to select floated images
  1103. if (/^(IMG|HR)$/.test(e.nodeName))
  1104. ed.selection.getSel().setBaseAndExtent(e, 0, e, 1);
  1105. if (e.nodeName == 'A' && ed.dom.hasClass(e, 'mceItemAnchor'))
  1106. ed.selection.select(e);
  1107. ed.nodeChanged();
  1108. });
  1109. };
  1110. function selectionChangeNodeChanged(ed) {
  1111. var lastRng, selectionTimer;
  1112. ed.dom.bind(ed.getDoc(), 'selectionchange', function() {
  1113. if (selectionTimer) {
  1114. clearTimeout(selectionTimer);
  1115. selectionTimer = 0;
  1116. }
  1117. selectionTimer = window.setTimeout(function() {
  1118. var rng = ed.selection.getRng();
  1119. // Compare the ranges to see if it was a real change or not
  1120. if (!lastRng || !tinymce.dom.RangeUtils.compareRanges(rng, lastRng)) {
  1121. ed.nodeChanged();
  1122. lastRng = rng;
  1123. }
  1124. }, 50);
  1125. });
  1126. }
  1127. function ensureBodyHasRoleApplication(ed) {
  1128. document.body.setAttribute("role", "application");
  1129. }
  1130. tinymce.create('tinymce.util.Quirks', {
  1131. Quirks: function(ed) {
  1132. // WebKit
  1133. if (tinymce.isWebKit) {
  1134. cleanupStylesWhenDeleting(ed);
  1135. emptyEditorWhenDeleting(ed);
  1136. inputMethodFocus(ed);
  1137. selectControlElements(ed);
  1138. // iOS
  1139. if (tinymce.isIDevice) {
  1140. selectionChangeNodeChanged(ed);
  1141. }
  1142. }
  1143. // IE
  1144. if (tinymce.isIE) {
  1145. removeHrOnBackspace(ed);
  1146. emptyEditorWhenDeleting(ed);
  1147. ensureBodyHasRoleApplication(ed);
  1148. }
  1149. // Gecko
  1150. if (tinymce.isGecko) {
  1151. removeHrOnBackspace(ed);
  1152. focusBody(ed);
  1153. }
  1154. }
  1155. });
  1156. })(tinymce);
  1157. (function(tinymce) {
  1158. var namedEntities, baseEntities, reverseEntities,
  1159. attrsCharsRegExp = /[&<>\"\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  1160. textCharsRegExp = /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  1161. rawCharsRegExp = /[<>&\"\']/g,
  1162. entityRegExp = /&(#x|#)?([\w]+);/g,
  1163. asciiMap = {
  1164. 128 : "\u20AC", 130 : "\u201A", 131 : "\u0192", 132 : "\u201E", 133 : "\u2026", 134 : "\u2020",
  1165. 135 : "\u2021", 136 : "\u02C6", 137 : "\u2030", 138 : "\u0160", 139 : "\u2039", 140 : "\u0152",
  1166. 142 : "\u017D", 145 : "\u2018", 146 : "\u2019", 147 : "\u201C", 148 : "\u201D", 149 : "\u2022",
  1167. 150 : "\u2013", 151 : "\u2014", 152 : "\u02DC", 153 : "\u2122", 154 : "\u0161", 155 : "\u203A",
  1168. 156 : "\u0153", 158 : "\u017E", 159 : "\u0178"
  1169. };
  1170. // Raw entities
  1171. baseEntities = {
  1172. '\"' : '&quot;', // Needs to be escaped since the YUI compressor would otherwise break the code
  1173. "'" : '&#39;',
  1174. '<' : '&lt;',
  1175. '>' : '&gt;',
  1176. '&' : '&amp;'
  1177. };
  1178. // Reverse lookup table for raw entities
  1179. reverseEntities = {
  1180. '&lt;' : '<',
  1181. '&gt;' : '>',
  1182. '&amp;' : '&',
  1183. '&quot;' : '"',
  1184. '&apos;' : "'"
  1185. };
  1186. // Decodes text by using the browser
  1187. function nativeDecode(text) {
  1188. var elm;
  1189. elm = document.createElement("div");
  1190. elm.innerHTML = text;
  1191. return elm.textContent || elm.innerText || text;
  1192. };
  1193. // Build a two way lookup table for the entities
  1194. function buildEntitiesLookup(items, radix) {
  1195. var i, chr, entity, lookup = {};
  1196. if (items) {
  1197. items = items.split(',');
  1198. radix = radix || 10;
  1199. // Build entities lookup table
  1200. for (i = 0; i < items.length; i += 2) {
  1201. chr = String.fromCharCode(parseInt(items[i], radix));
  1202. // Only add non base entities
  1203. if (!baseEntities[chr]) {
  1204. entity = '&' + items[i + 1] + ';';
  1205. lookup[chr] = entity;
  1206. lookup[entity] = chr;
  1207. }
  1208. }
  1209. return lookup;
  1210. }
  1211. };
  1212. // Unpack entities lookup where the numbers are in radix 32 to reduce the size
  1213. namedEntities = buildEntitiesLookup(
  1214. '50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' +
  1215. '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' +
  1216. '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' +
  1217. '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' +
  1218. '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' +
  1219. '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' +
  1220. '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' +
  1221. '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' +
  1222. '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' +
  1223. '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' +
  1224. 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' +
  1225. 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' +
  1226. 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' +
  1227. 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' +
  1228. 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' +
  1229. '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' +
  1230. '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' +
  1231. '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' +
  1232. '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' +
  1233. '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' +
  1234. 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' +
  1235. 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' +
  1236. 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' +
  1237. '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' +
  1238. '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro'
  1239. , 32);
  1240. tinymce.html = tinymce.html || {};
  1241. tinymce.html.Entities = {
  1242. encodeRaw : function(text, attr) {
  1243. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1244. return baseEntities[chr] || chr;
  1245. });
  1246. },
  1247. encodeAllRaw : function(text) {
  1248. return ('' + text).replace(rawCharsRegExp, function(chr) {
  1249. return baseEntities[chr] || chr;
  1250. });
  1251. },
  1252. encodeNumeric : function(text, attr) {
  1253. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1254. // Multi byte sequence convert it to a single entity
  1255. if (chr.length > 1)
  1256. return '&#' + (((chr.charCodeAt(0) - 0xD800) * 0x400) + (chr.charCodeAt(1) - 0xDC00) + 0x10000) + ';';
  1257. return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
  1258. });
  1259. },
  1260. encodeNamed : function(text, attr, entities) {
  1261. entities = entities || namedEntities;
  1262. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1263. return baseEntities[chr] || entities[chr] || chr;
  1264. });
  1265. },
  1266. getEncodeFunc : function(name, entities) {
  1267. var Entities = tinymce.html.Entities;
  1268. entities = buildEntitiesLookup(entities) || namedEntities;
  1269. function encodeNamedAndNumeric(text, attr) {
  1270. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1271. return baseEntities[chr] || entities[chr] || '&#' + chr.charCodeAt(0) + ';' || chr;
  1272. });
  1273. };
  1274. function encodeCustomNamed(text, attr) {
  1275. return Entities.encodeNamed(text, attr, entities);
  1276. };
  1277. // Replace + with , to be compatible with previous TinyMCE versions
  1278. name = tinymce.makeMap(name.replace(/\+/g, ','));
  1279. // Named and numeric encoder
  1280. if (name.named && name.numeric)
  1281. return encodeNamedAndNumeric;
  1282. // Named encoder
  1283. if (name.named) {
  1284. // Custom names
  1285. if (entities)
  1286. return encodeCustomNamed;
  1287. return Entities.encodeNamed;
  1288. }
  1289. // Numeric
  1290. if (name.numeric)
  1291. return Entities.encodeNumeric;
  1292. // Raw encoder
  1293. return Entities.encodeRaw;
  1294. },
  1295. decode : function(text) {
  1296. return text.replace(entityRegExp, function(all, numeric, value) {
  1297. if (numeric) {
  1298. value = parseInt(value, numeric.length === 2 ? 16 : 10);
  1299. // Support upper UTF
  1300. if (value > 0xFFFF) {
  1301. value -= 0x10000;
  1302. return String.fromCharCode(0xD800 + (value >> 10), 0xDC00 + (value & 0x3FF));
  1303. } else
  1304. return asciiMap[value] || String.fromCharCode(value);
  1305. }
  1306. return reverseEntities[all] || namedEntities[all] || nativeDecode(all);
  1307. });
  1308. }
  1309. };
  1310. })(tinymce);
  1311. tinymce.html.Styles = function(settings, schema) {
  1312. var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi,
  1313. urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi,
  1314. styleRegExp = /\s*([^:]+):\s*([^;]+);?/g,
  1315. trimRightRegExp = /\s+$/,
  1316. urlColorRegExp = /rgb/,
  1317. undef, i, encodingLookup = {}, encodingItems;
  1318. settings = settings || {};
  1319. encodingItems = '\\" \\\' \\; \\: ; : \uFEFF'.split(' ');
  1320. for (i = 0; i < encodingItems.length; i++) {
  1321. encodingLookup[encodingItems[i]] = '\uFEFF' + i;
  1322. encodingLookup['\uFEFF' + i] = encodingItems[i];
  1323. }
  1324. function toHex(match, r, g, b) {
  1325. function hex(val) {
  1326. val = parseInt(val).toString(16);
  1327. return val.length > 1 ? val : '0' + val; // 0 -> 00
  1328. };
  1329. return '#' + hex(r) + hex(g) + hex(b);
  1330. };
  1331. return {
  1332. toHex : function(color) {
  1333. return color.replace(rgbRegExp, toHex);
  1334. },
  1335. parse : function(css) {
  1336. var styles = {}, matches, name, value, isEncoded, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope || this;
  1337. function compress(prefix, suffix) {
  1338. var top, right, bottom, left;
  1339. // Get values and check it it needs compressing
  1340. top = styles[prefix + '-top' + suffix];
  1341. if (!top)
  1342. return;
  1343. right = styles[prefix + '-right' + suffix];
  1344. if (top != right)
  1345. return;
  1346. bottom = styles[prefix + '-bottom' + suffix];
  1347. if (right != bottom)
  1348. return;
  1349. left = styles[prefix + '-left' + suffix];
  1350. if (bottom != left)
  1351. return;
  1352. // Compress
  1353. styles[prefix + suffix] = left;
  1354. delete styles[prefix + '-top' + suffix];
  1355. delete styles[prefix + '-right' + suffix];
  1356. delete styles[prefix + '-bottom' + suffix];
  1357. delete styles[prefix + '-left' + suffix];
  1358. };
  1359. function canCompress(key) {
  1360. var value = styles[key], i;
  1361. if (!value || value.indexOf(' ') < 0)
  1362. return;
  1363. value = value.split(' ');
  1364. i = value.length;
  1365. while (i--) {
  1366. if (value[i] !== value[0])
  1367. return false;
  1368. }
  1369. styles[key] = value[0];
  1370. return true;
  1371. };
  1372. function compress2(target, a, b, c) {
  1373. if (!canCompress(a))
  1374. return;
  1375. if (!canCompress(b))
  1376. return;
  1377. if (!canCompress(c))
  1378. return;
  1379. // Compress
  1380. styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
  1381. delete styles[a];
  1382. delete styles[b];
  1383. delete styles[c];
  1384. };
  1385. // Encodes the specified string by replacing all \" \' ; : with _<num>
  1386. function encode(str) {
  1387. isEncoded = true;
  1388. return encodingLookup[str];
  1389. };
  1390. // Decodes the specified string by replacing all _<num> with it's original value \" \' etc
  1391. // It will also decode the \" \' if keep_slashes is set to fale or omitted
  1392. function decode(str, keep_slashes) {
  1393. if (isEncoded) {
  1394. str = str.replace(/\uFEFF[0-9]/g, function(str) {
  1395. return encodingLookup[str];
  1396. });
  1397. }
  1398. if (!keep_slashes)
  1399. str = str.replace(/\\([\'\";:])/g, "$1");
  1400. return str;
  1401. }
  1402. if (css) {
  1403. // Encode \" \' % and ; and : inside strings so they don't interfere with the style parsing
  1404. css = css.replace(/\\[\"\';:\uFEFF]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, function(str) {
  1405. return str.replace(/[;:]/g, encode);
  1406. });
  1407. // Parse styles
  1408. while (matches = styleRegExp.exec(css)) {
  1409. name = matches[1].replace(trimRightRegExp, '').toLowerCase();
  1410. value = matches[2].replace(trimRightRegExp, '');
  1411. if (name && value.length > 0) {
  1412. // Opera will produce 700 instead of bold in their style values
  1413. if (name === 'font-weight' && value === '700')
  1414. value = 'bold';
  1415. else if (name === 'color' || name === 'background-color') // Lowercase colors like RED
  1416. value = value.toLowerCase();
  1417. // Convert RGB colors to HEX
  1418. value = value.replace(rgbRegExp, toHex);
  1419. // Convert URLs and force them into url('value') format
  1420. value = value.replace(urlOrStrRegExp, function(match, url, url2, url3, str, str2) {
  1421. str = str || str2;
  1422. if (str) {
  1423. str = decode(str);
  1424. // Force strings into single quote format
  1425. return "'" + str.replace(/\'/g, "\\'") + "'";
  1426. }
  1427. url = decode(url || url2 || url3);
  1428. // Convert the URL to relative/absolute depending on config
  1429. if (urlConverter)
  1430. url = urlConverter.call(urlConverterScope, url, 'style');
  1431. // Output new URL format
  1432. return "url('" + url.replace(/\'/g, "\\'") + "')";
  1433. });
  1434. styles[name] = isEncoded ? decode(value, true) : value;
  1435. }
  1436. styleRegExp.lastIndex = matches.index + matches[0].length;
  1437. }
  1438. // Compress the styles to reduce it's size for example IE will expand styles
  1439. compress("border", "");
  1440. compress("border", "-width");
  1441. compress("border", "-color");
  1442. compress("border", "-style");
  1443. compress("padding", "");
  1444. compress("margin", "");
  1445. compress2('border', 'border-width', 'border-style', 'border-color');
  1446. // Remove pointless border, IE produces these
  1447. if (styles.border === 'medium none')
  1448. delete styles.border;
  1449. }
  1450. return styles;
  1451. },
  1452. serialize : function(styles, element_name) {
  1453. var css = '', name, value;
  1454. function serializeStyles(name) {
  1455. var styleList, i, l, value;
  1456. styleList = schema.styles[name];
  1457. if (styleList) {
  1458. for (i = 0, l = styleList.length; i < l; i++) {
  1459. name = styleList[i];
  1460. value = styles[name];
  1461. if (value !== undef && value.length > 0)
  1462. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  1463. }
  1464. }
  1465. };
  1466. // Serialize styles according to schema
  1467. if (element_name && schema && schema.styles) {
  1468. // Serialize global styles and element specific styles
  1469. serializeStyles('*');
  1470. serializeStyles(element_name);
  1471. } else {
  1472. // Output the styles in the order they are inside the object
  1473. for (name in styles) {
  1474. value = styles[name];
  1475. if (value !== undef && value.length > 0)
  1476. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  1477. }
  1478. }
  1479. return css;
  1480. }
  1481. };
  1482. };
  1483. (function(tinymce) {
  1484. var transitional = {}, boolAttrMap, blockElementsMap, shortEndedElementsMap, nonEmptyElementsMap, customElementsMap = {},
  1485. defaultWhiteSpaceElementsMap, selfClosingElementsMap, makeMap = tinymce.makeMap, each = tinymce.each;
  1486. function split(str, delim) {
  1487. return str.split(delim || ',');
  1488. };
  1489. function unpack(lookup, data) {
  1490. var key, elements = {};
  1491. function replace(value) {
  1492. return value.replace(/[A-Z]+/g, function(key) {
  1493. return replace(lookup[key]);
  1494. });
  1495. };
  1496. // Unpack lookup
  1497. for (key in lookup) {
  1498. if (lookup.hasOwnProperty(key))
  1499. lookup[key] = replace(lookup[key]);
  1500. }
  1501. // Unpack and parse data into object map
  1502. replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]\[([^\]]*)\]/g, function(str, name, attributes, children) {
  1503. attributes = split(attributes, '|');
  1504. elements[name] = {
  1505. attributes : makeMap(attributes),
  1506. attributesOrder : attributes,
  1507. children : makeMap(children, '|', {'#comment' : {}})
  1508. }
  1509. });
  1510. return elements;
  1511. };
  1512. // Build a lookup table for block elements both lowercase and uppercase
  1513. blockElementsMap = 'h1,h2,h3,h4,h5,h6,hr,p,div,address,pre,form,table,tbody,thead,tfoot,' +
  1514. 'th,tr,td,li,ol,ul,caption,blockquote,center,dl,dt,dd,dir,fieldset,' +
  1515. 'noscript,menu,isindex,samp,header,footer,article,section,hgroup';
  1516. blockElementsMap = makeMap(blockElementsMap, ',', makeMap(blockElementsMap.toUpperCase()));
  1517. // This is the XHTML 1.0 transitional elements with it's attributes and children packed to reduce it's size
  1518. transitional = unpack({
  1519. Z : 'H|K|N|O|P',
  1520. Y : 'X|form|R|Q',
  1521. ZG : 'E|span|width|align|char|charoff|valign',
  1522. X : 'p|T|div|U|W|isindex|fieldset|table',
  1523. ZF : 'E|align|char|charoff|valign',
  1524. W : 'pre|hr|blockquote|address|center|noframes',
  1525. ZE : 'abbr|axis|headers|scope|rowspan|colspan|align|char|charoff|valign|nowrap|bgcolor|width|height',
  1526. ZD : '[E][S]',
  1527. U : 'ul|ol|dl|menu|dir',
  1528. ZC : 'p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q',
  1529. T : 'h1|h2|h3|h4|h5|h6',
  1530. ZB : 'X|S|Q',
  1531. S : 'R|P',
  1532. ZA : 'a|G|J|M|O|P',
  1533. R : 'a|H|K|N|O',
  1534. Q : 'noscript|P',
  1535. P : 'ins|del|script',
  1536. O : 'input|select|textarea|label|button',
  1537. N : 'M|L',
  1538. M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym',
  1539. L : 'sub|sup',
  1540. K : 'J|I',
  1541. J : 'tt|i|b|u|s|strike',
  1542. I : 'big|small|font|basefont',
  1543. H : 'G|F',
  1544. G : 'br|span|bdo',
  1545. F : 'object|applet|img|map|iframe',
  1546. E : 'A|B|C',
  1547. D : 'accesskey|tabindex|onfocus|onblur',
  1548. C : 'onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
  1549. B : 'lang|xml:lang|dir',
  1550. A : 'id|class|style|title'
  1551. }, 'script[id|charset|type|language|src|defer|xml:space][]' +
  1552. 'style[B|id|type|media|title|xml:space][]' +
  1553. 'object[E|declare|classid|codebase|data|type|codetype|archive|standby|width|height|usemap|name|tabindex|align|border|hspace|vspace][#|param|Y]' +
  1554. 'param[id|name|value|valuetype|type][]' +
  1555. 'p[E|align][#|S]' +
  1556. 'a[E|D|charset|type|name|href|hreflang|rel|rev|shape|coords|target][#|Z]' +
  1557. 'br[A|clear][]' +
  1558. 'span[E][#|S]' +
  1559. 'bdo[A|C|B][#|S]' +
  1560. 'applet[A|codebase|archive|code|object|alt|name|width|height|align|hspace|vspace][#|param|Y]' +
  1561. 'h1[E|align][#|S]' +
  1562. 'img[E|src|alt|name|longdesc|width|height|usemap|ismap|align|border|hspace|vspace][]' +
  1563. 'map[B|C|A|name][X|form|Q|area]' +
  1564. 'h2[E|align][#|S]' +
  1565. 'iframe[A|longdesc|name|src|frameborder|marginwidth|marginheight|scrolling|align|width|height][#|Y]' +
  1566. 'h3[E|align][#|S]' +
  1567. 'tt[E][#|S]' +
  1568. 'i[E][#|S]' +
  1569. 'b[E][#|S]' +
  1570. 'u[E][#|S]' +
  1571. 's[E][#|S]' +
  1572. 'strike[E][#|S]' +
  1573. 'big[E][#|S]' +
  1574. 'small[E][#|S]' +
  1575. 'font[A|B|size|color|face][#|S]' +
  1576. 'basefont[id|size|color|face][]' +
  1577. 'em[E][#|S]' +
  1578. 'strong[E][#|S]' +
  1579. 'dfn[E][#|S]' +
  1580. 'code[E][#|S]' +
  1581. 'q[E|cite][#|S]' +
  1582. 'samp[E][#|S]' +
  1583. 'kbd[E][#|S]' +
  1584. 'var[E][#|S]' +
  1585. 'cite[E][#|S]' +
  1586. 'abbr[E][#|S]' +
  1587. 'acronym[E][#|S]' +
  1588. 'sub[E][#|S]' +
  1589. 'sup[E][#|S]' +
  1590. 'input[E|D|type|name|value|checked|disabled|readonly|size|maxlength|src|alt|usemap|onselect|onchange|accept|align][]' +
  1591. 'select[E|name|size|multiple|disabled|tabindex|onfocus|onblur|onchange][optgroup|option]' +
  1592. 'optgroup[E|disabled|label][option]' +
  1593. 'option[E|selected|disabled|label|value][]' +
  1594. 'textarea[E|D|name|rows|cols|disabled|readonly|onselect|onchange][]' +
  1595. 'label[E|for|accesskey|onfocus|onblur][#|S]' +
  1596. 'button[E|D|name|value|type|disabled][#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' +
  1597. 'h4[E|align][#|S]' +
  1598. 'ins[E|cite|datetime][#|Y]' +
  1599. 'h5[E|align][#|S]' +
  1600. 'del[E|cite|datetime][#|Y]' +
  1601. 'h6[E|align][#|S]' +
  1602. 'div[E|align][#|Y]' +
  1603. 'ul[E|type|compact][li]' +
  1604. 'li[E|type|value][#|Y]' +
  1605. 'ol[E|type|compact|start][li]' +
  1606. 'dl[E|compact][dt|dd]' +
  1607. 'dt[E][#|S]' +
  1608. 'dd[E][#|Y]' +
  1609. 'menu[E|compact][li]' +
  1610. 'dir[E|compact][li]' +
  1611. 'pre[E|width|xml:space][#|ZA]' +
  1612. 'hr[E|align|noshade|size|width][]' +
  1613. 'blockquote[E|cite][#|Y]' +
  1614. 'address[E][#|S|p]' +
  1615. 'center[E][#|Y]' +
  1616. 'noframes[E][#|Y]' +
  1617. 'isindex[A|B|prompt][]' +
  1618. 'fieldset[E][#|legend|Y]' +
  1619. 'legend[E|accesskey|align][#|S]' +
  1620. 'table[E|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor][caption|col|colgroup|thead|tfoot|tbody|tr]' +
  1621. 'caption[E|align][#|S]' +
  1622. 'col[ZG][]' +
  1623. 'colgroup[ZG][col]' +
  1624. 'thead[ZF][tr]' +
  1625. 'tr[ZF|bgcolor][th|td]' +
  1626. 'th[E|ZE][#|Y]' +
  1627. 'form[E|action|method|name|enctype|onsubmit|onreset|accept|accept-charset|target][#|X|R|Q]' +
  1628. 'noscript[E][#|Y]' +
  1629. 'td[E|ZE][#|Y]' +
  1630. 'tfoot[ZF][tr]' +
  1631. 'tbody[ZF][tr]' +
  1632. 'area[E|D|shape|coords|href|nohref|alt|target][]' +
  1633. 'base[id|href|target][]' +
  1634. 'body[E|onload|onunload|background|bgcolor|text|link|vlink|alink][#|Y]'
  1635. );
  1636. boolAttrMap = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected,autoplay,loop,controls');
  1637. shortEndedElementsMap = makeMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed,source');
  1638. nonEmptyElementsMap = tinymce.extend(makeMap('td,th,iframe,video,audio,object'), shortEndedElementsMap);
  1639. defaultWhiteSpaceElementsMap = makeMap('pre,script,style,textarea');
  1640. selfClosingElementsMap = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr');
  1641. tinymce.html.Schema = function(settings) {
  1642. var self = this, elements = {}, children = {}, patternElements = [], validStyles, whiteSpaceElementsMap;
  1643. settings = settings || {};
  1644. // Allow all elements and attributes if verify_html is set to false
  1645. if (settings.verify_html === false)
  1646. settings.valid_elements = '*[*]';
  1647. // Build styles list
  1648. if (settings.valid_styles) {
  1649. validStyles = {};
  1650. // Convert styles into a rule list
  1651. each(settings.valid_styles, function(value, key) {
  1652. validStyles[key] = tinymce.explode(value);
  1653. });
  1654. }
  1655. whiteSpaceElementsMap = settings.whitespace_elements ? makeMap(settings.whitespace_elements) : defaultWhiteSpaceElementsMap;
  1656. // Converts a wildcard expression string to a regexp for example *a will become /.*a/.
  1657. function patternToRegExp(str) {
  1658. return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$');
  1659. };
  1660. // Parses the specified valid_elements string and adds to the current rules
  1661. // This function is a bit hard to read since it's heavily optimized for speed
  1662. function addValidElements(valid_elements) {
  1663. var ei, el, ai, al, yl, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder,
  1664. prefix, outputName, globalAttributes, globalAttributesOrder, transElement, key, childKey, value,
  1665. elementRuleRegExp = /^([#+-])?([^\[\/]+)(?:\/([^\[]+))?(?:\[([^\]]+)\])?$/,
  1666. attrRuleRegExp = /^([!\-])?(\w+::\w+|[^=:<]+)?(?:([=:<])(.*))?$/,
  1667. hasPatternsRegExp = /[*?+]/;
  1668. if (valid_elements) {
  1669. // Split valid elements into an array with rules
  1670. valid_elements = split(valid_elements);
  1671. if (elements['@']) {
  1672. globalAttributes = elements['@'].attributes;
  1673. globalAttributesOrder = elements['@'].attributesOrder;
  1674. }
  1675. // Loop all rules
  1676. for (ei = 0, el = valid_elements.length; ei < el; ei++) {
  1677. // Parse element rule
  1678. matches = elementRuleRegExp.exec(valid_elements[ei]);
  1679. if (matches) {
  1680. // Setup local names for matches
  1681. prefix = matches[1];
  1682. elementName = matches[2];
  1683. outputName = matches[3];
  1684. attrData = matches[4];
  1685. // Create new attributes and attributesOrder
  1686. attributes = {};
  1687. attributesOrder = [];
  1688. // Create the new element
  1689. element = {
  1690. attributes : attributes,
  1691. attributesOrder : attributesOrder
  1692. };
  1693. // Padd empty elements prefix
  1694. if (prefix === '#')
  1695. element.paddEmpty = true;
  1696. // Remove empty elements prefix
  1697. if (prefix === '-')
  1698. element.removeEmpty = true;
  1699. // Copy attributes from global rule into current rule
  1700. if (globalAttributes) {
  1701. for (key in globalAttributes)
  1702. attributes[key] = globalAttributes[key];
  1703. attributesOrder.push.apply(attributesOrder, globalAttributesOrder);
  1704. }
  1705. // Attributes defined
  1706. if (attrData) {
  1707. attrData = split(attrData, '|');
  1708. for (ai = 0, al = attrData.length; ai < al; ai++) {
  1709. matches = attrRuleRegExp.exec(attrData[ai]);
  1710. if (matches) {
  1711. attr = {};
  1712. attrType = matches[1];
  1713. attrName = matches[2].replace(/::/g, ':');
  1714. prefix = matches[3];
  1715. value = matches[4];
  1716. // Required
  1717. if (attrType === '!') {
  1718. element.attributesRequired = element.attributesRequired || [];
  1719. element.attributesRequired.push(attrName);
  1720. attr.required = true;
  1721. }
  1722. // Denied from global
  1723. if (attrType === '-') {
  1724. delete attributes[attrName];
  1725. attributesOrder.splice(tinymce.inArray(attributesOrder, attrName), 1);
  1726. continue;
  1727. }
  1728. // Default value
  1729. if (prefix) {
  1730. // Default value
  1731. if (prefix === '=') {
  1732. element.attributesDefault = element.attributesDefault || [];
  1733. element.attributesDefault.push({name: attrName, value: value});
  1734. attr.defaultValue = value;
  1735. }
  1736. // Forced value
  1737. if (prefix === ':') {
  1738. element.attributesForced = element.attributesForced || [];
  1739. element.attributesForced.push({name: attrName, value: value});
  1740. attr.forcedValue = value;
  1741. }
  1742. // Required values
  1743. if (prefix === '<')
  1744. attr.validValues = makeMap(value, '?');
  1745. }
  1746. // Check for attribute patterns
  1747. if (hasPatternsRegExp.test(attrName)) {
  1748. element.attributePatterns = element.attributePatterns || [];
  1749. attr.pattern = patternToRegExp(attrName);
  1750. element.attributePatterns.push(attr);
  1751. } else {
  1752. // Add attribute to order list if it doesn't already exist
  1753. if (!attributes[attrName])
  1754. attributesOrder.push(attrName);
  1755. attributes[attrName] = attr;
  1756. }
  1757. }
  1758. }
  1759. }
  1760. // Global rule, store away these for later usage
  1761. if (!globalAttributes && elementName == '@') {
  1762. globalAttributes = attributes;
  1763. globalAttributesOrder = attributesOrder;
  1764. }
  1765. // Handle substitute elements such as b/strong
  1766. if (outputName) {
  1767. element.outputName = elementName;
  1768. elements[outputName] = element;
  1769. }
  1770. // Add pattern or exact element
  1771. if (hasPatternsRegExp.test(elementName)) {
  1772. element.pattern = patternToRegExp(elementName);
  1773. patternElements.push(element);
  1774. } else
  1775. elements[elementName] = element;
  1776. }
  1777. }
  1778. }
  1779. };
  1780. function setValidElements(valid_elements) {
  1781. elements = {};
  1782. patternElements = [];
  1783. addValidElements(valid_elements);
  1784. each(transitional, function(element, name) {
  1785. children[name] = element.children;
  1786. });
  1787. };
  1788. // Adds custom non HTML elements to the schema
  1789. function addCustomElements(custom_elements) {
  1790. var customElementRegExp = /^(~)?(.+)$/;
  1791. if (custom_elements) {
  1792. each(split(custom_elements), function(rule) {
  1793. var matches = customElementRegExp.exec(rule),
  1794. inline = matches[1] === '~',
  1795. cloneName = inline ? 'span' : 'div',
  1796. name = matches[2];
  1797. children[name] = children[cloneName];
  1798. customElementsMap[name] = cloneName;
  1799. // If it's not marked as inline then add it to valid block elements
  1800. if (!inline)
  1801. blockElementsMap[name] = {};
  1802. // Add custom elements at span/div positions
  1803. each(children, function(element, child) {
  1804. if (element[cloneName])
  1805. element[name] = element[cloneName];
  1806. });
  1807. });
  1808. }
  1809. };
  1810. // Adds valid children to the schema object
  1811. function addValidChildren(valid_children) {
  1812. var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/;
  1813. if (valid_children) {
  1814. each(split(valid_children), function(rule) {
  1815. var matches = childRuleRegExp.exec(rule), parent, prefix;
  1816. if (matches) {
  1817. prefix = matches[1];
  1818. // Add/remove items from default
  1819. if (prefix)
  1820. parent = children[matches[2]];
  1821. else
  1822. parent = children[matches[2]] = {'#comment' : {}};
  1823. parent = children[matches[2]];
  1824. each(split(matches[3], '|'), function(child) {
  1825. if (prefix === '-')
  1826. delete parent[child];
  1827. else
  1828. parent[child] = {};
  1829. });
  1830. }
  1831. });
  1832. }
  1833. };
  1834. function getElementRule(name) {
  1835. var element = elements[name], i;
  1836. // Exact match found
  1837. if (element)
  1838. return element;
  1839. // No exact match then try the patterns
  1840. i = patternElements.length;
  1841. while (i--) {
  1842. element = patternElements[i];
  1843. if (element.pattern.test(name))
  1844. return element;
  1845. }
  1846. };
  1847. if (!settings.valid_elements) {
  1848. // No valid elements defined then clone the elements from the transitional spec
  1849. each(transitional, function(element, name) {
  1850. elements[name] = {
  1851. attributes : element.attributes,
  1852. attributesOrder : element.attributesOrder
  1853. };
  1854. children[name] = element.children;
  1855. });
  1856. // Switch these
  1857. each(split('strong/b,em/i'), function(item) {
  1858. item = split(item, '/');
  1859. elements[item[1]].outputName = item[0];
  1860. });
  1861. // Add default alt attribute for images
  1862. elements.img.attributesDefault = [{name: 'alt', value: ''}];
  1863. // Remove these if they are empty by default
  1864. each(split('ol,ul,sub,sup,blockquote,span,font,a,table,tbody,tr'), function(name) {
  1865. elements[name].removeEmpty = true;
  1866. });
  1867. // Padd these by default
  1868. each(split('p,h1,h2,h3,h4,h5,h6,th,td,pre,div,address,caption'), function(name) {
  1869. elements[name].paddEmpty = true;
  1870. });
  1871. } else
  1872. setValidElements(settings.valid_elements);
  1873. addCustomElements(settings.custom_elements);
  1874. addValidChildren(settings.valid_children);
  1875. addValidElements(settings.extended_valid_elements);
  1876. // Todo: Remove this when we fix list handling to be valid
  1877. addValidChildren('+ol[ul|ol],+ul[ul|ol]');
  1878. // If the user didn't allow span only allow internal spans
  1879. if (!getElementRule('span'))
  1880. addValidElements('span[!data-mce-type|*]');
  1881. // Delete invalid elements
  1882. if (settings.invalid_elements) {
  1883. tinymce.each(tinymce.explode(settings.invalid_elements), function(item) {
  1884. if (elements[item])
  1885. delete elements[item];
  1886. });
  1887. }
  1888. self.children = children;
  1889. self.styles = validStyles;
  1890. self.getBoolAttrs = function() {
  1891. return boolAttrMap;
  1892. };
  1893. self.getBlockElements = function() {
  1894. return blockElementsMap;
  1895. };
  1896. self.getShortEndedElements = function() {
  1897. return shortEndedElementsMap;
  1898. };
  1899. self.getSelfClosingElements = function() {
  1900. return selfClosingElementsMap;
  1901. };
  1902. self.getNonEmptyElements = function() {
  1903. return nonEmptyElementsMap;
  1904. };
  1905. self.getWhiteSpaceElements = function() {
  1906. return whiteSpaceElementsMap;
  1907. };
  1908. self.isValidChild = function(name, child) {
  1909. var parent = children[name];
  1910. return !!(parent && parent[child]);
  1911. };
  1912. self.getElementRule = getElementRule;
  1913. self.getCustomElements = function() {
  1914. return customElementsMap;
  1915. };
  1916. self.addValidElements = addValidElements;
  1917. self.setValidElements = setValidElements;
  1918. self.addCustomElements = addCustomElements;
  1919. self.addValidChildren = addValidChildren;
  1920. };
  1921. // Expose boolMap and blockElementMap as static properties for usage in DOMUtils
  1922. tinymce.html.Schema.boolAttrMap = boolAttrMap;
  1923. tinymce.html.Schema.blockElementsMap = blockElementsMap;
  1924. })(tinymce);
  1925. (function(tinymce) {
  1926. tinymce.html.SaxParser = function(settings, schema) {
  1927. var self = this, noop = function() {};
  1928. settings = settings || {};
  1929. self.schema = schema = schema || new tinymce.html.Schema();
  1930. if (settings.fix_self_closing !== false)
  1931. settings.fix_self_closing = true;
  1932. // Add handler functions from settings and setup default handlers
  1933. tinymce.each('comment cdata text start end pi doctype'.split(' '), function(name) {
  1934. if (name)
  1935. self[name] = settings[name] || noop;
  1936. });
  1937. self.parse = function(html) {
  1938. var self = this, matches, index = 0, value, endRegExp, stack = [], attrList, i, text, name, isInternalElement, removeInternalElements,
  1939. shortEndedElements, fillAttrsMap, isShortEnded, validate, elementRule, isValidElement, attr, attribsValue, invalidPrefixRegExp,
  1940. validAttributesMap, validAttributePatterns, attributesRequired, attributesDefault, attributesForced, selfClosing,
  1941. tokenRegExp, attrRegExp, specialElements, attrValue, idCount = 0, decode = tinymce.html.Entities.decode, fixSelfClosing, isIE;
  1942. function processEndTag(name) {
  1943. var pos, i;
  1944. // Find position of parent of the same type
  1945. pos = stack.length;
  1946. while (pos--) {
  1947. if (stack[pos].name === name)
  1948. break;
  1949. }
  1950. // Found parent
  1951. if (pos >= 0) {
  1952. // Close all the open elements
  1953. for (i = stack.length - 1; i >= pos; i--) {
  1954. name = stack[i];
  1955. if (name.valid)
  1956. self.end(name.name);
  1957. }
  1958. // Remove the open elements from the stack
  1959. stack.length = pos;
  1960. }
  1961. };
  1962. // Precompile RegExps and map objects
  1963. tokenRegExp = new RegExp('<(?:' +
  1964. '(?:!--([\\w\\W]*?)-->)|' + // Comment
  1965. '(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|' + // CDATA
  1966. '(?:!DOCTYPE([\\w\\W]*?)>)|' + // DOCTYPE
  1967. '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' + // PI
  1968. '(?:\\/([^>]+)>)|' + // End element
  1969. '(?:([^\\s\\/<>]+)((?:\\s+[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*|\\/)>)' + // Start element
  1970. ')', 'g');
  1971. attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:\\.|[^\"])*)\")|(?:\'((?:\\.|[^\'])*)\')|([^>\s]+)))?/g;
  1972. specialElements = {
  1973. 'script' : /<\/script[^>]*>/gi,
  1974. 'style' : /<\/style[^>]*>/gi,
  1975. 'noscript' : /<\/noscript[^>]*>/gi
  1976. };
  1977. // Setup lookup tables for empty elements and boolean attributes
  1978. shortEndedElements = schema.getShortEndedElements();
  1979. selfClosing = schema.getSelfClosingElements();
  1980. fillAttrsMap = schema.getBoolAttrs();
  1981. validate = settings.validate;
  1982. removeInternalElements = settings.remove_internals;
  1983. fixSelfClosing = settings.fix_self_closing;
  1984. isIE = tinymce.isIE;
  1985. invalidPrefixRegExp = /^:/;
  1986. while (matches = tokenRegExp.exec(html)) {
  1987. // Text
  1988. if (index < matches.index)
  1989. self.text(decode(html.substr(index, matches.index - index)));
  1990. if (value = matches[6]) { // End element
  1991. value = value.toLowerCase();
  1992. // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
  1993. if (isIE && invalidPrefixRegExp.test(value))
  1994. value = value.substr(1);
  1995. processEndTag(value);
  1996. } else if (value = matches[7]) { // Start element
  1997. value = value.toLowerCase();
  1998. // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
  1999. if (isIE && invalidPrefixRegExp.test(value))
  2000. value = value.substr(1);
  2001. isShortEnded = value in shortEndedElements;
  2002. // Is self closing tag for example an <li> after an open <li>
  2003. if (fixSelfClosing && selfClosing[value] && stack.length > 0 && stack[stack.length - 1].name === value)
  2004. processEndTag(value);
  2005. // Validate element
  2006. if (!validate || (elementRule = schema.getElementRule(value))) {
  2007. isValidElement = true;
  2008. // Grab attributes map and patters when validation is enabled
  2009. if (validate) {
  2010. validAttributesMap = elementRule.attributes;
  2011. validAttributePatterns = elementRule.attributePatterns;
  2012. }
  2013. // Parse attributes
  2014. if (attribsValue = matches[8]) {
  2015. isInternalElement = attribsValue.indexOf('data-mce-type') !== -1; // Check if the element is an internal element
  2016. // If the element has internal attributes then remove it if we are told to do so
  2017. if (isInternalElement && removeInternalElements)
  2018. isValidElement = false;
  2019. attrList = [];
  2020. attrList.map = {};
  2021. attribsValue.replace(attrRegExp, function(match, name, value, val2, val3) {
  2022. var attrRule, i;
  2023. name = name.toLowerCase();
  2024. value = name in fillAttrsMap ? name : decode(value || val2 || val3 || ''); // Handle boolean attribute than value attribute
  2025. // Validate name and value
  2026. if (validate && !isInternalElement && name.indexOf('data-') !== 0) {
  2027. attrRule = validAttributesMap[name];
  2028. // Find rule by pattern matching
  2029. if (!attrRule && validAttributePatterns) {
  2030. i = validAttributePatterns.length;
  2031. while (i--) {
  2032. attrRule = validAttributePatterns[i];
  2033. if (attrRule.pattern.test(name))
  2034. break;
  2035. }
  2036. // No rule matched
  2037. if (i === -1)
  2038. attrRule = null;
  2039. }
  2040. // No attribute rule found
  2041. if (!attrRule)
  2042. return;
  2043. // Validate value
  2044. if (attrRule.validValues && !(value in attrRule.validValues))
  2045. return;
  2046. }
  2047. // Add attribute to list and map
  2048. attrList.map[name] = value;
  2049. attrList.push({
  2050. name: name,
  2051. value: value
  2052. });
  2053. });
  2054. } else {
  2055. attrList = [];
  2056. attrList.map = {};
  2057. }
  2058. // Process attributes if validation is enabled
  2059. if (validate && !isInternalElement) {
  2060. attributesRequired = elementRule.attributesRequired;
  2061. attributesDefault = elementRule.attributesDefault;
  2062. attributesForced = elementRule.attributesForced;
  2063. // Handle forced attributes
  2064. if (attributesForced) {
  2065. i = attributesForced.length;
  2066. while (i--) {
  2067. attr = attributesForced[i];
  2068. name = attr.name;
  2069. attrValue = attr.value;
  2070. if (attrValue === '{$uid}')
  2071. attrValue = 'mce_' + idCount++;
  2072. attrList.map[name] = attrValue;
  2073. attrList.push({name: name, value: attrValue});
  2074. }
  2075. }
  2076. // Handle default attributes
  2077. if (attributesDefault) {
  2078. i = attributesDefault.length;
  2079. while (i--) {
  2080. attr = attributesDefault[i];
  2081. name = attr.name;
  2082. if (!(name in attrList.map)) {
  2083. attrValue = attr.value;
  2084. if (attrValue === '{$uid}')
  2085. attrValue = 'mce_' + idCount++;
  2086. attrList.map[name] = attrValue;
  2087. attrList.push({name: name, value: attrValue});
  2088. }
  2089. }
  2090. }
  2091. // Handle required attributes
  2092. if (attributesRequired) {
  2093. i = attributesRequired.length;
  2094. while (i--) {
  2095. if (attributesRequired[i] in attrList.map)
  2096. break;
  2097. }
  2098. // None of the required attributes where found
  2099. if (i === -1)
  2100. isValidElement = false;
  2101. }
  2102. // Invalidate element if it's marked as bogus
  2103. if (attrList.map['data-mce-bogus'])
  2104. isValidElement = false;
  2105. }
  2106. if (isValidElement)
  2107. self.start(value, attrList, isShortEnded);
  2108. } else
  2109. isValidElement = false;
  2110. // Treat script, noscript and style a bit different since they may include code that looks like elements
  2111. if (endRegExp = specialElements[value]) {
  2112. endRegExp.lastIndex = index = matches.index + matches[0].length;
  2113. if (matches = endRegExp.exec(html)) {
  2114. if (isValidElement)
  2115. text = html.substr(index, matches.index - index);
  2116. index = matches.index + matches[0].length;
  2117. } else {
  2118. text = html.substr(index);
  2119. index = html.length;
  2120. }
  2121. if (isValidElement && text.length > 0)
  2122. self.text(text, true);
  2123. if (isValidElement)
  2124. self.end(value);
  2125. tokenRegExp.lastIndex = index;
  2126. continue;
  2127. }
  2128. // Push value on to stack
  2129. if (!isShortEnded) {
  2130. if (!attribsValue || attribsValue.indexOf('/') != attribsValue.length - 1)
  2131. stack.push({name: value, valid: isValidElement});
  2132. else if (isValidElement)
  2133. self.end(value);
  2134. }
  2135. } else if (value = matches[1]) { // Comment
  2136. self.comment(value);
  2137. } else if (value = matches[2]) { // CDATA
  2138. self.cdata(value);
  2139. } else if (value = matches[3]) { // DOCTYPE
  2140. self.doctype(value);
  2141. } else if (value = matches[4]) { // PI
  2142. self.pi(value, matches[5]);
  2143. }
  2144. index = matches.index + matches[0].length;
  2145. }
  2146. // Text
  2147. if (index < html.length)
  2148. self.text(decode(html.substr(index)));
  2149. // Close any open elements
  2150. for (i = stack.length - 1; i >= 0; i--) {
  2151. value = stack[i];
  2152. if (value.valid)
  2153. self.end(value.name);
  2154. }
  2155. };
  2156. }
  2157. })(tinymce);
  2158. (function(tinymce) {
  2159. var whiteSpaceRegExp = /^[ \t\r\n]*$/, typeLookup = {
  2160. '#text' : 3,
  2161. '#comment' : 8,
  2162. '#cdata' : 4,
  2163. '#pi' : 7,
  2164. '#doctype' : 10,
  2165. '#document-fragment' : 11
  2166. };
  2167. // Walks the tree left/right
  2168. function walk(node, root_node, prev) {
  2169. var sibling, parent, startName = prev ? 'lastChild' : 'firstChild', siblingName = prev ? 'prev' : 'next';
  2170. // Walk into nodes if it has a start
  2171. if (node[startName])
  2172. return node[startName];
  2173. // Return the sibling if it has one
  2174. if (node !== root_node) {
  2175. sibling = node[siblingName];
  2176. if (sibling)
  2177. return sibling;
  2178. // Walk up the parents to look for siblings
  2179. for (parent = node.parent; parent && parent !== root_node; parent = parent.parent) {
  2180. sibling = parent[siblingName];
  2181. if (sibling)
  2182. return sibling;
  2183. }
  2184. }
  2185. };
  2186. function Node(name, type) {
  2187. this.name = name;
  2188. this.type = type;
  2189. if (type === 1) {
  2190. this.attributes = [];
  2191. this.attributes.map = {};
  2192. }
  2193. }
  2194. tinymce.extend(Node.prototype, {
  2195. replace : function(node) {
  2196. var self = this;
  2197. if (node.parent)
  2198. node.remove();
  2199. self.insert(node, self);
  2200. self.remove();
  2201. return self;
  2202. },
  2203. attr : function(name, value) {
  2204. var self = this, attrs, i, undef;
  2205. if (typeof name !== "string") {
  2206. for (i in name)
  2207. self.attr(i, name[i]);
  2208. return self;
  2209. }
  2210. if (attrs = self.attributes) {
  2211. if (value !== undef) {
  2212. // Remove attribute
  2213. if (value === null) {
  2214. if (name in attrs.map) {
  2215. delete attrs.map[name];
  2216. i = attrs.length;
  2217. while (i--) {
  2218. if (attrs[i].name === name) {
  2219. attrs = attrs.splice(i, 1);
  2220. return self;
  2221. }
  2222. }
  2223. }
  2224. return self;
  2225. }
  2226. // Set attribute
  2227. if (name in attrs.map) {
  2228. // Set attribute
  2229. i = attrs.length;
  2230. while (i--) {
  2231. if (attrs[i].name === name) {
  2232. attrs[i].value = value;
  2233. break;
  2234. }
  2235. }
  2236. } else
  2237. attrs.push({name: name, value: value});
  2238. attrs.map[name] = value;
  2239. return self;
  2240. } else {
  2241. return attrs.map[name];
  2242. }
  2243. }
  2244. },
  2245. clone : function() {
  2246. var self = this, clone = new Node(self.name, self.type), i, l, selfAttrs, selfAttr, cloneAttrs;
  2247. // Clone element attributes
  2248. if (selfAttrs = self.attributes) {
  2249. cloneAttrs = [];
  2250. cloneAttrs.map = {};
  2251. for (i = 0, l = selfAttrs.length; i < l; i++) {
  2252. selfAttr = selfAttrs[i];
  2253. // Clone everything except id
  2254. if (selfAttr.name !== 'id') {
  2255. cloneAttrs[cloneAttrs.length] = {name: selfAttr.name, value: selfAttr.value};
  2256. cloneAttrs.map[selfAttr.name] = selfAttr.value;
  2257. }
  2258. }
  2259. clone.attributes = cloneAttrs;
  2260. }
  2261. clone.value = self.value;
  2262. clone.shortEnded = self.shortEnded;
  2263. return clone;
  2264. },
  2265. wrap : function(wrapper) {
  2266. var self = this;
  2267. self.parent.insert(wrapper, self);
  2268. wrapper.append(self);
  2269. return self;
  2270. },
  2271. unwrap : function() {
  2272. var self = this, node, next;
  2273. for (node = self.firstChild; node; ) {
  2274. next = node.next;
  2275. self.insert(node, self, true);
  2276. node = next;
  2277. }
  2278. self.remove();
  2279. },
  2280. remove : function() {
  2281. var self = this, parent = self.parent, next = self.next, prev = self.prev;
  2282. if (parent) {
  2283. if (parent.firstChild === self) {
  2284. parent.firstChild = next;
  2285. if (next)
  2286. next.prev = null;
  2287. } else {
  2288. prev.next = next;
  2289. }
  2290. if (parent.lastChild === self) {
  2291. parent.lastChild = prev;
  2292. if (prev)
  2293. prev.next = null;
  2294. } else {
  2295. next.prev = prev;
  2296. }
  2297. self.parent = self.next = self.prev = null;
  2298. }
  2299. return self;
  2300. },
  2301. append : function(node) {
  2302. var self = this, last;
  2303. if (node.parent)
  2304. node.remove();
  2305. last = self.lastChild;
  2306. if (last) {
  2307. last.next = node;
  2308. node.prev = last;
  2309. self.lastChild = node;
  2310. } else
  2311. self.lastChild = self.firstChild = node;
  2312. node.parent = self;
  2313. return node;
  2314. },
  2315. insert : function(node, ref_node, before) {
  2316. var parent;
  2317. if (node.parent)
  2318. node.remove();
  2319. parent = ref_node.parent || this;
  2320. if (before) {
  2321. if (ref_node === parent.firstChild)
  2322. parent.firstChild = node;
  2323. else
  2324. ref_node.prev.next = node;
  2325. node.prev = ref_node.prev;
  2326. node.next = ref_node;
  2327. ref_node.prev = node;
  2328. } else {
  2329. if (ref_node === parent.lastChild)
  2330. parent.lastChild = node;
  2331. else
  2332. ref_node.next.prev = node;
  2333. node.next = ref_node.next;
  2334. node.prev = ref_node;
  2335. ref_node.next = node;
  2336. }
  2337. node.parent = parent;
  2338. return node;
  2339. },
  2340. getAll : function(name) {
  2341. var self = this, node, collection = [];
  2342. for (node = self.firstChild; node; node = walk(node, self)) {
  2343. if (node.name === name)
  2344. collection.push(node);
  2345. }
  2346. return collection;
  2347. },
  2348. empty : function() {
  2349. var self = this, nodes, i, node;
  2350. // Remove all children
  2351. if (self.firstChild) {
  2352. nodes = [];
  2353. // Collect the children
  2354. for (node = self.firstChild; node; node = walk(node, self))
  2355. nodes.push(node);
  2356. // Remove the children
  2357. i = nodes.length;
  2358. while (i--) {
  2359. node = nodes[i];
  2360. node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;
  2361. }
  2362. }
  2363. self.firstChild = self.lastChild = null;
  2364. return self;
  2365. },
  2366. isEmpty : function(elements) {
  2367. var self = this, node = self.firstChild, i, name;
  2368. if (node) {
  2369. do {
  2370. if (node.type === 1) {
  2371. // Ignore bogus elements
  2372. if (node.attributes.map['data-mce-bogus'])
  2373. continue;
  2374. // Keep empty elements like <img />
  2375. if (elements[node.name])
  2376. return false;
  2377. // Keep elements with data attributes or name attribute like <a name="1"></a>
  2378. i = node.attributes.length;
  2379. while (i--) {
  2380. name = node.attributes[i].name;
  2381. if (name === "name" || name.indexOf('data-') === 0)
  2382. return false;
  2383. }
  2384. }
  2385. // Keep non whitespace text nodes
  2386. if ((node.type === 3 && !whiteSpaceRegExp.test(node.value)))
  2387. return false;
  2388. } while (node = walk(node, self));
  2389. }
  2390. return true;
  2391. },
  2392. walk : function(prev) {
  2393. return walk(this, null, prev);
  2394. }
  2395. });
  2396. tinymce.extend(Node, {
  2397. create : function(name, attrs) {
  2398. var node, attrName;
  2399. // Create node
  2400. node = new Node(name, typeLookup[name] || 1);
  2401. // Add attributes if needed
  2402. if (attrs) {
  2403. for (attrName in attrs)
  2404. node.attr(attrName, attrs[attrName]);
  2405. }
  2406. return node;
  2407. }
  2408. });
  2409. tinymce.html.Node = Node;
  2410. })(tinymce);
  2411. (function(tinymce) {
  2412. var Node = tinymce.html.Node;
  2413. tinymce.html.DomParser = function(settings, schema) {
  2414. var self = this, nodeFilters = {}, attributeFilters = [], matchedNodes = {}, matchedAttributes = {};
  2415. settings = settings || {};
  2416. settings.validate = "validate" in settings ? settings.validate : true;
  2417. settings.root_name = settings.root_name || 'body';
  2418. self.schema = schema = schema || new tinymce.html.Schema();
  2419. function fixInvalidChildren(nodes) {
  2420. var ni, node, parent, parents, newParent, currentNode, tempNode, childNode, i,
  2421. childClone, nonEmptyElements, nonSplitableElements, sibling, nextNode;
  2422. nonSplitableElements = tinymce.makeMap('tr,td,th,tbody,thead,tfoot,table');
  2423. nonEmptyElements = schema.getNonEmptyElements();
  2424. for (ni = 0; ni < nodes.length; ni++) {
  2425. node = nodes[ni];
  2426. // Already removed
  2427. if (!node.parent)
  2428. continue;
  2429. // Get list of all parent nodes until we find a valid parent to stick the child into
  2430. parents = [node];
  2431. for (parent = node.parent; parent && !schema.isValidChild(parent.name, node.name) && !nonSplitableElements[parent.name]; parent = parent.parent)
  2432. parents.push(parent);
  2433. // Found a suitable parent
  2434. if (parent && parents.length > 1) {
  2435. // Reverse the array since it makes looping easier
  2436. parents.reverse();
  2437. // Clone the related parent and insert that after the moved node
  2438. newParent = currentNode = self.filterNode(parents[0].clone());
  2439. // Start cloning and moving children on the left side of the target node
  2440. for (i = 0; i < parents.length - 1; i++) {
  2441. if (schema.isValidChild(currentNode.name, parents[i].name)) {
  2442. tempNode = self.filterNode(parents[i].clone());
  2443. currentNode.append(tempNode);
  2444. } else
  2445. tempNode = currentNode;
  2446. for (childNode = parents[i].firstChild; childNode && childNode != parents[i + 1]; ) {
  2447. nextNode = childNode.next;
  2448. tempNode.append(childNode);
  2449. childNode = nextNode;
  2450. }
  2451. currentNode = tempNode;
  2452. }
  2453. if (!newParent.isEmpty(nonEmptyElements)) {
  2454. parent.insert(newParent, parents[0], true);
  2455. parent.insert(node, newParent);
  2456. } else {
  2457. parent.insert(node, parents[0], true);
  2458. }
  2459. // Check if the element is empty by looking through it's contents and special treatment for <p><br /></p>
  2460. parent = parents[0];
  2461. if (parent.isEmpty(nonEmptyElements) || parent.firstChild === parent.lastChild && parent.firstChild.name === 'br') {
  2462. parent.empty().remove();
  2463. }
  2464. } else if (node.parent) {
  2465. // If it's an LI try to find a UL/OL for it or wrap it
  2466. if (node.name === 'li') {
  2467. sibling = node.prev;
  2468. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  2469. sibling.append(node);
  2470. continue;
  2471. }
  2472. sibling = node.next;
  2473. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  2474. sibling.insert(node, sibling.firstChild, true);
  2475. continue;
  2476. }
  2477. node.wrap(self.filterNode(new Node('ul', 1)));
  2478. continue;
  2479. }
  2480. // Try wrapping the element in a DIV
  2481. if (schema.isValidChild(node.parent.name, 'div') && schema.isValidChild('div', node.name)) {
  2482. node.wrap(self.filterNode(new Node('div', 1)));
  2483. } else {
  2484. // We failed wrapping it, then remove or unwrap it
  2485. if (node.name === 'style' || node.name === 'script')
  2486. node.empty().remove();
  2487. else
  2488. node.unwrap();
  2489. }
  2490. }
  2491. }
  2492. };
  2493. self.filterNode = function(node) {
  2494. var i, name, list;
  2495. // Run element filters
  2496. if (name in nodeFilters) {
  2497. list = matchedNodes[name];
  2498. if (list)
  2499. list.push(node);
  2500. else
  2501. matchedNodes[name] = [node];
  2502. }
  2503. // Run attribute filters
  2504. i = attributeFilters.length;
  2505. while (i--) {
  2506. name = attributeFilters[i].name;
  2507. if (name in node.attributes.map) {
  2508. list = matchedAttributes[name];
  2509. if (list)
  2510. list.push(node);
  2511. else
  2512. matchedAttributes[name] = [node];
  2513. }
  2514. }
  2515. return node;
  2516. };
  2517. self.addNodeFilter = function(name, callback) {
  2518. tinymce.each(tinymce.explode(name), function(name) {
  2519. var list = nodeFilters[name];
  2520. if (!list)
  2521. nodeFilters[name] = list = [];
  2522. list.push(callback);
  2523. });
  2524. };
  2525. self.addAttributeFilter = function(name, callback) {
  2526. tinymce.each(tinymce.explode(name), function(name) {
  2527. var i;
  2528. for (i = 0; i < attributeFilters.length; i++) {
  2529. if (attributeFilters[i].name === name) {
  2530. attributeFilters[i].callbacks.push(callback);
  2531. return;
  2532. }
  2533. }
  2534. attributeFilters.push({name: name, callbacks: [callback]});
  2535. });
  2536. };
  2537. self.parse = function(html, args) {
  2538. var parser, rootNode, node, nodes, i, l, fi, fl, list, name, validate,
  2539. blockElements, startWhiteSpaceRegExp, invalidChildren = [],
  2540. endWhiteSpaceRegExp, allWhiteSpaceRegExp, whiteSpaceElements, children, nonEmptyElements, rootBlockName;
  2541. args = args || {};
  2542. matchedNodes = {};
  2543. matchedAttributes = {};
  2544. blockElements = tinymce.extend(tinymce.makeMap('script,style,head,html,body,title,meta,param'), schema.getBlockElements());
  2545. nonEmptyElements = schema.getNonEmptyElements();
  2546. children = schema.children;
  2547. validate = settings.validate;
  2548. rootBlockName = "forced_root_block" in args ? args.forced_root_block : settings.forced_root_block;
  2549. whiteSpaceElements = schema.getWhiteSpaceElements();
  2550. startWhiteSpaceRegExp = /^[ \t\r\n]+/;
  2551. endWhiteSpaceRegExp = /[ \t\r\n]+$/;
  2552. allWhiteSpaceRegExp = /[ \t\r\n]+/g;
  2553. function addRootBlocks() {
  2554. var node = rootNode.firstChild, next, rootBlockNode;
  2555. while (node) {
  2556. next = node.next;
  2557. if (node.type == 3 || (node.type == 1 && node.name !== 'p' && !blockElements[node.name] && !node.attr('data-mce-type'))) {
  2558. if (!rootBlockNode) {
  2559. // Create a new root block element
  2560. rootBlockNode = createNode(rootBlockName, 1);
  2561. rootNode.insert(rootBlockNode, node);
  2562. rootBlockNode.append(node);
  2563. } else
  2564. rootBlockNode.append(node);
  2565. } else {
  2566. rootBlockNode = null;
  2567. }
  2568. node = next;
  2569. };
  2570. };
  2571. function createNode(name, type) {
  2572. var node = new Node(name, type), list;
  2573. if (name in nodeFilters) {
  2574. list = matchedNodes[name];
  2575. if (list)
  2576. list.push(node);
  2577. else
  2578. matchedNodes[name] = [node];
  2579. }
  2580. return node;
  2581. };
  2582. function removeWhitespaceBefore(node) {
  2583. var textNode, textVal, sibling;
  2584. for (textNode = node.prev; textNode && textNode.type === 3; ) {
  2585. textVal = textNode.value.replace(endWhiteSpaceRegExp, '');
  2586. if (textVal.length > 0) {
  2587. textNode.value = textVal;
  2588. textNode = textNode.prev;
  2589. } else {
  2590. sibling = textNode.prev;
  2591. textNode.remove();
  2592. textNode = sibling;
  2593. }
  2594. }
  2595. };
  2596. parser = new tinymce.html.SaxParser({
  2597. validate : validate,
  2598. fix_self_closing : !validate, // Let the DOM parser handle <li> in <li> or <p> in <p> for better results
  2599. cdata: function(text) {
  2600. node.append(createNode('#cdata', 4)).value = text;
  2601. },
  2602. text: function(text, raw) {
  2603. var textNode;
  2604. // Trim all redundant whitespace on non white space elements
  2605. if (!whiteSpaceElements[node.name]) {
  2606. text = text.replace(allWhiteSpaceRegExp, ' ');
  2607. if (node.lastChild && blockElements[node.lastChild.name])
  2608. text = text.replace(startWhiteSpaceRegExp, '');
  2609. }
  2610. // Do we need to create the node
  2611. if (text.length !== 0) {
  2612. textNode = createNode('#text', 3);
  2613. textNode.raw = !!raw;
  2614. node.append(textNode).value = text;
  2615. }
  2616. },
  2617. comment: function(text) {
  2618. node.append(createNode('#comment', 8)).value = text;
  2619. },
  2620. pi: function(name, text) {
  2621. node.append(createNode(name, 7)).value = text;
  2622. removeWhitespaceBefore(node);
  2623. },
  2624. doctype: function(text) {
  2625. var newNode;
  2626. newNode = node.append(createNode('#doctype', 10));
  2627. newNode.value = text;
  2628. removeWhitespaceBefore(node);
  2629. },
  2630. start: function(name, attrs, empty) {
  2631. var newNode, attrFiltersLen, elementRule, textNode, attrName, text, sibling, parent;
  2632. elementRule = validate ? schema.getElementRule(name) : {};
  2633. if (elementRule) {
  2634. newNode = createNode(elementRule.outputName || name, 1);
  2635. newNode.attributes = attrs;
  2636. newNode.shortEnded = empty;
  2637. node.append(newNode);
  2638. // Check if node is valid child of the parent node is the child is
  2639. // unknown we don't collect it since it's probably a custom element
  2640. parent = children[node.name];
  2641. if (parent && children[newNode.name] && !parent[newNode.name])
  2642. invalidChildren.push(newNode);
  2643. attrFiltersLen = attributeFilters.length;
  2644. while (attrFiltersLen--) {
  2645. attrName = attributeFilters[attrFiltersLen].name;
  2646. if (attrName in attrs.map) {
  2647. list = matchedAttributes[attrName];
  2648. if (list)
  2649. list.push(newNode);
  2650. else
  2651. matchedAttributes[attrName] = [newNode];
  2652. }
  2653. }
  2654. // Trim whitespace before block
  2655. if (blockElements[name])
  2656. removeWhitespaceBefore(newNode);
  2657. // Change current node if the element wasn't empty i.e not <br /> or <img />
  2658. if (!empty)
  2659. node = newNode;
  2660. }
  2661. },
  2662. end: function(name) {
  2663. var textNode, elementRule, text, sibling, tempNode;
  2664. elementRule = validate ? schema.getElementRule(name) : {};
  2665. if (elementRule) {
  2666. if (blockElements[name]) {
  2667. if (!whiteSpaceElements[node.name]) {
  2668. // Trim whitespace at beginning of block
  2669. for (textNode = node.firstChild; textNode && textNode.type === 3; ) {
  2670. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  2671. if (text.length > 0) {
  2672. textNode.value = text;
  2673. textNode = textNode.next;
  2674. } else {
  2675. sibling = textNode.next;
  2676. textNode.remove();
  2677. textNode = sibling;
  2678. }
  2679. }
  2680. // Trim whitespace at end of block
  2681. for (textNode = node.lastChild; textNode && textNode.type === 3; ) {
  2682. text = textNode.value.replace(endWhiteSpaceRegExp, '');
  2683. if (text.length > 0) {
  2684. textNode.value = text;
  2685. textNode = textNode.prev;
  2686. } else {
  2687. sibling = textNode.prev;
  2688. textNode.remove();
  2689. textNode = sibling;
  2690. }
  2691. }
  2692. }
  2693. // Trim start white space
  2694. textNode = node.prev;
  2695. if (textNode && textNode.type === 3) {
  2696. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  2697. if (text.length > 0)
  2698. textNode.value = text;
  2699. else
  2700. textNode.remove();
  2701. }
  2702. }
  2703. // Handle empty nodes
  2704. if (elementRule.removeEmpty || elementRule.paddEmpty) {
  2705. if (node.isEmpty(nonEmptyElements)) {
  2706. if (elementRule.paddEmpty)
  2707. node.empty().append(new Node('#text', '3')).value = '\u00a0';
  2708. else {
  2709. // Leave nodes that have a name like <a name="name">
  2710. if (!node.attributes.map.name) {
  2711. tempNode = node.parent;
  2712. node.empty().remove();
  2713. node = tempNode;
  2714. return;
  2715. }
  2716. }
  2717. }
  2718. }
  2719. node = node.parent;
  2720. }
  2721. }
  2722. }, schema);
  2723. rootNode = node = new Node(args.context || settings.root_name, 11);
  2724. parser.parse(html);
  2725. // Fix invalid children or report invalid children in a contextual parsing
  2726. if (validate && invalidChildren.length) {
  2727. if (!args.context)
  2728. fixInvalidChildren(invalidChildren);
  2729. else
  2730. args.invalid = true;
  2731. }
  2732. // Wrap nodes in the root into block elements if the root is body
  2733. if (rootBlockName && rootNode.name == 'body')
  2734. addRootBlocks();
  2735. // Run filters only when the contents is valid
  2736. if (!args.invalid) {
  2737. // Run node filters
  2738. for (name in matchedNodes) {
  2739. list = nodeFilters[name];
  2740. nodes = matchedNodes[name];
  2741. // Remove already removed children
  2742. fi = nodes.length;
  2743. while (fi--) {
  2744. if (!nodes[fi].parent)
  2745. nodes.splice(fi, 1);
  2746. }
  2747. for (i = 0, l = list.length; i < l; i++)
  2748. list[i](nodes, name, args);
  2749. }
  2750. // Run attribute filters
  2751. for (i = 0, l = attributeFilters.length; i < l; i++) {
  2752. list = attributeFilters[i];
  2753. if (list.name in matchedAttributes) {
  2754. nodes = matchedAttributes[list.name];
  2755. // Remove already removed children
  2756. fi = nodes.length;
  2757. while (fi--) {
  2758. if (!nodes[fi].parent)
  2759. nodes.splice(fi, 1);
  2760. }
  2761. for (fi = 0, fl = list.callbacks.length; fi < fl; fi++)
  2762. list.callbacks[fi](nodes, list.name, args);
  2763. }
  2764. }
  2765. }
  2766. return rootNode;
  2767. };
  2768. // Remove <br> at end of block elements Gecko and WebKit injects BR elements to
  2769. // make it possible to place the caret inside empty blocks. This logic tries to remove
  2770. // these elements and keep br elements that where intended to be there intact
  2771. if (settings.remove_trailing_brs) {
  2772. self.addNodeFilter('br', function(nodes, name) {
  2773. var i, l = nodes.length, node, blockElements = schema.getBlockElements(),
  2774. nonEmptyElements = schema.getNonEmptyElements(), parent, prev, prevName;
  2775. // Remove brs from body element as well
  2776. blockElements.body = 1;
  2777. // Must loop forwards since it will otherwise remove all brs in <p>a<br><br><br></p>
  2778. for (i = 0; i < l; i++) {
  2779. node = nodes[i];
  2780. parent = node.parent;
  2781. if (blockElements[node.parent.name] && node === parent.lastChild) {
  2782. // Loop all nodes to the right of the current node and check for other BR elements
  2783. // excluding bookmarks since they are invisible
  2784. prev = node.prev;
  2785. while (prev) {
  2786. prevName = prev.name;
  2787. // Ignore bookmarks
  2788. if (prevName !== "span" || prev.attr('data-mce-type') !== 'bookmark') {
  2789. // Found a non BR element
  2790. if (prevName !== "br")
  2791. break;
  2792. // Found another br it's a <br><br> structure then don't remove anything
  2793. if (prevName === 'br') {
  2794. node = null;
  2795. break;
  2796. }
  2797. }
  2798. prev = prev.prev;
  2799. }
  2800. if (node) {
  2801. node.remove();
  2802. // Is the parent to be considered empty after we removed the BR
  2803. if (parent.isEmpty(nonEmptyElements)) {
  2804. elementRule = schema.getElementRule(parent.name);
  2805. // Remove or padd the element depending on schema rule
  2806. if (elementRule) {
  2807. if (elementRule.removeEmpty)
  2808. parent.remove();
  2809. else if (elementRule.paddEmpty)
  2810. parent.empty().append(new tinymce.html.Node('#text', 3)).value = '\u00a0';
  2811. }
  2812. }
  2813. }
  2814. }
  2815. }
  2816. });
  2817. }
  2818. }
  2819. })(tinymce);
  2820. tinymce.html.Writer = function(settings) {
  2821. var html = [], indent, indentBefore, indentAfter, encode, htmlOutput;
  2822. settings = settings || {};
  2823. indent = settings.indent;
  2824. indentBefore = tinymce.makeMap(settings.indent_before || '');
  2825. indentAfter = tinymce.makeMap(settings.indent_after || '');
  2826. encode = tinymce.html.Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
  2827. htmlOutput = settings.element_format == "html";
  2828. return {
  2829. start: function(name, attrs, empty) {
  2830. var i, l, attr, value;
  2831. if (indent && indentBefore[name] && html.length > 0) {
  2832. value = html[html.length - 1];
  2833. if (value.length > 0 && value !== '\n')
  2834. html.push('\n');
  2835. }
  2836. html.push('<', name);
  2837. if (attrs) {
  2838. for (i = 0, l = attrs.length; i < l; i++) {
  2839. attr = attrs[i];
  2840. html.push(' ', attr.name, '="', encode(attr.value, true), '"');
  2841. }
  2842. }
  2843. if (!empty || htmlOutput)
  2844. html[html.length] = '>';
  2845. else
  2846. html[html.length] = ' />';
  2847. if (empty && indent && indentAfter[name] && html.length > 0) {
  2848. value = html[html.length - 1];
  2849. if (value.length > 0 && value !== '\n')
  2850. html.push('\n');
  2851. }
  2852. },
  2853. end: function(name) {
  2854. var value;
  2855. /*if (indent && indentBefore[name] && html.length > 0) {
  2856. value = html[html.length - 1];
  2857. if (value.length > 0 && value !== '\n')
  2858. html.push('\n');
  2859. }*/
  2860. html.push('</', name, '>');
  2861. if (indent && indentAfter[name] && html.length > 0) {
  2862. value = html[html.length - 1];
  2863. if (value.length > 0 && value !== '\n')
  2864. html.push('\n');
  2865. }
  2866. },
  2867. text: function(text, raw) {
  2868. if (text.length > 0)
  2869. html[html.length] = raw ? text : encode(text);
  2870. },
  2871. cdata: function(text) {
  2872. html.push('<![CDATA[', text, ']]>');
  2873. },
  2874. comment: function(text) {
  2875. html.push('<!--', text, '-->');
  2876. },
  2877. pi: function(name, text) {
  2878. if (text)
  2879. html.push('<?', name, ' ', text, '?>');
  2880. else
  2881. html.push('<?', name, '?>');
  2882. if (indent)
  2883. html.push('\n');
  2884. },
  2885. doctype: function(text) {
  2886. html.push('<!DOCTYPE', text, '>', indent ? '\n' : '');
  2887. },
  2888. reset: function() {
  2889. html.length = 0;
  2890. },
  2891. getContent: function() {
  2892. return html.join('').replace(/\n$/, '');
  2893. }
  2894. };
  2895. };
  2896. (function(tinymce) {
  2897. tinymce.html.Serializer = function(settings, schema) {
  2898. var self = this, writer = new tinymce.html.Writer(settings);
  2899. settings = settings || {};
  2900. settings.validate = "validate" in settings ? settings.validate : true;
  2901. self.schema = schema = schema || new tinymce.html.Schema();
  2902. self.writer = writer;
  2903. self.serialize = function(node) {
  2904. var handlers, validate;
  2905. validate = settings.validate;
  2906. handlers = {
  2907. // #text
  2908. 3: function(node, raw) {
  2909. writer.text(node.value, node.raw);
  2910. },
  2911. // #comment
  2912. 8: function(node) {
  2913. writer.comment(node.value);
  2914. },
  2915. // Processing instruction
  2916. 7: function(node) {
  2917. writer.pi(node.name, node.value);
  2918. },
  2919. // Doctype
  2920. 10: function(node) {
  2921. writer.doctype(node.value);
  2922. },
  2923. // CDATA
  2924. 4: function(node) {
  2925. writer.cdata(node.value);
  2926. },
  2927. // Document fragment
  2928. 11: function(node) {
  2929. if ((node = node.firstChild)) {
  2930. do {
  2931. walk(node);
  2932. } while (node = node.next);
  2933. }
  2934. }
  2935. };
  2936. writer.reset();
  2937. function walk(node) {
  2938. var handler = handlers[node.type], name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule;
  2939. if (!handler) {
  2940. name = node.name;
  2941. isEmpty = node.shortEnded;
  2942. attrs = node.attributes;
  2943. // Sort attributes
  2944. if (validate && attrs && attrs.length > 1) {
  2945. sortedAttrs = [];
  2946. sortedAttrs.map = {};
  2947. elementRule = schema.getElementRule(node.name);
  2948. for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
  2949. attrName = elementRule.attributesOrder[i];
  2950. if (attrName in attrs.map) {
  2951. attrValue = attrs.map[attrName];
  2952. sortedAttrs.map[attrName] = attrValue;
  2953. sortedAttrs.push({name: attrName, value: attrValue});
  2954. }
  2955. }
  2956. for (i = 0, l = attrs.length; i < l; i++) {
  2957. attrName = attrs[i].name;
  2958. if (!(attrName in sortedAttrs.map)) {
  2959. attrValue = attrs.map[attrName];
  2960. sortedAttrs.map[attrName] = attrValue;
  2961. sortedAttrs.push({name: attrName, value: attrValue});
  2962. }
  2963. }
  2964. attrs = sortedAttrs;
  2965. }
  2966. writer.start(node.name, attrs, isEmpty);
  2967. if (!isEmpty) {
  2968. if ((node = node.firstChild)) {
  2969. do {
  2970. walk(node);
  2971. } while (node = node.next);
  2972. }
  2973. writer.end(name);
  2974. }
  2975. } else
  2976. handler(node);
  2977. }
  2978. // Serialize element and treat all non elements as fragments
  2979. if (node.type == 1 && !settings.inner)
  2980. walk(node);
  2981. else
  2982. handlers[11](node);
  2983. return writer.getContent();
  2984. };
  2985. }
  2986. })(tinymce);
  2987. (function(tinymce) {
  2988. // Shorten names
  2989. var each = tinymce.each,
  2990. is = tinymce.is,
  2991. isWebKit = tinymce.isWebKit,
  2992. isIE = tinymce.isIE,
  2993. Entities = tinymce.html.Entities,
  2994. simpleSelectorRe = /^([a-z0-9],?)+$/i,
  2995. blockElementsMap = tinymce.html.Schema.blockElementsMap,
  2996. whiteSpaceRegExp = /^[ \t\r\n]*$/;
  2997. tinymce.create('tinymce.dom.DOMUtils', {
  2998. doc : null,
  2999. root : null,
  3000. files : null,
  3001. pixelStyles : /^(top|left|bottom|right|width|height|borderWidth)$/,
  3002. props : {
  3003. "for" : "htmlFor",
  3004. "class" : "className",
  3005. className : "className",
  3006. checked : "checked",
  3007. disabled : "disabled",
  3008. maxlength : "maxLength",
  3009. readonly : "readOnly",
  3010. selected : "selected",
  3011. value : "value",
  3012. id : "id",
  3013. name : "name",
  3014. type : "type"
  3015. },
  3016. DOMUtils : function(d, s) {
  3017. var t = this, globalStyle, name;
  3018. t.doc = d;
  3019. t.win = window;
  3020. t.files = {};
  3021. t.cssFlicker = false;
  3022. t.counter = 0;
  3023. t.stdMode = !tinymce.isIE || d.documentMode >= 8;
  3024. t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat" || t.stdMode;
  3025. t.hasOuterHTML = "outerHTML" in d.createElement("a");
  3026. t.settings = s = tinymce.extend({
  3027. keep_values : false,
  3028. hex_colors : 1
  3029. }, s);
  3030. t.schema = s.schema;
  3031. t.styles = new tinymce.html.Styles({
  3032. url_converter : s.url_converter,
  3033. url_converter_scope : s.url_converter_scope
  3034. }, s.schema);
  3035. // Fix IE6SP2 flicker and check it failed for pre SP2
  3036. if (tinymce.isIE6) {
  3037. try {
  3038. d.execCommand('BackgroundImageCache', false, true);
  3039. } catch (e) {
  3040. t.cssFlicker = true;
  3041. }
  3042. }
  3043. if (isIE && s.schema) {
  3044. // Add missing HTML 4/5 elements to IE
  3045. ('abbr article aside audio canvas ' +
  3046. 'details figcaption figure footer ' +
  3047. 'header hgroup mark menu meter nav ' +
  3048. 'output progress section summary ' +
  3049. 'time video').replace(/\w+/g, function(name) {
  3050. d.createElement(name);
  3051. });
  3052. // Create all custom elements
  3053. for (name in s.schema.getCustomElements()) {
  3054. d.createElement(name);
  3055. }
  3056. }
  3057. tinymce.addUnload(t.destroy, t);
  3058. },
  3059. getRoot : function() {
  3060. var t = this, s = t.settings;
  3061. return (s && t.get(s.root_element)) || t.doc.body;
  3062. },
  3063. getViewPort : function(w) {
  3064. var d, b;
  3065. w = !w ? this.win : w;
  3066. d = w.document;
  3067. b = this.boxModel ? d.documentElement : d.body;
  3068. // Returns viewport size excluding scrollbars
  3069. return {
  3070. x : w.pageXOffset || b.scrollLeft,
  3071. y : w.pageYOffset || b.scrollTop,
  3072. w : w.innerWidth || b.clientWidth,
  3073. h : w.innerHeight || b.clientHeight
  3074. };
  3075. },
  3076. getRect : function(e) {
  3077. var p, t = this, sr;
  3078. e = t.get(e);
  3079. p = t.getPos(e);
  3080. sr = t.getSize(e);
  3081. return {
  3082. x : p.x,
  3083. y : p.y,
  3084. w : sr.w,
  3085. h : sr.h
  3086. };
  3087. },
  3088. getSize : function(e) {
  3089. var t = this, w, h;
  3090. e = t.get(e);
  3091. w = t.getStyle(e, 'width');
  3092. h = t.getStyle(e, 'height');
  3093. // Non pixel value, then force offset/clientWidth
  3094. if (w.indexOf('px') === -1)
  3095. w = 0;
  3096. // Non pixel value, then force offset/clientWidth
  3097. if (h.indexOf('px') === -1)
  3098. h = 0;
  3099. return {
  3100. w : parseInt(w) || e.offsetWidth || e.clientWidth,
  3101. h : parseInt(h) || e.offsetHeight || e.clientHeight
  3102. };
  3103. },
  3104. getParent : function(n, f, r) {
  3105. return this.getParents(n, f, r, false);
  3106. },
  3107. getParents : function(n, f, r, c) {
  3108. var t = this, na, se = t.settings, o = [];
  3109. n = t.get(n);
  3110. c = c === undefined;
  3111. if (se.strict_root)
  3112. r = r || t.getRoot();
  3113. // Wrap node name as func
  3114. if (is(f, 'string')) {
  3115. na = f;
  3116. if (f === '*') {
  3117. f = function(n) {return n.nodeType == 1;};
  3118. } else {
  3119. f = function(n) {
  3120. return t.is(n, na);
  3121. };
  3122. }
  3123. }
  3124. while (n) {
  3125. if (n == r || !n.nodeType || n.nodeType === 9)
  3126. break;
  3127. if (!f || f(n)) {
  3128. if (c)
  3129. o.push(n);
  3130. else
  3131. return n;
  3132. }
  3133. n = n.parentNode;
  3134. }
  3135. return c ? o : null;
  3136. },
  3137. get : function(e) {
  3138. var n;
  3139. if (e && this.doc && typeof(e) == 'string') {
  3140. n = e;
  3141. e = this.doc.getElementById(e);
  3142. // IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick
  3143. if (e && e.id !== n)
  3144. return this.doc.getElementsByName(n)[1];
  3145. }
  3146. return e;
  3147. },
  3148. getNext : function(node, selector) {
  3149. return this._findSib(node, selector, 'nextSibling');
  3150. },
  3151. getPrev : function(node, selector) {
  3152. return this._findSib(node, selector, 'previousSibling');
  3153. },
  3154. add : function(p, n, a, h, c) {
  3155. var t = this;
  3156. return this.run(p, function(p) {
  3157. var e, k;
  3158. e = is(n, 'string') ? t.doc.createElement(n) : n;
  3159. t.setAttribs(e, a);
  3160. if (h) {
  3161. if (h.nodeType)
  3162. e.appendChild(h);
  3163. else
  3164. t.setHTML(e, h);
  3165. }
  3166. return !c ? p.appendChild(e) : e;
  3167. });
  3168. },
  3169. create : function(n, a, h) {
  3170. return this.add(this.doc.createElement(n), n, a, h, 1);
  3171. },
  3172. createHTML : function(n, a, h) {
  3173. var o = '', t = this, k;
  3174. o += '<' + n;
  3175. for (k in a) {
  3176. if (a.hasOwnProperty(k))
  3177. o += ' ' + k + '="' + t.encode(a[k]) + '"';
  3178. }
  3179. // A call to tinymce.is doesn't work for some odd reason on IE9 possible bug inside their JS runtime
  3180. if (typeof(h) != "undefined")
  3181. return o + '>' + h + '</' + n + '>';
  3182. return o + ' />';
  3183. },
  3184. remove : function(node, keep_children) {
  3185. return this.run(node, function(node) {
  3186. var child, parent = node.parentNode;
  3187. if (!parent)
  3188. return null;
  3189. if (keep_children) {
  3190. while (child = node.firstChild) {
  3191. // IE 8 will crash if you don't remove completely empty text nodes
  3192. if (!tinymce.isIE || child.nodeType !== 3 || child.nodeValue)
  3193. parent.insertBefore(child, node);
  3194. else
  3195. node.removeChild(child);
  3196. }
  3197. }
  3198. return parent.removeChild(node);
  3199. });
  3200. },
  3201. setStyle : function(n, na, v) {
  3202. var t = this;
  3203. return t.run(n, function(e) {
  3204. var s, i;
  3205. s = e.style;
  3206. // Camelcase it, if needed
  3207. na = na.replace(/-(\D)/g, function(a, b){
  3208. return b.toUpperCase();
  3209. });
  3210. // Default px suffix on these
  3211. if (t.pixelStyles.test(na) && (tinymce.is(v, 'number') || /^[\-0-9\.]+$/.test(v)))
  3212. v += 'px';
  3213. switch (na) {
  3214. case 'opacity':
  3215. // IE specific opacity
  3216. if (isIE) {
  3217. s.filter = v === '' ? '' : "alpha(opacity=" + (v * 100) + ")";
  3218. if (!n.currentStyle || !n.currentStyle.hasLayout)
  3219. s.display = 'inline-block';
  3220. }
  3221. // Fix for older browsers
  3222. s[na] = s['-moz-opacity'] = s['-khtml-opacity'] = v || '';
  3223. break;
  3224. case 'float':
  3225. isIE ? s.styleFloat = v : s.cssFloat = v;
  3226. break;
  3227. default:
  3228. s[na] = v || '';
  3229. }
  3230. // Force update of the style data
  3231. if (t.settings.update_styles)
  3232. t.setAttrib(e, 'data-mce-style');
  3233. });
  3234. },
  3235. getStyle : function(n, na, c) {
  3236. n = this.get(n);
  3237. if (!n)
  3238. return;
  3239. // Gecko
  3240. if (this.doc.defaultView && c) {
  3241. // Remove camelcase
  3242. na = na.replace(/[A-Z]/g, function(a){
  3243. return '-' + a;
  3244. });
  3245. try {
  3246. return this.doc.defaultView.getComputedStyle(n, null).getPropertyValue(na);
  3247. } catch (ex) {
  3248. // Old safari might fail
  3249. return null;
  3250. }
  3251. }
  3252. // Camelcase it, if needed
  3253. na = na.replace(/-(\D)/g, function(a, b){
  3254. return b.toUpperCase();
  3255. });
  3256. if (na == 'float')
  3257. na = isIE ? 'styleFloat' : 'cssFloat';
  3258. // IE & Opera
  3259. if (n.currentStyle && c)
  3260. return n.currentStyle[na];
  3261. return n.style ? n.style[na] : undefined;
  3262. },
  3263. setStyles : function(e, o) {
  3264. var t = this, s = t.settings, ol;
  3265. ol = s.update_styles;
  3266. s.update_styles = 0;
  3267. each(o, function(v, n) {
  3268. t.setStyle(e, n, v);
  3269. });
  3270. // Update style info
  3271. s.update_styles = ol;
  3272. if (s.update_styles)
  3273. t.setAttrib(e, s.cssText);
  3274. },
  3275. removeAllAttribs: function(e) {
  3276. return this.run(e, function(e) {
  3277. var i, attrs = e.attributes;
  3278. for (i = attrs.length - 1; i >= 0; i--) {
  3279. e.removeAttributeNode(attrs.item(i));
  3280. }
  3281. });
  3282. },
  3283. setAttrib : function(e, n, v) {
  3284. var t = this;
  3285. // Whats the point
  3286. if (!e || !n)
  3287. return;
  3288. // Strict XML mode
  3289. if (t.settings.strict)
  3290. n = n.toLowerCase();
  3291. return this.run(e, function(e) {
  3292. var s = t.settings;
  3293. if (v !== null) {
  3294. switch (n) {
  3295. case "style":
  3296. if (!is(v, 'string')) {
  3297. each(v, function(v, n) {
  3298. t.setStyle(e, n, v);
  3299. });
  3300. return;
  3301. }
  3302. // No mce_style for elements with these since they might get resized by the user
  3303. if (s.keep_values) {
  3304. if (v && !t._isRes(v))
  3305. e.setAttribute('data-mce-style', v, 2);
  3306. else
  3307. e.removeAttribute('data-mce-style', 2);
  3308. }
  3309. e.style.cssText = v;
  3310. break;
  3311. case "class":
  3312. e.className = v || ''; // Fix IE null bug
  3313. break;
  3314. case "src":
  3315. case "href":
  3316. if (s.keep_values) {
  3317. if (s.url_converter)
  3318. v = s.url_converter.call(s.url_converter_scope || t, v, n, e);
  3319. t.setAttrib(e, 'data-mce-' + n, v, 2);
  3320. }
  3321. break;
  3322. case "shape":
  3323. e.setAttribute('data-mce-style', v);
  3324. break;
  3325. }
  3326. }
  3327. if (is(v) && v !== null && v.length !== 0)
  3328. e.setAttribute(n, '' + v, 2);
  3329. else
  3330. e.removeAttribute(n, 2);
  3331. });
  3332. },
  3333. setAttribs : function(e, o) {
  3334. var t = this;
  3335. return this.run(e, function(e) {
  3336. each(o, function(v, n) {
  3337. t.setAttrib(e, n, v);
  3338. });
  3339. });
  3340. },
  3341. getAttrib : function(e, n, dv) {
  3342. var v, t = this, undef;
  3343. e = t.get(e);
  3344. if (!e || e.nodeType !== 1)
  3345. return dv === undef ? false : dv;
  3346. if (!is(dv))
  3347. dv = '';
  3348. // Try the mce variant for these
  3349. if (/^(src|href|style|coords|shape)$/.test(n)) {
  3350. v = e.getAttribute("data-mce-" + n);
  3351. if (v)
  3352. return v;
  3353. }
  3354. if (isIE && t.props[n]) {
  3355. v = e[t.props[n]];
  3356. v = v && v.nodeValue ? v.nodeValue : v;
  3357. }
  3358. if (!v)
  3359. v = e.getAttribute(n, 2);
  3360. // Check boolean attribs
  3361. if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(n)) {
  3362. if (e[t.props[n]] === true && v === '')
  3363. return n;
  3364. return v ? n : '';
  3365. }
  3366. // Inner input elements will override attributes on form elements
  3367. if (e.nodeName === "FORM" && e.getAttributeNode(n))
  3368. return e.getAttributeNode(n).nodeValue;
  3369. if (n === 'style') {
  3370. v = v || e.style.cssText;
  3371. if (v) {
  3372. v = t.serializeStyle(t.parseStyle(v), e.nodeName);
  3373. if (t.settings.keep_values && !t._isRes(v))
  3374. e.setAttribute('data-mce-style', v);
  3375. }
  3376. }
  3377. // Remove Apple and WebKit stuff
  3378. if (isWebKit && n === "class" && v)
  3379. v = v.replace(/(apple|webkit)\-[a-z\-]+/gi, '');
  3380. // Handle IE issues
  3381. if (isIE) {
  3382. switch (n) {
  3383. case 'rowspan':
  3384. case 'colspan':
  3385. // IE returns 1 as default value
  3386. if (v === 1)
  3387. v = '';
  3388. break;
  3389. case 'size':
  3390. // IE returns +0 as default value for size
  3391. if (v === '+0' || v === 20 || v === 0)
  3392. v = '';
  3393. break;
  3394. case 'width':
  3395. case 'height':
  3396. case 'vspace':
  3397. case 'checked':
  3398. case 'disabled':
  3399. case 'readonly':
  3400. if (v === 0)
  3401. v = '';
  3402. break;
  3403. case 'hspace':
  3404. // IE returns -1 as default value
  3405. if (v === -1)
  3406. v = '';
  3407. break;
  3408. case 'maxlength':
  3409. case 'tabindex':
  3410. // IE returns default value
  3411. if (v === 32768 || v === 2147483647 || v === '32768')
  3412. v = '';
  3413. break;
  3414. case 'multiple':
  3415. case 'compact':
  3416. case 'noshade':
  3417. case 'nowrap':
  3418. if (v === 65535)
  3419. return n;
  3420. return dv;
  3421. case 'shape':
  3422. v = v.toLowerCase();
  3423. break;
  3424. default:
  3425. // IE has odd anonymous function for event attributes
  3426. if (n.indexOf('on') === 0 && v)
  3427. v = tinymce._replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1', '' + v);
  3428. }
  3429. }
  3430. return (v !== undef && v !== null && v !== '') ? '' + v : dv;
  3431. },
  3432. getPos : function(n, ro) {
  3433. var t = this, x = 0, y = 0, e, d = t.doc, r;
  3434. n = t.get(n);
  3435. ro = ro || d.body;
  3436. if (n) {
  3437. // Use getBoundingClientRect if it exists since it's faster than looping offset nodes
  3438. if (n.getBoundingClientRect) {
  3439. n = n.getBoundingClientRect();
  3440. e = t.boxModel ? d.documentElement : d.body;
  3441. // Add scroll offsets from documentElement or body since IE with the wrong box model will use d.body and so do WebKit
  3442. // Also remove the body/documentelement clientTop/clientLeft on IE 6, 7 since they offset the position
  3443. x = n.left + (d.documentElement.scrollLeft || d.body.scrollLeft) - e.clientTop;
  3444. y = n.top + (d.documentElement.scrollTop || d.body.scrollTop) - e.clientLeft;
  3445. return {x : x, y : y};
  3446. }
  3447. r = n;
  3448. while (r && r != ro && r.nodeType) {
  3449. x += r.offsetLeft || 0;
  3450. y += r.offsetTop || 0;
  3451. r = r.offsetParent;
  3452. }
  3453. r = n.parentNode;
  3454. while (r && r != ro && r.nodeType) {
  3455. x -= r.scrollLeft || 0;
  3456. y -= r.scrollTop || 0;
  3457. r = r.parentNode;
  3458. }
  3459. }
  3460. return {x : x, y : y};
  3461. },
  3462. parseStyle : function(st) {
  3463. return this.styles.parse(st);
  3464. },
  3465. serializeStyle : function(o, name) {
  3466. return this.styles.serialize(o, name);
  3467. },
  3468. loadCSS : function(u) {
  3469. var t = this, d = t.doc, head;
  3470. if (!u)
  3471. u = '';
  3472. head = t.select('head')[0];
  3473. each(u.split(','), function(u) {
  3474. var link;
  3475. if (t.files[u])
  3476. return;
  3477. t.files[u] = true;
  3478. link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)});
  3479. // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug
  3480. // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading
  3481. // It's ugly but it seems to work fine.
  3482. if (isIE && d.documentMode && d.recalc) {
  3483. link.onload = function() {
  3484. if (d.recalc)
  3485. d.recalc();
  3486. link.onload = null;
  3487. };
  3488. }
  3489. head.appendChild(link);
  3490. });
  3491. },
  3492. addClass : function(e, c) {
  3493. return this.run(e, function(e) {
  3494. var o;
  3495. if (!c)
  3496. return 0;
  3497. if (this.hasClass(e, c))
  3498. return e.className;
  3499. o = this.removeClass(e, c);
  3500. return e.className = (o != '' ? (o + ' ') : '') + c;
  3501. });
  3502. },
  3503. removeClass : function(e, c) {
  3504. var t = this, re;
  3505. return t.run(e, function(e) {
  3506. var v;
  3507. if (t.hasClass(e, c)) {
  3508. if (!re)
  3509. re = new RegExp("(^|\\s+)" + c + "(\\s+|$)", "g");
  3510. v = e.className.replace(re, ' ');
  3511. v = tinymce.trim(v != ' ' ? v : '');
  3512. e.className = v;
  3513. // Empty class attr
  3514. if (!v) {
  3515. e.removeAttribute('class');
  3516. e.removeAttribute('className');
  3517. }
  3518. return v;
  3519. }
  3520. return e.className;
  3521. });
  3522. },
  3523. hasClass : function(n, c) {
  3524. n = this.get(n);
  3525. if (!n || !c)
  3526. return false;
  3527. return (' ' + n.className + ' ').indexOf(' ' + c + ' ') !== -1;
  3528. },
  3529. show : function(e) {
  3530. return this.setStyle(e, 'display', 'block');
  3531. },
  3532. hide : function(e) {
  3533. return this.setStyle(e, 'display', 'none');
  3534. },
  3535. isHidden : function(e) {
  3536. e = this.get(e);
  3537. return !e || e.style.display == 'none' || this.getStyle(e, 'display') == 'none';
  3538. },
  3539. uniqueId : function(p) {
  3540. return (!p ? 'mce_' : p) + (this.counter++);
  3541. },
  3542. setHTML : function(element, html) {
  3543. var self = this;
  3544. return self.run(element, function(element) {
  3545. if (isIE) {
  3546. // Remove all child nodes, IE keeps empty text nodes in DOM
  3547. while (element.firstChild)
  3548. element.removeChild(element.firstChild);
  3549. try {
  3550. // IE will remove comments from the beginning
  3551. // unless you padd the contents with something
  3552. element.innerHTML = '<br />' + html;
  3553. element.removeChild(element.firstChild);
  3554. } catch (ex) {
  3555. // 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
  3556. // This seems to fix this problem
  3557. // Create new div with HTML contents and a BR infront to keep comments
  3558. element = self.create('div');
  3559. element.innerHTML = '<br />' + html;
  3560. // Add all children from div to target
  3561. each (element.childNodes, function(node, i) {
  3562. // Skip br element
  3563. if (i)
  3564. element.appendChild(node);
  3565. });
  3566. }
  3567. } else
  3568. element.innerHTML = html;
  3569. return html;
  3570. });
  3571. },
  3572. getOuterHTML : function(elm) {
  3573. var doc, self = this;
  3574. elm = self.get(elm);
  3575. if (!elm)
  3576. return null;
  3577. if (elm.nodeType === 1 && self.hasOuterHTML)
  3578. return elm.outerHTML;
  3579. doc = (elm.ownerDocument || self.doc).createElement("body");
  3580. doc.appendChild(elm.cloneNode(true));
  3581. return doc.innerHTML;
  3582. },
  3583. setOuterHTML : function(e, h, d) {
  3584. var t = this;
  3585. function setHTML(e, h, d) {
  3586. var n, tp;
  3587. tp = d.createElement("body");
  3588. tp.innerHTML = h;
  3589. n = tp.lastChild;
  3590. while (n) {
  3591. t.insertAfter(n.cloneNode(true), e);
  3592. n = n.previousSibling;
  3593. }
  3594. t.remove(e);
  3595. };
  3596. return this.run(e, function(e) {
  3597. e = t.get(e);
  3598. // Only set HTML on elements
  3599. if (e.nodeType == 1) {
  3600. d = d || e.ownerDocument || t.doc;
  3601. if (isIE) {
  3602. try {
  3603. // Try outerHTML for IE it sometimes produces an unknown runtime error
  3604. if (isIE && e.nodeType == 1)
  3605. e.outerHTML = h;
  3606. else
  3607. setHTML(e, h, d);
  3608. } catch (ex) {
  3609. // Fix for unknown runtime error
  3610. setHTML(e, h, d);
  3611. }
  3612. } else
  3613. setHTML(e, h, d);
  3614. }
  3615. });
  3616. },
  3617. decode : Entities.decode,
  3618. encode : Entities.encodeAllRaw,
  3619. insertAfter : function(node, reference_node) {
  3620. reference_node = this.get(reference_node);
  3621. return this.run(node, function(node) {
  3622. var parent, nextSibling;
  3623. parent = reference_node.parentNode;
  3624. nextSibling = reference_node.nextSibling;
  3625. if (nextSibling)
  3626. parent.insertBefore(node, nextSibling);
  3627. else
  3628. parent.appendChild(node);
  3629. return node;
  3630. });
  3631. },
  3632. isBlock : function(node) {
  3633. var type = node.nodeType;
  3634. // If it's a node then check the type and use the nodeName
  3635. if (type)
  3636. return !!(type === 1 && blockElementsMap[node.nodeName]);
  3637. return !!blockElementsMap[node];
  3638. },
  3639. replace : function(n, o, k) {
  3640. var t = this;
  3641. if (is(o, 'array'))
  3642. n = n.cloneNode(true);
  3643. return t.run(o, function(o) {
  3644. if (k) {
  3645. each(tinymce.grep(o.childNodes), function(c) {
  3646. n.appendChild(c);
  3647. });
  3648. }
  3649. return o.parentNode.replaceChild(n, o);
  3650. });
  3651. },
  3652. rename : function(elm, name) {
  3653. var t = this, newElm;
  3654. if (elm.nodeName != name.toUpperCase()) {
  3655. // Rename block element
  3656. newElm = t.create(name);
  3657. // Copy attribs to new block
  3658. each(t.getAttribs(elm), function(attr_node) {
  3659. t.setAttrib(newElm, attr_node.nodeName, t.getAttrib(elm, attr_node.nodeName));
  3660. });
  3661. // Replace block
  3662. t.replace(newElm, elm, 1);
  3663. }
  3664. return newElm || elm;
  3665. },
  3666. findCommonAncestor : function(a, b) {
  3667. var ps = a, pe;
  3668. while (ps) {
  3669. pe = b;
  3670. while (pe && ps != pe)
  3671. pe = pe.parentNode;
  3672. if (ps == pe)
  3673. break;
  3674. ps = ps.parentNode;
  3675. }
  3676. if (!ps && a.ownerDocument)
  3677. return a.ownerDocument.documentElement;
  3678. return ps;
  3679. },
  3680. toHex : function(s) {
  3681. var c = /^\s*rgb\s*?\(\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?\)\s*$/i.exec(s);
  3682. function hex(s) {
  3683. s = parseInt(s).toString(16);
  3684. return s.length > 1 ? s : '0' + s; // 0 -> 00
  3685. };
  3686. if (c) {
  3687. s = '#' + hex(c[1]) + hex(c[2]) + hex(c[3]);
  3688. return s;
  3689. }
  3690. return s;
  3691. },
  3692. getClasses : function() {
  3693. var t = this, cl = [], i, lo = {}, f = t.settings.class_filter, ov;
  3694. if (t.classes)
  3695. return t.classes;
  3696. function addClasses(s) {
  3697. // IE style imports
  3698. each(s.imports, function(r) {
  3699. addClasses(r);
  3700. });
  3701. each(s.cssRules || s.rules, function(r) {
  3702. // Real type or fake it on IE
  3703. switch (r.type || 1) {
  3704. // Rule
  3705. case 1:
  3706. if (r.selectorText) {
  3707. each(r.selectorText.split(','), function(v) {
  3708. v = v.replace(/^\s*|\s*$|^\s\./g, "");
  3709. // Is internal or it doesn't contain a class
  3710. if (/\.mce/.test(v) || !/\.[\w\-]+$/.test(v))
  3711. return;
  3712. // Remove everything but class name
  3713. ov = v;
  3714. v = tinymce._replace(/.*\.([a-z0-9_\-]+).*/i, '$1', v);
  3715. // Filter classes
  3716. if (f && !(v = f(v, ov)))
  3717. return;
  3718. if (!lo[v]) {
  3719. cl.push({'class' : v});
  3720. lo[v] = 1;
  3721. }
  3722. });
  3723. }
  3724. break;
  3725. // Import
  3726. case 3:
  3727. addClasses(r.styleSheet);
  3728. break;
  3729. }
  3730. });
  3731. };
  3732. try {
  3733. each(t.doc.styleSheets, addClasses);
  3734. } catch (ex) {
  3735. // Ignore
  3736. }
  3737. if (cl.length > 0)
  3738. t.classes = cl;
  3739. return cl;
  3740. },
  3741. run : function(e, f, s) {
  3742. var t = this, o;
  3743. if (t.doc && typeof(e) === 'string')
  3744. e = t.get(e);
  3745. if (!e)
  3746. return false;
  3747. s = s || this;
  3748. if (!e.nodeType && (e.length || e.length === 0)) {
  3749. o = [];
  3750. each(e, function(e, i) {
  3751. if (e) {
  3752. if (typeof(e) == 'string')
  3753. e = t.doc.getElementById(e);
  3754. o.push(f.call(s, e, i));
  3755. }
  3756. });
  3757. return o;
  3758. }
  3759. return f.call(s, e);
  3760. },
  3761. getAttribs : function(n) {
  3762. var o;
  3763. n = this.get(n);
  3764. if (!n)
  3765. return [];
  3766. if (isIE) {
  3767. o = [];
  3768. // Object will throw exception in IE
  3769. if (n.nodeName == 'OBJECT')
  3770. return n.attributes;
  3771. // IE doesn't keep the selected attribute if you clone option elements
  3772. if (n.nodeName === 'OPTION' && this.getAttrib(n, 'selected'))
  3773. o.push({specified : 1, nodeName : 'selected'});
  3774. // It's crazy that this is faster in IE but it's because it returns all attributes all the time
  3775. n.cloneNode(false).outerHTML.replace(/<\/?[\w:\-]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=[\w\-]+|>/gi, '').replace(/[\w:\-]+/gi, function(a) {
  3776. o.push({specified : 1, nodeName : a});
  3777. });
  3778. return o;
  3779. }
  3780. return n.attributes;
  3781. },
  3782. isEmpty : function(node, elements) {
  3783. var self = this, i, attributes, type, walker, name, parentNode;
  3784. node = node.firstChild;
  3785. if (node) {
  3786. walker = new tinymce.dom.TreeWalker(node);
  3787. elements = elements || self.schema ? self.schema.getNonEmptyElements() : null;
  3788. do {
  3789. type = node.nodeType;
  3790. if (type === 1) {
  3791. // Ignore bogus elements
  3792. if (node.getAttribute('data-mce-bogus'))
  3793. continue;
  3794. // Keep empty elements like <img />
  3795. name = node.nodeName.toLowerCase();
  3796. if (elements && elements[name]) {
  3797. // Ignore single BR elements in blocks like <p><br /></p>
  3798. parentNode = node.parentNode;
  3799. if (name === 'br' && self.isBlock(parentNode) && parentNode.firstChild === node && parentNode.lastChild === node) {
  3800. continue;
  3801. }
  3802. return false;
  3803. }
  3804. // Keep elements with data-bookmark attributes or name attribute like <a name="1"></a>
  3805. attributes = self.getAttribs(node);
  3806. i = node.attributes.length;
  3807. while (i--) {
  3808. name = node.attributes[i].nodeName;
  3809. if (name === "name" || name === 'data-mce-bookmark')
  3810. return false;
  3811. }
  3812. }
  3813. // Keep non whitespace text nodes
  3814. if ((type === 3 && !whiteSpaceRegExp.test(node.nodeValue)))
  3815. return false;
  3816. } while (node = walker.next());
  3817. }
  3818. return true;
  3819. },
  3820. destroy : function(s) {
  3821. var t = this;
  3822. if (t.events)
  3823. t.events.destroy();
  3824. t.win = t.doc = t.root = t.events = null;
  3825. // Manual destroy then remove unload handler
  3826. if (!s)
  3827. tinymce.removeUnload(t.destroy);
  3828. },
  3829. createRng : function() {
  3830. var d = this.doc;
  3831. return d.createRange ? d.createRange() : new tinymce.dom.Range(this);
  3832. },
  3833. nodeIndex : function(node, normalized) {
  3834. var idx = 0, lastNodeType, lastNode, nodeType;
  3835. if (node) {
  3836. for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) {
  3837. nodeType = node.nodeType;
  3838. // Normalize text nodes
  3839. if (normalized && nodeType == 3) {
  3840. if (nodeType == lastNodeType || !node.nodeValue.length)
  3841. continue;
  3842. }
  3843. idx++;
  3844. lastNodeType = nodeType;
  3845. }
  3846. }
  3847. return idx;
  3848. },
  3849. split : function(pe, e, re) {
  3850. var t = this, r = t.createRng(), bef, aft, pa;
  3851. // W3C valid browsers tend to leave empty nodes to the left/right side of the contents, this makes sense
  3852. // but we don't want that in our code since it serves no purpose for the end user
  3853. // For example if this is chopped:
  3854. // <p>text 1<span><b>CHOP</b></span>text 2</p>
  3855. // would produce:
  3856. // <p>text 1<span></span></p><b>CHOP</b><p><span></span>text 2</p>
  3857. // this function will then trim of empty edges and produce:
  3858. // <p>text 1</p><b>CHOP</b><p>text 2</p>
  3859. function trim(node) {
  3860. var i, children = node.childNodes, type = node.nodeType;
  3861. if (type == 1 && node.getAttribute('data-mce-type') == 'bookmark')
  3862. return;
  3863. for (i = children.length - 1; i >= 0; i--)
  3864. trim(children[i]);
  3865. if (type != 9) {
  3866. // Keep non whitespace text nodes
  3867. if (type == 3 && node.nodeValue.length > 0) {
  3868. // If parent element isn't a block or there isn't any useful contents for example "<p> </p>"
  3869. if (!t.isBlock(node.parentNode) || tinymce.trim(node.nodeValue).length > 0)
  3870. return;
  3871. } else if (type == 1) {
  3872. // If the only child is a bookmark then move it up
  3873. children = node.childNodes;
  3874. if (children.length == 1 && children[0] && children[0].nodeType == 1 && children[0].getAttribute('data-mce-type') == 'bookmark')
  3875. node.parentNode.insertBefore(children[0], node);
  3876. // Keep non empty elements or img, hr etc
  3877. if (children.length || /^(br|hr|input|img)$/i.test(node.nodeName))
  3878. return;
  3879. }
  3880. t.remove(node);
  3881. }
  3882. return node;
  3883. };
  3884. if (pe && e) {
  3885. // Get before chunk
  3886. r.setStart(pe.parentNode, t.nodeIndex(pe));
  3887. r.setEnd(e.parentNode, t.nodeIndex(e));
  3888. bef = r.extractContents();
  3889. // Get after chunk
  3890. r = t.createRng();
  3891. r.setStart(e.parentNode, t.nodeIndex(e) + 1);
  3892. r.setEnd(pe.parentNode, t.nodeIndex(pe) + 1);
  3893. aft = r.extractContents();
  3894. // Insert before chunk
  3895. pa = pe.parentNode;
  3896. pa.insertBefore(trim(bef), pe);
  3897. // Insert middle chunk
  3898. if (re)
  3899. pa.replaceChild(re, e);
  3900. else
  3901. pa.insertBefore(e, pe);
  3902. // Insert after chunk
  3903. pa.insertBefore(trim(aft), pe);
  3904. t.remove(pe);
  3905. return re || e;
  3906. }
  3907. },
  3908. bind : function(target, name, func, scope) {
  3909. var t = this;
  3910. if (!t.events)
  3911. t.events = new tinymce.dom.EventUtils();
  3912. return t.events.add(target, name, func, scope || this);
  3913. },
  3914. unbind : function(target, name, func) {
  3915. var t = this;
  3916. if (!t.events)
  3917. t.events = new tinymce.dom.EventUtils();
  3918. return t.events.remove(target, name, func);
  3919. },
  3920. _findSib : function(node, selector, name) {
  3921. var t = this, f = selector;
  3922. if (node) {
  3923. // If expression make a function of it using is
  3924. if (is(f, 'string')) {
  3925. f = function(node) {
  3926. return t.is(node, selector);
  3927. };
  3928. }
  3929. // Loop all siblings
  3930. for (node = node[name]; node; node = node[name]) {
  3931. if (f(node))
  3932. return node;
  3933. }
  3934. }
  3935. return null;
  3936. },
  3937. _isRes : function(c) {
  3938. // Is live resizble element
  3939. return /^(top|left|bottom|right|width|height)/i.test(c) || /;\s*(top|left|bottom|right|width|height)/i.test(c);
  3940. }
  3941. /*
  3942. walk : function(n, f, s) {
  3943. var d = this.doc, w;
  3944. if (d.createTreeWalker) {
  3945. w = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false);
  3946. while ((n = w.nextNode()) != null)
  3947. f.call(s || this, n);
  3948. } else
  3949. tinymce.walk(n, f, 'childNodes', s);
  3950. }
  3951. */
  3952. /*
  3953. toRGB : function(s) {
  3954. var c = /^\s*?#([0-9A-F]{2})([0-9A-F]{1,2})([0-9A-F]{2})?\s*?$/.exec(s);
  3955. if (c) {
  3956. // #FFF -> #FFFFFF
  3957. if (!is(c[3]))
  3958. c[3] = c[2] = c[1];
  3959. return "rgb(" + parseInt(c[1], 16) + "," + parseInt(c[2], 16) + "," + parseInt(c[3], 16) + ")";
  3960. }
  3961. return s;
  3962. }
  3963. */
  3964. });
  3965. tinymce.DOM = new tinymce.dom.DOMUtils(document, {process_html : 0});
  3966. })(tinymce);
  3967. (function(ns) {
  3968. // Range constructor
  3969. function Range(dom) {
  3970. var t = this,
  3971. doc = dom.doc,
  3972. EXTRACT = 0,
  3973. CLONE = 1,
  3974. DELETE = 2,
  3975. TRUE = true,
  3976. FALSE = false,
  3977. START_OFFSET = 'startOffset',
  3978. START_CONTAINER = 'startContainer',
  3979. END_CONTAINER = 'endContainer',
  3980. END_OFFSET = 'endOffset',
  3981. extend = tinymce.extend,
  3982. nodeIndex = dom.nodeIndex;
  3983. extend(t, {
  3984. // Inital states
  3985. startContainer : doc,
  3986. startOffset : 0,
  3987. endContainer : doc,
  3988. endOffset : 0,
  3989. collapsed : TRUE,
  3990. commonAncestorContainer : doc,
  3991. // Range constants
  3992. START_TO_START : 0,
  3993. START_TO_END : 1,
  3994. END_TO_END : 2,
  3995. END_TO_START : 3,
  3996. // Public methods
  3997. setStart : setStart,
  3998. setEnd : setEnd,
  3999. setStartBefore : setStartBefore,
  4000. setStartAfter : setStartAfter,
  4001. setEndBefore : setEndBefore,
  4002. setEndAfter : setEndAfter,
  4003. collapse : collapse,
  4004. selectNode : selectNode,
  4005. selectNodeContents : selectNodeContents,
  4006. compareBoundaryPoints : compareBoundaryPoints,
  4007. deleteContents : deleteContents,
  4008. extractContents : extractContents,
  4009. cloneContents : cloneContents,
  4010. insertNode : insertNode,
  4011. surroundContents : surroundContents,
  4012. cloneRange : cloneRange
  4013. });
  4014. function setStart(n, o) {
  4015. _setEndPoint(TRUE, n, o);
  4016. };
  4017. function setEnd(n, o) {
  4018. _setEndPoint(FALSE, n, o);
  4019. };
  4020. function setStartBefore(n) {
  4021. setStart(n.parentNode, nodeIndex(n));
  4022. };
  4023. function setStartAfter(n) {
  4024. setStart(n.parentNode, nodeIndex(n) + 1);
  4025. };
  4026. function setEndBefore(n) {
  4027. setEnd(n.parentNode, nodeIndex(n));
  4028. };
  4029. function setEndAfter(n) {
  4030. setEnd(n.parentNode, nodeIndex(n) + 1);
  4031. };
  4032. function collapse(ts) {
  4033. if (ts) {
  4034. t[END_CONTAINER] = t[START_CONTAINER];
  4035. t[END_OFFSET] = t[START_OFFSET];
  4036. } else {
  4037. t[START_CONTAINER] = t[END_CONTAINER];
  4038. t[START_OFFSET] = t[END_OFFSET];
  4039. }
  4040. t.collapsed = TRUE;
  4041. };
  4042. function selectNode(n) {
  4043. setStartBefore(n);
  4044. setEndAfter(n);
  4045. };
  4046. function selectNodeContents(n) {
  4047. setStart(n, 0);
  4048. setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length);
  4049. };
  4050. function compareBoundaryPoints(h, r) {
  4051. var sc = t[START_CONTAINER], so = t[START_OFFSET], ec = t[END_CONTAINER], eo = t[END_OFFSET],
  4052. rsc = r.startContainer, rso = r.startOffset, rec = r.endContainer, reo = r.endOffset;
  4053. // Check START_TO_START
  4054. if (h === 0)
  4055. return _compareBoundaryPoints(sc, so, rsc, rso);
  4056. // Check START_TO_END
  4057. if (h === 1)
  4058. return _compareBoundaryPoints(ec, eo, rsc, rso);
  4059. // Check END_TO_END
  4060. if (h === 2)
  4061. return _compareBoundaryPoints(ec, eo, rec, reo);
  4062. // Check END_TO_START
  4063. if (h === 3)
  4064. return _compareBoundaryPoints(sc, so, rec, reo);
  4065. };
  4066. function deleteContents() {
  4067. _traverse(DELETE);
  4068. };
  4069. function extractContents() {
  4070. return _traverse(EXTRACT);
  4071. };
  4072. function cloneContents() {
  4073. return _traverse(CLONE);
  4074. };
  4075. function insertNode(n) {
  4076. var startContainer = this[START_CONTAINER],
  4077. startOffset = this[START_OFFSET], nn, o;
  4078. // Node is TEXT_NODE or CDATA
  4079. if ((startContainer.nodeType === 3 || startContainer.nodeType === 4) && startContainer.nodeValue) {
  4080. if (!startOffset) {
  4081. // At the start of text
  4082. startContainer.parentNode.insertBefore(n, startContainer);
  4083. } else if (startOffset >= startContainer.nodeValue.length) {
  4084. // At the end of text
  4085. dom.insertAfter(n, startContainer);
  4086. } else {
  4087. // Middle, need to split
  4088. nn = startContainer.splitText(startOffset);
  4089. startContainer.parentNode.insertBefore(n, nn);
  4090. }
  4091. } else {
  4092. // Insert element node
  4093. if (startContainer.childNodes.length > 0)
  4094. o = startContainer.childNodes[startOffset];
  4095. if (o)
  4096. startContainer.insertBefore(n, o);
  4097. else
  4098. startContainer.appendChild(n);
  4099. }
  4100. };
  4101. function surroundContents(n) {
  4102. var f = t.extractContents();
  4103. t.insertNode(n);
  4104. n.appendChild(f);
  4105. t.selectNode(n);
  4106. };
  4107. function cloneRange() {
  4108. return extend(new Range(dom), {
  4109. startContainer : t[START_CONTAINER],
  4110. startOffset : t[START_OFFSET],
  4111. endContainer : t[END_CONTAINER],
  4112. endOffset : t[END_OFFSET],
  4113. collapsed : t.collapsed,
  4114. commonAncestorContainer : t.commonAncestorContainer
  4115. });
  4116. };
  4117. // Private methods
  4118. function _getSelectedNode(container, offset) {
  4119. var child;
  4120. if (container.nodeType == 3 /* TEXT_NODE */)
  4121. return container;
  4122. if (offset < 0)
  4123. return container;
  4124. child = container.firstChild;
  4125. while (child && offset > 0) {
  4126. --offset;
  4127. child = child.nextSibling;
  4128. }
  4129. if (child)
  4130. return child;
  4131. return container;
  4132. };
  4133. function _isCollapsed() {
  4134. return (t[START_CONTAINER] == t[END_CONTAINER] && t[START_OFFSET] == t[END_OFFSET]);
  4135. };
  4136. function _compareBoundaryPoints(containerA, offsetA, containerB, offsetB) {
  4137. var c, offsetC, n, cmnRoot, childA, childB;
  4138. // In the first case the boundary-points have the same container. A is before B
  4139. // if its offset is less than the offset of B, A is equal to B if its offset is
  4140. // equal to the offset of B, and A is after B if its offset is greater than the
  4141. // offset of B.
  4142. if (containerA == containerB) {
  4143. if (offsetA == offsetB)
  4144. return 0; // equal
  4145. if (offsetA < offsetB)
  4146. return -1; // before
  4147. return 1; // after
  4148. }
  4149. // In the second case a child node C of the container of A is an ancestor
  4150. // container of B. In this case, A is before B if the offset of A is less than or
  4151. // equal to the index of the child node C and A is after B otherwise.
  4152. c = containerB;
  4153. while (c && c.parentNode != containerA)
  4154. c = c.parentNode;
  4155. if (c) {
  4156. offsetC = 0;
  4157. n = containerA.firstChild;
  4158. while (n != c && offsetC < offsetA) {
  4159. offsetC++;
  4160. n = n.nextSibling;
  4161. }
  4162. if (offsetA <= offsetC)
  4163. return -1; // before
  4164. return 1; // after
  4165. }
  4166. // In the third case a child node C of the container of B is an ancestor container
  4167. // of A. In this case, A is before B if the index of the child node C is less than
  4168. // the offset of B and A is after B otherwise.
  4169. c = containerA;
  4170. while (c && c.parentNode != containerB) {
  4171. c = c.parentNode;
  4172. }
  4173. if (c) {
  4174. offsetC = 0;
  4175. n = containerB.firstChild;
  4176. while (n != c && offsetC < offsetB) {
  4177. offsetC++;
  4178. n = n.nextSibling;
  4179. }
  4180. if (offsetC < offsetB)
  4181. return -1; // before
  4182. return 1; // after
  4183. }
  4184. // In the fourth case, none of three other cases hold: the containers of A and B
  4185. // are siblings or descendants of sibling nodes. In this case, A is before B if
  4186. // the container of A is before the container of B in a pre-order traversal of the
  4187. // Ranges' context tree and A is after B otherwise.
  4188. cmnRoot = dom.findCommonAncestor(containerA, containerB);
  4189. childA = containerA;
  4190. while (childA && childA.parentNode != cmnRoot)
  4191. childA = childA.parentNode;
  4192. if (!childA)
  4193. childA = cmnRoot;
  4194. childB = containerB;
  4195. while (childB && childB.parentNode != cmnRoot)
  4196. childB = childB.parentNode;
  4197. if (!childB)
  4198. childB = cmnRoot;
  4199. if (childA == childB)
  4200. return 0; // equal
  4201. n = cmnRoot.firstChild;
  4202. while (n) {
  4203. if (n == childA)
  4204. return -1; // before
  4205. if (n == childB)
  4206. return 1; // after
  4207. n = n.nextSibling;
  4208. }
  4209. };
  4210. function _setEndPoint(st, n, o) {
  4211. var ec, sc;
  4212. if (st) {
  4213. t[START_CONTAINER] = n;
  4214. t[START_OFFSET] = o;
  4215. } else {
  4216. t[END_CONTAINER] = n;
  4217. t[END_OFFSET] = o;
  4218. }
  4219. // If one boundary-point of a Range is set to have a root container
  4220. // other than the current one for the Range, the Range is collapsed to
  4221. // the new position. This enforces the restriction that both boundary-
  4222. // points of a Range must have the same root container.
  4223. ec = t[END_CONTAINER];
  4224. while (ec.parentNode)
  4225. ec = ec.parentNode;
  4226. sc = t[START_CONTAINER];
  4227. while (sc.parentNode)
  4228. sc = sc.parentNode;
  4229. if (sc == ec) {
  4230. // The start position of a Range is guaranteed to never be after the
  4231. // end position. To enforce this restriction, if the start is set to
  4232. // be at a position after the end, the Range is collapsed to that
  4233. // position.
  4234. if (_compareBoundaryPoints(t[START_CONTAINER], t[START_OFFSET], t[END_CONTAINER], t[END_OFFSET]) > 0)
  4235. t.collapse(st);
  4236. } else
  4237. t.collapse(st);
  4238. t.collapsed = _isCollapsed();
  4239. t.commonAncestorContainer = dom.findCommonAncestor(t[START_CONTAINER], t[END_CONTAINER]);
  4240. };
  4241. function _traverse(how) {
  4242. var c, endContainerDepth = 0, startContainerDepth = 0, p, depthDiff, startNode, endNode, sp, ep;
  4243. if (t[START_CONTAINER] == t[END_CONTAINER])
  4244. return _traverseSameContainer(how);
  4245. for (c = t[END_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  4246. if (p == t[START_CONTAINER])
  4247. return _traverseCommonStartContainer(c, how);
  4248. ++endContainerDepth;
  4249. }
  4250. for (c = t[START_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  4251. if (p == t[END_CONTAINER])
  4252. return _traverseCommonEndContainer(c, how);
  4253. ++startContainerDepth;
  4254. }
  4255. depthDiff = startContainerDepth - endContainerDepth;
  4256. startNode = t[START_CONTAINER];
  4257. while (depthDiff > 0) {
  4258. startNode = startNode.parentNode;
  4259. depthDiff--;
  4260. }
  4261. endNode = t[END_CONTAINER];
  4262. while (depthDiff < 0) {
  4263. endNode = endNode.parentNode;
  4264. depthDiff++;
  4265. }
  4266. // ascend the ancestor hierarchy until we have a common parent.
  4267. for (sp = startNode.parentNode, ep = endNode.parentNode; sp != ep; sp = sp.parentNode, ep = ep.parentNode) {
  4268. startNode = sp;
  4269. endNode = ep;
  4270. }
  4271. return _traverseCommonAncestors(startNode, endNode, how);
  4272. };
  4273. function _traverseSameContainer(how) {
  4274. var frag, s, sub, n, cnt, sibling, xferNode;
  4275. if (how != DELETE)
  4276. frag = doc.createDocumentFragment();
  4277. // If selection is empty, just return the fragment
  4278. if (t[START_OFFSET] == t[END_OFFSET])
  4279. return frag;
  4280. // Text node needs special case handling
  4281. if (t[START_CONTAINER].nodeType == 3 /* TEXT_NODE */) {
  4282. // get the substring
  4283. s = t[START_CONTAINER].nodeValue;
  4284. sub = s.substring(t[START_OFFSET], t[END_OFFSET]);
  4285. // set the original text node to its new value
  4286. if (how != CLONE) {
  4287. t[START_CONTAINER].deleteData(t[START_OFFSET], t[END_OFFSET] - t[START_OFFSET]);
  4288. // Nothing is partially selected, so collapse to start point
  4289. t.collapse(TRUE);
  4290. }
  4291. if (how == DELETE)
  4292. return;
  4293. frag.appendChild(doc.createTextNode(sub));
  4294. return frag;
  4295. }
  4296. // Copy nodes between the start/end offsets.
  4297. n = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]);
  4298. cnt = t[END_OFFSET] - t[START_OFFSET];
  4299. while (cnt > 0) {
  4300. sibling = n.nextSibling;
  4301. xferNode = _traverseFullySelected(n, how);
  4302. if (frag)
  4303. frag.appendChild( xferNode );
  4304. --cnt;
  4305. n = sibling;
  4306. }
  4307. // Nothing is partially selected, so collapse to start point
  4308. if (how != CLONE)
  4309. t.collapse(TRUE);
  4310. return frag;
  4311. };
  4312. function _traverseCommonStartContainer(endAncestor, how) {
  4313. var frag, n, endIdx, cnt, sibling, xferNode;
  4314. if (how != DELETE)
  4315. frag = doc.createDocumentFragment();
  4316. n = _traverseRightBoundary(endAncestor, how);
  4317. if (frag)
  4318. frag.appendChild(n);
  4319. endIdx = nodeIndex(endAncestor);
  4320. cnt = endIdx - t[START_OFFSET];
  4321. if (cnt <= 0) {
  4322. // Collapse to just before the endAncestor, which
  4323. // is partially selected.
  4324. if (how != CLONE) {
  4325. t.setEndBefore(endAncestor);
  4326. t.collapse(FALSE);
  4327. }
  4328. return frag;
  4329. }
  4330. n = endAncestor.previousSibling;
  4331. while (cnt > 0) {
  4332. sibling = n.previousSibling;
  4333. xferNode = _traverseFullySelected(n, how);
  4334. if (frag)
  4335. frag.insertBefore(xferNode, frag.firstChild);
  4336. --cnt;
  4337. n = sibling;
  4338. }
  4339. // Collapse to just before the endAncestor, which
  4340. // is partially selected.
  4341. if (how != CLONE) {
  4342. t.setEndBefore(endAncestor);
  4343. t.collapse(FALSE);
  4344. }
  4345. return frag;
  4346. };
  4347. function _traverseCommonEndContainer(startAncestor, how) {
  4348. var frag, startIdx, n, cnt, sibling, xferNode;
  4349. if (how != DELETE)
  4350. frag = doc.createDocumentFragment();
  4351. n = _traverseLeftBoundary(startAncestor, how);
  4352. if (frag)
  4353. frag.appendChild(n);
  4354. startIdx = nodeIndex(startAncestor);
  4355. ++startIdx; // Because we already traversed it
  4356. cnt = t[END_OFFSET] - startIdx;
  4357. n = startAncestor.nextSibling;
  4358. while (cnt > 0) {
  4359. sibling = n.nextSibling;
  4360. xferNode = _traverseFullySelected(n, how);
  4361. if (frag)
  4362. frag.appendChild(xferNode);
  4363. --cnt;
  4364. n = sibling;
  4365. }
  4366. if (how != CLONE) {
  4367. t.setStartAfter(startAncestor);
  4368. t.collapse(TRUE);
  4369. }
  4370. return frag;
  4371. };
  4372. function _traverseCommonAncestors(startAncestor, endAncestor, how) {
  4373. var n, frag, commonParent, startOffset, endOffset, cnt, sibling, nextSibling;
  4374. if (how != DELETE)
  4375. frag = doc.createDocumentFragment();
  4376. n = _traverseLeftBoundary(startAncestor, how);
  4377. if (frag)
  4378. frag.appendChild(n);
  4379. commonParent = startAncestor.parentNode;
  4380. startOffset = nodeIndex(startAncestor);
  4381. endOffset = nodeIndex(endAncestor);
  4382. ++startOffset;
  4383. cnt = endOffset - startOffset;
  4384. sibling = startAncestor.nextSibling;
  4385. while (cnt > 0) {
  4386. nextSibling = sibling.nextSibling;
  4387. n = _traverseFullySelected(sibling, how);
  4388. if (frag)
  4389. frag.appendChild(n);
  4390. sibling = nextSibling;
  4391. --cnt;
  4392. }
  4393. n = _traverseRightBoundary(endAncestor, how);
  4394. if (frag)
  4395. frag.appendChild(n);
  4396. if (how != CLONE) {
  4397. t.setStartAfter(startAncestor);
  4398. t.collapse(TRUE);
  4399. }
  4400. return frag;
  4401. };
  4402. function _traverseRightBoundary(root, how) {
  4403. var next = _getSelectedNode(t[END_CONTAINER], t[END_OFFSET] - 1), parent, clonedParent, prevSibling, clonedChild, clonedGrandParent, isFullySelected = next != t[END_CONTAINER];
  4404. if (next == root)
  4405. return _traverseNode(next, isFullySelected, FALSE, how);
  4406. parent = next.parentNode;
  4407. clonedParent = _traverseNode(parent, FALSE, FALSE, how);
  4408. while (parent) {
  4409. while (next) {
  4410. prevSibling = next.previousSibling;
  4411. clonedChild = _traverseNode(next, isFullySelected, FALSE, how);
  4412. if (how != DELETE)
  4413. clonedParent.insertBefore(clonedChild, clonedParent.firstChild);
  4414. isFullySelected = TRUE;
  4415. next = prevSibling;
  4416. }
  4417. if (parent == root)
  4418. return clonedParent;
  4419. next = parent.previousSibling;
  4420. parent = parent.parentNode;
  4421. clonedGrandParent = _traverseNode(parent, FALSE, FALSE, how);
  4422. if (how != DELETE)
  4423. clonedGrandParent.appendChild(clonedParent);
  4424. clonedParent = clonedGrandParent;
  4425. }
  4426. };
  4427. function _traverseLeftBoundary(root, how) {
  4428. var next = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]), isFullySelected = next != t[START_CONTAINER], parent, clonedParent, nextSibling, clonedChild, clonedGrandParent;
  4429. if (next == root)
  4430. return _traverseNode(next, isFullySelected, TRUE, how);
  4431. parent = next.parentNode;
  4432. clonedParent = _traverseNode(parent, FALSE, TRUE, how);
  4433. while (parent) {
  4434. while (next) {
  4435. nextSibling = next.nextSibling;
  4436. clonedChild = _traverseNode(next, isFullySelected, TRUE, how);
  4437. if (how != DELETE)
  4438. clonedParent.appendChild(clonedChild);
  4439. isFullySelected = TRUE;
  4440. next = nextSibling;
  4441. }
  4442. if (parent == root)
  4443. return clonedParent;
  4444. next = parent.nextSibling;
  4445. parent = parent.parentNode;
  4446. clonedGrandParent = _traverseNode(parent, FALSE, TRUE, how);
  4447. if (how != DELETE)
  4448. clonedGrandParent.appendChild(clonedParent);
  4449. clonedParent = clonedGrandParent;
  4450. }
  4451. };
  4452. function _traverseNode(n, isFullySelected, isLeft, how) {
  4453. var txtValue, newNodeValue, oldNodeValue, offset, newNode;
  4454. if (isFullySelected)
  4455. return _traverseFullySelected(n, how);
  4456. if (n.nodeType == 3 /* TEXT_NODE */) {
  4457. txtValue = n.nodeValue;
  4458. if (isLeft) {
  4459. offset = t[START_OFFSET];
  4460. newNodeValue = txtValue.substring(offset);
  4461. oldNodeValue = txtValue.substring(0, offset);
  4462. } else {
  4463. offset = t[END_OFFSET];
  4464. newNodeValue = txtValue.substring(0, offset);
  4465. oldNodeValue = txtValue.substring(offset);
  4466. }
  4467. if (how != CLONE)
  4468. n.nodeValue = oldNodeValue;
  4469. if (how == DELETE)
  4470. return;
  4471. newNode = n.cloneNode(FALSE);
  4472. newNode.nodeValue = newNodeValue;
  4473. return newNode;
  4474. }
  4475. if (how == DELETE)
  4476. return;
  4477. return n.cloneNode(FALSE);
  4478. };
  4479. function _traverseFullySelected(n, how) {
  4480. if (how != DELETE)
  4481. return how == CLONE ? n.cloneNode(TRUE) : n;
  4482. n.parentNode.removeChild(n);
  4483. };
  4484. };
  4485. ns.Range = Range;
  4486. })(tinymce.dom);
  4487. (function() {
  4488. function Selection(selection) {
  4489. var self = this, dom = selection.dom, TRUE = true, FALSE = false;
  4490. function getPosition(rng, start) {
  4491. var checkRng, startIndex = 0, endIndex, inside,
  4492. children, child, offset, index, position = -1, parent;
  4493. // Setup test range, collapse it and get the parent
  4494. checkRng = rng.duplicate();
  4495. checkRng.collapse(start);
  4496. parent = checkRng.parentElement();
  4497. // Check if the selection is within the right document
  4498. if (parent.ownerDocument !== selection.dom.doc)
  4499. return;
  4500. // IE will report non editable elements as it's parent so look for an editable one
  4501. while (parent.contentEditable === "false") {
  4502. parent = parent.parentNode;
  4503. }
  4504. // If parent doesn't have any children then return that we are inside the element
  4505. if (!parent.hasChildNodes()) {
  4506. return {node : parent, inside : 1};
  4507. }
  4508. // Setup node list and endIndex
  4509. children = parent.children;
  4510. endIndex = children.length - 1;
  4511. // Perform a binary search for the position
  4512. while (startIndex <= endIndex) {
  4513. index = Math.floor((startIndex + endIndex) / 2);
  4514. // Move selection to node and compare the ranges
  4515. child = children[index];
  4516. checkRng.moveToElementText(child);
  4517. position = checkRng.compareEndPoints(start ? 'StartToStart' : 'EndToEnd', rng);
  4518. // Before/after or an exact match
  4519. if (position > 0) {
  4520. endIndex = index - 1;
  4521. } else if (position < 0) {
  4522. startIndex = index + 1;
  4523. } else {
  4524. return {node : child};
  4525. }
  4526. }
  4527. // Check if child position is before or we didn't find a position
  4528. if (position < 0) {
  4529. // No element child was found use the parent element and the offset inside that
  4530. if (!child) {
  4531. checkRng.moveToElementText(parent);
  4532. checkRng.collapse(true);
  4533. child = parent;
  4534. inside = true;
  4535. } else
  4536. checkRng.collapse(false);
  4537. checkRng.setEndPoint(start ? 'EndToStart' : 'EndToEnd', rng);
  4538. // Fix for edge case: <div style="width: 100px; height:100px;"><table>..</table>ab|c</div>
  4539. if (checkRng.compareEndPoints(start ? 'StartToStart' : 'StartToEnd', rng) > 0) {
  4540. checkRng = rng.duplicate();
  4541. checkRng.collapse(start);
  4542. offset = -1;
  4543. while (parent == checkRng.parentElement()) {
  4544. if (checkRng.move('character', -1) == 0)
  4545. break;
  4546. offset++;
  4547. }
  4548. }
  4549. offset = offset || checkRng.text.replace('\r\n', ' ').length;
  4550. } else {
  4551. // Child position is after the selection endpoint
  4552. checkRng.collapse(true);
  4553. checkRng.setEndPoint(start ? 'StartToStart' : 'StartToEnd', rng);
  4554. // Get the length of the text to find where the endpoint is relative to it's container
  4555. offset = checkRng.text.replace('\r\n', ' ').length;
  4556. }
  4557. return {node : child, position : position, offset : offset, inside : inside};
  4558. };
  4559. // Returns a W3C DOM compatible range object by using the IE Range API
  4560. function getRange() {
  4561. var ieRange = selection.getRng(), domRange = dom.createRng(), element, collapsed, tmpRange, element2, bookmark, fail;
  4562. // If selection is outside the current document just return an empty range
  4563. element = ieRange.item ? ieRange.item(0) : ieRange.parentElement();
  4564. if (element.ownerDocument != dom.doc)
  4565. return domRange;
  4566. collapsed = selection.isCollapsed();
  4567. // Handle control selection
  4568. if (ieRange.item) {
  4569. domRange.setStart(element.parentNode, dom.nodeIndex(element));
  4570. domRange.setEnd(domRange.startContainer, domRange.startOffset + 1);
  4571. return domRange;
  4572. }
  4573. function findEndPoint(start) {
  4574. var endPoint = getPosition(ieRange, start), container, offset, textNodeOffset = 0, sibling, undef, nodeValue;
  4575. container = endPoint.node;
  4576. offset = endPoint.offset;
  4577. if (endPoint.inside && !container.hasChildNodes()) {
  4578. domRange[start ? 'setStart' : 'setEnd'](container, 0);
  4579. return;
  4580. }
  4581. if (offset === undef) {
  4582. domRange[start ? 'setStartBefore' : 'setEndAfter'](container);
  4583. return;
  4584. }
  4585. if (endPoint.position < 0) {
  4586. sibling = endPoint.inside ? container.firstChild : container.nextSibling;
  4587. if (!sibling) {
  4588. domRange[start ? 'setStartAfter' : 'setEndAfter'](container);
  4589. return;
  4590. }
  4591. if (!offset) {
  4592. if (sibling.nodeType == 3)
  4593. domRange[start ? 'setStart' : 'setEnd'](sibling, 0);
  4594. else
  4595. domRange[start ? 'setStartBefore' : 'setEndBefore'](sibling);
  4596. return;
  4597. }
  4598. // Find the text node and offset
  4599. while (sibling) {
  4600. nodeValue = sibling.nodeValue;
  4601. textNodeOffset += nodeValue.length;
  4602. // We are at or passed the position we where looking for
  4603. if (textNodeOffset >= offset) {
  4604. container = sibling;
  4605. textNodeOffset -= offset;
  4606. textNodeOffset = nodeValue.length - textNodeOffset;
  4607. break;
  4608. }
  4609. sibling = sibling.nextSibling;
  4610. }
  4611. } else {
  4612. // Find the text node and offset
  4613. sibling = container.previousSibling;
  4614. if (!sibling)
  4615. return domRange[start ? 'setStartBefore' : 'setEndBefore'](container);
  4616. // If there isn't any text to loop then use the first position
  4617. if (!offset) {
  4618. if (container.nodeType == 3)
  4619. domRange[start ? 'setStart' : 'setEnd'](sibling, container.nodeValue.length);
  4620. else
  4621. domRange[start ? 'setStartAfter' : 'setEndAfter'](sibling);
  4622. return;
  4623. }
  4624. while (sibling) {
  4625. textNodeOffset += sibling.nodeValue.length;
  4626. // We are at or passed the position we where looking for
  4627. if (textNodeOffset >= offset) {
  4628. container = sibling;
  4629. textNodeOffset -= offset;
  4630. break;
  4631. }
  4632. sibling = sibling.previousSibling;
  4633. }
  4634. }
  4635. domRange[start ? 'setStart' : 'setEnd'](container, textNodeOffset);
  4636. };
  4637. try {
  4638. // Find start point
  4639. findEndPoint(true);
  4640. // Find end point if needed
  4641. if (!collapsed)
  4642. findEndPoint();
  4643. } catch (ex) {
  4644. // IE has a nasty bug where text nodes might throw "invalid argument" when you
  4645. // access the nodeValue or other properties of text nodes. This seems to happend when
  4646. // text nodes are split into two nodes by a delete/backspace call. So lets detect it and try to fix it.
  4647. if (ex.number == -2147024809) {
  4648. // Get the current selection
  4649. bookmark = self.getBookmark(2);
  4650. // Get start element
  4651. tmpRange = ieRange.duplicate();
  4652. tmpRange.collapse(true);
  4653. element = tmpRange.parentElement();
  4654. // Get end element
  4655. if (!collapsed) {
  4656. tmpRange = ieRange.duplicate();
  4657. tmpRange.collapse(false);
  4658. element2 = tmpRange.parentElement();
  4659. element2.innerHTML = element2.innerHTML;
  4660. }
  4661. // Remove the broken elements
  4662. element.innerHTML = element.innerHTML;
  4663. // Restore the selection
  4664. self.moveToBookmark(bookmark);
  4665. // Since the range has moved we need to re-get it
  4666. ieRange = selection.getRng();
  4667. // Find start point
  4668. findEndPoint(true);
  4669. // Find end point if needed
  4670. if (!collapsed)
  4671. findEndPoint();
  4672. } else
  4673. throw ex; // Throw other errors
  4674. }
  4675. return domRange;
  4676. };
  4677. this.getBookmark = function(type) {
  4678. var rng = selection.getRng(), start, end, bookmark = {};
  4679. function getIndexes(node) {
  4680. var node, parent, root, children, i, indexes = [];
  4681. parent = node.parentNode;
  4682. root = dom.getRoot().parentNode;
  4683. while (parent != root && parent.nodeType !== 9) {
  4684. children = parent.children;
  4685. i = children.length;
  4686. while (i--) {
  4687. if (node === children[i]) {
  4688. indexes.push(i);
  4689. break;
  4690. }
  4691. }
  4692. node = parent;
  4693. parent = parent.parentNode;
  4694. }
  4695. return indexes;
  4696. };
  4697. function getBookmarkEndPoint(start) {
  4698. var position;
  4699. position = getPosition(rng, start);
  4700. if (position) {
  4701. return {
  4702. position : position.position,
  4703. offset : position.offset,
  4704. indexes : getIndexes(position.node),
  4705. inside : position.inside
  4706. };
  4707. }
  4708. };
  4709. // Non ubstructive bookmark
  4710. if (type === 2) {
  4711. // Handle text selection
  4712. if (!rng.item) {
  4713. bookmark.start = getBookmarkEndPoint(true);
  4714. if (!selection.isCollapsed())
  4715. bookmark.end = getBookmarkEndPoint();
  4716. } else
  4717. bookmark.start = {ctrl : true, indexes : getIndexes(rng.item(0))};
  4718. }
  4719. return bookmark;
  4720. };
  4721. this.moveToBookmark = function(bookmark) {
  4722. var rng, body = dom.doc.body;
  4723. function resolveIndexes(indexes) {
  4724. var node, i, idx, children;
  4725. node = dom.getRoot();
  4726. for (i = indexes.length - 1; i >= 0; i--) {
  4727. children = node.children;
  4728. idx = indexes[i];
  4729. if (idx <= children.length - 1) {
  4730. node = children[idx];
  4731. }
  4732. }
  4733. return node;
  4734. };
  4735. function setBookmarkEndPoint(start) {
  4736. var endPoint = bookmark[start ? 'start' : 'end'], moveLeft, moveRng, undef;
  4737. if (endPoint) {
  4738. moveLeft = endPoint.position > 0;
  4739. moveRng = body.createTextRange();
  4740. moveRng.moveToElementText(resolveIndexes(endPoint.indexes));
  4741. offset = endPoint.offset;
  4742. if (offset !== undef) {
  4743. moveRng.collapse(endPoint.inside || moveLeft);
  4744. moveRng.moveStart('character', moveLeft ? -offset : offset);
  4745. } else
  4746. moveRng.collapse(start);
  4747. rng.setEndPoint(start ? 'StartToStart' : 'EndToStart', moveRng);
  4748. if (start)
  4749. rng.collapse(true);
  4750. }
  4751. };
  4752. if (bookmark.start) {
  4753. if (bookmark.start.ctrl) {
  4754. rng = body.createControlRange();
  4755. rng.addElement(resolveIndexes(bookmark.start.indexes));
  4756. rng.select();
  4757. } else {
  4758. rng = body.createTextRange();
  4759. setBookmarkEndPoint(true);
  4760. setBookmarkEndPoint();
  4761. rng.select();
  4762. }
  4763. }
  4764. };
  4765. this.addRange = function(rng) {
  4766. var ieRng, ctrlRng, startContainer, startOffset, endContainer, endOffset, doc = selection.dom.doc, body = doc.body;
  4767. function setEndPoint(start) {
  4768. var container, offset, marker, tmpRng, nodes;
  4769. marker = dom.create('a');
  4770. container = start ? startContainer : endContainer;
  4771. offset = start ? startOffset : endOffset;
  4772. tmpRng = ieRng.duplicate();
  4773. if (container == doc || container == doc.documentElement) {
  4774. container = body;
  4775. offset = 0;
  4776. }
  4777. if (container.nodeType == 3) {
  4778. container.parentNode.insertBefore(marker, container);
  4779. tmpRng.moveToElementText(marker);
  4780. tmpRng.moveStart('character', offset);
  4781. dom.remove(marker);
  4782. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  4783. } else {
  4784. nodes = container.childNodes;
  4785. if (nodes.length) {
  4786. if (offset >= nodes.length) {
  4787. dom.insertAfter(marker, nodes[nodes.length - 1]);
  4788. } else {
  4789. container.insertBefore(marker, nodes[offset]);
  4790. }
  4791. tmpRng.moveToElementText(marker);
  4792. } else {
  4793. // Empty node selection for example <div>|</div>
  4794. marker = doc.createTextNode('\uFEFF');
  4795. container.appendChild(marker);
  4796. tmpRng.moveToElementText(marker.parentNode);
  4797. tmpRng.collapse(TRUE);
  4798. }
  4799. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  4800. dom.remove(marker);
  4801. }
  4802. }
  4803. // Setup some shorter versions
  4804. startContainer = rng.startContainer;
  4805. startOffset = rng.startOffset;
  4806. endContainer = rng.endContainer;
  4807. endOffset = rng.endOffset;
  4808. ieRng = body.createTextRange();
  4809. // If single element selection then try making a control selection out of it
  4810. if (startContainer == endContainer && startContainer.nodeType == 1 && startOffset == endOffset - 1) {
  4811. if (startOffset == endOffset - 1) {
  4812. try {
  4813. ctrlRng = body.createControlRange();
  4814. ctrlRng.addElement(startContainer.childNodes[startOffset]);
  4815. ctrlRng.select();
  4816. return;
  4817. } catch (ex) {
  4818. // Ignore
  4819. }
  4820. }
  4821. }
  4822. // Set start/end point of selection
  4823. setEndPoint(true);
  4824. setEndPoint();
  4825. // Select the new range and scroll it into view
  4826. ieRng.select();
  4827. };
  4828. // Expose range method
  4829. this.getRangeAt = getRange;
  4830. };
  4831. // Expose the selection object
  4832. tinymce.dom.TridentSelection = Selection;
  4833. })();
  4834. (function(tinymce) {
  4835. // Shorten names
  4836. var each = tinymce.each, DOM = tinymce.DOM, isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, Event;
  4837. tinymce.create('tinymce.dom.EventUtils', {
  4838. EventUtils : function() {
  4839. this.inits = [];
  4840. this.events = [];
  4841. },
  4842. add : function(o, n, f, s) {
  4843. var cb, t = this, el = t.events, r;
  4844. if (n instanceof Array) {
  4845. r = [];
  4846. each(n, function(n) {
  4847. r.push(t.add(o, n, f, s));
  4848. });
  4849. return r;
  4850. }
  4851. // Handle array
  4852. if (o && o.hasOwnProperty && o instanceof Array) {
  4853. r = [];
  4854. each(o, function(o) {
  4855. o = DOM.get(o);
  4856. r.push(t.add(o, n, f, s));
  4857. });
  4858. return r;
  4859. }
  4860. o = DOM.get(o);
  4861. if (!o)
  4862. return;
  4863. // Setup event callback
  4864. cb = function(e) {
  4865. // Is all events disabled
  4866. if (t.disabled)
  4867. return;
  4868. e = e || window.event;
  4869. // Patch in target, preventDefault and stopPropagation in IE it's W3C valid
  4870. if (e && isIE) {
  4871. if (!e.target)
  4872. e.target = e.srcElement;
  4873. // Patch in preventDefault, stopPropagation methods for W3C compatibility
  4874. tinymce.extend(e, t._stoppers);
  4875. }
  4876. if (!s)
  4877. return f(e);
  4878. return f.call(s, e);
  4879. };
  4880. if (n == 'unload') {
  4881. tinymce.unloads.unshift({func : cb});
  4882. return cb;
  4883. }
  4884. if (n == 'init') {
  4885. if (t.domLoaded)
  4886. cb();
  4887. else
  4888. t.inits.push(cb);
  4889. return cb;
  4890. }
  4891. // Store away listener reference
  4892. el.push({
  4893. obj : o,
  4894. name : n,
  4895. func : f,
  4896. cfunc : cb,
  4897. scope : s
  4898. });
  4899. t._add(o, n, cb);
  4900. return f;
  4901. },
  4902. remove : function(o, n, f) {
  4903. var t = this, a = t.events, s = false, r;
  4904. // Handle array
  4905. if (o && o.hasOwnProperty && o instanceof Array) {
  4906. r = [];
  4907. each(o, function(o) {
  4908. o = DOM.get(o);
  4909. r.push(t.remove(o, n, f));
  4910. });
  4911. return r;
  4912. }
  4913. o = DOM.get(o);
  4914. each(a, function(e, i) {
  4915. if (e.obj == o && e.name == n && (!f || (e.func == f || e.cfunc == f))) {
  4916. a.splice(i, 1);
  4917. t._remove(o, n, e.cfunc);
  4918. s = true;
  4919. return false;
  4920. }
  4921. });
  4922. return s;
  4923. },
  4924. clear : function(o) {
  4925. var t = this, a = t.events, i, e;
  4926. if (o) {
  4927. o = DOM.get(o);
  4928. for (i = a.length - 1; i >= 0; i--) {
  4929. e = a[i];
  4930. if (e.obj === o) {
  4931. t._remove(e.obj, e.name, e.cfunc);
  4932. e.obj = e.cfunc = null;
  4933. a.splice(i, 1);
  4934. }
  4935. }
  4936. }
  4937. },
  4938. cancel : function(e) {
  4939. if (!e)
  4940. return false;
  4941. this.stop(e);
  4942. return this.prevent(e);
  4943. },
  4944. stop : function(e) {
  4945. if (e.stopPropagation)
  4946. e.stopPropagation();
  4947. else
  4948. e.cancelBubble = true;
  4949. return false;
  4950. },
  4951. prevent : function(e) {
  4952. if (e.preventDefault)
  4953. e.preventDefault();
  4954. else
  4955. e.returnValue = false;
  4956. return false;
  4957. },
  4958. destroy : function() {
  4959. var t = this;
  4960. each(t.events, function(e, i) {
  4961. t._remove(e.obj, e.name, e.cfunc);
  4962. e.obj = e.cfunc = null;
  4963. });
  4964. t.events = [];
  4965. t = null;
  4966. },
  4967. _add : function(o, n, f) {
  4968. if (o.attachEvent)
  4969. o.attachEvent('on' + n, f);
  4970. else if (o.addEventListener)
  4971. o.addEventListener(n, f, false);
  4972. else
  4973. o['on' + n] = f;
  4974. },
  4975. _remove : function(o, n, f) {
  4976. if (o) {
  4977. try {
  4978. if (o.detachEvent)
  4979. o.detachEvent('on' + n, f);
  4980. else if (o.removeEventListener)
  4981. o.removeEventListener(n, f, false);
  4982. else
  4983. o['on' + n] = null;
  4984. } catch (ex) {
  4985. // Might fail with permission denined on IE so we just ignore that
  4986. }
  4987. }
  4988. },
  4989. _pageInit : function(win) {
  4990. var t = this;
  4991. // Keep it from running more than once
  4992. if (t.domLoaded)
  4993. return;
  4994. t.domLoaded = true;
  4995. each(t.inits, function(c) {
  4996. c();
  4997. });
  4998. t.inits = [];
  4999. },
  5000. _wait : function(win) {
  5001. var t = this, doc = win.document;
  5002. // No need since the document is already loaded
  5003. if (win.tinyMCE_GZ && tinyMCE_GZ.loaded) {
  5004. t.domLoaded = 1;
  5005. return;
  5006. }
  5007. // Use IE method
  5008. if (doc.attachEvent) {
  5009. doc.attachEvent("onreadystatechange", function() {
  5010. if (doc.readyState === "complete") {
  5011. doc.detachEvent("onreadystatechange", arguments.callee);
  5012. t._pageInit(win);
  5013. }
  5014. });
  5015. if (doc.documentElement.doScroll && win == win.top) {
  5016. (function() {
  5017. if (t.domLoaded)
  5018. return;
  5019. try {
  5020. // If IE is used, use the trick by Diego Perini licensed under MIT by request to the author.
  5021. // http://javascript.nwbox.com/IEContentLoaded/
  5022. doc.documentElement.doScroll("left");
  5023. } catch (ex) {
  5024. setTimeout(arguments.callee, 0);
  5025. return;
  5026. }
  5027. t._pageInit(win);
  5028. })();
  5029. }
  5030. } else if (doc.addEventListener) {
  5031. t._add(win, 'DOMContentLoaded', function() {
  5032. t._pageInit(win);
  5033. });
  5034. }
  5035. t._add(win, 'load', function() {
  5036. t._pageInit(win);
  5037. });
  5038. },
  5039. _stoppers : {
  5040. preventDefault : function() {
  5041. this.returnValue = false;
  5042. },
  5043. stopPropagation : function() {
  5044. this.cancelBubble = true;
  5045. }
  5046. }
  5047. });
  5048. Event = tinymce.dom.Event = new tinymce.dom.EventUtils();
  5049. // Dispatch DOM content loaded event for IE and Safari
  5050. Event._wait(window);
  5051. tinymce.addUnload(function() {
  5052. Event.destroy();
  5053. });
  5054. })(tinymce);
  5055. (function(tinymce) {
  5056. tinymce.dom.Element = function(id, settings) {
  5057. var t = this, dom, el;
  5058. t.settings = settings = settings || {};
  5059. t.id = id;
  5060. t.dom = dom = settings.dom || tinymce.DOM;
  5061. // Only IE leaks DOM references, this is a lot faster
  5062. if (!tinymce.isIE)
  5063. el = dom.get(t.id);
  5064. tinymce.each(
  5065. ('getPos,getRect,getParent,add,setStyle,getStyle,setStyles,' +
  5066. 'setAttrib,setAttribs,getAttrib,addClass,removeClass,' +
  5067. 'hasClass,getOuterHTML,setOuterHTML,remove,show,hide,' +
  5068. 'isHidden,setHTML,get').split(/,/)
  5069. , function(k) {
  5070. t[k] = function() {
  5071. var a = [id], i;
  5072. for (i = 0; i < arguments.length; i++)
  5073. a.push(arguments[i]);
  5074. a = dom[k].apply(dom, a);
  5075. t.update(k);
  5076. return a;
  5077. };
  5078. });
  5079. tinymce.extend(t, {
  5080. on : function(n, f, s) {
  5081. return tinymce.dom.Event.add(t.id, n, f, s);
  5082. },
  5083. getXY : function() {
  5084. return {
  5085. x : parseInt(t.getStyle('left')),
  5086. y : parseInt(t.getStyle('top'))
  5087. };
  5088. },
  5089. getSize : function() {
  5090. var n = dom.get(t.id);
  5091. return {
  5092. w : parseInt(t.getStyle('width') || n.clientWidth),
  5093. h : parseInt(t.getStyle('height') || n.clientHeight)
  5094. };
  5095. },
  5096. moveTo : function(x, y) {
  5097. t.setStyles({left : x, top : y});
  5098. },
  5099. moveBy : function(x, y) {
  5100. var p = t.getXY();
  5101. t.moveTo(p.x + x, p.y + y);
  5102. },
  5103. resizeTo : function(w, h) {
  5104. t.setStyles({width : w, height : h});
  5105. },
  5106. resizeBy : function(w, h) {
  5107. var s = t.getSize();
  5108. t.resizeTo(s.w + w, s.h + h);
  5109. },
  5110. update : function(k) {
  5111. var b;
  5112. if (tinymce.isIE6 && settings.blocker) {
  5113. k = k || '';
  5114. // Ignore getters
  5115. if (k.indexOf('get') === 0 || k.indexOf('has') === 0 || k.indexOf('is') === 0)
  5116. return;
  5117. // Remove blocker on remove
  5118. if (k == 'remove') {
  5119. dom.remove(t.blocker);
  5120. return;
  5121. }
  5122. if (!t.blocker) {
  5123. t.blocker = dom.uniqueId();
  5124. b = dom.add(settings.container || dom.getRoot(), 'iframe', {id : t.blocker, style : 'position:absolute;', frameBorder : 0, src : 'javascript:""'});
  5125. dom.setStyle(b, 'opacity', 0);
  5126. } else
  5127. b = dom.get(t.blocker);
  5128. dom.setStyles(b, {
  5129. left : t.getStyle('left', 1),
  5130. top : t.getStyle('top', 1),
  5131. width : t.getStyle('width', 1),
  5132. height : t.getStyle('height', 1),
  5133. display : t.getStyle('display', 1),
  5134. zIndex : parseInt(t.getStyle('zIndex', 1) || 0) - 1
  5135. });
  5136. }
  5137. }
  5138. });
  5139. };
  5140. })(tinymce);
  5141. (function(tinymce) {
  5142. function trimNl(s) {
  5143. return s.replace(/[\n\r]+/g, '');
  5144. };
  5145. // Shorten names
  5146. var is = tinymce.is, isIE = tinymce.isIE, each = tinymce.each;
  5147. tinymce.create('tinymce.dom.Selection', {
  5148. Selection : function(dom, win, serializer) {
  5149. var t = this;
  5150. t.dom = dom;
  5151. t.win = win;
  5152. t.serializer = serializer;
  5153. // Add events
  5154. each([
  5155. 'onBeforeSetContent',
  5156. 'onBeforeGetContent',
  5157. 'onSetContent',
  5158. 'onGetContent'
  5159. ], function(e) {
  5160. t[e] = new tinymce.util.Dispatcher(t);
  5161. });
  5162. // No W3C Range support
  5163. if (!t.win.getSelection)
  5164. t.tridentSel = new tinymce.dom.TridentSelection(t);
  5165. if (tinymce.isIE && dom.boxModel)
  5166. this._fixIESelection();
  5167. // Prevent leaks
  5168. tinymce.addUnload(t.destroy, t);
  5169. },
  5170. setCursorLocation: function(node, offset) {
  5171. var t = this; var r = t.dom.createRng();
  5172. r.setStart(node, offset);
  5173. r.setEnd(node, offset);
  5174. t.setRng(r);
  5175. t.collapse(false);
  5176. },
  5177. getContent : function(s) {
  5178. var t = this, r = t.getRng(), e = t.dom.create("body"), se = t.getSel(), wb, wa, n;
  5179. s = s || {};
  5180. wb = wa = '';
  5181. s.get = true;
  5182. s.format = s.format || 'html';
  5183. s.forced_root_block = '';
  5184. t.onBeforeGetContent.dispatch(t, s);
  5185. if (s.format == 'text')
  5186. return t.isCollapsed() ? '' : (r.text || (se.toString ? se.toString() : ''));
  5187. if (r.cloneContents) {
  5188. n = r.cloneContents();
  5189. if (n)
  5190. e.appendChild(n);
  5191. } else if (is(r.item) || is(r.htmlText)) {
  5192. // IE will produce invalid markup if elements are present that
  5193. // it doesn't understand like custom elements or HTML5 elements.
  5194. // Adding a BR in front of the contents and then remoiving it seems to fix it though.
  5195. e.innerHTML = '<br>' + (r.item ? r.item(0).outerHTML : r.htmlText);
  5196. e.removeChild(e.firstChild);
  5197. } else
  5198. e.innerHTML = r.toString();
  5199. // Keep whitespace before and after
  5200. if (/^\s/.test(e.innerHTML))
  5201. wb = ' ';
  5202. if (/\s+$/.test(e.innerHTML))
  5203. wa = ' ';
  5204. s.getInner = true;
  5205. s.content = t.isCollapsed() ? '' : wb + t.serializer.serialize(e, s) + wa;
  5206. t.onGetContent.dispatch(t, s);
  5207. return s.content;
  5208. },
  5209. setContent : function(content, args) {
  5210. var self = this, rng = self.getRng(), caretNode, doc = self.win.document, frag, temp;
  5211. args = args || {format : 'html'};
  5212. args.set = true;
  5213. content = args.content = content;
  5214. // Dispatch before set content event
  5215. if (!args.no_events)
  5216. self.onBeforeSetContent.dispatch(self, args);
  5217. content = args.content;
  5218. if (rng.insertNode) {
  5219. // Make caret marker since insertNode places the caret in the beginning of text after insert
  5220. content += '<span id="__caret">_</span>';
  5221. // Delete and insert new node
  5222. if (rng.startContainer == doc && rng.endContainer == doc) {
  5223. // WebKit will fail if the body is empty since the range is then invalid and it can't insert contents
  5224. doc.body.innerHTML = content;
  5225. } else {
  5226. rng.deleteContents();
  5227. if (doc.body.childNodes.length == 0) {
  5228. doc.body.innerHTML = content;
  5229. } else {
  5230. // createContextualFragment doesn't exists in IE 9 DOMRanges
  5231. if (rng.createContextualFragment) {
  5232. rng.insertNode(rng.createContextualFragment(content));
  5233. } else {
  5234. // Fake createContextualFragment call in IE 9
  5235. frag = doc.createDocumentFragment();
  5236. temp = doc.createElement('div');
  5237. frag.appendChild(temp);
  5238. temp.outerHTML = content;
  5239. rng.insertNode(frag);
  5240. }
  5241. }
  5242. }
  5243. // Move to caret marker
  5244. caretNode = self.dom.get('__caret');
  5245. // Make sure we wrap it compleatly, Opera fails with a simple select call
  5246. rng = doc.createRange();
  5247. rng.setStartBefore(caretNode);
  5248. rng.setEndBefore(caretNode);
  5249. self.setRng(rng);
  5250. // Remove the caret position
  5251. self.dom.remove('__caret');
  5252. try {
  5253. self.setRng(rng);
  5254. } catch (ex) {
  5255. // Might fail on Opera for some odd reason
  5256. }
  5257. } else {
  5258. if (rng.item) {
  5259. // Delete content and get caret text selection
  5260. doc.execCommand('Delete', false, null);
  5261. rng = self.getRng();
  5262. }
  5263. // Explorer removes spaces from the beginning of pasted contents
  5264. if (/^\s+/.test(content)) {
  5265. rng.pasteHTML('<span id="__mce_tmp">_</span>' + content);
  5266. self.dom.remove('__mce_tmp');
  5267. } else
  5268. rng.pasteHTML(content);
  5269. }
  5270. // Dispatch set content event
  5271. if (!args.no_events)
  5272. self.onSetContent.dispatch(self, args);
  5273. },
  5274. getStart : function() {
  5275. var rng = this.getRng(), startElement, parentElement, checkRng, node;
  5276. if (rng.duplicate || rng.item) {
  5277. // Control selection, return first item
  5278. if (rng.item)
  5279. return rng.item(0);
  5280. // Get start element
  5281. checkRng = rng.duplicate();
  5282. checkRng.collapse(1);
  5283. startElement = checkRng.parentElement();
  5284. // Check if range parent is inside the start element, then return the inner parent element
  5285. // This will fix issues when a single element is selected, IE would otherwise return the wrong start element
  5286. parentElement = node = rng.parentElement();
  5287. while (node = node.parentNode) {
  5288. if (node == startElement) {
  5289. startElement = parentElement;
  5290. break;
  5291. }
  5292. }
  5293. return startElement;
  5294. } else {
  5295. startElement = rng.startContainer;
  5296. if (startElement.nodeType == 1 && startElement.hasChildNodes())
  5297. startElement = startElement.childNodes[Math.min(startElement.childNodes.length - 1, rng.startOffset)];
  5298. if (startElement && startElement.nodeType == 3)
  5299. return startElement.parentNode;
  5300. return startElement;
  5301. }
  5302. },
  5303. getEnd : function() {
  5304. var t = this, r = t.getRng(), e, eo;
  5305. if (r.duplicate || r.item) {
  5306. if (r.item)
  5307. return r.item(0);
  5308. r = r.duplicate();
  5309. r.collapse(0);
  5310. e = r.parentElement();
  5311. if (e && e.nodeName == 'BODY')
  5312. return e.lastChild || e;
  5313. return e;
  5314. } else {
  5315. e = r.endContainer;
  5316. eo = r.endOffset;
  5317. if (e.nodeType == 1 && e.hasChildNodes())
  5318. e = e.childNodes[eo > 0 ? eo - 1 : eo];
  5319. if (e && e.nodeType == 3)
  5320. return e.parentNode;
  5321. return e;
  5322. }
  5323. },
  5324. getBookmark : function(type, normalized) {
  5325. var t = this, dom = t.dom, rng, rng2, id, collapsed, name, element, index, chr = '\uFEFF', styles;
  5326. function findIndex(name, element) {
  5327. var index = 0;
  5328. each(dom.select(name), function(node, i) {
  5329. if (node == element)
  5330. index = i;
  5331. });
  5332. return index;
  5333. };
  5334. if (type == 2) {
  5335. function getLocation() {
  5336. var rng = t.getRng(true), root = dom.getRoot(), bookmark = {};
  5337. function getPoint(rng, start) {
  5338. var container = rng[start ? 'startContainer' : 'endContainer'],
  5339. offset = rng[start ? 'startOffset' : 'endOffset'], point = [], node, childNodes, after = 0;
  5340. if (container.nodeType == 3) {
  5341. if (normalized) {
  5342. for (node = container.previousSibling; node && node.nodeType == 3; node = node.previousSibling)
  5343. offset += node.nodeValue.length;
  5344. }
  5345. point.push(offset);
  5346. } else {
  5347. childNodes = container.childNodes;
  5348. if (offset >= childNodes.length && childNodes.length) {
  5349. after = 1;
  5350. offset = Math.max(0, childNodes.length - 1);
  5351. }
  5352. point.push(t.dom.nodeIndex(childNodes[offset], normalized) + after);
  5353. }
  5354. for (; container && container != root; container = container.parentNode)
  5355. point.push(t.dom.nodeIndex(container, normalized));
  5356. return point;
  5357. };
  5358. bookmark.start = getPoint(rng, true);
  5359. if (!t.isCollapsed())
  5360. bookmark.end = getPoint(rng);
  5361. return bookmark;
  5362. };
  5363. if (t.tridentSel)
  5364. return t.tridentSel.getBookmark(type);
  5365. return getLocation();
  5366. }
  5367. // Handle simple range
  5368. if (type)
  5369. return {rng : t.getRng()};
  5370. rng = t.getRng();
  5371. id = dom.uniqueId();
  5372. collapsed = tinyMCE.activeEditor.selection.isCollapsed();
  5373. styles = 'overflow:hidden;line-height:0px';
  5374. // Explorer method
  5375. if (rng.duplicate || rng.item) {
  5376. // Text selection
  5377. if (!rng.item) {
  5378. rng2 = rng.duplicate();
  5379. try {
  5380. // Insert start marker
  5381. rng.collapse();
  5382. rng.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_start" style="' + styles + '">' + chr + '</span>');
  5383. // Insert end marker
  5384. if (!collapsed) {
  5385. rng2.collapse(false);
  5386. // Detect the empty space after block elements in IE and move the end back one character <p></p>] becomes <p>]</p>
  5387. rng.moveToElementText(rng2.parentElement());
  5388. if (rng.compareEndPoints('StartToEnd', rng2) == 0)
  5389. rng2.move('character', -1);
  5390. rng2.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_end" style="' + styles + '">' + chr + '</span>');
  5391. }
  5392. } catch (ex) {
  5393. // IE might throw unspecified error so lets ignore it
  5394. return null;
  5395. }
  5396. } else {
  5397. // Control selection
  5398. element = rng.item(0);
  5399. name = element.nodeName;
  5400. return {name : name, index : findIndex(name, element)};
  5401. }
  5402. } else {
  5403. element = t.getNode();
  5404. name = element.nodeName;
  5405. if (name == 'IMG')
  5406. return {name : name, index : findIndex(name, element)};
  5407. // W3C method
  5408. rng2 = rng.cloneRange();
  5409. // Insert end marker
  5410. if (!collapsed) {
  5411. rng2.collapse(false);
  5412. rng2.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_end', style : styles}, chr));
  5413. }
  5414. rng.collapse(true);
  5415. rng.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_start', style : styles}, chr));
  5416. }
  5417. t.moveToBookmark({id : id, keep : 1});
  5418. return {id : id};
  5419. },
  5420. moveToBookmark : function(bookmark) {
  5421. var t = this, dom = t.dom, marker1, marker2, rng, root, startContainer, endContainer, startOffset, endOffset;
  5422. if (bookmark) {
  5423. if (bookmark.start) {
  5424. rng = dom.createRng();
  5425. root = dom.getRoot();
  5426. function setEndPoint(start) {
  5427. var point = bookmark[start ? 'start' : 'end'], i, node, offset, children;
  5428. if (point) {
  5429. offset = point[0];
  5430. // Find container node
  5431. for (node = root, i = point.length - 1; i >= 1; i--) {
  5432. children = node.childNodes;
  5433. if (point[i] > children.length - 1)
  5434. return;
  5435. node = children[point[i]];
  5436. }
  5437. // Move text offset to best suitable location
  5438. if (node.nodeType === 3)
  5439. offset = Math.min(point[0], node.nodeValue.length);
  5440. // Move element offset to best suitable location
  5441. if (node.nodeType === 1)
  5442. offset = Math.min(point[0], node.childNodes.length);
  5443. // Set offset within container node
  5444. if (start)
  5445. rng.setStart(node, offset);
  5446. else
  5447. rng.setEnd(node, offset);
  5448. }
  5449. return true;
  5450. };
  5451. if (t.tridentSel)
  5452. return t.tridentSel.moveToBookmark(bookmark);
  5453. if (setEndPoint(true) && setEndPoint()) {
  5454. t.setRng(rng);
  5455. }
  5456. } else if (bookmark.id) {
  5457. function restoreEndPoint(suffix) {
  5458. var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep;
  5459. if (marker) {
  5460. node = marker.parentNode;
  5461. if (suffix == 'start') {
  5462. if (!keep) {
  5463. idx = dom.nodeIndex(marker);
  5464. } else {
  5465. node = marker.firstChild;
  5466. idx = 1;
  5467. }
  5468. startContainer = endContainer = node;
  5469. startOffset = endOffset = idx;
  5470. } else {
  5471. if (!keep) {
  5472. idx = dom.nodeIndex(marker);
  5473. } else {
  5474. node = marker.firstChild;
  5475. idx = 1;
  5476. }
  5477. endContainer = node;
  5478. endOffset = idx;
  5479. }
  5480. if (!keep) {
  5481. prev = marker.previousSibling;
  5482. next = marker.nextSibling;
  5483. // Remove all marker text nodes
  5484. each(tinymce.grep(marker.childNodes), function(node) {
  5485. if (node.nodeType == 3)
  5486. node.nodeValue = node.nodeValue.replace(/\uFEFF/g, '');
  5487. });
  5488. // Remove marker but keep children if for example contents where inserted into the marker
  5489. // Also remove duplicated instances of the marker for example by a split operation or by WebKit auto split on paste feature
  5490. while (marker = dom.get(bookmark.id + '_' + suffix))
  5491. dom.remove(marker, 1);
  5492. // If siblings are text nodes then merge them unless it's Opera since it some how removes the node
  5493. // 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
  5494. if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3 && !tinymce.isOpera) {
  5495. idx = prev.nodeValue.length;
  5496. prev.appendData(next.nodeValue);
  5497. dom.remove(next);
  5498. if (suffix == 'start') {
  5499. startContainer = endContainer = prev;
  5500. startOffset = endOffset = idx;
  5501. } else {
  5502. endContainer = prev;
  5503. endOffset = idx;
  5504. }
  5505. }
  5506. }
  5507. }
  5508. };
  5509. function addBogus(node) {
  5510. // Adds a bogus BR element for empty block elements or just a space on IE since it renders BR elements incorrectly
  5511. if (dom.isBlock(node) && !node.innerHTML)
  5512. node.innerHTML = !isIE ? '<br data-mce-bogus="1" />' : ' ';
  5513. return node;
  5514. };
  5515. // Restore start/end points
  5516. restoreEndPoint('start');
  5517. restoreEndPoint('end');
  5518. if (startContainer) {
  5519. rng = dom.createRng();
  5520. rng.setStart(addBogus(startContainer), startOffset);
  5521. rng.setEnd(addBogus(endContainer), endOffset);
  5522. t.setRng(rng);
  5523. }
  5524. } else if (bookmark.name) {
  5525. t.select(dom.select(bookmark.name)[bookmark.index]);
  5526. } else if (bookmark.rng)
  5527. t.setRng(bookmark.rng);
  5528. }
  5529. },
  5530. select : function(node, content) {
  5531. var t = this, dom = t.dom, rng = dom.createRng(), idx;
  5532. if (node) {
  5533. idx = dom.nodeIndex(node);
  5534. rng.setStart(node.parentNode, idx);
  5535. rng.setEnd(node.parentNode, idx + 1);
  5536. // Find first/last text node or BR element
  5537. if (content) {
  5538. function setPoint(node, start) {
  5539. var walker = new tinymce.dom.TreeWalker(node, node);
  5540. do {
  5541. // Text node
  5542. if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) {
  5543. if (start)
  5544. rng.setStart(node, 0);
  5545. else
  5546. rng.setEnd(node, node.nodeValue.length);
  5547. return;
  5548. }
  5549. // BR element
  5550. if (node.nodeName == 'BR') {
  5551. if (start)
  5552. rng.setStartBefore(node);
  5553. else
  5554. rng.setEndBefore(node);
  5555. return;
  5556. }
  5557. } while (node = (start ? walker.next() : walker.prev()));
  5558. };
  5559. setPoint(node, 1);
  5560. setPoint(node);
  5561. }
  5562. t.setRng(rng);
  5563. }
  5564. return node;
  5565. },
  5566. isCollapsed : function() {
  5567. var t = this, r = t.getRng(), s = t.getSel();
  5568. if (!r || r.item)
  5569. return false;
  5570. if (r.compareEndPoints)
  5571. return r.compareEndPoints('StartToEnd', r) === 0;
  5572. return !s || r.collapsed;
  5573. },
  5574. collapse : function(to_start) {
  5575. var self = this, rng = self.getRng(), node;
  5576. // Control range on IE
  5577. if (rng.item) {
  5578. node = rng.item(0);
  5579. rng = self.win.document.body.createTextRange();
  5580. rng.moveToElementText(node);
  5581. }
  5582. rng.collapse(!!to_start);
  5583. self.setRng(rng);
  5584. },
  5585. getSel : function() {
  5586. var t = this, w = this.win;
  5587. return w.getSelection ? w.getSelection() : w.document.selection;
  5588. },
  5589. getRng : function(w3c) {
  5590. var t = this, s, r, elm, doc = t.win.document;
  5591. // Found tridentSel object then we need to use that one
  5592. if (w3c && t.tridentSel)
  5593. return t.tridentSel.getRangeAt(0);
  5594. try {
  5595. if (s = t.getSel())
  5596. r = s.rangeCount > 0 ? s.getRangeAt(0) : (s.createRange ? s.createRange() : doc.createRange());
  5597. } catch (ex) {
  5598. // IE throws unspecified error here if TinyMCE is placed in a frame/iframe
  5599. }
  5600. // We have W3C ranges and it's IE then fake control selection since IE9 doesn't handle that correctly yet
  5601. if (tinymce.isIE && r && r.setStart && doc.selection.createRange().item) {
  5602. elm = doc.selection.createRange().item(0);
  5603. r = doc.createRange();
  5604. r.setStartBefore(elm);
  5605. r.setEndAfter(elm);
  5606. }
  5607. // No range found then create an empty one
  5608. // This can occur when the editor is placed in a hidden container element on Gecko
  5609. // Or on IE when there was an exception
  5610. if (!r)
  5611. r = doc.createRange ? doc.createRange() : doc.body.createTextRange();
  5612. if (t.selectedRange && t.explicitRange) {
  5613. if (r.compareBoundaryPoints(r.START_TO_START, t.selectedRange) === 0 && r.compareBoundaryPoints(r.END_TO_END, t.selectedRange) === 0) {
  5614. // Safari, Opera and Chrome only ever select text which causes the range to change.
  5615. // This lets us use the originally set range if the selection hasn't been changed by the user.
  5616. r = t.explicitRange;
  5617. } else {
  5618. t.selectedRange = null;
  5619. t.explicitRange = null;
  5620. }
  5621. }
  5622. return r;
  5623. },
  5624. setRng : function(r) {
  5625. var s, t = this;
  5626. if (!t.tridentSel) {
  5627. s = t.getSel();
  5628. if (s) {
  5629. t.explicitRange = r;
  5630. try {
  5631. s.removeAllRanges();
  5632. } catch (ex) {
  5633. // IE9 might throw errors here don't know why
  5634. }
  5635. s.addRange(r);
  5636. t.selectedRange = s.getRangeAt(0);
  5637. }
  5638. } else {
  5639. // Is W3C Range
  5640. if (r.cloneRange) {
  5641. t.tridentSel.addRange(r);
  5642. return;
  5643. }
  5644. // Is IE specific range
  5645. try {
  5646. r.select();
  5647. } catch (ex) {
  5648. // Needed for some odd IE bug #1843306
  5649. }
  5650. }
  5651. },
  5652. setNode : function(n) {
  5653. var t = this;
  5654. t.setContent(t.dom.getOuterHTML(n));
  5655. return n;
  5656. },
  5657. getNode : function() {
  5658. var t = this, rng = t.getRng(), sel = t.getSel(), elm, start = rng.startContainer, end = rng.endContainer;
  5659. // Range maybe lost after the editor is made visible again
  5660. if (!rng)
  5661. return t.dom.getRoot();
  5662. if (rng.setStart) {
  5663. elm = rng.commonAncestorContainer;
  5664. // Handle selection a image or other control like element such as anchors
  5665. if (!rng.collapsed) {
  5666. if (rng.startContainer == rng.endContainer) {
  5667. if (rng.endOffset - rng.startOffset < 2) {
  5668. if (rng.startContainer.hasChildNodes())
  5669. elm = rng.startContainer.childNodes[rng.startOffset];
  5670. }
  5671. }
  5672. // If the anchor node is a element instead of a text node then return this element
  5673. //if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1)
  5674. // return sel.anchorNode.childNodes[sel.anchorOffset];
  5675. // Handle cases where the selection is immediately wrapped around a node and return that node instead of it's parent.
  5676. // This happens when you double click an underlined word in FireFox.
  5677. if (start.nodeType === 3 && end.nodeType === 3) {
  5678. function skipEmptyTextNodes(n, forwards) {
  5679. var orig = n;
  5680. while (n && n.nodeType === 3 && n.length === 0) {
  5681. n = forwards ? n.nextSibling : n.previousSibling;
  5682. }
  5683. return n || orig;
  5684. }
  5685. if (start.length === rng.startOffset) {
  5686. start = skipEmptyTextNodes(start.nextSibling, true);
  5687. } else {
  5688. start = start.parentNode;
  5689. }
  5690. if (rng.endOffset === 0) {
  5691. end = skipEmptyTextNodes(end.previousSibling, false);
  5692. } else {
  5693. end = end.parentNode;
  5694. }
  5695. if (start && start === end)
  5696. return start;
  5697. }
  5698. }
  5699. if (elm && elm.nodeType == 3)
  5700. return elm.parentNode;
  5701. return elm;
  5702. }
  5703. return rng.item ? rng.item(0) : rng.parentElement();
  5704. },
  5705. getSelectedBlocks : function(st, en) {
  5706. var t = this, dom = t.dom, sb, eb, n, bl = [];
  5707. sb = dom.getParent(st || t.getStart(), dom.isBlock);
  5708. eb = dom.getParent(en || t.getEnd(), dom.isBlock);
  5709. if (sb)
  5710. bl.push(sb);
  5711. if (sb && eb && sb != eb) {
  5712. n = sb;
  5713. var walker = new tinymce.dom.TreeWalker(sb, dom.getRoot());
  5714. while ((n = walker.next()) && n != eb) {
  5715. if (dom.isBlock(n))
  5716. bl.push(n);
  5717. }
  5718. }
  5719. if (eb && sb != eb)
  5720. bl.push(eb);
  5721. return bl;
  5722. },
  5723. normalize : function() {
  5724. var self = this, rng, normalized;
  5725. // Normalize only on non IE browsers for now
  5726. if (tinymce.isIE)
  5727. return;
  5728. function normalizeEndPoint(start) {
  5729. var container, offset, walker, dom = self.dom, body = dom.getRoot(), node;
  5730. container = rng[(start ? 'start' : 'end') + 'Container'];
  5731. offset = rng[(start ? 'start' : 'end') + 'Offset'];
  5732. // If the container is a document move it to the body element
  5733. if (container.nodeType === 9) {
  5734. container = container.body;
  5735. offset = 0;
  5736. }
  5737. // If the container is body try move it into the closest text node or position
  5738. // TODO: Add more logic here to handle element selection cases
  5739. if (container === body) {
  5740. // Resolve the index
  5741. if (container.hasChildNodes()) {
  5742. container = container.childNodes[Math.min(!start && offset > 0 ? offset - 1 : offset, container.childNodes.length - 1)];
  5743. offset = 0;
  5744. // Don't walk into elements that doesn't have any child nodes like a IMG
  5745. if (container.hasChildNodes()) {
  5746. // Walk the DOM to find a text node to place the caret at or a BR
  5747. node = container;
  5748. walker = new tinymce.dom.TreeWalker(container, body);
  5749. do {
  5750. // Found a text node use that position
  5751. if (node.nodeType === 3) {
  5752. offset = start ? 0 : node.nodeValue.length - 1;
  5753. container = node;
  5754. break;
  5755. }
  5756. // Found a BR element that we can place the caret before
  5757. if (node.nodeName === 'BR') {
  5758. offset = dom.nodeIndex(node);
  5759. container = node.parentNode;
  5760. break;
  5761. }
  5762. } while (node = (start ? walker.next() : walker.prev()));
  5763. normalized = true;
  5764. }
  5765. }
  5766. }
  5767. // Set endpoint if it was normalized
  5768. if (normalized)
  5769. rng['set' + (start ? 'Start' : 'End')](container, offset);
  5770. };
  5771. rng = self.getRng();
  5772. // Normalize the end points
  5773. normalizeEndPoint(true);
  5774. if (rng.collapsed)
  5775. normalizeEndPoint();
  5776. // Set the selection if it was normalized
  5777. if (normalized) {
  5778. //console.log(self.dom.dumpRng(rng));
  5779. self.setRng(rng);
  5780. }
  5781. },
  5782. destroy : function(s) {
  5783. var t = this;
  5784. t.win = null;
  5785. // Manual destroy then remove unload handler
  5786. if (!s)
  5787. tinymce.removeUnload(t.destroy);
  5788. },
  5789. // IE has an issue where you can't select/move the caret by clicking outside the body if the document is in standards mode
  5790. _fixIESelection : function() {
  5791. var dom = this.dom, doc = dom.doc, body = doc.body, started, startRng, htmlElm;
  5792. // Make HTML element unselectable since we are going to handle selection by hand
  5793. doc.documentElement.unselectable = true;
  5794. // Return range from point or null if it failed
  5795. function rngFromPoint(x, y) {
  5796. var rng = body.createTextRange();
  5797. try {
  5798. rng.moveToPoint(x, y);
  5799. } catch (ex) {
  5800. // IE sometimes throws and exception, so lets just ignore it
  5801. rng = null;
  5802. }
  5803. return rng;
  5804. };
  5805. // Fires while the selection is changing
  5806. function selectionChange(e) {
  5807. var pointRng;
  5808. // Check if the button is down or not
  5809. if (e.button) {
  5810. // Create range from mouse position
  5811. pointRng = rngFromPoint(e.x, e.y);
  5812. if (pointRng) {
  5813. // Check if pointRange is before/after selection then change the endPoint
  5814. if (pointRng.compareEndPoints('StartToStart', startRng) > 0)
  5815. pointRng.setEndPoint('StartToStart', startRng);
  5816. else
  5817. pointRng.setEndPoint('EndToEnd', startRng);
  5818. pointRng.select();
  5819. }
  5820. } else
  5821. endSelection();
  5822. }
  5823. // Removes listeners
  5824. function endSelection() {
  5825. var rng = doc.selection.createRange();
  5826. // If the range is collapsed then use the last start range
  5827. if (startRng && !rng.item && rng.compareEndPoints('StartToEnd', rng) === 0)
  5828. startRng.select();
  5829. dom.unbind(doc, 'mouseup', endSelection);
  5830. dom.unbind(doc, 'mousemove', selectionChange);
  5831. startRng = started = 0;
  5832. };
  5833. // Detect when user selects outside BODY
  5834. dom.bind(doc, ['mousedown', 'contextmenu'], function(e) {
  5835. if (e.target.nodeName === 'HTML') {
  5836. if (started)
  5837. endSelection();
  5838. // Detect vertical scrollbar, since IE will fire a mousedown on the scrollbar and have target set as HTML
  5839. htmlElm = doc.documentElement;
  5840. if (htmlElm.scrollHeight > htmlElm.clientHeight)
  5841. return;
  5842. started = 1;
  5843. // Setup start position
  5844. startRng = rngFromPoint(e.x, e.y);
  5845. if (startRng) {
  5846. // Listen for selection change events
  5847. dom.bind(doc, 'mouseup', endSelection);
  5848. dom.bind(doc, 'mousemove', selectionChange);
  5849. dom.win.focus();
  5850. startRng.select();
  5851. }
  5852. }
  5853. });
  5854. }
  5855. });
  5856. })(tinymce);
  5857. (function(tinymce) {
  5858. tinymce.dom.Serializer = function(settings, dom, schema) {
  5859. var onPreProcess, onPostProcess, isIE = tinymce.isIE, each = tinymce.each, htmlParser;
  5860. // Support the old apply_source_formatting option
  5861. if (!settings.apply_source_formatting)
  5862. settings.indent = false;
  5863. settings.remove_trailing_brs = true;
  5864. // Default DOM and Schema if they are undefined
  5865. dom = dom || tinymce.DOM;
  5866. schema = schema || new tinymce.html.Schema(settings);
  5867. settings.entity_encoding = settings.entity_encoding || 'named';
  5868. onPreProcess = new tinymce.util.Dispatcher(self);
  5869. onPostProcess = new tinymce.util.Dispatcher(self);
  5870. htmlParser = new tinymce.html.DomParser(settings, schema);
  5871. // Convert move data-mce-src, data-mce-href and data-mce-style into nodes or process them if needed
  5872. htmlParser.addAttributeFilter('src,href,style', function(nodes, name) {
  5873. var i = nodes.length, node, value, internalName = 'data-mce-' + name, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope, undef;
  5874. while (i--) {
  5875. node = nodes[i];
  5876. value = node.attributes.map[internalName];
  5877. if (value !== undef) {
  5878. // Set external name to internal value and remove internal
  5879. node.attr(name, value.length > 0 ? value : null);
  5880. node.attr(internalName, null);
  5881. } else {
  5882. // No internal attribute found then convert the value we have in the DOM
  5883. value = node.attributes.map[name];
  5884. if (name === "style")
  5885. value = dom.serializeStyle(dom.parseStyle(value), node.name);
  5886. else if (urlConverter)
  5887. value = urlConverter.call(urlConverterScope, value, name, node.name);
  5888. node.attr(name, value.length > 0 ? value : null);
  5889. }
  5890. }
  5891. });
  5892. // Remove internal classes mceItem<..>
  5893. htmlParser.addAttributeFilter('class', function(nodes, name) {
  5894. var i = nodes.length, node, value;
  5895. while (i--) {
  5896. node = nodes[i];
  5897. value = node.attr('class').replace(/\s*mce(Item\w+|Selected)\s*/g, '');
  5898. node.attr('class', value.length > 0 ? value : null);
  5899. }
  5900. });
  5901. // Remove bookmark elements
  5902. htmlParser.addAttributeFilter('data-mce-type', function(nodes, name, args) {
  5903. var i = nodes.length, node;
  5904. while (i--) {
  5905. node = nodes[i];
  5906. if (node.attributes.map['data-mce-type'] === 'bookmark' && !args.cleanup)
  5907. node.remove();
  5908. }
  5909. });
  5910. // Force script into CDATA sections and remove the mce- prefix also add comments around styles
  5911. htmlParser.addNodeFilter('script,style', function(nodes, name) {
  5912. var i = nodes.length, node, value;
  5913. function trim(value) {
  5914. return value.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n')
  5915. .replace(/^[\r\n]*|[\r\n]*$/g, '')
  5916. .replace(/^\s*(\/\/\s*<!--|\/\/\s*<!\[CDATA\[|<!--|<!\[CDATA\[)[\r\n]*/g, '')
  5917. .replace(/\s*(\/\/\s*\]\]>|\/\/\s*-->|\]\]>|-->|\]\]-->)\s*$/g, '');
  5918. };
  5919. while (i--) {
  5920. node = nodes[i];
  5921. value = node.firstChild ? node.firstChild.value : '';
  5922. if (name === "script") {
  5923. // Remove mce- prefix from script elements
  5924. node.attr('type', (node.attr('type') || 'text/javascript').replace(/^mce\-/, ''));
  5925. if (value.length > 0)
  5926. node.firstChild.value = '// <![CDATA[\n' + trim(value) + '\n// ]]>';
  5927. } else {
  5928. if (value.length > 0)
  5929. node.firstChild.value = '<!--\n' + trim(value) + '\n-->';
  5930. }
  5931. }
  5932. });
  5933. // Convert comments to cdata and handle protected comments
  5934. htmlParser.addNodeFilter('#comment', function(nodes, name) {
  5935. var i = nodes.length, node;
  5936. while (i--) {
  5937. node = nodes[i];
  5938. if (node.value.indexOf('[CDATA[') === 0) {
  5939. node.name = '#cdata';
  5940. node.type = 4;
  5941. node.value = node.value.replace(/^\[CDATA\[|\]\]$/g, '');
  5942. } else if (node.value.indexOf('mce:protected ') === 0) {
  5943. node.name = "#text";
  5944. node.type = 3;
  5945. node.raw = true;
  5946. node.value = unescape(node.value).substr(14);
  5947. }
  5948. }
  5949. });
  5950. htmlParser.addNodeFilter('xml:namespace,input', function(nodes, name) {
  5951. var i = nodes.length, node;
  5952. while (i--) {
  5953. node = nodes[i];
  5954. if (node.type === 7)
  5955. node.remove();
  5956. else if (node.type === 1) {
  5957. if (name === "input" && !("type" in node.attributes.map))
  5958. node.attr('type', 'text');
  5959. }
  5960. }
  5961. });
  5962. // Fix list elements, TODO: Replace this later
  5963. if (settings.fix_list_elements) {
  5964. htmlParser.addNodeFilter('ul,ol', function(nodes, name) {
  5965. var i = nodes.length, node, parentNode;
  5966. while (i--) {
  5967. node = nodes[i];
  5968. parentNode = node.parent;
  5969. if (parentNode.name === 'ul' || parentNode.name === 'ol') {
  5970. if (node.prev && node.prev.name === 'li') {
  5971. node.prev.append(node);
  5972. }
  5973. }
  5974. }
  5975. });
  5976. }
  5977. // Remove internal data attributes
  5978. htmlParser.addAttributeFilter('data-mce-src,data-mce-href,data-mce-style', function(nodes, name) {
  5979. var i = nodes.length;
  5980. while (i--) {
  5981. nodes[i].attr(name, null);
  5982. }
  5983. });
  5984. // Return public methods
  5985. return {
  5986. schema : schema,
  5987. addNodeFilter : htmlParser.addNodeFilter,
  5988. addAttributeFilter : htmlParser.addAttributeFilter,
  5989. onPreProcess : onPreProcess,
  5990. onPostProcess : onPostProcess,
  5991. serialize : function(node, args) {
  5992. var impl, doc, oldDoc, htmlSerializer, content;
  5993. // Explorer won't clone contents of script and style and the
  5994. // selected index of select elements are cleared on a clone operation.
  5995. if (isIE && dom.select('script,style,select,map').length > 0) {
  5996. content = node.innerHTML;
  5997. node = node.cloneNode(false);
  5998. dom.setHTML(node, content);
  5999. } else
  6000. node = node.cloneNode(true);
  6001. // Nodes needs to be attached to something in WebKit/Opera
  6002. // Older builds of Opera crashes if you attach the node to an document created dynamically
  6003. // and since we can't feature detect a crash we need to sniff the acutal build number
  6004. // This fix will make DOM ranges and make Sizzle happy!
  6005. impl = node.ownerDocument.implementation;
  6006. if (impl.createHTMLDocument) {
  6007. // Create an empty HTML document
  6008. doc = impl.createHTMLDocument("");
  6009. // Add the element or it's children if it's a body element to the new document
  6010. each(node.nodeName == 'BODY' ? node.childNodes : [node], function(node) {
  6011. doc.body.appendChild(doc.importNode(node, true));
  6012. });
  6013. // Grab first child or body element for serialization
  6014. if (node.nodeName != 'BODY')
  6015. node = doc.body.firstChild;
  6016. else
  6017. node = doc.body;
  6018. // set the new document in DOMUtils so createElement etc works
  6019. oldDoc = dom.doc;
  6020. dom.doc = doc;
  6021. }
  6022. args = args || {};
  6023. args.format = args.format || 'html';
  6024. // Pre process
  6025. if (!args.no_events) {
  6026. args.node = node;
  6027. onPreProcess.dispatch(self, args);
  6028. }
  6029. // Setup serializer
  6030. htmlSerializer = new tinymce.html.Serializer(settings, schema);
  6031. // Parse and serialize HTML
  6032. args.content = htmlSerializer.serialize(
  6033. htmlParser.parse(args.getInner ? node.innerHTML : tinymce.trim(dom.getOuterHTML(node), args), args)
  6034. );
  6035. // Replace all BOM characters for now until we can find a better solution
  6036. if (!args.cleanup)
  6037. args.content = args.content.replace(/\uFEFF|\u200B/g, '');
  6038. // Post process
  6039. if (!args.no_events)
  6040. onPostProcess.dispatch(self, args);
  6041. // Restore the old document if it was changed
  6042. if (oldDoc)
  6043. dom.doc = oldDoc;
  6044. args.node = null;
  6045. return args.content;
  6046. },
  6047. addRules : function(rules) {
  6048. schema.addValidElements(rules);
  6049. },
  6050. setRules : function(rules) {
  6051. schema.setValidElements(rules);
  6052. }
  6053. };
  6054. };
  6055. })(tinymce);
  6056. (function(tinymce) {
  6057. tinymce.dom.ScriptLoader = function(settings) {
  6058. var QUEUED = 0,
  6059. LOADING = 1,
  6060. LOADED = 2,
  6061. states = {},
  6062. queue = [],
  6063. scriptLoadedCallbacks = {},
  6064. queueLoadedCallbacks = [],
  6065. loading = 0,
  6066. undefined;
  6067. function loadScript(url, callback) {
  6068. var t = this, dom = tinymce.DOM, elm, uri, loc, id;
  6069. // Execute callback when script is loaded
  6070. function done() {
  6071. dom.remove(id);
  6072. if (elm)
  6073. elm.onreadystatechange = elm.onload = elm = null;
  6074. callback();
  6075. };
  6076. function error() {
  6077. // Report the error so it's easier for people to spot loading errors
  6078. if (typeof(console) !== "undefined" && console.log)
  6079. console.log("Failed to load: " + url);
  6080. // We can't mark it as done if there is a load error since
  6081. // A) We don't want to produce 404 errors on the server and
  6082. // B) the onerror event won't fire on all browsers.
  6083. // done();
  6084. };
  6085. id = dom.uniqueId();
  6086. if (tinymce.isIE6) {
  6087. uri = new tinymce.util.URI(url);
  6088. loc = location;
  6089. // If script is from same domain and we
  6090. // use IE 6 then use XHR since it's more reliable
  6091. if (uri.host == loc.hostname && uri.port == loc.port && (uri.protocol + ':') == loc.protocol && uri.protocol.toLowerCase() != 'file') {
  6092. tinymce.util.XHR.send({
  6093. url : tinymce._addVer(uri.getURI()),
  6094. success : function(content) {
  6095. // Create new temp script element
  6096. var script = dom.create('script', {
  6097. type : 'text/javascript'
  6098. });
  6099. // Evaluate script in global scope
  6100. script.text = content;
  6101. document.getElementsByTagName('head')[0].appendChild(script);
  6102. dom.remove(script);
  6103. done();
  6104. },
  6105. error : error
  6106. });
  6107. return;
  6108. }
  6109. }
  6110. // Create new script element
  6111. elm = dom.create('script', {
  6112. id : id,
  6113. type : 'text/javascript',
  6114. src : tinymce._addVer(url)
  6115. });
  6116. // Add onload listener for non IE browsers since IE9
  6117. // fires onload event before the script is parsed and executed
  6118. if (!tinymce.isIE)
  6119. elm.onload = done;
  6120. // Add onerror event will get fired on some browsers but not all of them
  6121. elm.onerror = error;
  6122. // Opera 9.60 doesn't seem to fire the onreadystate event at correctly
  6123. if (!tinymce.isOpera) {
  6124. elm.onreadystatechange = function() {
  6125. var state = elm.readyState;
  6126. // Loaded state is passed on IE 6 however there
  6127. // are known issues with this method but we can't use
  6128. // XHR in a cross domain loading
  6129. if (state == 'complete' || state == 'loaded')
  6130. done();
  6131. };
  6132. }
  6133. // Most browsers support this feature so we report errors
  6134. // for those at least to help users track their missing plugins etc
  6135. // todo: Removed since it produced error if the document is unloaded by navigating away, re-add it as an option
  6136. /*elm.onerror = function() {
  6137. alert('Failed to load: ' + url);
  6138. };*/
  6139. // Add script to document
  6140. (document.getElementsByTagName('head')[0] || document.body).appendChild(elm);
  6141. };
  6142. this.isDone = function(url) {
  6143. return states[url] == LOADED;
  6144. };
  6145. this.markDone = function(url) {
  6146. states[url] = LOADED;
  6147. };
  6148. this.add = this.load = function(url, callback, scope) {
  6149. var item, state = states[url];
  6150. // Add url to load queue
  6151. if (state == undefined) {
  6152. queue.push(url);
  6153. states[url] = QUEUED;
  6154. }
  6155. if (callback) {
  6156. // Store away callback for later execution
  6157. if (!scriptLoadedCallbacks[url])
  6158. scriptLoadedCallbacks[url] = [];
  6159. scriptLoadedCallbacks[url].push({
  6160. func : callback,
  6161. scope : scope || this
  6162. });
  6163. }
  6164. };
  6165. this.loadQueue = function(callback, scope) {
  6166. this.loadScripts(queue, callback, scope);
  6167. };
  6168. this.loadScripts = function(scripts, callback, scope) {
  6169. var loadScripts;
  6170. function execScriptLoadedCallbacks(url) {
  6171. // Execute URL callback functions
  6172. tinymce.each(scriptLoadedCallbacks[url], function(callback) {
  6173. callback.func.call(callback.scope);
  6174. });
  6175. scriptLoadedCallbacks[url] = undefined;
  6176. };
  6177. queueLoadedCallbacks.push({
  6178. func : callback,
  6179. scope : scope || this
  6180. });
  6181. loadScripts = function() {
  6182. var loadingScripts = tinymce.grep(scripts);
  6183. // Current scripts has been handled
  6184. scripts.length = 0;
  6185. // Load scripts that needs to be loaded
  6186. tinymce.each(loadingScripts, function(url) {
  6187. // Script is already loaded then execute script callbacks directly
  6188. if (states[url] == LOADED) {
  6189. execScriptLoadedCallbacks(url);
  6190. return;
  6191. }
  6192. // Is script not loading then start loading it
  6193. if (states[url] != LOADING) {
  6194. states[url] = LOADING;
  6195. loading++;
  6196. loadScript(url, function() {
  6197. states[url] = LOADED;
  6198. loading--;
  6199. execScriptLoadedCallbacks(url);
  6200. // Load more scripts if they where added by the recently loaded script
  6201. loadScripts();
  6202. });
  6203. }
  6204. });
  6205. // No scripts are currently loading then execute all pending queue loaded callbacks
  6206. if (!loading) {
  6207. tinymce.each(queueLoadedCallbacks, function(callback) {
  6208. callback.func.call(callback.scope);
  6209. });
  6210. queueLoadedCallbacks.length = 0;
  6211. }
  6212. };
  6213. loadScripts();
  6214. };
  6215. };
  6216. // Global script loader
  6217. tinymce.ScriptLoader = new tinymce.dom.ScriptLoader();
  6218. })(tinymce);
  6219. tinymce.dom.TreeWalker = function(start_node, root_node) {
  6220. var node = start_node;
  6221. function findSibling(node, start_name, sibling_name, shallow) {
  6222. var sibling, parent;
  6223. if (node) {
  6224. // Walk into nodes if it has a start
  6225. if (!shallow && node[start_name])
  6226. return node[start_name];
  6227. // Return the sibling if it has one
  6228. if (node != root_node) {
  6229. sibling = node[sibling_name];
  6230. if (sibling)
  6231. return sibling;
  6232. // Walk up the parents to look for siblings
  6233. for (parent = node.parentNode; parent && parent != root_node; parent = parent.parentNode) {
  6234. sibling = parent[sibling_name];
  6235. if (sibling)
  6236. return sibling;
  6237. }
  6238. }
  6239. }
  6240. };
  6241. this.current = function() {
  6242. return node;
  6243. };
  6244. this.next = function(shallow) {
  6245. return (node = findSibling(node, 'firstChild', 'nextSibling', shallow));
  6246. };
  6247. this.prev = function(shallow) {
  6248. return (node = findSibling(node, 'lastChild', 'previousSibling', shallow));
  6249. };
  6250. };
  6251. (function(tinymce) {
  6252. tinymce.dom.RangeUtils = function(dom) {
  6253. var INVISIBLE_CHAR = '\uFEFF';
  6254. this.walk = function(rng, callback) {
  6255. var startContainer = rng.startContainer,
  6256. startOffset = rng.startOffset,
  6257. endContainer = rng.endContainer,
  6258. endOffset = rng.endOffset,
  6259. ancestor, startPoint,
  6260. endPoint, node, parent, siblings, nodes;
  6261. // Handle table cell selection the table plugin enables
  6262. // you to fake select table cells and perform formatting actions on them
  6263. nodes = dom.select('td.mceSelected,th.mceSelected');
  6264. if (nodes.length > 0) {
  6265. tinymce.each(nodes, function(node) {
  6266. callback([node]);
  6267. });
  6268. return;
  6269. }
  6270. function exclude(nodes) {
  6271. var node;
  6272. // First node is excluded
  6273. node = nodes[0];
  6274. if (node.nodeType === 3 && node === startContainer && startOffset >= node.nodeValue.length) {
  6275. nodes.splice(0, 1);
  6276. }
  6277. // Last node is excluded
  6278. node = nodes[nodes.length - 1];
  6279. if (endOffset === 0 && nodes.length > 0 && node === endContainer && node.nodeType === 3) {
  6280. nodes.splice(nodes.length - 1, 1);
  6281. }
  6282. return nodes;
  6283. };
  6284. function collectSiblings(node, name, end_node) {
  6285. var siblings = [];
  6286. for (; node && node != end_node; node = node[name])
  6287. siblings.push(node);
  6288. return siblings;
  6289. };
  6290. function findEndPoint(node, root) {
  6291. do {
  6292. if (node.parentNode == root)
  6293. return node;
  6294. node = node.parentNode;
  6295. } while(node);
  6296. };
  6297. function walkBoundary(start_node, end_node, next) {
  6298. var siblingName = next ? 'nextSibling' : 'previousSibling';
  6299. for (node = start_node, parent = node.parentNode; node && node != end_node; node = parent) {
  6300. parent = node.parentNode;
  6301. siblings = collectSiblings(node == start_node ? node : node[siblingName], siblingName);
  6302. if (siblings.length) {
  6303. if (!next)
  6304. siblings.reverse();
  6305. callback(exclude(siblings));
  6306. }
  6307. }
  6308. };
  6309. // If index based start position then resolve it
  6310. if (startContainer.nodeType == 1 && startContainer.hasChildNodes())
  6311. startContainer = startContainer.childNodes[startOffset];
  6312. // If index based end position then resolve it
  6313. if (endContainer.nodeType == 1 && endContainer.hasChildNodes())
  6314. endContainer = endContainer.childNodes[Math.min(endOffset - 1, endContainer.childNodes.length - 1)];
  6315. // Same container
  6316. if (startContainer == endContainer)
  6317. return callback(exclude([startContainer]));
  6318. // Find common ancestor and end points
  6319. ancestor = dom.findCommonAncestor(startContainer, endContainer);
  6320. // Process left side
  6321. for (node = startContainer; node; node = node.parentNode) {
  6322. if (node === endContainer)
  6323. return walkBoundary(startContainer, ancestor, true);
  6324. if (node === ancestor)
  6325. break;
  6326. }
  6327. // Process right side
  6328. for (node = endContainer; node; node = node.parentNode) {
  6329. if (node === startContainer)
  6330. return walkBoundary(endContainer, ancestor);
  6331. if (node === ancestor)
  6332. break;
  6333. }
  6334. // Find start/end point
  6335. startPoint = findEndPoint(startContainer, ancestor) || startContainer;
  6336. endPoint = findEndPoint(endContainer, ancestor) || endContainer;
  6337. // Walk left leaf
  6338. walkBoundary(startContainer, startPoint, true);
  6339. // Walk the middle from start to end point
  6340. siblings = collectSiblings(
  6341. startPoint == startContainer ? startPoint : startPoint.nextSibling,
  6342. 'nextSibling',
  6343. endPoint == endContainer ? endPoint.nextSibling : endPoint
  6344. );
  6345. if (siblings.length)
  6346. callback(exclude(siblings));
  6347. // Walk right leaf
  6348. walkBoundary(endContainer, endPoint);
  6349. };
  6350. this.split = function(rng) {
  6351. var startContainer = rng.startContainer,
  6352. startOffset = rng.startOffset,
  6353. endContainer = rng.endContainer,
  6354. endOffset = rng.endOffset;
  6355. function splitText(node, offset) {
  6356. return node.splitText(offset);
  6357. };
  6358. // Handle single text node
  6359. if (startContainer == endContainer && startContainer.nodeType == 3) {
  6360. if (startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  6361. endContainer = splitText(startContainer, startOffset);
  6362. startContainer = endContainer.previousSibling;
  6363. if (endOffset > startOffset) {
  6364. endOffset = endOffset - startOffset;
  6365. startContainer = endContainer = splitText(endContainer, endOffset).previousSibling;
  6366. endOffset = endContainer.nodeValue.length;
  6367. startOffset = 0;
  6368. } else {
  6369. endOffset = 0;
  6370. }
  6371. }
  6372. } else {
  6373. // Split startContainer text node if needed
  6374. if (startContainer.nodeType == 3 && startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  6375. startContainer = splitText(startContainer, startOffset);
  6376. startOffset = 0;
  6377. }
  6378. // Split endContainer text node if needed
  6379. if (endContainer.nodeType == 3 && endOffset > 0 && endOffset < endContainer.nodeValue.length) {
  6380. endContainer = splitText(endContainer, endOffset).previousSibling;
  6381. endOffset = endContainer.nodeValue.length;
  6382. }
  6383. }
  6384. return {
  6385. startContainer : startContainer,
  6386. startOffset : startOffset,
  6387. endContainer : endContainer,
  6388. endOffset : endOffset
  6389. };
  6390. };
  6391. };
  6392. tinymce.dom.RangeUtils.compareRanges = function(rng1, rng2) {
  6393. if (rng1 && rng2) {
  6394. // Compare native IE ranges
  6395. if (rng1.item || rng1.duplicate) {
  6396. // Both are control ranges and the selected element matches
  6397. if (rng1.item && rng2.item && rng1.item(0) === rng2.item(0))
  6398. return true;
  6399. // Both are text ranges and the range matches
  6400. if (rng1.isEqual && rng2.isEqual && rng2.isEqual(rng1))
  6401. return true;
  6402. } else {
  6403. // Compare w3c ranges
  6404. return rng1.startContainer == rng2.startContainer && rng1.startOffset == rng2.startOffset;
  6405. }
  6406. }
  6407. return false;
  6408. };
  6409. })(tinymce);
  6410. (function(tinymce) {
  6411. var Event = tinymce.dom.Event, each = tinymce.each;
  6412. tinymce.create('tinymce.ui.KeyboardNavigation', {
  6413. KeyboardNavigation: function(settings, dom) {
  6414. var t = this, root = settings.root, items = settings.items,
  6415. enableUpDown = settings.enableUpDown, enableLeftRight = settings.enableLeftRight || !settings.enableUpDown,
  6416. excludeFromTabOrder = settings.excludeFromTabOrder,
  6417. itemFocussed, itemBlurred, rootKeydown, rootFocussed, focussedId;
  6418. dom = dom || tinymce.DOM;
  6419. itemFocussed = function(evt) {
  6420. focussedId = evt.target.id;
  6421. };
  6422. itemBlurred = function(evt) {
  6423. dom.setAttrib(evt.target.id, 'tabindex', '-1');
  6424. };
  6425. rootFocussed = function(evt) {
  6426. var item = dom.get(focussedId);
  6427. dom.setAttrib(item, 'tabindex', '0');
  6428. item.focus();
  6429. };
  6430. t.focus = function() {
  6431. dom.get(focussedId).focus();
  6432. };
  6433. t.destroy = function() {
  6434. each(items, function(item) {
  6435. dom.unbind(dom.get(item.id), 'focus', itemFocussed);
  6436. dom.unbind(dom.get(item.id), 'blur', itemBlurred);
  6437. });
  6438. dom.unbind(dom.get(root), 'focus', rootFocussed);
  6439. dom.unbind(dom.get(root), 'keydown', rootKeydown);
  6440. items = dom = root = t.focus = itemFocussed = itemBlurred = rootKeydown = rootFocussed = null;
  6441. t.destroy = function() {};
  6442. };
  6443. t.moveFocus = function(dir, evt) {
  6444. var idx = -1, controls = t.controls, newFocus;
  6445. if (!focussedId)
  6446. return;
  6447. each(items, function(item, index) {
  6448. if (item.id === focussedId) {
  6449. idx = index;
  6450. return false;
  6451. }
  6452. });
  6453. idx += dir;
  6454. if (idx < 0) {
  6455. idx = items.length - 1;
  6456. } else if (idx >= items.length) {
  6457. idx = 0;
  6458. }
  6459. newFocus = items[idx];
  6460. dom.setAttrib(focussedId, 'tabindex', '-1');
  6461. dom.setAttrib(newFocus.id, 'tabindex', '0');
  6462. dom.get(newFocus.id).focus();
  6463. if (settings.actOnFocus) {
  6464. settings.onAction(newFocus.id);
  6465. }
  6466. if (evt)
  6467. Event.cancel(evt);
  6468. };
  6469. rootKeydown = function(evt) {
  6470. 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;
  6471. switch (evt.keyCode) {
  6472. case DOM_VK_LEFT:
  6473. if (enableLeftRight) t.moveFocus(-1);
  6474. break;
  6475. case DOM_VK_RIGHT:
  6476. if (enableLeftRight) t.moveFocus(1);
  6477. break;
  6478. case DOM_VK_UP:
  6479. if (enableUpDown) t.moveFocus(-1);
  6480. break;
  6481. case DOM_VK_DOWN:
  6482. if (enableUpDown) t.moveFocus(1);
  6483. break;
  6484. case DOM_VK_ESCAPE:
  6485. if (settings.onCancel) {
  6486. settings.onCancel();
  6487. Event.cancel(evt);
  6488. }
  6489. break;
  6490. case DOM_VK_ENTER:
  6491. case DOM_VK_RETURN:
  6492. case DOM_VK_SPACE:
  6493. if (settings.onAction) {
  6494. settings.onAction(focussedId);
  6495. Event.cancel(evt);
  6496. }
  6497. break;
  6498. }
  6499. };
  6500. // Set up state and listeners for each item.
  6501. each(items, function(item, idx) {
  6502. var tabindex;
  6503. if (!item.id) {
  6504. item.id = dom.uniqueId('_mce_item_');
  6505. }
  6506. if (excludeFromTabOrder) {
  6507. dom.bind(item.id, 'blur', itemBlurred);
  6508. tabindex = '-1';
  6509. } else {
  6510. tabindex = (idx === 0 ? '0' : '-1');
  6511. }
  6512. dom.setAttrib(item.id, 'tabindex', tabindex);
  6513. dom.bind(dom.get(item.id), 'focus', itemFocussed);
  6514. });
  6515. // Setup initial state for root element.
  6516. if (items[0]){
  6517. focussedId = items[0].id;
  6518. }
  6519. dom.setAttrib(root, 'tabindex', '-1');
  6520. // Setup listeners for root element.
  6521. dom.bind(dom.get(root), 'focus', rootFocussed);
  6522. dom.bind(dom.get(root), 'keydown', rootKeydown);
  6523. }
  6524. });
  6525. })(tinymce);
  6526. (function(tinymce) {
  6527. // Shorten class names
  6528. var DOM = tinymce.DOM, is = tinymce.is;
  6529. tinymce.create('tinymce.ui.Control', {
  6530. Control : function(id, s, editor) {
  6531. this.id = id;
  6532. this.settings = s = s || {};
  6533. this.rendered = false;
  6534. this.onRender = new tinymce.util.Dispatcher(this);
  6535. this.classPrefix = '';
  6536. this.scope = s.scope || this;
  6537. this.disabled = 0;
  6538. this.active = 0;
  6539. this.editor = editor;
  6540. },
  6541. setAriaProperty : function(property, value) {
  6542. var element = DOM.get(this.id + '_aria') || DOM.get(this.id);
  6543. if (element) {
  6544. DOM.setAttrib(element, 'aria-' + property, !!value);
  6545. }
  6546. },
  6547. focus : function() {
  6548. DOM.get(this.id).focus();
  6549. },
  6550. setDisabled : function(s) {
  6551. if (s != this.disabled) {
  6552. this.setAriaProperty('disabled', s);
  6553. this.setState('Disabled', s);
  6554. this.setState('Enabled', !s);
  6555. this.disabled = s;
  6556. }
  6557. },
  6558. isDisabled : function() {
  6559. return this.disabled;
  6560. },
  6561. setActive : function(s) {
  6562. if (s != this.active) {
  6563. this.setState('Active', s);
  6564. this.active = s;
  6565. this.setAriaProperty('pressed', s);
  6566. }
  6567. },
  6568. isActive : function() {
  6569. return this.active;
  6570. },
  6571. setState : function(c, s) {
  6572. var n = DOM.get(this.id);
  6573. c = this.classPrefix + c;
  6574. if (s)
  6575. DOM.addClass(n, c);
  6576. else
  6577. DOM.removeClass(n, c);
  6578. },
  6579. isRendered : function() {
  6580. return this.rendered;
  6581. },
  6582. renderHTML : function() {
  6583. },
  6584. renderTo : function(n) {
  6585. DOM.setHTML(n, this.renderHTML());
  6586. },
  6587. postRender : function() {
  6588. var t = this, b;
  6589. // Set pending states
  6590. if (is(t.disabled)) {
  6591. b = t.disabled;
  6592. t.disabled = -1;
  6593. t.setDisabled(b);
  6594. }
  6595. if (is(t.active)) {
  6596. b = t.active;
  6597. t.active = -1;
  6598. t.setActive(b);
  6599. }
  6600. },
  6601. remove : function() {
  6602. DOM.remove(this.id);
  6603. this.destroy();
  6604. },
  6605. destroy : function() {
  6606. tinymce.dom.Event.clear(this.id);
  6607. }
  6608. });
  6609. })(tinymce);
  6610. tinymce.create('tinymce.ui.Container:tinymce.ui.Control', {
  6611. Container : function(id, s, editor) {
  6612. this.parent(id, s, editor);
  6613. this.controls = [];
  6614. this.lookup = {};
  6615. },
  6616. add : function(c) {
  6617. this.lookup[c.id] = c;
  6618. this.controls.push(c);
  6619. return c;
  6620. },
  6621. get : function(n) {
  6622. return this.lookup[n];
  6623. }
  6624. });
  6625. tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', {
  6626. Separator : function(id, s) {
  6627. this.parent(id, s);
  6628. this.classPrefix = 'mceSeparator';
  6629. this.setDisabled(true);
  6630. },
  6631. renderHTML : function() {
  6632. return tinymce.DOM.createHTML('span', {'class' : this.classPrefix, role : 'separator', 'aria-orientation' : 'vertical', tabindex : '-1'});
  6633. }
  6634. });
  6635. (function(tinymce) {
  6636. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  6637. tinymce.create('tinymce.ui.MenuItem:tinymce.ui.Control', {
  6638. MenuItem : function(id, s) {
  6639. this.parent(id, s);
  6640. this.classPrefix = 'mceMenuItem';
  6641. },
  6642. setSelected : function(s) {
  6643. this.setState('Selected', s);
  6644. this.setAriaProperty('checked', !!s);
  6645. this.selected = s;
  6646. },
  6647. isSelected : function() {
  6648. return this.selected;
  6649. },
  6650. postRender : function() {
  6651. var t = this;
  6652. t.parent();
  6653. // Set pending state
  6654. if (is(t.selected))
  6655. t.setSelected(t.selected);
  6656. }
  6657. });
  6658. })(tinymce);
  6659. (function(tinymce) {
  6660. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  6661. tinymce.create('tinymce.ui.Menu:tinymce.ui.MenuItem', {
  6662. Menu : function(id, s) {
  6663. var t = this;
  6664. t.parent(id, s);
  6665. t.items = {};
  6666. t.collapsed = false;
  6667. t.menuCount = 0;
  6668. t.onAddItem = new tinymce.util.Dispatcher(this);
  6669. },
  6670. expand : function(d) {
  6671. var t = this;
  6672. if (d) {
  6673. walk(t, function(o) {
  6674. if (o.expand)
  6675. o.expand();
  6676. }, 'items', t);
  6677. }
  6678. t.collapsed = false;
  6679. },
  6680. collapse : function(d) {
  6681. var t = this;
  6682. if (d) {
  6683. walk(t, function(o) {
  6684. if (o.collapse)
  6685. o.collapse();
  6686. }, 'items', t);
  6687. }
  6688. t.collapsed = true;
  6689. },
  6690. isCollapsed : function() {
  6691. return this.collapsed;
  6692. },
  6693. add : function(o) {
  6694. if (!o.settings)
  6695. o = new tinymce.ui.MenuItem(o.id || DOM.uniqueId(), o);
  6696. this.onAddItem.dispatch(this, o);
  6697. return this.items[o.id] = o;
  6698. },
  6699. addSeparator : function() {
  6700. return this.add({separator : true});
  6701. },
  6702. addMenu : function(o) {
  6703. if (!o.collapse)
  6704. o = this.createMenu(o);
  6705. this.menuCount++;
  6706. return this.add(o);
  6707. },
  6708. hasMenus : function() {
  6709. return this.menuCount !== 0;
  6710. },
  6711. remove : function(o) {
  6712. delete this.items[o.id];
  6713. },
  6714. removeAll : function() {
  6715. var t = this;
  6716. walk(t, function(o) {
  6717. if (o.removeAll)
  6718. o.removeAll();
  6719. else
  6720. o.remove();
  6721. o.destroy();
  6722. }, 'items', t);
  6723. t.items = {};
  6724. },
  6725. createMenu : function(o) {
  6726. var m = new tinymce.ui.Menu(o.id || DOM.uniqueId(), o);
  6727. m.onAddItem.add(this.onAddItem.dispatch, this.onAddItem);
  6728. return m;
  6729. }
  6730. });
  6731. })(tinymce);
  6732. (function(tinymce) {
  6733. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event, Element = tinymce.dom.Element;
  6734. tinymce.create('tinymce.ui.DropMenu:tinymce.ui.Menu', {
  6735. DropMenu : function(id, s) {
  6736. s = s || {};
  6737. s.container = s.container || DOM.doc.body;
  6738. s.offset_x = s.offset_x || 0;
  6739. s.offset_y = s.offset_y || 0;
  6740. s.vp_offset_x = s.vp_offset_x || 0;
  6741. s.vp_offset_y = s.vp_offset_y || 0;
  6742. if (is(s.icons) && !s.icons)
  6743. s['class'] += ' mceNoIcons';
  6744. this.parent(id, s);
  6745. this.onShowMenu = new tinymce.util.Dispatcher(this);
  6746. this.onHideMenu = new tinymce.util.Dispatcher(this);
  6747. this.classPrefix = 'mceMenu';
  6748. },
  6749. createMenu : function(s) {
  6750. var t = this, cs = t.settings, m;
  6751. s.container = s.container || cs.container;
  6752. s.parent = t;
  6753. s.constrain = s.constrain || cs.constrain;
  6754. s['class'] = s['class'] || cs['class'];
  6755. s.vp_offset_x = s.vp_offset_x || cs.vp_offset_x;
  6756. s.vp_offset_y = s.vp_offset_y || cs.vp_offset_y;
  6757. s.keyboard_focus = cs.keyboard_focus;
  6758. m = new tinymce.ui.DropMenu(s.id || DOM.uniqueId(), s);
  6759. m.onAddItem.add(t.onAddItem.dispatch, t.onAddItem);
  6760. return m;
  6761. },
  6762. focus : function() {
  6763. var t = this;
  6764. if (t.keyboardNav) {
  6765. t.keyboardNav.focus();
  6766. }
  6767. },
  6768. update : function() {
  6769. var t = this, s = t.settings, tb = DOM.get('menu_' + t.id + '_tbl'), co = DOM.get('menu_' + t.id + '_co'), tw, th;
  6770. tw = s.max_width ? Math.min(tb.clientWidth, s.max_width) : tb.clientWidth;
  6771. th = s.max_height ? Math.min(tb.clientHeight, s.max_height) : tb.clientHeight;
  6772. if (!DOM.boxModel)
  6773. t.element.setStyles({width : tw + 2, height : th + 2});
  6774. else
  6775. t.element.setStyles({width : tw, height : th});
  6776. if (s.max_width)
  6777. DOM.setStyle(co, 'width', tw);
  6778. if (s.max_height) {
  6779. DOM.setStyle(co, 'height', th);
  6780. if (tb.clientHeight < s.max_height)
  6781. DOM.setStyle(co, 'overflow', 'hidden');
  6782. }
  6783. },
  6784. showMenu : function(x, y, px) {
  6785. var t = this, s = t.settings, co, vp = DOM.getViewPort(), w, h, mx, my, ot = 2, dm, tb, cp = t.classPrefix;
  6786. t.collapse(1);
  6787. if (t.isMenuVisible)
  6788. return;
  6789. if (!t.rendered) {
  6790. co = DOM.add(t.settings.container, t.renderNode());
  6791. each(t.items, function(o) {
  6792. o.postRender();
  6793. });
  6794. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  6795. } else
  6796. co = DOM.get('menu_' + t.id);
  6797. // Move layer out of sight unless it's Opera since it scrolls to top of page due to an bug
  6798. if (!tinymce.isOpera)
  6799. DOM.setStyles(co, {left : -0xFFFF , top : -0xFFFF});
  6800. DOM.show(co);
  6801. t.update();
  6802. x += s.offset_x || 0;
  6803. y += s.offset_y || 0;
  6804. vp.w -= 4;
  6805. vp.h -= 4;
  6806. // Move inside viewport if not submenu
  6807. if (s.constrain) {
  6808. w = co.clientWidth - ot;
  6809. h = co.clientHeight - ot;
  6810. mx = vp.x + vp.w;
  6811. my = vp.y + vp.h;
  6812. if ((x + s.vp_offset_x + w) > mx)
  6813. x = px ? px - w : Math.max(0, (mx - s.vp_offset_x) - w);
  6814. if ((y + s.vp_offset_y + h) > my)
  6815. y = Math.max(0, (my - s.vp_offset_y) - h);
  6816. }
  6817. DOM.setStyles(co, {left : x , top : y});
  6818. t.element.update();
  6819. t.isMenuVisible = 1;
  6820. t.mouseClickFunc = Event.add(co, 'click', function(e) {
  6821. var m;
  6822. e = e.target;
  6823. if (e && (e = DOM.getParent(e, 'tr')) && !DOM.hasClass(e, cp + 'ItemSub')) {
  6824. m = t.items[e.id];
  6825. if (m.isDisabled())
  6826. return;
  6827. dm = t;
  6828. while (dm) {
  6829. if (dm.hideMenu)
  6830. dm.hideMenu();
  6831. dm = dm.settings.parent;
  6832. }
  6833. if (m.settings.onclick)
  6834. m.settings.onclick(e);
  6835. return Event.cancel(e); // Cancel to fix onbeforeunload problem
  6836. }
  6837. });
  6838. if (t.hasMenus()) {
  6839. t.mouseOverFunc = Event.add(co, 'mouseover', function(e) {
  6840. var m, r, mi;
  6841. e = e.target;
  6842. if (e && (e = DOM.getParent(e, 'tr'))) {
  6843. m = t.items[e.id];
  6844. if (t.lastMenu)
  6845. t.lastMenu.collapse(1);
  6846. if (m.isDisabled())
  6847. return;
  6848. if (e && DOM.hasClass(e, cp + 'ItemSub')) {
  6849. //p = DOM.getPos(s.container);
  6850. r = DOM.getRect(e);
  6851. m.showMenu((r.x + r.w - ot), r.y - ot, r.x);
  6852. t.lastMenu = m;
  6853. DOM.addClass(DOM.get(m.id).firstChild, cp + 'ItemActive');
  6854. }
  6855. }
  6856. });
  6857. }
  6858. Event.add(co, 'keydown', t._keyHandler, t);
  6859. t.onShowMenu.dispatch(t);
  6860. if (s.keyboard_focus) {
  6861. t._setupKeyboardNav();
  6862. }
  6863. },
  6864. hideMenu : function(c) {
  6865. var t = this, co = DOM.get('menu_' + t.id), e;
  6866. if (!t.isMenuVisible)
  6867. return;
  6868. if (t.keyboardNav) t.keyboardNav.destroy();
  6869. Event.remove(co, 'mouseover', t.mouseOverFunc);
  6870. Event.remove(co, 'click', t.mouseClickFunc);
  6871. Event.remove(co, 'keydown', t._keyHandler);
  6872. DOM.hide(co);
  6873. t.isMenuVisible = 0;
  6874. if (!c)
  6875. t.collapse(1);
  6876. if (t.element)
  6877. t.element.hide();
  6878. if (e = DOM.get(t.id))
  6879. DOM.removeClass(e.firstChild, t.classPrefix + 'ItemActive');
  6880. t.onHideMenu.dispatch(t);
  6881. },
  6882. add : function(o) {
  6883. var t = this, co;
  6884. o = t.parent(o);
  6885. if (t.isRendered && (co = DOM.get('menu_' + t.id)))
  6886. t._add(DOM.select('tbody', co)[0], o);
  6887. return o;
  6888. },
  6889. collapse : function(d) {
  6890. this.parent(d);
  6891. this.hideMenu(1);
  6892. },
  6893. remove : function(o) {
  6894. DOM.remove(o.id);
  6895. this.destroy();
  6896. return this.parent(o);
  6897. },
  6898. destroy : function() {
  6899. var t = this, co = DOM.get('menu_' + t.id);
  6900. if (t.keyboardNav) t.keyboardNav.destroy();
  6901. Event.remove(co, 'mouseover', t.mouseOverFunc);
  6902. Event.remove(DOM.select('a', co), 'focus', t.mouseOverFunc);
  6903. Event.remove(co, 'click', t.mouseClickFunc);
  6904. Event.remove(co, 'keydown', t._keyHandler);
  6905. if (t.element)
  6906. t.element.remove();
  6907. DOM.remove(co);
  6908. },
  6909. renderNode : function() {
  6910. var t = this, s = t.settings, n, tb, co, w;
  6911. 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'});
  6912. if (t.settings.parent) {
  6913. DOM.setAttrib(w, 'aria-parent', 'menu_' + t.settings.parent.id);
  6914. }
  6915. co = DOM.add(w, 'div', {role: 'presentation', id : 'menu_' + t.id + '_co', 'class' : t.classPrefix + (s['class'] ? ' ' + s['class'] : '')});
  6916. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  6917. if (s.menu_line)
  6918. DOM.add(co, 'span', {'class' : t.classPrefix + 'Line'});
  6919. // n = DOM.add(co, 'div', {id : 'menu_' + t.id + '_co', 'class' : 'mceMenuContainer'});
  6920. n = DOM.add(co, 'table', {role: 'presentation', id : 'menu_' + t.id + '_tbl', border : 0, cellPadding : 0, cellSpacing : 0});
  6921. tb = DOM.add(n, 'tbody');
  6922. each(t.items, function(o) {
  6923. t._add(tb, o);
  6924. });
  6925. t.rendered = true;
  6926. return w;
  6927. },
  6928. // Internal functions
  6929. _setupKeyboardNav : function(){
  6930. var contextMenu, menuItems, t=this;
  6931. contextMenu = DOM.select('#menu_' + t.id)[0];
  6932. menuItems = DOM.select('a[role=option]', 'menu_' + t.id);
  6933. menuItems.splice(0,0,contextMenu);
  6934. t.keyboardNav = new tinymce.ui.KeyboardNavigation({
  6935. root: 'menu_' + t.id,
  6936. items: menuItems,
  6937. onCancel: function() {
  6938. t.hideMenu();
  6939. },
  6940. enableUpDown: true
  6941. });
  6942. contextMenu.focus();
  6943. },
  6944. _keyHandler : function(evt) {
  6945. var t = this, e;
  6946. switch (evt.keyCode) {
  6947. case 37: // Left
  6948. if (t.settings.parent) {
  6949. t.hideMenu();
  6950. t.settings.parent.focus();
  6951. Event.cancel(evt);
  6952. }
  6953. break;
  6954. case 39: // Right
  6955. if (t.mouseOverFunc)
  6956. t.mouseOverFunc(evt);
  6957. break;
  6958. }
  6959. },
  6960. _add : function(tb, o) {
  6961. var n, s = o.settings, a, ro, it, cp = this.classPrefix, ic;
  6962. if (s.separator) {
  6963. ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'ItemSeparator'});
  6964. DOM.add(ro, 'td', {'class' : cp + 'ItemSeparator'});
  6965. if (n = ro.previousSibling)
  6966. DOM.addClass(n, 'mceLast');
  6967. return;
  6968. }
  6969. n = ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'Item ' + cp + 'ItemEnabled'});
  6970. n = it = DOM.add(n, s.titleItem ? 'th' : 'td');
  6971. n = a = DOM.add(n, 'a', {id: o.id + '_aria', role: s.titleItem ? 'presentation' : 'option', href : 'javascript:;', onclick : "return false;", onmousedown : 'return false;'});
  6972. if (s.parent) {
  6973. DOM.setAttrib(a, 'aria-haspopup', 'true');
  6974. DOM.setAttrib(a, 'aria-owns', 'menu_' + o.id);
  6975. }
  6976. DOM.addClass(it, s['class']);
  6977. // n = DOM.add(n, 'span', {'class' : 'item'});
  6978. ic = DOM.add(n, 'span', {'class' : 'mceIcon' + (s.icon ? ' mce_' + s.icon : '')});
  6979. if (s.icon_src)
  6980. DOM.add(ic, 'img', {src : s.icon_src});
  6981. n = DOM.add(n, s.element || 'span', {'class' : 'mceText', title : o.settings.title}, o.settings.title);
  6982. if (o.settings.style)
  6983. DOM.setAttrib(n, 'style', o.settings.style);
  6984. if (tb.childNodes.length == 1)
  6985. DOM.addClass(ro, 'mceFirst');
  6986. if ((n = ro.previousSibling) && DOM.hasClass(n, cp + 'ItemSeparator'))
  6987. DOM.addClass(ro, 'mceFirst');
  6988. if (o.collapse)
  6989. DOM.addClass(ro, cp + 'ItemSub');
  6990. if (n = ro.previousSibling)
  6991. DOM.removeClass(n, 'mceLast');
  6992. DOM.addClass(ro, 'mceLast');
  6993. }
  6994. });
  6995. })(tinymce);
  6996. (function(tinymce) {
  6997. var DOM = tinymce.DOM;
  6998. tinymce.create('tinymce.ui.Button:tinymce.ui.Control', {
  6999. Button : function(id, s, ed) {
  7000. this.parent(id, s, ed);
  7001. this.classPrefix = 'mceButton';
  7002. },
  7003. renderHTML : function() {
  7004. var cp = this.classPrefix, s = this.settings, h, l;
  7005. l = DOM.encode(s.label || '');
  7006. 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) + '">';
  7007. if (s.image && !(this.editor &&this.editor.forcedHighContrastMode) )
  7008. h += '<img class="mceIcon" src="' + s.image + '" alt="' + DOM.encode(s.title) + '" />' + l;
  7009. else
  7010. h += '<span class="mceIcon ' + s['class'] + '"></span>' + (l ? '<span class="' + cp + 'Label">' + l + '</span>' : '');
  7011. h += '<span class="mceVoiceLabel mceIconOnly" style="display: none;" id="' + this.id + '_voice">' + s.title + '</span>';
  7012. h += '</a>';
  7013. return h;
  7014. },
  7015. postRender : function() {
  7016. var t = this, s = t.settings;
  7017. tinymce.dom.Event.add(t.id, 'click', function(e) {
  7018. if (!t.isDisabled())
  7019. return s.onclick.call(s.scope, e);
  7020. });
  7021. }
  7022. });
  7023. })(tinymce);
  7024. (function(tinymce) {
  7025. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher;
  7026. tinymce.create('tinymce.ui.ListBox:tinymce.ui.Control', {
  7027. ListBox : function(id, s, ed) {
  7028. var t = this;
  7029. t.parent(id, s, ed);
  7030. t.items = [];
  7031. t.onChange = new Dispatcher(t);
  7032. t.onPostRender = new Dispatcher(t);
  7033. t.onAdd = new Dispatcher(t);
  7034. t.onRenderMenu = new tinymce.util.Dispatcher(this);
  7035. t.classPrefix = 'mceListBox';
  7036. },
  7037. select : function(va) {
  7038. var t = this, fv, f;
  7039. if (va == undefined)
  7040. return t.selectByIndex(-1);
  7041. // Is string or number make function selector
  7042. if (va && va.call)
  7043. f = va;
  7044. else {
  7045. f = function(v) {
  7046. return v == va;
  7047. };
  7048. }
  7049. // Do we need to do something?
  7050. if (va != t.selectedValue) {
  7051. // Find item
  7052. each(t.items, function(o, i) {
  7053. if (f(o.value)) {
  7054. fv = 1;
  7055. t.selectByIndex(i);
  7056. return false;
  7057. }
  7058. });
  7059. if (!fv)
  7060. t.selectByIndex(-1);
  7061. }
  7062. },
  7063. selectByIndex : function(idx) {
  7064. var t = this, e, o, label;
  7065. if (idx != t.selectedIndex) {
  7066. e = DOM.get(t.id + '_text');
  7067. label = DOM.get(t.id + '_voiceDesc');
  7068. o = t.items[idx];
  7069. if (o) {
  7070. t.selectedValue = o.value;
  7071. t.selectedIndex = idx;
  7072. DOM.setHTML(e, DOM.encode(o.title));
  7073. DOM.setHTML(label, t.settings.title + " - " + o.title);
  7074. DOM.removeClass(e, 'mceTitle');
  7075. DOM.setAttrib(t.id, 'aria-valuenow', o.title);
  7076. } else {
  7077. DOM.setHTML(e, DOM.encode(t.settings.title));
  7078. DOM.setHTML(label, DOM.encode(t.settings.title));
  7079. DOM.addClass(e, 'mceTitle');
  7080. t.selectedValue = t.selectedIndex = null;
  7081. DOM.setAttrib(t.id, 'aria-valuenow', t.settings.title);
  7082. }
  7083. e = 0;
  7084. }
  7085. },
  7086. add : function(n, v, o) {
  7087. var t = this;
  7088. o = o || {};
  7089. o = tinymce.extend(o, {
  7090. title : n,
  7091. value : v
  7092. });
  7093. t.items.push(o);
  7094. t.onAdd.dispatch(t, o);
  7095. },
  7096. getLength : function() {
  7097. return this.items.length;
  7098. },
  7099. renderHTML : function() {
  7100. var h = '', t = this, s = t.settings, cp = t.classPrefix;
  7101. 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>';
  7102. h += '<td>' + DOM.createHTML('span', {id: t.id + '_voiceDesc', 'class': 'voiceLabel', style:'display:none;'}, t.settings.title);
  7103. 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>';
  7104. 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>';
  7105. h += '</tr></tbody></table></span>';
  7106. return h;
  7107. },
  7108. showMenu : function() {
  7109. var t = this, p2, e = DOM.get(this.id), m;
  7110. if (t.isDisabled() || t.items.length == 0)
  7111. return;
  7112. if (t.menu && t.menu.isMenuVisible)
  7113. return t.hideMenu();
  7114. if (!t.isMenuRendered) {
  7115. t.renderMenu();
  7116. t.isMenuRendered = true;
  7117. }
  7118. p2 = DOM.getPos(e);
  7119. m = t.menu;
  7120. m.settings.offset_x = p2.x;
  7121. m.settings.offset_y = p2.y;
  7122. m.settings.keyboard_focus = !tinymce.isOpera; // Opera is buggy when it comes to auto focus
  7123. // Select in menu
  7124. if (t.oldID)
  7125. m.items[t.oldID].setSelected(0);
  7126. each(t.items, function(o) {
  7127. if (o.value === t.selectedValue) {
  7128. m.items[o.id].setSelected(1);
  7129. t.oldID = o.id;
  7130. }
  7131. });
  7132. m.showMenu(0, e.clientHeight);
  7133. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  7134. DOM.addClass(t.id, t.classPrefix + 'Selected');
  7135. //DOM.get(t.id + '_text').focus();
  7136. },
  7137. hideMenu : function(e) {
  7138. var t = this;
  7139. if (t.menu && t.menu.isMenuVisible) {
  7140. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  7141. // Prevent double toogles by canceling the mouse click event to the button
  7142. if (e && e.type == "mousedown" && (e.target.id == t.id + '_text' || e.target.id == t.id + '_open'))
  7143. return;
  7144. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  7145. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  7146. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  7147. t.menu.hideMenu();
  7148. }
  7149. }
  7150. },
  7151. renderMenu : function() {
  7152. var t = this, m;
  7153. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  7154. menu_line : 1,
  7155. 'class' : t.classPrefix + 'Menu mceNoIcons',
  7156. max_width : 150,
  7157. max_height : 150
  7158. });
  7159. m.onHideMenu.add(function() {
  7160. t.hideMenu();
  7161. t.focus();
  7162. });
  7163. m.add({
  7164. title : t.settings.title,
  7165. 'class' : 'mceMenuItemTitle',
  7166. onclick : function() {
  7167. if (t.settings.onselect('') !== false)
  7168. t.select(''); // Must be runned after
  7169. }
  7170. });
  7171. each(t.items, function(o) {
  7172. // No value then treat it as a title
  7173. if (o.value === undefined) {
  7174. m.add({
  7175. title : o.title,
  7176. role : "option",
  7177. 'class' : 'mceMenuItemTitle',
  7178. onclick : function() {
  7179. if (t.settings.onselect('') !== false)
  7180. t.select(''); // Must be runned after
  7181. }
  7182. });
  7183. } else {
  7184. o.id = DOM.uniqueId();
  7185. o.role= "option";
  7186. o.onclick = function() {
  7187. if (t.settings.onselect(o.value) !== false)
  7188. t.select(o.value); // Must be runned after
  7189. };
  7190. m.add(o);
  7191. }
  7192. });
  7193. t.onRenderMenu.dispatch(t, m);
  7194. t.menu = m;
  7195. },
  7196. postRender : function() {
  7197. var t = this, cp = t.classPrefix;
  7198. Event.add(t.id, 'click', t.showMenu, t);
  7199. Event.add(t.id, 'keydown', function(evt) {
  7200. if (evt.keyCode == 32) { // Space
  7201. t.showMenu(evt);
  7202. Event.cancel(evt);
  7203. }
  7204. });
  7205. Event.add(t.id, 'focus', function() {
  7206. if (!t._focused) {
  7207. t.keyDownHandler = Event.add(t.id, 'keydown', function(e) {
  7208. if (e.keyCode == 40) {
  7209. t.showMenu();
  7210. Event.cancel(e);
  7211. }
  7212. });
  7213. t.keyPressHandler = Event.add(t.id, 'keypress', function(e) {
  7214. var v;
  7215. if (e.keyCode == 13) {
  7216. // Fake select on enter
  7217. v = t.selectedValue;
  7218. t.selectedValue = null; // Needs to be null to fake change
  7219. Event.cancel(e);
  7220. t.settings.onselect(v);
  7221. }
  7222. });
  7223. }
  7224. t._focused = 1;
  7225. });
  7226. Event.add(t.id, 'blur', function() {
  7227. Event.remove(t.id, 'keydown', t.keyDownHandler);
  7228. Event.remove(t.id, 'keypress', t.keyPressHandler);
  7229. t._focused = 0;
  7230. });
  7231. // Old IE doesn't have hover on all elements
  7232. if (tinymce.isIE6 || !DOM.boxModel) {
  7233. Event.add(t.id, 'mouseover', function() {
  7234. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  7235. DOM.addClass(t.id, cp + 'Hover');
  7236. });
  7237. Event.add(t.id, 'mouseout', function() {
  7238. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  7239. DOM.removeClass(t.id, cp + 'Hover');
  7240. });
  7241. }
  7242. t.onPostRender.dispatch(t, DOM.get(t.id));
  7243. },
  7244. destroy : function() {
  7245. this.parent();
  7246. Event.clear(this.id + '_text');
  7247. Event.clear(this.id + '_open');
  7248. }
  7249. });
  7250. })(tinymce);
  7251. (function(tinymce) {
  7252. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher;
  7253. tinymce.create('tinymce.ui.NativeListBox:tinymce.ui.ListBox', {
  7254. NativeListBox : function(id, s) {
  7255. this.parent(id, s);
  7256. this.classPrefix = 'mceNativeListBox';
  7257. },
  7258. setDisabled : function(s) {
  7259. DOM.get(this.id).disabled = s;
  7260. this.setAriaProperty('disabled', s);
  7261. },
  7262. isDisabled : function() {
  7263. return DOM.get(this.id).disabled;
  7264. },
  7265. select : function(va) {
  7266. var t = this, fv, f;
  7267. if (va == undefined)
  7268. return t.selectByIndex(-1);
  7269. // Is string or number make function selector
  7270. if (va && va.call)
  7271. f = va;
  7272. else {
  7273. f = function(v) {
  7274. return v == va;
  7275. };
  7276. }
  7277. // Do we need to do something?
  7278. if (va != t.selectedValue) {
  7279. // Find item
  7280. each(t.items, function(o, i) {
  7281. if (f(o.value)) {
  7282. fv = 1;
  7283. t.selectByIndex(i);
  7284. return false;
  7285. }
  7286. });
  7287. if (!fv)
  7288. t.selectByIndex(-1);
  7289. }
  7290. },
  7291. selectByIndex : function(idx) {
  7292. DOM.get(this.id).selectedIndex = idx + 1;
  7293. this.selectedValue = this.items[idx] ? this.items[idx].value : null;
  7294. },
  7295. add : function(n, v, a) {
  7296. var o, t = this;
  7297. a = a || {};
  7298. a.value = v;
  7299. if (t.isRendered())
  7300. DOM.add(DOM.get(this.id), 'option', a, n);
  7301. o = {
  7302. title : n,
  7303. value : v,
  7304. attribs : a
  7305. };
  7306. t.items.push(o);
  7307. t.onAdd.dispatch(t, o);
  7308. },
  7309. getLength : function() {
  7310. return this.items.length;
  7311. },
  7312. renderHTML : function() {
  7313. var h, t = this;
  7314. h = DOM.createHTML('option', {value : ''}, '-- ' + t.settings.title + ' --');
  7315. each(t.items, function(it) {
  7316. h += DOM.createHTML('option', {value : it.value}, it.title);
  7317. });
  7318. h = DOM.createHTML('select', {id : t.id, 'class' : 'mceNativeListBox', 'aria-labelledby': t.id + '_aria'}, h);
  7319. h += DOM.createHTML('span', {id : t.id + '_aria', 'style': 'display: none'}, t.settings.title);
  7320. return h;
  7321. },
  7322. postRender : function() {
  7323. var t = this, ch, changeListenerAdded = true;
  7324. t.rendered = true;
  7325. function onChange(e) {
  7326. var v = t.items[e.target.selectedIndex - 1];
  7327. if (v && (v = v.value)) {
  7328. t.onChange.dispatch(t, v);
  7329. if (t.settings.onselect)
  7330. t.settings.onselect(v);
  7331. }
  7332. };
  7333. Event.add(t.id, 'change', onChange);
  7334. // Accessibility keyhandler
  7335. Event.add(t.id, 'keydown', function(e) {
  7336. var bf;
  7337. Event.remove(t.id, 'change', ch);
  7338. changeListenerAdded = false;
  7339. bf = Event.add(t.id, 'blur', function() {
  7340. if (changeListenerAdded) return;
  7341. changeListenerAdded = true;
  7342. Event.add(t.id, 'change', onChange);
  7343. Event.remove(t.id, 'blur', bf);
  7344. });
  7345. //prevent default left and right keys on chrome - so that the keyboard navigation is used.
  7346. if (tinymce.isWebKit && (e.keyCode==37 ||e.keyCode==39)) {
  7347. return Event.prevent(e);
  7348. }
  7349. if (e.keyCode == 13 || e.keyCode == 32) {
  7350. onChange(e);
  7351. return Event.cancel(e);
  7352. }
  7353. });
  7354. t.onPostRender.dispatch(t, DOM.get(t.id));
  7355. }
  7356. });
  7357. })(tinymce);
  7358. (function(tinymce) {
  7359. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  7360. tinymce.create('tinymce.ui.MenuButton:tinymce.ui.Button', {
  7361. MenuButton : function(id, s, ed) {
  7362. this.parent(id, s, ed);
  7363. this.onRenderMenu = new tinymce.util.Dispatcher(this);
  7364. s.menu_container = s.menu_container || DOM.doc.body;
  7365. },
  7366. showMenu : function() {
  7367. var t = this, p1, p2, e = DOM.get(t.id), m;
  7368. if (t.isDisabled())
  7369. return;
  7370. if (!t.isMenuRendered) {
  7371. t.renderMenu();
  7372. t.isMenuRendered = true;
  7373. }
  7374. if (t.isMenuVisible)
  7375. return t.hideMenu();
  7376. p1 = DOM.getPos(t.settings.menu_container);
  7377. p2 = DOM.getPos(e);
  7378. m = t.menu;
  7379. m.settings.offset_x = p2.x;
  7380. m.settings.offset_y = p2.y;
  7381. m.settings.vp_offset_x = p2.x;
  7382. m.settings.vp_offset_y = p2.y;
  7383. m.settings.keyboard_focus = t._focused;
  7384. m.showMenu(0, e.clientHeight);
  7385. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  7386. t.setState('Selected', 1);
  7387. t.isMenuVisible = 1;
  7388. },
  7389. renderMenu : function() {
  7390. var t = this, m;
  7391. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  7392. menu_line : 1,
  7393. 'class' : this.classPrefix + 'Menu',
  7394. icons : t.settings.icons
  7395. });
  7396. m.onHideMenu.add(function() {
  7397. t.hideMenu();
  7398. t.focus();
  7399. });
  7400. t.onRenderMenu.dispatch(t, m);
  7401. t.menu = m;
  7402. },
  7403. hideMenu : function(e) {
  7404. var t = this;
  7405. // Prevent double toogles by canceling the mouse click event to the button
  7406. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id || e.id === t.id + '_open';}))
  7407. return;
  7408. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  7409. t.setState('Selected', 0);
  7410. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  7411. if (t.menu)
  7412. t.menu.hideMenu();
  7413. }
  7414. t.isMenuVisible = 0;
  7415. },
  7416. postRender : function() {
  7417. var t = this, s = t.settings;
  7418. Event.add(t.id, 'click', function() {
  7419. if (!t.isDisabled()) {
  7420. if (s.onclick)
  7421. s.onclick(t.value);
  7422. t.showMenu();
  7423. }
  7424. });
  7425. }
  7426. });
  7427. })(tinymce);
  7428. (function(tinymce) {
  7429. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  7430. tinymce.create('tinymce.ui.SplitButton:tinymce.ui.MenuButton', {
  7431. SplitButton : function(id, s, ed) {
  7432. this.parent(id, s, ed);
  7433. this.classPrefix = 'mceSplitButton';
  7434. },
  7435. renderHTML : function() {
  7436. var h, t = this, s = t.settings, h1;
  7437. h = '<tbody><tr>';
  7438. if (s.image)
  7439. h1 = DOM.createHTML('img ', {src : s.image, role: 'presentation', 'class' : 'mceAction ' + s['class']});
  7440. else
  7441. h1 = DOM.createHTML('span', {'class' : 'mceAction ' + s['class']}, '');
  7442. h1 += DOM.createHTML('span', {'class': 'mceVoiceLabel mceIconOnly', id: t.id + '_voice', style: 'display:none;'}, s.title);
  7443. 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>';
  7444. h1 = DOM.createHTML('span', {'class' : 'mceOpen ' + s['class']}, '<span style="display:none;" class="mceIconOnly" aria-hidden="true">\u25BC</span>');
  7445. 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>';
  7446. h += '</tr></tbody>';
  7447. h = DOM.createHTML('table', { role: 'presentation', 'class' : 'mceSplitButton mceSplitButtonEnabled ' + s['class'], cellpadding : '0', cellspacing : '0', title : s.title}, h);
  7448. return DOM.createHTML('div', {id : t.id, role: 'button', tabindex: '0', 'aria-labelledby': t.id + '_voice', 'aria-haspopup': 'true'}, h);
  7449. },
  7450. postRender : function() {
  7451. var t = this, s = t.settings, activate;
  7452. if (s.onclick) {
  7453. activate = function(evt) {
  7454. if (!t.isDisabled()) {
  7455. s.onclick(t.value);
  7456. Event.cancel(evt);
  7457. }
  7458. };
  7459. Event.add(t.id + '_action', 'click', activate);
  7460. Event.add(t.id, ['click', 'keydown'], function(evt) {
  7461. var DOM_VK_SPACE = 32, DOM_VK_ENTER = 14, DOM_VK_RETURN = 13, DOM_VK_UP = 38, DOM_VK_DOWN = 40;
  7462. if ((evt.keyCode === 32 || evt.keyCode === 13 || evt.keyCode === 14) && !evt.altKey && !evt.ctrlKey && !evt.metaKey) {
  7463. activate();
  7464. Event.cancel(evt);
  7465. } else if (evt.type === 'click' || evt.keyCode === DOM_VK_DOWN) {
  7466. t.showMenu();
  7467. Event.cancel(evt);
  7468. }
  7469. });
  7470. }
  7471. Event.add(t.id + '_open', 'click', function (evt) {
  7472. t.showMenu();
  7473. Event.cancel(evt);
  7474. });
  7475. Event.add([t.id, t.id + '_open'], 'focus', function() {t._focused = 1;});
  7476. Event.add([t.id, t.id + '_open'], 'blur', function() {t._focused = 0;});
  7477. // Old IE doesn't have hover on all elements
  7478. if (tinymce.isIE6 || !DOM.boxModel) {
  7479. Event.add(t.id, 'mouseover', function() {
  7480. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  7481. DOM.addClass(t.id, 'mceSplitButtonHover');
  7482. });
  7483. Event.add(t.id, 'mouseout', function() {
  7484. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  7485. DOM.removeClass(t.id, 'mceSplitButtonHover');
  7486. });
  7487. }
  7488. },
  7489. destroy : function() {
  7490. this.parent();
  7491. Event.clear(this.id + '_action');
  7492. Event.clear(this.id + '_open');
  7493. Event.clear(this.id);
  7494. }
  7495. });
  7496. })(tinymce);
  7497. (function(tinymce) {
  7498. var DOM = tinymce.DOM, Event = tinymce.dom.Event, is = tinymce.is, each = tinymce.each;
  7499. tinymce.create('tinymce.ui.ColorSplitButton:tinymce.ui.SplitButton', {
  7500. ColorSplitButton : function(id, s, ed) {
  7501. var t = this;
  7502. t.parent(id, s, ed);
  7503. t.settings = s = tinymce.extend({
  7504. 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',
  7505. grid_width : 8,
  7506. default_color : '#888888'
  7507. }, t.settings);
  7508. t.onShowMenu = new tinymce.util.Dispatcher(t);
  7509. t.onHideMenu = new tinymce.util.Dispatcher(t);
  7510. t.value = s.default_color;
  7511. },
  7512. showMenu : function() {
  7513. var t = this, r, p, e, p2;
  7514. if (t.isDisabled())
  7515. return;
  7516. if (!t.isMenuRendered) {
  7517. t.renderMenu();
  7518. t.isMenuRendered = true;
  7519. }
  7520. if (t.isMenuVisible)
  7521. return t.hideMenu();
  7522. e = DOM.get(t.id);
  7523. DOM.show(t.id + '_menu');
  7524. DOM.addClass(e, 'mceSplitButtonSelected');
  7525. p2 = DOM.getPos(e);
  7526. DOM.setStyles(t.id + '_menu', {
  7527. left : p2.x,
  7528. top : p2.y + e.clientHeight,
  7529. zIndex : 200000
  7530. });
  7531. e = 0;
  7532. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  7533. t.onShowMenu.dispatch(t);
  7534. if (t._focused) {
  7535. t._keyHandler = Event.add(t.id + '_menu', 'keydown', function(e) {
  7536. if (e.keyCode == 27)
  7537. t.hideMenu();
  7538. });
  7539. DOM.select('a', t.id + '_menu')[0].focus(); // Select first link
  7540. }
  7541. t.isMenuVisible = 1;
  7542. },
  7543. hideMenu : function(e) {
  7544. var t = this;
  7545. if (t.isMenuVisible) {
  7546. // Prevent double toogles by canceling the mouse click event to the button
  7547. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id + '_open';}))
  7548. return;
  7549. if (!e || !DOM.getParent(e.target, '.mceSplitButtonMenu')) {
  7550. DOM.removeClass(t.id, 'mceSplitButtonSelected');
  7551. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  7552. Event.remove(t.id + '_menu', 'keydown', t._keyHandler);
  7553. DOM.hide(t.id + '_menu');
  7554. }
  7555. t.isMenuVisible = 0;
  7556. t.onHideMenu.dispatch();
  7557. }
  7558. },
  7559. renderMenu : function() {
  7560. var t = this, m, i = 0, s = t.settings, n, tb, tr, w, context;
  7561. 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;'});
  7562. m = DOM.add(w, 'div', {'class' : s['class'] + ' mceSplitButtonMenu'});
  7563. DOM.add(m, 'span', {'class' : 'mceMenuLine'});
  7564. n = DOM.add(m, 'table', {role: 'presentation', 'class' : 'mceColorSplitMenu'});
  7565. tb = DOM.add(n, 'tbody');
  7566. // Generate color grid
  7567. i = 0;
  7568. each(is(s.colors, 'array') ? s.colors : s.colors.split(','), function(c) {
  7569. c = c.replace(/^#/, '');
  7570. if (!i--) {
  7571. tr = DOM.add(tb, 'tr');
  7572. i = s.grid_width - 1;
  7573. }
  7574. n = DOM.add(tr, 'td');
  7575. n = DOM.add(n, 'a', {
  7576. role : 'option',
  7577. href : 'javascript:;',
  7578. style : {
  7579. backgroundColor : '#' + c
  7580. },
  7581. 'title': t.editor.getLang('colors.' + c, c),
  7582. 'data-mce-color' : '#' + c
  7583. });
  7584. if (t.editor.forcedHighContrastMode) {
  7585. n = DOM.add(n, 'canvas', { width: 16, height: 16, 'aria-hidden': 'true' });
  7586. if (n.getContext && (context = n.getContext("2d"))) {
  7587. context.fillStyle = '#' + c;
  7588. context.fillRect(0, 0, 16, 16);
  7589. } else {
  7590. // No point leaving a canvas element around if it's not supported for drawing on anyway.
  7591. DOM.remove(n);
  7592. }
  7593. }
  7594. });
  7595. if (s.more_colors_func) {
  7596. n = DOM.add(tb, 'tr');
  7597. n = DOM.add(n, 'td', {colspan : s.grid_width, 'class' : 'mceMoreColors'});
  7598. n = DOM.add(n, 'a', {role: 'option', id : t.id + '_more', href : 'javascript:;', onclick : 'return false;', 'class' : 'mceMoreColors'}, s.more_colors_title);
  7599. Event.add(n, 'click', function(e) {
  7600. s.more_colors_func.call(s.more_colors_scope || this);
  7601. return Event.cancel(e); // Cancel to fix onbeforeunload problem
  7602. });
  7603. }
  7604. DOM.addClass(m, 'mceColorSplitMenu');
  7605. new tinymce.ui.KeyboardNavigation({
  7606. root: t.id + '_menu',
  7607. items: DOM.select('a', t.id + '_menu'),
  7608. onCancel: function() {
  7609. t.hideMenu();
  7610. t.focus();
  7611. }
  7612. });
  7613. // Prevent IE from scrolling and hindering click to occur #4019
  7614. Event.add(t.id + '_menu', 'mousedown', function(e) {return Event.cancel(e);});
  7615. Event.add(t.id + '_menu', 'click', function(e) {
  7616. var c;
  7617. e = DOM.getParent(e.target, 'a', tb);
  7618. if (e && e.nodeName.toLowerCase() == 'a' && (c = e.getAttribute('data-mce-color')))
  7619. t.setColor(c);
  7620. return Event.cancel(e); // Prevent IE auto save warning
  7621. });
  7622. return w;
  7623. },
  7624. setColor : function(c) {
  7625. this.displayColor(c);
  7626. this.hideMenu();
  7627. this.settings.onselect(c);
  7628. },
  7629. displayColor : function(c) {
  7630. var t = this;
  7631. DOM.setStyle(t.id + '_preview', 'backgroundColor', c);
  7632. t.value = c;
  7633. },
  7634. postRender : function() {
  7635. var t = this, id = t.id;
  7636. t.parent();
  7637. DOM.add(id + '_action', 'div', {id : id + '_preview', 'class' : 'mceColorPreview'});
  7638. DOM.setStyle(t.id + '_preview', 'backgroundColor', t.value);
  7639. },
  7640. destroy : function() {
  7641. this.parent();
  7642. Event.clear(this.id + '_menu');
  7643. Event.clear(this.id + '_more');
  7644. DOM.remove(this.id + '_menu');
  7645. }
  7646. });
  7647. })(tinymce);
  7648. (function(tinymce) {
  7649. // Shorten class names
  7650. var dom = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event;
  7651. tinymce.create('tinymce.ui.ToolbarGroup:tinymce.ui.Container', {
  7652. renderHTML : function() {
  7653. var t = this, h = [], controls = t.controls, each = tinymce.each, settings = t.settings;
  7654. h.push('<div id="' + t.id + '" role="group" aria-labelledby="' + t.id + '_voice">');
  7655. //TODO: ACC test this out - adding a role = application for getting the landmarks working well.
  7656. h.push("<span role='application'>");
  7657. h.push('<span id="' + t.id + '_voice" class="mceVoiceLabel" style="display:none;">' + dom.encode(settings.name) + '</span>');
  7658. each(controls, function(toolbar) {
  7659. h.push(toolbar.renderHTML());
  7660. });
  7661. h.push("</span>");
  7662. h.push('</div>');
  7663. return h.join('');
  7664. },
  7665. focus : function() {
  7666. var t = this;
  7667. dom.get(t.id).focus();
  7668. },
  7669. postRender : function() {
  7670. var t = this, items = [];
  7671. each(t.controls, function(toolbar) {
  7672. each (toolbar.controls, function(control) {
  7673. if (control.id) {
  7674. items.push(control);
  7675. }
  7676. });
  7677. });
  7678. t.keyNav = new tinymce.ui.KeyboardNavigation({
  7679. root: t.id,
  7680. items: items,
  7681. onCancel: function() {
  7682. //Move focus if webkit so that navigation back will read the item.
  7683. if (tinymce.isWebKit) {
  7684. dom.get(t.editor.id+"_ifr").focus();
  7685. }
  7686. t.editor.focus();
  7687. },
  7688. excludeFromTabOrder: !t.settings.tab_focus_toolbar
  7689. });
  7690. },
  7691. destroy : function() {
  7692. var self = this;
  7693. self.parent();
  7694. self.keyNav.destroy();
  7695. Event.clear(self.id);
  7696. }
  7697. });
  7698. })(tinymce);
  7699. (function(tinymce) {
  7700. // Shorten class names
  7701. var dom = tinymce.DOM, each = tinymce.each;
  7702. tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', {
  7703. renderHTML : function() {
  7704. var t = this, h = '', c, co, s = t.settings, i, pr, nx, cl;
  7705. cl = t.controls;
  7706. for (i=0; i<cl.length; i++) {
  7707. // Get current control, prev control, next control and if the control is a list box or not
  7708. co = cl[i];
  7709. pr = cl[i - 1];
  7710. nx = cl[i + 1];
  7711. // Add toolbar start
  7712. if (i === 0) {
  7713. c = 'mceToolbarStart';
  7714. if (co.Button)
  7715. c += ' mceToolbarStartButton';
  7716. else if (co.SplitButton)
  7717. c += ' mceToolbarStartSplitButton';
  7718. else if (co.ListBox)
  7719. c += ' mceToolbarStartListBox';
  7720. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  7721. }
  7722. // Add toolbar end before list box and after the previous button
  7723. // This is to fix the o2k7 editor skins
  7724. if (pr && co.ListBox) {
  7725. if (pr.Button || pr.SplitButton)
  7726. h += dom.createHTML('td', {'class' : 'mceToolbarEnd'}, dom.createHTML('span', null, '<!-- IE -->'));
  7727. }
  7728. // Render control HTML
  7729. // IE 8 quick fix, needed to propertly generate a hit area for anchors
  7730. if (dom.stdMode)
  7731. h += '<td style="position: relative">' + co.renderHTML() + '</td>';
  7732. else
  7733. h += '<td>' + co.renderHTML() + '</td>';
  7734. // Add toolbar start after list box and before the next button
  7735. // This is to fix the o2k7 editor skins
  7736. if (nx && co.ListBox) {
  7737. if (nx.Button || nx.SplitButton)
  7738. h += dom.createHTML('td', {'class' : 'mceToolbarStart'}, dom.createHTML('span', null, '<!-- IE -->'));
  7739. }
  7740. }
  7741. c = 'mceToolbarEnd';
  7742. if (co.Button)
  7743. c += ' mceToolbarEndButton';
  7744. else if (co.SplitButton)
  7745. c += ' mceToolbarEndSplitButton';
  7746. else if (co.ListBox)
  7747. c += ' mceToolbarEndListBox';
  7748. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  7749. 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>');
  7750. }
  7751. });
  7752. })(tinymce);
  7753. (function(tinymce) {
  7754. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each;
  7755. tinymce.create('tinymce.AddOnManager', {
  7756. AddOnManager : function() {
  7757. var self = this;
  7758. self.items = [];
  7759. self.urls = {};
  7760. self.lookup = {};
  7761. self.onAdd = new Dispatcher(self);
  7762. },
  7763. get : function(n) {
  7764. if (this.lookup[n]) {
  7765. return this.lookup[n].instance;
  7766. } else {
  7767. return undefined;
  7768. }
  7769. },
  7770. dependencies : function(n) {
  7771. var result;
  7772. if (this.lookup[n]) {
  7773. result = this.lookup[n].dependencies;
  7774. }
  7775. return result || [];
  7776. },
  7777. requireLangPack : function(n) {
  7778. var s = tinymce.settings;
  7779. if (s && s.language && s.language_load !== false)
  7780. tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js');
  7781. },
  7782. add : function(id, o, dependencies) {
  7783. this.items.push(o);
  7784. this.lookup[id] = {instance:o, dependencies:dependencies};
  7785. this.onAdd.dispatch(this, id, o);
  7786. return o;
  7787. },
  7788. createUrl: function(baseUrl, dep) {
  7789. if (typeof dep === "object") {
  7790. return dep
  7791. } else {
  7792. return {prefix: baseUrl.prefix, resource: dep, suffix: baseUrl.suffix};
  7793. }
  7794. },
  7795. addComponents: function(pluginName, scripts) {
  7796. var pluginUrl = this.urls[pluginName];
  7797. tinymce.each(scripts, function(script){
  7798. tinymce.ScriptLoader.add(pluginUrl+"/"+script);
  7799. });
  7800. },
  7801. load : function(n, u, cb, s) {
  7802. var t = this, url = u;
  7803. function loadDependencies() {
  7804. var dependencies = t.dependencies(n);
  7805. tinymce.each(dependencies, function(dep) {
  7806. var newUrl = t.createUrl(u, dep);
  7807. t.load(newUrl.resource, newUrl, undefined, undefined);
  7808. });
  7809. if (cb) {
  7810. if (s) {
  7811. cb.call(s);
  7812. } else {
  7813. cb.call(tinymce.ScriptLoader);
  7814. }
  7815. }
  7816. }
  7817. if (t.urls[n])
  7818. return;
  7819. if (typeof u === "object")
  7820. url = u.prefix + u.resource + u.suffix;
  7821. if (url.indexOf('/') != 0 && url.indexOf('://') == -1)
  7822. url = tinymce.baseURL + '/' + url;
  7823. t.urls[n] = url.substring(0, url.lastIndexOf('/'));
  7824. if (t.lookup[n]) {
  7825. loadDependencies();
  7826. } else {
  7827. tinymce.ScriptLoader.add(url, loadDependencies, s);
  7828. }
  7829. }
  7830. });
  7831. // Create plugin and theme managers
  7832. tinymce.PluginManager = new tinymce.AddOnManager();
  7833. tinymce.ThemeManager = new tinymce.AddOnManager();
  7834. }(tinymce));
  7835. (function(tinymce) {
  7836. // Shorten names
  7837. var each = tinymce.each, extend = tinymce.extend,
  7838. DOM = tinymce.DOM, Event = tinymce.dom.Event,
  7839. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  7840. explode = tinymce.explode,
  7841. Dispatcher = tinymce.util.Dispatcher, undefined, instanceCounter = 0;
  7842. // Setup some URLs where the editor API is located and where the document is
  7843. tinymce.documentBaseURL = window.location.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
  7844. if (!/[\/\\]$/.test(tinymce.documentBaseURL))
  7845. tinymce.documentBaseURL += '/';
  7846. tinymce.baseURL = new tinymce.util.URI(tinymce.documentBaseURL).toAbsolute(tinymce.baseURL);
  7847. tinymce.baseURI = new tinymce.util.URI(tinymce.baseURL);
  7848. // Add before unload listener
  7849. // This was required since IE was leaking memory if you added and removed beforeunload listeners
  7850. // with attachEvent/detatchEvent so this only adds one listener and instances can the attach to the onBeforeUnload event
  7851. tinymce.onBeforeUnload = new Dispatcher(tinymce);
  7852. // Must be on window or IE will leak if the editor is placed in frame or iframe
  7853. Event.add(window, 'beforeunload', function(e) {
  7854. tinymce.onBeforeUnload.dispatch(tinymce, e);
  7855. });
  7856. tinymce.onAddEditor = new Dispatcher(tinymce);
  7857. tinymce.onRemoveEditor = new Dispatcher(tinymce);
  7858. tinymce.EditorManager = extend(tinymce, {
  7859. editors : [],
  7860. i18n : {},
  7861. activeEditor : null,
  7862. init : function(s) {
  7863. var t = this, pl, sl = tinymce.ScriptLoader, e, el = [], ed;
  7864. function execCallback(se, n, s) {
  7865. var f = se[n];
  7866. if (!f)
  7867. return;
  7868. if (tinymce.is(f, 'string')) {
  7869. s = f.replace(/\.\w+$/, '');
  7870. s = s ? tinymce.resolve(s) : 0;
  7871. f = tinymce.resolve(f);
  7872. }
  7873. return f.apply(s || this, Array.prototype.slice.call(arguments, 2));
  7874. };
  7875. s = extend({
  7876. theme : "simple",
  7877. language : "en"
  7878. }, s);
  7879. t.settings = s;
  7880. // Legacy call
  7881. Event.add(document, 'init', function() {
  7882. var l, co;
  7883. execCallback(s, 'onpageload');
  7884. switch (s.mode) {
  7885. case "exact":
  7886. l = s.elements || '';
  7887. if(l.length > 0) {
  7888. each(explode(l), function(v) {
  7889. if (DOM.get(v)) {
  7890. ed = new tinymce.Editor(v, s);
  7891. el.push(ed);
  7892. ed.render(1);
  7893. } else {
  7894. each(document.forms, function(f) {
  7895. each(f.elements, function(e) {
  7896. if (e.name === v) {
  7897. v = 'mce_editor_' + instanceCounter++;
  7898. DOM.setAttrib(e, 'id', v);
  7899. ed = new tinymce.Editor(v, s);
  7900. el.push(ed);
  7901. ed.render(1);
  7902. }
  7903. });
  7904. });
  7905. }
  7906. });
  7907. }
  7908. break;
  7909. case "textareas":
  7910. case "specific_textareas":
  7911. function hasClass(n, c) {
  7912. return c.constructor === RegExp ? c.test(n.className) : DOM.hasClass(n, c);
  7913. };
  7914. each(DOM.select('textarea'), function(v) {
  7915. if (s.editor_deselector && hasClass(v, s.editor_deselector))
  7916. return;
  7917. if (!s.editor_selector || hasClass(v, s.editor_selector)) {
  7918. // Can we use the name
  7919. e = DOM.get(v.name);
  7920. if (!v.id && !e)
  7921. v.id = v.name;
  7922. // Generate unique name if missing or already exists
  7923. if (!v.id || t.get(v.id))
  7924. v.id = DOM.uniqueId();
  7925. ed = new tinymce.Editor(v.id, s);
  7926. el.push(ed);
  7927. ed.render(1);
  7928. }
  7929. });
  7930. break;
  7931. }
  7932. // Call onInit when all editors are initialized
  7933. if (s.oninit) {
  7934. l = co = 0;
  7935. each(el, function(ed) {
  7936. co++;
  7937. if (!ed.initialized) {
  7938. // Wait for it
  7939. ed.onInit.add(function() {
  7940. l++;
  7941. // All done
  7942. if (l == co)
  7943. execCallback(s, 'oninit');
  7944. });
  7945. } else
  7946. l++;
  7947. // All done
  7948. if (l == co)
  7949. execCallback(s, 'oninit');
  7950. });
  7951. }
  7952. });
  7953. },
  7954. get : function(id) {
  7955. if (id === undefined)
  7956. return this.editors;
  7957. return this.editors[id];
  7958. },
  7959. getInstanceById : function(id) {
  7960. return this.get(id);
  7961. },
  7962. add : function(editor) {
  7963. var self = this, editors = self.editors;
  7964. // Add named and index editor instance
  7965. editors[editor.id] = editor;
  7966. editors.push(editor);
  7967. self._setActive(editor);
  7968. self.onAddEditor.dispatch(self, editor);
  7969. // Patch the tinymce.Editor instance with jQuery adapter logic
  7970. if (tinymce.adapter)
  7971. tinymce.adapter.patchEditor(editor);
  7972. return editor;
  7973. },
  7974. remove : function(editor) {
  7975. var t = this, i, editors = t.editors;
  7976. // Not in the collection
  7977. if (!editors[editor.id])
  7978. return null;
  7979. delete editors[editor.id];
  7980. for (i = 0; i < editors.length; i++) {
  7981. if (editors[i] == editor) {
  7982. editors.splice(i, 1);
  7983. break;
  7984. }
  7985. }
  7986. // Select another editor since the active one was removed
  7987. if (t.activeEditor == editor)
  7988. t._setActive(editors[0]);
  7989. editor.destroy();
  7990. t.onRemoveEditor.dispatch(t, editor);
  7991. return editor;
  7992. },
  7993. execCommand : function(c, u, v) {
  7994. var t = this, ed = t.get(v), w;
  7995. // Manager commands
  7996. switch (c) {
  7997. case "mceFocus":
  7998. ed.focus();
  7999. return true;
  8000. case "mceAddEditor":
  8001. case "mceAddControl":
  8002. if (!t.get(v))
  8003. new tinymce.Editor(v, t.settings).render();
  8004. return true;
  8005. case "mceAddFrameControl":
  8006. w = v.window;
  8007. // Add tinyMCE global instance and tinymce namespace to specified window
  8008. w.tinyMCE = tinyMCE;
  8009. w.tinymce = tinymce;
  8010. tinymce.DOM.doc = w.document;
  8011. tinymce.DOM.win = w;
  8012. ed = new tinymce.Editor(v.element_id, v);
  8013. ed.render();
  8014. // Fix IE memory leaks
  8015. if (tinymce.isIE) {
  8016. function clr() {
  8017. ed.destroy();
  8018. w.detachEvent('onunload', clr);
  8019. w = w.tinyMCE = w.tinymce = null; // IE leak
  8020. };
  8021. w.attachEvent('onunload', clr);
  8022. }
  8023. v.page_window = null;
  8024. return true;
  8025. case "mceRemoveEditor":
  8026. case "mceRemoveControl":
  8027. if (ed)
  8028. ed.remove();
  8029. return true;
  8030. case 'mceToggleEditor':
  8031. if (!ed) {
  8032. t.execCommand('mceAddControl', 0, v);
  8033. return true;
  8034. }
  8035. if (ed.isHidden())
  8036. ed.show();
  8037. else
  8038. ed.hide();
  8039. return true;
  8040. }
  8041. // Run command on active editor
  8042. if (t.activeEditor)
  8043. return t.activeEditor.execCommand(c, u, v);
  8044. return false;
  8045. },
  8046. execInstanceCommand : function(id, c, u, v) {
  8047. var ed = this.get(id);
  8048. if (ed)
  8049. return ed.execCommand(c, u, v);
  8050. return false;
  8051. },
  8052. triggerSave : function() {
  8053. each(this.editors, function(e) {
  8054. e.save();
  8055. });
  8056. },
  8057. addI18n : function(p, o) {
  8058. var lo, i18n = this.i18n;
  8059. if (!tinymce.is(p, 'string')) {
  8060. each(p, function(o, lc) {
  8061. each(o, function(o, g) {
  8062. each(o, function(o, k) {
  8063. if (g === 'common')
  8064. i18n[lc + '.' + k] = o;
  8065. else
  8066. i18n[lc + '.' + g + '.' + k] = o;
  8067. });
  8068. });
  8069. });
  8070. } else {
  8071. each(o, function(o, k) {
  8072. i18n[p + '.' + k] = o;
  8073. });
  8074. }
  8075. },
  8076. // Private methods
  8077. _setActive : function(editor) {
  8078. this.selectedInstance = this.activeEditor = editor;
  8079. }
  8080. });
  8081. })(tinymce);
  8082. (function(tinymce) {
  8083. // Shorten these names
  8084. var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend,
  8085. Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isGecko = tinymce.isGecko,
  8086. isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, is = tinymce.is,
  8087. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  8088. inArray = tinymce.inArray, grep = tinymce.grep, explode = tinymce.explode;
  8089. tinymce.create('tinymce.Editor', {
  8090. Editor : function(id, s) {
  8091. var t = this;
  8092. t.id = t.editorId = id;
  8093. t.execCommands = {};
  8094. t.queryStateCommands = {};
  8095. t.queryValueCommands = {};
  8096. t.isNotDirty = false;
  8097. t.plugins = {};
  8098. // Add events to the editor
  8099. each([
  8100. 'onPreInit',
  8101. 'onBeforeRenderUI',
  8102. 'onPostRender',
  8103. 'onInit',
  8104. 'onRemove',
  8105. 'onActivate',
  8106. 'onDeactivate',
  8107. 'onClick',
  8108. 'onEvent',
  8109. 'onMouseUp',
  8110. 'onMouseDown',
  8111. 'onDblClick',
  8112. 'onKeyDown',
  8113. 'onKeyUp',
  8114. 'onKeyPress',
  8115. 'onContextMenu',
  8116. 'onSubmit',
  8117. 'onReset',
  8118. 'onPaste',
  8119. 'onPreProcess',
  8120. 'onPostProcess',
  8121. 'onBeforeSetContent',
  8122. 'onBeforeGetContent',
  8123. 'onSetContent',
  8124. 'onGetContent',
  8125. 'onLoadContent',
  8126. 'onSaveContent',
  8127. 'onNodeChange',
  8128. 'onChange',
  8129. 'onBeforeExecCommand',
  8130. 'onExecCommand',
  8131. 'onUndo',
  8132. 'onRedo',
  8133. 'onVisualAid',
  8134. 'onSetProgressState'
  8135. ], function(e) {
  8136. t[e] = new Dispatcher(t);
  8137. });
  8138. t.settings = s = extend({
  8139. id : id,
  8140. language : 'en',
  8141. docs_language : 'en',
  8142. theme : 'simple',
  8143. skin : 'default',
  8144. delta_width : 0,
  8145. delta_height : 0,
  8146. popup_css : '',
  8147. plugins : '',
  8148. document_base_url : tinymce.documentBaseURL,
  8149. add_form_submit_trigger : 1,
  8150. submit_patch : 1,
  8151. add_unload_trigger : 1,
  8152. convert_urls : 1,
  8153. relative_urls : 1,
  8154. remove_script_host : 1,
  8155. table_inline_editing : 0,
  8156. object_resizing : 1,
  8157. cleanup : 1,
  8158. accessibility_focus : 1,
  8159. custom_shortcuts : 1,
  8160. custom_undo_redo_keyboard_shortcuts : 1,
  8161. custom_undo_redo_restore_selection : 1,
  8162. custom_undo_redo : 1,
  8163. doctype : tinymce.isIE6 ? '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' : '<!DOCTYPE>', // Use old doctype on IE 6 to avoid horizontal scroll
  8164. visual_table_class : 'mceItemTable',
  8165. visual : 1,
  8166. font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large',
  8167. 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
  8168. apply_source_formatting : 1,
  8169. directionality : 'ltr',
  8170. forced_root_block : 'p',
  8171. hidden_input : 1,
  8172. padd_empty_editor : 1,
  8173. render_ui : 1,
  8174. init_theme : 1,
  8175. force_p_newlines : 1,
  8176. indentation : '30px',
  8177. keep_styles : 1,
  8178. fix_table_elements : 1,
  8179. inline_styles : 1,
  8180. convert_fonts_to_spans : true,
  8181. indent : 'simple',
  8182. indent_before : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr',
  8183. indent_after : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr',
  8184. validate : true,
  8185. entity_encoding : 'named',
  8186. url_converter : t.convertURL,
  8187. url_converter_scope : t,
  8188. ie7_compat : true
  8189. }, s);
  8190. t.documentBaseURI = new tinymce.util.URI(s.document_base_url || tinymce.documentBaseURL, {
  8191. base_uri : tinyMCE.baseURI
  8192. });
  8193. t.baseURI = tinymce.baseURI;
  8194. t.contentCSS = [];
  8195. // Call setup
  8196. t.execCallback('setup', t);
  8197. },
  8198. render : function(nst) {
  8199. var t = this, s = t.settings, id = t.id, sl = tinymce.ScriptLoader;
  8200. // Page is not loaded yet, wait for it
  8201. if (!Event.domLoaded) {
  8202. Event.add(document, 'init', function() {
  8203. t.render();
  8204. });
  8205. return;
  8206. }
  8207. tinyMCE.settings = s;
  8208. // Element not found, then skip initialization
  8209. if (!t.getElement())
  8210. return;
  8211. // Is a iPad/iPhone and not on iOS5, then skip initialization. We need to sniff
  8212. // here since the browser says it has contentEditable support but there is no visible
  8213. // caret We will remove this check ones Apple implements full contentEditable support
  8214. if (tinymce.isIDevice && !tinymce.isIOS5)
  8215. return;
  8216. // Add hidden input for non input elements inside form elements
  8217. if (!/TEXTAREA|INPUT/i.test(t.getElement().nodeName) && s.hidden_input && DOM.getParent(id, 'form'))
  8218. DOM.insertAfter(DOM.create('input', {type : 'hidden', name : id}), id);
  8219. if (tinymce.WindowManager)
  8220. t.windowManager = new tinymce.WindowManager(t);
  8221. if (s.encoding == 'xml') {
  8222. t.onGetContent.add(function(ed, o) {
  8223. if (o.save)
  8224. o.content = DOM.encode(o.content);
  8225. });
  8226. }
  8227. if (s.add_form_submit_trigger) {
  8228. t.onSubmit.addToTop(function() {
  8229. if (t.initialized) {
  8230. t.save();
  8231. t.isNotDirty = 1;
  8232. }
  8233. });
  8234. }
  8235. if (s.add_unload_trigger) {
  8236. t._beforeUnload = tinyMCE.onBeforeUnload.add(function() {
  8237. if (t.initialized && !t.destroyed && !t.isHidden())
  8238. t.save({format : 'raw', no_events : true});
  8239. });
  8240. }
  8241. tinymce.addUnload(t.destroy, t);
  8242. if (s.submit_patch) {
  8243. t.onBeforeRenderUI.add(function() {
  8244. var n = t.getElement().form;
  8245. if (!n)
  8246. return;
  8247. // Already patched
  8248. if (n._mceOldSubmit)
  8249. return;
  8250. // Check page uses id="submit" or name="submit" for it's submit button
  8251. if (!n.submit.nodeType && !n.submit.length) {
  8252. t.formElement = n;
  8253. n._mceOldSubmit = n.submit;
  8254. n.submit = function() {
  8255. // Save all instances
  8256. tinymce.triggerSave();
  8257. t.isNotDirty = 1;
  8258. return t.formElement._mceOldSubmit(t.formElement);
  8259. };
  8260. }
  8261. n = null;
  8262. });
  8263. }
  8264. // Load scripts
  8265. function loadScripts() {
  8266. if (s.language && s.language_load !== false)
  8267. sl.add(tinymce.baseURL + '/langs/' + s.language + '.js');
  8268. if (s.theme && s.theme.charAt(0) != '-' && !ThemeManager.urls[s.theme])
  8269. ThemeManager.load(s.theme, 'themes/' + s.theme + '/editor_template' + tinymce.suffix + '.js');
  8270. each(explode(s.plugins), function(p) {
  8271. if (p &&!PluginManager.urls[p]) {
  8272. if (p.charAt(0) == '-') {
  8273. p = p.substr(1, p.length);
  8274. var dependencies = PluginManager.dependencies(p);
  8275. each(dependencies, function(dep) {
  8276. var defaultSettings = {prefix:'plugins/', resource: dep, suffix:'/editor_plugin' + tinymce.suffix + '.js'};
  8277. var dep = PluginManager.createUrl(defaultSettings, dep);
  8278. PluginManager.load(dep.resource, dep);
  8279. });
  8280. } else {
  8281. // Skip safari plugin, since it is removed as of 3.3b1
  8282. if (p == 'safari') {
  8283. return;
  8284. }
  8285. PluginManager.load(p, {prefix:'plugins/', resource: p, suffix:'/editor_plugin' + tinymce.suffix + '.js'});
  8286. }
  8287. }
  8288. });
  8289. // Init when que is loaded
  8290. sl.loadQueue(function() {
  8291. if (!t.removed)
  8292. t.init();
  8293. });
  8294. };
  8295. loadScripts();
  8296. },
  8297. init : function() {
  8298. var n, t = this, s = t.settings, w, h, e = t.getElement(), o, ti, u, bi, bc, re, i, initializedPlugins = [];
  8299. tinymce.add(t);
  8300. s.aria_label = s.aria_label || DOM.getAttrib(e, 'aria-label', t.getLang('aria.rich_text_area'));
  8301. if (s.theme) {
  8302. s.theme = s.theme.replace(/-/, '');
  8303. o = ThemeManager.get(s.theme);
  8304. t.theme = new o();
  8305. if (t.theme.init && s.init_theme)
  8306. t.theme.init(t, ThemeManager.urls[s.theme] || tinymce.documentBaseURL.replace(/\/$/, ''));
  8307. }
  8308. function initPlugin(p) {
  8309. var c = PluginManager.get(p), u = PluginManager.urls[p] || tinymce.documentBaseURL.replace(/\/$/, ''), po;
  8310. if (c && tinymce.inArray(initializedPlugins,p) === -1) {
  8311. each(PluginManager.dependencies(p), function(dep){
  8312. initPlugin(dep);
  8313. });
  8314. po = new c(t, u);
  8315. t.plugins[p] = po;
  8316. if (po.init) {
  8317. po.init(t, u);
  8318. initializedPlugins.push(p);
  8319. }
  8320. }
  8321. }
  8322. // Create all plugins
  8323. each(explode(s.plugins.replace(/\-/g, '')), initPlugin);
  8324. // Setup popup CSS path(s)
  8325. if (s.popup_css !== false) {
  8326. if (s.popup_css)
  8327. s.popup_css = t.documentBaseURI.toAbsolute(s.popup_css);
  8328. else
  8329. s.popup_css = t.baseURI.toAbsolute("themes/" + s.theme + "/skins/" + s.skin + "/dialog.css");
  8330. }
  8331. if (s.popup_css_add)
  8332. s.popup_css += ',' + t.documentBaseURI.toAbsolute(s.popup_css_add);
  8333. t.controlManager = new tinymce.ControlManager(t);
  8334. if (s.custom_undo_redo) {
  8335. t.onBeforeExecCommand.add(function(ed, cmd, ui, val, a) {
  8336. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo))
  8337. t.undoManager.beforeChange();
  8338. });
  8339. t.onExecCommand.add(function(ed, cmd, ui, val, a) {
  8340. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo))
  8341. t.undoManager.add();
  8342. });
  8343. }
  8344. t.onExecCommand.add(function(ed, c) {
  8345. // Don't refresh the select lists until caret move
  8346. if (!/^(FontName|FontSize)$/.test(c))
  8347. t.nodeChanged();
  8348. });
  8349. // Remove ghost selections on images and tables in Gecko
  8350. if (isGecko) {
  8351. function repaint(a, o) {
  8352. if (!o || !o.initial)
  8353. t.execCommand('mceRepaint');
  8354. };
  8355. t.onUndo.add(repaint);
  8356. t.onRedo.add(repaint);
  8357. t.onSetContent.add(repaint);
  8358. }
  8359. // Enables users to override the control factory
  8360. t.onBeforeRenderUI.dispatch(t, t.controlManager);
  8361. // Measure box
  8362. if (s.render_ui) {
  8363. w = s.width || e.style.width || e.offsetWidth;
  8364. h = s.height || e.style.height || e.offsetHeight;
  8365. t.orgDisplay = e.style.display;
  8366. re = /^[0-9\.]+(|px)$/i;
  8367. if (re.test('' + w))
  8368. w = Math.max(parseInt(w) + (o.deltaWidth || 0), 100);
  8369. if (re.test('' + h))
  8370. h = Math.max(parseInt(h) + (o.deltaHeight || 0), 100);
  8371. // Render UI
  8372. o = t.theme.renderUI({
  8373. targetNode : e,
  8374. width : w,
  8375. height : h,
  8376. deltaWidth : s.delta_width,
  8377. deltaHeight : s.delta_height
  8378. });
  8379. t.editorContainer = o.editorContainer;
  8380. }
  8381. // User specified a document.domain value
  8382. if (document.domain && location.hostname != document.domain)
  8383. tinymce.relaxedDomain = document.domain;
  8384. // Resize editor
  8385. DOM.setStyles(o.sizeContainer || o.editorContainer, {
  8386. width : w,
  8387. height : h
  8388. });
  8389. // Load specified content CSS last
  8390. if (s.content_css) {
  8391. tinymce.each(explode(s.content_css), function(u) {
  8392. t.contentCSS.push(t.documentBaseURI.toAbsolute(u));
  8393. });
  8394. }
  8395. h = (o.iframeHeight || h) + (typeof(h) == 'number' ? (o.deltaHeight || 0) : '');
  8396. if (h < 100)
  8397. h = 100;
  8398. t.iframeHTML = s.doctype + '<html><head xmlns="http://www.w3.org/1999/xhtml">';
  8399. // We only need to override paths if we have to
  8400. // IE has a bug where it remove site absolute urls to relative ones if this is specified
  8401. if (s.document_base_url != tinymce.documentBaseURL)
  8402. t.iframeHTML += '<base href="' + t.documentBaseURI.getURI() + '" />';
  8403. // IE8 doesn't support carets behind images setting ie7_compat would force IE8+ to run in IE7 compat mode.
  8404. if (s.ie7_compat)
  8405. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=7" />';
  8406. else
  8407. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=edge" />';
  8408. t.iframeHTML += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
  8409. // Load the CSS by injecting them into the HTML this will reduce "flicker"
  8410. for (i = 0; i < t.contentCSS.length; i++) {
  8411. t.iframeHTML += '<link type="text/css" rel="stylesheet" href="' + t.contentCSS[i] + '" />';
  8412. }
  8413. bi = s.body_id || 'tinymce';
  8414. if (bi.indexOf('=') != -1) {
  8415. bi = t.getParam('body_id', '', 'hash');
  8416. bi = bi[t.id] || bi;
  8417. }
  8418. bc = s.body_class || '';
  8419. if (bc.indexOf('=') != -1) {
  8420. bc = t.getParam('body_class', '', 'hash');
  8421. bc = bc[t.id] || '';
  8422. }
  8423. t.iframeHTML += '</head><body id="' + bi + '" class="mceContentBody ' + bc + '"><br></body></html>';
  8424. // Domain relaxing enabled, then set document domain
  8425. if (tinymce.relaxedDomain && (isIE || (tinymce.isOpera && parseFloat(opera.version()) < 11))) {
  8426. // We need to write the contents here in IE since multiple writes messes up refresh button and back button
  8427. 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();})()';
  8428. }
  8429. // Create iframe
  8430. // TODO: ACC add the appropriate description on this.
  8431. n = DOM.add(o.iframeContainer, 'iframe', {
  8432. id : t.id + "_ifr",
  8433. src : u || 'javascript:""', // Workaround for HTTPS warning in IE6/7
  8434. frameBorder : '0',
  8435. allowTransparency : "true",
  8436. title : s.aria_label,
  8437. style : {
  8438. width : '100%',
  8439. height : h,
  8440. display : 'block' // Important for Gecko to render the iframe correctly
  8441. }
  8442. });
  8443. t.contentAreaContainer = o.iframeContainer;
  8444. DOM.get(o.editorContainer).style.display = t.orgDisplay;
  8445. DOM.get(t.id).style.display = 'none';
  8446. DOM.setAttrib(t.id, 'aria-hidden', true);
  8447. if (!tinymce.relaxedDomain || !u)
  8448. t.setupIframe();
  8449. e = n = o = null; // Cleanup
  8450. },
  8451. setupIframe : function() {
  8452. var t = this, s = t.settings, e = DOM.get(t.id), d = t.getDoc(), h, b;
  8453. // Setup iframe body
  8454. if (!isIE || !tinymce.relaxedDomain) {
  8455. d.open();
  8456. d.write(t.iframeHTML);
  8457. d.close();
  8458. if (tinymce.relaxedDomain)
  8459. d.domain = tinymce.relaxedDomain;
  8460. }
  8461. // It will not steal focus while setting contentEditable
  8462. b = t.getBody();
  8463. b.disabled = true;
  8464. if (!s.readonly)
  8465. b.contentEditable = true;
  8466. b.disabled = false;
  8467. t.schema = new tinymce.html.Schema(s);
  8468. t.dom = new tinymce.dom.DOMUtils(t.getDoc(), {
  8469. keep_values : true,
  8470. url_converter : t.convertURL,
  8471. url_converter_scope : t,
  8472. hex_colors : s.force_hex_style_colors,
  8473. class_filter : s.class_filter,
  8474. update_styles : 1,
  8475. fix_ie_paragraphs : 1,
  8476. schema : t.schema
  8477. });
  8478. t.parser = new tinymce.html.DomParser(s, t.schema);
  8479. // Force anchor names closed, unless the setting "allow_html_in_named_anchor" is explicitly included.
  8480. if (!t.settings.allow_html_in_named_anchor) {
  8481. t.parser.addAttributeFilter('name', function(nodes, name) {
  8482. var i = nodes.length, sibling, prevSibling, parent, node;
  8483. while (i--) {
  8484. node = nodes[i];
  8485. if (node.name === 'a' && node.firstChild) {
  8486. parent = node.parent;
  8487. // Move children after current node
  8488. sibling = node.lastChild;
  8489. do {
  8490. prevSibling = sibling.prev;
  8491. parent.insert(sibling, node);
  8492. sibling = prevSibling;
  8493. } while (sibling);
  8494. }
  8495. }
  8496. });
  8497. }
  8498. // Convert src and href into data-mce-src, data-mce-href and data-mce-style
  8499. t.parser.addAttributeFilter('src,href,style', function(nodes, name) {
  8500. var i = nodes.length, node, dom = t.dom, value, internalName;
  8501. while (i--) {
  8502. node = nodes[i];
  8503. value = node.attr(name);
  8504. internalName = 'data-mce-' + name;
  8505. // Add internal attribute if we need to we don't on a refresh of the document
  8506. if (!node.attributes.map[internalName]) {
  8507. if (name === "style")
  8508. node.attr(internalName, dom.serializeStyle(dom.parseStyle(value), node.name));
  8509. else
  8510. node.attr(internalName, t.convertURL(value, name, node.name));
  8511. }
  8512. }
  8513. });
  8514. // Keep scripts from executing
  8515. t.parser.addNodeFilter('script', function(nodes, name) {
  8516. var i = nodes.length, node;
  8517. while (i--) {
  8518. node = nodes[i];
  8519. node.attr('type', 'mce-' + (node.attr('type') || 'text/javascript'));
  8520. }
  8521. });
  8522. t.parser.addNodeFilter('#cdata', function(nodes, name) {
  8523. var i = nodes.length, node;
  8524. while (i--) {
  8525. node = nodes[i];
  8526. node.type = 8;
  8527. node.name = '#comment';
  8528. node.value = '[CDATA[' + node.value + ']]';
  8529. }
  8530. });
  8531. t.parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function(nodes, name) {
  8532. var i = nodes.length, node, nonEmptyElements = t.schema.getNonEmptyElements();
  8533. while (i--) {
  8534. node = nodes[i];
  8535. if (node.isEmpty(nonEmptyElements))
  8536. node.empty().append(new tinymce.html.Node('br', 1)).shortEnded = true;
  8537. }
  8538. });
  8539. t.serializer = new tinymce.dom.Serializer(s, t.dom, t.schema);
  8540. t.selection = new tinymce.dom.Selection(t.dom, t.getWin(), t.serializer);
  8541. t.formatter = new tinymce.Formatter(this);
  8542. // Register default formats
  8543. t.formatter.register({
  8544. alignleft : [
  8545. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}},
  8546. {selector : 'img,table', collapsed : false, styles : {'float' : 'left'}}
  8547. ],
  8548. aligncenter : [
  8549. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}},
  8550. {selector : 'img', collapsed : false, styles : {display : 'block', marginLeft : 'auto', marginRight : 'auto'}},
  8551. {selector : 'table', collapsed : false, styles : {marginLeft : 'auto', marginRight : 'auto'}}
  8552. ],
  8553. alignright : [
  8554. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}},
  8555. {selector : 'img,table', collapsed : false, styles : {'float' : 'right'}}
  8556. ],
  8557. alignfull : [
  8558. {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'justify'}}
  8559. ],
  8560. bold : [
  8561. {inline : 'strong', remove : 'all'},
  8562. {inline : 'span', styles : {fontWeight : 'bold'}},
  8563. {inline : 'b', remove : 'all'}
  8564. ],
  8565. italic : [
  8566. {inline : 'em', remove : 'all'},
  8567. {inline : 'span', styles : {fontStyle : 'italic'}},
  8568. {inline : 'i', remove : 'all'}
  8569. ],
  8570. underline : [
  8571. {inline : 'span', styles : {textDecoration : 'underline'}, exact : true},
  8572. {inline : 'u', remove : 'all'}
  8573. ],
  8574. strikethrough : [
  8575. {inline : 'span', styles : {textDecoration : 'line-through'}, exact : true},
  8576. {inline : 'strike', remove : 'all'}
  8577. ],
  8578. forecolor : {inline : 'span', styles : {color : '%value'}, wrap_links : false},
  8579. hilitecolor : {inline : 'span', styles : {backgroundColor : '%value'}, wrap_links : false},
  8580. fontname : {inline : 'span', styles : {fontFamily : '%value'}},
  8581. fontsize : {inline : 'span', styles : {fontSize : '%value'}},
  8582. fontsize_class : {inline : 'span', attributes : {'class' : '%value'}},
  8583. blockquote : {block : 'blockquote', wrapper : 1, remove : 'all'},
  8584. subscript : {inline : 'sub'},
  8585. superscript : {inline : 'sup'},
  8586. link : {inline : 'a', selector : 'a', remove : 'all', split : true, deep : true,
  8587. onmatch : function(node) {
  8588. return true;
  8589. },
  8590. onformat : function(elm, fmt, vars) {
  8591. each(vars, function(value, key) {
  8592. t.dom.setAttrib(elm, key, value);
  8593. });
  8594. }
  8595. },
  8596. removeformat : [
  8597. {selector : 'b,strong,em,i,font,u,strike', remove : 'all', split : true, expand : false, block_expand : true, deep : true},
  8598. {selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true},
  8599. {selector : '*', attributes : ['style', 'class'], split : false, expand : false, deep : true}
  8600. ]
  8601. });
  8602. // Register default block formats
  8603. each('p h1 h2 h3 h4 h5 h6 div address pre div code dt dd samp'.split(/\s/), function(name) {
  8604. t.formatter.register(name, {block : name, remove : 'all'});
  8605. });
  8606. // Register user defined formats
  8607. t.formatter.register(t.settings.formats);
  8608. t.undoManager = new tinymce.UndoManager(t);
  8609. // Pass through
  8610. t.undoManager.onAdd.add(function(um, l) {
  8611. if (um.hasUndo())
  8612. return t.onChange.dispatch(t, l, um);
  8613. });
  8614. t.undoManager.onUndo.add(function(um, l) {
  8615. return t.onUndo.dispatch(t, l, um);
  8616. });
  8617. t.undoManager.onRedo.add(function(um, l) {
  8618. return t.onRedo.dispatch(t, l, um);
  8619. });
  8620. t.forceBlocks = new tinymce.ForceBlocks(t, {
  8621. forced_root_block : s.forced_root_block
  8622. });
  8623. t.editorCommands = new tinymce.EditorCommands(t);
  8624. // Pass through
  8625. t.serializer.onPreProcess.add(function(se, o) {
  8626. return t.onPreProcess.dispatch(t, o, se);
  8627. });
  8628. t.serializer.onPostProcess.add(function(se, o) {
  8629. return t.onPostProcess.dispatch(t, o, se);
  8630. });
  8631. t.onPreInit.dispatch(t);
  8632. if (!s.gecko_spellcheck)
  8633. t.getBody().spellcheck = 0;
  8634. if (!s.readonly)
  8635. t._addEvents();
  8636. t.controlManager.onPostRender.dispatch(t, t.controlManager);
  8637. t.onPostRender.dispatch(t);
  8638. t.quirks = new tinymce.util.Quirks(this);
  8639. if (s.directionality)
  8640. t.getBody().dir = s.directionality;
  8641. if (s.nowrap)
  8642. t.getBody().style.whiteSpace = "nowrap";
  8643. if (s.handle_node_change_callback) {
  8644. t.onNodeChange.add(function(ed, cm, n) {
  8645. t.execCallback('handle_node_change_callback', t.id, n, -1, -1, true, t.selection.isCollapsed());
  8646. });
  8647. }
  8648. if (s.save_callback) {
  8649. t.onSaveContent.add(function(ed, o) {
  8650. var h = t.execCallback('save_callback', t.id, o.content, t.getBody());
  8651. if (h)
  8652. o.content = h;
  8653. });
  8654. }
  8655. if (s.onchange_callback) {
  8656. t.onChange.add(function(ed, l) {
  8657. t.execCallback('onchange_callback', t, l);
  8658. });
  8659. }
  8660. if (s.protect) {
  8661. t.onBeforeSetContent.add(function(ed, o) {
  8662. if (s.protect) {
  8663. each(s.protect, function(pattern) {
  8664. o.content = o.content.replace(pattern, function(str) {
  8665. return '<!--mce:protected ' + escape(str) + '-->';
  8666. });
  8667. });
  8668. }
  8669. });
  8670. }
  8671. if (s.convert_newlines_to_brs) {
  8672. t.onBeforeSetContent.add(function(ed, o) {
  8673. if (o.initial)
  8674. o.content = o.content.replace(/\r?\n/g, '<br />');
  8675. });
  8676. }
  8677. if (s.preformatted) {
  8678. t.onPostProcess.add(function(ed, o) {
  8679. o.content = o.content.replace(/^\s*<pre.*?>/, '');
  8680. o.content = o.content.replace(/<\/pre>\s*$/, '');
  8681. if (o.set)
  8682. o.content = '<pre class="mceItemHidden">' + o.content + '</pre>';
  8683. });
  8684. }
  8685. if (s.verify_css_classes) {
  8686. t.serializer.attribValueFilter = function(n, v) {
  8687. var s, cl;
  8688. if (n == 'class') {
  8689. // Build regexp for classes
  8690. if (!t.classesRE) {
  8691. cl = t.dom.getClasses();
  8692. if (cl.length > 0) {
  8693. s = '';
  8694. each (cl, function(o) {
  8695. s += (s ? '|' : '') + o['class'];
  8696. });
  8697. t.classesRE = new RegExp('(' + s + ')', 'gi');
  8698. }
  8699. }
  8700. return !t.classesRE || /(\bmceItem\w+\b|\bmceTemp\w+\b)/g.test(v) || t.classesRE.test(v) ? v : '';
  8701. }
  8702. return v;
  8703. };
  8704. }
  8705. if (s.cleanup_callback) {
  8706. t.onBeforeSetContent.add(function(ed, o) {
  8707. o.content = t.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  8708. });
  8709. t.onPreProcess.add(function(ed, o) {
  8710. if (o.set)
  8711. t.execCallback('cleanup_callback', 'insert_to_editor_dom', o.node, o);
  8712. if (o.get)
  8713. t.execCallback('cleanup_callback', 'get_from_editor_dom', o.node, o);
  8714. });
  8715. t.onPostProcess.add(function(ed, o) {
  8716. if (o.set)
  8717. o.content = t.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  8718. if (o.get)
  8719. o.content = t.execCallback('cleanup_callback', 'get_from_editor', o.content, o);
  8720. });
  8721. }
  8722. if (s.save_callback) {
  8723. t.onGetContent.add(function(ed, o) {
  8724. if (o.save)
  8725. o.content = t.execCallback('save_callback', t.id, o.content, t.getBody());
  8726. });
  8727. }
  8728. if (s.handle_event_callback) {
  8729. t.onEvent.add(function(ed, e, o) {
  8730. if (t.execCallback('handle_event_callback', e, ed, o) === false)
  8731. Event.cancel(e);
  8732. });
  8733. }
  8734. // Add visual aids when new contents is added
  8735. t.onSetContent.add(function() {
  8736. t.addVisual(t.getBody());
  8737. });
  8738. // Remove empty contents
  8739. if (s.padd_empty_editor) {
  8740. t.onPostProcess.add(function(ed, o) {
  8741. o.content = o.content.replace(/^(<p[^>]*>(&nbsp;|&#160;|\s|\u00a0|)<\/p>[\r\n]*|<br \/>[\r\n]*)$/, '');
  8742. });
  8743. }
  8744. if (isGecko) {
  8745. // Fix gecko link bug, when a link is placed at the end of block elements there is
  8746. // no way to move the caret behind the link. This fix adds a bogus br element after the link
  8747. function fixLinks(ed, o) {
  8748. each(ed.dom.select('a'), function(n) {
  8749. var pn = n.parentNode;
  8750. if (ed.dom.isBlock(pn) && pn.lastChild === n)
  8751. ed.dom.add(pn, 'br', {'data-mce-bogus' : 1});
  8752. });
  8753. };
  8754. t.onExecCommand.add(function(ed, cmd) {
  8755. if (cmd === 'CreateLink')
  8756. fixLinks(ed);
  8757. });
  8758. t.onSetContent.add(t.selection.onSetContent.add(fixLinks));
  8759. }
  8760. t.load({initial : true, format : 'html'});
  8761. t.startContent = t.getContent({format : 'raw'});
  8762. t.undoManager.add();
  8763. t.initialized = true;
  8764. t.onInit.dispatch(t);
  8765. t.execCallback('setupcontent_callback', t.id, t.getBody(), t.getDoc());
  8766. t.execCallback('init_instance_callback', t);
  8767. t.focus(true);
  8768. t.nodeChanged({initial : 1});
  8769. // Load specified content CSS last
  8770. each(t.contentCSS, function(u) {
  8771. t.dom.loadCSS(u);
  8772. });
  8773. // Handle auto focus
  8774. if (s.auto_focus) {
  8775. setTimeout(function () {
  8776. var ed = tinymce.get(s.auto_focus);
  8777. ed.selection.select(ed.getBody(), 1);
  8778. ed.selection.collapse(1);
  8779. ed.getBody().focus();
  8780. ed.getWin().focus();
  8781. }, 100);
  8782. }
  8783. e = null;
  8784. },
  8785. focus : function(sf) {
  8786. var oed, t = this, selection = t.selection, ce = t.settings.content_editable, ieRng, controlElm, doc = t.getDoc();
  8787. if (!sf) {
  8788. // Get selected control element
  8789. ieRng = selection.getRng();
  8790. if (ieRng.item) {
  8791. controlElm = ieRng.item(0);
  8792. }
  8793. t._refreshContentEditable();
  8794. selection.normalize();
  8795. // Is not content editable
  8796. if (!ce)
  8797. t.getWin().focus();
  8798. // Focus the body as well since it's contentEditable
  8799. if (tinymce.isGecko) {
  8800. t.getBody().focus();
  8801. }
  8802. // Restore selected control element
  8803. // This is needed when for example an image is selected within a
  8804. // layer a call to focus will then remove the control selection
  8805. if (controlElm && controlElm.ownerDocument == doc) {
  8806. ieRng = doc.body.createControlRange();
  8807. ieRng.addElement(controlElm);
  8808. ieRng.select();
  8809. }
  8810. }
  8811. if (tinymce.activeEditor != t) {
  8812. if ((oed = tinymce.activeEditor) != null)
  8813. oed.onDeactivate.dispatch(oed, t);
  8814. t.onActivate.dispatch(t, oed);
  8815. }
  8816. tinymce._setActive(t);
  8817. },
  8818. execCallback : function(n) {
  8819. var t = this, f = t.settings[n], s;
  8820. if (!f)
  8821. return;
  8822. // Look through lookup
  8823. if (t.callbackLookup && (s = t.callbackLookup[n])) {
  8824. f = s.func;
  8825. s = s.scope;
  8826. }
  8827. if (is(f, 'string')) {
  8828. s = f.replace(/\.\w+$/, '');
  8829. s = s ? tinymce.resolve(s) : 0;
  8830. f = tinymce.resolve(f);
  8831. t.callbackLookup = t.callbackLookup || {};
  8832. t.callbackLookup[n] = {func : f, scope : s};
  8833. }
  8834. return f.apply(s || t, Array.prototype.slice.call(arguments, 1));
  8835. },
  8836. translate : function(s) {
  8837. var c = this.settings.language || 'en', i18n = tinymce.i18n;
  8838. if (!s)
  8839. return '';
  8840. return i18n[c + '.' + s] || s.replace(/{\#([^}]+)\}/g, function(a, b) {
  8841. return i18n[c + '.' + b] || '{#' + b + '}';
  8842. });
  8843. },
  8844. getLang : function(n, dv) {
  8845. return tinymce.i18n[(this.settings.language || 'en') + '.' + n] || (is(dv) ? dv : '{#' + n + '}');
  8846. },
  8847. getParam : function(n, dv, ty) {
  8848. var tr = tinymce.trim, v = is(this.settings[n]) ? this.settings[n] : dv, o;
  8849. if (ty === 'hash') {
  8850. o = {};
  8851. if (is(v, 'string')) {
  8852. each(v.indexOf('=') > 0 ? v.split(/[;,](?![^=;,]*(?:[;,]|$))/) : v.split(','), function(v) {
  8853. v = v.split('=');
  8854. if (v.length > 1)
  8855. o[tr(v[0])] = tr(v[1]);
  8856. else
  8857. o[tr(v[0])] = tr(v);
  8858. });
  8859. } else
  8860. o = v;
  8861. return o;
  8862. }
  8863. return v;
  8864. },
  8865. nodeChanged : function(o) {
  8866. var t = this, s = t.selection, n = s.getStart() || t.getBody();
  8867. // Fix for bug #1896577 it seems that this can not be fired while the editor is loading
  8868. if (t.initialized) {
  8869. o = o || {};
  8870. n = isIE && n.ownerDocument != t.getDoc() ? t.getBody() : n; // Fix for IE initial state
  8871. // Get parents and add them to object
  8872. o.parents = [];
  8873. t.dom.getParent(n, function(node) {
  8874. if (node.nodeName == 'BODY')
  8875. return true;
  8876. o.parents.push(node);
  8877. });
  8878. t.onNodeChange.dispatch(
  8879. t,
  8880. o ? o.controlManager || t.controlManager : t.controlManager,
  8881. n,
  8882. s.isCollapsed(),
  8883. o
  8884. );
  8885. }
  8886. },
  8887. addButton : function(n, s) {
  8888. var t = this;
  8889. t.buttons = t.buttons || {};
  8890. t.buttons[n] = s;
  8891. },
  8892. addCommand : function(name, callback, scope) {
  8893. this.execCommands[name] = {func : callback, scope : scope || this};
  8894. },
  8895. addQueryStateHandler : function(name, callback, scope) {
  8896. this.queryStateCommands[name] = {func : callback, scope : scope || this};
  8897. },
  8898. addQueryValueHandler : function(name, callback, scope) {
  8899. this.queryValueCommands[name] = {func : callback, scope : scope || this};
  8900. },
  8901. addShortcut : function(pa, desc, cmd_func, sc) {
  8902. var t = this, c;
  8903. if (!t.settings.custom_shortcuts)
  8904. return false;
  8905. t.shortcuts = t.shortcuts || {};
  8906. if (is(cmd_func, 'string')) {
  8907. c = cmd_func;
  8908. cmd_func = function() {
  8909. t.execCommand(c, false, null);
  8910. };
  8911. }
  8912. if (is(cmd_func, 'object')) {
  8913. c = cmd_func;
  8914. cmd_func = function() {
  8915. t.execCommand(c[0], c[1], c[2]);
  8916. };
  8917. }
  8918. each(explode(pa), function(pa) {
  8919. var o = {
  8920. func : cmd_func,
  8921. scope : sc || this,
  8922. desc : desc,
  8923. alt : false,
  8924. ctrl : false,
  8925. shift : false
  8926. };
  8927. each(explode(pa, '+'), function(v) {
  8928. switch (v) {
  8929. case 'alt':
  8930. case 'ctrl':
  8931. case 'shift':
  8932. o[v] = true;
  8933. break;
  8934. default:
  8935. o.charCode = v.charCodeAt(0);
  8936. o.keyCode = v.toUpperCase().charCodeAt(0);
  8937. }
  8938. });
  8939. t.shortcuts[(o.ctrl ? 'ctrl' : '') + ',' + (o.alt ? 'alt' : '') + ',' + (o.shift ? 'shift' : '') + ',' + o.keyCode] = o;
  8940. });
  8941. return true;
  8942. },
  8943. execCommand : function(cmd, ui, val, a) {
  8944. var t = this, s = 0, o, st;
  8945. if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint|SelectAll)$/.test(cmd) && (!a || !a.skip_focus))
  8946. t.focus();
  8947. o = {};
  8948. t.onBeforeExecCommand.dispatch(t, cmd, ui, val, o);
  8949. if (o.terminate)
  8950. return false;
  8951. // Command callback
  8952. if (t.execCallback('execcommand_callback', t.id, t.selection.getNode(), cmd, ui, val)) {
  8953. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  8954. return true;
  8955. }
  8956. // Registred commands
  8957. if (o = t.execCommands[cmd]) {
  8958. st = o.func.call(o.scope, ui, val);
  8959. // Fall through on true
  8960. if (st !== true) {
  8961. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  8962. return st;
  8963. }
  8964. }
  8965. // Plugin commands
  8966. each(t.plugins, function(p) {
  8967. if (p.execCommand && p.execCommand(cmd, ui, val)) {
  8968. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  8969. s = 1;
  8970. return false;
  8971. }
  8972. });
  8973. if (s)
  8974. return true;
  8975. // Theme commands
  8976. if (t.theme && t.theme.execCommand && t.theme.execCommand(cmd, ui, val)) {
  8977. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  8978. return true;
  8979. }
  8980. // Editor commands
  8981. if (t.editorCommands.execCommand(cmd, ui, val)) {
  8982. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  8983. return true;
  8984. }
  8985. // Browser commands
  8986. t.getDoc().execCommand(cmd, ui, val);
  8987. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  8988. },
  8989. queryCommandState : function(cmd) {
  8990. var t = this, o, s;
  8991. // Is hidden then return undefined
  8992. if (t._isHidden())
  8993. return;
  8994. // Registred commands
  8995. if (o = t.queryStateCommands[cmd]) {
  8996. s = o.func.call(o.scope);
  8997. // Fall though on true
  8998. if (s !== true)
  8999. return s;
  9000. }
  9001. // Registred commands
  9002. o = t.editorCommands.queryCommandState(cmd);
  9003. if (o !== -1)
  9004. return o;
  9005. // Browser commands
  9006. try {
  9007. return this.getDoc().queryCommandState(cmd);
  9008. } catch (ex) {
  9009. // Fails sometimes see bug: 1896577
  9010. }
  9011. },
  9012. queryCommandValue : function(c) {
  9013. var t = this, o, s;
  9014. // Is hidden then return undefined
  9015. if (t._isHidden())
  9016. return;
  9017. // Registred commands
  9018. if (o = t.queryValueCommands[c]) {
  9019. s = o.func.call(o.scope);
  9020. // Fall though on true
  9021. if (s !== true)
  9022. return s;
  9023. }
  9024. // Registred commands
  9025. o = t.editorCommands.queryCommandValue(c);
  9026. if (is(o))
  9027. return o;
  9028. // Browser commands
  9029. try {
  9030. return this.getDoc().queryCommandValue(c);
  9031. } catch (ex) {
  9032. // Fails sometimes see bug: 1896577
  9033. }
  9034. },
  9035. show : function() {
  9036. var t = this;
  9037. DOM.show(t.getContainer());
  9038. DOM.hide(t.id);
  9039. t.load();
  9040. },
  9041. hide : function() {
  9042. var t = this, d = t.getDoc();
  9043. // Fixed bug where IE has a blinking cursor left from the editor
  9044. if (isIE && d)
  9045. d.execCommand('SelectAll');
  9046. // We must save before we hide so Safari doesn't crash
  9047. t.save();
  9048. DOM.hide(t.getContainer());
  9049. DOM.setStyle(t.id, 'display', t.orgDisplay);
  9050. },
  9051. isHidden : function() {
  9052. return !DOM.isHidden(this.id);
  9053. },
  9054. setProgressState : function(b, ti, o) {
  9055. this.onSetProgressState.dispatch(this, b, ti, o);
  9056. return b;
  9057. },
  9058. load : function(o) {
  9059. var t = this, e = t.getElement(), h;
  9060. if (e) {
  9061. o = o || {};
  9062. o.load = true;
  9063. // Double encode existing entities in the value
  9064. h = t.setContent(is(e.value) ? e.value : e.innerHTML, o);
  9065. o.element = e;
  9066. if (!o.no_events)
  9067. t.onLoadContent.dispatch(t, o);
  9068. o.element = e = null;
  9069. return h;
  9070. }
  9071. },
  9072. save : function(o) {
  9073. var t = this, e = t.getElement(), h, f;
  9074. if (!e || !t.initialized)
  9075. return;
  9076. o = o || {};
  9077. o.save = true;
  9078. // Add undo level will trigger onchange event
  9079. if (!o.no_events) {
  9080. t.undoManager.typing = false;
  9081. t.undoManager.add();
  9082. }
  9083. o.element = e;
  9084. h = o.content = t.getContent(o);
  9085. if (!o.no_events)
  9086. t.onSaveContent.dispatch(t, o);
  9087. h = o.content;
  9088. if (!/TEXTAREA|INPUT/i.test(e.nodeName)) {
  9089. e.innerHTML = h;
  9090. // Update hidden form element
  9091. if (f = DOM.getParent(t.id, 'form')) {
  9092. each(f.elements, function(e) {
  9093. if (e.name == t.id) {
  9094. e.value = h;
  9095. return false;
  9096. }
  9097. });
  9098. }
  9099. } else
  9100. e.value = h;
  9101. o.element = e = null;
  9102. return h;
  9103. },
  9104. setContent : function(content, args) {
  9105. var self = this, rootNode, body = self.getBody(), forcedRootBlockName;
  9106. // Setup args object
  9107. args = args || {};
  9108. args.format = args.format || 'html';
  9109. args.set = true;
  9110. args.content = content;
  9111. // Do preprocessing
  9112. if (!args.no_events)
  9113. self.onBeforeSetContent.dispatch(self, args);
  9114. content = args.content;
  9115. // Padd empty content in Gecko and Safari. Commands will otherwise fail on the content
  9116. // It will also be impossible to place the caret in the editor unless there is a BR element present
  9117. if (!tinymce.isIE && (content.length === 0 || /^\s+$/.test(content))) {
  9118. forcedRootBlockName = self.settings.forced_root_block;
  9119. if (forcedRootBlockName)
  9120. content = '<' + forcedRootBlockName + '><br data-mce-bogus="1"></' + forcedRootBlockName + '>';
  9121. else
  9122. content = '<br data-mce-bogus="1">';
  9123. body.innerHTML = content;
  9124. self.selection.select(body, true);
  9125. self.selection.collapse(true);
  9126. return;
  9127. }
  9128. // Parse and serialize the html
  9129. if (args.format !== 'raw') {
  9130. content = new tinymce.html.Serializer({}, self.schema).serialize(
  9131. self.parser.parse(content)
  9132. );
  9133. }
  9134. // Set the new cleaned contents to the editor
  9135. args.content = tinymce.trim(content);
  9136. self.dom.setHTML(body, args.content);
  9137. // Do post processing
  9138. if (!args.no_events)
  9139. self.onSetContent.dispatch(self, args);
  9140. self.selection.normalize();
  9141. return args.content;
  9142. },
  9143. getContent : function(args) {
  9144. var self = this, content;
  9145. // Setup args object
  9146. args = args || {};
  9147. args.format = args.format || 'html';
  9148. args.get = true;
  9149. // Do preprocessing
  9150. if (!args.no_events)
  9151. self.onBeforeGetContent.dispatch(self, args);
  9152. // Get raw contents or by default the cleaned contents
  9153. if (args.format == 'raw')
  9154. content = self.getBody().innerHTML;
  9155. else
  9156. content = self.serializer.serialize(self.getBody(), args);
  9157. args.content = tinymce.trim(content);
  9158. // Do post processing
  9159. if (!args.no_events)
  9160. self.onGetContent.dispatch(self, args);
  9161. return args.content;
  9162. },
  9163. isDirty : function() {
  9164. var self = this;
  9165. return tinymce.trim(self.startContent) != tinymce.trim(self.getContent({format : 'raw', no_events : 1})) && !self.isNotDirty;
  9166. },
  9167. getContainer : function() {
  9168. var t = this;
  9169. if (!t.container)
  9170. t.container = DOM.get(t.editorContainer || t.id + '_parent');
  9171. return t.container;
  9172. },
  9173. getContentAreaContainer : function() {
  9174. return this.contentAreaContainer;
  9175. },
  9176. getElement : function() {
  9177. return DOM.get(this.settings.content_element || this.id);
  9178. },
  9179. getWin : function() {
  9180. var t = this, e;
  9181. if (!t.contentWindow) {
  9182. e = DOM.get(t.id + "_ifr");
  9183. if (e)
  9184. t.contentWindow = e.contentWindow;
  9185. }
  9186. return t.contentWindow;
  9187. },
  9188. getDoc : function() {
  9189. var t = this, w;
  9190. if (!t.contentDocument) {
  9191. w = t.getWin();
  9192. if (w)
  9193. t.contentDocument = w.document;
  9194. }
  9195. return t.contentDocument;
  9196. },
  9197. getBody : function() {
  9198. return this.bodyElement || this.getDoc().body;
  9199. },
  9200. convertURL : function(u, n, e) {
  9201. var t = this, s = t.settings;
  9202. // Use callback instead
  9203. if (s.urlconverter_callback)
  9204. return t.execCallback('urlconverter_callback', u, e, true, n);
  9205. // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs
  9206. if (!s.convert_urls || (e && e.nodeName == 'LINK') || u.indexOf('file:') === 0)
  9207. return u;
  9208. // Convert to relative
  9209. if (s.relative_urls)
  9210. return t.documentBaseURI.toRelative(u);
  9211. // Convert to absolute
  9212. u = t.documentBaseURI.toAbsolute(u, s.remove_script_host);
  9213. return u;
  9214. },
  9215. addVisual : function(e) {
  9216. var t = this, s = t.settings;
  9217. e = e || t.getBody();
  9218. if (!is(t.hasVisual))
  9219. t.hasVisual = s.visual;
  9220. each(t.dom.select('table,a', e), function(e) {
  9221. var v;
  9222. switch (e.nodeName) {
  9223. case 'TABLE':
  9224. v = t.dom.getAttrib(e, 'border');
  9225. if (!v || v == '0') {
  9226. if (t.hasVisual)
  9227. t.dom.addClass(e, s.visual_table_class);
  9228. else
  9229. t.dom.removeClass(e, s.visual_table_class);
  9230. }
  9231. return;
  9232. case 'A':
  9233. v = t.dom.getAttrib(e, 'name');
  9234. if (v) {
  9235. if (t.hasVisual)
  9236. t.dom.addClass(e, 'mceItemAnchor');
  9237. else
  9238. t.dom.removeClass(e, 'mceItemAnchor');
  9239. }
  9240. return;
  9241. }
  9242. });
  9243. t.onVisualAid.dispatch(t, e, t.hasVisual);
  9244. },
  9245. remove : function() {
  9246. var t = this, e = t.getContainer();
  9247. t.removed = 1; // Cancels post remove event execution
  9248. t.hide();
  9249. t.execCallback('remove_instance_callback', t);
  9250. t.onRemove.dispatch(t);
  9251. // Clear all execCommand listeners this is required to avoid errors if the editor was removed inside another command
  9252. t.onExecCommand.listeners = [];
  9253. tinymce.remove(t);
  9254. DOM.remove(e);
  9255. },
  9256. destroy : function(s) {
  9257. var t = this;
  9258. // One time is enough
  9259. if (t.destroyed)
  9260. return;
  9261. if (!s) {
  9262. tinymce.removeUnload(t.destroy);
  9263. tinyMCE.onBeforeUnload.remove(t._beforeUnload);
  9264. // Manual destroy
  9265. if (t.theme && t.theme.destroy)
  9266. t.theme.destroy();
  9267. // Destroy controls, selection and dom
  9268. t.controlManager.destroy();
  9269. t.selection.destroy();
  9270. t.dom.destroy();
  9271. // Remove all events
  9272. // Don't clear the window or document if content editable
  9273. // is enabled since other instances might still be present
  9274. if (!t.settings.content_editable) {
  9275. Event.clear(t.getWin());
  9276. Event.clear(t.getDoc());
  9277. }
  9278. Event.clear(t.getBody());
  9279. Event.clear(t.formElement);
  9280. }
  9281. if (t.formElement) {
  9282. t.formElement.submit = t.formElement._mceOldSubmit;
  9283. t.formElement._mceOldSubmit = null;
  9284. }
  9285. t.contentAreaContainer = t.formElement = t.container = t.settings.content_element = t.bodyElement = t.contentDocument = t.contentWindow = null;
  9286. if (t.selection)
  9287. t.selection = t.selection.win = t.selection.dom = t.selection.dom.doc = null;
  9288. t.destroyed = 1;
  9289. },
  9290. // Internal functions
  9291. _addEvents : function() {
  9292. // 'focus', 'blur', 'dblclick', 'beforedeactivate', submit, reset
  9293. var t = this, i, s = t.settings, dom = t.dom, lo = {
  9294. mouseup : 'onMouseUp',
  9295. mousedown : 'onMouseDown',
  9296. click : 'onClick',
  9297. keyup : 'onKeyUp',
  9298. keydown : 'onKeyDown',
  9299. keypress : 'onKeyPress',
  9300. submit : 'onSubmit',
  9301. reset : 'onReset',
  9302. contextmenu : 'onContextMenu',
  9303. dblclick : 'onDblClick',
  9304. paste : 'onPaste' // Doesn't work in all browsers yet
  9305. };
  9306. function eventHandler(e, o) {
  9307. var ty = e.type;
  9308. // Don't fire events when it's removed
  9309. if (t.removed)
  9310. return;
  9311. // Generic event handler
  9312. if (t.onEvent.dispatch(t, e, o) !== false) {
  9313. // Specific event handler
  9314. t[lo[e.fakeType || e.type]].dispatch(t, e, o);
  9315. }
  9316. };
  9317. // Add DOM events
  9318. each(lo, function(v, k) {
  9319. switch (k) {
  9320. case 'contextmenu':
  9321. dom.bind(t.getDoc(), k, eventHandler);
  9322. break;
  9323. case 'paste':
  9324. dom.bind(t.getBody(), k, function(e) {
  9325. eventHandler(e);
  9326. });
  9327. break;
  9328. case 'submit':
  9329. case 'reset':
  9330. dom.bind(t.getElement().form || DOM.getParent(t.id, 'form'), k, eventHandler);
  9331. break;
  9332. default:
  9333. dom.bind(s.content_editable ? t.getBody() : t.getDoc(), k, eventHandler);
  9334. }
  9335. });
  9336. dom.bind(s.content_editable ? t.getBody() : (isGecko ? t.getDoc() : t.getWin()), 'focus', function(e) {
  9337. t.focus(true);
  9338. });
  9339. // Fixes bug where a specified document_base_uri could result in broken images
  9340. // This will also fix drag drop of images in Gecko
  9341. if (tinymce.isGecko) {
  9342. dom.bind(t.getDoc(), 'DOMNodeInserted', function(e) {
  9343. var v;
  9344. e = e.target;
  9345. if (e.nodeType === 1 && e.nodeName === 'IMG' && (v = e.getAttribute('data-mce-src')))
  9346. e.src = t.documentBaseURI.toAbsolute(v);
  9347. });
  9348. }
  9349. // Set various midas options in Gecko
  9350. if (isGecko) {
  9351. function setOpts() {
  9352. var t = this, d = t.getDoc(), s = t.settings;
  9353. if (isGecko && !s.readonly) {
  9354. t._refreshContentEditable();
  9355. try {
  9356. // Try new Gecko method
  9357. d.execCommand("styleWithCSS", 0, false);
  9358. } catch (ex) {
  9359. // Use old method
  9360. if (!t._isHidden())
  9361. try {d.execCommand("useCSS", 0, true);} catch (ex) {}
  9362. }
  9363. if (!s.table_inline_editing)
  9364. try {d.execCommand('enableInlineTableEditing', false, false);} catch (ex) {}
  9365. if (!s.object_resizing)
  9366. try {d.execCommand('enableObjectResizing', false, false);} catch (ex) {}
  9367. }
  9368. };
  9369. t.onBeforeExecCommand.add(setOpts);
  9370. t.onMouseDown.add(setOpts);
  9371. }
  9372. // Add node change handlers
  9373. t.onMouseUp.add(t.nodeChanged);
  9374. //t.onClick.add(t.nodeChanged);
  9375. t.onKeyUp.add(function(ed, e) {
  9376. var c = e.keyCode;
  9377. 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)
  9378. t.nodeChanged();
  9379. });
  9380. // Add block quote deletion handler
  9381. t.onKeyDown.add(function(ed, e) {
  9382. // Was the BACKSPACE key pressed?
  9383. if (e.keyCode != 8)
  9384. return;
  9385. var n = ed.selection.getRng().startContainer;
  9386. var offset = ed.selection.getRng().startOffset;
  9387. while (n && n.nodeType && n.nodeType != 1 && n.parentNode)
  9388. n = n.parentNode;
  9389. // Is the cursor at the beginning of a blockquote?
  9390. if (n && n.parentNode && n.parentNode.tagName === 'BLOCKQUOTE' && n.parentNode.firstChild == n && offset == 0) {
  9391. // Remove the blockquote
  9392. ed.formatter.toggle('blockquote', null, n.parentNode);
  9393. // Move the caret to the beginning of n
  9394. var rng = ed.selection.getRng();
  9395. rng.setStart(n, 0);
  9396. rng.setEnd(n, 0);
  9397. ed.selection.setRng(rng);
  9398. ed.selection.collapse(false);
  9399. }
  9400. });
  9401. // Add reset handler
  9402. t.onReset.add(function() {
  9403. t.setContent(t.startContent, {format : 'raw'});
  9404. });
  9405. // Add shortcuts
  9406. if (s.custom_shortcuts) {
  9407. if (s.custom_undo_redo_keyboard_shortcuts) {
  9408. t.addShortcut('ctrl+z', t.getLang('undo_desc'), 'Undo');
  9409. t.addShortcut('ctrl+y', t.getLang('redo_desc'), 'Redo');
  9410. }
  9411. // Add default shortcuts for gecko
  9412. t.addShortcut('ctrl+b', t.getLang('bold_desc'), 'Bold');
  9413. t.addShortcut('ctrl+i', t.getLang('italic_desc'), 'Italic');
  9414. t.addShortcut('ctrl+u', t.getLang('underline_desc'), 'Underline');
  9415. // BlockFormat shortcuts keys
  9416. for (i=1; i<=6; i++)
  9417. t.addShortcut('ctrl+' + i, '', ['FormatBlock', false, 'h' + i]);
  9418. t.addShortcut('ctrl+7', '', ['FormatBlock', false, 'p']);
  9419. t.addShortcut('ctrl+8', '', ['FormatBlock', false, 'div']);
  9420. t.addShortcut('ctrl+9', '', ['FormatBlock', false, 'address']);
  9421. function find(e) {
  9422. var v = null;
  9423. if (!e.altKey && !e.ctrlKey && !e.metaKey)
  9424. return v;
  9425. each(t.shortcuts, function(o) {
  9426. if (tinymce.isMac && o.ctrl != e.metaKey)
  9427. return;
  9428. else if (!tinymce.isMac && o.ctrl != e.ctrlKey)
  9429. return;
  9430. if (o.alt != e.altKey)
  9431. return;
  9432. if (o.shift != e.shiftKey)
  9433. return;
  9434. if (e.keyCode == o.keyCode || (e.charCode && e.charCode == o.charCode)) {
  9435. v = o;
  9436. return false;
  9437. }
  9438. });
  9439. return v;
  9440. };
  9441. t.onKeyUp.add(function(ed, e) {
  9442. var o = find(e);
  9443. if (o)
  9444. return Event.cancel(e);
  9445. });
  9446. t.onKeyPress.add(function(ed, e) {
  9447. var o = find(e);
  9448. if (o)
  9449. return Event.cancel(e);
  9450. });
  9451. t.onKeyDown.add(function(ed, e) {
  9452. var o = find(e);
  9453. if (o) {
  9454. o.func.call(o.scope);
  9455. return Event.cancel(e);
  9456. }
  9457. });
  9458. }
  9459. if (tinymce.isIE) {
  9460. // Fix so resize will only update the width and height attributes not the styles of an image
  9461. // It will also block mceItemNoResize items
  9462. dom.bind(t.getDoc(), 'controlselect', function(e) {
  9463. var re = t.resizeInfo, cb;
  9464. e = e.target;
  9465. // Don't do this action for non image elements
  9466. if (e.nodeName !== 'IMG')
  9467. return;
  9468. if (re)
  9469. dom.unbind(re.node, re.ev, re.cb);
  9470. if (!dom.hasClass(e, 'mceItemNoResize')) {
  9471. ev = 'resizeend';
  9472. cb = dom.bind(e, ev, function(e) {
  9473. var v;
  9474. e = e.target;
  9475. if (v = dom.getStyle(e, 'width')) {
  9476. dom.setAttrib(e, 'width', v.replace(/[^0-9%]+/g, ''));
  9477. dom.setStyle(e, 'width', '');
  9478. }
  9479. if (v = dom.getStyle(e, 'height')) {
  9480. dom.setAttrib(e, 'height', v.replace(/[^0-9%]+/g, ''));
  9481. dom.setStyle(e, 'height', '');
  9482. }
  9483. });
  9484. } else {
  9485. ev = 'resizestart';
  9486. cb = dom.bind(e, 'resizestart', Event.cancel, Event);
  9487. }
  9488. re = t.resizeInfo = {
  9489. node : e,
  9490. ev : ev,
  9491. cb : cb
  9492. };
  9493. });
  9494. }
  9495. if (tinymce.isOpera) {
  9496. t.onClick.add(function(ed, e) {
  9497. Event.prevent(e);
  9498. });
  9499. }
  9500. // Add custom undo/redo handlers
  9501. if (s.custom_undo_redo) {
  9502. function addUndo() {
  9503. t.undoManager.typing = false;
  9504. t.undoManager.add();
  9505. };
  9506. dom.bind(t.getDoc(), 'focusout', function(e) {
  9507. if (!t.removed && t.undoManager.typing)
  9508. addUndo();
  9509. });
  9510. // Add undo level when contents is drag/dropped within the editor
  9511. t.dom.bind(t.dom.getRoot(), 'dragend', function(e) {
  9512. addUndo();
  9513. });
  9514. t.onKeyUp.add(function(ed, e) {
  9515. var keyCode = e.keyCode;
  9516. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 13 || keyCode == 45 || e.ctrlKey)
  9517. addUndo();
  9518. });
  9519. t.onKeyDown.add(function(ed, e) {
  9520. var keyCode = e.keyCode, sel;
  9521. if (keyCode == 8) {
  9522. sel = t.getDoc().selection;
  9523. // Fix IE control + backspace browser bug
  9524. if (sel && sel.createRange && sel.createRange().item) {
  9525. t.undoManager.beforeChange();
  9526. ed.dom.remove(sel.createRange().item(0));
  9527. addUndo();
  9528. return Event.cancel(e);
  9529. }
  9530. }
  9531. // Is caracter positon keys left,right,up,down,home,end,pgdown,pgup,enter
  9532. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 13 || keyCode == 45) {
  9533. // Add position before enter key is pressed, used by IE since it still uses the default browser behavior
  9534. // Todo: Remove this once we normalize enter behavior on IE
  9535. if (tinymce.isIE && keyCode == 13)
  9536. t.undoManager.beforeChange();
  9537. if (t.undoManager.typing)
  9538. addUndo();
  9539. return;
  9540. }
  9541. // If key isn't shift,ctrl,alt,capslock,metakey
  9542. if ((keyCode < 16 || keyCode > 20) && keyCode != 224 && keyCode != 91 && !t.undoManager.typing) {
  9543. t.undoManager.beforeChange();
  9544. t.undoManager.typing = true;
  9545. t.undoManager.add();
  9546. }
  9547. });
  9548. t.onMouseDown.add(function() {
  9549. if (t.undoManager.typing)
  9550. addUndo();
  9551. });
  9552. }
  9553. // Bug fix for FireFox keeping styles from end of selection instead of start.
  9554. if (tinymce.isGecko) {
  9555. function getAttributeApplyFunction() {
  9556. var template = t.dom.getAttribs(t.selection.getStart().cloneNode(false));
  9557. return function() {
  9558. var target = t.selection.getStart();
  9559. if (target !== t.getBody()) {
  9560. t.dom.setAttrib(target, "style", null);
  9561. each(template, function(attr) {
  9562. target.setAttributeNode(attr.cloneNode(true));
  9563. });
  9564. }
  9565. };
  9566. }
  9567. function isSelectionAcrossElements() {
  9568. var s = t.selection;
  9569. return !s.isCollapsed() && s.getStart() != s.getEnd();
  9570. }
  9571. t.onKeyPress.add(function(ed, e) {
  9572. var applyAttributes;
  9573. if ((e.keyCode == 8 || e.keyCode == 46) && isSelectionAcrossElements()) {
  9574. applyAttributes = getAttributeApplyFunction();
  9575. t.getDoc().execCommand('delete', false, null);
  9576. applyAttributes();
  9577. return Event.cancel(e);
  9578. }
  9579. });
  9580. t.dom.bind(t.getDoc(), 'cut', function(e) {
  9581. var applyAttributes;
  9582. if (isSelectionAcrossElements()) {
  9583. applyAttributes = getAttributeApplyFunction();
  9584. t.onKeyUp.addToTop(Event.cancel, Event);
  9585. setTimeout(function() {
  9586. applyAttributes();
  9587. t.onKeyUp.remove(Event.cancel, Event);
  9588. }, 0);
  9589. }
  9590. });
  9591. }
  9592. },
  9593. _refreshContentEditable : function() {
  9594. var self = this, body, parent;
  9595. // Check if the editor was hidden and the re-initalize contentEditable mode by removing and adding the body again
  9596. if (self._isHidden()) {
  9597. body = self.getBody();
  9598. parent = body.parentNode;
  9599. parent.removeChild(body);
  9600. parent.appendChild(body);
  9601. body.focus();
  9602. }
  9603. },
  9604. _isHidden : function() {
  9605. var s;
  9606. if (!isGecko)
  9607. return 0;
  9608. // Weird, wheres that cursor selection?
  9609. s = this.selection.getSel();
  9610. return (!s || !s.rangeCount || s.rangeCount == 0);
  9611. }
  9612. });
  9613. })(tinymce);
  9614. (function(tinymce) {
  9615. // Added for compression purposes
  9616. var each = tinymce.each, undefined, TRUE = true, FALSE = false;
  9617. tinymce.EditorCommands = function(editor) {
  9618. var dom = editor.dom,
  9619. selection = editor.selection,
  9620. commands = {state: {}, exec : {}, value : {}},
  9621. settings = editor.settings,
  9622. formatter = editor.formatter,
  9623. bookmark;
  9624. function execCommand(command, ui, value) {
  9625. var func;
  9626. command = command.toLowerCase();
  9627. if (func = commands.exec[command]) {
  9628. func(command, ui, value);
  9629. return TRUE;
  9630. }
  9631. return FALSE;
  9632. };
  9633. function queryCommandState(command) {
  9634. var func;
  9635. command = command.toLowerCase();
  9636. if (func = commands.state[command])
  9637. return func(command);
  9638. return -1;
  9639. };
  9640. function queryCommandValue(command) {
  9641. var func;
  9642. command = command.toLowerCase();
  9643. if (func = commands.value[command])
  9644. return func(command);
  9645. return FALSE;
  9646. };
  9647. function addCommands(command_list, type) {
  9648. type = type || 'exec';
  9649. each(command_list, function(callback, command) {
  9650. each(command.toLowerCase().split(','), function(command) {
  9651. commands[type][command] = callback;
  9652. });
  9653. });
  9654. };
  9655. // Expose public methods
  9656. tinymce.extend(this, {
  9657. execCommand : execCommand,
  9658. queryCommandState : queryCommandState,
  9659. queryCommandValue : queryCommandValue,
  9660. addCommands : addCommands
  9661. });
  9662. // Private methods
  9663. function execNativeCommand(command, ui, value) {
  9664. if (ui === undefined)
  9665. ui = FALSE;
  9666. if (value === undefined)
  9667. value = null;
  9668. return editor.getDoc().execCommand(command, ui, value);
  9669. };
  9670. function isFormatMatch(name) {
  9671. return formatter.match(name);
  9672. };
  9673. function toggleFormat(name, value) {
  9674. formatter.toggle(name, value ? {value : value} : undefined);
  9675. };
  9676. function storeSelection(type) {
  9677. bookmark = selection.getBookmark(type);
  9678. };
  9679. function restoreSelection() {
  9680. selection.moveToBookmark(bookmark);
  9681. };
  9682. // Add execCommand overrides
  9683. addCommands({
  9684. // Ignore these, added for compatibility
  9685. 'mceResetDesignMode,mceBeginUndoLevel' : function() {},
  9686. // Add undo manager logic
  9687. 'mceEndUndoLevel,mceAddUndoLevel' : function() {
  9688. editor.undoManager.add();
  9689. },
  9690. 'Cut,Copy,Paste' : function(command) {
  9691. var doc = editor.getDoc(), failed;
  9692. // Try executing the native command
  9693. try {
  9694. execNativeCommand(command);
  9695. } catch (ex) {
  9696. // Command failed
  9697. failed = TRUE;
  9698. }
  9699. // Present alert message about clipboard access not being available
  9700. if (failed || !doc.queryCommandSupported(command)) {
  9701. if (tinymce.isGecko) {
  9702. editor.windowManager.confirm(editor.getLang('clipboard_msg'), function(state) {
  9703. if (state)
  9704. open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', '_blank');
  9705. });
  9706. } else
  9707. editor.windowManager.alert(editor.getLang('clipboard_no_support'));
  9708. }
  9709. },
  9710. // Override unlink command
  9711. unlink : function(command) {
  9712. if (selection.isCollapsed())
  9713. selection.select(selection.getNode());
  9714. execNativeCommand(command);
  9715. selection.collapse(FALSE);
  9716. },
  9717. // Override justify commands to use the text formatter engine
  9718. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  9719. var align = command.substring(7);
  9720. // Remove all other alignments first
  9721. each('left,center,right,full'.split(','), function(name) {
  9722. if (align != name)
  9723. formatter.remove('align' + name);
  9724. });
  9725. toggleFormat('align' + align);
  9726. execCommand('mceRepaint');
  9727. },
  9728. // Override list commands to fix WebKit bug
  9729. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  9730. var listElm, listParent;
  9731. execNativeCommand(command);
  9732. // WebKit produces lists within block elements so we need to split them
  9733. // we will replace the native list creation logic to custom logic later on
  9734. // TODO: Remove this when the list creation logic is removed
  9735. listElm = dom.getParent(selection.getNode(), 'ol,ul');
  9736. if (listElm) {
  9737. listParent = listElm.parentNode;
  9738. // If list is within a text block then split that block
  9739. if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) {
  9740. storeSelection();
  9741. dom.split(listParent, listElm);
  9742. restoreSelection();
  9743. }
  9744. }
  9745. },
  9746. // Override commands to use the text formatter engine
  9747. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  9748. toggleFormat(command);
  9749. },
  9750. // Override commands to use the text formatter engine
  9751. 'ForeColor,HiliteColor,FontName' : function(command, ui, value) {
  9752. toggleFormat(command, value);
  9753. },
  9754. FontSize : function(command, ui, value) {
  9755. var fontClasses, fontSizes;
  9756. // Convert font size 1-7 to styles
  9757. if (value >= 1 && value <= 7) {
  9758. fontSizes = tinymce.explode(settings.font_size_style_values);
  9759. fontClasses = tinymce.explode(settings.font_size_classes);
  9760. if (fontClasses)
  9761. value = fontClasses[value - 1] || value;
  9762. else
  9763. value = fontSizes[value - 1] || value;
  9764. }
  9765. toggleFormat(command, value);
  9766. },
  9767. RemoveFormat : function(command) {
  9768. formatter.remove(command);
  9769. },
  9770. mceBlockQuote : function(command) {
  9771. toggleFormat('blockquote');
  9772. },
  9773. FormatBlock : function(command, ui, value) {
  9774. return toggleFormat(value || 'p');
  9775. },
  9776. mceCleanup : function() {
  9777. var bookmark = selection.getBookmark();
  9778. editor.setContent(editor.getContent({cleanup : TRUE}), {cleanup : TRUE});
  9779. selection.moveToBookmark(bookmark);
  9780. },
  9781. mceRemoveNode : function(command, ui, value) {
  9782. var node = value || selection.getNode();
  9783. // Make sure that the body node isn't removed
  9784. if (node != editor.getBody()) {
  9785. storeSelection();
  9786. editor.dom.remove(node, TRUE);
  9787. restoreSelection();
  9788. }
  9789. },
  9790. mceSelectNodeDepth : function(command, ui, value) {
  9791. var counter = 0;
  9792. dom.getParent(selection.getNode(), function(node) {
  9793. if (node.nodeType == 1 && counter++ == value) {
  9794. selection.select(node);
  9795. return FALSE;
  9796. }
  9797. }, editor.getBody());
  9798. },
  9799. mceSelectNode : function(command, ui, value) {
  9800. selection.select(value);
  9801. },
  9802. mceInsertContent : function(command, ui, value) {
  9803. var parser, serializer, parentNode, rootNode, fragment, args,
  9804. marker, nodeRect, viewPortRect, rng, node, node2, bookmarkHtml, viewportBodyElement;
  9805. // Setup parser and serializer
  9806. parser = editor.parser;
  9807. serializer = new tinymce.html.Serializer({}, editor.schema);
  9808. bookmarkHtml = '<span id="mce_marker" data-mce-type="bookmark">\uFEFF</span>';
  9809. // Run beforeSetContent handlers on the HTML to be inserted
  9810. args = {content: value, format: 'html'};
  9811. selection.onBeforeSetContent.dispatch(selection, args);
  9812. value = args.content;
  9813. // Add caret at end of contents if it's missing
  9814. if (value.indexOf('{$caret}') == -1)
  9815. value += '{$caret}';
  9816. // Replace the caret marker with a span bookmark element
  9817. value = value.replace(/\{\$caret\}/, bookmarkHtml);
  9818. // Insert node maker where we will insert the new HTML and get it's parent
  9819. if (!selection.isCollapsed())
  9820. editor.getDoc().execCommand('Delete', false, null);
  9821. parentNode = selection.getNode();
  9822. // Parse the fragment within the context of the parent node
  9823. args = {context : parentNode.nodeName.toLowerCase()};
  9824. fragment = parser.parse(value, args);
  9825. // Move the caret to a more suitable location
  9826. node = fragment.lastChild;
  9827. if (node.attr('id') == 'mce_marker') {
  9828. marker = node;
  9829. for (node = node.prev; node; node = node.walk(true)) {
  9830. if (node.type == 3 || !dom.isBlock(node.name)) {
  9831. node.parent.insert(marker, node, node.name === 'br');
  9832. break;
  9833. }
  9834. }
  9835. }
  9836. // If parser says valid we can insert the contents into that parent
  9837. if (!args.invalid) {
  9838. value = serializer.serialize(fragment);
  9839. // Check if parent is empty or only has one BR element then set the innerHTML of that parent
  9840. node = parentNode.firstChild;
  9841. node2 = parentNode.lastChild;
  9842. if (!node || (node === node2 && node.nodeName === 'BR'))
  9843. dom.setHTML(parentNode, value);
  9844. else
  9845. selection.setContent(value);
  9846. } else {
  9847. // If the fragment was invalid within that context then we need
  9848. // to parse and process the parent it's inserted into
  9849. // Insert bookmark node and get the parent
  9850. selection.setContent(bookmarkHtml);
  9851. parentNode = editor.selection.getNode();
  9852. rootNode = editor.getBody();
  9853. // Opera will return the document node when selection is in root
  9854. if (parentNode.nodeType == 9)
  9855. parentNode = node = rootNode;
  9856. else
  9857. node = parentNode;
  9858. // Find the ancestor just before the root element
  9859. while (node !== rootNode) {
  9860. parentNode = node;
  9861. node = node.parentNode;
  9862. }
  9863. // Get the outer/inner HTML depending on if we are in the root and parser and serialize that
  9864. value = parentNode == rootNode ? rootNode.innerHTML : dom.getOuterHTML(parentNode);
  9865. value = serializer.serialize(
  9866. parser.parse(
  9867. // Need to replace by using a function since $ in the contents would otherwise be a problem
  9868. value.replace(/<span (id="mce_marker"|id=mce_marker).+?<\/span>/i, function() {
  9869. return serializer.serialize(fragment);
  9870. })
  9871. )
  9872. );
  9873. // Set the inner/outer HTML depending on if we are in the root or not
  9874. if (parentNode == rootNode)
  9875. dom.setHTML(rootNode, value);
  9876. else
  9877. dom.setOuterHTML(parentNode, value);
  9878. }
  9879. marker = dom.get('mce_marker');
  9880. // Scroll range into view scrollIntoView on element can't be used since it will scroll the main view port as well
  9881. nodeRect = dom.getRect(marker);
  9882. viewPortRect = dom.getViewPort(editor.getWin());
  9883. // Check if node is out side the viewport if it is then scroll to it
  9884. if ((nodeRect.y + nodeRect.h > viewPortRect.y + viewPortRect.h || nodeRect.y < viewPortRect.y) ||
  9885. (nodeRect.x > viewPortRect.x + viewPortRect.w || nodeRect.x < viewPortRect.x)) {
  9886. viewportBodyElement = tinymce.isIE ? editor.getDoc().documentElement : editor.getBody();
  9887. viewportBodyElement.scrollLeft = nodeRect.x;
  9888. viewportBodyElement.scrollTop = nodeRect.y - viewPortRect.h + 25;
  9889. }
  9890. // Move selection before marker and remove it
  9891. rng = dom.createRng();
  9892. // If previous sibling is a text node set the selection to the end of that node
  9893. node = marker.previousSibling;
  9894. if (node && node.nodeType == 3) {
  9895. rng.setStart(node, node.nodeValue.length);
  9896. } else {
  9897. // If the previous sibling isn't a text node or doesn't exist set the selection before the marker node
  9898. rng.setStartBefore(marker);
  9899. rng.setEndBefore(marker);
  9900. }
  9901. // Remove the marker node and set the new range
  9902. dom.remove(marker);
  9903. selection.setRng(rng);
  9904. // Dispatch after event and add any visual elements needed
  9905. selection.onSetContent.dispatch(selection, args);
  9906. editor.addVisual();
  9907. },
  9908. mceInsertRawHTML : function(command, ui, value) {
  9909. selection.setContent('tiny_mce_marker');
  9910. editor.setContent(editor.getContent().replace(/tiny_mce_marker/g, function() { return value }));
  9911. },
  9912. mceSetContent : function(command, ui, value) {
  9913. editor.setContent(value);
  9914. },
  9915. 'Indent,Outdent' : function(command) {
  9916. var intentValue, indentUnit, value;
  9917. // Setup indent level
  9918. intentValue = settings.indentation;
  9919. indentUnit = /[a-z%]+$/i.exec(intentValue);
  9920. intentValue = parseInt(intentValue);
  9921. if (!queryCommandState('InsertUnorderedList') && !queryCommandState('InsertOrderedList')) {
  9922. each(selection.getSelectedBlocks(), function(element) {
  9923. if (command == 'outdent') {
  9924. value = Math.max(0, parseInt(element.style.paddingLeft || 0) - intentValue);
  9925. dom.setStyle(element, 'paddingLeft', value ? value + indentUnit : '');
  9926. } else
  9927. dom.setStyle(element, 'paddingLeft', (parseInt(element.style.paddingLeft || 0) + intentValue) + indentUnit);
  9928. });
  9929. } else
  9930. execNativeCommand(command);
  9931. },
  9932. mceRepaint : function() {
  9933. var bookmark;
  9934. if (tinymce.isGecko) {
  9935. try {
  9936. storeSelection(TRUE);
  9937. if (selection.getSel())
  9938. selection.getSel().selectAllChildren(editor.getBody());
  9939. selection.collapse(TRUE);
  9940. restoreSelection();
  9941. } catch (ex) {
  9942. // Ignore
  9943. }
  9944. }
  9945. },
  9946. mceToggleFormat : function(command, ui, value) {
  9947. formatter.toggle(value);
  9948. },
  9949. InsertHorizontalRule : function() {
  9950. editor.execCommand('mceInsertContent', false, '<hr />');
  9951. },
  9952. mceToggleVisualAid : function() {
  9953. editor.hasVisual = !editor.hasVisual;
  9954. editor.addVisual();
  9955. },
  9956. mceReplaceContent : function(command, ui, value) {
  9957. editor.execCommand('mceInsertContent', false, value.replace(/\{\$selection\}/g, selection.getContent({format : 'text'})));
  9958. },
  9959. mceInsertLink : function(command, ui, value) {
  9960. var anchor;
  9961. if (typeof(value) == 'string')
  9962. value = {href : value};
  9963. anchor = dom.getParent(selection.getNode(), 'a');
  9964. // Spaces are never valid in URLs and it's a very common mistake for people to make so we fix it here.
  9965. value.href = value.href.replace(' ', '%20');
  9966. // Remove existing links if there could be child links or that the href isn't specified
  9967. if (!anchor || !value.href) {
  9968. formatter.remove('link');
  9969. }
  9970. // Apply new link to selection
  9971. if (value.href) {
  9972. formatter.apply('link', value, anchor);
  9973. }
  9974. },
  9975. selectAll : function() {
  9976. var root = dom.getRoot(), rng = dom.createRng();
  9977. rng.setStart(root, 0);
  9978. rng.setEnd(root, root.childNodes.length);
  9979. editor.selection.setRng(rng);
  9980. }
  9981. });
  9982. // Add queryCommandState overrides
  9983. addCommands({
  9984. // Override justify commands
  9985. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  9986. return isFormatMatch('align' + command.substring(7));
  9987. },
  9988. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  9989. return isFormatMatch(command);
  9990. },
  9991. mceBlockQuote : function() {
  9992. return isFormatMatch('blockquote');
  9993. },
  9994. Outdent : function() {
  9995. var node;
  9996. if (settings.inline_styles) {
  9997. if ((node = dom.getParent(selection.getStart(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  9998. return TRUE;
  9999. if ((node = dom.getParent(selection.getEnd(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  10000. return TRUE;
  10001. }
  10002. return queryCommandState('InsertUnorderedList') || queryCommandState('InsertOrderedList') || (!settings.inline_styles && !!dom.getParent(selection.getNode(), 'BLOCKQUOTE'));
  10003. },
  10004. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  10005. return dom.getParent(selection.getNode(), command == 'insertunorderedlist' ? 'UL' : 'OL');
  10006. }
  10007. }, 'state');
  10008. // Add queryCommandValue overrides
  10009. addCommands({
  10010. 'FontSize,FontName' : function(command) {
  10011. var value = 0, parent;
  10012. if (parent = dom.getParent(selection.getNode(), 'span')) {
  10013. if (command == 'fontsize')
  10014. value = parent.style.fontSize;
  10015. else
  10016. value = parent.style.fontFamily.replace(/, /g, ',').replace(/[\'\"]/g, '').toLowerCase();
  10017. }
  10018. return value;
  10019. }
  10020. }, 'value');
  10021. // Add undo manager logic
  10022. if (settings.custom_undo_redo) {
  10023. addCommands({
  10024. Undo : function() {
  10025. editor.undoManager.undo();
  10026. },
  10027. Redo : function() {
  10028. editor.undoManager.redo();
  10029. }
  10030. });
  10031. }
  10032. };
  10033. })(tinymce);
  10034. (function(tinymce) {
  10035. var Dispatcher = tinymce.util.Dispatcher;
  10036. tinymce.UndoManager = function(editor) {
  10037. var self, index = 0, data = [], beforeBookmark;
  10038. function getContent() {
  10039. return tinymce.trim(editor.getContent({format : 'raw', no_events : 1}));
  10040. };
  10041. return self = {
  10042. typing : false,
  10043. onAdd : new Dispatcher(self),
  10044. onUndo : new Dispatcher(self),
  10045. onRedo : new Dispatcher(self),
  10046. beforeChange : function() {
  10047. beforeBookmark = editor.selection.getBookmark(2, true);
  10048. },
  10049. add : function(level) {
  10050. var i, settings = editor.settings, lastLevel;
  10051. level = level || {};
  10052. level.content = getContent();
  10053. // Add undo level if needed
  10054. lastLevel = data[index];
  10055. if (lastLevel && lastLevel.content == level.content)
  10056. return null;
  10057. // Set before bookmark on previous level
  10058. if (data[index])
  10059. data[index].beforeBookmark = beforeBookmark;
  10060. // Time to compress
  10061. if (settings.custom_undo_redo_levels) {
  10062. if (data.length > settings.custom_undo_redo_levels) {
  10063. for (i = 0; i < data.length - 1; i++)
  10064. data[i] = data[i + 1];
  10065. data.length--;
  10066. index = data.length;
  10067. }
  10068. }
  10069. // Get a non intrusive normalized bookmark
  10070. level.bookmark = editor.selection.getBookmark(2, true);
  10071. // Crop array if needed
  10072. if (index < data.length - 1)
  10073. data.length = index + 1;
  10074. data.push(level);
  10075. index = data.length - 1;
  10076. self.onAdd.dispatch(self, level);
  10077. editor.isNotDirty = 0;
  10078. return level;
  10079. },
  10080. undo : function() {
  10081. var level, i;
  10082. if (self.typing) {
  10083. self.add();
  10084. self.typing = false;
  10085. }
  10086. if (index > 0) {
  10087. level = data[--index];
  10088. editor.setContent(level.content, {format : 'raw'});
  10089. editor.selection.moveToBookmark(level.beforeBookmark);
  10090. self.onUndo.dispatch(self, level);
  10091. }
  10092. return level;
  10093. },
  10094. redo : function() {
  10095. var level;
  10096. if (index < data.length - 1) {
  10097. level = data[++index];
  10098. editor.setContent(level.content, {format : 'raw'});
  10099. editor.selection.moveToBookmark(level.bookmark);
  10100. self.onRedo.dispatch(self, level);
  10101. }
  10102. return level;
  10103. },
  10104. clear : function() {
  10105. data = [];
  10106. index = 0;
  10107. self.typing = false;
  10108. },
  10109. hasUndo : function() {
  10110. return index > 0 || this.typing;
  10111. },
  10112. hasRedo : function() {
  10113. return index < data.length - 1 && !this.typing;
  10114. }
  10115. };
  10116. };
  10117. })(tinymce);
  10118. (function(tinymce) {
  10119. // Shorten names
  10120. var Event = tinymce.dom.Event,
  10121. isIE = tinymce.isIE,
  10122. isGecko = tinymce.isGecko,
  10123. isOpera = tinymce.isOpera,
  10124. each = tinymce.each,
  10125. extend = tinymce.extend,
  10126. TRUE = true,
  10127. FALSE = false;
  10128. function cloneFormats(node) {
  10129. var clone, temp, inner;
  10130. do {
  10131. if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(node.nodeName)) {
  10132. if (clone) {
  10133. temp = node.cloneNode(false);
  10134. temp.appendChild(clone);
  10135. clone = temp;
  10136. } else {
  10137. clone = inner = node.cloneNode(false);
  10138. }
  10139. clone.removeAttribute('id');
  10140. }
  10141. } while (node = node.parentNode);
  10142. if (clone)
  10143. return {wrapper : clone, inner : inner};
  10144. };
  10145. // Checks if the selection/caret is at the end of the specified block element
  10146. function isAtEnd(rng, par) {
  10147. var rng2 = par.ownerDocument.createRange();
  10148. rng2.setStart(rng.endContainer, rng.endOffset);
  10149. rng2.setEndAfter(par);
  10150. // 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
  10151. return rng2.cloneContents().textContent.length == 0;
  10152. };
  10153. function splitList(selection, dom, li) {
  10154. var listBlock, block;
  10155. if (dom.isEmpty(li)) {
  10156. listBlock = dom.getParent(li, 'ul,ol');
  10157. if (!dom.getParent(listBlock.parentNode, 'ul,ol')) {
  10158. dom.split(listBlock, li);
  10159. block = dom.create('p', 0, '<br data-mce-bogus="1" />');
  10160. dom.replace(block, li);
  10161. selection.select(block, 1);
  10162. }
  10163. return FALSE;
  10164. }
  10165. return TRUE;
  10166. };
  10167. tinymce.create('tinymce.ForceBlocks', {
  10168. ForceBlocks : function(ed) {
  10169. var t = this, s = ed.settings, elm;
  10170. t.editor = ed;
  10171. t.dom = ed.dom;
  10172. elm = (s.forced_root_block || 'p').toLowerCase();
  10173. s.element = elm.toUpperCase();
  10174. ed.onPreInit.add(t.setup, t);
  10175. },
  10176. setup : function() {
  10177. var t = this, ed = t.editor, s = ed.settings, dom = ed.dom, selection = ed.selection, blockElements = ed.schema.getBlockElements();
  10178. // Force root blocks
  10179. if (s.forced_root_block) {
  10180. function addRootBlocks() {
  10181. var node = selection.getStart(), rootNode = ed.getBody(), rng, startContainer, startOffset, endContainer, endOffset, rootBlockNode, tempNode, offset = -0xFFFFFF;
  10182. if (!node || node.nodeType !== 1)
  10183. return;
  10184. // Check if node is wrapped in block
  10185. while (node != rootNode) {
  10186. if (blockElements[node.nodeName])
  10187. return;
  10188. node = node.parentNode;
  10189. }
  10190. // Get current selection
  10191. rng = selection.getRng();
  10192. if (rng.setStart) {
  10193. startContainer = rng.startContainer;
  10194. startOffset = rng.startOffset;
  10195. endContainer = rng.endContainer;
  10196. endOffset = rng.endOffset;
  10197. } else {
  10198. // Force control range into text range
  10199. if (rng.item) {
  10200. rng = ed.getDoc().body.createTextRange();
  10201. rng.moveToElementText(rng.item(0));
  10202. }
  10203. tmpRng = rng.duplicate();
  10204. tmpRng.collapse(true);
  10205. startOffset = tmpRng.move('character', offset) * -1;
  10206. if (!tmpRng.collapsed) {
  10207. tmpRng = rng.duplicate();
  10208. tmpRng.collapse(false);
  10209. endOffset = (tmpRng.move('character', offset) * -1) - startOffset;
  10210. }
  10211. }
  10212. // Wrap non block elements and text nodes
  10213. for (node = rootNode.firstChild; node; node) {
  10214. if (node.nodeType === 3 || (node.nodeType == 1 && !blockElements[node.nodeName])) {
  10215. if (!rootBlockNode) {
  10216. rootBlockNode = dom.create(s.forced_root_block);
  10217. node.parentNode.insertBefore(rootBlockNode, node);
  10218. }
  10219. tempNode = node;
  10220. node = node.nextSibling;
  10221. rootBlockNode.appendChild(tempNode);
  10222. } else {
  10223. rootBlockNode = null;
  10224. node = node.nextSibling;
  10225. }
  10226. }
  10227. if (rng.setStart) {
  10228. rng.setStart(startContainer, startOffset);
  10229. rng.setEnd(endContainer, endOffset);
  10230. selection.setRng(rng);
  10231. } else {
  10232. try {
  10233. rng = ed.getDoc().body.createTextRange();
  10234. rng.moveToElementText(rootNode);
  10235. rng.collapse(true);
  10236. rng.moveStart('character', startOffset);
  10237. if (endOffset > 0)
  10238. rng.moveEnd('character', endOffset);
  10239. rng.select();
  10240. } catch (ex) {
  10241. // Ignore
  10242. }
  10243. }
  10244. ed.nodeChanged();
  10245. };
  10246. ed.onKeyUp.add(addRootBlocks);
  10247. ed.onClick.add(addRootBlocks);
  10248. }
  10249. if (s.force_br_newlines) {
  10250. // Force IE to produce BRs on enter
  10251. if (isIE) {
  10252. ed.onKeyPress.add(function(ed, e) {
  10253. var n;
  10254. if (e.keyCode == 13 && selection.getNode().nodeName != 'LI') {
  10255. selection.setContent('<br id="__" /> ', {format : 'raw'});
  10256. n = dom.get('__');
  10257. n.removeAttribute('id');
  10258. selection.select(n);
  10259. selection.collapse();
  10260. return Event.cancel(e);
  10261. }
  10262. });
  10263. }
  10264. }
  10265. if (s.force_p_newlines) {
  10266. if (!isIE) {
  10267. ed.onKeyPress.add(function(ed, e) {
  10268. if (e.keyCode == 13 && !e.shiftKey && !t.insertPara(e))
  10269. Event.cancel(e);
  10270. });
  10271. } else {
  10272. // Ungly hack to for IE to preserve the formatting when you press
  10273. // enter at the end of a block element with formatted contents
  10274. // This logic overrides the browsers default logic with
  10275. // custom logic that enables us to control the output
  10276. tinymce.addUnload(function() {
  10277. t._previousFormats = 0; // Fix IE leak
  10278. });
  10279. ed.onKeyPress.add(function(ed, e) {
  10280. t._previousFormats = 0;
  10281. // Clone the current formats, this will later be applied to the new block contents
  10282. if (e.keyCode == 13 && !e.shiftKey && ed.selection.isCollapsed() && s.keep_styles)
  10283. t._previousFormats = cloneFormats(ed.selection.getStart());
  10284. });
  10285. ed.onKeyUp.add(function(ed, e) {
  10286. // Let IE break the element and the wrap the new caret location in the previous formats
  10287. if (e.keyCode == 13 && !e.shiftKey) {
  10288. var parent = ed.selection.getStart(), fmt = t._previousFormats;
  10289. // Parent is an empty block
  10290. if (!parent.hasChildNodes() && fmt) {
  10291. parent = dom.getParent(parent, dom.isBlock);
  10292. if (parent && parent.nodeName != 'LI') {
  10293. parent.innerHTML = '';
  10294. if (t._previousFormats) {
  10295. parent.appendChild(fmt.wrapper);
  10296. fmt.inner.innerHTML = '\uFEFF';
  10297. } else
  10298. parent.innerHTML = '\uFEFF';
  10299. selection.select(parent, 1);
  10300. selection.collapse(true);
  10301. ed.getDoc().execCommand('Delete', false, null);
  10302. t._previousFormats = 0;
  10303. }
  10304. }
  10305. }
  10306. });
  10307. }
  10308. if (isGecko) {
  10309. ed.onKeyDown.add(function(ed, e) {
  10310. if ((e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey)
  10311. t.backspaceDelete(e, e.keyCode == 8);
  10312. });
  10313. }
  10314. }
  10315. // Workaround for missing shift+enter support, http://bugs.webkit.org/show_bug.cgi?id=16973
  10316. if (tinymce.isWebKit) {
  10317. function insertBr(ed) {
  10318. var rng = selection.getRng(), br, div = dom.create('div', null, ' '), divYPos, vpHeight = dom.getViewPort(ed.getWin()).h;
  10319. // Insert BR element
  10320. rng.insertNode(br = dom.create('br'));
  10321. // Place caret after BR
  10322. rng.setStartAfter(br);
  10323. rng.setEndAfter(br);
  10324. selection.setRng(rng);
  10325. // Could not place caret after BR then insert an nbsp entity and move the caret
  10326. if (selection.getSel().focusNode == br.previousSibling) {
  10327. selection.select(dom.insertAfter(dom.doc.createTextNode('\u00a0'), br));
  10328. selection.collapse(TRUE);
  10329. }
  10330. // Create a temporary DIV after the BR and get the position as it
  10331. // seems like getPos() returns 0 for text nodes and BR elements.
  10332. dom.insertAfter(div, br);
  10333. divYPos = dom.getPos(div).y;
  10334. dom.remove(div);
  10335. // Scroll to new position, scrollIntoView can't be used due to bug: http://bugs.webkit.org/show_bug.cgi?id=16117
  10336. if (divYPos > vpHeight) // It is not necessary to scroll if the DIV is inside the view port.
  10337. ed.getWin().scrollTo(0, divYPos);
  10338. };
  10339. ed.onKeyPress.add(function(ed, e) {
  10340. if (e.keyCode == 13 && (e.shiftKey || (s.force_br_newlines && !dom.getParent(selection.getNode(), 'h1,h2,h3,h4,h5,h6,ol,ul')))) {
  10341. insertBr(ed);
  10342. Event.cancel(e);
  10343. }
  10344. });
  10345. }
  10346. // IE specific fixes
  10347. if (isIE) {
  10348. // Replaces IE:s auto generated paragraphs with the specified element name
  10349. if (s.element != 'P') {
  10350. ed.onKeyPress.add(function(ed, e) {
  10351. t.lastElm = selection.getNode().nodeName;
  10352. });
  10353. ed.onKeyUp.add(function(ed, e) {
  10354. var bl, n = selection.getNode(), b = ed.getBody();
  10355. if (b.childNodes.length === 1 && n.nodeName == 'P') {
  10356. n = dom.rename(n, s.element);
  10357. selection.select(n);
  10358. selection.collapse();
  10359. ed.nodeChanged();
  10360. } else if (e.keyCode == 13 && !e.shiftKey && t.lastElm != 'P') {
  10361. bl = dom.getParent(n, 'p');
  10362. if (bl) {
  10363. dom.rename(bl, s.element);
  10364. ed.nodeChanged();
  10365. }
  10366. }
  10367. });
  10368. }
  10369. }
  10370. },
  10371. getParentBlock : function(n) {
  10372. var d = this.dom;
  10373. return d.getParent(n, d.isBlock);
  10374. },
  10375. insertPara : function(e) {
  10376. 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;
  10377. var rb, ra, dir, sn, so, en, eo, sb, eb, bn, bef, aft, sc, ec, n, vp = dom.getViewPort(ed.getWin()), y, ch, car;
  10378. ed.undoManager.beforeChange();
  10379. // If root blocks are forced then use Operas default behavior since it's really good
  10380. // Removed due to bug: #1853816
  10381. // if (se.forced_root_block && isOpera)
  10382. // return TRUE;
  10383. // Setup before range
  10384. rb = d.createRange();
  10385. // If is before the first block element and in body, then move it into first block element
  10386. rb.setStart(s.anchorNode, s.anchorOffset);
  10387. rb.collapse(TRUE);
  10388. // Setup after range
  10389. ra = d.createRange();
  10390. // If is before the first block element and in body, then move it into first block element
  10391. ra.setStart(s.focusNode, s.focusOffset);
  10392. ra.collapse(TRUE);
  10393. // Setup start/end points
  10394. dir = rb.compareBoundaryPoints(rb.START_TO_END, ra) < 0;
  10395. sn = dir ? s.anchorNode : s.focusNode;
  10396. so = dir ? s.anchorOffset : s.focusOffset;
  10397. en = dir ? s.focusNode : s.anchorNode;
  10398. eo = dir ? s.focusOffset : s.anchorOffset;
  10399. // If selection is in empty table cell
  10400. if (sn === en && /^(TD|TH)$/.test(sn.nodeName)) {
  10401. if (sn.firstChild.nodeName == 'BR')
  10402. dom.remove(sn.firstChild); // Remove BR
  10403. // Create two new block elements
  10404. if (sn.childNodes.length == 0) {
  10405. ed.dom.add(sn, se.element, null, '<br />');
  10406. aft = ed.dom.add(sn, se.element, null, '<br />');
  10407. } else {
  10408. n = sn.innerHTML;
  10409. sn.innerHTML = '';
  10410. ed.dom.add(sn, se.element, null, n);
  10411. aft = ed.dom.add(sn, se.element, null, '<br />');
  10412. }
  10413. // Move caret into the last one
  10414. r = d.createRange();
  10415. r.selectNodeContents(aft);
  10416. r.collapse(1);
  10417. ed.selection.setRng(r);
  10418. return FALSE;
  10419. }
  10420. // If the caret is in an invalid location in FF we need to move it into the first block
  10421. if (sn == b && en == b && b.firstChild && ed.dom.isBlock(b.firstChild)) {
  10422. sn = en = sn.firstChild;
  10423. so = eo = 0;
  10424. rb = d.createRange();
  10425. rb.setStart(sn, 0);
  10426. ra = d.createRange();
  10427. ra.setStart(en, 0);
  10428. }
  10429. // If the body is totally empty add a BR element this might happen on webkit
  10430. if (!d.body.hasChildNodes()) {
  10431. d.body.appendChild(dom.create('br'));
  10432. }
  10433. // Never use body as start or end node
  10434. sn = sn.nodeName == "HTML" ? d.body : sn; // Fix for Opera bug: https://bugs.opera.com/show_bug.cgi?id=273224&comments=yes
  10435. sn = sn.nodeName == "BODY" ? sn.firstChild : sn;
  10436. en = en.nodeName == "HTML" ? d.body : en; // Fix for Opera bug: https://bugs.opera.com/show_bug.cgi?id=273224&comments=yes
  10437. en = en.nodeName == "BODY" ? en.firstChild : en;
  10438. // Get start and end blocks
  10439. sb = t.getParentBlock(sn);
  10440. eb = t.getParentBlock(en);
  10441. bn = sb ? sb.nodeName : se.element; // Get block name to create
  10442. // Return inside list use default browser behavior
  10443. if (n = t.dom.getParent(sb, 'li,pre')) {
  10444. if (n.nodeName == 'LI')
  10445. return splitList(ed.selection, t.dom, n);
  10446. return TRUE;
  10447. }
  10448. // If caption or absolute layers then always generate new blocks within
  10449. if (sb && (sb.nodeName == 'CAPTION' || /absolute|relative|fixed/gi.test(dom.getStyle(sb, 'position', 1)))) {
  10450. bn = se.element;
  10451. sb = null;
  10452. }
  10453. // If caption or absolute layers then always generate new blocks within
  10454. if (eb && (eb.nodeName == 'CAPTION' || /absolute|relative|fixed/gi.test(dom.getStyle(sb, 'position', 1)))) {
  10455. bn = se.element;
  10456. eb = null;
  10457. }
  10458. // Use P instead
  10459. if (/(TD|TABLE|TH|CAPTION)/.test(bn) || (sb && bn == "DIV" && /left|right/gi.test(dom.getStyle(sb, 'float', 1)))) {
  10460. bn = se.element;
  10461. sb = eb = null;
  10462. }
  10463. // Setup new before and after blocks
  10464. bef = (sb && sb.nodeName == bn) ? sb.cloneNode(0) : ed.dom.create(bn);
  10465. aft = (eb && eb.nodeName == bn) ? eb.cloneNode(0) : ed.dom.create(bn);
  10466. // Remove id from after clone
  10467. aft.removeAttribute('id');
  10468. // Is header and cursor is at the end, then force paragraph under
  10469. if (/^(H[1-6])$/.test(bn) && isAtEnd(r, sb))
  10470. aft = ed.dom.create(se.element);
  10471. // Find start chop node
  10472. n = sc = sn;
  10473. do {
  10474. if (n == b || n.nodeType == 9 || t.dom.isBlock(n) || /(TD|TABLE|TH|CAPTION)/.test(n.nodeName))
  10475. break;
  10476. sc = n;
  10477. } while ((n = n.previousSibling ? n.previousSibling : n.parentNode));
  10478. // Find end chop node
  10479. n = ec = en;
  10480. do {
  10481. if (n == b || n.nodeType == 9 || t.dom.isBlock(n) || /(TD|TABLE|TH|CAPTION)/.test(n.nodeName))
  10482. break;
  10483. ec = n;
  10484. } while ((n = n.nextSibling ? n.nextSibling : n.parentNode));
  10485. // Place first chop part into before block element
  10486. if (sc.nodeName == bn)
  10487. rb.setStart(sc, 0);
  10488. else
  10489. rb.setStartBefore(sc);
  10490. rb.setEnd(sn, so);
  10491. bef.appendChild(rb.cloneContents() || d.createTextNode('')); // Empty text node needed for Safari
  10492. // Place secnd chop part within new block element
  10493. try {
  10494. ra.setEndAfter(ec);
  10495. } catch(ex) {
  10496. //console.debug(s.focusNode, s.focusOffset);
  10497. }
  10498. ra.setStart(en, eo);
  10499. aft.appendChild(ra.cloneContents() || d.createTextNode('')); // Empty text node needed for Safari
  10500. // Create range around everything
  10501. r = d.createRange();
  10502. if (!sc.previousSibling && sc.parentNode.nodeName == bn) {
  10503. r.setStartBefore(sc.parentNode);
  10504. } else {
  10505. if (rb.startContainer.nodeName == bn && rb.startOffset == 0)
  10506. r.setStartBefore(rb.startContainer);
  10507. else
  10508. r.setStart(rb.startContainer, rb.startOffset);
  10509. }
  10510. if (!ec.nextSibling && ec.parentNode.nodeName == bn)
  10511. r.setEndAfter(ec.parentNode);
  10512. else
  10513. r.setEnd(ra.endContainer, ra.endOffset);
  10514. // Delete and replace it with new block elements
  10515. r.deleteContents();
  10516. if (isOpera)
  10517. ed.getWin().scrollTo(0, vp.y);
  10518. // Never wrap blocks in blocks
  10519. if (bef.firstChild && bef.firstChild.nodeName == bn)
  10520. bef.innerHTML = bef.firstChild.innerHTML;
  10521. if (aft.firstChild && aft.firstChild.nodeName == bn)
  10522. aft.innerHTML = aft.firstChild.innerHTML;
  10523. function appendStyles(e, en) {
  10524. var nl = [], nn, n, i;
  10525. e.innerHTML = '';
  10526. // Make clones of style elements
  10527. if (se.keep_styles) {
  10528. n = en;
  10529. do {
  10530. // We only want style specific elements
  10531. if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(n.nodeName)) {
  10532. nn = n.cloneNode(FALSE);
  10533. dom.setAttrib(nn, 'id', ''); // Remove ID since it needs to be unique
  10534. nl.push(nn);
  10535. }
  10536. } while (n = n.parentNode);
  10537. }
  10538. // Append style elements to aft
  10539. if (nl.length > 0) {
  10540. for (i = nl.length - 1, nn = e; i >= 0; i--)
  10541. nn = nn.appendChild(nl[i]);
  10542. // Padd most inner style element
  10543. nl[0].innerHTML = isOpera ? '\u00a0' : '<br />'; // Extra space for Opera so that the caret can move there
  10544. return nl[0]; // Move caret to most inner element
  10545. } else
  10546. e.innerHTML = isOpera ? '\u00a0' : '<br />'; // Extra space for Opera so that the caret can move there
  10547. };
  10548. // Padd empty blocks
  10549. if (dom.isEmpty(bef))
  10550. appendStyles(bef, sn);
  10551. // Fill empty afterblook with current style
  10552. if (dom.isEmpty(aft))
  10553. car = appendStyles(aft, en);
  10554. // Opera needs this one backwards for older versions
  10555. if (isOpera && parseFloat(opera.version()) < 9.5) {
  10556. r.insertNode(bef);
  10557. r.insertNode(aft);
  10558. } else {
  10559. r.insertNode(aft);
  10560. r.insertNode(bef);
  10561. }
  10562. // Normalize
  10563. aft.normalize();
  10564. bef.normalize();
  10565. // Move cursor and scroll into view
  10566. ed.selection.select(aft, true);
  10567. ed.selection.collapse(true);
  10568. // 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
  10569. y = ed.dom.getPos(aft).y;
  10570. //ch = aft.clientHeight;
  10571. // Is element within viewport
  10572. if (y < vp.y || y + 25 > vp.y + vp.h) {
  10573. 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
  10574. /*console.debug(
  10575. 'Element: y=' + y + ', h=' + ch + ', ' +
  10576. 'Viewport: y=' + vp.y + ", h=" + vp.h + ', bottom=' + (vp.y + vp.h)
  10577. );*/
  10578. }
  10579. ed.undoManager.add();
  10580. return FALSE;
  10581. },
  10582. backspaceDelete : function(e, bs) {
  10583. 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;
  10584. // Delete when caret is behind a element doesn't work correctly on Gecko see #3011651
  10585. if (!bs && r.collapsed && sc.nodeType == 1 && r.startOffset == sc.childNodes.length) {
  10586. walker = new tinymce.dom.TreeWalker(sc.lastChild, sc);
  10587. // Walk the dom backwards until we find a text node
  10588. for (n = sc.lastChild; n; n = walker.prev()) {
  10589. if (n.nodeType == 3) {
  10590. r.setStart(n, n.nodeValue.length);
  10591. r.collapse(true);
  10592. se.setRng(r);
  10593. return;
  10594. }
  10595. }
  10596. }
  10597. // The caret sometimes gets stuck in Gecko if you delete empty paragraphs
  10598. // This workaround removes the element by hand and moves the caret to the previous element
  10599. if (sc && ed.dom.isBlock(sc) && !/^(TD|TH)$/.test(sc.nodeName) && bs) {
  10600. if (sc.childNodes.length == 0 || (sc.childNodes.length == 1 && sc.firstChild.nodeName == 'BR')) {
  10601. // Find previous block element
  10602. n = sc;
  10603. while ((n = n.previousSibling) && !ed.dom.isBlock(n)) ;
  10604. if (n) {
  10605. if (sc != b.firstChild) {
  10606. // Find last text node
  10607. w = ed.dom.doc.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, FALSE);
  10608. while (tn = w.nextNode())
  10609. n = tn;
  10610. // Place caret at the end of last text node
  10611. r = ed.getDoc().createRange();
  10612. r.setStart(n, n.nodeValue ? n.nodeValue.length : 0);
  10613. r.setEnd(n, n.nodeValue ? n.nodeValue.length : 0);
  10614. se.setRng(r);
  10615. // Remove the target container
  10616. ed.dom.remove(sc);
  10617. }
  10618. return Event.cancel(e);
  10619. }
  10620. }
  10621. }
  10622. }
  10623. });
  10624. })(tinymce);
  10625. (function(tinymce) {
  10626. // Shorten names
  10627. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, extend = tinymce.extend;
  10628. tinymce.create('tinymce.ControlManager', {
  10629. ControlManager : function(ed, s) {
  10630. var t = this, i;
  10631. s = s || {};
  10632. t.editor = ed;
  10633. t.controls = {};
  10634. t.onAdd = new tinymce.util.Dispatcher(t);
  10635. t.onPostRender = new tinymce.util.Dispatcher(t);
  10636. t.prefix = s.prefix || ed.id + '_';
  10637. t._cls = {};
  10638. t.onPostRender.add(function() {
  10639. each(t.controls, function(c) {
  10640. c.postRender();
  10641. });
  10642. });
  10643. },
  10644. get : function(id) {
  10645. return this.controls[this.prefix + id] || this.controls[id];
  10646. },
  10647. setActive : function(id, s) {
  10648. var c = null;
  10649. if (c = this.get(id))
  10650. c.setActive(s);
  10651. return c;
  10652. },
  10653. setDisabled : function(id, s) {
  10654. var c = null;
  10655. if (c = this.get(id))
  10656. c.setDisabled(s);
  10657. return c;
  10658. },
  10659. add : function(c) {
  10660. var t = this;
  10661. if (c) {
  10662. t.controls[c.id] = c;
  10663. t.onAdd.dispatch(c, t);
  10664. }
  10665. return c;
  10666. },
  10667. createControl : function(n) {
  10668. var c, t = this, ed = t.editor;
  10669. each(ed.plugins, function(p) {
  10670. if (p.createControl) {
  10671. c = p.createControl(n, t);
  10672. if (c)
  10673. return false;
  10674. }
  10675. });
  10676. switch (n) {
  10677. case "|":
  10678. case "separator":
  10679. return t.createSeparator();
  10680. }
  10681. if (!c && ed.buttons && (c = ed.buttons[n]))
  10682. return t.createButton(n, c);
  10683. return t.add(c);
  10684. },
  10685. createDropMenu : function(id, s, cc) {
  10686. var t = this, ed = t.editor, c, bm, v, cls;
  10687. s = extend({
  10688. 'class' : 'mceDropDown',
  10689. constrain : ed.settings.constrain_menus
  10690. }, s);
  10691. s['class'] = s['class'] + ' ' + ed.getParam('skin') + 'Skin';
  10692. if (v = ed.getParam('skin_variant'))
  10693. s['class'] += ' ' + ed.getParam('skin') + 'Skin' + v.substring(0, 1).toUpperCase() + v.substring(1);
  10694. id = t.prefix + id;
  10695. cls = cc || t._cls.dropmenu || tinymce.ui.DropMenu;
  10696. c = t.controls[id] = new cls(id, s);
  10697. c.onAddItem.add(function(c, o) {
  10698. var s = o.settings;
  10699. s.title = ed.getLang(s.title, s.title);
  10700. if (!s.onclick) {
  10701. s.onclick = function(v) {
  10702. if (s.cmd)
  10703. ed.execCommand(s.cmd, s.ui || false, s.value);
  10704. };
  10705. }
  10706. });
  10707. ed.onRemove.add(function() {
  10708. c.destroy();
  10709. });
  10710. // Fix for bug #1897785, #1898007
  10711. if (tinymce.isIE) {
  10712. c.onShowMenu.add(function() {
  10713. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  10714. ed.focus();
  10715. bm = ed.selection.getBookmark(1);
  10716. });
  10717. c.onHideMenu.add(function() {
  10718. if (bm) {
  10719. ed.selection.moveToBookmark(bm);
  10720. bm = 0;
  10721. }
  10722. });
  10723. }
  10724. return t.add(c);
  10725. },
  10726. createListBox : function(id, s, cc) {
  10727. var t = this, ed = t.editor, cmd, c, cls;
  10728. if (t.get(id))
  10729. return null;
  10730. s.title = ed.translate(s.title);
  10731. s.scope = s.scope || ed;
  10732. if (!s.onselect) {
  10733. s.onselect = function(v) {
  10734. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  10735. };
  10736. }
  10737. s = extend({
  10738. title : s.title,
  10739. 'class' : 'mce_' + id,
  10740. scope : s.scope,
  10741. control_manager : t
  10742. }, s);
  10743. id = t.prefix + id;
  10744. function useNativeListForAccessibility(ed) {
  10745. return ed.settings.use_accessible_selects && !tinymce.isGecko
  10746. }
  10747. if (ed.settings.use_native_selects || useNativeListForAccessibility(ed))
  10748. c = new tinymce.ui.NativeListBox(id, s);
  10749. else {
  10750. cls = cc || t._cls.listbox || tinymce.ui.ListBox;
  10751. c = new cls(id, s, ed);
  10752. }
  10753. t.controls[id] = c;
  10754. // Fix focus problem in Safari
  10755. if (tinymce.isWebKit) {
  10756. c.onPostRender.add(function(c, n) {
  10757. // Store bookmark on mousedown
  10758. Event.add(n, 'mousedown', function() {
  10759. ed.bookmark = ed.selection.getBookmark(1);
  10760. });
  10761. // Restore on focus, since it might be lost
  10762. Event.add(n, 'focus', function() {
  10763. ed.selection.moveToBookmark(ed.bookmark);
  10764. ed.bookmark = null;
  10765. });
  10766. });
  10767. }
  10768. if (c.hideMenu)
  10769. ed.onMouseDown.add(c.hideMenu, c);
  10770. return t.add(c);
  10771. },
  10772. createButton : function(id, s, cc) {
  10773. var t = this, ed = t.editor, o, c, cls;
  10774. if (t.get(id))
  10775. return null;
  10776. s.title = ed.translate(s.title);
  10777. s.label = ed.translate(s.label);
  10778. s.scope = s.scope || ed;
  10779. if (!s.onclick && !s.menu_button) {
  10780. s.onclick = function() {
  10781. ed.execCommand(s.cmd, s.ui || false, s.value);
  10782. };
  10783. }
  10784. s = extend({
  10785. title : s.title,
  10786. 'class' : 'mce_' + id,
  10787. unavailable_prefix : ed.getLang('unavailable', ''),
  10788. scope : s.scope,
  10789. control_manager : t
  10790. }, s);
  10791. id = t.prefix + id;
  10792. if (s.menu_button) {
  10793. cls = cc || t._cls.menubutton || tinymce.ui.MenuButton;
  10794. c = new cls(id, s, ed);
  10795. ed.onMouseDown.add(c.hideMenu, c);
  10796. } else {
  10797. cls = t._cls.button || tinymce.ui.Button;
  10798. c = new cls(id, s, ed);
  10799. }
  10800. return t.add(c);
  10801. },
  10802. createMenuButton : function(id, s, cc) {
  10803. s = s || {};
  10804. s.menu_button = 1;
  10805. return this.createButton(id, s, cc);
  10806. },
  10807. createSplitButton : function(id, s, cc) {
  10808. var t = this, ed = t.editor, cmd, c, cls;
  10809. if (t.get(id))
  10810. return null;
  10811. s.title = ed.translate(s.title);
  10812. s.scope = s.scope || ed;
  10813. if (!s.onclick) {
  10814. s.onclick = function(v) {
  10815. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  10816. };
  10817. }
  10818. if (!s.onselect) {
  10819. s.onselect = function(v) {
  10820. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  10821. };
  10822. }
  10823. s = extend({
  10824. title : s.title,
  10825. 'class' : 'mce_' + id,
  10826. scope : s.scope,
  10827. control_manager : t
  10828. }, s);
  10829. id = t.prefix + id;
  10830. cls = cc || t._cls.splitbutton || tinymce.ui.SplitButton;
  10831. c = t.add(new cls(id, s, ed));
  10832. ed.onMouseDown.add(c.hideMenu, c);
  10833. return c;
  10834. },
  10835. createColorSplitButton : function(id, s, cc) {
  10836. var t = this, ed = t.editor, cmd, c, cls, bm;
  10837. if (t.get(id))
  10838. return null;
  10839. s.title = ed.translate(s.title);
  10840. s.scope = s.scope || ed;
  10841. if (!s.onclick) {
  10842. s.onclick = function(v) {
  10843. if (tinymce.isIE)
  10844. bm = ed.selection.getBookmark(1);
  10845. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  10846. };
  10847. }
  10848. if (!s.onselect) {
  10849. s.onselect = function(v) {
  10850. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  10851. };
  10852. }
  10853. s = extend({
  10854. title : s.title,
  10855. 'class' : 'mce_' + id,
  10856. 'menu_class' : ed.getParam('skin') + 'Skin',
  10857. scope : s.scope,
  10858. more_colors_title : ed.getLang('more_colors')
  10859. }, s);
  10860. id = t.prefix + id;
  10861. cls = cc || t._cls.colorsplitbutton || tinymce.ui.ColorSplitButton;
  10862. c = new cls(id, s, ed);
  10863. ed.onMouseDown.add(c.hideMenu, c);
  10864. // Remove the menu element when the editor is removed
  10865. ed.onRemove.add(function() {
  10866. c.destroy();
  10867. });
  10868. // Fix for bug #1897785, #1898007
  10869. if (tinymce.isIE) {
  10870. c.onShowMenu.add(function() {
  10871. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  10872. ed.focus();
  10873. bm = ed.selection.getBookmark(1);
  10874. });
  10875. c.onHideMenu.add(function() {
  10876. if (bm) {
  10877. ed.selection.moveToBookmark(bm);
  10878. bm = 0;
  10879. }
  10880. });
  10881. }
  10882. return t.add(c);
  10883. },
  10884. createToolbar : function(id, s, cc) {
  10885. var c, t = this, cls;
  10886. id = t.prefix + id;
  10887. cls = cc || t._cls.toolbar || tinymce.ui.Toolbar;
  10888. c = new cls(id, s, t.editor);
  10889. if (t.get(id))
  10890. return null;
  10891. return t.add(c);
  10892. },
  10893. createToolbarGroup : function(id, s, cc) {
  10894. var c, t = this, cls;
  10895. id = t.prefix + id;
  10896. cls = cc || this._cls.toolbarGroup || tinymce.ui.ToolbarGroup;
  10897. c = new cls(id, s, t.editor);
  10898. if (t.get(id))
  10899. return null;
  10900. return t.add(c);
  10901. },
  10902. createSeparator : function(cc) {
  10903. var cls = cc || this._cls.separator || tinymce.ui.Separator;
  10904. return new cls();
  10905. },
  10906. setControlType : function(n, c) {
  10907. return this._cls[n.toLowerCase()] = c;
  10908. },
  10909. destroy : function() {
  10910. each(this.controls, function(c) {
  10911. c.destroy();
  10912. });
  10913. this.controls = null;
  10914. }
  10915. });
  10916. })(tinymce);
  10917. (function(tinymce) {
  10918. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isIE = tinymce.isIE, isOpera = tinymce.isOpera;
  10919. tinymce.create('tinymce.WindowManager', {
  10920. WindowManager : function(ed) {
  10921. var t = this;
  10922. t.editor = ed;
  10923. t.onOpen = new Dispatcher(t);
  10924. t.onClose = new Dispatcher(t);
  10925. t.params = {};
  10926. t.features = {};
  10927. },
  10928. open : function(s, p) {
  10929. var t = this, f = '', x, y, mo = t.editor.settings.dialog_type == 'modal', w, sw, sh, vp = tinymce.DOM.getViewPort(), u;
  10930. // Default some options
  10931. s = s || {};
  10932. p = p || {};
  10933. sw = isOpera ? vp.w : screen.width; // Opera uses windows inside the Opera window
  10934. sh = isOpera ? vp.h : screen.height;
  10935. s.name = s.name || 'mc_' + new Date().getTime();
  10936. s.width = parseInt(s.width || 320);
  10937. s.height = parseInt(s.height || 240);
  10938. s.resizable = true;
  10939. s.left = s.left || parseInt(sw / 2.0) - (s.width / 2.0);
  10940. s.top = s.top || parseInt(sh / 2.0) - (s.height / 2.0);
  10941. p.inline = false;
  10942. p.mce_width = s.width;
  10943. p.mce_height = s.height;
  10944. p.mce_auto_focus = s.auto_focus;
  10945. if (mo) {
  10946. if (isIE) {
  10947. s.center = true;
  10948. s.help = false;
  10949. s.dialogWidth = s.width + 'px';
  10950. s.dialogHeight = s.height + 'px';
  10951. s.scroll = s.scrollbars || false;
  10952. }
  10953. }
  10954. // Build features string
  10955. each(s, function(v, k) {
  10956. if (tinymce.is(v, 'boolean'))
  10957. v = v ? 'yes' : 'no';
  10958. if (!/^(name|url)$/.test(k)) {
  10959. if (isIE && mo)
  10960. f += (f ? ';' : '') + k + ':' + v;
  10961. else
  10962. f += (f ? ',' : '') + k + '=' + v;
  10963. }
  10964. });
  10965. t.features = s;
  10966. t.params = p;
  10967. t.onOpen.dispatch(t, s, p);
  10968. u = s.url || s.file;
  10969. u = tinymce._addVer(u);
  10970. try {
  10971. if (isIE && mo) {
  10972. w = 1;
  10973. window.showModalDialog(u, window, f);
  10974. } else
  10975. w = window.open(u, s.name, f);
  10976. } catch (ex) {
  10977. // Ignore
  10978. }
  10979. if (!w)
  10980. alert(t.editor.getLang('popup_blocked'));
  10981. },
  10982. close : function(w) {
  10983. w.close();
  10984. this.onClose.dispatch(this);
  10985. },
  10986. createInstance : function(cl, a, b, c, d, e) {
  10987. var f = tinymce.resolve(cl);
  10988. return new f(a, b, c, d, e);
  10989. },
  10990. confirm : function(t, cb, s, w) {
  10991. w = w || window;
  10992. cb.call(s || this, w.confirm(this._decode(this.editor.getLang(t, t))));
  10993. },
  10994. alert : function(tx, cb, s, w) {
  10995. var t = this;
  10996. w = w || window;
  10997. w.alert(t._decode(t.editor.getLang(tx, tx)));
  10998. if (cb)
  10999. cb.call(s || t);
  11000. },
  11001. resizeBy : function(dw, dh, win) {
  11002. win.resizeBy(dw, dh);
  11003. },
  11004. // Internal functions
  11005. _decode : function(s) {
  11006. return tinymce.DOM.decode(s).replace(/\\n/g, '\n');
  11007. }
  11008. });
  11009. }(tinymce));
  11010. (function(tinymce) {
  11011. tinymce.Formatter = function(ed) {
  11012. var formats = {},
  11013. each = tinymce.each,
  11014. dom = ed.dom,
  11015. selection = ed.selection,
  11016. TreeWalker = tinymce.dom.TreeWalker,
  11017. rangeUtils = new tinymce.dom.RangeUtils(dom),
  11018. isValid = ed.schema.isValidChild,
  11019. isBlock = dom.isBlock,
  11020. forcedRootBlock = ed.settings.forced_root_block,
  11021. nodeIndex = dom.nodeIndex,
  11022. INVISIBLE_CHAR = '\uFEFF',
  11023. MCE_ATTR_RE = /^(src|href|style)$/,
  11024. FALSE = false,
  11025. TRUE = true,
  11026. undefined;
  11027. function isArray(obj) {
  11028. return obj instanceof Array;
  11029. };
  11030. function getParents(node, selector) {
  11031. return dom.getParents(node, selector, dom.getRoot());
  11032. };
  11033. function isCaretNode(node) {
  11034. return node.nodeType === 1 && (node.face === 'mceinline' || node.style.fontFamily === 'mceinline');
  11035. };
  11036. // Public functions
  11037. function get(name) {
  11038. return name ? formats[name] : formats;
  11039. };
  11040. function register(name, format) {
  11041. if (name) {
  11042. if (typeof(name) !== 'string') {
  11043. each(name, function(format, name) {
  11044. register(name, format);
  11045. });
  11046. } else {
  11047. // Force format into array and add it to internal collection
  11048. format = format.length ? format : [format];
  11049. each(format, function(format) {
  11050. // Set deep to false by default on selector formats this to avoid removing
  11051. // alignment on images inside paragraphs when alignment is changed on paragraphs
  11052. if (format.deep === undefined)
  11053. format.deep = !format.selector;
  11054. // Default to true
  11055. if (format.split === undefined)
  11056. format.split = !format.selector || format.inline;
  11057. // Default to true
  11058. if (format.remove === undefined && format.selector && !format.inline)
  11059. format.remove = 'none';
  11060. // Mark format as a mixed format inline + block level
  11061. if (format.selector && format.inline) {
  11062. format.mixed = true;
  11063. format.block_expand = true;
  11064. }
  11065. // Split classes if needed
  11066. if (typeof(format.classes) === 'string')
  11067. format.classes = format.classes.split(/\s+/);
  11068. });
  11069. formats[name] = format;
  11070. }
  11071. }
  11072. };
  11073. var getTextDecoration = function(node) {
  11074. var decoration;
  11075. ed.dom.getParent(node, function(n) {
  11076. decoration = ed.dom.getStyle(n, 'text-decoration');
  11077. return decoration && decoration !== 'none';
  11078. });
  11079. return decoration;
  11080. };
  11081. var processUnderlineAndColor = function(node) {
  11082. var textDecoration;
  11083. if (node.nodeType === 1 && node.parentNode && node.parentNode.nodeType === 1) {
  11084. textDecoration = getTextDecoration(node.parentNode);
  11085. if (ed.dom.getStyle(node, 'color') && textDecoration) {
  11086. ed.dom.setStyle(node, 'text-decoration', textDecoration);
  11087. } else if (ed.dom.getStyle(node, 'textdecoration') === textDecoration) {
  11088. ed.dom.setStyle(node, 'text-decoration', null);
  11089. }
  11090. }
  11091. };
  11092. function apply(name, vars, node) {
  11093. var formatList = get(name), format = formatList[0], bookmark, rng, i, isCollapsed = selection.isCollapsed();
  11094. function moveStart(rng) {
  11095. var container = rng.startContainer,
  11096. offset = rng.startOffset,
  11097. walker, node;
  11098. // Move startContainer/startOffset in to a suitable node
  11099. if (container.nodeType == 1 || container.nodeValue === "") {
  11100. container = container.nodeType == 1 ? container.childNodes[offset] : container;
  11101. // Might fail if the offset is behind the last element in it's container
  11102. if (container) {
  11103. walker = new TreeWalker(container, container.parentNode);
  11104. for (node = walker.current(); node; node = walker.next()) {
  11105. if (node.nodeType == 3 && !isWhiteSpaceNode(node)) {
  11106. rng.setStart(node, 0);
  11107. break;
  11108. }
  11109. }
  11110. }
  11111. }
  11112. return rng;
  11113. };
  11114. function setElementFormat(elm, fmt) {
  11115. fmt = fmt || format;
  11116. if (elm) {
  11117. if (fmt.onformat) {
  11118. fmt.onformat(elm, fmt, vars, node);
  11119. }
  11120. each(fmt.styles, function(value, name) {
  11121. dom.setStyle(elm, name, replaceVars(value, vars));
  11122. });
  11123. each(fmt.attributes, function(value, name) {
  11124. dom.setAttrib(elm, name, replaceVars(value, vars));
  11125. });
  11126. each(fmt.classes, function(value) {
  11127. value = replaceVars(value, vars);
  11128. if (!dom.hasClass(elm, value))
  11129. dom.addClass(elm, value);
  11130. });
  11131. }
  11132. };
  11133. function adjustSelectionToVisibleSelection() {
  11134. function findSelectionEnd(start, end) {
  11135. var walker = new TreeWalker(end);
  11136. for (node = walker.current(); node; node = walker.prev()) {
  11137. if (node.childNodes.length > 1 || node == start) {
  11138. return node;
  11139. }
  11140. }
  11141. };
  11142. // Adjust selection so that a end container with a end offset of zero is not included in the selection
  11143. // as this isn't visible to the user.
  11144. var rng = ed.selection.getRng();
  11145. var start = rng.startContainer;
  11146. var end = rng.endContainer;
  11147. if (start != end && rng.endOffset == 0) {
  11148. var newEnd = findSelectionEnd(start, end);
  11149. var endOffset = newEnd.nodeType == 3 ? newEnd.length : newEnd.childNodes.length;
  11150. rng.setEnd(newEnd, endOffset);
  11151. }
  11152. return rng;
  11153. }
  11154. function applyStyleToList(node, bookmark, wrapElm, newWrappers, process){
  11155. var nodes = [], listIndex = -1, list, startIndex = -1, endIndex = -1, currentWrapElm;
  11156. // find the index of the first child list.
  11157. each(node.childNodes, function(n, index) {
  11158. if (n.nodeName === "UL" || n.nodeName === "OL") {
  11159. listIndex = index;
  11160. list = n;
  11161. return false;
  11162. }
  11163. });
  11164. // get the index of the bookmarks
  11165. each(node.childNodes, function(n, index) {
  11166. if (n.nodeName === "SPAN" && dom.getAttrib(n, "data-mce-type") == "bookmark") {
  11167. if (n.id == bookmark.id + "_start") {
  11168. startIndex = index;
  11169. } else if (n.id == bookmark.id + "_end") {
  11170. endIndex = index;
  11171. }
  11172. }
  11173. });
  11174. // if the selection spans across an embedded list, or there isn't an embedded list - handle processing normally
  11175. if (listIndex <= 0 || (startIndex < listIndex && endIndex > listIndex)) {
  11176. each(tinymce.grep(node.childNodes), process);
  11177. return 0;
  11178. } else {
  11179. currentWrapElm = wrapElm.cloneNode(FALSE);
  11180. // create a list of the nodes on the same side of the list as the selection
  11181. each(tinymce.grep(node.childNodes), function(n, index) {
  11182. if ((startIndex < listIndex && index < listIndex) || (startIndex > listIndex && index > listIndex)) {
  11183. nodes.push(n);
  11184. n.parentNode.removeChild(n);
  11185. }
  11186. });
  11187. // insert the wrapping element either before or after the list.
  11188. if (startIndex < listIndex) {
  11189. node.insertBefore(currentWrapElm, list);
  11190. } else if (startIndex > listIndex) {
  11191. node.insertBefore(currentWrapElm, list.nextSibling);
  11192. }
  11193. // add the new nodes to the list.
  11194. newWrappers.push(currentWrapElm);
  11195. each(nodes, function(node) {
  11196. currentWrapElm.appendChild(node);
  11197. });
  11198. return currentWrapElm;
  11199. }
  11200. };
  11201. function applyRngStyle(rng, bookmark, node_specific) {
  11202. var newWrappers = [], wrapName, wrapElm;
  11203. // Setup wrapper element
  11204. wrapName = format.inline || format.block;
  11205. wrapElm = dom.create(wrapName);
  11206. setElementFormat(wrapElm);
  11207. rangeUtils.walk(rng, function(nodes) {
  11208. var currentWrapElm;
  11209. function process(node) {
  11210. var nodeName = node.nodeName.toLowerCase(), parentName = node.parentNode.nodeName.toLowerCase(), found;
  11211. // Stop wrapping on br elements
  11212. if (isEq(nodeName, 'br')) {
  11213. currentWrapElm = 0;
  11214. // Remove any br elements when we wrap things
  11215. if (format.block)
  11216. dom.remove(node);
  11217. return;
  11218. }
  11219. // If node is wrapper type
  11220. if (format.wrapper && matchNode(node, name, vars)) {
  11221. currentWrapElm = 0;
  11222. return;
  11223. }
  11224. // Can we rename the block
  11225. if (format.block && !format.wrapper && isTextBlock(nodeName)) {
  11226. node = dom.rename(node, wrapName);
  11227. setElementFormat(node);
  11228. newWrappers.push(node);
  11229. currentWrapElm = 0;
  11230. return;
  11231. }
  11232. // Handle selector patterns
  11233. if (format.selector) {
  11234. // Look for matching formats
  11235. each(formatList, function(format) {
  11236. // Check collapsed state if it exists
  11237. if ('collapsed' in format && format.collapsed !== isCollapsed) {
  11238. return;
  11239. }
  11240. if (dom.is(node, format.selector) && !isCaretNode(node)) {
  11241. setElementFormat(node, format);
  11242. found = true;
  11243. }
  11244. });
  11245. // Continue processing if a selector match wasn't found and a inline element is defined
  11246. if (!format.inline || found) {
  11247. currentWrapElm = 0;
  11248. return;
  11249. }
  11250. }
  11251. // Is it valid to wrap this item
  11252. if (isValid(wrapName, nodeName) && isValid(parentName, wrapName) &&
  11253. !(!node_specific && node.nodeType === 3 && node.nodeValue.length === 1 && node.nodeValue.charCodeAt(0) === 65279) && node.id !== '_mce_caret') {
  11254. // Start wrapping
  11255. if (!currentWrapElm) {
  11256. // Wrap the node
  11257. currentWrapElm = wrapElm.cloneNode(FALSE);
  11258. node.parentNode.insertBefore(currentWrapElm, node);
  11259. newWrappers.push(currentWrapElm);
  11260. }
  11261. currentWrapElm.appendChild(node);
  11262. } else if (nodeName == 'li' && bookmark) {
  11263. // Start wrapping - if we are in a list node and have a bookmark, then we will always begin by wrapping in a new element.
  11264. currentWrapElm = applyStyleToList(node, bookmark, wrapElm, newWrappers, process);
  11265. } else {
  11266. // Start a new wrapper for possible children
  11267. currentWrapElm = 0;
  11268. each(tinymce.grep(node.childNodes), process);
  11269. // End the last wrapper
  11270. currentWrapElm = 0;
  11271. }
  11272. };
  11273. // Process siblings from range
  11274. each(nodes, process);
  11275. });
  11276. // Wrap links inside as well, for example color inside a link when the wrapper is around the link
  11277. if (format.wrap_links === false) {
  11278. each(newWrappers, function(node) {
  11279. function process(node) {
  11280. var i, currentWrapElm, children;
  11281. if (node.nodeName === 'A') {
  11282. currentWrapElm = wrapElm.cloneNode(FALSE);
  11283. newWrappers.push(currentWrapElm);
  11284. children = tinymce.grep(node.childNodes);
  11285. for (i = 0; i < children.length; i++)
  11286. currentWrapElm.appendChild(children[i]);
  11287. node.appendChild(currentWrapElm);
  11288. }
  11289. each(tinymce.grep(node.childNodes), process);
  11290. };
  11291. process(node);
  11292. });
  11293. }
  11294. // Cleanup
  11295. each(newWrappers, function(node) {
  11296. var childCount;
  11297. function getChildCount(node) {
  11298. var count = 0;
  11299. each(node.childNodes, function(node) {
  11300. if (!isWhiteSpaceNode(node) && !isBookmarkNode(node))
  11301. count++;
  11302. });
  11303. return count;
  11304. };
  11305. function mergeStyles(node) {
  11306. var child, clone;
  11307. each(node.childNodes, function(node) {
  11308. if (node.nodeType == 1 && !isBookmarkNode(node) && !isCaretNode(node)) {
  11309. child = node;
  11310. return FALSE; // break loop
  11311. }
  11312. });
  11313. // If child was found and of the same type as the current node
  11314. if (child && matchName(child, format)) {
  11315. clone = child.cloneNode(FALSE);
  11316. setElementFormat(clone);
  11317. dom.replace(clone, node, TRUE);
  11318. dom.remove(child, 1);
  11319. }
  11320. return clone || node;
  11321. };
  11322. childCount = getChildCount(node);
  11323. // Remove empty nodes but only if there is multiple wrappers and they are not block
  11324. // elements so never remove single <h1></h1> since that would remove the currrent empty block element where the caret is at
  11325. if ((newWrappers.length > 1 || !isBlock(node)) && childCount === 0) {
  11326. dom.remove(node, 1);
  11327. return;
  11328. }
  11329. if (format.inline || format.wrapper) {
  11330. // Merges the current node with it's children of similar type to reduce the number of elements
  11331. if (!format.exact && childCount === 1)
  11332. node = mergeStyles(node);
  11333. // Remove/merge children
  11334. each(formatList, function(format) {
  11335. // Merge all children of similar type will move styles from child to parent
  11336. // this: <span style="color:red"><b><span style="color:red; font-size:10px">text</span></b></span>
  11337. // will become: <span style="color:red"><b><span style="font-size:10px">text</span></b></span>
  11338. each(dom.select(format.inline, node), function(child) {
  11339. var parent;
  11340. // When wrap_links is set to false we don't want
  11341. // to remove the format on children within links
  11342. if (format.wrap_links === false) {
  11343. parent = child.parentNode;
  11344. do {
  11345. if (parent.nodeName === 'A')
  11346. return;
  11347. } while (parent = parent.parentNode);
  11348. }
  11349. removeFormat(format, vars, child, format.exact ? child : null);
  11350. });
  11351. });
  11352. // Remove child if direct parent is of same type
  11353. if (matchNode(node.parentNode, name, vars)) {
  11354. dom.remove(node, 1);
  11355. node = 0;
  11356. return TRUE;
  11357. }
  11358. // Look for parent with similar style format
  11359. if (format.merge_with_parents) {
  11360. dom.getParent(node.parentNode, function(parent) {
  11361. if (matchNode(parent, name, vars)) {
  11362. dom.remove(node, 1);
  11363. node = 0;
  11364. return TRUE;
  11365. }
  11366. });
  11367. }
  11368. // Merge next and previous siblings if they are similar <b>text</b><b>text</b> becomes <b>texttext</b>
  11369. if (node && format.merge_siblings !== false) {
  11370. node = mergeSiblings(getNonWhiteSpaceSibling(node), node);
  11371. node = mergeSiblings(node, getNonWhiteSpaceSibling(node, TRUE));
  11372. }
  11373. }
  11374. });
  11375. };
  11376. if (format) {
  11377. if (node) {
  11378. if (node.nodeType) {
  11379. rng = dom.createRng();
  11380. rng.setStartBefore(node);
  11381. rng.setEndAfter(node);
  11382. applyRngStyle(expandRng(rng, formatList), null, true);
  11383. } else {
  11384. applyRngStyle(node, null, true);
  11385. }
  11386. } else {
  11387. if (!isCollapsed || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  11388. // Obtain selection node before selection is unselected by applyRngStyle()
  11389. var curSelNode = ed.selection.getNode();
  11390. // Apply formatting to selection
  11391. ed.selection.setRng(adjustSelectionToVisibleSelection());
  11392. bookmark = selection.getBookmark();
  11393. applyRngStyle(expandRng(selection.getRng(TRUE), formatList), bookmark);
  11394. // Colored nodes should be underlined so that the color of the underline matches the text color.
  11395. if (format.styles && (format.styles.color || format.styles.textDecoration)) {
  11396. tinymce.walk(curSelNode, processUnderlineAndColor, 'childNodes');
  11397. processUnderlineAndColor(curSelNode);
  11398. }
  11399. selection.moveToBookmark(bookmark);
  11400. selection.setRng(moveStart(selection.getRng(TRUE)));
  11401. ed.nodeChanged();
  11402. } else
  11403. performCaretAction('apply', name, vars);
  11404. }
  11405. }
  11406. };
  11407. function remove(name, vars, node) {
  11408. var formatList = get(name), format = formatList[0], bookmark, i, rng;
  11409. function moveStart(rng) {
  11410. var container = rng.startContainer,
  11411. offset = rng.startOffset,
  11412. walker, node, nodes, tmpNode;
  11413. // Convert text node into index if possible
  11414. if (container.nodeType == 3 && offset >= container.nodeValue.length - 1) {
  11415. container = container.parentNode;
  11416. offset = nodeIndex(container) + 1;
  11417. }
  11418. // Move startContainer/startOffset in to a suitable node
  11419. if (container.nodeType == 1) {
  11420. nodes = container.childNodes;
  11421. container = nodes[Math.min(offset, nodes.length - 1)];
  11422. walker = new TreeWalker(container);
  11423. // If offset is at end of the parent node walk to the next one
  11424. if (offset > nodes.length - 1)
  11425. walker.next();
  11426. for (node = walker.current(); node; node = walker.next()) {
  11427. if (node.nodeType == 3 && !isWhiteSpaceNode(node)) {
  11428. // IE has a "neat" feature where it moves the start node into the closest element
  11429. // we can avoid this by inserting an element before it and then remove it after we set the selection
  11430. tmpNode = dom.create('a', null, INVISIBLE_CHAR);
  11431. node.parentNode.insertBefore(tmpNode, node);
  11432. // Set selection and remove tmpNode
  11433. rng.setStart(node, 0);
  11434. selection.setRng(rng);
  11435. dom.remove(tmpNode);
  11436. return;
  11437. }
  11438. }
  11439. }
  11440. };
  11441. // Merges the styles for each node
  11442. function process(node) {
  11443. var children, i, l;
  11444. // Grab the children first since the nodelist might be changed
  11445. children = tinymce.grep(node.childNodes);
  11446. // Process current node
  11447. for (i = 0, l = formatList.length; i < l; i++) {
  11448. if (removeFormat(formatList[i], vars, node, node))
  11449. break;
  11450. }
  11451. // Process the children
  11452. if (format.deep) {
  11453. for (i = 0, l = children.length; i < l; i++)
  11454. process(children[i]);
  11455. }
  11456. };
  11457. function findFormatRoot(container) {
  11458. var formatRoot;
  11459. // Find format root
  11460. each(getParents(container.parentNode).reverse(), function(parent) {
  11461. var format;
  11462. // Find format root element
  11463. if (!formatRoot && parent.id != '_start' && parent.id != '_end') {
  11464. // Is the node matching the format we are looking for
  11465. format = matchNode(parent, name, vars);
  11466. if (format && format.split !== false)
  11467. formatRoot = parent;
  11468. }
  11469. });
  11470. return formatRoot;
  11471. };
  11472. function wrapAndSplit(format_root, container, target, split) {
  11473. var parent, clone, lastClone, firstClone, i, formatRootParent;
  11474. // Format root found then clone formats and split it
  11475. if (format_root) {
  11476. formatRootParent = format_root.parentNode;
  11477. for (parent = container.parentNode; parent && parent != formatRootParent; parent = parent.parentNode) {
  11478. clone = parent.cloneNode(FALSE);
  11479. for (i = 0; i < formatList.length; i++) {
  11480. if (removeFormat(formatList[i], vars, clone, clone)) {
  11481. clone = 0;
  11482. break;
  11483. }
  11484. }
  11485. // Build wrapper node
  11486. if (clone) {
  11487. if (lastClone)
  11488. clone.appendChild(lastClone);
  11489. if (!firstClone)
  11490. firstClone = clone;
  11491. lastClone = clone;
  11492. }
  11493. }
  11494. // Never split block elements if the format is mixed
  11495. if (split && (!format.mixed || !isBlock(format_root)))
  11496. container = dom.split(format_root, container);
  11497. // Wrap container in cloned formats
  11498. if (lastClone) {
  11499. target.parentNode.insertBefore(lastClone, target);
  11500. firstClone.appendChild(target);
  11501. }
  11502. }
  11503. return container;
  11504. };
  11505. function splitToFormatRoot(container) {
  11506. return wrapAndSplit(findFormatRoot(container), container, container, true);
  11507. };
  11508. function unwrap(start) {
  11509. var node = dom.get(start ? '_start' : '_end'),
  11510. out = node[start ? 'firstChild' : 'lastChild'];
  11511. // If the end is placed within the start the result will be removed
  11512. // So this checks if the out node is a bookmark node if it is it
  11513. // checks for another more suitable node
  11514. if (isBookmarkNode(out))
  11515. out = out[start ? 'firstChild' : 'lastChild'];
  11516. dom.remove(node, true);
  11517. return out;
  11518. };
  11519. function removeRngStyle(rng) {
  11520. var startContainer, endContainer;
  11521. rng = expandRng(rng, formatList, TRUE);
  11522. if (format.split) {
  11523. startContainer = getContainer(rng, TRUE);
  11524. endContainer = getContainer(rng);
  11525. if (startContainer != endContainer) {
  11526. // Wrap start/end nodes in span element since these might be cloned/moved
  11527. startContainer = wrap(startContainer, 'span', {id : '_start', 'data-mce-type' : 'bookmark'});
  11528. endContainer = wrap(endContainer, 'span', {id : '_end', 'data-mce-type' : 'bookmark'});
  11529. // Split start/end
  11530. splitToFormatRoot(startContainer);
  11531. splitToFormatRoot(endContainer);
  11532. // Unwrap start/end to get real elements again
  11533. startContainer = unwrap(TRUE);
  11534. endContainer = unwrap();
  11535. } else
  11536. startContainer = endContainer = splitToFormatRoot(startContainer);
  11537. // Update range positions since they might have changed after the split operations
  11538. rng.startContainer = startContainer.parentNode;
  11539. rng.startOffset = nodeIndex(startContainer);
  11540. rng.endContainer = endContainer.parentNode;
  11541. rng.endOffset = nodeIndex(endContainer) + 1;
  11542. }
  11543. // Remove items between start/end
  11544. rangeUtils.walk(rng, function(nodes) {
  11545. each(nodes, function(node) {
  11546. process(node);
  11547. // Remove parent span if it only contains text-decoration: underline, yet a parent node is also underlined.
  11548. if (node.nodeType === 1 && ed.dom.getStyle(node, 'text-decoration') === 'underline' && node.parentNode && getTextDecoration(node.parentNode) === 'underline') {
  11549. removeFormat({'deep': false, 'exact': true, 'inline': 'span', 'styles': {'textDecoration' : 'underline'}}, null, node);
  11550. }
  11551. });
  11552. });
  11553. };
  11554. // Handle node
  11555. if (node) {
  11556. if (node.nodeType) {
  11557. rng = dom.createRng();
  11558. rng.setStartBefore(node);
  11559. rng.setEndAfter(node);
  11560. removeRngStyle(rng);
  11561. } else {
  11562. removeRngStyle(node);
  11563. }
  11564. return;
  11565. }
  11566. if (!selection.isCollapsed() || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  11567. bookmark = selection.getBookmark();
  11568. removeRngStyle(selection.getRng(TRUE));
  11569. selection.moveToBookmark(bookmark);
  11570. // 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
  11571. if (format.inline && match(name, vars, selection.getStart())) {
  11572. moveStart(selection.getRng(true));
  11573. }
  11574. ed.nodeChanged();
  11575. } else
  11576. performCaretAction('remove', name, vars);
  11577. // 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
  11578. if (tinymce.isWebKit) {
  11579. ed.execCommand('mceCleanup');
  11580. }
  11581. };
  11582. function toggle(name, vars, node) {
  11583. var fmt = get(name);
  11584. if (match(name, vars, node) && (!('toggle' in fmt[0]) || fmt[0]['toggle']))
  11585. remove(name, vars, node);
  11586. else
  11587. apply(name, vars, node);
  11588. };
  11589. function matchNode(node, name, vars, similar) {
  11590. var formatList = get(name), format, i, classes;
  11591. function matchItems(node, format, item_name) {
  11592. var key, value, items = format[item_name], i;
  11593. // Custom match
  11594. if (format.onmatch) {
  11595. return format.onmatch(node, format, item_name);
  11596. }
  11597. // Check all items
  11598. if (items) {
  11599. // Non indexed object
  11600. if (items.length === undefined) {
  11601. for (key in items) {
  11602. if (items.hasOwnProperty(key)) {
  11603. if (item_name === 'attributes')
  11604. value = dom.getAttrib(node, key);
  11605. else
  11606. value = getStyle(node, key);
  11607. if (similar && !value && !format.exact)
  11608. return;
  11609. if ((!similar || format.exact) && !isEq(value, replaceVars(items[key], vars)))
  11610. return;
  11611. }
  11612. }
  11613. } else {
  11614. // Only one match needed for indexed arrays
  11615. for (i = 0; i < items.length; i++) {
  11616. if (item_name === 'attributes' ? dom.getAttrib(node, items[i]) : getStyle(node, items[i]))
  11617. return format;
  11618. }
  11619. }
  11620. }
  11621. return format;
  11622. };
  11623. if (formatList && node) {
  11624. // Check each format in list
  11625. for (i = 0; i < formatList.length; i++) {
  11626. format = formatList[i];
  11627. // Name name, attributes, styles and classes
  11628. if (matchName(node, format) && matchItems(node, format, 'attributes') && matchItems(node, format, 'styles')) {
  11629. // Match classes
  11630. if (classes = format.classes) {
  11631. for (i = 0; i < classes.length; i++) {
  11632. if (!dom.hasClass(node, classes[i]))
  11633. return;
  11634. }
  11635. }
  11636. return format;
  11637. }
  11638. }
  11639. }
  11640. };
  11641. function match(name, vars, node) {
  11642. var startNode;
  11643. function matchParents(node) {
  11644. // Find first node with similar format settings
  11645. node = dom.getParent(node, function(node) {
  11646. return !!matchNode(node, name, vars, true);
  11647. });
  11648. // Do an exact check on the similar format element
  11649. return matchNode(node, name, vars);
  11650. };
  11651. // Check specified node
  11652. if (node)
  11653. return matchParents(node);
  11654. // Check selected node
  11655. node = selection.getNode();
  11656. if (matchParents(node))
  11657. return TRUE;
  11658. // Check start node if it's different
  11659. startNode = selection.getStart();
  11660. if (startNode != node) {
  11661. if (matchParents(startNode))
  11662. return TRUE;
  11663. }
  11664. return FALSE;
  11665. };
  11666. function matchAll(names, vars) {
  11667. var startElement, matchedFormatNames = [], checkedMap = {}, i, ni, name;
  11668. // Check start of selection for formats
  11669. startElement = selection.getStart();
  11670. dom.getParent(startElement, function(node) {
  11671. var i, name;
  11672. for (i = 0; i < names.length; i++) {
  11673. name = names[i];
  11674. if (!checkedMap[name] && matchNode(node, name, vars)) {
  11675. checkedMap[name] = true;
  11676. matchedFormatNames.push(name);
  11677. }
  11678. }
  11679. });
  11680. return matchedFormatNames;
  11681. };
  11682. function canApply(name) {
  11683. var formatList = get(name), startNode, parents, i, x, selector;
  11684. if (formatList) {
  11685. startNode = selection.getStart();
  11686. parents = getParents(startNode);
  11687. for (x = formatList.length - 1; x >= 0; x--) {
  11688. selector = formatList[x].selector;
  11689. // Format is not selector based, then always return TRUE
  11690. if (!selector)
  11691. return TRUE;
  11692. for (i = parents.length - 1; i >= 0; i--) {
  11693. if (dom.is(parents[i], selector))
  11694. return TRUE;
  11695. }
  11696. }
  11697. }
  11698. return FALSE;
  11699. };
  11700. // Expose to public
  11701. tinymce.extend(this, {
  11702. get : get,
  11703. register : register,
  11704. apply : apply,
  11705. remove : remove,
  11706. toggle : toggle,
  11707. match : match,
  11708. matchAll : matchAll,
  11709. matchNode : matchNode,
  11710. canApply : canApply
  11711. });
  11712. // Private functions
  11713. function matchName(node, format) {
  11714. // Check for inline match
  11715. if (isEq(node, format.inline))
  11716. return TRUE;
  11717. // Check for block match
  11718. if (isEq(node, format.block))
  11719. return TRUE;
  11720. // Check for selector match
  11721. if (format.selector)
  11722. return dom.is(node, format.selector);
  11723. };
  11724. function isEq(str1, str2) {
  11725. str1 = str1 || '';
  11726. str2 = str2 || '';
  11727. str1 = '' + (str1.nodeName || str1);
  11728. str2 = '' + (str2.nodeName || str2);
  11729. return str1.toLowerCase() == str2.toLowerCase();
  11730. };
  11731. function getStyle(node, name) {
  11732. var styleVal = dom.getStyle(node, name);
  11733. // Force the format to hex
  11734. if (name == 'color' || name == 'backgroundColor')
  11735. styleVal = dom.toHex(styleVal);
  11736. // Opera will return bold as 700
  11737. if (name == 'fontWeight' && styleVal == 700)
  11738. styleVal = 'bold';
  11739. return '' + styleVal;
  11740. };
  11741. function replaceVars(value, vars) {
  11742. if (typeof(value) != "string")
  11743. value = value(vars);
  11744. else if (vars) {
  11745. value = value.replace(/%(\w+)/g, function(str, name) {
  11746. return vars[name] || str;
  11747. });
  11748. }
  11749. return value;
  11750. };
  11751. function isWhiteSpaceNode(node) {
  11752. return node && node.nodeType === 3 && /^([\t \r\n]+|)$/.test(node.nodeValue);
  11753. };
  11754. function wrap(node, name, attrs) {
  11755. var wrapper = dom.create(name, attrs);
  11756. node.parentNode.insertBefore(wrapper, node);
  11757. wrapper.appendChild(node);
  11758. return wrapper;
  11759. };
  11760. function expandRng(rng, format, remove) {
  11761. var startContainer = rng.startContainer,
  11762. startOffset = rng.startOffset,
  11763. endContainer = rng.endContainer,
  11764. endOffset = rng.endOffset, sibling, lastIdx, leaf, endPoint;
  11765. // This function walks up the tree if there is no siblings before/after the node
  11766. function findParentContainer(start) {
  11767. var container, parent, child, sibling, siblingName;
  11768. container = parent = start ? startContainer : endContainer;
  11769. siblingName = start ? 'previousSibling' : 'nextSibling';
  11770. root = dom.getRoot();
  11771. // If it's a text node and the offset is inside the text
  11772. if (container.nodeType == 3 && !isWhiteSpaceNode(container)) {
  11773. if (start ? startOffset > 0 : endOffset < container.nodeValue.length) {
  11774. return container;
  11775. }
  11776. }
  11777. for (;;) {
  11778. // Stop expanding on block elements or root depending on format
  11779. if (parent == root || (!format[0].block_expand && isBlock(parent)))
  11780. return parent;
  11781. // Walk left/right
  11782. for (sibling = parent[siblingName]; sibling; sibling = sibling[siblingName]) {
  11783. if (!isBookmarkNode(sibling) && !isWhiteSpaceNode(sibling)) {
  11784. return parent;
  11785. }
  11786. }
  11787. // Check if we can move up are we at root level or body level
  11788. parent = parent.parentNode;
  11789. }
  11790. return container;
  11791. };
  11792. // This function walks down the tree to find the leaf at the selection.
  11793. // The offset is also returned as if node initially a leaf, the offset may be in the middle of the text node.
  11794. function findLeaf(node, offset) {
  11795. if (offset === undefined)
  11796. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  11797. while (node && node.hasChildNodes()) {
  11798. node = node.childNodes[offset];
  11799. if (node)
  11800. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  11801. }
  11802. return { node: node, offset: offset };
  11803. }
  11804. // If index based start position then resolve it
  11805. if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) {
  11806. lastIdx = startContainer.childNodes.length - 1;
  11807. startContainer = startContainer.childNodes[startOffset > lastIdx ? lastIdx : startOffset];
  11808. if (startContainer.nodeType == 3)
  11809. startOffset = 0;
  11810. }
  11811. // If index based end position then resolve it
  11812. if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) {
  11813. lastIdx = endContainer.childNodes.length - 1;
  11814. endContainer = endContainer.childNodes[endOffset > lastIdx ? lastIdx : endOffset - 1];
  11815. if (endContainer.nodeType == 3)
  11816. endOffset = endContainer.nodeValue.length;
  11817. }
  11818. // Exclude bookmark nodes if possible
  11819. if (isBookmarkNode(startContainer.parentNode) || isBookmarkNode(startContainer)) {
  11820. startContainer = isBookmarkNode(startContainer) ? startContainer : startContainer.parentNode;
  11821. startContainer = startContainer.nextSibling || startContainer;
  11822. if (startContainer.nodeType == 3)
  11823. startOffset = 0;
  11824. }
  11825. if (isBookmarkNode(endContainer.parentNode) || isBookmarkNode(endContainer)) {
  11826. endContainer = isBookmarkNode(endContainer) ? endContainer : endContainer.parentNode;
  11827. endContainer = endContainer.previousSibling || endContainer;
  11828. if (endContainer.nodeType == 3)
  11829. endOffset = endContainer.length;
  11830. }
  11831. if (format[0].inline) {
  11832. if (rng.collapsed) {
  11833. function findWordEndPoint(container, offset, start) {
  11834. var walker, node, pos, lastTextNode;
  11835. function findSpace(node, offset) {
  11836. var pos, pos2, str = node.nodeValue;
  11837. if (typeof(offset) == "undefined") {
  11838. offset = start ? str.length : 0;
  11839. }
  11840. if (start) {
  11841. pos = str.lastIndexOf(' ', offset);
  11842. pos2 = str.lastIndexOf('\u00a0', offset);
  11843. pos = pos > pos2 ? pos : pos2;
  11844. // Include the space on remove to avoid tag soup
  11845. if (pos !== -1 && !remove) {
  11846. pos++;
  11847. }
  11848. } else {
  11849. pos = str.indexOf(' ', offset);
  11850. pos2 = str.indexOf('\u00a0', offset);
  11851. pos = pos !== -1 && (pos2 === -1 || pos < pos2) ? pos : pos2;
  11852. }
  11853. return pos;
  11854. };
  11855. if (container.nodeType === 3) {
  11856. pos = findSpace(container, offset);
  11857. if (pos !== -1) {
  11858. return {container : container, offset : pos};
  11859. }
  11860. lastTextNode = container;
  11861. }
  11862. // Walk the nodes inside the block
  11863. walker = new TreeWalker(container, dom.getParent(container, isBlock) || ed.getBody());
  11864. while (node = walker[start ? 'prev' : 'next']()) {
  11865. if (node.nodeType === 3) {
  11866. lastTextNode = node;
  11867. pos = findSpace(node);
  11868. if (pos !== -1) {
  11869. return {container : node, offset : pos};
  11870. }
  11871. } else if (isBlock(node)) {
  11872. break;
  11873. }
  11874. }
  11875. if (lastTextNode) {
  11876. if (start) {
  11877. offset = 0;
  11878. } else {
  11879. offset = lastTextNode.length;
  11880. }
  11881. return {container: lastTextNode, offset: offset};
  11882. }
  11883. }
  11884. // Expand left to closest word boundery
  11885. endPoint = findWordEndPoint(startContainer, startOffset, true);
  11886. if (endPoint) {
  11887. startContainer = endPoint.container;
  11888. startOffset = endPoint.offset;
  11889. }
  11890. // Expand right to closest word boundery
  11891. endPoint = findWordEndPoint(endContainer, endOffset);
  11892. if (endPoint) {
  11893. endContainer = endPoint.container;
  11894. endOffset = endPoint.offset;
  11895. }
  11896. }
  11897. // Avoid applying formatting to a trailing space.
  11898. leaf = findLeaf(endContainer, endOffset);
  11899. if (leaf.node) {
  11900. while (leaf.node && leaf.offset === 0 && leaf.node.previousSibling)
  11901. leaf = findLeaf(leaf.node.previousSibling);
  11902. if (leaf.node && leaf.offset > 0 && leaf.node.nodeType === 3 &&
  11903. leaf.node.nodeValue.charAt(leaf.offset - 1) === ' ') {
  11904. if (leaf.offset > 1) {
  11905. endContainer = leaf.node;
  11906. endContainer.splitText(leaf.offset - 1);
  11907. } else if (leaf.node.previousSibling) {
  11908. // TODO: Figure out why this is in here
  11909. //endContainer = leaf.node.previousSibling;
  11910. }
  11911. }
  11912. }
  11913. }
  11914. // Move start/end point up the tree if the leaves are sharp and if we are in different containers
  11915. // Example * becomes !: !<p><b><i>*text</i><i>text*</i></b></p>!
  11916. // This will reduce the number of wrapper elements that needs to be created
  11917. // Move start point up the tree
  11918. if (format[0].inline || format[0].block_expand) {
  11919. if (!format[0].inline || (startContainer.nodeType != 3 || startOffset === 0)) {
  11920. startContainer = findParentContainer(true);
  11921. }
  11922. if (!format[0].inline || (endContainer.nodeType != 3 || endOffset === endContainer.nodeValue.length)) {
  11923. endContainer = findParentContainer();
  11924. }
  11925. }
  11926. // Expand start/end container to matching selector
  11927. if (format[0].selector && format[0].expand !== FALSE && !format[0].inline) {
  11928. function findSelectorEndPoint(container, sibling_name) {
  11929. var parents, i, y, curFormat;
  11930. if (container.nodeType == 3 && container.nodeValue.length == 0 && container[sibling_name])
  11931. container = container[sibling_name];
  11932. parents = getParents(container);
  11933. for (i = 0; i < parents.length; i++) {
  11934. for (y = 0; y < format.length; y++) {
  11935. curFormat = format[y];
  11936. // If collapsed state is set then skip formats that doesn't match that
  11937. if ("collapsed" in curFormat && curFormat.collapsed !== rng.collapsed)
  11938. continue;
  11939. if (dom.is(parents[i], curFormat.selector))
  11940. return parents[i];
  11941. }
  11942. }
  11943. return container;
  11944. };
  11945. // Find new startContainer/endContainer if there is better one
  11946. startContainer = findSelectorEndPoint(startContainer, 'previousSibling');
  11947. endContainer = findSelectorEndPoint(endContainer, 'nextSibling');
  11948. }
  11949. // Expand start/end container to matching block element or text node
  11950. if (format[0].block || format[0].selector) {
  11951. function findBlockEndPoint(container, sibling_name, sibling_name2) {
  11952. var node;
  11953. // Expand to block of similar type
  11954. if (!format[0].wrapper)
  11955. node = dom.getParent(container, format[0].block);
  11956. // Expand to first wrappable block element or any block element
  11957. if (!node)
  11958. node = dom.getParent(container.nodeType == 3 ? container.parentNode : container, isBlock);
  11959. // Exclude inner lists from wrapping
  11960. if (node && format[0].wrapper)
  11961. node = getParents(node, 'ul,ol').reverse()[0] || node;
  11962. // Didn't find a block element look for first/last wrappable element
  11963. if (!node) {
  11964. node = container;
  11965. while (node[sibling_name] && !isBlock(node[sibling_name])) {
  11966. node = node[sibling_name];
  11967. // Break on BR but include it will be removed later on
  11968. // we can't remove it now since we need to check if it can be wrapped
  11969. if (isEq(node, 'br'))
  11970. break;
  11971. }
  11972. }
  11973. return node || container;
  11974. };
  11975. // Find new startContainer/endContainer if there is better one
  11976. startContainer = findBlockEndPoint(startContainer, 'previousSibling');
  11977. endContainer = findBlockEndPoint(endContainer, 'nextSibling');
  11978. // Non block element then try to expand up the leaf
  11979. if (format[0].block) {
  11980. if (!isBlock(startContainer))
  11981. startContainer = findParentContainer(true);
  11982. if (!isBlock(endContainer))
  11983. endContainer = findParentContainer();
  11984. }
  11985. }
  11986. // Setup index for startContainer
  11987. if (startContainer.nodeType == 1) {
  11988. startOffset = nodeIndex(startContainer);
  11989. startContainer = startContainer.parentNode;
  11990. }
  11991. // Setup index for endContainer
  11992. if (endContainer.nodeType == 1) {
  11993. endOffset = nodeIndex(endContainer) + 1;
  11994. endContainer = endContainer.parentNode;
  11995. }
  11996. // Return new range like object
  11997. return {
  11998. startContainer : startContainer,
  11999. startOffset : startOffset,
  12000. endContainer : endContainer,
  12001. endOffset : endOffset
  12002. };
  12003. }
  12004. function removeFormat(format, vars, node, compare_node) {
  12005. var i, attrs, stylesModified;
  12006. // Check if node matches format
  12007. if (!matchName(node, format))
  12008. return FALSE;
  12009. // Should we compare with format attribs and styles
  12010. if (format.remove != 'all') {
  12011. // Remove styles
  12012. each(format.styles, function(value, name) {
  12013. value = replaceVars(value, vars);
  12014. // Indexed array
  12015. if (typeof(name) === 'number') {
  12016. name = value;
  12017. compare_node = 0;
  12018. }
  12019. if (!compare_node || isEq(getStyle(compare_node, name), value))
  12020. dom.setStyle(node, name, '');
  12021. stylesModified = 1;
  12022. });
  12023. // Remove style attribute if it's empty
  12024. if (stylesModified && dom.getAttrib(node, 'style') == '') {
  12025. node.removeAttribute('style');
  12026. node.removeAttribute('data-mce-style');
  12027. }
  12028. // Remove attributes
  12029. each(format.attributes, function(value, name) {
  12030. var valueOut;
  12031. value = replaceVars(value, vars);
  12032. // Indexed array
  12033. if (typeof(name) === 'number') {
  12034. name = value;
  12035. compare_node = 0;
  12036. }
  12037. if (!compare_node || isEq(dom.getAttrib(compare_node, name), value)) {
  12038. // Keep internal classes
  12039. if (name == 'class') {
  12040. value = dom.getAttrib(node, name);
  12041. if (value) {
  12042. // Build new class value where everything is removed except the internal prefixed classes
  12043. valueOut = '';
  12044. each(value.split(/\s+/), function(cls) {
  12045. if (/mce\w+/.test(cls))
  12046. valueOut += (valueOut ? ' ' : '') + cls;
  12047. });
  12048. // We got some internal classes left
  12049. if (valueOut) {
  12050. dom.setAttrib(node, name, valueOut);
  12051. return;
  12052. }
  12053. }
  12054. }
  12055. // IE6 has a bug where the attribute doesn't get removed correctly
  12056. if (name == "class")
  12057. node.removeAttribute('className');
  12058. // Remove mce prefixed attributes
  12059. if (MCE_ATTR_RE.test(name))
  12060. node.removeAttribute('data-mce-' + name);
  12061. node.removeAttribute(name);
  12062. }
  12063. });
  12064. // Remove classes
  12065. each(format.classes, function(value) {
  12066. value = replaceVars(value, vars);
  12067. if (!compare_node || dom.hasClass(compare_node, value))
  12068. dom.removeClass(node, value);
  12069. });
  12070. // Check for non internal attributes
  12071. attrs = dom.getAttribs(node);
  12072. for (i = 0; i < attrs.length; i++) {
  12073. if (attrs[i].nodeName.indexOf('_') !== 0)
  12074. return FALSE;
  12075. }
  12076. }
  12077. // Remove the inline child if it's empty for example <b> or <span>
  12078. if (format.remove != 'none') {
  12079. removeNode(node, format);
  12080. return TRUE;
  12081. }
  12082. };
  12083. function removeNode(node, format) {
  12084. var parentNode = node.parentNode, rootBlockElm;
  12085. if (format.block) {
  12086. if (!forcedRootBlock) {
  12087. function find(node, next, inc) {
  12088. node = getNonWhiteSpaceSibling(node, next, inc);
  12089. return !node || (node.nodeName == 'BR' || isBlock(node));
  12090. };
  12091. // Append BR elements if needed before we remove the block
  12092. if (isBlock(node) && !isBlock(parentNode)) {
  12093. if (!find(node, FALSE) && !find(node.firstChild, TRUE, 1))
  12094. node.insertBefore(dom.create('br'), node.firstChild);
  12095. if (!find(node, TRUE) && !find(node.lastChild, FALSE, 1))
  12096. node.appendChild(dom.create('br'));
  12097. }
  12098. } else {
  12099. // Wrap the block in a forcedRootBlock if we are at the root of document
  12100. if (parentNode == dom.getRoot()) {
  12101. if (!format.list_block || !isEq(node, format.list_block)) {
  12102. each(tinymce.grep(node.childNodes), function(node) {
  12103. if (isValid(forcedRootBlock, node.nodeName.toLowerCase())) {
  12104. if (!rootBlockElm)
  12105. rootBlockElm = wrap(node, forcedRootBlock);
  12106. else
  12107. rootBlockElm.appendChild(node);
  12108. } else
  12109. rootBlockElm = 0;
  12110. });
  12111. }
  12112. }
  12113. }
  12114. }
  12115. // Never remove nodes that isn't the specified inline element if a selector is specified too
  12116. if (format.selector && format.inline && !isEq(format.inline, node))
  12117. return;
  12118. dom.remove(node, 1);
  12119. };
  12120. function getNonWhiteSpaceSibling(node, next, inc) {
  12121. if (node) {
  12122. next = next ? 'nextSibling' : 'previousSibling';
  12123. for (node = inc ? node : node[next]; node; node = node[next]) {
  12124. if (node.nodeType == 1 || !isWhiteSpaceNode(node))
  12125. return node;
  12126. }
  12127. }
  12128. };
  12129. function isBookmarkNode(node) {
  12130. return node && node.nodeType == 1 && node.getAttribute('data-mce-type') == 'bookmark';
  12131. };
  12132. function mergeSiblings(prev, next) {
  12133. var marker, sibling, tmpSibling;
  12134. function compareElements(node1, node2) {
  12135. // Not the same name
  12136. if (node1.nodeName != node2.nodeName)
  12137. return FALSE;
  12138. function getAttribs(node) {
  12139. var attribs = {};
  12140. each(dom.getAttribs(node), function(attr) {
  12141. var name = attr.nodeName.toLowerCase();
  12142. // Don't compare internal attributes or style
  12143. if (name.indexOf('_') !== 0 && name !== 'style')
  12144. attribs[name] = dom.getAttrib(node, name);
  12145. });
  12146. return attribs;
  12147. };
  12148. function compareObjects(obj1, obj2) {
  12149. var value, name;
  12150. for (name in obj1) {
  12151. // Obj1 has item obj2 doesn't have
  12152. if (obj1.hasOwnProperty(name)) {
  12153. value = obj2[name];
  12154. // Obj2 doesn't have obj1 item
  12155. if (value === undefined)
  12156. return FALSE;
  12157. // Obj2 item has a different value
  12158. if (obj1[name] != value)
  12159. return FALSE;
  12160. // Delete similar value
  12161. delete obj2[name];
  12162. }
  12163. }
  12164. // Check if obj 2 has something obj 1 doesn't have
  12165. for (name in obj2) {
  12166. // Obj2 has item obj1 doesn't have
  12167. if (obj2.hasOwnProperty(name))
  12168. return FALSE;
  12169. }
  12170. return TRUE;
  12171. };
  12172. // Attribs are not the same
  12173. if (!compareObjects(getAttribs(node1), getAttribs(node2)))
  12174. return FALSE;
  12175. // Styles are not the same
  12176. if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style'))))
  12177. return FALSE;
  12178. return TRUE;
  12179. };
  12180. // Check if next/prev exists and that they are elements
  12181. if (prev && next) {
  12182. function findElementSibling(node, sibling_name) {
  12183. for (sibling = node; sibling; sibling = sibling[sibling_name]) {
  12184. if (sibling.nodeType == 3 && sibling.nodeValue.length !== 0)
  12185. return node;
  12186. if (sibling.nodeType == 1 && !isBookmarkNode(sibling))
  12187. return sibling;
  12188. }
  12189. return node;
  12190. };
  12191. // If previous sibling is empty then jump over it
  12192. prev = findElementSibling(prev, 'previousSibling');
  12193. next = findElementSibling(next, 'nextSibling');
  12194. // Compare next and previous nodes
  12195. if (compareElements(prev, next)) {
  12196. // Append nodes between
  12197. for (sibling = prev.nextSibling; sibling && sibling != next;) {
  12198. tmpSibling = sibling;
  12199. sibling = sibling.nextSibling;
  12200. prev.appendChild(tmpSibling);
  12201. }
  12202. // Remove next node
  12203. dom.remove(next);
  12204. // Move children into prev node
  12205. each(tinymce.grep(next.childNodes), function(node) {
  12206. prev.appendChild(node);
  12207. });
  12208. return prev;
  12209. }
  12210. }
  12211. return next;
  12212. };
  12213. function isTextBlock(name) {
  12214. return /^(h[1-6]|p|div|pre|address|dl|dt|dd)$/.test(name);
  12215. };
  12216. function getContainer(rng, start) {
  12217. var container, offset, lastIdx, walker;
  12218. container = rng[start ? 'startContainer' : 'endContainer'];
  12219. offset = rng[start ? 'startOffset' : 'endOffset'];
  12220. if (container.nodeType == 1) {
  12221. lastIdx = container.childNodes.length - 1;
  12222. if (!start && offset)
  12223. offset--;
  12224. container = container.childNodes[offset > lastIdx ? lastIdx : offset];
  12225. }
  12226. // If start text node is excluded then walk to the next node
  12227. if (container.nodeType === 3 && start && offset >= container.nodeValue.length) {
  12228. container = new TreeWalker(container, ed.getBody()).next() || container;
  12229. }
  12230. // If end text node is excluded then walk to the previous node
  12231. if (container.nodeType === 3 && !start && offset == 0) {
  12232. container = new TreeWalker(container, ed.getBody()).prev() || container;
  12233. }
  12234. return container;
  12235. };
  12236. function performCaretAction(type, name, vars) {
  12237. var invisibleChar, caretContainerId = '_mce_caret', debug = ed.settings.caret_debug;
  12238. // Setup invisible character use zero width space on Gecko since it doesn't change the heigt of the container
  12239. invisibleChar = tinymce.isGecko ? '\u200B' : INVISIBLE_CHAR;
  12240. // Creates a caret container bogus element
  12241. function createCaretContainer(fill) {
  12242. var caretContainer = dom.create('span', {id: caretContainerId, 'data-mce-bogus': true, style: debug ? 'color:red' : ''});
  12243. if (fill) {
  12244. caretContainer.appendChild(ed.getDoc().createTextNode(invisibleChar));
  12245. }
  12246. return caretContainer;
  12247. };
  12248. function isCaretContainerEmpty(node, nodes) {
  12249. while (node) {
  12250. if ((node.nodeType === 3 && node.nodeValue !== invisibleChar) || node.childNodes.length > 1) {
  12251. return false;
  12252. }
  12253. // Collect nodes
  12254. if (nodes && node.nodeType === 1) {
  12255. nodes.push(node);
  12256. }
  12257. node = node.firstChild;
  12258. }
  12259. return true;
  12260. };
  12261. // Returns any parent caret container element
  12262. function getParentCaretContainer(node) {
  12263. while (node) {
  12264. if (node.id === caretContainerId) {
  12265. return node;
  12266. }
  12267. node = node.parentNode;
  12268. }
  12269. };
  12270. // Finds the first text node in the specified node
  12271. function findFirstTextNode(node) {
  12272. var walker;
  12273. if (node) {
  12274. walker = new TreeWalker(node, node);
  12275. for (node = walker.current(); node; node = walker.next()) {
  12276. if (node.nodeType === 3) {
  12277. return node;
  12278. }
  12279. }
  12280. }
  12281. };
  12282. // Removes the caret container for the specified node or all on the current document
  12283. function removeCaretContainer(node, move_caret) {
  12284. var child, rng;
  12285. if (!node) {
  12286. node = getParentCaretContainer(selection.getStart());
  12287. if (!node) {
  12288. while (node = dom.get(caretContainerId)) {
  12289. removeCaretContainer(node, false);
  12290. }
  12291. }
  12292. } else {
  12293. rng = selection.getRng(true);
  12294. if (isCaretContainerEmpty(node)) {
  12295. if (move_caret !== false) {
  12296. rng.setStartBefore(node);
  12297. rng.setEndBefore(node);
  12298. }
  12299. dom.remove(node);
  12300. } else {
  12301. child = findFirstTextNode(node);
  12302. child = child.deleteData(0, 1);
  12303. dom.remove(node, 1);
  12304. }
  12305. selection.setRng(rng);
  12306. }
  12307. };
  12308. // Applies formatting to the caret postion
  12309. function applyCaretFormat() {
  12310. var rng, caretContainer, textNode, offset, bookmark, container, text;
  12311. rng = selection.getRng(true);
  12312. offset = rng.startOffset;
  12313. container = rng.startContainer;
  12314. text = container.nodeValue;
  12315. caretContainer = getParentCaretContainer(selection.getStart());
  12316. if (caretContainer) {
  12317. textNode = findFirstTextNode(caretContainer);
  12318. }
  12319. // Expand to word is caret is in the middle of a text node and the char before/after is a alpha numeric character
  12320. if (text && offset > 0 && offset < text.length && /\w/.test(text.charAt(offset)) && /\w/.test(text.charAt(offset - 1))) {
  12321. // Get bookmark of caret position
  12322. bookmark = selection.getBookmark();
  12323. // Collapse bookmark range (WebKit)
  12324. rng.collapse(true);
  12325. // Expand the range to the closest word and split it at those points
  12326. rng = expandRng(rng, get(name));
  12327. rng = rangeUtils.split(rng);
  12328. // Apply the format to the range
  12329. apply(name, vars, rng);
  12330. // Move selection back to caret position
  12331. selection.moveToBookmark(bookmark);
  12332. } else {
  12333. if (!caretContainer || textNode.nodeValue !== invisibleChar) {
  12334. caretContainer = createCaretContainer(true);
  12335. textNode = caretContainer.firstChild;
  12336. rng.insertNode(caretContainer);
  12337. offset = 1;
  12338. apply(name, vars, caretContainer);
  12339. } else {
  12340. apply(name, vars, caretContainer);
  12341. }
  12342. // Move selection to text node
  12343. selection.setCursorLocation(textNode, offset);
  12344. }
  12345. };
  12346. function removeCaretFormat() {
  12347. var rng = selection.getRng(true), container, offset, bookmark,
  12348. hasContentAfter, node, formatNode, parents = [], i, caretContainer;
  12349. container = rng.startContainer;
  12350. offset = rng.startOffset;
  12351. node = container;
  12352. if (container.nodeType == 3) {
  12353. if (offset != container.nodeValue.length || container.nodeValue === invisibleChar) {
  12354. hasContentAfter = true;
  12355. }
  12356. node = node.parentNode;
  12357. }
  12358. while (node) {
  12359. if (matchNode(node, name, vars)) {
  12360. formatNode = node;
  12361. break;
  12362. }
  12363. if (node.nextSibling) {
  12364. hasContentAfter = true;
  12365. }
  12366. parents.push(node);
  12367. node = node.parentNode;
  12368. }
  12369. // Node doesn't have the specified format
  12370. if (!formatNode) {
  12371. return;
  12372. }
  12373. // Is there contents after the caret then remove the format on the element
  12374. if (hasContentAfter) {
  12375. // Get bookmark of caret position
  12376. bookmark = selection.getBookmark();
  12377. // Collapse bookmark range (WebKit)
  12378. rng.collapse(true);
  12379. // Expand the range to the closest word and split it at those points
  12380. rng = expandRng(rng, get(name), true);
  12381. rng = rangeUtils.split(rng);
  12382. // Remove the format from the range
  12383. remove(name, vars, rng);
  12384. // Move selection back to caret position
  12385. selection.moveToBookmark(bookmark);
  12386. } else {
  12387. caretContainer = createCaretContainer();
  12388. node = caretContainer;
  12389. for (i = parents.length - 1; i >= 0; i--) {
  12390. node.appendChild(parents[i].cloneNode(false));
  12391. node = node.firstChild;
  12392. }
  12393. // Insert invisible character into inner most format element
  12394. node.appendChild(dom.doc.createTextNode(invisibleChar));
  12395. node = node.firstChild;
  12396. // Insert caret container after the formated node
  12397. dom.insertAfter(caretContainer, formatNode);
  12398. // Move selection to text node
  12399. selection.setCursorLocation(node, 1);
  12400. }
  12401. };
  12402. // Mark current caret container elements as bogus when getting the contents so we don't end up with empty elements
  12403. ed.onBeforeGetContent.addToTop(function() {
  12404. var nodes = [], i;
  12405. if (isCaretContainerEmpty(getParentCaretContainer(selection.getStart()), nodes)) {
  12406. // Mark children
  12407. i = nodes.length;
  12408. while (i--) {
  12409. dom.setAttrib(nodes[i], 'data-mce-bogus', '1');
  12410. }
  12411. }
  12412. });
  12413. // Remove caret container on mouse up and on key up
  12414. tinymce.each('onMouseUp onKeyUp'.split(' '), function(name) {
  12415. ed[name].addToTop(function() {
  12416. removeCaretContainer();
  12417. });
  12418. });
  12419. // Remove caret container on keydown and it's a backspace, enter or left/right arrow keys
  12420. ed.onKeyDown.addToTop(function(ed, e) {
  12421. var keyCode = e.keyCode;
  12422. if (keyCode == 8 || keyCode == 37 || keyCode == 39) {
  12423. removeCaretContainer(getParentCaretContainer(selection.getStart()));
  12424. }
  12425. });
  12426. // Do apply or remove caret format
  12427. if (type == "apply") {
  12428. applyCaretFormat();
  12429. } else {
  12430. removeCaretFormat();
  12431. }
  12432. };
  12433. };
  12434. })(tinymce);
  12435. tinymce.onAddEditor.add(function(tinymce, ed) {
  12436. var filters, fontSizes, dom, settings = ed.settings;
  12437. if (settings.inline_styles) {
  12438. fontSizes = tinymce.explode(settings.font_size_legacy_values);
  12439. function replaceWithSpan(node, styles) {
  12440. tinymce.each(styles, function(value, name) {
  12441. if (value)
  12442. dom.setStyle(node, name, value);
  12443. });
  12444. dom.rename(node, 'span');
  12445. };
  12446. filters = {
  12447. font : function(dom, node) {
  12448. replaceWithSpan(node, {
  12449. backgroundColor : node.style.backgroundColor,
  12450. color : node.color,
  12451. fontFamily : node.face,
  12452. fontSize : fontSizes[parseInt(node.size) - 1]
  12453. });
  12454. },
  12455. u : function(dom, node) {
  12456. replaceWithSpan(node, {
  12457. textDecoration : 'underline'
  12458. });
  12459. },
  12460. strike : function(dom, node) {
  12461. replaceWithSpan(node, {
  12462. textDecoration : 'line-through'
  12463. });
  12464. }
  12465. };
  12466. function convert(editor, params) {
  12467. dom = editor.dom;
  12468. if (settings.convert_fonts_to_spans) {
  12469. tinymce.each(dom.select('font,u,strike', params.node), function(node) {
  12470. filters[node.nodeName.toLowerCase()](ed.dom, node);
  12471. });
  12472. }
  12473. };
  12474. ed.onPreProcess.add(convert);
  12475. ed.onSetContent.add(convert);
  12476. ed.onInit.add(function() {
  12477. ed.selection.onSetContent.add(convert);
  12478. });
  12479. }
  12480. });