1
0

tiny_mce_src.js 480 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811
  1. // FILE IS GENERATED BY COMBINING THE SOURCES IN THE "classes" DIRECTORY SO DON'T MODIFY THIS FILE DIRECTLY
  2. (function(win) {
  3. var whiteSpaceRe = /^\s*|\s*$/g,
  4. undef, isRegExpBroken = 'B'.replace(/A(.)|B/, '$1') === '$1';
  5. var tinymce = {
  6. majorVersion : '3',
  7. minorVersion : '5.8',
  8. releaseDate : '2012-11-20',
  9. _init : function() {
  10. var t = this, d = document, na = navigator, ua = na.userAgent, i, nl, n, base, p, v;
  11. t.isOpera = win.opera && opera.buildNumber;
  12. t.isWebKit = /WebKit/.test(ua);
  13. t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName);
  14. t.isIE6 = t.isIE && /MSIE [56]/.test(ua);
  15. t.isIE7 = t.isIE && /MSIE [7]/.test(ua);
  16. t.isIE8 = t.isIE && /MSIE [8]/.test(ua);
  17. t.isIE9 = t.isIE && /MSIE [9]/.test(ua);
  18. t.isGecko = !t.isWebKit && /Gecko/.test(ua);
  19. t.isMac = ua.indexOf('Mac') != -1;
  20. t.isAir = /adobeair/i.test(ua);
  21. t.isIDevice = /(iPad|iPhone)/.test(ua);
  22. t.isIOS5 = t.isIDevice && ua.match(/AppleWebKit\/(\d*)/)[1]>=534;
  23. // TinyMCE .NET webcontrol might be setting the values for TinyMCE
  24. if (win.tinyMCEPreInit) {
  25. t.suffix = tinyMCEPreInit.suffix;
  26. t.baseURL = tinyMCEPreInit.base;
  27. t.query = tinyMCEPreInit.query;
  28. return;
  29. }
  30. // Get suffix and base
  31. t.suffix = '';
  32. // If base element found, add that infront of baseURL
  33. nl = d.getElementsByTagName('base');
  34. for (i=0; i<nl.length; i++) {
  35. v = nl[i].href;
  36. if (v) {
  37. // Host only value like http://site.com or http://site.com:8008
  38. if (/^https?:\/\/[^\/]+$/.test(v))
  39. v += '/';
  40. base = v ? v.match(/.*\//)[0] : ''; // Get only directory
  41. }
  42. }
  43. function getBase(n) {
  44. if (n.src && /tiny_mce(|_gzip|_jquery|_prototype|_full)(_dev|_src)?.js/.test(n.src)) {
  45. if (/_(src|dev)\.js/g.test(n.src))
  46. t.suffix = '_src';
  47. if ((p = n.src.indexOf('?')) != -1)
  48. t.query = n.src.substring(p + 1);
  49. t.baseURL = n.src.substring(0, n.src.lastIndexOf('/'));
  50. // If path to script is relative and a base href was found add that one infront
  51. // the src property will always be an absolute one on non IE browsers and IE 8
  52. // so this logic will basically only be executed on older IE versions
  53. if (base && t.baseURL.indexOf('://') == -1 && t.baseURL.indexOf('/') !== 0)
  54. t.baseURL = base + t.baseURL;
  55. return t.baseURL;
  56. }
  57. return null;
  58. };
  59. // Check document
  60. nl = d.getElementsByTagName('script');
  61. for (i=0; i<nl.length; i++) {
  62. if (getBase(nl[i]))
  63. return;
  64. }
  65. // Check head
  66. n = d.getElementsByTagName('head')[0];
  67. if (n) {
  68. nl = n.getElementsByTagName('script');
  69. for (i=0; i<nl.length; i++) {
  70. if (getBase(nl[i]))
  71. return;
  72. }
  73. }
  74. return;
  75. },
  76. is : function(o, t) {
  77. if (!t)
  78. return o !== undef;
  79. if (t == 'array' && tinymce.isArray(o))
  80. return true;
  81. return typeof(o) == t;
  82. },
  83. isArray: Array.isArray || function(obj) {
  84. return Object.prototype.toString.call(obj) === "[object Array]";
  85. },
  86. makeMap : function(items, delim, map) {
  87. var i;
  88. items = items || [];
  89. delim = delim || ',';
  90. if (typeof(items) == "string")
  91. items = items.split(delim);
  92. map = map || {};
  93. i = items.length;
  94. while (i--)
  95. map[items[i]] = {};
  96. return map;
  97. },
  98. each : function(o, cb, s) {
  99. var n, l;
  100. if (!o)
  101. return 0;
  102. s = s || o;
  103. if (o.length !== undef) {
  104. // Indexed arrays, needed for Safari
  105. for (n=0, l = o.length; n < l; n++) {
  106. if (cb.call(s, o[n], n, o) === false)
  107. return 0;
  108. }
  109. } else {
  110. // Hashtables
  111. for (n in o) {
  112. if (o.hasOwnProperty(n)) {
  113. if (cb.call(s, o[n], n, o) === false)
  114. return 0;
  115. }
  116. }
  117. }
  118. return 1;
  119. },
  120. trim : function(s) {
  121. return (s ? '' + s : '').replace(whiteSpaceRe, '');
  122. },
  123. create : function(s, p, root) {
  124. var t = this, sp, ns, cn, scn, c, de = 0;
  125. // Parse : <prefix> <class>:<super class>
  126. s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s);
  127. cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name
  128. // Create namespace for new class
  129. ns = t.createNS(s[3].replace(/\.\w+$/, ''), root);
  130. // Class already exists
  131. if (ns[cn])
  132. return;
  133. // Make pure static class
  134. if (s[2] == 'static') {
  135. ns[cn] = p;
  136. if (this.onCreate)
  137. this.onCreate(s[2], s[3], ns[cn]);
  138. return;
  139. }
  140. // Create default constructor
  141. if (!p[cn]) {
  142. p[cn] = function() {};
  143. de = 1;
  144. }
  145. // Add constructor and methods
  146. ns[cn] = p[cn];
  147. t.extend(ns[cn].prototype, p);
  148. // Extend
  149. if (s[5]) {
  150. sp = t.resolve(s[5]).prototype;
  151. scn = s[5].match(/\.(\w+)$/i)[1]; // Class name
  152. // Extend constructor
  153. c = ns[cn];
  154. if (de) {
  155. // Add passthrough constructor
  156. ns[cn] = function() {
  157. return sp[scn].apply(this, arguments);
  158. };
  159. } else {
  160. // Add inherit constructor
  161. ns[cn] = function() {
  162. this.parent = sp[scn];
  163. return c.apply(this, arguments);
  164. };
  165. }
  166. ns[cn].prototype[cn] = ns[cn];
  167. // Add super methods
  168. t.each(sp, function(f, n) {
  169. ns[cn].prototype[n] = sp[n];
  170. });
  171. // Add overridden methods
  172. t.each(p, function(f, n) {
  173. // Extend methods if needed
  174. if (sp[n]) {
  175. ns[cn].prototype[n] = function() {
  176. this.parent = sp[n];
  177. return f.apply(this, arguments);
  178. };
  179. } else {
  180. if (n != cn)
  181. ns[cn].prototype[n] = f;
  182. }
  183. });
  184. }
  185. // Add static methods
  186. t.each(p['static'], function(f, n) {
  187. ns[cn][n] = f;
  188. });
  189. if (this.onCreate)
  190. this.onCreate(s[2], s[3], ns[cn].prototype);
  191. },
  192. walk : function(o, f, n, s) {
  193. s = s || this;
  194. if (o) {
  195. if (n)
  196. o = o[n];
  197. tinymce.each(o, function(o, i) {
  198. if (f.call(s, o, i, n) === false)
  199. return false;
  200. tinymce.walk(o, f, n, s);
  201. });
  202. }
  203. },
  204. createNS : function(n, o) {
  205. var i, v;
  206. o = o || win;
  207. n = n.split('.');
  208. for (i=0; i<n.length; i++) {
  209. v = n[i];
  210. if (!o[v])
  211. o[v] = {};
  212. o = o[v];
  213. }
  214. return o;
  215. },
  216. resolve : function(n, o) {
  217. var i, l;
  218. o = o || win;
  219. n = n.split('.');
  220. for (i = 0, l = n.length; i < l; i++) {
  221. o = o[n[i]];
  222. if (!o)
  223. break;
  224. }
  225. return o;
  226. },
  227. addUnload : function(f, s) {
  228. var t = this, unload;
  229. unload = function() {
  230. var li = t.unloads, o, n;
  231. if (li) {
  232. // Call unload handlers
  233. for (n in li) {
  234. o = li[n];
  235. if (o && o.func)
  236. o.func.call(o.scope, 1); // Send in one arg to distinct unload and user destroy
  237. }
  238. // Detach unload function
  239. if (win.detachEvent) {
  240. win.detachEvent('onbeforeunload', fakeUnload);
  241. win.detachEvent('onunload', unload);
  242. } else if (win.removeEventListener)
  243. win.removeEventListener('unload', unload, false);
  244. // Destroy references
  245. t.unloads = o = li = w = unload = 0;
  246. // Run garbarge collector on IE
  247. if (win.CollectGarbage)
  248. CollectGarbage();
  249. }
  250. };
  251. function fakeUnload() {
  252. var d = document;
  253. function stop() {
  254. // Prevent memory leak
  255. d.detachEvent('onstop', stop);
  256. // Call unload handler
  257. if (unload)
  258. unload();
  259. d = 0;
  260. };
  261. // Is there things still loading, then do some magic
  262. if (d.readyState == 'interactive') {
  263. // Fire unload when the currently loading page is stopped
  264. if (d)
  265. d.attachEvent('onstop', stop);
  266. // Remove onstop listener after a while to prevent the unload function
  267. // to execute if the user presses cancel in an onbeforeunload
  268. // confirm dialog and then presses the browser stop button
  269. win.setTimeout(function() {
  270. if (d)
  271. d.detachEvent('onstop', stop);
  272. }, 0);
  273. }
  274. };
  275. f = {func : f, scope : s || this};
  276. if (!t.unloads) {
  277. // Attach unload handler
  278. if (win.attachEvent) {
  279. win.attachEvent('onunload', unload);
  280. win.attachEvent('onbeforeunload', fakeUnload);
  281. } else if (win.addEventListener)
  282. win.addEventListener('unload', unload, false);
  283. // Setup initial unload handler array
  284. t.unloads = [f];
  285. } else
  286. t.unloads.push(f);
  287. return f;
  288. },
  289. removeUnload : function(f) {
  290. var u = this.unloads, r = null;
  291. tinymce.each(u, function(o, i) {
  292. if (o && o.func == f) {
  293. u.splice(i, 1);
  294. r = f;
  295. return false;
  296. }
  297. });
  298. return r;
  299. },
  300. explode : function(s, d) {
  301. if (!s || tinymce.is(s, 'array')) {
  302. return s;
  303. }
  304. return tinymce.map(s.split(d || ','), tinymce.trim);
  305. },
  306. _addVer : function(u) {
  307. var v;
  308. if (!this.query)
  309. return u;
  310. v = (u.indexOf('?') == -1 ? '?' : '&') + this.query;
  311. if (u.indexOf('#') == -1)
  312. return u + v;
  313. return u.replace('#', v + '#');
  314. },
  315. // Fix function for IE 9 where regexps isn't working correctly
  316. // Todo: remove me once MS fixes the bug
  317. _replace : function(find, replace, str) {
  318. // On IE9 we have to fake $x replacement
  319. if (isRegExpBroken) {
  320. return str.replace(find, function() {
  321. var val = replace, args = arguments, i;
  322. for (i = 0; i < args.length - 2; i++) {
  323. if (args[i] === undef) {
  324. val = val.replace(new RegExp('\\$' + i, 'g'), '');
  325. } else {
  326. val = val.replace(new RegExp('\\$' + i, 'g'), args[i]);
  327. }
  328. }
  329. return val;
  330. });
  331. }
  332. return str.replace(find, replace);
  333. }
  334. };
  335. // Initialize the API
  336. tinymce._init();
  337. // Expose tinymce namespace to the global namespace (window)
  338. win.tinymce = win.tinyMCE = tinymce;
  339. // Describe the different namespaces
  340. })(window);
  341. (function($, tinymce) {
  342. var is = tinymce.is, attrRegExp = /^(href|src|style)$/i, undef;
  343. // jQuery is undefined
  344. if (!$ && window.console) {
  345. return console.log("Load jQuery first!");
  346. }
  347. // Stick jQuery into the tinymce namespace
  348. tinymce.$ = $;
  349. // Setup adapter
  350. tinymce.adapter = {
  351. patchEditor : function(editor) {
  352. var fn = $.fn;
  353. // Adapt the css function to make sure that the data-mce-style
  354. // attribute gets updated with the new style information
  355. function css(name, value) {
  356. var self = this;
  357. // Remove data-mce-style when set operation occurs
  358. if (value)
  359. self.removeAttr('data-mce-style');
  360. return fn.css.apply(self, arguments);
  361. };
  362. // Apapt the attr function to make sure that it uses the data-mce- prefixed variants
  363. function attr(name, value) {
  364. var self = this;
  365. // Update/retrive data-mce- attribute variants
  366. if (attrRegExp.test(name)) {
  367. if (value !== undef) {
  368. // Use TinyMCE behavior when setting the specifc attributes
  369. self.each(function(i, node) {
  370. editor.dom.setAttrib(node, name, value);
  371. });
  372. return self;
  373. } else
  374. return self.attr('data-mce-' + name);
  375. }
  376. // Default behavior
  377. return fn.attr.apply(self, arguments);
  378. };
  379. // Patch various jQuery functions to handle tinymce specific attribute and content behavior
  380. // we don't patch the jQuery.fn directly since it will most likely break compatibility
  381. // with other jQuery logic on the page. Only instances created by TinyMCE should be patched.
  382. function patch(jq) {
  383. // Patch some functions, only patch the object once
  384. if (jq.css !== css) {
  385. // Patch css/attr to use the data-mce- prefixed attribute variants
  386. jq.css = css;
  387. jq.attr = attr;
  388. jq.tinymce = editor;
  389. // Each pushed jQuery instance needs to be patched
  390. // as well for example when traversing the DOM
  391. jq.pushStack = function() {
  392. return patch(fn.pushStack.apply(this, arguments));
  393. };
  394. }
  395. return jq;
  396. };
  397. // Add a $ function on each editor instance this one is scoped for the editor document object
  398. // this way you can do chaining like this tinymce.get(0).$('p').append('text').css('color', 'red');
  399. editor.$ = function(selector, scope) {
  400. var doc = editor.getDoc();
  401. return patch($(selector || doc, doc || scope));
  402. };
  403. }
  404. };
  405. // Patch in core NS functions
  406. tinymce.extend = $.extend;
  407. tinymce.extend(tinymce, {
  408. map : $.map,
  409. grep : function(a, f) {return $.grep(a, f || function(){return 1;});},
  410. inArray : function(a, v) {return $.inArray(v, a || []);}
  411. /* Didn't iterate stylesheets
  412. each : function(o, cb, s) {
  413. if (!o)
  414. return 0;
  415. var r = 1;
  416. $.each(o, function(nr, el){
  417. if (cb.call(s, el, nr, o) === false) {
  418. r = 0;
  419. return false;
  420. }
  421. });
  422. return r;
  423. }*/
  424. });
  425. // Patch in functions in various clases
  426. // Add a "#ifndefjquery" statement around each core API function you add below
  427. var patches = {
  428. 'tinymce.dom.DOMUtils' : {
  429. /*
  430. addClass : function(e, c) {
  431. if (is(e, 'array') && is(e[0], 'string'))
  432. e = e.join(',#');
  433. return (e && $(is(e, 'string') ? '#' + e : e)
  434. .addClass(c)
  435. .attr('class')) || false;
  436. },
  437. hasClass : function(n, c) {
  438. return $(is(n, 'string') ? '#' + n : n).hasClass(c);
  439. },
  440. removeClass : function(e, c) {
  441. if (!e)
  442. return false;
  443. var r = [];
  444. $(is(e, 'string') ? '#' + e : e)
  445. .removeClass(c)
  446. .each(function(){
  447. r.push(this.className);
  448. });
  449. return r.length == 1 ? r[0] : r;
  450. },
  451. */
  452. select : function(pattern, scope) {
  453. var t = this;
  454. return $.find(pattern, t.get(scope) || t.get(t.settings.root_element) || t.doc, []);
  455. },
  456. is : function(n, patt) {
  457. return $(this.get(n)).is(patt);
  458. }
  459. /*
  460. show : function(e) {
  461. if (is(e, 'array') && is(e[0], 'string'))
  462. e = e.join(',#');
  463. $(is(e, 'string') ? '#' + e : e).css('display', 'block');
  464. },
  465. hide : function(e) {
  466. if (is(e, 'array') && is(e[0], 'string'))
  467. e = e.join(',#');
  468. $(is(e, 'string') ? '#' + e : e).css('display', 'none');
  469. },
  470. isHidden : function(e) {
  471. return $(is(e, 'string') ? '#' + e : e).is(':hidden');
  472. },
  473. insertAfter : function(n, e) {
  474. return $(is(e, 'string') ? '#' + e : e).after(n);
  475. },
  476. replace : function(o, n, k) {
  477. n = $(is(n, 'string') ? '#' + n : n);
  478. if (k)
  479. n.children().appendTo(o);
  480. n.replaceWith(o);
  481. },
  482. setStyle : function(n, na, v) {
  483. if (is(n, 'array') && is(n[0], 'string'))
  484. n = n.join(',#');
  485. $(is(n, 'string') ? '#' + n : n).css(na, v);
  486. },
  487. getStyle : function(n, na, c) {
  488. return $(is(n, 'string') ? '#' + n : n).css(na);
  489. },
  490. setStyles : function(e, o) {
  491. if (is(e, 'array') && is(e[0], 'string'))
  492. e = e.join(',#');
  493. $(is(e, 'string') ? '#' + e : e).css(o);
  494. },
  495. setAttrib : function(e, n, v) {
  496. var t = this, s = t.settings;
  497. if (is(e, 'array') && is(e[0], 'string'))
  498. e = e.join(',#');
  499. e = $(is(e, 'string') ? '#' + e : e);
  500. switch (n) {
  501. case "style":
  502. e.each(function(i, v){
  503. if (s.keep_values)
  504. $(v).attr('data-mce-style', v);
  505. v.style.cssText = v;
  506. });
  507. break;
  508. case "class":
  509. e.each(function(){
  510. this.className = v;
  511. });
  512. break;
  513. case "src":
  514. case "href":
  515. e.each(function(i, v){
  516. if (s.keep_values) {
  517. if (s.url_converter)
  518. v = s.url_converter.call(s.url_converter_scope || t, v, n, v);
  519. t.setAttrib(v, 'data-mce-' + n, v);
  520. }
  521. });
  522. break;
  523. }
  524. if (v !== null && v.length !== 0)
  525. e.attr(n, '' + v);
  526. else
  527. e.removeAttr(n);
  528. },
  529. setAttribs : function(e, o) {
  530. var t = this;
  531. $.each(o, function(n, v){
  532. t.setAttrib(e,n,v);
  533. });
  534. }
  535. */
  536. }
  537. /*
  538. 'tinymce.dom.Event' : {
  539. add : function (o, n, f, s) {
  540. var lo, cb;
  541. cb = function(e) {
  542. e.target = e.target || this;
  543. f.call(s || this, e);
  544. };
  545. if (is(o, 'array') && is(o[0], 'string'))
  546. o = o.join(',#');
  547. o = $(is(o, 'string') ? '#' + o : o);
  548. if (n == 'init') {
  549. o.ready(cb, s);
  550. } else {
  551. if (s) {
  552. o.bind(n, s, cb);
  553. } else {
  554. o.bind(n, cb);
  555. }
  556. }
  557. lo = this._jqLookup || (this._jqLookup = []);
  558. lo.push({func : f, cfunc : cb});
  559. return cb;
  560. },
  561. remove : function(o, n, f) {
  562. // Find cfunc
  563. $(this._jqLookup).each(function() {
  564. if (this.func === f)
  565. f = this.cfunc;
  566. });
  567. if (is(o, 'array') && is(o[0], 'string'))
  568. o = o.join(',#');
  569. $(is(o, 'string') ? '#' + o : o).unbind(n,f);
  570. return true;
  571. }
  572. }
  573. */
  574. };
  575. // Patch functions after a class is created
  576. tinymce.onCreate = function(ty, c, p) {
  577. tinymce.extend(p, patches[c]);
  578. };
  579. })(window.jQuery, tinymce);
  580. tinymce.create('tinymce.util.Dispatcher', {
  581. scope : null,
  582. listeners : null,
  583. inDispatch: false,
  584. Dispatcher : function(scope) {
  585. this.scope = scope || this;
  586. this.listeners = [];
  587. },
  588. add : function(callback, scope) {
  589. this.listeners.push({cb : callback, scope : scope || this.scope});
  590. return callback;
  591. },
  592. addToTop : function(callback, scope) {
  593. var self = this, listener = {cb : callback, scope : scope || self.scope};
  594. // Create new listeners if addToTop is executed in a dispatch loop
  595. if (self.inDispatch) {
  596. self.listeners = [listener].concat(self.listeners);
  597. } else {
  598. self.listeners.unshift(listener);
  599. }
  600. return callback;
  601. },
  602. remove : function(callback) {
  603. var listeners = this.listeners, output = null;
  604. tinymce.each(listeners, function(listener, i) {
  605. if (callback == listener.cb) {
  606. output = listener;
  607. listeners.splice(i, 1);
  608. return false;
  609. }
  610. });
  611. return output;
  612. },
  613. dispatch : function() {
  614. var self = this, returnValue, args = arguments, i, listeners = self.listeners, listener;
  615. self.inDispatch = true;
  616. // Needs to be a real loop since the listener count might change while looping
  617. // And this is also more efficient
  618. for (i = 0; i < listeners.length; i++) {
  619. listener = listeners[i];
  620. returnValue = listener.cb.apply(listener.scope, args.length > 0 ? args : [listener.scope]);
  621. if (returnValue === false)
  622. break;
  623. }
  624. self.inDispatch = false;
  625. return returnValue;
  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. b = s.base_uri;
  662. if (b) {
  663. if (!t.protocol)
  664. t.protocol = b.protocol;
  665. if (!t.userInfo)
  666. t.userInfo = b.userInfo;
  667. if (!t.port && t.host === 'mce_host')
  668. t.port = b.port;
  669. if (!t.host || t.host === 'mce_host')
  670. t.host = b.host;
  671. t.source = '';
  672. }
  673. //t.path = t.path || '/';
  674. },
  675. setPath : function(p) {
  676. var t = this;
  677. p = /^(.*?)\/?(\w+)?$/.exec(p);
  678. // Update path parts
  679. t.path = p[0];
  680. t.directory = p[1];
  681. t.file = p[2];
  682. // Rebuild source
  683. t.source = '';
  684. t.getURI();
  685. },
  686. toRelative : function(u) {
  687. var t = this, o;
  688. if (u === "./")
  689. return u;
  690. u = new tinymce.util.URI(u, {base_uri : t});
  691. // Not on same domain/port or protocol
  692. if ((u.host != 'mce_host' && t.host != u.host && u.host) || t.port != u.port || t.protocol != u.protocol)
  693. return u.getURI();
  694. var tu = t.getURI(), uu = u.getURI();
  695. // Allow usage of the base_uri when relative_urls = true
  696. if(tu == uu || (tu.charAt(tu.length - 1) == "/" && tu.substr(0, tu.length - 1) == uu))
  697. return tu;
  698. o = t.toRelPath(t.path, u.path);
  699. // Add query
  700. if (u.query)
  701. o += '?' + u.query;
  702. // Add anchor
  703. if (u.anchor)
  704. o += '#' + u.anchor;
  705. return o;
  706. },
  707. toAbsolute : function(u, nh) {
  708. u = new tinymce.util.URI(u, {base_uri : this});
  709. return u.getURI(this.host == u.host && this.protocol == u.protocol ? nh : 0);
  710. },
  711. toRelPath : function(base, path) {
  712. var items, bp = 0, out = '', i, l;
  713. // Split the paths
  714. base = base.substring(0, base.lastIndexOf('/'));
  715. base = base.split('/');
  716. items = path.split('/');
  717. if (base.length >= items.length) {
  718. for (i = 0, l = base.length; i < l; i++) {
  719. if (i >= items.length || base[i] != items[i]) {
  720. bp = i + 1;
  721. break;
  722. }
  723. }
  724. }
  725. if (base.length < items.length) {
  726. for (i = 0, l = items.length; i < l; i++) {
  727. if (i >= base.length || base[i] != items[i]) {
  728. bp = i + 1;
  729. break;
  730. }
  731. }
  732. }
  733. if (bp === 1)
  734. return path;
  735. for (i = 0, l = base.length - (bp - 1); i < l; i++)
  736. out += "../";
  737. for (i = bp - 1, l = items.length; i < l; i++) {
  738. if (i != bp - 1)
  739. out += "/" + items[i];
  740. else
  741. out += items[i];
  742. }
  743. return out;
  744. },
  745. toAbsPath : function(base, path) {
  746. var i, nb = 0, o = [], tr, outPath;
  747. // Split paths
  748. tr = /\/$/.test(path) ? '/' : '';
  749. base = base.split('/');
  750. path = path.split('/');
  751. // Remove empty chunks
  752. each(base, function(k) {
  753. if (k)
  754. o.push(k);
  755. });
  756. base = o;
  757. // Merge relURLParts chunks
  758. for (i = path.length - 1, o = []; i >= 0; i--) {
  759. // Ignore empty or .
  760. if (path[i].length === 0 || path[i] === ".")
  761. continue;
  762. // Is parent
  763. if (path[i] === '..') {
  764. nb++;
  765. continue;
  766. }
  767. // Move up
  768. if (nb > 0) {
  769. nb--;
  770. continue;
  771. }
  772. o.push(path[i]);
  773. }
  774. i = base.length - nb;
  775. // If /a/b/c or /
  776. if (i <= 0)
  777. outPath = o.reverse().join('/');
  778. else
  779. outPath = base.slice(0, i).join('/') + '/' + o.reverse().join('/');
  780. // Add front / if it's needed
  781. if (outPath.indexOf('/') !== 0)
  782. outPath = '/' + outPath;
  783. // Add traling / if it's needed
  784. if (tr && outPath.lastIndexOf('/') !== outPath.length - 1)
  785. outPath += tr;
  786. return outPath;
  787. },
  788. getURI : function(nh) {
  789. var s, t = this;
  790. // Rebuild source
  791. if (!t.source || nh) {
  792. s = '';
  793. if (!nh) {
  794. if (t.protocol)
  795. s += t.protocol + '://';
  796. if (t.userInfo)
  797. s += t.userInfo + '@';
  798. if (t.host)
  799. s += t.host;
  800. if (t.port)
  801. s += ':' + t.port;
  802. }
  803. if (t.path)
  804. s += t.path;
  805. if (t.query)
  806. s += '?' + t.query;
  807. if (t.anchor)
  808. s += '#' + t.anchor;
  809. t.source = s;
  810. }
  811. return t.source;
  812. }
  813. });
  814. })();
  815. (function() {
  816. var each = tinymce.each;
  817. tinymce.create('static tinymce.util.Cookie', {
  818. getHash : function(n) {
  819. var v = this.get(n), h;
  820. if (v) {
  821. each(v.split('&'), function(v) {
  822. v = v.split('=');
  823. h = h || {};
  824. h[unescape(v[0])] = unescape(v[1]);
  825. });
  826. }
  827. return h;
  828. },
  829. setHash : function(n, v, e, p, d, s) {
  830. var o = '';
  831. each(v, function(v, k) {
  832. o += (!o ? '' : '&') + escape(k) + '=' + escape(v);
  833. });
  834. this.set(n, o, e, p, d, s);
  835. },
  836. get : function(n) {
  837. var c = document.cookie, e, p = n + "=", b;
  838. // Strict mode
  839. if (!c)
  840. return;
  841. b = c.indexOf("; " + p);
  842. if (b == -1) {
  843. b = c.indexOf(p);
  844. if (b !== 0)
  845. return null;
  846. } else
  847. b += 2;
  848. e = c.indexOf(";", b);
  849. if (e == -1)
  850. e = c.length;
  851. return unescape(c.substring(b + p.length, e));
  852. },
  853. set : function(n, v, e, p, d, s) {
  854. document.cookie = n + "=" + escape(v) +
  855. ((e) ? "; expires=" + e.toGMTString() : "") +
  856. ((p) ? "; path=" + escape(p) : "") +
  857. ((d) ? "; domain=" + d : "") +
  858. ((s) ? "; secure" : "");
  859. },
  860. remove : function(name, path, domain) {
  861. var date = new Date();
  862. date.setTime(date.getTime() - 1000);
  863. this.set(name, '', date, path, domain);
  864. }
  865. });
  866. })();
  867. (function() {
  868. function serialize(o, quote) {
  869. var i, v, t, name;
  870. quote = quote || '"';
  871. if (o == null)
  872. return 'null';
  873. t = typeof o;
  874. if (t == 'string') {
  875. v = '\bb\tt\nn\ff\rr\""\'\'\\\\';
  876. return quote + o.replace(/([\u0080-\uFFFF\x00-\x1f\"\'\\])/g, function(a, b) {
  877. // Make sure single quotes never get encoded inside double quotes for JSON compatibility
  878. if (quote === '"' && a === "'")
  879. return a;
  880. i = v.indexOf(b);
  881. if (i + 1)
  882. return '\\' + v.charAt(i + 1);
  883. a = b.charCodeAt().toString(16);
  884. return '\\u' + '0000'.substring(a.length) + a;
  885. }) + quote;
  886. }
  887. if (t == 'object') {
  888. if (o.hasOwnProperty && Object.prototype.toString.call(o) === '[object Array]') {
  889. for (i=0, v = '['; i<o.length; i++)
  890. v += (i > 0 ? ',' : '') + serialize(o[i], quote);
  891. return v + ']';
  892. }
  893. v = '{';
  894. for (name in o) {
  895. if (o.hasOwnProperty(name)) {
  896. v += typeof o[name] != 'function' ? (v.length > 1 ? ',' + quote : quote) + name + quote +':' + serialize(o[name], quote) : '';
  897. }
  898. }
  899. return v + '}';
  900. }
  901. return '' + o;
  902. };
  903. tinymce.util.JSON = {
  904. serialize: serialize,
  905. parse: function(s) {
  906. try {
  907. return eval('(' + s + ')');
  908. } catch (ex) {
  909. // Ignore
  910. }
  911. }
  912. };
  913. })();
  914. tinymce.create('static tinymce.util.XHR', {
  915. send : function(o) {
  916. var x, t, w = window, c = 0;
  917. function ready() {
  918. if (!o.async || x.readyState == 4 || c++ > 10000) {
  919. if (o.success && c < 10000 && x.status == 200)
  920. o.success.call(o.success_scope, '' + x.responseText, x, o);
  921. else if (o.error)
  922. o.error.call(o.error_scope, c > 10000 ? 'TIMED_OUT' : 'GENERAL', x, o);
  923. x = null;
  924. } else
  925. w.setTimeout(ready, 10);
  926. };
  927. // Default settings
  928. o.scope = o.scope || this;
  929. o.success_scope = o.success_scope || o.scope;
  930. o.error_scope = o.error_scope || o.scope;
  931. o.async = o.async === false ? false : true;
  932. o.data = o.data || '';
  933. function get(s) {
  934. x = 0;
  935. try {
  936. x = new ActiveXObject(s);
  937. } catch (ex) {
  938. }
  939. return x;
  940. };
  941. x = w.XMLHttpRequest ? new XMLHttpRequest() : get('Microsoft.XMLHTTP') || get('Msxml2.XMLHTTP');
  942. if (x) {
  943. if (x.overrideMimeType)
  944. x.overrideMimeType(o.content_type);
  945. x.open(o.type || (o.data ? 'POST' : 'GET'), o.url, o.async);
  946. if (o.content_type)
  947. x.setRequestHeader('Content-Type', o.content_type);
  948. x.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  949. x.send(o.data);
  950. // Syncronous request
  951. if (!o.async)
  952. return ready();
  953. // Wait for response, onReadyStateChange can not be used since it leaks memory in IE
  954. t = w.setTimeout(ready, 10);
  955. }
  956. }
  957. });
  958. (function() {
  959. var extend = tinymce.extend, JSON = tinymce.util.JSON, XHR = tinymce.util.XHR;
  960. tinymce.create('tinymce.util.JSONRequest', {
  961. JSONRequest : function(s) {
  962. this.settings = extend({
  963. }, s);
  964. this.count = 0;
  965. },
  966. send : function(o) {
  967. var ecb = o.error, scb = o.success;
  968. o = extend(this.settings, o);
  969. o.success = function(c, x) {
  970. c = JSON.parse(c);
  971. if (typeof(c) == 'undefined') {
  972. c = {
  973. error : 'JSON Parse error.'
  974. };
  975. }
  976. if (c.error)
  977. ecb.call(o.error_scope || o.scope, c.error, x);
  978. else
  979. scb.call(o.success_scope || o.scope, c.result);
  980. };
  981. o.error = function(ty, x) {
  982. if (ecb)
  983. ecb.call(o.error_scope || o.scope, ty, x);
  984. };
  985. o.data = JSON.serialize({
  986. id : o.id || 'c' + (this.count++),
  987. method : o.method,
  988. params : o.params
  989. });
  990. // JSON content type for Ruby on rails. Bug: #1883287
  991. o.content_type = 'application/json';
  992. XHR.send(o);
  993. },
  994. 'static' : {
  995. sendRPC : function(o) {
  996. return new tinymce.util.JSONRequest().send(o);
  997. }
  998. }
  999. });
  1000. }());
  1001. (function(tinymce){
  1002. tinymce.VK = {
  1003. BACKSPACE: 8,
  1004. DELETE: 46,
  1005. DOWN: 40,
  1006. ENTER: 13,
  1007. LEFT: 37,
  1008. RIGHT: 39,
  1009. SPACEBAR: 32,
  1010. TAB: 9,
  1011. UP: 38,
  1012. modifierPressed: function (e) {
  1013. return e.shiftKey || e.ctrlKey || e.altKey;
  1014. },
  1015. metaKeyPressed: function(e) {
  1016. // Check if ctrl or meta key is pressed also check if alt is false for Polish users
  1017. return tinymce.isMac ? e.metaKey : e.ctrlKey && !e.altKey;
  1018. }
  1019. };
  1020. })(tinymce);
  1021. tinymce.util.Quirks = function(editor) {
  1022. var VK = tinymce.VK, BACKSPACE = VK.BACKSPACE, DELETE = VK.DELETE, dom = editor.dom, selection = editor.selection,
  1023. settings = editor.settings, parser = editor.parser, serializer = editor.serializer, each = tinymce.each;
  1024. function setEditorCommandState(cmd, state) {
  1025. try {
  1026. editor.getDoc().execCommand(cmd, false, state);
  1027. } catch (ex) {
  1028. // Ignore
  1029. }
  1030. }
  1031. function getDocumentMode() {
  1032. var documentMode = editor.getDoc().documentMode;
  1033. return documentMode ? documentMode : 6;
  1034. };
  1035. function isDefaultPrevented(e) {
  1036. return e.isDefaultPrevented();
  1037. };
  1038. function cleanupStylesWhenDeleting() {
  1039. function removeMergedFormatSpans(isDelete) {
  1040. var rng, blockElm, node, clonedSpan;
  1041. rng = selection.getRng();
  1042. // Find root block
  1043. blockElm = dom.getParent(rng.startContainer, dom.isBlock);
  1044. // On delete clone the root span of the next block element
  1045. if (isDelete) {
  1046. blockElm = dom.getNext(blockElm, dom.isBlock);
  1047. }
  1048. // Locate root span element and clone it since it would otherwise get merged by the "apple-style-span" on delete/backspace
  1049. if (blockElm) {
  1050. node = blockElm.firstChild;
  1051. // Ignore empty text nodes
  1052. while (node && node.nodeType == 3 && node.nodeValue.length === 0) {
  1053. node = node.nextSibling;
  1054. }
  1055. if (node && node.nodeName === 'SPAN') {
  1056. clonedSpan = node.cloneNode(false);
  1057. }
  1058. }
  1059. each(dom.select('span', blockElm), function(span) {
  1060. span.setAttribute('data-mce-mark', '1');
  1061. });
  1062. // Do the backspace/delete action
  1063. editor.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null);
  1064. // Find all odd apple-style-spans
  1065. blockElm = dom.getParent(rng.startContainer, dom.isBlock);
  1066. each(dom.select('span', blockElm), function(span) {
  1067. var bm = selection.getBookmark();
  1068. if (clonedSpan) {
  1069. dom.replace(clonedSpan.cloneNode(false), span, true);
  1070. } else if (!span.getAttribute('data-mce-mark')) {
  1071. dom.remove(span, true);
  1072. } else {
  1073. span.removeAttribute('data-mce-mark');
  1074. }
  1075. // Restore the selection
  1076. selection.moveToBookmark(bm);
  1077. });
  1078. }
  1079. editor.onKeyDown.add(function(editor, e) {
  1080. var isDelete;
  1081. isDelete = e.keyCode == DELETE;
  1082. if (!isDefaultPrevented(e) && (isDelete || e.keyCode == BACKSPACE) && !VK.modifierPressed(e)) {
  1083. e.preventDefault();
  1084. removeMergedFormatSpans(isDelete);
  1085. }
  1086. });
  1087. editor.addCommand('Delete', function() {removeMergedFormatSpans();});
  1088. };
  1089. function emptyEditorWhenDeleting() {
  1090. function serializeRng(rng) {
  1091. var body = dom.create("body");
  1092. var contents = rng.cloneContents();
  1093. body.appendChild(contents);
  1094. return selection.serializer.serialize(body, {format: 'html'});
  1095. }
  1096. function allContentsSelected(rng) {
  1097. var selection = serializeRng(rng);
  1098. var allRng = dom.createRng();
  1099. allRng.selectNode(editor.getBody());
  1100. var allSelection = serializeRng(allRng);
  1101. return selection === allSelection;
  1102. }
  1103. editor.onKeyDown.add(function(editor, e) {
  1104. var keyCode = e.keyCode, isCollapsed;
  1105. // Empty the editor if it's needed for example backspace at <p><b>|</b></p>
  1106. if (!isDefaultPrevented(e) && (keyCode == DELETE || keyCode == BACKSPACE)) {
  1107. isCollapsed = editor.selection.isCollapsed();
  1108. // Selection is collapsed but the editor isn't empty
  1109. if (isCollapsed && !dom.isEmpty(editor.getBody())) {
  1110. return;
  1111. }
  1112. // IE deletes all contents correctly when everything is selected
  1113. if (tinymce.isIE && !isCollapsed) {
  1114. return;
  1115. }
  1116. // Selection isn't collapsed but not all the contents is selected
  1117. if (!isCollapsed && !allContentsSelected(editor.selection.getRng())) {
  1118. return;
  1119. }
  1120. // Manually empty the editor
  1121. editor.setContent('');
  1122. editor.selection.setCursorLocation(editor.getBody(), 0);
  1123. editor.nodeChanged();
  1124. }
  1125. });
  1126. };
  1127. function selectAll() {
  1128. editor.onKeyDown.add(function(editor, e) {
  1129. if (!isDefaultPrevented(e) && e.keyCode == 65 && VK.metaKeyPressed(e)) {
  1130. e.preventDefault();
  1131. editor.execCommand('SelectAll');
  1132. }
  1133. });
  1134. };
  1135. function inputMethodFocus() {
  1136. if (!editor.settings.content_editable) {
  1137. // Case 1 IME doesn't initialize if you focus the document
  1138. dom.bind(editor.getDoc(), 'focusin', function(e) {
  1139. selection.setRng(selection.getRng());
  1140. });
  1141. // Case 2 IME doesn't initialize if you click the documentElement it also doesn't properly fire the focusin event
  1142. dom.bind(editor.getDoc(), 'mousedown', function(e) {
  1143. if (e.target == editor.getDoc().documentElement) {
  1144. editor.getWin().focus();
  1145. selection.setRng(selection.getRng());
  1146. }
  1147. });
  1148. }
  1149. };
  1150. function removeHrOnBackspace() {
  1151. editor.onKeyDown.add(function(editor, e) {
  1152. if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
  1153. if (selection.isCollapsed() && selection.getRng(true).startOffset === 0) {
  1154. var node = selection.getNode();
  1155. var previousSibling = node.previousSibling;
  1156. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "hr") {
  1157. dom.remove(previousSibling);
  1158. tinymce.dom.Event.cancel(e);
  1159. }
  1160. }
  1161. }
  1162. })
  1163. }
  1164. function focusBody() {
  1165. // Fix for a focus bug in FF 3.x where the body element
  1166. // wouldn't get proper focus if the user clicked on the HTML element
  1167. if (!Range.prototype.getClientRects) { // Detect getClientRects got introduced in FF 4
  1168. editor.onMouseDown.add(function(editor, e) {
  1169. if (!isDefaultPrevented(e) && e.target.nodeName === "HTML") {
  1170. var body = editor.getBody();
  1171. // Blur the body it's focused but not correctly focused
  1172. body.blur();
  1173. // Refocus the body after a little while
  1174. setTimeout(function() {
  1175. body.focus();
  1176. }, 0);
  1177. }
  1178. });
  1179. }
  1180. };
  1181. function selectControlElements() {
  1182. editor.onClick.add(function(editor, e) {
  1183. e = e.target;
  1184. // Workaround for bug, http://bugs.webkit.org/show_bug.cgi?id=12250
  1185. // WebKit can't even do simple things like selecting an image
  1186. // Needs tobe the setBaseAndExtend or it will fail to select floated images
  1187. if (/^(IMG|HR)$/.test(e.nodeName)) {
  1188. selection.getSel().setBaseAndExtent(e, 0, e, 1);
  1189. }
  1190. if (e.nodeName == 'A' && dom.hasClass(e, 'mceItemAnchor')) {
  1191. selection.select(e);
  1192. }
  1193. editor.nodeChanged();
  1194. });
  1195. };
  1196. function removeStylesWhenDeletingAccrossBlockElements() {
  1197. function getAttributeApplyFunction() {
  1198. var template = dom.getAttribs(selection.getStart().cloneNode(false));
  1199. return function() {
  1200. var target = selection.getStart();
  1201. if (target !== editor.getBody()) {
  1202. dom.setAttrib(target, "style", null);
  1203. each(template, function(attr) {
  1204. target.setAttributeNode(attr.cloneNode(true));
  1205. });
  1206. }
  1207. };
  1208. }
  1209. function isSelectionAcrossElements() {
  1210. return !selection.isCollapsed() && dom.getParent(selection.getStart(), dom.isBlock) != dom.getParent(selection.getEnd(), dom.isBlock);
  1211. }
  1212. function blockEvent(editor, e) {
  1213. e.preventDefault();
  1214. return false;
  1215. }
  1216. editor.onKeyPress.add(function(editor, e) {
  1217. var applyAttributes;
  1218. if (!isDefaultPrevented(e) && (e.keyCode == 8 || e.keyCode == 46) && isSelectionAcrossElements()) {
  1219. applyAttributes = getAttributeApplyFunction();
  1220. editor.getDoc().execCommand('delete', false, null);
  1221. applyAttributes();
  1222. e.preventDefault();
  1223. return false;
  1224. }
  1225. });
  1226. dom.bind(editor.getDoc(), 'cut', function(e) {
  1227. var applyAttributes;
  1228. if (!isDefaultPrevented(e) && isSelectionAcrossElements()) {
  1229. applyAttributes = getAttributeApplyFunction();
  1230. editor.onKeyUp.addToTop(blockEvent);
  1231. setTimeout(function() {
  1232. applyAttributes();
  1233. editor.onKeyUp.remove(blockEvent);
  1234. }, 0);
  1235. }
  1236. });
  1237. }
  1238. function selectionChangeNodeChanged() {
  1239. var lastRng, selectionTimer;
  1240. dom.bind(editor.getDoc(), 'selectionchange', function() {
  1241. if (selectionTimer) {
  1242. clearTimeout(selectionTimer);
  1243. selectionTimer = 0;
  1244. }
  1245. selectionTimer = window.setTimeout(function() {
  1246. var rng = selection.getRng();
  1247. // Compare the ranges to see if it was a real change or not
  1248. if (!lastRng || !tinymce.dom.RangeUtils.compareRanges(rng, lastRng)) {
  1249. editor.nodeChanged();
  1250. lastRng = rng;
  1251. }
  1252. }, 50);
  1253. });
  1254. }
  1255. function ensureBodyHasRoleApplication() {
  1256. document.body.setAttribute("role", "application");
  1257. }
  1258. function disableBackspaceIntoATable() {
  1259. editor.onKeyDown.add(function(editor, e) {
  1260. if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
  1261. if (selection.isCollapsed() && selection.getRng(true).startOffset === 0) {
  1262. var previousSibling = selection.getNode().previousSibling;
  1263. if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "table") {
  1264. return tinymce.dom.Event.cancel(e);
  1265. }
  1266. }
  1267. }
  1268. })
  1269. }
  1270. function addNewLinesBeforeBrInPre() {
  1271. // IE8+ rendering mode does the right thing with BR in PRE
  1272. if (getDocumentMode() > 7) {
  1273. return;
  1274. }
  1275. // Enable display: none in area and add a specific class that hides all BR elements in PRE to
  1276. // avoid the caret from getting stuck at the BR elements while pressing the right arrow key
  1277. setEditorCommandState('RespectVisibilityInDesign', true);
  1278. editor.contentStyles.push('.mceHideBrInPre pre br {display: none}');
  1279. dom.addClass(editor.getBody(), 'mceHideBrInPre');
  1280. // Adds a \n before all BR elements in PRE to get them visual
  1281. parser.addNodeFilter('pre', function(nodes, name) {
  1282. var i = nodes.length, brNodes, j, brElm, sibling;
  1283. while (i--) {
  1284. brNodes = nodes[i].getAll('br');
  1285. j = brNodes.length;
  1286. while (j--) {
  1287. brElm = brNodes[j];
  1288. // Add \n before BR in PRE elements on older IE:s so the new lines get rendered
  1289. sibling = brElm.prev;
  1290. if (sibling && sibling.type === 3 && sibling.value.charAt(sibling.value - 1) != '\n') {
  1291. sibling.value += '\n';
  1292. } else {
  1293. brElm.parent.insert(new tinymce.html.Node('#text', 3), brElm, true).value = '\n';
  1294. }
  1295. }
  1296. }
  1297. });
  1298. // Removes any \n before BR elements in PRE since other browsers and in contentEditable=false mode they will be visible
  1299. serializer.addNodeFilter('pre', function(nodes, name) {
  1300. var i = nodes.length, brNodes, j, brElm, sibling;
  1301. while (i--) {
  1302. brNodes = nodes[i].getAll('br');
  1303. j = brNodes.length;
  1304. while (j--) {
  1305. brElm = brNodes[j];
  1306. sibling = brElm.prev;
  1307. if (sibling && sibling.type == 3) {
  1308. sibling.value = sibling.value.replace(/\r?\n$/, '');
  1309. }
  1310. }
  1311. }
  1312. });
  1313. }
  1314. function removePreSerializedStylesWhenSelectingControls() {
  1315. dom.bind(editor.getBody(), 'mouseup', function(e) {
  1316. var value, node = selection.getNode();
  1317. // Moved styles to attributes on IMG eements
  1318. if (node.nodeName == 'IMG') {
  1319. // Convert style width to width attribute
  1320. if (value = dom.getStyle(node, 'width')) {
  1321. dom.setAttrib(node, 'width', value.replace(/[^0-9%]+/g, ''));
  1322. dom.setStyle(node, 'width', '');
  1323. }
  1324. // Convert style height to height attribute
  1325. if (value = dom.getStyle(node, 'height')) {
  1326. dom.setAttrib(node, 'height', value.replace(/[^0-9%]+/g, ''));
  1327. dom.setStyle(node, 'height', '');
  1328. }
  1329. }
  1330. });
  1331. }
  1332. function keepInlineElementOnDeleteBackspace() {
  1333. editor.onKeyDown.add(function(editor, e) {
  1334. var isDelete, rng, container, offset, brElm, sibling, collapsed;
  1335. isDelete = e.keyCode == DELETE;
  1336. if (!isDefaultPrevented(e) && (isDelete || e.keyCode == BACKSPACE) && !VK.modifierPressed(e)) {
  1337. rng = selection.getRng();
  1338. container = rng.startContainer;
  1339. offset = rng.startOffset;
  1340. collapsed = rng.collapsed;
  1341. // Override delete if the start container is a text node and is at the beginning of text or
  1342. // just before/after the last character to be deleted in collapsed mode
  1343. if (container.nodeType == 3 && container.nodeValue.length > 0 && ((offset === 0 && !collapsed) || (collapsed && offset === (isDelete ? 0 : 1)))) {
  1344. nonEmptyElements = editor.schema.getNonEmptyElements();
  1345. // Prevent default logic since it's broken
  1346. e.preventDefault();
  1347. // Insert a BR before the text node this will prevent the containing element from being deleted/converted
  1348. brElm = dom.create('br', {id: '__tmp'});
  1349. container.parentNode.insertBefore(brElm, container);
  1350. // Do the browser delete
  1351. editor.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null);
  1352. // Check if the previous sibling is empty after deleting for example: <p><b></b>|</p>
  1353. container = selection.getRng().startContainer;
  1354. sibling = container.previousSibling;
  1355. if (sibling && sibling.nodeType == 1 && !dom.isBlock(sibling) && dom.isEmpty(sibling) && !nonEmptyElements[sibling.nodeName.toLowerCase()]) {
  1356. dom.remove(sibling);
  1357. }
  1358. // Remove the temp element we inserted
  1359. dom.remove('__tmp');
  1360. }
  1361. }
  1362. });
  1363. }
  1364. function removeBlockQuoteOnBackSpace() {
  1365. // Add block quote deletion handler
  1366. editor.onKeyDown.add(function(editor, e) {
  1367. var rng, container, offset, root, parent;
  1368. if (isDefaultPrevented(e) || e.keyCode != VK.BACKSPACE) {
  1369. return;
  1370. }
  1371. rng = selection.getRng();
  1372. container = rng.startContainer;
  1373. offset = rng.startOffset;
  1374. root = dom.getRoot();
  1375. parent = container;
  1376. if (!rng.collapsed || offset !== 0) {
  1377. return;
  1378. }
  1379. while (parent && parent.parentNode && parent.parentNode.firstChild == parent && parent.parentNode != root) {
  1380. parent = parent.parentNode;
  1381. }
  1382. // Is the cursor at the beginning of a blockquote?
  1383. if (parent.tagName === 'BLOCKQUOTE') {
  1384. // Remove the blockquote
  1385. editor.formatter.toggle('blockquote', null, parent);
  1386. // Move the caret to the beginning of container
  1387. rng = dom.createRng();
  1388. rng.setStart(container, 0);
  1389. rng.setEnd(container, 0);
  1390. selection.setRng(rng);
  1391. }
  1392. });
  1393. };
  1394. function setGeckoEditingOptions() {
  1395. function setOpts() {
  1396. editor._refreshContentEditable();
  1397. setEditorCommandState("StyleWithCSS", false);
  1398. setEditorCommandState("enableInlineTableEditing", false);
  1399. if (!settings.object_resizing) {
  1400. setEditorCommandState("enableObjectResizing", false);
  1401. }
  1402. };
  1403. if (!settings.readonly) {
  1404. editor.onBeforeExecCommand.add(setOpts);
  1405. editor.onMouseDown.add(setOpts);
  1406. }
  1407. };
  1408. function addBrAfterLastLinks() {
  1409. function fixLinks(editor, o) {
  1410. each(dom.select('a'), function(node) {
  1411. var parentNode = node.parentNode, root = dom.getRoot();
  1412. if (parentNode.lastChild === node) {
  1413. while (parentNode && !dom.isBlock(parentNode)) {
  1414. if (parentNode.parentNode.lastChild !== parentNode || parentNode === root) {
  1415. return;
  1416. }
  1417. parentNode = parentNode.parentNode;
  1418. }
  1419. dom.add(parentNode, 'br', {'data-mce-bogus' : 1});
  1420. }
  1421. });
  1422. };
  1423. editor.onExecCommand.add(function(editor, cmd) {
  1424. if (cmd === 'CreateLink') {
  1425. fixLinks(editor);
  1426. }
  1427. });
  1428. editor.onSetContent.add(selection.onSetContent.add(fixLinks));
  1429. };
  1430. function setDefaultBlockType() {
  1431. if (settings.forced_root_block) {
  1432. editor.onInit.add(function() {
  1433. setEditorCommandState('DefaultParagraphSeparator', settings.forced_root_block);
  1434. });
  1435. }
  1436. }
  1437. function removeGhostSelection() {
  1438. function repaint(sender, args) {
  1439. if (!sender || !args.initial) {
  1440. editor.execCommand('mceRepaint');
  1441. }
  1442. };
  1443. editor.onUndo.add(repaint);
  1444. editor.onRedo.add(repaint);
  1445. editor.onSetContent.add(repaint);
  1446. };
  1447. function deleteControlItemOnBackSpace() {
  1448. editor.onKeyDown.add(function(editor, e) {
  1449. var rng;
  1450. if (!isDefaultPrevented(e) && e.keyCode == BACKSPACE) {
  1451. rng = editor.getDoc().selection.createRange();
  1452. if (rng && rng.item) {
  1453. e.preventDefault();
  1454. editor.undoManager.beforeChange();
  1455. dom.remove(rng.item(0));
  1456. editor.undoManager.add();
  1457. }
  1458. }
  1459. });
  1460. };
  1461. function renderEmptyBlocksFix() {
  1462. var emptyBlocksCSS;
  1463. // IE10+
  1464. if (getDocumentMode() >= 10) {
  1465. emptyBlocksCSS = '';
  1466. each('p div h1 h2 h3 h4 h5 h6'.split(' '), function(name, i) {
  1467. emptyBlocksCSS += (i > 0 ? ',' : '') + name + ':empty';
  1468. });
  1469. editor.contentStyles.push(emptyBlocksCSS + '{padding-right: 1px !important}');
  1470. }
  1471. };
  1472. function fakeImageResize() {
  1473. var selectedElmX, selectedElmY, selectedElm, selectedElmGhost, selectedHandle, startX, startY, startW, startH, ratio,
  1474. resizeHandles, width, height, rootDocument = document, editableDoc = editor.getDoc();
  1475. if (!settings.object_resizing || settings.webkit_fake_resize === false) {
  1476. return;
  1477. }
  1478. // Try disabling object resizing if WebKit implements resizing in the future
  1479. setEditorCommandState("enableObjectResizing", false);
  1480. // Details about each resize handle how to scale etc
  1481. resizeHandles = {
  1482. // Name: x multiplier, y multiplier, delta size x, delta size y
  1483. n: [.5, 0, 0, -1],
  1484. e: [1, .5, 1, 0],
  1485. s: [.5, 1, 0, 1],
  1486. w: [0, .5, -1, 0],
  1487. nw: [0, 0, -1, -1],
  1488. ne: [1, 0, 1, -1],
  1489. se: [1, 1, 1, 1],
  1490. sw : [0, 1, -1, 1]
  1491. };
  1492. function resizeElement(e) {
  1493. var deltaX, deltaY;
  1494. // Calc new width/height
  1495. deltaX = e.screenX - startX;
  1496. deltaY = e.screenY - startY;
  1497. // Calc new size
  1498. width = deltaX * selectedHandle[2] + startW;
  1499. height = deltaY * selectedHandle[3] + startH;
  1500. // Never scale down lower than 5 pixels
  1501. width = width < 5 ? 5 : width;
  1502. height = height < 5 ? 5 : height;
  1503. // Constrain proportions when modifier key is pressed or if the nw, ne, sw, se corners are moved on an image
  1504. if (VK.modifierPressed(e) || (selectedElm.nodeName == "IMG" && selectedHandle[2] * selectedHandle[3] !== 0)) {
  1505. width = Math.round(height / ratio);
  1506. height = Math.round(width * ratio);
  1507. }
  1508. // Update ghost size
  1509. dom.setStyles(selectedElmGhost, {
  1510. width: width,
  1511. height: height
  1512. });
  1513. // Update ghost X position if needed
  1514. if (selectedHandle[2] < 0 && selectedElmGhost.clientWidth <= width) {
  1515. dom.setStyle(selectedElmGhost, 'left', selectedElmX + (startW - width));
  1516. }
  1517. // Update ghost Y position if needed
  1518. if (selectedHandle[3] < 0 && selectedElmGhost.clientHeight <= height) {
  1519. dom.setStyle(selectedElmGhost, 'top', selectedElmY + (startH - height));
  1520. }
  1521. }
  1522. function endResize() {
  1523. function setSizeProp(name, value) {
  1524. if (value) {
  1525. // Resize by using style or attribute
  1526. if (selectedElm.style[name] || !editor.schema.isValid(selectedElm.nodeName.toLowerCase(), name)) {
  1527. dom.setStyle(selectedElm, name, value);
  1528. } else {
  1529. dom.setAttrib(selectedElm, name, value);
  1530. }
  1531. }
  1532. }
  1533. // Set width/height properties
  1534. setSizeProp('width', width);
  1535. setSizeProp('height', height);
  1536. dom.unbind(editableDoc, 'mousemove', resizeElement);
  1537. dom.unbind(editableDoc, 'mouseup', endResize);
  1538. if (rootDocument != editableDoc) {
  1539. dom.unbind(rootDocument, 'mousemove', resizeElement);
  1540. dom.unbind(rootDocument, 'mouseup', endResize);
  1541. }
  1542. // Remove ghost and update resize handle positions
  1543. dom.remove(selectedElmGhost);
  1544. showResizeRect(selectedElm);
  1545. }
  1546. function showResizeRect(targetElm) {
  1547. var position, targetWidth, targetHeight;
  1548. hideResizeRect();
  1549. // Get position and size of target
  1550. position = dom.getPos(targetElm);
  1551. selectedElmX = position.x;
  1552. selectedElmY = position.y;
  1553. targetWidth = targetElm.offsetWidth;
  1554. targetHeight = targetElm.offsetHeight;
  1555. // Reset width/height if user selects a new image/table
  1556. if (selectedElm != targetElm) {
  1557. selectedElm = targetElm;
  1558. width = height = 0;
  1559. }
  1560. each(resizeHandles, function(handle, name) {
  1561. var handleElm;
  1562. // Get existing or render resize handle
  1563. handleElm = dom.get('mceResizeHandle' + name);
  1564. if (!handleElm) {
  1565. handleElm = dom.add(editableDoc.documentElement, 'div', {
  1566. id: 'mceResizeHandle' + name,
  1567. 'class': 'mceResizeHandle',
  1568. style: 'cursor:' + name + '-resize; margin:0; padding:0'
  1569. });
  1570. dom.bind(handleElm, 'mousedown', function(e) {
  1571. e.preventDefault();
  1572. endResize();
  1573. startX = e.screenX;
  1574. startY = e.screenY;
  1575. startW = selectedElm.clientWidth;
  1576. startH = selectedElm.clientHeight;
  1577. ratio = startH / startW;
  1578. selectedHandle = handle;
  1579. selectedElmGhost = selectedElm.cloneNode(true);
  1580. dom.addClass(selectedElmGhost, 'mceClonedResizable');
  1581. dom.setStyles(selectedElmGhost, {
  1582. left: selectedElmX,
  1583. top: selectedElmY,
  1584. margin: 0
  1585. });
  1586. editableDoc.documentElement.appendChild(selectedElmGhost);
  1587. dom.bind(editableDoc, 'mousemove', resizeElement);
  1588. dom.bind(editableDoc, 'mouseup', endResize);
  1589. if (rootDocument != editableDoc) {
  1590. dom.bind(rootDocument, 'mousemove', resizeElement);
  1591. dom.bind(rootDocument, 'mouseup', endResize);
  1592. }
  1593. });
  1594. } else {
  1595. dom.show(handleElm);
  1596. }
  1597. // Position element
  1598. dom.setStyles(handleElm, {
  1599. left: (targetWidth * handle[0] + selectedElmX) - (handleElm.offsetWidth / 2),
  1600. top: (targetHeight * handle[1] + selectedElmY) - (handleElm.offsetHeight / 2)
  1601. });
  1602. });
  1603. // Only add resize rectangle on WebKit and only on images
  1604. if (!tinymce.isOpera && selectedElm.nodeName == "IMG") {
  1605. selectedElm.setAttribute('data-mce-selected', '1');
  1606. }
  1607. }
  1608. function hideResizeRect() {
  1609. if (selectedElm) {
  1610. selectedElm.removeAttribute('data-mce-selected');
  1611. }
  1612. for (var name in resizeHandles) {
  1613. dom.hide('mceResizeHandle' + name);
  1614. }
  1615. }
  1616. // Add CSS for resize handles, cloned element and selected
  1617. editor.contentStyles.push(
  1618. '.mceResizeHandle {' +
  1619. 'position: absolute;' +
  1620. 'border: 1px solid black;' +
  1621. 'background: #FFF;' +
  1622. 'width: 5px;' +
  1623. 'height: 5px;' +
  1624. 'z-index: 10000' +
  1625. '}' +
  1626. '.mceResizeHandle:hover {' +
  1627. 'background: #000' +
  1628. '}' +
  1629. 'img[data-mce-selected] {' +
  1630. 'outline: 1px solid black' +
  1631. '}' +
  1632. 'img.mceClonedResizable, table.mceClonedResizable {' +
  1633. 'position: absolute;' +
  1634. 'outline: 1px dashed black;' +
  1635. 'opacity: .5;' +
  1636. 'z-index: 10000' +
  1637. '}'
  1638. );
  1639. function updateResizeRect() {
  1640. var controlElm = dom.getParent(selection.getNode(), 'table,img');
  1641. // Remove data-mce-selected from all elements since they might have been copied using Ctrl+c/v
  1642. each(dom.select('img[data-mce-selected]'), function(img) {
  1643. img.removeAttribute('data-mce-selected');
  1644. });
  1645. if (controlElm) {
  1646. showResizeRect(controlElm);
  1647. } else {
  1648. hideResizeRect();
  1649. }
  1650. }
  1651. // Show/hide resize rect when image is selected
  1652. editor.onNodeChange.add(updateResizeRect);
  1653. // Fixes WebKit quirk where it returns IMG on getNode if caret is after last image in container
  1654. dom.bind(editableDoc, 'selectionchange', updateResizeRect);
  1655. // Remove the internal attribute when serializing the DOM
  1656. editor.serializer.addAttributeFilter('data-mce-selected', function(nodes, name) {
  1657. var i = nodes.length;
  1658. while (i--) {
  1659. nodes[i].attr(name, null);
  1660. }
  1661. });
  1662. }
  1663. function keepNoScriptContents() {
  1664. if (getDocumentMode() < 9) {
  1665. parser.addNodeFilter('noscript', function(nodes) {
  1666. var i = nodes.length, node, textNode;
  1667. while (i--) {
  1668. node = nodes[i];
  1669. textNode = node.firstChild;
  1670. if (textNode) {
  1671. node.attr('data-mce-innertext', textNode.value);
  1672. }
  1673. }
  1674. });
  1675. serializer.addNodeFilter('noscript', function(nodes) {
  1676. var i = nodes.length, node, textNode, value;
  1677. while (i--) {
  1678. node = nodes[i];
  1679. textNode = nodes[i].firstChild;
  1680. if (textNode) {
  1681. textNode.value = tinymce.html.Entities.decode(textNode.value);
  1682. } else {
  1683. // Old IE can't retain noscript value so an attribute is used to store it
  1684. value = node.attributes.map['data-mce-innertext'];
  1685. if (value) {
  1686. node.attr('data-mce-innertext', null);
  1687. textNode = new tinymce.html.Node('#text', 3);
  1688. textNode.value = value;
  1689. textNode.raw = true;
  1690. node.append(textNode);
  1691. }
  1692. }
  1693. }
  1694. });
  1695. }
  1696. }
  1697. // All browsers
  1698. disableBackspaceIntoATable();
  1699. removeBlockQuoteOnBackSpace();
  1700. emptyEditorWhenDeleting();
  1701. // WebKit
  1702. if (tinymce.isWebKit) {
  1703. keepInlineElementOnDeleteBackspace();
  1704. cleanupStylesWhenDeleting();
  1705. inputMethodFocus();
  1706. selectControlElements();
  1707. setDefaultBlockType();
  1708. // iOS
  1709. if (tinymce.isIDevice) {
  1710. selectionChangeNodeChanged();
  1711. } else {
  1712. fakeImageResize();
  1713. selectAll();
  1714. }
  1715. }
  1716. // IE
  1717. if (tinymce.isIE) {
  1718. removeHrOnBackspace();
  1719. ensureBodyHasRoleApplication();
  1720. addNewLinesBeforeBrInPre();
  1721. removePreSerializedStylesWhenSelectingControls();
  1722. deleteControlItemOnBackSpace();
  1723. renderEmptyBlocksFix();
  1724. keepNoScriptContents();
  1725. }
  1726. // Gecko
  1727. if (tinymce.isGecko) {
  1728. removeHrOnBackspace();
  1729. focusBody();
  1730. removeStylesWhenDeletingAccrossBlockElements();
  1731. setGeckoEditingOptions();
  1732. addBrAfterLastLinks();
  1733. removeGhostSelection();
  1734. }
  1735. // Opera
  1736. if (tinymce.isOpera) {
  1737. fakeImageResize();
  1738. }
  1739. };
  1740. (function(tinymce) {
  1741. var namedEntities, baseEntities, reverseEntities,
  1742. attrsCharsRegExp = /[&<>\"\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  1743. textCharsRegExp = /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
  1744. rawCharsRegExp = /[<>&\"\']/g,
  1745. entityRegExp = /&(#x|#)?([\w]+);/g,
  1746. asciiMap = {
  1747. 128 : "\u20AC", 130 : "\u201A", 131 : "\u0192", 132 : "\u201E", 133 : "\u2026", 134 : "\u2020",
  1748. 135 : "\u2021", 136 : "\u02C6", 137 : "\u2030", 138 : "\u0160", 139 : "\u2039", 140 : "\u0152",
  1749. 142 : "\u017D", 145 : "\u2018", 146 : "\u2019", 147 : "\u201C", 148 : "\u201D", 149 : "\u2022",
  1750. 150 : "\u2013", 151 : "\u2014", 152 : "\u02DC", 153 : "\u2122", 154 : "\u0161", 155 : "\u203A",
  1751. 156 : "\u0153", 158 : "\u017E", 159 : "\u0178"
  1752. };
  1753. // Raw entities
  1754. baseEntities = {
  1755. '\"' : '&quot;', // Needs to be escaped since the YUI compressor would otherwise break the code
  1756. "'" : '&#39;',
  1757. '<' : '&lt;',
  1758. '>' : '&gt;',
  1759. '&' : '&amp;'
  1760. };
  1761. // Reverse lookup table for raw entities
  1762. reverseEntities = {
  1763. '&lt;' : '<',
  1764. '&gt;' : '>',
  1765. '&amp;' : '&',
  1766. '&quot;' : '"',
  1767. '&apos;' : "'"
  1768. };
  1769. // Decodes text by using the browser
  1770. function nativeDecode(text) {
  1771. var elm;
  1772. elm = document.createElement("div");
  1773. elm.innerHTML = text;
  1774. return elm.textContent || elm.innerText || text;
  1775. };
  1776. // Build a two way lookup table for the entities
  1777. function buildEntitiesLookup(items, radix) {
  1778. var i, chr, entity, lookup = {};
  1779. if (items) {
  1780. items = items.split(',');
  1781. radix = radix || 10;
  1782. // Build entities lookup table
  1783. for (i = 0; i < items.length; i += 2) {
  1784. chr = String.fromCharCode(parseInt(items[i], radix));
  1785. // Only add non base entities
  1786. if (!baseEntities[chr]) {
  1787. entity = '&' + items[i + 1] + ';';
  1788. lookup[chr] = entity;
  1789. lookup[entity] = chr;
  1790. }
  1791. }
  1792. return lookup;
  1793. }
  1794. };
  1795. // Unpack entities lookup where the numbers are in radix 32 to reduce the size
  1796. namedEntities = buildEntitiesLookup(
  1797. '50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' +
  1798. '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' +
  1799. '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' +
  1800. '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' +
  1801. '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' +
  1802. '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' +
  1803. '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' +
  1804. '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' +
  1805. '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' +
  1806. '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' +
  1807. 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' +
  1808. 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' +
  1809. 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' +
  1810. 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' +
  1811. 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' +
  1812. '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' +
  1813. '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' +
  1814. '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' +
  1815. '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' +
  1816. '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' +
  1817. 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' +
  1818. 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' +
  1819. 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' +
  1820. '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' +
  1821. '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro', 32);
  1822. tinymce.html = tinymce.html || {};
  1823. tinymce.html.Entities = {
  1824. encodeRaw : function(text, attr) {
  1825. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1826. return baseEntities[chr] || chr;
  1827. });
  1828. },
  1829. encodeAllRaw : function(text) {
  1830. return ('' + text).replace(rawCharsRegExp, function(chr) {
  1831. return baseEntities[chr] || chr;
  1832. });
  1833. },
  1834. encodeNumeric : function(text, attr) {
  1835. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1836. // Multi byte sequence convert it to a single entity
  1837. if (chr.length > 1)
  1838. return '&#' + (((chr.charCodeAt(0) - 0xD800) * 0x400) + (chr.charCodeAt(1) - 0xDC00) + 0x10000) + ';';
  1839. return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
  1840. });
  1841. },
  1842. encodeNamed : function(text, attr, entities) {
  1843. entities = entities || namedEntities;
  1844. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1845. return baseEntities[chr] || entities[chr] || chr;
  1846. });
  1847. },
  1848. getEncodeFunc : function(name, entities) {
  1849. var Entities = tinymce.html.Entities;
  1850. entities = buildEntitiesLookup(entities) || namedEntities;
  1851. function encodeNamedAndNumeric(text, attr) {
  1852. return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
  1853. return baseEntities[chr] || entities[chr] || '&#' + chr.charCodeAt(0) + ';' || chr;
  1854. });
  1855. };
  1856. function encodeCustomNamed(text, attr) {
  1857. return Entities.encodeNamed(text, attr, entities);
  1858. };
  1859. // Replace + with , to be compatible with previous TinyMCE versions
  1860. name = tinymce.makeMap(name.replace(/\+/g, ','));
  1861. // Named and numeric encoder
  1862. if (name.named && name.numeric)
  1863. return encodeNamedAndNumeric;
  1864. // Named encoder
  1865. if (name.named) {
  1866. // Custom names
  1867. if (entities)
  1868. return encodeCustomNamed;
  1869. return Entities.encodeNamed;
  1870. }
  1871. // Numeric
  1872. if (name.numeric)
  1873. return Entities.encodeNumeric;
  1874. // Raw encoder
  1875. return Entities.encodeRaw;
  1876. },
  1877. decode : function(text) {
  1878. return text.replace(entityRegExp, function(all, numeric, value) {
  1879. if (numeric) {
  1880. value = parseInt(value, numeric.length === 2 ? 16 : 10);
  1881. // Support upper UTF
  1882. if (value > 0xFFFF) {
  1883. value -= 0x10000;
  1884. return String.fromCharCode(0xD800 + (value >> 10), 0xDC00 + (value & 0x3FF));
  1885. } else
  1886. return asciiMap[value] || String.fromCharCode(value);
  1887. }
  1888. return reverseEntities[all] || namedEntities[all] || nativeDecode(all);
  1889. });
  1890. }
  1891. };
  1892. })(tinymce);
  1893. tinymce.html.Styles = function(settings, schema) {
  1894. var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi,
  1895. urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi,
  1896. styleRegExp = /\s*([^:]+):\s*([^;]+);?/g,
  1897. trimRightRegExp = /\s+$/,
  1898. urlColorRegExp = /rgb/,
  1899. undef, i, encodingLookup = {}, encodingItems;
  1900. settings = settings || {};
  1901. encodingItems = '\\" \\\' \\; \\: ; : \uFEFF'.split(' ');
  1902. for (i = 0; i < encodingItems.length; i++) {
  1903. encodingLookup[encodingItems[i]] = '\uFEFF' + i;
  1904. encodingLookup['\uFEFF' + i] = encodingItems[i];
  1905. }
  1906. function toHex(match, r, g, b) {
  1907. function hex(val) {
  1908. val = parseInt(val).toString(16);
  1909. return val.length > 1 ? val : '0' + val; // 0 -> 00
  1910. };
  1911. return '#' + hex(r) + hex(g) + hex(b);
  1912. };
  1913. return {
  1914. toHex : function(color) {
  1915. return color.replace(rgbRegExp, toHex);
  1916. },
  1917. parse : function(css) {
  1918. var styles = {}, matches, name, value, isEncoded, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope || this;
  1919. function compress(prefix, suffix) {
  1920. var top, right, bottom, left;
  1921. // Get values and check it it needs compressing
  1922. top = styles[prefix + '-top' + suffix];
  1923. if (!top)
  1924. return;
  1925. right = styles[prefix + '-right' + suffix];
  1926. if (top != right)
  1927. return;
  1928. bottom = styles[prefix + '-bottom' + suffix];
  1929. if (right != bottom)
  1930. return;
  1931. left = styles[prefix + '-left' + suffix];
  1932. if (bottom != left)
  1933. return;
  1934. // Compress
  1935. styles[prefix + suffix] = left;
  1936. delete styles[prefix + '-top' + suffix];
  1937. delete styles[prefix + '-right' + suffix];
  1938. delete styles[prefix + '-bottom' + suffix];
  1939. delete styles[prefix + '-left' + suffix];
  1940. };
  1941. function canCompress(key) {
  1942. var value = styles[key], i;
  1943. if (!value || value.indexOf(' ') < 0)
  1944. return;
  1945. value = value.split(' ');
  1946. i = value.length;
  1947. while (i--) {
  1948. if (value[i] !== value[0])
  1949. return false;
  1950. }
  1951. styles[key] = value[0];
  1952. return true;
  1953. };
  1954. function compress2(target, a, b, c) {
  1955. if (!canCompress(a))
  1956. return;
  1957. if (!canCompress(b))
  1958. return;
  1959. if (!canCompress(c))
  1960. return;
  1961. // Compress
  1962. styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
  1963. delete styles[a];
  1964. delete styles[b];
  1965. delete styles[c];
  1966. };
  1967. // Encodes the specified string by replacing all \" \' ; : with _<num>
  1968. function encode(str) {
  1969. isEncoded = true;
  1970. return encodingLookup[str];
  1971. };
  1972. // Decodes the specified string by replacing all _<num> with it's original value \" \' etc
  1973. // It will also decode the \" \' if keep_slashes is set to fale or omitted
  1974. function decode(str, keep_slashes) {
  1975. if (isEncoded) {
  1976. str = str.replace(/\uFEFF[0-9]/g, function(str) {
  1977. return encodingLookup[str];
  1978. });
  1979. }
  1980. if (!keep_slashes)
  1981. str = str.replace(/\\([\'\";:])/g, "$1");
  1982. return str;
  1983. };
  1984. function processUrl(match, url, url2, url3, str, str2) {
  1985. str = str || str2;
  1986. if (str) {
  1987. str = decode(str);
  1988. // Force strings into single quote format
  1989. return "'" + str.replace(/\'/g, "\\'") + "'";
  1990. }
  1991. url = decode(url || url2 || url3);
  1992. // Convert the URL to relative/absolute depending on config
  1993. if (urlConverter)
  1994. url = urlConverter.call(urlConverterScope, url, 'style');
  1995. // Output new URL format
  1996. return "url('" + url.replace(/\'/g, "\\'") + "')";
  1997. };
  1998. if (css) {
  1999. // Encode \" \' % and ; and : inside strings so they don't interfere with the style parsing
  2000. css = css.replace(/\\[\"\';:\uFEFF]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, function(str) {
  2001. return str.replace(/[;:]/g, encode);
  2002. });
  2003. // Parse styles
  2004. while (matches = styleRegExp.exec(css)) {
  2005. name = matches[1].replace(trimRightRegExp, '').toLowerCase();
  2006. value = matches[2].replace(trimRightRegExp, '');
  2007. if (name && value.length > 0) {
  2008. // Opera will produce 700 instead of bold in their style values
  2009. if (name === 'font-weight' && value === '700')
  2010. value = 'bold';
  2011. else if (name === 'color' || name === 'background-color') // Lowercase colors like RED
  2012. value = value.toLowerCase();
  2013. // Convert RGB colors to HEX
  2014. value = value.replace(rgbRegExp, toHex);
  2015. // Convert URLs and force them into url('value') format
  2016. value = value.replace(urlOrStrRegExp, processUrl);
  2017. styles[name] = isEncoded ? decode(value, true) : value;
  2018. }
  2019. styleRegExp.lastIndex = matches.index + matches[0].length;
  2020. }
  2021. // Compress the styles to reduce it's size for example IE will expand styles
  2022. compress("border", "");
  2023. compress("border", "-width");
  2024. compress("border", "-color");
  2025. compress("border", "-style");
  2026. compress("padding", "");
  2027. compress("margin", "");
  2028. compress2('border', 'border-width', 'border-style', 'border-color');
  2029. // Remove pointless border, IE produces these
  2030. if (styles.border === 'medium none')
  2031. delete styles.border;
  2032. }
  2033. return styles;
  2034. },
  2035. serialize : function(styles, element_name) {
  2036. var css = '', name, value;
  2037. function serializeStyles(name) {
  2038. var styleList, i, l, value;
  2039. styleList = schema.styles[name];
  2040. if (styleList) {
  2041. for (i = 0, l = styleList.length; i < l; i++) {
  2042. name = styleList[i];
  2043. value = styles[name];
  2044. if (value !== undef && value.length > 0)
  2045. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  2046. }
  2047. }
  2048. };
  2049. // Serialize styles according to schema
  2050. if (element_name && schema && schema.styles) {
  2051. // Serialize global styles and element specific styles
  2052. serializeStyles('*');
  2053. serializeStyles(element_name);
  2054. } else {
  2055. // Output the styles in the order they are inside the object
  2056. for (name in styles) {
  2057. value = styles[name];
  2058. if (value !== undef && value.length > 0)
  2059. css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
  2060. }
  2061. }
  2062. return css;
  2063. }
  2064. };
  2065. };
  2066. (function(tinymce) {
  2067. var mapCache = {}, makeMap = tinymce.makeMap, each = tinymce.each;
  2068. function split(str, delim) {
  2069. return str.split(delim || ',');
  2070. };
  2071. function unpack(lookup, data) {
  2072. var key, elements = {};
  2073. function replace(value) {
  2074. return value.replace(/[A-Z]+/g, function(key) {
  2075. return replace(lookup[key]);
  2076. });
  2077. };
  2078. // Unpack lookup
  2079. for (key in lookup) {
  2080. if (lookup.hasOwnProperty(key))
  2081. lookup[key] = replace(lookup[key]);
  2082. }
  2083. // Unpack and parse data into object map
  2084. replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]\[([^\]]*)\]/g, function(str, name, attributes, children) {
  2085. attributes = split(attributes, '|');
  2086. elements[name] = {
  2087. attributes : makeMap(attributes),
  2088. attributesOrder : attributes,
  2089. children : makeMap(children, '|', {'#comment' : {}})
  2090. }
  2091. });
  2092. return elements;
  2093. };
  2094. function getHTML5() {
  2095. var html5 = mapCache.html5;
  2096. if (!html5) {
  2097. html5 = mapCache.html5 = unpack({
  2098. A : 'id|accesskey|class|dir|draggable|item|hidden|itemprop|role|spellcheck|style|subject|title|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
  2099. B : '#|a|abbr|area|audio|b|bdo|br|button|canvas|cite|code|command|datalist|del|dfn|em|embed|i|iframe|img|input|ins|kbd|keygen|label|link|map|mark|meta|' +
  2100. 'meter|noscript|object|output|progress|q|ruby|samp|script|select|small|span|strong|sub|sup|svg|textarea|time|var|video|wbr',
  2101. C : '#|a|abbr|area|address|article|aside|audio|b|bdo|blockquote|br|button|canvas|cite|code|command|datalist|del|details|dfn|dialog|div|dl|em|embed|fieldset|' +
  2102. 'figure|footer|form|h1|h2|h3|h4|h5|h6|header|hgroup|hr|i|iframe|img|input|ins|kbd|keygen|label|link|map|mark|menu|meta|meter|nav|noscript|ol|object|output|' +
  2103. 'p|pre|progress|q|ruby|samp|script|section|select|small|span|strong|style|sub|sup|svg|table|textarea|time|ul|var|video'
  2104. }, 'html[A|manifest][body|head]' +
  2105. 'head[A][base|command|link|meta|noscript|script|style|title]' +
  2106. 'title[A][#]' +
  2107. 'base[A|href|target][]' +
  2108. 'link[A|href|rel|media|type|sizes][]' +
  2109. 'meta[A|http-equiv|name|content|charset][]' +
  2110. 'style[A|type|media|scoped][#]' +
  2111. 'script[A|charset|type|src|defer|async][#]' +
  2112. 'noscript[A][C]' +
  2113. 'body[A][C]' +
  2114. 'section[A][C]' +
  2115. 'nav[A][C]' +
  2116. 'article[A][C]' +
  2117. 'aside[A][C]' +
  2118. 'h1[A][B]' +
  2119. 'h2[A][B]' +
  2120. 'h3[A][B]' +
  2121. 'h4[A][B]' +
  2122. 'h5[A][B]' +
  2123. 'h6[A][B]' +
  2124. 'hgroup[A][h1|h2|h3|h4|h5|h6]' +
  2125. 'header[A][C]' +
  2126. 'footer[A][C]' +
  2127. 'address[A][C]' +
  2128. 'p[A][B]' +
  2129. 'br[A][]' +
  2130. 'pre[A][B]' +
  2131. 'dialog[A][dd|dt]' +
  2132. 'blockquote[A|cite][C]' +
  2133. 'ol[A|start|reversed][li]' +
  2134. 'ul[A][li]' +
  2135. 'li[A|value][C]' +
  2136. 'dl[A][dd|dt]' +
  2137. 'dt[A][B]' +
  2138. 'dd[A][C]' +
  2139. 'a[A|href|target|ping|rel|media|type][B]' +
  2140. 'em[A][B]' +
  2141. 'strong[A][B]' +
  2142. 'small[A][B]' +
  2143. 'cite[A][B]' +
  2144. 'q[A|cite][B]' +
  2145. 'dfn[A][B]' +
  2146. 'abbr[A][B]' +
  2147. 'code[A][B]' +
  2148. 'var[A][B]' +
  2149. 'samp[A][B]' +
  2150. 'kbd[A][B]' +
  2151. 'sub[A][B]' +
  2152. 'sup[A][B]' +
  2153. 'i[A][B]' +
  2154. 'b[A][B]' +
  2155. 'mark[A][B]' +
  2156. 'progress[A|value|max][B]' +
  2157. 'meter[A|value|min|max|low|high|optimum][B]' +
  2158. 'time[A|datetime][B]' +
  2159. 'ruby[A][B|rt|rp]' +
  2160. 'rt[A][B]' +
  2161. 'rp[A][B]' +
  2162. 'bdo[A][B]' +
  2163. 'span[A][B]' +
  2164. 'ins[A|cite|datetime][B]' +
  2165. 'del[A|cite|datetime][B]' +
  2166. 'figure[A][C|legend|figcaption]' +
  2167. 'figcaption[A][C]' +
  2168. 'img[A|alt|src|height|width|usemap|ismap][]' +
  2169. 'iframe[A|name|src|height|width|sandbox|seamless][]' +
  2170. 'embed[A|src|height|width|type][]' +
  2171. 'object[A|data|type|height|width|usemap|name|form|classid][param]' +
  2172. 'param[A|name|value][]' +
  2173. 'details[A|open][C|legend]' +
  2174. 'command[A|type|label|icon|disabled|checked|radiogroup][]' +
  2175. 'menu[A|type|label][C|li]' +
  2176. 'legend[A][C|B]' +
  2177. 'div[A][C]' +
  2178. 'source[A|src|type|media][]' +
  2179. 'audio[A|src|autobuffer|autoplay|loop|controls][source]' +
  2180. 'video[A|src|autobuffer|autoplay|loop|controls|width|height|poster][source]' +
  2181. 'hr[A][]' +
  2182. 'form[A|accept-charset|action|autocomplete|enctype|method|name|novalidate|target][C]' +
  2183. 'fieldset[A|disabled|form|name][C|legend]' +
  2184. 'label[A|form|for][B]' +
  2185. 'input[A|type|accept|alt|autocomplete|autofocus|checked|disabled|form|formaction|formenctype|formmethod|formnovalidate|formtarget|height|list|max|maxlength|min|' +
  2186. 'multiple|pattern|placeholder|readonly|required|size|src|step|width|files|value|name][]' +
  2187. 'button[A|autofocus|disabled|form|formaction|formenctype|formmethod|formnovalidate|formtarget|name|value|type][B]' +
  2188. 'select[A|autofocus|disabled|form|multiple|name|size][option|optgroup]' +
  2189. 'datalist[A][B|option]' +
  2190. 'optgroup[A|disabled|label][option]' +
  2191. 'option[A|disabled|selected|label|value][]' +
  2192. 'textarea[A|autofocus|disabled|form|maxlength|name|placeholder|readonly|required|rows|cols|wrap][]' +
  2193. 'keygen[A|autofocus|challenge|disabled|form|keytype|name][]' +
  2194. 'output[A|for|form|name][B]' +
  2195. 'canvas[A|width|height][]' +
  2196. 'map[A|name][B|C]' +
  2197. 'area[A|shape|coords|href|alt|target|media|rel|ping|type][]' +
  2198. 'mathml[A][]' +
  2199. 'svg[A][]' +
  2200. 'table[A|border][caption|colgroup|thead|tfoot|tbody|tr]' +
  2201. 'caption[A][C]' +
  2202. 'colgroup[A|span][col]' +
  2203. 'col[A|span][]' +
  2204. 'thead[A][tr]' +
  2205. 'tfoot[A][tr]' +
  2206. 'tbody[A][tr]' +
  2207. 'tr[A][th|td]' +
  2208. 'th[A|headers|rowspan|colspan|scope][B]' +
  2209. 'td[A|headers|rowspan|colspan][C]' +
  2210. 'wbr[A][]'
  2211. );
  2212. }
  2213. return html5;
  2214. };
  2215. function getHTML4() {
  2216. var html4 = mapCache.html4;
  2217. if (!html4) {
  2218. // This is the XHTML 1.0 transitional elements with it's attributes and children packed to reduce it's size
  2219. html4 = mapCache.html4 = unpack({
  2220. Z : 'H|K|N|O|P',
  2221. Y : 'X|form|R|Q',
  2222. ZG : 'E|span|width|align|char|charoff|valign',
  2223. X : 'p|T|div|U|W|isindex|fieldset|table',
  2224. ZF : 'E|align|char|charoff|valign',
  2225. W : 'pre|hr|blockquote|address|center|noframes',
  2226. ZE : 'abbr|axis|headers|scope|rowspan|colspan|align|char|charoff|valign|nowrap|bgcolor|width|height',
  2227. ZD : '[E][S]',
  2228. U : 'ul|ol|dl|menu|dir',
  2229. ZC : 'p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q',
  2230. T : 'h1|h2|h3|h4|h5|h6',
  2231. ZB : 'X|S|Q',
  2232. S : 'R|P',
  2233. ZA : 'a|G|J|M|O|P',
  2234. R : 'a|H|K|N|O',
  2235. Q : 'noscript|P',
  2236. P : 'ins|del|script',
  2237. O : 'input|select|textarea|label|button',
  2238. N : 'M|L',
  2239. M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym',
  2240. L : 'sub|sup',
  2241. K : 'J|I',
  2242. J : 'tt|i|b|u|s|strike',
  2243. I : 'big|small|font|basefont',
  2244. H : 'G|F',
  2245. G : 'br|span|bdo',
  2246. F : 'object|applet|img|map|iframe',
  2247. E : 'A|B|C',
  2248. D : 'accesskey|tabindex|onfocus|onblur',
  2249. C : 'onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
  2250. B : 'lang|xml:lang|dir',
  2251. A : 'id|class|style|title'
  2252. }, 'script[id|charset|type|language|src|defer|xml:space][]' +
  2253. 'style[B|id|type|media|title|xml:space][]' +
  2254. 'object[E|declare|classid|codebase|data|type|codetype|archive|standby|width|height|usemap|name|tabindex|align|border|hspace|vspace][#|param|Y]' +
  2255. 'param[id|name|value|valuetype|type][]' +
  2256. 'p[E|align][#|S]' +
  2257. 'a[E|D|charset|type|name|href|hreflang|rel|rev|shape|coords|target][#|Z]' +
  2258. 'br[A|clear][]' +
  2259. 'span[E][#|S]' +
  2260. 'bdo[A|C|B][#|S]' +
  2261. 'applet[A|codebase|archive|code|object|alt|name|width|height|align|hspace|vspace][#|param|Y]' +
  2262. 'h1[E|align][#|S]' +
  2263. 'img[E|src|alt|name|longdesc|width|height|usemap|ismap|align|border|hspace|vspace][]' +
  2264. 'map[B|C|A|name][X|form|Q|area]' +
  2265. 'h2[E|align][#|S]' +
  2266. 'iframe[A|longdesc|name|src|frameborder|marginwidth|marginheight|scrolling|align|width|height][#|Y]' +
  2267. 'h3[E|align][#|S]' +
  2268. 'tt[E][#|S]' +
  2269. 'i[E][#|S]' +
  2270. 'b[E][#|S]' +
  2271. 'u[E][#|S]' +
  2272. 's[E][#|S]' +
  2273. 'strike[E][#|S]' +
  2274. 'big[E][#|S]' +
  2275. 'small[E][#|S]' +
  2276. 'font[A|B|size|color|face][#|S]' +
  2277. 'basefont[id|size|color|face][]' +
  2278. 'em[E][#|S]' +
  2279. 'strong[E][#|S]' +
  2280. 'dfn[E][#|S]' +
  2281. 'code[E][#|S]' +
  2282. 'q[E|cite][#|S]' +
  2283. 'samp[E][#|S]' +
  2284. 'kbd[E][#|S]' +
  2285. 'var[E][#|S]' +
  2286. 'cite[E][#|S]' +
  2287. 'abbr[E][#|S]' +
  2288. 'acronym[E][#|S]' +
  2289. 'sub[E][#|S]' +
  2290. 'sup[E][#|S]' +
  2291. 'input[E|D|type|name|value|checked|disabled|readonly|size|maxlength|src|alt|usemap|onselect|onchange|accept|align][]' +
  2292. 'select[E|name|size|multiple|disabled|tabindex|onfocus|onblur|onchange][optgroup|option]' +
  2293. 'optgroup[E|disabled|label][option]' +
  2294. 'option[E|selected|disabled|label|value][]' +
  2295. 'textarea[E|D|name|rows|cols|disabled|readonly|onselect|onchange][]' +
  2296. 'label[E|for|accesskey|onfocus|onblur][#|S]' +
  2297. 'button[E|D|name|value|type|disabled][#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' +
  2298. 'h4[E|align][#|S]' +
  2299. 'ins[E|cite|datetime][#|Y]' +
  2300. 'h5[E|align][#|S]' +
  2301. 'del[E|cite|datetime][#|Y]' +
  2302. 'h6[E|align][#|S]' +
  2303. 'div[E|align][#|Y]' +
  2304. 'ul[E|type|compact][li]' +
  2305. 'li[E|type|value][#|Y]' +
  2306. 'ol[E|type|compact|start][li]' +
  2307. 'dl[E|compact][dt|dd]' +
  2308. 'dt[E][#|S]' +
  2309. 'dd[E][#|Y]' +
  2310. 'menu[E|compact][li]' +
  2311. 'dir[E|compact][li]' +
  2312. 'pre[E|width|xml:space][#|ZA]' +
  2313. 'hr[E|align|noshade|size|width][]' +
  2314. 'blockquote[E|cite][#|Y]' +
  2315. 'address[E][#|S|p]' +
  2316. 'center[E][#|Y]' +
  2317. 'noframes[E][#|Y]' +
  2318. 'isindex[A|B|prompt][]' +
  2319. 'fieldset[E][#|legend|Y]' +
  2320. 'legend[E|accesskey|align][#|S]' +
  2321. 'table[E|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor][caption|col|colgroup|thead|tfoot|tbody|tr]' +
  2322. 'caption[E|align][#|S]' +
  2323. 'col[ZG][]' +
  2324. 'colgroup[ZG][col]' +
  2325. 'thead[ZF][tr]' +
  2326. 'tr[ZF|bgcolor][th|td]' +
  2327. 'th[E|ZE][#|Y]' +
  2328. 'form[E|action|method|name|enctype|onsubmit|onreset|accept|accept-charset|target][#|X|R|Q]' +
  2329. 'noscript[E][#|Y]' +
  2330. 'td[E|ZE][#|Y]' +
  2331. 'tfoot[ZF][tr]' +
  2332. 'tbody[ZF][tr]' +
  2333. 'area[E|D|shape|coords|href|nohref|alt|target][]' +
  2334. 'base[id|href|target][]' +
  2335. 'body[E|onload|onunload|background|bgcolor|text|link|vlink|alink][#|Y]'
  2336. );
  2337. }
  2338. return html4;
  2339. };
  2340. tinymce.html.Schema = function(settings) {
  2341. var self = this, elements = {}, children = {}, patternElements = [], validStyles, schemaItems;
  2342. var whiteSpaceElementsMap, selfClosingElementsMap, shortEndedElementsMap, boolAttrMap, blockElementsMap, nonEmptyElementsMap, customElementsMap = {};
  2343. // Creates an lookup table map object for the specified option or the default value
  2344. function createLookupTable(option, default_value, extend) {
  2345. var value = settings[option];
  2346. if (!value) {
  2347. // Get cached default map or make it if needed
  2348. value = mapCache[option];
  2349. if (!value) {
  2350. value = makeMap(default_value, ' ', makeMap(default_value.toUpperCase(), ' '));
  2351. value = tinymce.extend(value, extend);
  2352. mapCache[option] = value;
  2353. }
  2354. } else {
  2355. // Create custom map
  2356. value = makeMap(value, ',', makeMap(value.toUpperCase(), ' '));
  2357. }
  2358. return value;
  2359. };
  2360. settings = settings || {};
  2361. schemaItems = settings.schema == "html5" ? getHTML5() : getHTML4();
  2362. // Allow all elements and attributes if verify_html is set to false
  2363. if (settings.verify_html === false)
  2364. settings.valid_elements = '*[*]';
  2365. // Build styles list
  2366. if (settings.valid_styles) {
  2367. validStyles = {};
  2368. // Convert styles into a rule list
  2369. each(settings.valid_styles, function(value, key) {
  2370. validStyles[key] = tinymce.explode(value);
  2371. });
  2372. }
  2373. // Setup map objects
  2374. whiteSpaceElementsMap = createLookupTable('whitespace_elements', 'pre script noscript style textarea');
  2375. selfClosingElementsMap = createLookupTable('self_closing_elements', 'colgroup dd dt li option p td tfoot th thead tr');
  2376. shortEndedElementsMap = createLookupTable('short_ended_elements', 'area base basefont br col frame hr img input isindex link meta param embed source wbr');
  2377. boolAttrMap = createLookupTable('boolean_attributes', 'checked compact declare defer disabled ismap multiple nohref noresize noshade nowrap readonly selected autoplay loop controls');
  2378. nonEmptyElementsMap = createLookupTable('non_empty_elements', 'td th iframe video audio object', shortEndedElementsMap);
  2379. textBlockElementsMap = createLookupTable('text_block_elements', 'h1 h2 h3 h4 h5 h6 p div address pre form ' +
  2380. 'blockquote center dir fieldset header footer article section hgroup aside nav figure');
  2381. blockElementsMap = createLookupTable('block_elements', 'hr table tbody thead tfoot ' +
  2382. 'th tr td li ol ul caption dl dt dd noscript menu isindex samp option datalist select optgroup', textBlockElementsMap);
  2383. // Converts a wildcard expression string to a regexp for example *a will become /.*a/.
  2384. function patternToRegExp(str) {
  2385. return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$');
  2386. };
  2387. // Parses the specified valid_elements string and adds to the current rules
  2388. // This function is a bit hard to read since it's heavily optimized for speed
  2389. function addValidElements(valid_elements) {
  2390. var ei, el, ai, al, yl, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder,
  2391. prefix, outputName, globalAttributes, globalAttributesOrder, transElement, key, childKey, value,
  2392. elementRuleRegExp = /^([#+\-])?([^\[\/]+)(?:\/([^\[]+))?(?:\[([^\]]+)\])?$/,
  2393. attrRuleRegExp = /^([!\-])?(\w+::\w+|[^=:<]+)?(?:([=:<])(.*))?$/,
  2394. hasPatternsRegExp = /[*?+]/;
  2395. if (valid_elements) {
  2396. // Split valid elements into an array with rules
  2397. valid_elements = split(valid_elements);
  2398. if (elements['@']) {
  2399. globalAttributes = elements['@'].attributes;
  2400. globalAttributesOrder = elements['@'].attributesOrder;
  2401. }
  2402. // Loop all rules
  2403. for (ei = 0, el = valid_elements.length; ei < el; ei++) {
  2404. // Parse element rule
  2405. matches = elementRuleRegExp.exec(valid_elements[ei]);
  2406. if (matches) {
  2407. // Setup local names for matches
  2408. prefix = matches[1];
  2409. elementName = matches[2];
  2410. outputName = matches[3];
  2411. attrData = matches[4];
  2412. // Create new attributes and attributesOrder
  2413. attributes = {};
  2414. attributesOrder = [];
  2415. // Create the new element
  2416. element = {
  2417. attributes : attributes,
  2418. attributesOrder : attributesOrder
  2419. };
  2420. // Padd empty elements prefix
  2421. if (prefix === '#')
  2422. element.paddEmpty = true;
  2423. // Remove empty elements prefix
  2424. if (prefix === '-')
  2425. element.removeEmpty = true;
  2426. // Copy attributes from global rule into current rule
  2427. if (globalAttributes) {
  2428. for (key in globalAttributes)
  2429. attributes[key] = globalAttributes[key];
  2430. attributesOrder.push.apply(attributesOrder, globalAttributesOrder);
  2431. }
  2432. // Attributes defined
  2433. if (attrData) {
  2434. attrData = split(attrData, '|');
  2435. for (ai = 0, al = attrData.length; ai < al; ai++) {
  2436. matches = attrRuleRegExp.exec(attrData[ai]);
  2437. if (matches) {
  2438. attr = {};
  2439. attrType = matches[1];
  2440. attrName = matches[2].replace(/::/g, ':');
  2441. prefix = matches[3];
  2442. value = matches[4];
  2443. // Required
  2444. if (attrType === '!') {
  2445. element.attributesRequired = element.attributesRequired || [];
  2446. element.attributesRequired.push(attrName);
  2447. attr.required = true;
  2448. }
  2449. // Denied from global
  2450. if (attrType === '-') {
  2451. delete attributes[attrName];
  2452. attributesOrder.splice(tinymce.inArray(attributesOrder, attrName), 1);
  2453. continue;
  2454. }
  2455. // Default value
  2456. if (prefix) {
  2457. // Default value
  2458. if (prefix === '=') {
  2459. element.attributesDefault = element.attributesDefault || [];
  2460. element.attributesDefault.push({name: attrName, value: value});
  2461. attr.defaultValue = value;
  2462. }
  2463. // Forced value
  2464. if (prefix === ':') {
  2465. element.attributesForced = element.attributesForced || [];
  2466. element.attributesForced.push({name: attrName, value: value});
  2467. attr.forcedValue = value;
  2468. }
  2469. // Required values
  2470. if (prefix === '<')
  2471. attr.validValues = makeMap(value, '?');
  2472. }
  2473. // Check for attribute patterns
  2474. if (hasPatternsRegExp.test(attrName)) {
  2475. element.attributePatterns = element.attributePatterns || [];
  2476. attr.pattern = patternToRegExp(attrName);
  2477. element.attributePatterns.push(attr);
  2478. } else {
  2479. // Add attribute to order list if it doesn't already exist
  2480. if (!attributes[attrName])
  2481. attributesOrder.push(attrName);
  2482. attributes[attrName] = attr;
  2483. }
  2484. }
  2485. }
  2486. }
  2487. // Global rule, store away these for later usage
  2488. if (!globalAttributes && elementName == '@') {
  2489. globalAttributes = attributes;
  2490. globalAttributesOrder = attributesOrder;
  2491. }
  2492. // Handle substitute elements such as b/strong
  2493. if (outputName) {
  2494. element.outputName = elementName;
  2495. elements[outputName] = element;
  2496. }
  2497. // Add pattern or exact element
  2498. if (hasPatternsRegExp.test(elementName)) {
  2499. element.pattern = patternToRegExp(elementName);
  2500. patternElements.push(element);
  2501. } else
  2502. elements[elementName] = element;
  2503. }
  2504. }
  2505. }
  2506. };
  2507. function setValidElements(valid_elements) {
  2508. elements = {};
  2509. patternElements = [];
  2510. addValidElements(valid_elements);
  2511. each(schemaItems, function(element, name) {
  2512. children[name] = element.children;
  2513. });
  2514. };
  2515. // Adds custom non HTML elements to the schema
  2516. function addCustomElements(custom_elements) {
  2517. var customElementRegExp = /^(~)?(.+)$/;
  2518. if (custom_elements) {
  2519. each(split(custom_elements), function(rule) {
  2520. var matches = customElementRegExp.exec(rule),
  2521. inline = matches[1] === '~',
  2522. cloneName = inline ? 'span' : 'div',
  2523. name = matches[2];
  2524. children[name] = children[cloneName];
  2525. customElementsMap[name] = cloneName;
  2526. // If it's not marked as inline then add it to valid block elements
  2527. if (!inline) {
  2528. blockElementsMap[name.toUpperCase()] = {};
  2529. blockElementsMap[name] = {};
  2530. }
  2531. // Add elements clone if needed
  2532. if (!elements[name]) {
  2533. elements[name] = elements[cloneName];
  2534. }
  2535. // Add custom elements at span/div positions
  2536. each(children, function(element, child) {
  2537. if (element[cloneName])
  2538. element[name] = element[cloneName];
  2539. });
  2540. });
  2541. }
  2542. };
  2543. // Adds valid children to the schema object
  2544. function addValidChildren(valid_children) {
  2545. var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/;
  2546. if (valid_children) {
  2547. each(split(valid_children), function(rule) {
  2548. var matches = childRuleRegExp.exec(rule), parent, prefix;
  2549. if (matches) {
  2550. prefix = matches[1];
  2551. // Add/remove items from default
  2552. if (prefix)
  2553. parent = children[matches[2]];
  2554. else
  2555. parent = children[matches[2]] = {'#comment' : {}};
  2556. parent = children[matches[2]];
  2557. each(split(matches[3], '|'), function(child) {
  2558. if (prefix === '-')
  2559. delete parent[child];
  2560. else
  2561. parent[child] = {};
  2562. });
  2563. }
  2564. });
  2565. }
  2566. };
  2567. function getElementRule(name) {
  2568. var element = elements[name], i;
  2569. // Exact match found
  2570. if (element)
  2571. return element;
  2572. // No exact match then try the patterns
  2573. i = patternElements.length;
  2574. while (i--) {
  2575. element = patternElements[i];
  2576. if (element.pattern.test(name))
  2577. return element;
  2578. }
  2579. };
  2580. if (!settings.valid_elements) {
  2581. // No valid elements defined then clone the elements from the schema spec
  2582. each(schemaItems, function(element, name) {
  2583. elements[name] = {
  2584. attributes : element.attributes,
  2585. attributesOrder : element.attributesOrder
  2586. };
  2587. children[name] = element.children;
  2588. });
  2589. // Switch these on HTML4
  2590. if (settings.schema != "html5") {
  2591. each(split('strong/b,em/i'), function(item) {
  2592. item = split(item, '/');
  2593. elements[item[1]].outputName = item[0];
  2594. });
  2595. }
  2596. // Add default alt attribute for images
  2597. elements.img.attributesDefault = [{name: 'alt', value: ''}];
  2598. // Remove these if they are empty by default
  2599. each(split('ol,ul,sub,sup,blockquote,span,font,a,table,tbody,tr,strong,em,b,i'), function(name) {
  2600. if (elements[name]) {
  2601. elements[name].removeEmpty = true;
  2602. }
  2603. });
  2604. // Padd these by default
  2605. each(split('p,h1,h2,h3,h4,h5,h6,th,td,pre,div,address,caption'), function(name) {
  2606. elements[name].paddEmpty = true;
  2607. });
  2608. } else
  2609. setValidElements(settings.valid_elements);
  2610. addCustomElements(settings.custom_elements);
  2611. addValidChildren(settings.valid_children);
  2612. addValidElements(settings.extended_valid_elements);
  2613. // Todo: Remove this when we fix list handling to be valid
  2614. addValidChildren('+ol[ul|ol],+ul[ul|ol]');
  2615. // Delete invalid elements
  2616. if (settings.invalid_elements) {
  2617. tinymce.each(tinymce.explode(settings.invalid_elements), function(item) {
  2618. if (elements[item])
  2619. delete elements[item];
  2620. });
  2621. }
  2622. // If the user didn't allow span only allow internal spans
  2623. if (!getElementRule('span'))
  2624. addValidElements('span[!data-mce-type|*]');
  2625. self.children = children;
  2626. self.styles = validStyles;
  2627. self.getBoolAttrs = function() {
  2628. return boolAttrMap;
  2629. };
  2630. self.getBlockElements = function() {
  2631. return blockElementsMap;
  2632. };
  2633. self.getTextBlockElements = function() {
  2634. return textBlockElementsMap;
  2635. };
  2636. self.getShortEndedElements = function() {
  2637. return shortEndedElementsMap;
  2638. };
  2639. self.getSelfClosingElements = function() {
  2640. return selfClosingElementsMap;
  2641. };
  2642. self.getNonEmptyElements = function() {
  2643. return nonEmptyElementsMap;
  2644. };
  2645. self.getWhiteSpaceElements = function() {
  2646. return whiteSpaceElementsMap;
  2647. };
  2648. self.isValidChild = function(name, child) {
  2649. var parent = children[name];
  2650. return !!(parent && parent[child]);
  2651. };
  2652. self.isValid = function(name, attr) {
  2653. var attrPatterns, i, rule = getElementRule(name);
  2654. // Check if it's a valid element
  2655. if (rule) {
  2656. if (attr) {
  2657. // Check if attribute name exists
  2658. if (rule.attributes[attr]) {
  2659. return true;
  2660. }
  2661. // Check if attribute matches a regexp pattern
  2662. attrPatterns = rule.attributePatterns;
  2663. if (attrPatterns) {
  2664. i = attrPatterns.length;
  2665. while (i--) {
  2666. if (attrPatterns[i].pattern.test(name)) {
  2667. return true;
  2668. }
  2669. }
  2670. }
  2671. } else {
  2672. return true;
  2673. }
  2674. }
  2675. // No match
  2676. return false;
  2677. };
  2678. self.getElementRule = getElementRule;
  2679. self.getCustomElements = function() {
  2680. return customElementsMap;
  2681. };
  2682. self.addValidElements = addValidElements;
  2683. self.setValidElements = setValidElements;
  2684. self.addCustomElements = addCustomElements;
  2685. self.addValidChildren = addValidChildren;
  2686. self.elements = elements;
  2687. };
  2688. })(tinymce);
  2689. (function(tinymce) {
  2690. tinymce.html.SaxParser = function(settings, schema) {
  2691. var self = this, noop = function() {};
  2692. settings = settings || {};
  2693. self.schema = schema = schema || new tinymce.html.Schema();
  2694. if (settings.fix_self_closing !== false)
  2695. settings.fix_self_closing = true;
  2696. // Add handler functions from settings and setup default handlers
  2697. tinymce.each('comment cdata text start end pi doctype'.split(' '), function(name) {
  2698. if (name)
  2699. self[name] = settings[name] || noop;
  2700. });
  2701. self.parse = function(html) {
  2702. var self = this, matches, index = 0, value, endRegExp, stack = [], attrList, i, text, name, isInternalElement, removeInternalElements,
  2703. shortEndedElements, fillAttrsMap, isShortEnded, validate, elementRule, isValidElement, attr, attribsValue, invalidPrefixRegExp,
  2704. validAttributesMap, validAttributePatterns, attributesRequired, attributesDefault, attributesForced, selfClosing,
  2705. tokenRegExp, attrRegExp, specialElements, attrValue, idCount = 0, decode = tinymce.html.Entities.decode, fixSelfClosing, isIE;
  2706. function processEndTag(name) {
  2707. var pos, i;
  2708. // Find position of parent of the same type
  2709. pos = stack.length;
  2710. while (pos--) {
  2711. if (stack[pos].name === name)
  2712. break;
  2713. }
  2714. // Found parent
  2715. if (pos >= 0) {
  2716. // Close all the open elements
  2717. for (i = stack.length - 1; i >= pos; i--) {
  2718. name = stack[i];
  2719. if (name.valid)
  2720. self.end(name.name);
  2721. }
  2722. // Remove the open elements from the stack
  2723. stack.length = pos;
  2724. }
  2725. };
  2726. function parseAttribute(match, name, value, val2, val3) {
  2727. var attrRule, i;
  2728. name = name.toLowerCase();
  2729. value = name in fillAttrsMap ? name : decode(value || val2 || val3 || ''); // Handle boolean attribute than value attribute
  2730. // Validate name and value
  2731. if (validate && !isInternalElement && name.indexOf('data-') !== 0) {
  2732. attrRule = validAttributesMap[name];
  2733. // Find rule by pattern matching
  2734. if (!attrRule && validAttributePatterns) {
  2735. i = validAttributePatterns.length;
  2736. while (i--) {
  2737. attrRule = validAttributePatterns[i];
  2738. if (attrRule.pattern.test(name))
  2739. break;
  2740. }
  2741. // No rule matched
  2742. if (i === -1)
  2743. attrRule = null;
  2744. }
  2745. // No attribute rule found
  2746. if (!attrRule)
  2747. return;
  2748. // Validate value
  2749. if (attrRule.validValues && !(value in attrRule.validValues))
  2750. return;
  2751. }
  2752. // Add attribute to list and map
  2753. attrList.map[name] = value;
  2754. attrList.push({
  2755. name: name,
  2756. value: value
  2757. });
  2758. };
  2759. // Precompile RegExps and map objects
  2760. tokenRegExp = new RegExp('<(?:' +
  2761. '(?:!--([\\w\\W]*?)-->)|' + // Comment
  2762. '(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|' + // CDATA
  2763. '(?:!DOCTYPE([\\w\\W]*?)>)|' + // DOCTYPE
  2764. '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' + // PI
  2765. '(?:\\/([^>]+)>)|' + // End element
  2766. '(?:([A-Za-z0-9\\-\\:\\.]+)((?:\\s+[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*|\\/|\\s+)>)' + // Start element
  2767. ')', 'g');
  2768. attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:[^\"])*)\")|(?:\'((?:[^\'])*)\')|([^>\s]+)))?/g;
  2769. specialElements = {
  2770. 'script' : /<\/script[^>]*>/gi,
  2771. 'style' : /<\/style[^>]*>/gi,
  2772. 'noscript' : /<\/noscript[^>]*>/gi
  2773. };
  2774. // Setup lookup tables for empty elements and boolean attributes
  2775. shortEndedElements = schema.getShortEndedElements();
  2776. selfClosing = settings.self_closing_elements || schema.getSelfClosingElements();
  2777. fillAttrsMap = schema.getBoolAttrs();
  2778. validate = settings.validate;
  2779. removeInternalElements = settings.remove_internals;
  2780. fixSelfClosing = settings.fix_self_closing;
  2781. isIE = tinymce.isIE;
  2782. invalidPrefixRegExp = /^:/;
  2783. while (matches = tokenRegExp.exec(html)) {
  2784. // Text
  2785. if (index < matches.index)
  2786. self.text(decode(html.substr(index, matches.index - index)));
  2787. if (value = matches[6]) { // End element
  2788. value = value.toLowerCase();
  2789. // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
  2790. if (isIE && invalidPrefixRegExp.test(value))
  2791. value = value.substr(1);
  2792. processEndTag(value);
  2793. } else if (value = matches[7]) { // Start element
  2794. value = value.toLowerCase();
  2795. // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
  2796. if (isIE && invalidPrefixRegExp.test(value))
  2797. value = value.substr(1);
  2798. isShortEnded = value in shortEndedElements;
  2799. // Is self closing tag for example an <li> after an open <li>
  2800. if (fixSelfClosing && selfClosing[value] && stack.length > 0 && stack[stack.length - 1].name === value)
  2801. processEndTag(value);
  2802. // Validate element
  2803. if (!validate || (elementRule = schema.getElementRule(value))) {
  2804. isValidElement = true;
  2805. // Grab attributes map and patters when validation is enabled
  2806. if (validate) {
  2807. validAttributesMap = elementRule.attributes;
  2808. validAttributePatterns = elementRule.attributePatterns;
  2809. }
  2810. // Parse attributes
  2811. if (attribsValue = matches[8]) {
  2812. isInternalElement = attribsValue.indexOf('data-mce-type') !== -1; // Check if the element is an internal element
  2813. // If the element has internal attributes then remove it if we are told to do so
  2814. if (isInternalElement && removeInternalElements)
  2815. isValidElement = false;
  2816. attrList = [];
  2817. attrList.map = {};
  2818. attribsValue.replace(attrRegExp, parseAttribute);
  2819. } else {
  2820. attrList = [];
  2821. attrList.map = {};
  2822. }
  2823. // Process attributes if validation is enabled
  2824. if (validate && !isInternalElement) {
  2825. attributesRequired = elementRule.attributesRequired;
  2826. attributesDefault = elementRule.attributesDefault;
  2827. attributesForced = elementRule.attributesForced;
  2828. // Handle forced attributes
  2829. if (attributesForced) {
  2830. i = attributesForced.length;
  2831. while (i--) {
  2832. attr = attributesForced[i];
  2833. name = attr.name;
  2834. attrValue = attr.value;
  2835. if (attrValue === '{$uid}')
  2836. attrValue = 'mce_' + idCount++;
  2837. attrList.map[name] = attrValue;
  2838. attrList.push({name: name, value: attrValue});
  2839. }
  2840. }
  2841. // Handle default attributes
  2842. if (attributesDefault) {
  2843. i = attributesDefault.length;
  2844. while (i--) {
  2845. attr = attributesDefault[i];
  2846. name = attr.name;
  2847. if (!(name in attrList.map)) {
  2848. attrValue = attr.value;
  2849. if (attrValue === '{$uid}')
  2850. attrValue = 'mce_' + idCount++;
  2851. attrList.map[name] = attrValue;
  2852. attrList.push({name: name, value: attrValue});
  2853. }
  2854. }
  2855. }
  2856. // Handle required attributes
  2857. if (attributesRequired) {
  2858. i = attributesRequired.length;
  2859. while (i--) {
  2860. if (attributesRequired[i] in attrList.map)
  2861. break;
  2862. }
  2863. // None of the required attributes where found
  2864. if (i === -1)
  2865. isValidElement = false;
  2866. }
  2867. // Invalidate element if it's marked as bogus
  2868. if (attrList.map['data-mce-bogus'])
  2869. isValidElement = false;
  2870. }
  2871. if (isValidElement)
  2872. self.start(value, attrList, isShortEnded);
  2873. } else
  2874. isValidElement = false;
  2875. // Treat script, noscript and style a bit different since they may include code that looks like elements
  2876. if (endRegExp = specialElements[value]) {
  2877. endRegExp.lastIndex = index = matches.index + matches[0].length;
  2878. if (matches = endRegExp.exec(html)) {
  2879. if (isValidElement)
  2880. text = html.substr(index, matches.index - index);
  2881. index = matches.index + matches[0].length;
  2882. } else {
  2883. text = html.substr(index);
  2884. index = html.length;
  2885. }
  2886. if (isValidElement && text.length > 0)
  2887. self.text(text, true);
  2888. if (isValidElement)
  2889. self.end(value);
  2890. tokenRegExp.lastIndex = index;
  2891. continue;
  2892. }
  2893. // Push value on to stack
  2894. if (!isShortEnded) {
  2895. if (!attribsValue || attribsValue.indexOf('/') != attribsValue.length - 1)
  2896. stack.push({name: value, valid: isValidElement});
  2897. else if (isValidElement)
  2898. self.end(value);
  2899. }
  2900. } else if (value = matches[1]) { // Comment
  2901. self.comment(value);
  2902. } else if (value = matches[2]) { // CDATA
  2903. self.cdata(value);
  2904. } else if (value = matches[3]) { // DOCTYPE
  2905. self.doctype(value);
  2906. } else if (value = matches[4]) { // PI
  2907. self.pi(value, matches[5]);
  2908. }
  2909. index = matches.index + matches[0].length;
  2910. }
  2911. // Text
  2912. if (index < html.length)
  2913. self.text(decode(html.substr(index)));
  2914. // Close any open elements
  2915. for (i = stack.length - 1; i >= 0; i--) {
  2916. value = stack[i];
  2917. if (value.valid)
  2918. self.end(value.name);
  2919. }
  2920. };
  2921. }
  2922. })(tinymce);
  2923. (function(tinymce) {
  2924. var whiteSpaceRegExp = /^[ \t\r\n]*$/, typeLookup = {
  2925. '#text' : 3,
  2926. '#comment' : 8,
  2927. '#cdata' : 4,
  2928. '#pi' : 7,
  2929. '#doctype' : 10,
  2930. '#document-fragment' : 11
  2931. };
  2932. // Walks the tree left/right
  2933. function walk(node, root_node, prev) {
  2934. var sibling, parent, startName = prev ? 'lastChild' : 'firstChild', siblingName = prev ? 'prev' : 'next';
  2935. // Walk into nodes if it has a start
  2936. if (node[startName])
  2937. return node[startName];
  2938. // Return the sibling if it has one
  2939. if (node !== root_node) {
  2940. sibling = node[siblingName];
  2941. if (sibling)
  2942. return sibling;
  2943. // Walk up the parents to look for siblings
  2944. for (parent = node.parent; parent && parent !== root_node; parent = parent.parent) {
  2945. sibling = parent[siblingName];
  2946. if (sibling)
  2947. return sibling;
  2948. }
  2949. }
  2950. };
  2951. function Node(name, type) {
  2952. this.name = name;
  2953. this.type = type;
  2954. if (type === 1) {
  2955. this.attributes = [];
  2956. this.attributes.map = {};
  2957. }
  2958. }
  2959. tinymce.extend(Node.prototype, {
  2960. replace : function(node) {
  2961. var self = this;
  2962. if (node.parent)
  2963. node.remove();
  2964. self.insert(node, self);
  2965. self.remove();
  2966. return self;
  2967. },
  2968. attr : function(name, value) {
  2969. var self = this, attrs, i, undef;
  2970. if (typeof name !== "string") {
  2971. for (i in name)
  2972. self.attr(i, name[i]);
  2973. return self;
  2974. }
  2975. if (attrs = self.attributes) {
  2976. if (value !== undef) {
  2977. // Remove attribute
  2978. if (value === null) {
  2979. if (name in attrs.map) {
  2980. delete attrs.map[name];
  2981. i = attrs.length;
  2982. while (i--) {
  2983. if (attrs[i].name === name) {
  2984. attrs = attrs.splice(i, 1);
  2985. return self;
  2986. }
  2987. }
  2988. }
  2989. return self;
  2990. }
  2991. // Set attribute
  2992. if (name in attrs.map) {
  2993. // Set attribute
  2994. i = attrs.length;
  2995. while (i--) {
  2996. if (attrs[i].name === name) {
  2997. attrs[i].value = value;
  2998. break;
  2999. }
  3000. }
  3001. } else
  3002. attrs.push({name: name, value: value});
  3003. attrs.map[name] = value;
  3004. return self;
  3005. } else {
  3006. return attrs.map[name];
  3007. }
  3008. }
  3009. },
  3010. clone : function() {
  3011. var self = this, clone = new Node(self.name, self.type), i, l, selfAttrs, selfAttr, cloneAttrs;
  3012. // Clone element attributes
  3013. if (selfAttrs = self.attributes) {
  3014. cloneAttrs = [];
  3015. cloneAttrs.map = {};
  3016. for (i = 0, l = selfAttrs.length; i < l; i++) {
  3017. selfAttr = selfAttrs[i];
  3018. // Clone everything except id
  3019. if (selfAttr.name !== 'id') {
  3020. cloneAttrs[cloneAttrs.length] = {name: selfAttr.name, value: selfAttr.value};
  3021. cloneAttrs.map[selfAttr.name] = selfAttr.value;
  3022. }
  3023. }
  3024. clone.attributes = cloneAttrs;
  3025. }
  3026. clone.value = self.value;
  3027. clone.shortEnded = self.shortEnded;
  3028. return clone;
  3029. },
  3030. wrap : function(wrapper) {
  3031. var self = this;
  3032. self.parent.insert(wrapper, self);
  3033. wrapper.append(self);
  3034. return self;
  3035. },
  3036. unwrap : function() {
  3037. var self = this, node, next;
  3038. for (node = self.firstChild; node; ) {
  3039. next = node.next;
  3040. self.insert(node, self, true);
  3041. node = next;
  3042. }
  3043. self.remove();
  3044. },
  3045. remove : function() {
  3046. var self = this, parent = self.parent, next = self.next, prev = self.prev;
  3047. if (parent) {
  3048. if (parent.firstChild === self) {
  3049. parent.firstChild = next;
  3050. if (next)
  3051. next.prev = null;
  3052. } else {
  3053. prev.next = next;
  3054. }
  3055. if (parent.lastChild === self) {
  3056. parent.lastChild = prev;
  3057. if (prev)
  3058. prev.next = null;
  3059. } else {
  3060. next.prev = prev;
  3061. }
  3062. self.parent = self.next = self.prev = null;
  3063. }
  3064. return self;
  3065. },
  3066. append : function(node) {
  3067. var self = this, last;
  3068. if (node.parent)
  3069. node.remove();
  3070. last = self.lastChild;
  3071. if (last) {
  3072. last.next = node;
  3073. node.prev = last;
  3074. self.lastChild = node;
  3075. } else
  3076. self.lastChild = self.firstChild = node;
  3077. node.parent = self;
  3078. return node;
  3079. },
  3080. insert : function(node, ref_node, before) {
  3081. var parent;
  3082. if (node.parent)
  3083. node.remove();
  3084. parent = ref_node.parent || this;
  3085. if (before) {
  3086. if (ref_node === parent.firstChild)
  3087. parent.firstChild = node;
  3088. else
  3089. ref_node.prev.next = node;
  3090. node.prev = ref_node.prev;
  3091. node.next = ref_node;
  3092. ref_node.prev = node;
  3093. } else {
  3094. if (ref_node === parent.lastChild)
  3095. parent.lastChild = node;
  3096. else
  3097. ref_node.next.prev = node;
  3098. node.next = ref_node.next;
  3099. node.prev = ref_node;
  3100. ref_node.next = node;
  3101. }
  3102. node.parent = parent;
  3103. return node;
  3104. },
  3105. getAll : function(name) {
  3106. var self = this, node, collection = [];
  3107. for (node = self.firstChild; node; node = walk(node, self)) {
  3108. if (node.name === name)
  3109. collection.push(node);
  3110. }
  3111. return collection;
  3112. },
  3113. empty : function() {
  3114. var self = this, nodes, i, node;
  3115. // Remove all children
  3116. if (self.firstChild) {
  3117. nodes = [];
  3118. // Collect the children
  3119. for (node = self.firstChild; node; node = walk(node, self))
  3120. nodes.push(node);
  3121. // Remove the children
  3122. i = nodes.length;
  3123. while (i--) {
  3124. node = nodes[i];
  3125. node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;
  3126. }
  3127. }
  3128. self.firstChild = self.lastChild = null;
  3129. return self;
  3130. },
  3131. isEmpty : function(elements) {
  3132. var self = this, node = self.firstChild, i, name;
  3133. if (node) {
  3134. do {
  3135. if (node.type === 1) {
  3136. // Ignore bogus elements
  3137. if (node.attributes.map['data-mce-bogus'])
  3138. continue;
  3139. // Keep empty elements like <img />
  3140. if (elements[node.name])
  3141. return false;
  3142. // Keep elements with data attributes or name attribute like <a name="1"></a>
  3143. i = node.attributes.length;
  3144. while (i--) {
  3145. name = node.attributes[i].name;
  3146. if (name === "name" || name.indexOf('data-mce-') === 0)
  3147. return false;
  3148. }
  3149. }
  3150. // Keep comments
  3151. if (node.type === 8)
  3152. return false;
  3153. // Keep non whitespace text nodes
  3154. if ((node.type === 3 && !whiteSpaceRegExp.test(node.value)))
  3155. return false;
  3156. } while (node = walk(node, self));
  3157. }
  3158. return true;
  3159. },
  3160. walk : function(prev) {
  3161. return walk(this, null, prev);
  3162. }
  3163. });
  3164. tinymce.extend(Node, {
  3165. create : function(name, attrs) {
  3166. var node, attrName;
  3167. // Create node
  3168. node = new Node(name, typeLookup[name] || 1);
  3169. // Add attributes if needed
  3170. if (attrs) {
  3171. for (attrName in attrs)
  3172. node.attr(attrName, attrs[attrName]);
  3173. }
  3174. return node;
  3175. }
  3176. });
  3177. tinymce.html.Node = Node;
  3178. })(tinymce);
  3179. (function(tinymce) {
  3180. var Node = tinymce.html.Node;
  3181. tinymce.html.DomParser = function(settings, schema) {
  3182. var self = this, nodeFilters = {}, attributeFilters = [], matchedNodes = {}, matchedAttributes = {};
  3183. settings = settings || {};
  3184. settings.validate = "validate" in settings ? settings.validate : true;
  3185. settings.root_name = settings.root_name || 'body';
  3186. self.schema = schema = schema || new tinymce.html.Schema();
  3187. function fixInvalidChildren(nodes) {
  3188. var ni, node, parent, parents, newParent, currentNode, tempNode, childNode, i,
  3189. childClone, nonEmptyElements, nonSplitableElements, textBlockElements, sibling, nextNode;
  3190. nonSplitableElements = tinymce.makeMap('tr,td,th,tbody,thead,tfoot,table');
  3191. nonEmptyElements = schema.getNonEmptyElements();
  3192. textBlockElements = schema.getTextBlockElements();
  3193. for (ni = 0; ni < nodes.length; ni++) {
  3194. node = nodes[ni];
  3195. // Already removed or fixed
  3196. if (!node.parent || node.fixed)
  3197. continue;
  3198. // If the invalid element is a text block and the text block is within a parent LI element
  3199. // Then unwrap the first text block and convert other sibling text blocks to LI elements similar to Word/Open Office
  3200. if (textBlockElements[node.name] && node.parent.name == 'li') {
  3201. // Move sibling text blocks after LI element
  3202. sibling = node.next;
  3203. while (sibling) {
  3204. if (textBlockElements[sibling.name]) {
  3205. sibling.name = 'li';
  3206. sibling.fixed = true;
  3207. node.parent.insert(sibling, node.parent);
  3208. } else {
  3209. break;
  3210. }
  3211. sibling = sibling.next;
  3212. }
  3213. // Unwrap current text block
  3214. node.unwrap(node);
  3215. continue;
  3216. }
  3217. // Get list of all parent nodes until we find a valid parent to stick the child into
  3218. parents = [node];
  3219. for (parent = node.parent; parent && !schema.isValidChild(parent.name, node.name) && !nonSplitableElements[parent.name]; parent = parent.parent)
  3220. parents.push(parent);
  3221. // Found a suitable parent
  3222. if (parent && parents.length > 1) {
  3223. // Reverse the array since it makes looping easier
  3224. parents.reverse();
  3225. // Clone the related parent and insert that after the moved node
  3226. newParent = currentNode = self.filterNode(parents[0].clone());
  3227. // Start cloning and moving children on the left side of the target node
  3228. for (i = 0; i < parents.length - 1; i++) {
  3229. if (schema.isValidChild(currentNode.name, parents[i].name)) {
  3230. tempNode = self.filterNode(parents[i].clone());
  3231. currentNode.append(tempNode);
  3232. } else
  3233. tempNode = currentNode;
  3234. for (childNode = parents[i].firstChild; childNode && childNode != parents[i + 1]; ) {
  3235. nextNode = childNode.next;
  3236. tempNode.append(childNode);
  3237. childNode = nextNode;
  3238. }
  3239. currentNode = tempNode;
  3240. }
  3241. if (!newParent.isEmpty(nonEmptyElements)) {
  3242. parent.insert(newParent, parents[0], true);
  3243. parent.insert(node, newParent);
  3244. } else {
  3245. parent.insert(node, parents[0], true);
  3246. }
  3247. // Check if the element is empty by looking through it's contents and special treatment for <p><br /></p>
  3248. parent = parents[0];
  3249. if (parent.isEmpty(nonEmptyElements) || parent.firstChild === parent.lastChild && parent.firstChild.name === 'br') {
  3250. parent.empty().remove();
  3251. }
  3252. } else if (node.parent) {
  3253. // If it's an LI try to find a UL/OL for it or wrap it
  3254. if (node.name === 'li') {
  3255. sibling = node.prev;
  3256. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  3257. sibling.append(node);
  3258. continue;
  3259. }
  3260. sibling = node.next;
  3261. if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
  3262. sibling.insert(node, sibling.firstChild, true);
  3263. continue;
  3264. }
  3265. node.wrap(self.filterNode(new Node('ul', 1)));
  3266. continue;
  3267. }
  3268. // Try wrapping the element in a DIV
  3269. if (schema.isValidChild(node.parent.name, 'div') && schema.isValidChild('div', node.name)) {
  3270. node.wrap(self.filterNode(new Node('div', 1)));
  3271. } else {
  3272. // We failed wrapping it, then remove or unwrap it
  3273. if (node.name === 'style' || node.name === 'script')
  3274. node.empty().remove();
  3275. else
  3276. node.unwrap();
  3277. }
  3278. }
  3279. }
  3280. };
  3281. self.filterNode = function(node) {
  3282. var i, name, list;
  3283. // Run element filters
  3284. if (name in nodeFilters) {
  3285. list = matchedNodes[name];
  3286. if (list)
  3287. list.push(node);
  3288. else
  3289. matchedNodes[name] = [node];
  3290. }
  3291. // Run attribute filters
  3292. i = attributeFilters.length;
  3293. while (i--) {
  3294. name = attributeFilters[i].name;
  3295. if (name in node.attributes.map) {
  3296. list = matchedAttributes[name];
  3297. if (list)
  3298. list.push(node);
  3299. else
  3300. matchedAttributes[name] = [node];
  3301. }
  3302. }
  3303. return node;
  3304. };
  3305. self.addNodeFilter = function(name, callback) {
  3306. tinymce.each(tinymce.explode(name), function(name) {
  3307. var list = nodeFilters[name];
  3308. if (!list)
  3309. nodeFilters[name] = list = [];
  3310. list.push(callback);
  3311. });
  3312. };
  3313. self.addAttributeFilter = function(name, callback) {
  3314. tinymce.each(tinymce.explode(name), function(name) {
  3315. var i;
  3316. for (i = 0; i < attributeFilters.length; i++) {
  3317. if (attributeFilters[i].name === name) {
  3318. attributeFilters[i].callbacks.push(callback);
  3319. return;
  3320. }
  3321. }
  3322. attributeFilters.push({name: name, callbacks: [callback]});
  3323. });
  3324. };
  3325. self.parse = function(html, args) {
  3326. var parser, rootNode, node, nodes, i, l, fi, fl, list, name, validate,
  3327. blockElements, startWhiteSpaceRegExp, invalidChildren = [], isInWhiteSpacePreservedElement,
  3328. endWhiteSpaceRegExp, allWhiteSpaceRegExp, isAllWhiteSpaceRegExp, whiteSpaceElements, children, nonEmptyElements, rootBlockName;
  3329. args = args || {};
  3330. matchedNodes = {};
  3331. matchedAttributes = {};
  3332. blockElements = tinymce.extend(tinymce.makeMap('script,style,head,html,body,title,meta,param'), schema.getBlockElements());
  3333. nonEmptyElements = schema.getNonEmptyElements();
  3334. children = schema.children;
  3335. validate = settings.validate;
  3336. rootBlockName = "forced_root_block" in args ? args.forced_root_block : settings.forced_root_block;
  3337. whiteSpaceElements = schema.getWhiteSpaceElements();
  3338. startWhiteSpaceRegExp = /^[ \t\r\n]+/;
  3339. endWhiteSpaceRegExp = /[ \t\r\n]+$/;
  3340. allWhiteSpaceRegExp = /[ \t\r\n]+/g;
  3341. isAllWhiteSpaceRegExp = /^[ \t\r\n]+$/;
  3342. function addRootBlocks() {
  3343. var node = rootNode.firstChild, next, rootBlockNode;
  3344. while (node) {
  3345. next = node.next;
  3346. if (node.type == 3 || (node.type == 1 && node.name !== 'p' && !blockElements[node.name] && !node.attr('data-mce-type'))) {
  3347. if (!rootBlockNode) {
  3348. // Create a new root block element
  3349. rootBlockNode = createNode(rootBlockName, 1);
  3350. rootNode.insert(rootBlockNode, node);
  3351. rootBlockNode.append(node);
  3352. } else
  3353. rootBlockNode.append(node);
  3354. } else {
  3355. rootBlockNode = null;
  3356. }
  3357. node = next;
  3358. };
  3359. };
  3360. function createNode(name, type) {
  3361. var node = new Node(name, type), list;
  3362. if (name in nodeFilters) {
  3363. list = matchedNodes[name];
  3364. if (list)
  3365. list.push(node);
  3366. else
  3367. matchedNodes[name] = [node];
  3368. }
  3369. return node;
  3370. };
  3371. function removeWhitespaceBefore(node) {
  3372. var textNode, textVal, sibling;
  3373. for (textNode = node.prev; textNode && textNode.type === 3; ) {
  3374. textVal = textNode.value.replace(endWhiteSpaceRegExp, '');
  3375. if (textVal.length > 0) {
  3376. textNode.value = textVal;
  3377. textNode = textNode.prev;
  3378. } else {
  3379. sibling = textNode.prev;
  3380. textNode.remove();
  3381. textNode = sibling;
  3382. }
  3383. }
  3384. };
  3385. function cloneAndExcludeBlocks(input) {
  3386. var name, output = {};
  3387. for (name in input) {
  3388. if (name !== 'li' && name != 'p') {
  3389. output[name] = input[name];
  3390. }
  3391. }
  3392. return output;
  3393. };
  3394. parser = new tinymce.html.SaxParser({
  3395. validate : validate,
  3396. // Exclude P and LI from DOM parsing since it's treated better by the DOM parser
  3397. self_closing_elements: cloneAndExcludeBlocks(schema.getSelfClosingElements()),
  3398. cdata: function(text) {
  3399. node.append(createNode('#cdata', 4)).value = text;
  3400. },
  3401. text: function(text, raw) {
  3402. var textNode;
  3403. // Trim all redundant whitespace on non white space elements
  3404. if (!isInWhiteSpacePreservedElement) {
  3405. text = text.replace(allWhiteSpaceRegExp, ' ');
  3406. if (node.lastChild && blockElements[node.lastChild.name])
  3407. text = text.replace(startWhiteSpaceRegExp, '');
  3408. }
  3409. // Do we need to create the node
  3410. if (text.length !== 0) {
  3411. textNode = createNode('#text', 3);
  3412. textNode.raw = !!raw;
  3413. node.append(textNode).value = text;
  3414. }
  3415. },
  3416. comment: function(text) {
  3417. node.append(createNode('#comment', 8)).value = text;
  3418. },
  3419. pi: function(name, text) {
  3420. node.append(createNode(name, 7)).value = text;
  3421. removeWhitespaceBefore(node);
  3422. },
  3423. doctype: function(text) {
  3424. var newNode;
  3425. newNode = node.append(createNode('#doctype', 10));
  3426. newNode.value = text;
  3427. removeWhitespaceBefore(node);
  3428. },
  3429. start: function(name, attrs, empty) {
  3430. var newNode, attrFiltersLen, elementRule, textNode, attrName, text, sibling, parent;
  3431. elementRule = validate ? schema.getElementRule(name) : {};
  3432. if (elementRule) {
  3433. newNode = createNode(elementRule.outputName || name, 1);
  3434. newNode.attributes = attrs;
  3435. newNode.shortEnded = empty;
  3436. node.append(newNode);
  3437. // Check if node is valid child of the parent node is the child is
  3438. // unknown we don't collect it since it's probably a custom element
  3439. parent = children[node.name];
  3440. if (parent && children[newNode.name] && !parent[newNode.name])
  3441. invalidChildren.push(newNode);
  3442. attrFiltersLen = attributeFilters.length;
  3443. while (attrFiltersLen--) {
  3444. attrName = attributeFilters[attrFiltersLen].name;
  3445. if (attrName in attrs.map) {
  3446. list = matchedAttributes[attrName];
  3447. if (list)
  3448. list.push(newNode);
  3449. else
  3450. matchedAttributes[attrName] = [newNode];
  3451. }
  3452. }
  3453. // Trim whitespace before block
  3454. if (blockElements[name])
  3455. removeWhitespaceBefore(newNode);
  3456. // Change current node if the element wasn't empty i.e not <br /> or <img />
  3457. if (!empty)
  3458. node = newNode;
  3459. // Check if we are inside a whitespace preserved element
  3460. if (!isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
  3461. isInWhiteSpacePreservedElement = true;
  3462. }
  3463. }
  3464. },
  3465. end: function(name) {
  3466. var textNode, elementRule, text, sibling, tempNode;
  3467. elementRule = validate ? schema.getElementRule(name) : {};
  3468. if (elementRule) {
  3469. if (blockElements[name]) {
  3470. if (!isInWhiteSpacePreservedElement) {
  3471. // Trim whitespace of the first node in a block
  3472. textNode = node.firstChild;
  3473. if (textNode && textNode.type === 3) {
  3474. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  3475. // Any characters left after trim or should we remove it
  3476. if (text.length > 0) {
  3477. textNode.value = text;
  3478. textNode = textNode.next;
  3479. } else {
  3480. sibling = textNode.next;
  3481. textNode.remove();
  3482. textNode = sibling;
  3483. }
  3484. // Remove any pure whitespace siblings
  3485. while (textNode && textNode.type === 3) {
  3486. text = textNode.value;
  3487. sibling = textNode.next;
  3488. if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) {
  3489. textNode.remove();
  3490. textNode = sibling;
  3491. }
  3492. textNode = sibling;
  3493. }
  3494. }
  3495. // Trim whitespace of the last node in a block
  3496. textNode = node.lastChild;
  3497. if (textNode && textNode.type === 3) {
  3498. text = textNode.value.replace(endWhiteSpaceRegExp, '');
  3499. // Any characters left after trim or should we remove it
  3500. if (text.length > 0) {
  3501. textNode.value = text;
  3502. textNode = textNode.prev;
  3503. } else {
  3504. sibling = textNode.prev;
  3505. textNode.remove();
  3506. textNode = sibling;
  3507. }
  3508. // Remove any pure whitespace siblings
  3509. while (textNode && textNode.type === 3) {
  3510. text = textNode.value;
  3511. sibling = textNode.prev;
  3512. if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) {
  3513. textNode.remove();
  3514. textNode = sibling;
  3515. }
  3516. textNode = sibling;
  3517. }
  3518. }
  3519. }
  3520. // Trim start white space
  3521. // Removed due to: #5424
  3522. /*textNode = node.prev;
  3523. if (textNode && textNode.type === 3) {
  3524. text = textNode.value.replace(startWhiteSpaceRegExp, '');
  3525. if (text.length > 0)
  3526. textNode.value = text;
  3527. else
  3528. textNode.remove();
  3529. }*/
  3530. }
  3531. // Check if we exited a whitespace preserved element
  3532. if (isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
  3533. isInWhiteSpacePreservedElement = false;
  3534. }
  3535. // Handle empty nodes
  3536. if (elementRule.removeEmpty || elementRule.paddEmpty) {
  3537. if (node.isEmpty(nonEmptyElements)) {
  3538. if (elementRule.paddEmpty)
  3539. node.empty().append(new Node('#text', '3')).value = '\u00a0';
  3540. else {
  3541. // Leave nodes that have a name like <a name="name">
  3542. if (!node.attributes.map.name && !node.attributes.map.id) {
  3543. tempNode = node.parent;
  3544. node.empty().remove();
  3545. node = tempNode;
  3546. return;
  3547. }
  3548. }
  3549. }
  3550. }
  3551. node = node.parent;
  3552. }
  3553. }
  3554. }, schema);
  3555. rootNode = node = new Node(args.context || settings.root_name, 11);
  3556. parser.parse(html);
  3557. // Fix invalid children or report invalid children in a contextual parsing
  3558. if (validate && invalidChildren.length) {
  3559. if (!args.context)
  3560. fixInvalidChildren(invalidChildren);
  3561. else
  3562. args.invalid = true;
  3563. }
  3564. // Wrap nodes in the root into block elements if the root is body
  3565. if (rootBlockName && rootNode.name == 'body')
  3566. addRootBlocks();
  3567. // Run filters only when the contents is valid
  3568. if (!args.invalid) {
  3569. // Run node filters
  3570. for (name in matchedNodes) {
  3571. list = nodeFilters[name];
  3572. nodes = matchedNodes[name];
  3573. // Remove already removed children
  3574. fi = nodes.length;
  3575. while (fi--) {
  3576. if (!nodes[fi].parent)
  3577. nodes.splice(fi, 1);
  3578. }
  3579. for (i = 0, l = list.length; i < l; i++)
  3580. list[i](nodes, name, args);
  3581. }
  3582. // Run attribute filters
  3583. for (i = 0, l = attributeFilters.length; i < l; i++) {
  3584. list = attributeFilters[i];
  3585. if (list.name in matchedAttributes) {
  3586. nodes = matchedAttributes[list.name];
  3587. // Remove already removed children
  3588. fi = nodes.length;
  3589. while (fi--) {
  3590. if (!nodes[fi].parent)
  3591. nodes.splice(fi, 1);
  3592. }
  3593. for (fi = 0, fl = list.callbacks.length; fi < fl; fi++)
  3594. list.callbacks[fi](nodes, list.name, args);
  3595. }
  3596. }
  3597. }
  3598. return rootNode;
  3599. };
  3600. // Remove <br> at end of block elements Gecko and WebKit injects BR elements to
  3601. // make it possible to place the caret inside empty blocks. This logic tries to remove
  3602. // these elements and keep br elements that where intended to be there intact
  3603. if (settings.remove_trailing_brs) {
  3604. self.addNodeFilter('br', function(nodes, name) {
  3605. var i, l = nodes.length, node, blockElements = tinymce.extend({}, schema.getBlockElements()),
  3606. nonEmptyElements = schema.getNonEmptyElements(), parent, lastParent, prev, prevName;
  3607. // Remove brs from body element as well
  3608. blockElements.body = 1;
  3609. // Must loop forwards since it will otherwise remove all brs in <p>a<br><br><br></p>
  3610. for (i = 0; i < l; i++) {
  3611. node = nodes[i];
  3612. parent = node.parent;
  3613. if (blockElements[node.parent.name] && node === parent.lastChild) {
  3614. // Loop all nodes to the left of the current node and check for other BR elements
  3615. // excluding bookmarks since they are invisible
  3616. prev = node.prev;
  3617. while (prev) {
  3618. prevName = prev.name;
  3619. // Ignore bookmarks
  3620. if (prevName !== "span" || prev.attr('data-mce-type') !== 'bookmark') {
  3621. // Found a non BR element
  3622. if (prevName !== "br")
  3623. break;
  3624. // Found another br it's a <br><br> structure then don't remove anything
  3625. if (prevName === 'br') {
  3626. node = null;
  3627. break;
  3628. }
  3629. }
  3630. prev = prev.prev;
  3631. }
  3632. if (node) {
  3633. node.remove();
  3634. // Is the parent to be considered empty after we removed the BR
  3635. if (parent.isEmpty(nonEmptyElements)) {
  3636. elementRule = schema.getElementRule(parent.name);
  3637. // Remove or padd the element depending on schema rule
  3638. if (elementRule) {
  3639. if (elementRule.removeEmpty)
  3640. parent.remove();
  3641. else if (elementRule.paddEmpty)
  3642. parent.empty().append(new tinymce.html.Node('#text', 3)).value = '\u00a0';
  3643. }
  3644. }
  3645. }
  3646. } else {
  3647. // Replaces BR elements inside inline elements like <p><b><i><br></i></b></p> so they become <p><b><i>&nbsp;</i></b></p>
  3648. lastParent = node;
  3649. while (parent.firstChild === lastParent && parent.lastChild === lastParent) {
  3650. lastParent = parent;
  3651. if (blockElements[parent.name]) {
  3652. break;
  3653. }
  3654. parent = parent.parent;
  3655. }
  3656. if (lastParent === parent) {
  3657. textNode = new tinymce.html.Node('#text', 3);
  3658. textNode.value = '\u00a0';
  3659. node.replace(textNode);
  3660. }
  3661. }
  3662. }
  3663. });
  3664. }
  3665. // Force anchor names closed, unless the setting "allow_html_in_named_anchor" is explicitly included.
  3666. if (!settings.allow_html_in_named_anchor) {
  3667. self.addAttributeFilter('id,name', function(nodes, name) {
  3668. var i = nodes.length, sibling, prevSibling, parent, node;
  3669. while (i--) {
  3670. node = nodes[i];
  3671. if (node.name === 'a' && node.firstChild && !node.attr('href')) {
  3672. parent = node.parent;
  3673. // Move children after current node
  3674. sibling = node.lastChild;
  3675. do {
  3676. prevSibling = sibling.prev;
  3677. parent.insert(sibling, node);
  3678. sibling = prevSibling;
  3679. } while (sibling);
  3680. }
  3681. }
  3682. });
  3683. }
  3684. }
  3685. })(tinymce);
  3686. tinymce.html.Writer = function(settings) {
  3687. var html = [], indent, indentBefore, indentAfter, encode, htmlOutput;
  3688. settings = settings || {};
  3689. indent = settings.indent;
  3690. indentBefore = tinymce.makeMap(settings.indent_before || '');
  3691. indentAfter = tinymce.makeMap(settings.indent_after || '');
  3692. encode = tinymce.html.Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
  3693. htmlOutput = settings.element_format == "html";
  3694. return {
  3695. start: function(name, attrs, empty) {
  3696. var i, l, attr, value;
  3697. if (indent && indentBefore[name] && html.length > 0) {
  3698. value = html[html.length - 1];
  3699. if (value.length > 0 && value !== '\n')
  3700. html.push('\n');
  3701. }
  3702. html.push('<', name);
  3703. if (attrs) {
  3704. for (i = 0, l = attrs.length; i < l; i++) {
  3705. attr = attrs[i];
  3706. html.push(' ', attr.name, '="', encode(attr.value, true), '"');
  3707. }
  3708. }
  3709. if (!empty || htmlOutput)
  3710. html[html.length] = '>';
  3711. else
  3712. html[html.length] = ' />';
  3713. if (empty && indent && indentAfter[name] && html.length > 0) {
  3714. value = html[html.length - 1];
  3715. if (value.length > 0 && value !== '\n')
  3716. html.push('\n');
  3717. }
  3718. },
  3719. end: function(name) {
  3720. var value;
  3721. /*if (indent && indentBefore[name] && html.length > 0) {
  3722. value = html[html.length - 1];
  3723. if (value.length > 0 && value !== '\n')
  3724. html.push('\n');
  3725. }*/
  3726. html.push('</', name, '>');
  3727. if (indent && indentAfter[name] && html.length > 0) {
  3728. value = html[html.length - 1];
  3729. if (value.length > 0 && value !== '\n')
  3730. html.push('\n');
  3731. }
  3732. },
  3733. text: function(text, raw) {
  3734. if (text.length > 0)
  3735. html[html.length] = raw ? text : encode(text);
  3736. },
  3737. cdata: function(text) {
  3738. html.push('<![CDATA[', text, ']]>');
  3739. },
  3740. comment: function(text) {
  3741. html.push('<!--', text, '-->');
  3742. },
  3743. pi: function(name, text) {
  3744. if (text)
  3745. html.push('<?', name, ' ', text, '?>');
  3746. else
  3747. html.push('<?', name, '?>');
  3748. if (indent)
  3749. html.push('\n');
  3750. },
  3751. doctype: function(text) {
  3752. html.push('<!DOCTYPE', text, '>', indent ? '\n' : '');
  3753. },
  3754. reset: function() {
  3755. html.length = 0;
  3756. },
  3757. getContent: function() {
  3758. return html.join('').replace(/\n$/, '');
  3759. }
  3760. };
  3761. };
  3762. (function(tinymce) {
  3763. tinymce.html.Serializer = function(settings, schema) {
  3764. var self = this, writer = new tinymce.html.Writer(settings);
  3765. settings = settings || {};
  3766. settings.validate = "validate" in settings ? settings.validate : true;
  3767. self.schema = schema = schema || new tinymce.html.Schema();
  3768. self.writer = writer;
  3769. self.serialize = function(node) {
  3770. var handlers, validate;
  3771. validate = settings.validate;
  3772. handlers = {
  3773. // #text
  3774. 3: function(node, raw) {
  3775. writer.text(node.value, node.raw);
  3776. },
  3777. // #comment
  3778. 8: function(node) {
  3779. writer.comment(node.value);
  3780. },
  3781. // Processing instruction
  3782. 7: function(node) {
  3783. writer.pi(node.name, node.value);
  3784. },
  3785. // Doctype
  3786. 10: function(node) {
  3787. writer.doctype(node.value);
  3788. },
  3789. // CDATA
  3790. 4: function(node) {
  3791. writer.cdata(node.value);
  3792. },
  3793. // Document fragment
  3794. 11: function(node) {
  3795. if ((node = node.firstChild)) {
  3796. do {
  3797. walk(node);
  3798. } while (node = node.next);
  3799. }
  3800. }
  3801. };
  3802. writer.reset();
  3803. function walk(node) {
  3804. var handler = handlers[node.type], name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule;
  3805. if (!handler) {
  3806. name = node.name;
  3807. isEmpty = node.shortEnded;
  3808. attrs = node.attributes;
  3809. // Sort attributes
  3810. if (validate && attrs && attrs.length > 1) {
  3811. sortedAttrs = [];
  3812. sortedAttrs.map = {};
  3813. elementRule = schema.getElementRule(node.name);
  3814. for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
  3815. attrName = elementRule.attributesOrder[i];
  3816. if (attrName in attrs.map) {
  3817. attrValue = attrs.map[attrName];
  3818. sortedAttrs.map[attrName] = attrValue;
  3819. sortedAttrs.push({name: attrName, value: attrValue});
  3820. }
  3821. }
  3822. for (i = 0, l = attrs.length; i < l; i++) {
  3823. attrName = attrs[i].name;
  3824. if (!(attrName in sortedAttrs.map)) {
  3825. attrValue = attrs.map[attrName];
  3826. sortedAttrs.map[attrName] = attrValue;
  3827. sortedAttrs.push({name: attrName, value: attrValue});
  3828. }
  3829. }
  3830. attrs = sortedAttrs;
  3831. }
  3832. writer.start(node.name, attrs, isEmpty);
  3833. if (!isEmpty) {
  3834. if ((node = node.firstChild)) {
  3835. do {
  3836. walk(node);
  3837. } while (node = node.next);
  3838. }
  3839. writer.end(name);
  3840. }
  3841. } else
  3842. handler(node);
  3843. }
  3844. // Serialize element and treat all non elements as fragments
  3845. if (node.type == 1 && !settings.inner)
  3846. walk(node);
  3847. else
  3848. handlers[11](node);
  3849. return writer.getContent();
  3850. };
  3851. }
  3852. })(tinymce);
  3853. // JSLint defined globals
  3854. /*global tinymce:false, window:false */
  3855. tinymce.dom = {};
  3856. (function(namespace, expando) {
  3857. var w3cEventModel = !!document.addEventListener;
  3858. function addEvent(target, name, callback, capture) {
  3859. if (target.addEventListener) {
  3860. target.addEventListener(name, callback, capture || false);
  3861. } else if (target.attachEvent) {
  3862. target.attachEvent('on' + name, callback);
  3863. }
  3864. }
  3865. function removeEvent(target, name, callback, capture) {
  3866. if (target.removeEventListener) {
  3867. target.removeEventListener(name, callback, capture || false);
  3868. } else if (target.detachEvent) {
  3869. target.detachEvent('on' + name, callback);
  3870. }
  3871. }
  3872. function fix(original_event, data) {
  3873. var name, event = data || {};
  3874. // Dummy function that gets replaced on the delegation state functions
  3875. function returnFalse() {
  3876. return false;
  3877. }
  3878. // Dummy function that gets replaced on the delegation state functions
  3879. function returnTrue() {
  3880. return true;
  3881. }
  3882. // Copy all properties from the original event
  3883. for (name in original_event) {
  3884. // layerX/layerY is deprecated in Chrome and produces a warning
  3885. if (name !== "layerX" && name !== "layerY") {
  3886. event[name] = original_event[name];
  3887. }
  3888. }
  3889. // Normalize target IE uses srcElement
  3890. if (!event.target) {
  3891. event.target = event.srcElement || document;
  3892. }
  3893. // Add preventDefault method
  3894. event.preventDefault = function() {
  3895. event.isDefaultPrevented = returnTrue;
  3896. // Execute preventDefault on the original event object
  3897. if (original_event) {
  3898. if (original_event.preventDefault) {
  3899. original_event.preventDefault();
  3900. } else {
  3901. original_event.returnValue = false; // IE
  3902. }
  3903. }
  3904. };
  3905. // Add stopPropagation
  3906. event.stopPropagation = function() {
  3907. event.isPropagationStopped = returnTrue;
  3908. // Execute stopPropagation on the original event object
  3909. if (original_event) {
  3910. if (original_event.stopPropagation) {
  3911. original_event.stopPropagation();
  3912. } else {
  3913. original_event.cancelBubble = true; // IE
  3914. }
  3915. }
  3916. };
  3917. // Add stopImmediatePropagation
  3918. event.stopImmediatePropagation = function() {
  3919. event.isImmediatePropagationStopped = returnTrue;
  3920. event.stopPropagation();
  3921. };
  3922. // Add event delegation states
  3923. if (!event.isDefaultPrevented) {
  3924. event.isDefaultPrevented = returnFalse;
  3925. event.isPropagationStopped = returnFalse;
  3926. event.isImmediatePropagationStopped = returnFalse;
  3927. }
  3928. return event;
  3929. }
  3930. function bindOnReady(win, callback, event_utils) {
  3931. var doc = win.document, event = {type: 'ready'};
  3932. // Gets called when the DOM is ready
  3933. function readyHandler() {
  3934. if (!event_utils.domLoaded) {
  3935. event_utils.domLoaded = true;
  3936. callback(event);
  3937. }
  3938. }
  3939. // Page already loaded then fire it directly
  3940. if (doc.readyState == "complete") {
  3941. readyHandler();
  3942. return;
  3943. }
  3944. // Use W3C method
  3945. if (w3cEventModel) {
  3946. addEvent(win, 'DOMContentLoaded', readyHandler);
  3947. } else {
  3948. // Use IE method
  3949. addEvent(doc, "readystatechange", function() {
  3950. if (doc.readyState === "complete") {
  3951. removeEvent(doc, "readystatechange", arguments.callee);
  3952. readyHandler();
  3953. }
  3954. });
  3955. // Wait until we can scroll, when we can the DOM is initialized
  3956. if (doc.documentElement.doScroll && win === win.top) {
  3957. (function() {
  3958. try {
  3959. // If IE is used, use the trick by Diego Perini licensed under MIT by request to the author.
  3960. // http://javascript.nwbox.com/IEContentLoaded/
  3961. doc.documentElement.doScroll("left");
  3962. } catch (ex) {
  3963. setTimeout(arguments.callee, 0);
  3964. return;
  3965. }
  3966. readyHandler();
  3967. })();
  3968. }
  3969. }
  3970. // Fallback if any of the above methods should fail for some odd reason
  3971. addEvent(win, 'load', readyHandler);
  3972. }
  3973. function EventUtils(proxy) {
  3974. var self = this, events = {}, count, isFocusBlurBound, hasFocusIn, hasMouseEnterLeave, mouseEnterLeave;
  3975. hasMouseEnterLeave = "onmouseenter" in document.documentElement;
  3976. hasFocusIn = "onfocusin" in document.documentElement;
  3977. mouseEnterLeave = {mouseenter: 'mouseover', mouseleave: 'mouseout'};
  3978. count = 1;
  3979. // State if the DOMContentLoaded was executed or not
  3980. self.domLoaded = false;
  3981. self.events = events;
  3982. function executeHandlers(evt, id) {
  3983. var callbackList, i, l, callback;
  3984. callbackList = events[id][evt.type];
  3985. if (callbackList) {
  3986. for (i = 0, l = callbackList.length; i < l; i++) {
  3987. callback = callbackList[i];
  3988. // Check if callback exists might be removed if a unbind is called inside the callback
  3989. if (callback && callback.func.call(callback.scope, evt) === false) {
  3990. evt.preventDefault();
  3991. }
  3992. // Should we stop propagation to immediate listeners
  3993. if (evt.isImmediatePropagationStopped()) {
  3994. return;
  3995. }
  3996. }
  3997. }
  3998. }
  3999. self.bind = function(target, names, callback, scope) {
  4000. var id, callbackList, i, name, fakeName, nativeHandler, capture, win = window;
  4001. // Native event handler function patches the event and executes the callbacks for the expando
  4002. function defaultNativeHandler(evt) {
  4003. executeHandlers(fix(evt || win.event), id);
  4004. }
  4005. // Don't bind to text nodes or comments
  4006. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4007. return;
  4008. }
  4009. // Create or get events id for the target
  4010. if (!target[expando]) {
  4011. id = count++;
  4012. target[expando] = id;
  4013. events[id] = {};
  4014. } else {
  4015. id = target[expando];
  4016. if (!events[id]) {
  4017. events[id] = {};
  4018. }
  4019. }
  4020. // Setup the specified scope or use the target as a default
  4021. scope = scope || target;
  4022. // Split names and bind each event, enables you to bind multiple events with one call
  4023. names = names.split(' ');
  4024. i = names.length;
  4025. while (i--) {
  4026. name = names[i];
  4027. nativeHandler = defaultNativeHandler;
  4028. fakeName = capture = false;
  4029. // Use ready instead of DOMContentLoaded
  4030. if (name === "DOMContentLoaded") {
  4031. name = "ready";
  4032. }
  4033. // DOM is already ready
  4034. if ((self.domLoaded || target.readyState == 'complete') && name === "ready") {
  4035. self.domLoaded = true;
  4036. callback.call(scope, fix({type: name}));
  4037. continue;
  4038. }
  4039. // Handle mouseenter/mouseleaver
  4040. if (!hasMouseEnterLeave) {
  4041. fakeName = mouseEnterLeave[name];
  4042. if (fakeName) {
  4043. nativeHandler = function(evt) {
  4044. var current, related;
  4045. current = evt.currentTarget;
  4046. related = evt.relatedTarget;
  4047. // Check if related is inside the current target if it's not then the event should be ignored since it's a mouseover/mouseout inside the element
  4048. if (related && current.contains) {
  4049. // Use contains for performance
  4050. related = current.contains(related);
  4051. } else {
  4052. while (related && related !== current) {
  4053. related = related.parentNode;
  4054. }
  4055. }
  4056. // Fire fake event
  4057. if (!related) {
  4058. evt = fix(evt || win.event);
  4059. evt.type = evt.type === 'mouseout' ? 'mouseleave' : 'mouseenter';
  4060. evt.target = current;
  4061. executeHandlers(evt, id);
  4062. }
  4063. };
  4064. }
  4065. }
  4066. // Fake bubbeling of focusin/focusout
  4067. if (!hasFocusIn && (name === "focusin" || name === "focusout")) {
  4068. capture = true;
  4069. fakeName = name === "focusin" ? "focus" : "blur";
  4070. nativeHandler = function(evt) {
  4071. evt = fix(evt || win.event);
  4072. evt.type = evt.type === 'focus' ? 'focusin' : 'focusout';
  4073. executeHandlers(evt, id);
  4074. };
  4075. }
  4076. // Setup callback list and bind native event
  4077. callbackList = events[id][name];
  4078. if (!callbackList) {
  4079. events[id][name] = callbackList = [{func: callback, scope: scope}];
  4080. callbackList.fakeName = fakeName;
  4081. callbackList.capture = capture;
  4082. // Add the nativeHandler to the callback list so that we can later unbind it
  4083. callbackList.nativeHandler = nativeHandler;
  4084. if (!w3cEventModel) {
  4085. callbackList.proxyHandler = proxy(id);
  4086. }
  4087. // Check if the target has native events support
  4088. if (name === "ready") {
  4089. bindOnReady(target, nativeHandler, self);
  4090. } else {
  4091. addEvent(target, fakeName || name, w3cEventModel ? nativeHandler : callbackList.proxyHandler, capture);
  4092. }
  4093. } else {
  4094. // If it already has an native handler then just push the callback
  4095. callbackList.push({func: callback, scope: scope});
  4096. }
  4097. }
  4098. target = callbackList = 0; // Clean memory for IE
  4099. return callback;
  4100. };
  4101. self.unbind = function(target, names, callback) {
  4102. var id, callbackList, i, ci, name, eventMap;
  4103. // Don't bind to text nodes or comments
  4104. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4105. return self;
  4106. }
  4107. // Unbind event or events if the target has the expando
  4108. id = target[expando];
  4109. if (id) {
  4110. eventMap = events[id];
  4111. // Specific callback
  4112. if (names) {
  4113. names = names.split(' ');
  4114. i = names.length;
  4115. while (i--) {
  4116. name = names[i];
  4117. callbackList = eventMap[name];
  4118. // Unbind the event if it exists in the map
  4119. if (callbackList) {
  4120. // Remove specified callback
  4121. if (callback) {
  4122. ci = callbackList.length;
  4123. while (ci--) {
  4124. if (callbackList[ci].func === callback) {
  4125. callbackList.splice(ci, 1);
  4126. }
  4127. }
  4128. }
  4129. // Remove all callbacks if there isn't a specified callback or there is no callbacks left
  4130. if (!callback || callbackList.length === 0) {
  4131. delete eventMap[name];
  4132. removeEvent(target, callbackList.fakeName || name, w3cEventModel ? callbackList.nativeHandler : callbackList.proxyHandler, callbackList.capture);
  4133. }
  4134. }
  4135. }
  4136. } else {
  4137. // All events for a specific element
  4138. for (name in eventMap) {
  4139. callbackList = eventMap[name];
  4140. removeEvent(target, callbackList.fakeName || name, w3cEventModel ? callbackList.nativeHandler : callbackList.proxyHandler, callbackList.capture);
  4141. }
  4142. eventMap = {};
  4143. }
  4144. // Check if object is empty, if it isn't then we won't remove the expando map
  4145. for (name in eventMap) {
  4146. return self;
  4147. }
  4148. // Delete event object
  4149. delete events[id];
  4150. // Remove expando from target
  4151. try {
  4152. // IE will fail here since it can't delete properties from window
  4153. delete target[expando];
  4154. } catch (ex) {
  4155. // IE will set it to null
  4156. target[expando] = null;
  4157. }
  4158. }
  4159. return self;
  4160. };
  4161. self.fire = function(target, name, args) {
  4162. var id, event;
  4163. // Don't bind to text nodes or comments
  4164. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4165. return self;
  4166. }
  4167. // Build event object by patching the args
  4168. event = fix(null, args);
  4169. event.type = name;
  4170. do {
  4171. // Found an expando that means there is listeners to execute
  4172. id = target[expando];
  4173. if (id) {
  4174. executeHandlers(event, id);
  4175. }
  4176. // Walk up the DOM
  4177. target = target.parentNode || target.ownerDocument || target.defaultView || target.parentWindow;
  4178. } while (target && !event.isPropagationStopped());
  4179. return self;
  4180. };
  4181. self.clean = function(target) {
  4182. var i, children, unbind = self.unbind;
  4183. // Don't bind to text nodes or comments
  4184. if (!target || target.nodeType === 3 || target.nodeType === 8) {
  4185. return self;
  4186. }
  4187. // Unbind any element on the specificed target
  4188. if (target[expando]) {
  4189. unbind(target);
  4190. }
  4191. // Target doesn't have getElementsByTagName it's probably a window object then use it's document to find the children
  4192. if (!target.getElementsByTagName) {
  4193. target = target.document;
  4194. }
  4195. // Remove events from each child element
  4196. if (target && target.getElementsByTagName) {
  4197. unbind(target);
  4198. children = target.getElementsByTagName('*');
  4199. i = children.length;
  4200. while (i--) {
  4201. target = children[i];
  4202. if (target[expando]) {
  4203. unbind(target);
  4204. }
  4205. }
  4206. }
  4207. return self;
  4208. };
  4209. self.callNativeHandler = function(id, evt) {
  4210. if (events) {
  4211. events[id][evt.type].nativeHandler(evt);
  4212. }
  4213. };
  4214. self.destory = function() {
  4215. events = {};
  4216. };
  4217. // Legacy function calls
  4218. self.add = function(target, events, func, scope) {
  4219. // Old API supported direct ID assignment
  4220. if (typeof(target) === "string") {
  4221. target = document.getElementById(target);
  4222. }
  4223. // Old API supported multiple targets
  4224. if (target && target instanceof Array) {
  4225. var i = target.length;
  4226. while (i--) {
  4227. self.add(target[i], events, func, scope);
  4228. }
  4229. return;
  4230. }
  4231. // Old API called ready init
  4232. if (events === "init") {
  4233. events = "ready";
  4234. }
  4235. return self.bind(target, events instanceof Array ? events.join(' ') : events, func, scope);
  4236. };
  4237. self.remove = function(target, events, func, scope) {
  4238. if (!target) {
  4239. return self;
  4240. }
  4241. // Old API supported direct ID assignment
  4242. if (typeof(target) === "string") {
  4243. target = document.getElementById(target);
  4244. }
  4245. // Old API supported multiple targets
  4246. if (target instanceof Array) {
  4247. var i = target.length;
  4248. while (i--) {
  4249. self.remove(target[i], events, func, scope);
  4250. }
  4251. return self;
  4252. }
  4253. return self.unbind(target, events instanceof Array ? events.join(' ') : events, func);
  4254. };
  4255. self.clear = function(target) {
  4256. // Old API supported direct ID assignment
  4257. if (typeof(target) === "string") {
  4258. target = document.getElementById(target);
  4259. }
  4260. return self.clean(target);
  4261. };
  4262. self.cancel = function(e) {
  4263. if (e) {
  4264. self.prevent(e);
  4265. self.stop(e);
  4266. }
  4267. return false;
  4268. };
  4269. self.prevent = function(e) {
  4270. if (!e.preventDefault) {
  4271. e = fix(e);
  4272. }
  4273. e.preventDefault();
  4274. return false;
  4275. };
  4276. self.stop = function(e) {
  4277. if (!e.stopPropagation) {
  4278. e = fix(e);
  4279. }
  4280. e.stopPropagation();
  4281. return false;
  4282. };
  4283. }
  4284. namespace.EventUtils = EventUtils;
  4285. namespace.Event = new EventUtils(function(id) {
  4286. return function(evt) {
  4287. tinymce.dom.Event.callNativeHandler(id, evt);
  4288. };
  4289. });
  4290. // Bind ready event when tinymce script is loaded
  4291. namespace.Event.bind(window, 'ready', function() {});
  4292. namespace = 0;
  4293. })(tinymce.dom, 'data-mce-expando'); // Namespace and expando
  4294. tinymce.dom.TreeWalker = function(start_node, root_node) {
  4295. var node = start_node;
  4296. function findSibling(node, start_name, sibling_name, shallow) {
  4297. var sibling, parent;
  4298. if (node) {
  4299. // Walk into nodes if it has a start
  4300. if (!shallow && node[start_name])
  4301. return node[start_name];
  4302. // Return the sibling if it has one
  4303. if (node != root_node) {
  4304. sibling = node[sibling_name];
  4305. if (sibling)
  4306. return sibling;
  4307. // Walk up the parents to look for siblings
  4308. for (parent = node.parentNode; parent && parent != root_node; parent = parent.parentNode) {
  4309. sibling = parent[sibling_name];
  4310. if (sibling)
  4311. return sibling;
  4312. }
  4313. }
  4314. }
  4315. };
  4316. this.current = function() {
  4317. return node;
  4318. };
  4319. this.next = function(shallow) {
  4320. return (node = findSibling(node, 'firstChild', 'nextSibling', shallow));
  4321. };
  4322. this.prev = function(shallow) {
  4323. return (node = findSibling(node, 'lastChild', 'previousSibling', shallow));
  4324. };
  4325. };
  4326. (function(tinymce) {
  4327. // Shorten names
  4328. var each = tinymce.each,
  4329. is = tinymce.is,
  4330. isWebKit = tinymce.isWebKit,
  4331. isIE = tinymce.isIE,
  4332. Entities = tinymce.html.Entities,
  4333. simpleSelectorRe = /^([a-z0-9],?)+$/i,
  4334. whiteSpaceRegExp = /^[ \t\r\n]*$/;
  4335. tinymce.create('tinymce.dom.DOMUtils', {
  4336. doc : null,
  4337. root : null,
  4338. files : null,
  4339. pixelStyles : /^(top|left|bottom|right|width|height|borderWidth)$/,
  4340. props : {
  4341. "for" : "htmlFor",
  4342. "class" : "className",
  4343. className : "className",
  4344. checked : "checked",
  4345. disabled : "disabled",
  4346. maxlength : "maxLength",
  4347. readonly : "readOnly",
  4348. selected : "selected",
  4349. value : "value",
  4350. id : "id",
  4351. name : "name",
  4352. type : "type"
  4353. },
  4354. DOMUtils : function(d, s) {
  4355. var t = this, globalStyle, name, blockElementsMap;
  4356. t.doc = d;
  4357. t.win = window;
  4358. t.files = {};
  4359. t.cssFlicker = false;
  4360. t.counter = 0;
  4361. t.stdMode = !tinymce.isIE || d.documentMode >= 8;
  4362. t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat" || t.stdMode;
  4363. t.hasOuterHTML = "outerHTML" in d.createElement("a");
  4364. t.settings = s = tinymce.extend({
  4365. keep_values : false,
  4366. hex_colors : 1
  4367. }, s);
  4368. t.schema = s.schema;
  4369. t.styles = new tinymce.html.Styles({
  4370. url_converter : s.url_converter,
  4371. url_converter_scope : s.url_converter_scope
  4372. }, s.schema);
  4373. // Fix IE6SP2 flicker and check it failed for pre SP2
  4374. if (tinymce.isIE6) {
  4375. try {
  4376. d.execCommand('BackgroundImageCache', false, true);
  4377. } catch (e) {
  4378. t.cssFlicker = true;
  4379. }
  4380. }
  4381. t.fixDoc(d);
  4382. t.events = s.ownEvents ? new tinymce.dom.EventUtils(s.proxy) : tinymce.dom.Event;
  4383. tinymce.addUnload(t.destroy, t);
  4384. blockElementsMap = s.schema ? s.schema.getBlockElements() : {};
  4385. t.isBlock = function(node) {
  4386. // Fix for #5446
  4387. if (!node) {
  4388. return false;
  4389. }
  4390. // This function is called in module pattern style since it might be executed with the wrong this scope
  4391. var type = node.nodeType;
  4392. // If it's a node then check the type and use the nodeName
  4393. if (type)
  4394. return !!(type === 1 && blockElementsMap[node.nodeName]);
  4395. return !!blockElementsMap[node];
  4396. };
  4397. },
  4398. fixDoc: function(doc) {
  4399. var settings = this.settings, name;
  4400. if (isIE && settings.schema) {
  4401. // Add missing HTML 4/5 elements to IE
  4402. ('abbr article aside audio canvas ' +
  4403. 'details figcaption figure footer ' +
  4404. 'header hgroup mark menu meter nav ' +
  4405. 'output progress section summary ' +
  4406. 'time video').replace(/\w+/g, function(name) {
  4407. doc.createElement(name);
  4408. });
  4409. // Create all custom elements
  4410. for (name in settings.schema.getCustomElements()) {
  4411. doc.createElement(name);
  4412. }
  4413. }
  4414. },
  4415. clone: function(node, deep) {
  4416. var self = this, clone, doc;
  4417. // TODO: Add feature detection here in the future
  4418. if (!isIE || node.nodeType !== 1 || deep) {
  4419. return node.cloneNode(deep);
  4420. }
  4421. doc = self.doc;
  4422. // Make a HTML5 safe shallow copy
  4423. if (!deep) {
  4424. clone = doc.createElement(node.nodeName);
  4425. // Copy attribs
  4426. each(self.getAttribs(node), function(attr) {
  4427. self.setAttrib(clone, attr.nodeName, self.getAttrib(node, attr.nodeName));
  4428. });
  4429. return clone;
  4430. }
  4431. /*
  4432. // Setup HTML5 patched document fragment
  4433. if (!self.frag) {
  4434. self.frag = doc.createDocumentFragment();
  4435. self.fixDoc(self.frag);
  4436. }
  4437. // Make a deep copy by adding it to the document fragment then removing it this removed the :section
  4438. clone = doc.createElement('div');
  4439. self.frag.appendChild(clone);
  4440. clone.innerHTML = node.outerHTML;
  4441. self.frag.removeChild(clone);
  4442. */
  4443. return clone.firstChild;
  4444. },
  4445. getRoot : function() {
  4446. var t = this, s = t.settings;
  4447. return (s && t.get(s.root_element)) || t.doc.body;
  4448. },
  4449. getViewPort : function(w) {
  4450. var d, b;
  4451. w = !w ? this.win : w;
  4452. d = w.document;
  4453. b = this.boxModel ? d.documentElement : d.body;
  4454. // Returns viewport size excluding scrollbars
  4455. return {
  4456. x : w.pageXOffset || b.scrollLeft,
  4457. y : w.pageYOffset || b.scrollTop,
  4458. w : w.innerWidth || b.clientWidth,
  4459. h : w.innerHeight || b.clientHeight
  4460. };
  4461. },
  4462. getRect : function(e) {
  4463. var p, t = this, sr;
  4464. e = t.get(e);
  4465. p = t.getPos(e);
  4466. sr = t.getSize(e);
  4467. return {
  4468. x : p.x,
  4469. y : p.y,
  4470. w : sr.w,
  4471. h : sr.h
  4472. };
  4473. },
  4474. getSize : function(e) {
  4475. var t = this, w, h;
  4476. e = t.get(e);
  4477. w = t.getStyle(e, 'width');
  4478. h = t.getStyle(e, 'height');
  4479. // Non pixel value, then force offset/clientWidth
  4480. if (w.indexOf('px') === -1)
  4481. w = 0;
  4482. // Non pixel value, then force offset/clientWidth
  4483. if (h.indexOf('px') === -1)
  4484. h = 0;
  4485. return {
  4486. w : parseInt(w, 10) || e.offsetWidth || e.clientWidth,
  4487. h : parseInt(h, 10) || e.offsetHeight || e.clientHeight
  4488. };
  4489. },
  4490. getParent : function(n, f, r) {
  4491. return this.getParents(n, f, r, false);
  4492. },
  4493. getParents : function(n, f, r, c) {
  4494. var t = this, na, se = t.settings, o = [];
  4495. n = t.get(n);
  4496. c = c === undefined;
  4497. if (se.strict_root)
  4498. r = r || t.getRoot();
  4499. // Wrap node name as func
  4500. if (is(f, 'string')) {
  4501. na = f;
  4502. if (f === '*') {
  4503. f = function(n) {return n.nodeType == 1;};
  4504. } else {
  4505. f = function(n) {
  4506. return t.is(n, na);
  4507. };
  4508. }
  4509. }
  4510. while (n) {
  4511. if (n == r || !n.nodeType || n.nodeType === 9)
  4512. break;
  4513. if (!f || f(n)) {
  4514. if (c)
  4515. o.push(n);
  4516. else
  4517. return n;
  4518. }
  4519. n = n.parentNode;
  4520. }
  4521. return c ? o : null;
  4522. },
  4523. get : function(e) {
  4524. var n;
  4525. if (e && this.doc && typeof(e) == 'string') {
  4526. n = e;
  4527. e = this.doc.getElementById(e);
  4528. // IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick
  4529. if (e && e.id !== n)
  4530. return this.doc.getElementsByName(n)[1];
  4531. }
  4532. return e;
  4533. },
  4534. getNext : function(node, selector) {
  4535. return this._findSib(node, selector, 'nextSibling');
  4536. },
  4537. getPrev : function(node, selector) {
  4538. return this._findSib(node, selector, 'previousSibling');
  4539. },
  4540. add : function(p, n, a, h, c) {
  4541. var t = this;
  4542. return this.run(p, function(p) {
  4543. var e, k;
  4544. e = is(n, 'string') ? t.doc.createElement(n) : n;
  4545. t.setAttribs(e, a);
  4546. if (h) {
  4547. if (h.nodeType)
  4548. e.appendChild(h);
  4549. else
  4550. t.setHTML(e, h);
  4551. }
  4552. return !c ? p.appendChild(e) : e;
  4553. });
  4554. },
  4555. create : function(n, a, h) {
  4556. return this.add(this.doc.createElement(n), n, a, h, 1);
  4557. },
  4558. createHTML : function(n, a, h) {
  4559. var o = '', t = this, k;
  4560. o += '<' + n;
  4561. for (k in a) {
  4562. if (a.hasOwnProperty(k))
  4563. o += ' ' + k + '="' + t.encode(a[k]) + '"';
  4564. }
  4565. // A call to tinymce.is doesn't work for some odd reason on IE9 possible bug inside their JS runtime
  4566. if (typeof(h) != "undefined")
  4567. return o + '>' + h + '</' + n + '>';
  4568. return o + ' />';
  4569. },
  4570. remove : function(node, keep_children) {
  4571. return this.run(node, function(node) {
  4572. var child, parent = node.parentNode;
  4573. if (!parent)
  4574. return null;
  4575. if (keep_children) {
  4576. while (child = node.firstChild) {
  4577. // IE 8 will crash if you don't remove completely empty text nodes
  4578. if (!tinymce.isIE || child.nodeType !== 3 || child.nodeValue)
  4579. parent.insertBefore(child, node);
  4580. else
  4581. node.removeChild(child);
  4582. }
  4583. }
  4584. return parent.removeChild(node);
  4585. });
  4586. },
  4587. setStyle : function(n, na, v) {
  4588. var t = this;
  4589. return t.run(n, function(e) {
  4590. var s, i;
  4591. s = e.style;
  4592. // Camelcase it, if needed
  4593. na = na.replace(/-(\D)/g, function(a, b){
  4594. return b.toUpperCase();
  4595. });
  4596. // Default px suffix on these
  4597. if (t.pixelStyles.test(na) && (tinymce.is(v, 'number') || /^[\-0-9\.]+$/.test(v)))
  4598. v += 'px';
  4599. switch (na) {
  4600. case 'opacity':
  4601. // IE specific opacity
  4602. if (isIE) {
  4603. s.filter = v === '' ? '' : "alpha(opacity=" + (v * 100) + ")";
  4604. if (!n.currentStyle || !n.currentStyle.hasLayout)
  4605. s.display = 'inline-block';
  4606. }
  4607. // Fix for older browsers
  4608. s[na] = s['-moz-opacity'] = s['-khtml-opacity'] = v || '';
  4609. break;
  4610. case 'float':
  4611. isIE ? s.styleFloat = v : s.cssFloat = v;
  4612. break;
  4613. default:
  4614. s[na] = v || '';
  4615. }
  4616. // Force update of the style data
  4617. if (t.settings.update_styles)
  4618. t.setAttrib(e, 'data-mce-style');
  4619. });
  4620. },
  4621. getStyle : function(n, na, c) {
  4622. n = this.get(n);
  4623. if (!n)
  4624. return;
  4625. // Gecko
  4626. if (this.doc.defaultView && c) {
  4627. // Remove camelcase
  4628. na = na.replace(/[A-Z]/g, function(a){
  4629. return '-' + a;
  4630. });
  4631. try {
  4632. return this.doc.defaultView.getComputedStyle(n, null).getPropertyValue(na);
  4633. } catch (ex) {
  4634. // Old safari might fail
  4635. return null;
  4636. }
  4637. }
  4638. // Camelcase it, if needed
  4639. na = na.replace(/-(\D)/g, function(a, b){
  4640. return b.toUpperCase();
  4641. });
  4642. if (na == 'float')
  4643. na = isIE ? 'styleFloat' : 'cssFloat';
  4644. // IE & Opera
  4645. if (n.currentStyle && c)
  4646. return n.currentStyle[na];
  4647. return n.style ? n.style[na] : undefined;
  4648. },
  4649. setStyles : function(e, o) {
  4650. var t = this, s = t.settings, ol;
  4651. ol = s.update_styles;
  4652. s.update_styles = 0;
  4653. each(o, function(v, n) {
  4654. t.setStyle(e, n, v);
  4655. });
  4656. // Update style info
  4657. s.update_styles = ol;
  4658. if (s.update_styles)
  4659. t.setAttrib(e, s.cssText);
  4660. },
  4661. removeAllAttribs: function(e) {
  4662. return this.run(e, function(e) {
  4663. var i, attrs = e.attributes;
  4664. for (i = attrs.length - 1; i >= 0; i--) {
  4665. e.removeAttributeNode(attrs.item(i));
  4666. }
  4667. });
  4668. },
  4669. setAttrib : function(e, n, v) {
  4670. var t = this;
  4671. // Whats the point
  4672. if (!e || !n)
  4673. return;
  4674. // Strict XML mode
  4675. if (t.settings.strict)
  4676. n = n.toLowerCase();
  4677. return this.run(e, function(e) {
  4678. var s = t.settings;
  4679. var originalValue = e.getAttribute(n);
  4680. if (v !== null) {
  4681. switch (n) {
  4682. case "style":
  4683. if (!is(v, 'string')) {
  4684. each(v, function(v, n) {
  4685. t.setStyle(e, n, v);
  4686. });
  4687. return;
  4688. }
  4689. // No mce_style for elements with these since they might get resized by the user
  4690. if (s.keep_values) {
  4691. if (v && !t._isRes(v))
  4692. e.setAttribute('data-mce-style', v, 2);
  4693. else
  4694. e.removeAttribute('data-mce-style', 2);
  4695. }
  4696. e.style.cssText = v;
  4697. break;
  4698. case "class":
  4699. e.className = v || ''; // Fix IE null bug
  4700. break;
  4701. case "src":
  4702. case "href":
  4703. if (s.keep_values) {
  4704. if (s.url_converter)
  4705. v = s.url_converter.call(s.url_converter_scope || t, v, n, e);
  4706. t.setAttrib(e, 'data-mce-' + n, v, 2);
  4707. }
  4708. break;
  4709. case "shape":
  4710. e.setAttribute('data-mce-style', v);
  4711. break;
  4712. }
  4713. }
  4714. if (is(v) && v !== null && v.length !== 0)
  4715. e.setAttribute(n, '' + v, 2);
  4716. else
  4717. e.removeAttribute(n, 2);
  4718. // fire onChangeAttrib event for attributes that have changed
  4719. if (tinyMCE.activeEditor && originalValue != v) {
  4720. var ed = tinyMCE.activeEditor;
  4721. ed.onSetAttrib.dispatch(ed, e, n, v);
  4722. }
  4723. });
  4724. },
  4725. setAttribs : function(e, o) {
  4726. var t = this;
  4727. return this.run(e, function(e) {
  4728. each(o, function(v, n) {
  4729. t.setAttrib(e, n, v);
  4730. });
  4731. });
  4732. },
  4733. getAttrib : function(e, n, dv) {
  4734. var v, t = this, undef;
  4735. e = t.get(e);
  4736. if (!e || e.nodeType !== 1)
  4737. return dv === undef ? false : dv;
  4738. if (!is(dv))
  4739. dv = '';
  4740. // Try the mce variant for these
  4741. if (/^(src|href|style|coords|shape)$/.test(n)) {
  4742. v = e.getAttribute("data-mce-" + n);
  4743. if (v)
  4744. return v;
  4745. }
  4746. if (isIE && t.props[n]) {
  4747. v = e[t.props[n]];
  4748. v = v && v.nodeValue ? v.nodeValue : v;
  4749. }
  4750. if (!v)
  4751. v = e.getAttribute(n, 2);
  4752. // Check boolean attribs
  4753. if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(n)) {
  4754. if (e[t.props[n]] === true && v === '')
  4755. return n;
  4756. return v ? n : '';
  4757. }
  4758. // Inner input elements will override attributes on form elements
  4759. if (e.nodeName === "FORM" && e.getAttributeNode(n))
  4760. return e.getAttributeNode(n).nodeValue;
  4761. if (n === 'style') {
  4762. v = v || e.style.cssText;
  4763. if (v) {
  4764. v = t.serializeStyle(t.parseStyle(v), e.nodeName);
  4765. if (t.settings.keep_values && !t._isRes(v))
  4766. e.setAttribute('data-mce-style', v);
  4767. }
  4768. }
  4769. // Remove Apple and WebKit stuff
  4770. if (isWebKit && n === "class" && v)
  4771. v = v.replace(/(apple|webkit)\-[a-z\-]+/gi, '');
  4772. // Handle IE issues
  4773. if (isIE) {
  4774. switch (n) {
  4775. case 'rowspan':
  4776. case 'colspan':
  4777. // IE returns 1 as default value
  4778. if (v === 1)
  4779. v = '';
  4780. break;
  4781. case 'size':
  4782. // IE returns +0 as default value for size
  4783. if (v === '+0' || v === 20 || v === 0)
  4784. v = '';
  4785. break;
  4786. case 'width':
  4787. case 'height':
  4788. case 'vspace':
  4789. case 'checked':
  4790. case 'disabled':
  4791. case 'readonly':
  4792. if (v === 0)
  4793. v = '';
  4794. break;
  4795. case 'hspace':
  4796. // IE returns -1 as default value
  4797. if (v === -1)
  4798. v = '';
  4799. break;
  4800. case 'maxlength':
  4801. case 'tabindex':
  4802. // IE returns default value
  4803. if (v === 32768 || v === 2147483647 || v === '32768')
  4804. v = '';
  4805. break;
  4806. case 'multiple':
  4807. case 'compact':
  4808. case 'noshade':
  4809. case 'nowrap':
  4810. if (v === 65535)
  4811. return n;
  4812. return dv;
  4813. case 'shape':
  4814. v = v.toLowerCase();
  4815. break;
  4816. default:
  4817. // IE has odd anonymous function for event attributes
  4818. if (n.indexOf('on') === 0 && v)
  4819. v = tinymce._replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1', '' + v);
  4820. }
  4821. }
  4822. return (v !== undef && v !== null && v !== '') ? '' + v : dv;
  4823. },
  4824. getPos : function(n, ro) {
  4825. var t = this, x = 0, y = 0, e, d = t.doc, r;
  4826. n = t.get(n);
  4827. ro = ro || d.body;
  4828. if (n) {
  4829. // Use getBoundingClientRect if it exists since it's faster than looping offset nodes
  4830. if (n.getBoundingClientRect) {
  4831. n = n.getBoundingClientRect();
  4832. e = t.boxModel ? d.documentElement : d.body;
  4833. // Add scroll offsets from documentElement or body since IE with the wrong box model will use d.body and so do WebKit
  4834. // Also remove the body/documentelement clientTop/clientLeft on IE 6, 7 since they offset the position
  4835. x = n.left + (d.documentElement.scrollLeft || d.body.scrollLeft) - e.clientTop;
  4836. y = n.top + (d.documentElement.scrollTop || d.body.scrollTop) - e.clientLeft;
  4837. return {x : x, y : y};
  4838. }
  4839. r = n;
  4840. while (r && r != ro && r.nodeType) {
  4841. x += r.offsetLeft || 0;
  4842. y += r.offsetTop || 0;
  4843. r = r.offsetParent;
  4844. }
  4845. r = n.parentNode;
  4846. while (r && r != ro && r.nodeType) {
  4847. x -= r.scrollLeft || 0;
  4848. y -= r.scrollTop || 0;
  4849. r = r.parentNode;
  4850. }
  4851. }
  4852. return {x : x, y : y};
  4853. },
  4854. parseStyle : function(st) {
  4855. return this.styles.parse(st);
  4856. },
  4857. serializeStyle : function(o, name) {
  4858. return this.styles.serialize(o, name);
  4859. },
  4860. addStyle: function(cssText) {
  4861. var doc = this.doc, head;
  4862. // Create style element if needed
  4863. styleElm = doc.getElementById('mceDefaultStyles');
  4864. if (!styleElm) {
  4865. styleElm = doc.createElement('style'),
  4866. styleElm.id = 'mceDefaultStyles';
  4867. styleElm.type = 'text/css';
  4868. head = doc.getElementsByTagName('head')[0];
  4869. if (head.firstChild) {
  4870. head.insertBefore(styleElm, head.firstChild);
  4871. } else {
  4872. head.appendChild(styleElm);
  4873. }
  4874. }
  4875. // Append style data to old or new style element
  4876. if (styleElm.styleSheet) {
  4877. styleElm.styleSheet.cssText += cssText;
  4878. } else {
  4879. styleElm.appendChild(doc.createTextNode(cssText));
  4880. }
  4881. },
  4882. loadCSS : function(u) {
  4883. var t = this, d = t.doc, head;
  4884. if (!u)
  4885. u = '';
  4886. head = d.getElementsByTagName('head')[0];
  4887. each(u.split(','), function(u) {
  4888. var link;
  4889. if (t.files[u])
  4890. return;
  4891. t.files[u] = true;
  4892. link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)});
  4893. // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug
  4894. // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading
  4895. // It's ugly but it seems to work fine.
  4896. if (isIE && d.documentMode && d.recalc) {
  4897. link.onload = function() {
  4898. if (d.recalc)
  4899. d.recalc();
  4900. link.onload = null;
  4901. };
  4902. }
  4903. head.appendChild(link);
  4904. });
  4905. },
  4906. addClass : function(e, c) {
  4907. return this.run(e, function(e) {
  4908. var o;
  4909. if (!c)
  4910. return 0;
  4911. if (this.hasClass(e, c))
  4912. return e.className;
  4913. o = this.removeClass(e, c);
  4914. return e.className = (o != '' ? (o + ' ') : '') + c;
  4915. });
  4916. },
  4917. removeClass : function(e, c) {
  4918. var t = this, re;
  4919. return t.run(e, function(e) {
  4920. var v;
  4921. if (t.hasClass(e, c)) {
  4922. if (!re)
  4923. re = new RegExp("(^|\\s+)" + c + "(\\s+|$)", "g");
  4924. v = e.className.replace(re, ' ');
  4925. v = tinymce.trim(v != ' ' ? v : '');
  4926. e.className = v;
  4927. // Empty class attr
  4928. if (!v) {
  4929. e.removeAttribute('class');
  4930. e.removeAttribute('className');
  4931. }
  4932. return v;
  4933. }
  4934. return e.className;
  4935. });
  4936. },
  4937. hasClass : function(n, c) {
  4938. n = this.get(n);
  4939. if (!n || !c)
  4940. return false;
  4941. return (' ' + n.className + ' ').indexOf(' ' + c + ' ') !== -1;
  4942. },
  4943. show : function(e) {
  4944. return this.setStyle(e, 'display', 'block');
  4945. },
  4946. hide : function(e) {
  4947. return this.setStyle(e, 'display', 'none');
  4948. },
  4949. isHidden : function(e) {
  4950. e = this.get(e);
  4951. return !e || e.style.display == 'none' || this.getStyle(e, 'display') == 'none';
  4952. },
  4953. uniqueId : function(p) {
  4954. return (!p ? 'mce_' : p) + (this.counter++);
  4955. },
  4956. setHTML : function(element, html) {
  4957. var self = this;
  4958. return self.run(element, function(element) {
  4959. if (isIE) {
  4960. // Remove all child nodes, IE keeps empty text nodes in DOM
  4961. while (element.firstChild)
  4962. element.removeChild(element.firstChild);
  4963. try {
  4964. // IE will remove comments from the beginning
  4965. // unless you padd the contents with something
  4966. element.innerHTML = '<br />' + html;
  4967. element.removeChild(element.firstChild);
  4968. } catch (ex) {
  4969. // 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
  4970. // This seems to fix this problem
  4971. // Create new div with HTML contents and a BR infront to keep comments
  4972. var newElement = self.create('div');
  4973. newElement.innerHTML = '<br />' + html;
  4974. // Add all children from div to target
  4975. each (tinymce.grep(newElement.childNodes), function(node, i) {
  4976. // Skip br element
  4977. if (i && element.canHaveHTML)
  4978. element.appendChild(node);
  4979. });
  4980. }
  4981. } else
  4982. element.innerHTML = html;
  4983. return html;
  4984. });
  4985. },
  4986. getOuterHTML : function(elm) {
  4987. var doc, self = this;
  4988. elm = self.get(elm);
  4989. if (!elm)
  4990. return null;
  4991. if (elm.nodeType === 1 && self.hasOuterHTML)
  4992. return elm.outerHTML;
  4993. doc = (elm.ownerDocument || self.doc).createElement("body");
  4994. doc.appendChild(elm.cloneNode(true));
  4995. return doc.innerHTML;
  4996. },
  4997. setOuterHTML : function(e, h, d) {
  4998. var t = this;
  4999. function setHTML(e, h, d) {
  5000. var n, tp;
  5001. tp = d.createElement("body");
  5002. tp.innerHTML = h;
  5003. n = tp.lastChild;
  5004. while (n) {
  5005. t.insertAfter(n.cloneNode(true), e);
  5006. n = n.previousSibling;
  5007. }
  5008. t.remove(e);
  5009. };
  5010. return this.run(e, function(e) {
  5011. e = t.get(e);
  5012. // Only set HTML on elements
  5013. if (e.nodeType == 1) {
  5014. d = d || e.ownerDocument || t.doc;
  5015. if (isIE) {
  5016. try {
  5017. // Try outerHTML for IE it sometimes produces an unknown runtime error
  5018. if (isIE && e.nodeType == 1)
  5019. e.outerHTML = h;
  5020. else
  5021. setHTML(e, h, d);
  5022. } catch (ex) {
  5023. // Fix for unknown runtime error
  5024. setHTML(e, h, d);
  5025. }
  5026. } else
  5027. setHTML(e, h, d);
  5028. }
  5029. });
  5030. },
  5031. decode : Entities.decode,
  5032. encode : Entities.encodeAllRaw,
  5033. insertAfter : function(node, reference_node) {
  5034. reference_node = this.get(reference_node);
  5035. return this.run(node, function(node) {
  5036. var parent, nextSibling;
  5037. parent = reference_node.parentNode;
  5038. nextSibling = reference_node.nextSibling;
  5039. if (nextSibling)
  5040. parent.insertBefore(node, nextSibling);
  5041. else
  5042. parent.appendChild(node);
  5043. return node;
  5044. });
  5045. },
  5046. replace : function(n, o, k) {
  5047. var t = this;
  5048. if (is(o, 'array'))
  5049. n = n.cloneNode(true);
  5050. return t.run(o, function(o) {
  5051. if (k) {
  5052. each(tinymce.grep(o.childNodes), function(c) {
  5053. n.appendChild(c);
  5054. });
  5055. }
  5056. return o.parentNode.replaceChild(n, o);
  5057. });
  5058. },
  5059. rename : function(elm, name) {
  5060. var t = this, newElm;
  5061. if (elm.nodeName != name.toUpperCase()) {
  5062. // Rename block element
  5063. newElm = t.create(name);
  5064. // Copy attribs to new block
  5065. each(t.getAttribs(elm), function(attr_node) {
  5066. t.setAttrib(newElm, attr_node.nodeName, t.getAttrib(elm, attr_node.nodeName));
  5067. });
  5068. // Replace block
  5069. t.replace(newElm, elm, 1);
  5070. }
  5071. return newElm || elm;
  5072. },
  5073. findCommonAncestor : function(a, b) {
  5074. var ps = a, pe;
  5075. while (ps) {
  5076. pe = b;
  5077. while (pe && ps != pe)
  5078. pe = pe.parentNode;
  5079. if (ps == pe)
  5080. break;
  5081. ps = ps.parentNode;
  5082. }
  5083. if (!ps && a.ownerDocument)
  5084. return a.ownerDocument.documentElement;
  5085. return ps;
  5086. },
  5087. toHex : function(s) {
  5088. var c = /^\s*rgb\s*?\(\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?\)\s*$/i.exec(s);
  5089. function hex(s) {
  5090. s = parseInt(s, 10).toString(16);
  5091. return s.length > 1 ? s : '0' + s; // 0 -> 00
  5092. };
  5093. if (c) {
  5094. s = '#' + hex(c[1]) + hex(c[2]) + hex(c[3]);
  5095. return s;
  5096. }
  5097. return s;
  5098. },
  5099. getClasses : function() {
  5100. var t = this, cl = [], i, lo = {}, f = t.settings.class_filter, ov;
  5101. if (t.classes)
  5102. return t.classes;
  5103. function addClasses(s) {
  5104. // IE style imports
  5105. each(s.imports, function(r) {
  5106. addClasses(r);
  5107. });
  5108. each(s.cssRules || s.rules, function(r) {
  5109. // Real type or fake it on IE
  5110. switch (r.type || 1) {
  5111. // Rule
  5112. case 1:
  5113. if (r.selectorText) {
  5114. each(r.selectorText.split(','), function(v) {
  5115. v = v.replace(/^\s*|\s*$|^\s\./g, "");
  5116. // Is internal or it doesn't contain a class
  5117. if (/\.mce/.test(v) || !/\.[\w\-]+$/.test(v))
  5118. return;
  5119. // Remove everything but class name
  5120. ov = v;
  5121. v = tinymce._replace(/.*\.([a-z0-9_\-]+).*/i, '$1', v);
  5122. // Filter classes
  5123. if (f && !(v = f(v, ov)))
  5124. return;
  5125. if (!lo[v]) {
  5126. cl.push({'class' : v});
  5127. lo[v] = 1;
  5128. }
  5129. });
  5130. }
  5131. break;
  5132. // Import
  5133. case 3:
  5134. addClasses(r.styleSheet);
  5135. break;
  5136. }
  5137. });
  5138. };
  5139. try {
  5140. each(t.doc.styleSheets, addClasses);
  5141. } catch (ex) {
  5142. // Ignore
  5143. }
  5144. if (cl.length > 0)
  5145. t.classes = cl;
  5146. return cl;
  5147. },
  5148. run : function(e, f, s) {
  5149. var t = this, o;
  5150. if (t.doc && typeof(e) === 'string')
  5151. e = t.get(e);
  5152. if (!e)
  5153. return false;
  5154. s = s || this;
  5155. if (!e.nodeType && (e.length || e.length === 0)) {
  5156. o = [];
  5157. each(e, function(e, i) {
  5158. if (e) {
  5159. if (typeof(e) == 'string')
  5160. e = t.doc.getElementById(e);
  5161. o.push(f.call(s, e, i));
  5162. }
  5163. });
  5164. return o;
  5165. }
  5166. return f.call(s, e);
  5167. },
  5168. getAttribs : function(n) {
  5169. var o;
  5170. n = this.get(n);
  5171. if (!n)
  5172. return [];
  5173. if (isIE) {
  5174. o = [];
  5175. // Object will throw exception in IE
  5176. if (n.nodeName == 'OBJECT')
  5177. return n.attributes;
  5178. // IE doesn't keep the selected attribute if you clone option elements
  5179. if (n.nodeName === 'OPTION' && this.getAttrib(n, 'selected'))
  5180. o.push({specified : 1, nodeName : 'selected'});
  5181. // It's crazy that this is faster in IE but it's because it returns all attributes all the time
  5182. n.cloneNode(false).outerHTML.replace(/<\/?[\w:\-]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=[\w\-]+|>/gi, '').replace(/[\w:\-]+/gi, function(a) {
  5183. o.push({specified : 1, nodeName : a});
  5184. });
  5185. return o;
  5186. }
  5187. return n.attributes;
  5188. },
  5189. isEmpty : function(node, elements) {
  5190. var self = this, i, attributes, type, walker, name, brCount = 0;
  5191. node = node.firstChild;
  5192. if (node) {
  5193. walker = new tinymce.dom.TreeWalker(node, node.parentNode);
  5194. elements = elements || self.schema ? self.schema.getNonEmptyElements() : null;
  5195. do {
  5196. type = node.nodeType;
  5197. if (type === 1) {
  5198. // Ignore bogus elements
  5199. if (node.getAttribute('data-mce-bogus'))
  5200. continue;
  5201. // Keep empty elements like <img />
  5202. name = node.nodeName.toLowerCase();
  5203. if (elements && elements[name]) {
  5204. // Ignore single BR elements in blocks like <p><br /></p> or <p><span><br /></span></p>
  5205. if (name === 'br') {
  5206. brCount++;
  5207. continue;
  5208. }
  5209. return false;
  5210. }
  5211. // Keep elements with data-bookmark attributes or name attribute like <a name="1"></a>
  5212. attributes = self.getAttribs(node);
  5213. i = node.attributes.length;
  5214. while (i--) {
  5215. name = node.attributes[i].nodeName;
  5216. if (name === "name" || name === 'data-mce-bookmark')
  5217. return false;
  5218. }
  5219. }
  5220. // Keep comment nodes
  5221. if (type == 8)
  5222. return false;
  5223. // Keep non whitespace text nodes
  5224. if ((type === 3 && !whiteSpaceRegExp.test(node.nodeValue)))
  5225. return false;
  5226. } while (node = walker.next());
  5227. }
  5228. return brCount <= 1;
  5229. },
  5230. destroy : function(s) {
  5231. var t = this;
  5232. t.win = t.doc = t.root = t.events = t.frag = null;
  5233. // Manual destroy then remove unload handler
  5234. if (!s)
  5235. tinymce.removeUnload(t.destroy);
  5236. },
  5237. createRng : function() {
  5238. var d = this.doc;
  5239. return d.createRange ? d.createRange() : new tinymce.dom.Range(this);
  5240. },
  5241. nodeIndex : function(node, normalized) {
  5242. var idx = 0, lastNodeType, lastNode, nodeType;
  5243. if (node) {
  5244. for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) {
  5245. nodeType = node.nodeType;
  5246. // Normalize text nodes
  5247. if (normalized && nodeType == 3) {
  5248. if (nodeType == lastNodeType || !node.nodeValue.length)
  5249. continue;
  5250. }
  5251. idx++;
  5252. lastNodeType = nodeType;
  5253. }
  5254. }
  5255. return idx;
  5256. },
  5257. split : function(pe, e, re) {
  5258. var t = this, r = t.createRng(), bef, aft, pa;
  5259. // W3C valid browsers tend to leave empty nodes to the left/right side of the contents, this makes sense
  5260. // but we don't want that in our code since it serves no purpose for the end user
  5261. // For example if this is chopped:
  5262. // <p>text 1<span><b>CHOP</b></span>text 2</p>
  5263. // would produce:
  5264. // <p>text 1<span></span></p><b>CHOP</b><p><span></span>text 2</p>
  5265. // this function will then trim of empty edges and produce:
  5266. // <p>text 1</p><b>CHOP</b><p>text 2</p>
  5267. function trim(node) {
  5268. var i, children = node.childNodes, type = node.nodeType;
  5269. function surroundedBySpans(node) {
  5270. var previousIsSpan = node.previousSibling && node.previousSibling.nodeName == 'SPAN';
  5271. var nextIsSpan = node.nextSibling && node.nextSibling.nodeName == 'SPAN';
  5272. return previousIsSpan && nextIsSpan;
  5273. }
  5274. if (type == 1 && node.getAttribute('data-mce-type') == 'bookmark')
  5275. return;
  5276. for (i = children.length - 1; i >= 0; i--)
  5277. trim(children[i]);
  5278. if (type != 9) {
  5279. // Keep non whitespace text nodes
  5280. if (type == 3 && node.nodeValue.length > 0) {
  5281. // If parent element isn't a block or there isn't any useful contents for example "<p> </p>"
  5282. // Also keep text nodes with only spaces if surrounded by spans.
  5283. // eg. "<p><span>a</span> <span>b</span></p>" should keep space between a and b
  5284. var trimmedLength = tinymce.trim(node.nodeValue).length;
  5285. if (!t.isBlock(node.parentNode) || trimmedLength > 0 || trimmedLength === 0 && surroundedBySpans(node))
  5286. return;
  5287. } else if (type == 1) {
  5288. // If the only child is a bookmark then move it up
  5289. children = node.childNodes;
  5290. if (children.length == 1 && children[0] && children[0].nodeType == 1 && children[0].getAttribute('data-mce-type') == 'bookmark')
  5291. node.parentNode.insertBefore(children[0], node);
  5292. // Keep non empty elements or img, hr etc
  5293. if (children.length || /^(br|hr|input|img)$/i.test(node.nodeName))
  5294. return;
  5295. }
  5296. t.remove(node);
  5297. }
  5298. return node;
  5299. };
  5300. if (pe && e) {
  5301. // Get before chunk
  5302. r.setStart(pe.parentNode, t.nodeIndex(pe));
  5303. r.setEnd(e.parentNode, t.nodeIndex(e));
  5304. bef = r.extractContents();
  5305. // Get after chunk
  5306. r = t.createRng();
  5307. r.setStart(e.parentNode, t.nodeIndex(e) + 1);
  5308. r.setEnd(pe.parentNode, t.nodeIndex(pe) + 1);
  5309. aft = r.extractContents();
  5310. // Insert before chunk
  5311. pa = pe.parentNode;
  5312. pa.insertBefore(trim(bef), pe);
  5313. // Insert middle chunk
  5314. if (re)
  5315. pa.replaceChild(re, e);
  5316. else
  5317. pa.insertBefore(e, pe);
  5318. // Insert after chunk
  5319. pa.insertBefore(trim(aft), pe);
  5320. t.remove(pe);
  5321. return re || e;
  5322. }
  5323. },
  5324. bind : function(target, name, func, scope) {
  5325. return this.events.add(target, name, func, scope || this);
  5326. },
  5327. unbind : function(target, name, func) {
  5328. return this.events.remove(target, name, func);
  5329. },
  5330. fire : function(target, name, evt) {
  5331. return this.events.fire(target, name, evt);
  5332. },
  5333. // Returns the content editable state of a node
  5334. getContentEditable: function(node) {
  5335. var contentEditable;
  5336. // Check type
  5337. if (node.nodeType != 1) {
  5338. return null;
  5339. }
  5340. // Check for fake content editable
  5341. contentEditable = node.getAttribute("data-mce-contenteditable");
  5342. if (contentEditable && contentEditable !== "inherit") {
  5343. return contentEditable;
  5344. }
  5345. // Check for real content editable
  5346. return node.contentEditable !== "inherit" ? node.contentEditable : null;
  5347. },
  5348. _findSib : function(node, selector, name) {
  5349. var t = this, f = selector;
  5350. if (node) {
  5351. // If expression make a function of it using is
  5352. if (is(f, 'string')) {
  5353. f = function(node) {
  5354. return t.is(node, selector);
  5355. };
  5356. }
  5357. // Loop all siblings
  5358. for (node = node[name]; node; node = node[name]) {
  5359. if (f(node))
  5360. return node;
  5361. }
  5362. }
  5363. return null;
  5364. },
  5365. _isRes : function(c) {
  5366. // Is live resizble element
  5367. return /^(top|left|bottom|right|width|height)/i.test(c) || /;\s*(top|left|bottom|right|width|height)/i.test(c);
  5368. }
  5369. /*
  5370. walk : function(n, f, s) {
  5371. var d = this.doc, w;
  5372. if (d.createTreeWalker) {
  5373. w = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false);
  5374. while ((n = w.nextNode()) != null)
  5375. f.call(s || this, n);
  5376. } else
  5377. tinymce.walk(n, f, 'childNodes', s);
  5378. }
  5379. */
  5380. /*
  5381. toRGB : function(s) {
  5382. var c = /^\s*?#([0-9A-F]{2})([0-9A-F]{1,2})([0-9A-F]{2})?\s*?$/.exec(s);
  5383. if (c) {
  5384. // #FFF -> #FFFFFF
  5385. if (!is(c[3]))
  5386. c[3] = c[2] = c[1];
  5387. return "rgb(" + parseInt(c[1], 16) + "," + parseInt(c[2], 16) + "," + parseInt(c[3], 16) + ")";
  5388. }
  5389. return s;
  5390. }
  5391. */
  5392. });
  5393. tinymce.DOM = new tinymce.dom.DOMUtils(document, {process_html : 0});
  5394. })(tinymce);
  5395. (function(ns) {
  5396. // Range constructor
  5397. function Range(dom) {
  5398. var t = this,
  5399. doc = dom.doc,
  5400. EXTRACT = 0,
  5401. CLONE = 1,
  5402. DELETE = 2,
  5403. TRUE = true,
  5404. FALSE = false,
  5405. START_OFFSET = 'startOffset',
  5406. START_CONTAINER = 'startContainer',
  5407. END_CONTAINER = 'endContainer',
  5408. END_OFFSET = 'endOffset',
  5409. extend = tinymce.extend,
  5410. nodeIndex = dom.nodeIndex;
  5411. extend(t, {
  5412. // Inital states
  5413. startContainer : doc,
  5414. startOffset : 0,
  5415. endContainer : doc,
  5416. endOffset : 0,
  5417. collapsed : TRUE,
  5418. commonAncestorContainer : doc,
  5419. // Range constants
  5420. START_TO_START : 0,
  5421. START_TO_END : 1,
  5422. END_TO_END : 2,
  5423. END_TO_START : 3,
  5424. // Public methods
  5425. setStart : setStart,
  5426. setEnd : setEnd,
  5427. setStartBefore : setStartBefore,
  5428. setStartAfter : setStartAfter,
  5429. setEndBefore : setEndBefore,
  5430. setEndAfter : setEndAfter,
  5431. collapse : collapse,
  5432. selectNode : selectNode,
  5433. selectNodeContents : selectNodeContents,
  5434. compareBoundaryPoints : compareBoundaryPoints,
  5435. deleteContents : deleteContents,
  5436. extractContents : extractContents,
  5437. cloneContents : cloneContents,
  5438. insertNode : insertNode,
  5439. surroundContents : surroundContents,
  5440. cloneRange : cloneRange,
  5441. toStringIE : toStringIE
  5442. });
  5443. function createDocumentFragment() {
  5444. return doc.createDocumentFragment();
  5445. };
  5446. function setStart(n, o) {
  5447. _setEndPoint(TRUE, n, o);
  5448. };
  5449. function setEnd(n, o) {
  5450. _setEndPoint(FALSE, n, o);
  5451. };
  5452. function setStartBefore(n) {
  5453. setStart(n.parentNode, nodeIndex(n));
  5454. };
  5455. function setStartAfter(n) {
  5456. setStart(n.parentNode, nodeIndex(n) + 1);
  5457. };
  5458. function setEndBefore(n) {
  5459. setEnd(n.parentNode, nodeIndex(n));
  5460. };
  5461. function setEndAfter(n) {
  5462. setEnd(n.parentNode, nodeIndex(n) + 1);
  5463. };
  5464. function collapse(ts) {
  5465. if (ts) {
  5466. t[END_CONTAINER] = t[START_CONTAINER];
  5467. t[END_OFFSET] = t[START_OFFSET];
  5468. } else {
  5469. t[START_CONTAINER] = t[END_CONTAINER];
  5470. t[START_OFFSET] = t[END_OFFSET];
  5471. }
  5472. t.collapsed = TRUE;
  5473. };
  5474. function selectNode(n) {
  5475. setStartBefore(n);
  5476. setEndAfter(n);
  5477. };
  5478. function selectNodeContents(n) {
  5479. setStart(n, 0);
  5480. setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length);
  5481. };
  5482. function compareBoundaryPoints(h, r) {
  5483. var sc = t[START_CONTAINER], so = t[START_OFFSET], ec = t[END_CONTAINER], eo = t[END_OFFSET],
  5484. rsc = r.startContainer, rso = r.startOffset, rec = r.endContainer, reo = r.endOffset;
  5485. // Check START_TO_START
  5486. if (h === 0)
  5487. return _compareBoundaryPoints(sc, so, rsc, rso);
  5488. // Check START_TO_END
  5489. if (h === 1)
  5490. return _compareBoundaryPoints(ec, eo, rsc, rso);
  5491. // Check END_TO_END
  5492. if (h === 2)
  5493. return _compareBoundaryPoints(ec, eo, rec, reo);
  5494. // Check END_TO_START
  5495. if (h === 3)
  5496. return _compareBoundaryPoints(sc, so, rec, reo);
  5497. };
  5498. function deleteContents() {
  5499. _traverse(DELETE);
  5500. };
  5501. function extractContents() {
  5502. return _traverse(EXTRACT);
  5503. };
  5504. function cloneContents() {
  5505. return _traverse(CLONE);
  5506. };
  5507. function insertNode(n) {
  5508. var startContainer = this[START_CONTAINER],
  5509. startOffset = this[START_OFFSET], nn, o;
  5510. // Node is TEXT_NODE or CDATA
  5511. if ((startContainer.nodeType === 3 || startContainer.nodeType === 4) && startContainer.nodeValue) {
  5512. if (!startOffset) {
  5513. // At the start of text
  5514. startContainer.parentNode.insertBefore(n, startContainer);
  5515. } else if (startOffset >= startContainer.nodeValue.length) {
  5516. // At the end of text
  5517. dom.insertAfter(n, startContainer);
  5518. } else {
  5519. // Middle, need to split
  5520. nn = startContainer.splitText(startOffset);
  5521. startContainer.parentNode.insertBefore(n, nn);
  5522. }
  5523. } else {
  5524. // Insert element node
  5525. if (startContainer.childNodes.length > 0)
  5526. o = startContainer.childNodes[startOffset];
  5527. if (o)
  5528. startContainer.insertBefore(n, o);
  5529. else
  5530. startContainer.appendChild(n);
  5531. }
  5532. };
  5533. function surroundContents(n) {
  5534. var f = t.extractContents();
  5535. t.insertNode(n);
  5536. n.appendChild(f);
  5537. t.selectNode(n);
  5538. };
  5539. function cloneRange() {
  5540. return extend(new Range(dom), {
  5541. startContainer : t[START_CONTAINER],
  5542. startOffset : t[START_OFFSET],
  5543. endContainer : t[END_CONTAINER],
  5544. endOffset : t[END_OFFSET],
  5545. collapsed : t.collapsed,
  5546. commonAncestorContainer : t.commonAncestorContainer
  5547. });
  5548. };
  5549. // Private methods
  5550. function _getSelectedNode(container, offset) {
  5551. var child;
  5552. if (container.nodeType == 3 /* TEXT_NODE */)
  5553. return container;
  5554. if (offset < 0)
  5555. return container;
  5556. child = container.firstChild;
  5557. while (child && offset > 0) {
  5558. --offset;
  5559. child = child.nextSibling;
  5560. }
  5561. if (child)
  5562. return child;
  5563. return container;
  5564. };
  5565. function _isCollapsed() {
  5566. return (t[START_CONTAINER] == t[END_CONTAINER] && t[START_OFFSET] == t[END_OFFSET]);
  5567. };
  5568. function _compareBoundaryPoints(containerA, offsetA, containerB, offsetB) {
  5569. var c, offsetC, n, cmnRoot, childA, childB;
  5570. // In the first case the boundary-points have the same container. A is before B
  5571. // if its offset is less than the offset of B, A is equal to B if its offset is
  5572. // equal to the offset of B, and A is after B if its offset is greater than the
  5573. // offset of B.
  5574. if (containerA == containerB) {
  5575. if (offsetA == offsetB)
  5576. return 0; // equal
  5577. if (offsetA < offsetB)
  5578. return -1; // before
  5579. return 1; // after
  5580. }
  5581. // In the second case a child node C of the container of A is an ancestor
  5582. // container of B. In this case, A is before B if the offset of A is less than or
  5583. // equal to the index of the child node C and A is after B otherwise.
  5584. c = containerB;
  5585. while (c && c.parentNode != containerA)
  5586. c = c.parentNode;
  5587. if (c) {
  5588. offsetC = 0;
  5589. n = containerA.firstChild;
  5590. while (n != c && offsetC < offsetA) {
  5591. offsetC++;
  5592. n = n.nextSibling;
  5593. }
  5594. if (offsetA <= offsetC)
  5595. return -1; // before
  5596. return 1; // after
  5597. }
  5598. // In the third case a child node C of the container of B is an ancestor container
  5599. // of A. In this case, A is before B if the index of the child node C is less than
  5600. // the offset of B and A is after B otherwise.
  5601. c = containerA;
  5602. while (c && c.parentNode != containerB) {
  5603. c = c.parentNode;
  5604. }
  5605. if (c) {
  5606. offsetC = 0;
  5607. n = containerB.firstChild;
  5608. while (n != c && offsetC < offsetB) {
  5609. offsetC++;
  5610. n = n.nextSibling;
  5611. }
  5612. if (offsetC < offsetB)
  5613. return -1; // before
  5614. return 1; // after
  5615. }
  5616. // In the fourth case, none of three other cases hold: the containers of A and B
  5617. // are siblings or descendants of sibling nodes. In this case, A is before B if
  5618. // the container of A is before the container of B in a pre-order traversal of the
  5619. // Ranges' context tree and A is after B otherwise.
  5620. cmnRoot = dom.findCommonAncestor(containerA, containerB);
  5621. childA = containerA;
  5622. while (childA && childA.parentNode != cmnRoot)
  5623. childA = childA.parentNode;
  5624. if (!childA)
  5625. childA = cmnRoot;
  5626. childB = containerB;
  5627. while (childB && childB.parentNode != cmnRoot)
  5628. childB = childB.parentNode;
  5629. if (!childB)
  5630. childB = cmnRoot;
  5631. if (childA == childB)
  5632. return 0; // equal
  5633. n = cmnRoot.firstChild;
  5634. while (n) {
  5635. if (n == childA)
  5636. return -1; // before
  5637. if (n == childB)
  5638. return 1; // after
  5639. n = n.nextSibling;
  5640. }
  5641. };
  5642. function _setEndPoint(st, n, o) {
  5643. var ec, sc;
  5644. if (st) {
  5645. t[START_CONTAINER] = n;
  5646. t[START_OFFSET] = o;
  5647. } else {
  5648. t[END_CONTAINER] = n;
  5649. t[END_OFFSET] = o;
  5650. }
  5651. // If one boundary-point of a Range is set to have a root container
  5652. // other than the current one for the Range, the Range is collapsed to
  5653. // the new position. This enforces the restriction that both boundary-
  5654. // points of a Range must have the same root container.
  5655. ec = t[END_CONTAINER];
  5656. while (ec.parentNode)
  5657. ec = ec.parentNode;
  5658. sc = t[START_CONTAINER];
  5659. while (sc.parentNode)
  5660. sc = sc.parentNode;
  5661. if (sc == ec) {
  5662. // The start position of a Range is guaranteed to never be after the
  5663. // end position. To enforce this restriction, if the start is set to
  5664. // be at a position after the end, the Range is collapsed to that
  5665. // position.
  5666. if (_compareBoundaryPoints(t[START_CONTAINER], t[START_OFFSET], t[END_CONTAINER], t[END_OFFSET]) > 0)
  5667. t.collapse(st);
  5668. } else
  5669. t.collapse(st);
  5670. t.collapsed = _isCollapsed();
  5671. t.commonAncestorContainer = dom.findCommonAncestor(t[START_CONTAINER], t[END_CONTAINER]);
  5672. };
  5673. function _traverse(how) {
  5674. var c, endContainerDepth = 0, startContainerDepth = 0, p, depthDiff, startNode, endNode, sp, ep;
  5675. if (t[START_CONTAINER] == t[END_CONTAINER])
  5676. return _traverseSameContainer(how);
  5677. for (c = t[END_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  5678. if (p == t[START_CONTAINER])
  5679. return _traverseCommonStartContainer(c, how);
  5680. ++endContainerDepth;
  5681. }
  5682. for (c = t[START_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
  5683. if (p == t[END_CONTAINER])
  5684. return _traverseCommonEndContainer(c, how);
  5685. ++startContainerDepth;
  5686. }
  5687. depthDiff = startContainerDepth - endContainerDepth;
  5688. startNode = t[START_CONTAINER];
  5689. while (depthDiff > 0) {
  5690. startNode = startNode.parentNode;
  5691. depthDiff--;
  5692. }
  5693. endNode = t[END_CONTAINER];
  5694. while (depthDiff < 0) {
  5695. endNode = endNode.parentNode;
  5696. depthDiff++;
  5697. }
  5698. // ascend the ancestor hierarchy until we have a common parent.
  5699. for (sp = startNode.parentNode, ep = endNode.parentNode; sp != ep; sp = sp.parentNode, ep = ep.parentNode) {
  5700. startNode = sp;
  5701. endNode = ep;
  5702. }
  5703. return _traverseCommonAncestors(startNode, endNode, how);
  5704. };
  5705. function _traverseSameContainer(how) {
  5706. var frag, s, sub, n, cnt, sibling, xferNode, start, len;
  5707. if (how != DELETE)
  5708. frag = createDocumentFragment();
  5709. // If selection is empty, just return the fragment
  5710. if (t[START_OFFSET] == t[END_OFFSET])
  5711. return frag;
  5712. // Text node needs special case handling
  5713. if (t[START_CONTAINER].nodeType == 3 /* TEXT_NODE */) {
  5714. // get the substring
  5715. s = t[START_CONTAINER].nodeValue;
  5716. sub = s.substring(t[START_OFFSET], t[END_OFFSET]);
  5717. // set the original text node to its new value
  5718. if (how != CLONE) {
  5719. n = t[START_CONTAINER];
  5720. start = t[START_OFFSET];
  5721. len = t[END_OFFSET] - t[START_OFFSET];
  5722. if (start === 0 && len >= n.nodeValue.length - 1) {
  5723. n.parentNode.removeChild(n);
  5724. } else {
  5725. n.deleteData(start, len);
  5726. }
  5727. // Nothing is partially selected, so collapse to start point
  5728. t.collapse(TRUE);
  5729. }
  5730. if (how == DELETE)
  5731. return;
  5732. if (sub.length > 0) {
  5733. frag.appendChild(doc.createTextNode(sub));
  5734. }
  5735. return frag;
  5736. }
  5737. // Copy nodes between the start/end offsets.
  5738. n = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]);
  5739. cnt = t[END_OFFSET] - t[START_OFFSET];
  5740. while (n && cnt > 0) {
  5741. sibling = n.nextSibling;
  5742. xferNode = _traverseFullySelected(n, how);
  5743. if (frag)
  5744. frag.appendChild( xferNode );
  5745. --cnt;
  5746. n = sibling;
  5747. }
  5748. // Nothing is partially selected, so collapse to start point
  5749. if (how != CLONE)
  5750. t.collapse(TRUE);
  5751. return frag;
  5752. };
  5753. function _traverseCommonStartContainer(endAncestor, how) {
  5754. var frag, n, endIdx, cnt, sibling, xferNode;
  5755. if (how != DELETE)
  5756. frag = createDocumentFragment();
  5757. n = _traverseRightBoundary(endAncestor, how);
  5758. if (frag)
  5759. frag.appendChild(n);
  5760. endIdx = nodeIndex(endAncestor);
  5761. cnt = endIdx - t[START_OFFSET];
  5762. if (cnt <= 0) {
  5763. // Collapse to just before the endAncestor, which
  5764. // is partially selected.
  5765. if (how != CLONE) {
  5766. t.setEndBefore(endAncestor);
  5767. t.collapse(FALSE);
  5768. }
  5769. return frag;
  5770. }
  5771. n = endAncestor.previousSibling;
  5772. while (cnt > 0) {
  5773. sibling = n.previousSibling;
  5774. xferNode = _traverseFullySelected(n, how);
  5775. if (frag)
  5776. frag.insertBefore(xferNode, frag.firstChild);
  5777. --cnt;
  5778. n = sibling;
  5779. }
  5780. // Collapse to just before the endAncestor, which
  5781. // is partially selected.
  5782. if (how != CLONE) {
  5783. t.setEndBefore(endAncestor);
  5784. t.collapse(FALSE);
  5785. }
  5786. return frag;
  5787. };
  5788. function _traverseCommonEndContainer(startAncestor, how) {
  5789. var frag, startIdx, n, cnt, sibling, xferNode;
  5790. if (how != DELETE)
  5791. frag = createDocumentFragment();
  5792. n = _traverseLeftBoundary(startAncestor, how);
  5793. if (frag)
  5794. frag.appendChild(n);
  5795. startIdx = nodeIndex(startAncestor);
  5796. ++startIdx; // Because we already traversed it
  5797. cnt = t[END_OFFSET] - startIdx;
  5798. n = startAncestor.nextSibling;
  5799. while (n && cnt > 0) {
  5800. sibling = n.nextSibling;
  5801. xferNode = _traverseFullySelected(n, how);
  5802. if (frag)
  5803. frag.appendChild(xferNode);
  5804. --cnt;
  5805. n = sibling;
  5806. }
  5807. if (how != CLONE) {
  5808. t.setStartAfter(startAncestor);
  5809. t.collapse(TRUE);
  5810. }
  5811. return frag;
  5812. };
  5813. function _traverseCommonAncestors(startAncestor, endAncestor, how) {
  5814. var n, frag, commonParent, startOffset, endOffset, cnt, sibling, nextSibling;
  5815. if (how != DELETE)
  5816. frag = createDocumentFragment();
  5817. n = _traverseLeftBoundary(startAncestor, how);
  5818. if (frag)
  5819. frag.appendChild(n);
  5820. commonParent = startAncestor.parentNode;
  5821. startOffset = nodeIndex(startAncestor);
  5822. endOffset = nodeIndex(endAncestor);
  5823. ++startOffset;
  5824. cnt = endOffset - startOffset;
  5825. sibling = startAncestor.nextSibling;
  5826. while (cnt > 0) {
  5827. nextSibling = sibling.nextSibling;
  5828. n = _traverseFullySelected(sibling, how);
  5829. if (frag)
  5830. frag.appendChild(n);
  5831. sibling = nextSibling;
  5832. --cnt;
  5833. }
  5834. n = _traverseRightBoundary(endAncestor, how);
  5835. if (frag)
  5836. frag.appendChild(n);
  5837. if (how != CLONE) {
  5838. t.setStartAfter(startAncestor);
  5839. t.collapse(TRUE);
  5840. }
  5841. return frag;
  5842. };
  5843. function _traverseRightBoundary(root, how) {
  5844. var next = _getSelectedNode(t[END_CONTAINER], t[END_OFFSET] - 1), parent, clonedParent, prevSibling, clonedChild, clonedGrandParent, isFullySelected = next != t[END_CONTAINER];
  5845. if (next == root)
  5846. return _traverseNode(next, isFullySelected, FALSE, how);
  5847. parent = next.parentNode;
  5848. clonedParent = _traverseNode(parent, FALSE, FALSE, how);
  5849. while (parent) {
  5850. while (next) {
  5851. prevSibling = next.previousSibling;
  5852. clonedChild = _traverseNode(next, isFullySelected, FALSE, how);
  5853. if (how != DELETE)
  5854. clonedParent.insertBefore(clonedChild, clonedParent.firstChild);
  5855. isFullySelected = TRUE;
  5856. next = prevSibling;
  5857. }
  5858. if (parent == root)
  5859. return clonedParent;
  5860. next = parent.previousSibling;
  5861. parent = parent.parentNode;
  5862. clonedGrandParent = _traverseNode(parent, FALSE, FALSE, how);
  5863. if (how != DELETE)
  5864. clonedGrandParent.appendChild(clonedParent);
  5865. clonedParent = clonedGrandParent;
  5866. }
  5867. };
  5868. function _traverseLeftBoundary(root, how) {
  5869. var next = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]), isFullySelected = next != t[START_CONTAINER], parent, clonedParent, nextSibling, clonedChild, clonedGrandParent;
  5870. if (next == root)
  5871. return _traverseNode(next, isFullySelected, TRUE, how);
  5872. parent = next.parentNode;
  5873. clonedParent = _traverseNode(parent, FALSE, TRUE, how);
  5874. while (parent) {
  5875. while (next) {
  5876. nextSibling = next.nextSibling;
  5877. clonedChild = _traverseNode(next, isFullySelected, TRUE, how);
  5878. if (how != DELETE)
  5879. clonedParent.appendChild(clonedChild);
  5880. isFullySelected = TRUE;
  5881. next = nextSibling;
  5882. }
  5883. if (parent == root)
  5884. return clonedParent;
  5885. next = parent.nextSibling;
  5886. parent = parent.parentNode;
  5887. clonedGrandParent = _traverseNode(parent, FALSE, TRUE, how);
  5888. if (how != DELETE)
  5889. clonedGrandParent.appendChild(clonedParent);
  5890. clonedParent = clonedGrandParent;
  5891. }
  5892. };
  5893. function _traverseNode(n, isFullySelected, isLeft, how) {
  5894. var txtValue, newNodeValue, oldNodeValue, offset, newNode;
  5895. if (isFullySelected)
  5896. return _traverseFullySelected(n, how);
  5897. if (n.nodeType == 3 /* TEXT_NODE */) {
  5898. txtValue = n.nodeValue;
  5899. if (isLeft) {
  5900. offset = t[START_OFFSET];
  5901. newNodeValue = txtValue.substring(offset);
  5902. oldNodeValue = txtValue.substring(0, offset);
  5903. } else {
  5904. offset = t[END_OFFSET];
  5905. newNodeValue = txtValue.substring(0, offset);
  5906. oldNodeValue = txtValue.substring(offset);
  5907. }
  5908. if (how != CLONE)
  5909. n.nodeValue = oldNodeValue;
  5910. if (how == DELETE)
  5911. return;
  5912. newNode = dom.clone(n, FALSE);
  5913. newNode.nodeValue = newNodeValue;
  5914. return newNode;
  5915. }
  5916. if (how == DELETE)
  5917. return;
  5918. return dom.clone(n, FALSE);
  5919. };
  5920. function _traverseFullySelected(n, how) {
  5921. if (how != DELETE)
  5922. return how == CLONE ? dom.clone(n, TRUE) : n;
  5923. n.parentNode.removeChild(n);
  5924. };
  5925. function toStringIE() {
  5926. return dom.create('body', null, cloneContents()).outerText;
  5927. }
  5928. return t;
  5929. };
  5930. ns.Range = Range;
  5931. // Older IE versions doesn't let you override toString by it's constructor so we have to stick it in the prototype
  5932. Range.prototype.toString = function() {
  5933. return this.toStringIE();
  5934. };
  5935. })(tinymce.dom);
  5936. (function() {
  5937. function Selection(selection) {
  5938. var self = this, dom = selection.dom, TRUE = true, FALSE = false;
  5939. function getPosition(rng, start) {
  5940. var checkRng, startIndex = 0, endIndex, inside,
  5941. children, child, offset, index, position = -1, parent;
  5942. // Setup test range, collapse it and get the parent
  5943. checkRng = rng.duplicate();
  5944. checkRng.collapse(start);
  5945. parent = checkRng.parentElement();
  5946. // Check if the selection is within the right document
  5947. if (parent.ownerDocument !== selection.dom.doc)
  5948. return;
  5949. // IE will report non editable elements as it's parent so look for an editable one
  5950. while (parent.contentEditable === "false") {
  5951. parent = parent.parentNode;
  5952. }
  5953. // If parent doesn't have any children then return that we are inside the element
  5954. if (!parent.hasChildNodes()) {
  5955. return {node : parent, inside : 1};
  5956. }
  5957. // Setup node list and endIndex
  5958. children = parent.children;
  5959. endIndex = children.length - 1;
  5960. // Perform a binary search for the position
  5961. while (startIndex <= endIndex) {
  5962. index = Math.floor((startIndex + endIndex) / 2);
  5963. // Move selection to node and compare the ranges
  5964. child = children[index];
  5965. checkRng.moveToElementText(child);
  5966. position = checkRng.compareEndPoints(start ? 'StartToStart' : 'EndToEnd', rng);
  5967. // Before/after or an exact match
  5968. if (position > 0) {
  5969. endIndex = index - 1;
  5970. } else if (position < 0) {
  5971. startIndex = index + 1;
  5972. } else {
  5973. return {node : child};
  5974. }
  5975. }
  5976. // Check if child position is before or we didn't find a position
  5977. if (position < 0) {
  5978. // No element child was found use the parent element and the offset inside that
  5979. if (!child) {
  5980. checkRng.moveToElementText(parent);
  5981. checkRng.collapse(true);
  5982. child = parent;
  5983. inside = true;
  5984. } else
  5985. checkRng.collapse(false);
  5986. // Walk character by character in text node until we hit the selected range endpoint, hit the end of document or parent isn't the right one
  5987. // We need to walk char by char since rng.text or rng.htmlText will trim line endings
  5988. offset = 0;
  5989. while (checkRng.compareEndPoints(start ? 'StartToStart' : 'StartToEnd', rng) !== 0) {
  5990. if (checkRng.move('character', 1) === 0 || parent != checkRng.parentElement()) {
  5991. break;
  5992. }
  5993. offset++;
  5994. }
  5995. } else {
  5996. // Child position is after the selection endpoint
  5997. checkRng.collapse(true);
  5998. // Walk character by character in text node until we hit the selected range endpoint, hit the end of document or parent isn't the right one
  5999. offset = 0;
  6000. while (checkRng.compareEndPoints(start ? 'StartToStart' : 'StartToEnd', rng) !== 0) {
  6001. if (checkRng.move('character', -1) === 0 || parent != checkRng.parentElement()) {
  6002. break;
  6003. }
  6004. offset++;
  6005. }
  6006. }
  6007. return {node : child, position : position, offset : offset, inside : inside};
  6008. };
  6009. // Returns a W3C DOM compatible range object by using the IE Range API
  6010. function getRange() {
  6011. var ieRange = selection.getRng(), domRange = dom.createRng(), element, collapsed, tmpRange, element2, bookmark, fail;
  6012. // If selection is outside the current document just return an empty range
  6013. element = ieRange.item ? ieRange.item(0) : ieRange.parentElement();
  6014. if (element.ownerDocument != dom.doc)
  6015. return domRange;
  6016. collapsed = selection.isCollapsed();
  6017. // Handle control selection
  6018. if (ieRange.item) {
  6019. domRange.setStart(element.parentNode, dom.nodeIndex(element));
  6020. domRange.setEnd(domRange.startContainer, domRange.startOffset + 1);
  6021. return domRange;
  6022. }
  6023. function findEndPoint(start) {
  6024. var endPoint = getPosition(ieRange, start), container, offset, textNodeOffset = 0, sibling, undef, nodeValue;
  6025. container = endPoint.node;
  6026. offset = endPoint.offset;
  6027. if (endPoint.inside && !container.hasChildNodes()) {
  6028. domRange[start ? 'setStart' : 'setEnd'](container, 0);
  6029. return;
  6030. }
  6031. if (offset === undef) {
  6032. domRange[start ? 'setStartBefore' : 'setEndAfter'](container);
  6033. return;
  6034. }
  6035. if (endPoint.position < 0) {
  6036. sibling = endPoint.inside ? container.firstChild : container.nextSibling;
  6037. if (!sibling) {
  6038. domRange[start ? 'setStartAfter' : 'setEndAfter'](container);
  6039. return;
  6040. }
  6041. if (!offset) {
  6042. if (sibling.nodeType == 3)
  6043. domRange[start ? 'setStart' : 'setEnd'](sibling, 0);
  6044. else
  6045. domRange[start ? 'setStartBefore' : 'setEndBefore'](sibling);
  6046. return;
  6047. }
  6048. // Find the text node and offset
  6049. while (sibling) {
  6050. nodeValue = sibling.nodeValue;
  6051. textNodeOffset += nodeValue.length;
  6052. // We are at or passed the position we where looking for
  6053. if (textNodeOffset >= offset) {
  6054. container = sibling;
  6055. textNodeOffset -= offset;
  6056. textNodeOffset = nodeValue.length - textNodeOffset;
  6057. break;
  6058. }
  6059. sibling = sibling.nextSibling;
  6060. }
  6061. } else {
  6062. // Find the text node and offset
  6063. sibling = container.previousSibling;
  6064. if (!sibling)
  6065. return domRange[start ? 'setStartBefore' : 'setEndBefore'](container);
  6066. // If there isn't any text to loop then use the first position
  6067. if (!offset) {
  6068. if (container.nodeType == 3)
  6069. domRange[start ? 'setStart' : 'setEnd'](sibling, container.nodeValue.length);
  6070. else
  6071. domRange[start ? 'setStartAfter' : 'setEndAfter'](sibling);
  6072. return;
  6073. }
  6074. while (sibling) {
  6075. textNodeOffset += sibling.nodeValue.length;
  6076. // We are at or passed the position we where looking for
  6077. if (textNodeOffset >= offset) {
  6078. container = sibling;
  6079. textNodeOffset -= offset;
  6080. break;
  6081. }
  6082. sibling = sibling.previousSibling;
  6083. }
  6084. }
  6085. domRange[start ? 'setStart' : 'setEnd'](container, textNodeOffset);
  6086. };
  6087. try {
  6088. // Find start point
  6089. findEndPoint(true);
  6090. // Find end point if needed
  6091. if (!collapsed)
  6092. findEndPoint();
  6093. } catch (ex) {
  6094. // IE has a nasty bug where text nodes might throw "invalid argument" when you
  6095. // access the nodeValue or other properties of text nodes. This seems to happend when
  6096. // text nodes are split into two nodes by a delete/backspace call. So lets detect it and try to fix it.
  6097. if (ex.number == -2147024809) {
  6098. // Get the current selection
  6099. bookmark = self.getBookmark(2);
  6100. // Get start element
  6101. tmpRange = ieRange.duplicate();
  6102. tmpRange.collapse(true);
  6103. element = tmpRange.parentElement();
  6104. // Get end element
  6105. if (!collapsed) {
  6106. tmpRange = ieRange.duplicate();
  6107. tmpRange.collapse(false);
  6108. element2 = tmpRange.parentElement();
  6109. element2.innerHTML = element2.innerHTML;
  6110. }
  6111. // Remove the broken elements
  6112. element.innerHTML = element.innerHTML;
  6113. // Restore the selection
  6114. self.moveToBookmark(bookmark);
  6115. // Since the range has moved we need to re-get it
  6116. ieRange = selection.getRng();
  6117. // Find start point
  6118. findEndPoint(true);
  6119. // Find end point if needed
  6120. if (!collapsed)
  6121. findEndPoint();
  6122. } else
  6123. throw ex; // Throw other errors
  6124. }
  6125. return domRange;
  6126. };
  6127. this.getBookmark = function(type) {
  6128. var rng = selection.getRng(), start, end, bookmark = {};
  6129. function getIndexes(node) {
  6130. var parent, root, children, i, indexes = [];
  6131. parent = node.parentNode;
  6132. root = dom.getRoot().parentNode;
  6133. while (parent != root && parent.nodeType !== 9) {
  6134. children = parent.children;
  6135. i = children.length;
  6136. while (i--) {
  6137. if (node === children[i]) {
  6138. indexes.push(i);
  6139. break;
  6140. }
  6141. }
  6142. node = parent;
  6143. parent = parent.parentNode;
  6144. }
  6145. return indexes;
  6146. };
  6147. function getBookmarkEndPoint(start) {
  6148. var position;
  6149. position = getPosition(rng, start);
  6150. if (position) {
  6151. return {
  6152. position : position.position,
  6153. offset : position.offset,
  6154. indexes : getIndexes(position.node),
  6155. inside : position.inside
  6156. };
  6157. }
  6158. };
  6159. // Non ubstructive bookmark
  6160. if (type === 2) {
  6161. // Handle text selection
  6162. if (!rng.item) {
  6163. bookmark.start = getBookmarkEndPoint(true);
  6164. if (!selection.isCollapsed())
  6165. bookmark.end = getBookmarkEndPoint();
  6166. } else
  6167. bookmark.start = {ctrl : true, indexes : getIndexes(rng.item(0))};
  6168. }
  6169. return bookmark;
  6170. };
  6171. this.moveToBookmark = function(bookmark) {
  6172. var rng, body = dom.doc.body;
  6173. function resolveIndexes(indexes) {
  6174. var node, i, idx, children;
  6175. node = dom.getRoot();
  6176. for (i = indexes.length - 1; i >= 0; i--) {
  6177. children = node.children;
  6178. idx = indexes[i];
  6179. if (idx <= children.length - 1) {
  6180. node = children[idx];
  6181. }
  6182. }
  6183. return node;
  6184. };
  6185. function setBookmarkEndPoint(start) {
  6186. var endPoint = bookmark[start ? 'start' : 'end'], moveLeft, moveRng, undef;
  6187. if (endPoint) {
  6188. moveLeft = endPoint.position > 0;
  6189. moveRng = body.createTextRange();
  6190. moveRng.moveToElementText(resolveIndexes(endPoint.indexes));
  6191. offset = endPoint.offset;
  6192. if (offset !== undef) {
  6193. moveRng.collapse(endPoint.inside || moveLeft);
  6194. moveRng.moveStart('character', moveLeft ? -offset : offset);
  6195. } else
  6196. moveRng.collapse(start);
  6197. rng.setEndPoint(start ? 'StartToStart' : 'EndToStart', moveRng);
  6198. if (start)
  6199. rng.collapse(true);
  6200. }
  6201. };
  6202. if (bookmark.start) {
  6203. if (bookmark.start.ctrl) {
  6204. rng = body.createControlRange();
  6205. rng.addElement(resolveIndexes(bookmark.start.indexes));
  6206. rng.select();
  6207. } else {
  6208. rng = body.createTextRange();
  6209. setBookmarkEndPoint(true);
  6210. setBookmarkEndPoint();
  6211. rng.select();
  6212. }
  6213. }
  6214. };
  6215. this.addRange = function(rng) {
  6216. var ieRng, ctrlRng, startContainer, startOffset, endContainer, endOffset, sibling,
  6217. doc = selection.dom.doc, body = doc.body, nativeRng, ctrlElm;
  6218. function setEndPoint(start) {
  6219. var container, offset, marker, tmpRng, nodes;
  6220. marker = dom.create('a');
  6221. container = start ? startContainer : endContainer;
  6222. offset = start ? startOffset : endOffset;
  6223. tmpRng = ieRng.duplicate();
  6224. if (container == doc || container == doc.documentElement) {
  6225. container = body;
  6226. offset = 0;
  6227. }
  6228. if (container.nodeType == 3) {
  6229. container.parentNode.insertBefore(marker, container);
  6230. tmpRng.moveToElementText(marker);
  6231. tmpRng.moveStart('character', offset);
  6232. dom.remove(marker);
  6233. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  6234. } else {
  6235. nodes = container.childNodes;
  6236. if (nodes.length) {
  6237. if (offset >= nodes.length) {
  6238. dom.insertAfter(marker, nodes[nodes.length - 1]);
  6239. } else {
  6240. container.insertBefore(marker, nodes[offset]);
  6241. }
  6242. tmpRng.moveToElementText(marker);
  6243. } else if (container.canHaveHTML) {
  6244. // Empty node selection for example <div>|</div>
  6245. // Setting innerHTML with a span marker then remove that marker seems to keep empty block elements open
  6246. container.innerHTML = '<span>\uFEFF</span>';
  6247. marker = container.firstChild;
  6248. tmpRng.moveToElementText(marker);
  6249. tmpRng.collapse(FALSE); // Collapse false works better than true for some odd reason
  6250. }
  6251. ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
  6252. dom.remove(marker);
  6253. }
  6254. }
  6255. // Setup some shorter versions
  6256. startContainer = rng.startContainer;
  6257. startOffset = rng.startOffset;
  6258. endContainer = rng.endContainer;
  6259. endOffset = rng.endOffset;
  6260. ieRng = body.createTextRange();
  6261. // If single element selection then try making a control selection out of it
  6262. if (startContainer == endContainer && startContainer.nodeType == 1) {
  6263. // Trick to place the caret inside an empty block element like <p></p>
  6264. if (startOffset == endOffset && !startContainer.hasChildNodes()) {
  6265. if (startContainer.canHaveHTML) {
  6266. // Check if previous sibling is an empty block if it is then we need to render it
  6267. // IE would otherwise move the caret into the sibling instead of the empty startContainer see: #5236
  6268. // Example this: <p></p><p>|</p> would become this: <p>|</p><p></p>
  6269. sibling = startContainer.previousSibling;
  6270. if (sibling && !sibling.hasChildNodes() && dom.isBlock(sibling)) {
  6271. sibling.innerHTML = '\uFEFF';
  6272. } else {
  6273. sibling = null;
  6274. }
  6275. startContainer.innerHTML = '<span>\uFEFF</span><span>\uFEFF</span>';
  6276. ieRng.moveToElementText(startContainer.lastChild);
  6277. ieRng.select();
  6278. dom.doc.selection.clear();
  6279. startContainer.innerHTML = '';
  6280. if (sibling) {
  6281. sibling.innerHTML = '';
  6282. }
  6283. return;
  6284. } else {
  6285. startOffset = dom.nodeIndex(startContainer);
  6286. startContainer = startContainer.parentNode;
  6287. }
  6288. }
  6289. if (startOffset == endOffset - 1) {
  6290. try {
  6291. ctrlElm = startContainer.childNodes[startOffset];
  6292. ctrlRng = body.createControlRange();
  6293. ctrlRng.addElement(ctrlElm);
  6294. ctrlRng.select();
  6295. // Check if the range produced is on the correct element and is a control range
  6296. // On IE 8 it will select the parent contentEditable container if you select an inner element see: #5398
  6297. nativeRng = selection.getRng();
  6298. if (nativeRng.item && ctrlElm === nativeRng.item(0)) {
  6299. return;
  6300. }
  6301. } catch (ex) {
  6302. // Ignore
  6303. }
  6304. }
  6305. }
  6306. // Set start/end point of selection
  6307. setEndPoint(true);
  6308. setEndPoint();
  6309. // Select the new range and scroll it into view
  6310. ieRng.select();
  6311. };
  6312. // Expose range method
  6313. this.getRangeAt = getRange;
  6314. };
  6315. // Expose the selection object
  6316. tinymce.dom.TridentSelection = Selection;
  6317. })();
  6318. (function(tinymce) {
  6319. tinymce.dom.Element = function(id, settings) {
  6320. var t = this, dom, el;
  6321. t.settings = settings = settings || {};
  6322. t.id = id;
  6323. t.dom = dom = settings.dom || tinymce.DOM;
  6324. // Only IE leaks DOM references, this is a lot faster
  6325. if (!tinymce.isIE)
  6326. el = dom.get(t.id);
  6327. tinymce.each(
  6328. ('getPos,getRect,getParent,add,setStyle,getStyle,setStyles,' +
  6329. 'setAttrib,setAttribs,getAttrib,addClass,removeClass,' +
  6330. 'hasClass,getOuterHTML,setOuterHTML,remove,show,hide,' +
  6331. 'isHidden,setHTML,get').split(/,/), function(k) {
  6332. t[k] = function() {
  6333. var a = [id], i;
  6334. for (i = 0; i < arguments.length; i++)
  6335. a.push(arguments[i]);
  6336. a = dom[k].apply(dom, a);
  6337. t.update(k);
  6338. return a;
  6339. };
  6340. }
  6341. );
  6342. tinymce.extend(t, {
  6343. on : function(n, f, s) {
  6344. return tinymce.dom.Event.add(t.id, n, f, s);
  6345. },
  6346. getXY : function() {
  6347. return {
  6348. x : parseInt(t.getStyle('left')),
  6349. y : parseInt(t.getStyle('top'))
  6350. };
  6351. },
  6352. getSize : function() {
  6353. var n = dom.get(t.id);
  6354. return {
  6355. w : parseInt(t.getStyle('width') || n.clientWidth),
  6356. h : parseInt(t.getStyle('height') || n.clientHeight)
  6357. };
  6358. },
  6359. moveTo : function(x, y) {
  6360. t.setStyles({left : x, top : y});
  6361. },
  6362. moveBy : function(x, y) {
  6363. var p = t.getXY();
  6364. t.moveTo(p.x + x, p.y + y);
  6365. },
  6366. resizeTo : function(w, h) {
  6367. t.setStyles({width : w, height : h});
  6368. },
  6369. resizeBy : function(w, h) {
  6370. var s = t.getSize();
  6371. t.resizeTo(s.w + w, s.h + h);
  6372. },
  6373. update : function(k) {
  6374. var b;
  6375. if (tinymce.isIE6 && settings.blocker) {
  6376. k = k || '';
  6377. // Ignore getters
  6378. if (k.indexOf('get') === 0 || k.indexOf('has') === 0 || k.indexOf('is') === 0)
  6379. return;
  6380. // Remove blocker on remove
  6381. if (k == 'remove') {
  6382. dom.remove(t.blocker);
  6383. return;
  6384. }
  6385. if (!t.blocker) {
  6386. t.blocker = dom.uniqueId();
  6387. b = dom.add(settings.container || dom.getRoot(), 'iframe', {id : t.blocker, style : 'position:absolute;', frameBorder : 0, src : 'javascript:""'});
  6388. dom.setStyle(b, 'opacity', 0);
  6389. } else
  6390. b = dom.get(t.blocker);
  6391. dom.setStyles(b, {
  6392. left : t.getStyle('left', 1),
  6393. top : t.getStyle('top', 1),
  6394. width : t.getStyle('width', 1),
  6395. height : t.getStyle('height', 1),
  6396. display : t.getStyle('display', 1),
  6397. zIndex : parseInt(t.getStyle('zIndex', 1) || 0) - 1
  6398. });
  6399. }
  6400. }
  6401. });
  6402. };
  6403. })(tinymce);
  6404. (function(tinymce) {
  6405. function trimNl(s) {
  6406. return s.replace(/[\n\r]+/g, '');
  6407. };
  6408. // Shorten names
  6409. var is = tinymce.is, isIE = tinymce.isIE, each = tinymce.each, TreeWalker = tinymce.dom.TreeWalker;
  6410. tinymce.create('tinymce.dom.Selection', {
  6411. Selection : function(dom, win, serializer, editor) {
  6412. var t = this;
  6413. t.dom = dom;
  6414. t.win = win;
  6415. t.serializer = serializer;
  6416. t.editor = editor;
  6417. // Add events
  6418. each([
  6419. 'onBeforeSetContent',
  6420. 'onBeforeGetContent',
  6421. 'onSetContent',
  6422. 'onGetContent'
  6423. ], function(e) {
  6424. t[e] = new tinymce.util.Dispatcher(t);
  6425. });
  6426. // No W3C Range support
  6427. if (!t.win.getSelection)
  6428. t.tridentSel = new tinymce.dom.TridentSelection(t);
  6429. if (tinymce.isIE && dom.boxModel)
  6430. this._fixIESelection();
  6431. // Prevent leaks
  6432. tinymce.addUnload(t.destroy, t);
  6433. },
  6434. setCursorLocation: function(node, offset) {
  6435. var t = this; var r = t.dom.createRng();
  6436. r.setStart(node, offset);
  6437. r.setEnd(node, offset);
  6438. t.setRng(r);
  6439. t.collapse(false);
  6440. },
  6441. getContent : function(s) {
  6442. var t = this, r = t.getRng(), e = t.dom.create("body"), se = t.getSel(), wb, wa, n;
  6443. s = s || {};
  6444. wb = wa = '';
  6445. s.get = true;
  6446. s.format = s.format || 'html';
  6447. s.forced_root_block = '';
  6448. t.onBeforeGetContent.dispatch(t, s);
  6449. if (s.format == 'text')
  6450. return t.isCollapsed() ? '' : (r.text || (se.toString ? se.toString() : ''));
  6451. if (r.cloneContents) {
  6452. n = r.cloneContents();
  6453. if (n)
  6454. e.appendChild(n);
  6455. } else if (is(r.item) || is(r.htmlText)) {
  6456. // IE will produce invalid markup if elements are present that
  6457. // it doesn't understand like custom elements or HTML5 elements.
  6458. // Adding a BR in front of the contents and then remoiving it seems to fix it though.
  6459. e.innerHTML = '<br>' + (r.item ? r.item(0).outerHTML : r.htmlText);
  6460. e.removeChild(e.firstChild);
  6461. } else
  6462. e.innerHTML = r.toString();
  6463. // Keep whitespace before and after
  6464. if (/^\s/.test(e.innerHTML))
  6465. wb = ' ';
  6466. if (/\s+$/.test(e.innerHTML))
  6467. wa = ' ';
  6468. s.getInner = true;
  6469. s.content = t.isCollapsed() ? '' : wb + t.serializer.serialize(e, s) + wa;
  6470. t.onGetContent.dispatch(t, s);
  6471. return s.content;
  6472. },
  6473. setContent : function(content, args) {
  6474. var self = this, rng = self.getRng(), caretNode, doc = self.win.document, frag, temp;
  6475. args = args || {format : 'html'};
  6476. args.set = true;
  6477. content = args.content = content;
  6478. // Dispatch before set content event
  6479. if (!args.no_events)
  6480. self.onBeforeSetContent.dispatch(self, args);
  6481. content = args.content;
  6482. if (rng.insertNode) {
  6483. // Make caret marker since insertNode places the caret in the beginning of text after insert
  6484. content += '<span id="__caret">_</span>';
  6485. // Delete and insert new node
  6486. if (rng.startContainer == doc && rng.endContainer == doc) {
  6487. // WebKit will fail if the body is empty since the range is then invalid and it can't insert contents
  6488. doc.body.innerHTML = content;
  6489. } else {
  6490. rng.deleteContents();
  6491. if (doc.body.childNodes.length === 0) {
  6492. doc.body.innerHTML = content;
  6493. } else {
  6494. // createContextualFragment doesn't exists in IE 9 DOMRanges
  6495. if (rng.createContextualFragment) {
  6496. rng.insertNode(rng.createContextualFragment(content));
  6497. } else {
  6498. // Fake createContextualFragment call in IE 9
  6499. frag = doc.createDocumentFragment();
  6500. temp = doc.createElement('div');
  6501. frag.appendChild(temp);
  6502. temp.outerHTML = content;
  6503. rng.insertNode(frag);
  6504. }
  6505. }
  6506. }
  6507. // Move to caret marker
  6508. caretNode = self.dom.get('__caret');
  6509. // Make sure we wrap it compleatly, Opera fails with a simple select call
  6510. rng = doc.createRange();
  6511. rng.setStartBefore(caretNode);
  6512. rng.setEndBefore(caretNode);
  6513. self.setRng(rng);
  6514. // Remove the caret position
  6515. self.dom.remove('__caret');
  6516. try {
  6517. self.setRng(rng);
  6518. } catch (ex) {
  6519. // Might fail on Opera for some odd reason
  6520. }
  6521. } else {
  6522. if (rng.item) {
  6523. // Delete content and get caret text selection
  6524. doc.execCommand('Delete', false, null);
  6525. rng = self.getRng();
  6526. }
  6527. // Explorer removes spaces from the beginning of pasted contents
  6528. if (/^\s+/.test(content)) {
  6529. rng.pasteHTML('<span id="__mce_tmp">_</span>' + content);
  6530. self.dom.remove('__mce_tmp');
  6531. } else
  6532. rng.pasteHTML(content);
  6533. }
  6534. // Dispatch set content event
  6535. if (!args.no_events)
  6536. self.onSetContent.dispatch(self, args);
  6537. },
  6538. getStart : function() {
  6539. var self = this, rng = self.getRng(), startElement, parentElement, checkRng, node;
  6540. if (rng.duplicate || rng.item) {
  6541. // Control selection, return first item
  6542. if (rng.item)
  6543. return rng.item(0);
  6544. // Get start element
  6545. checkRng = rng.duplicate();
  6546. checkRng.collapse(1);
  6547. startElement = checkRng.parentElement();
  6548. if (startElement.ownerDocument !== self.dom.doc) {
  6549. startElement = self.dom.getRoot();
  6550. }
  6551. // Check if range parent is inside the start element, then return the inner parent element
  6552. // This will fix issues when a single element is selected, IE would otherwise return the wrong start element
  6553. parentElement = node = rng.parentElement();
  6554. while (node = node.parentNode) {
  6555. if (node == startElement) {
  6556. startElement = parentElement;
  6557. break;
  6558. }
  6559. }
  6560. return startElement;
  6561. } else {
  6562. startElement = rng.startContainer;
  6563. if (startElement.nodeType == 1 && startElement.hasChildNodes())
  6564. startElement = startElement.childNodes[Math.min(startElement.childNodes.length - 1, rng.startOffset)];
  6565. if (startElement && startElement.nodeType == 3)
  6566. return startElement.parentNode;
  6567. return startElement;
  6568. }
  6569. },
  6570. getEnd : function() {
  6571. var self = this, rng = self.getRng(), endElement, endOffset;
  6572. if (rng.duplicate || rng.item) {
  6573. if (rng.item)
  6574. return rng.item(0);
  6575. rng = rng.duplicate();
  6576. rng.collapse(0);
  6577. endElement = rng.parentElement();
  6578. if (endElement.ownerDocument !== self.dom.doc) {
  6579. endElement = self.dom.getRoot();
  6580. }
  6581. if (endElement && endElement.nodeName == 'BODY')
  6582. return endElement.lastChild || endElement;
  6583. return endElement;
  6584. } else {
  6585. endElement = rng.endContainer;
  6586. endOffset = rng.endOffset;
  6587. if (endElement.nodeType == 1 && endElement.hasChildNodes())
  6588. endElement = endElement.childNodes[endOffset > 0 ? endOffset - 1 : endOffset];
  6589. if (endElement && endElement.nodeType == 3)
  6590. return endElement.parentNode;
  6591. return endElement;
  6592. }
  6593. },
  6594. getBookmark : function(type, normalized) {
  6595. var t = this, dom = t.dom, rng, rng2, id, collapsed, name, element, index, chr = '\uFEFF', styles;
  6596. function findIndex(name, element) {
  6597. var index = 0;
  6598. each(dom.select(name), function(node, i) {
  6599. if (node == element)
  6600. index = i;
  6601. });
  6602. return index;
  6603. };
  6604. function normalizeTableCellSelection(rng) {
  6605. function moveEndPoint(start) {
  6606. var container, offset, childNodes, prefix = start ? 'start' : 'end';
  6607. container = rng[prefix + 'Container'];
  6608. offset = rng[prefix + 'Offset'];
  6609. if (container.nodeType == 1 && container.nodeName == "TR") {
  6610. childNodes = container.childNodes;
  6611. container = childNodes[Math.min(start ? offset : offset - 1, childNodes.length - 1)];
  6612. if (container) {
  6613. offset = start ? 0 : container.childNodes.length;
  6614. rng['set' + (start ? 'Start' : 'End')](container, offset);
  6615. }
  6616. }
  6617. };
  6618. moveEndPoint(true);
  6619. moveEndPoint();
  6620. return rng;
  6621. };
  6622. function getLocation() {
  6623. var rng = t.getRng(true), root = dom.getRoot(), bookmark = {};
  6624. function getPoint(rng, start) {
  6625. var container = rng[start ? 'startContainer' : 'endContainer'],
  6626. offset = rng[start ? 'startOffset' : 'endOffset'], point = [], node, childNodes, after = 0;
  6627. if (container.nodeType == 3) {
  6628. if (normalized) {
  6629. for (node = container.previousSibling; node && node.nodeType == 3; node = node.previousSibling)
  6630. offset += node.nodeValue.length;
  6631. }
  6632. point.push(offset);
  6633. } else {
  6634. childNodes = container.childNodes;
  6635. if (offset >= childNodes.length && childNodes.length) {
  6636. after = 1;
  6637. offset = Math.max(0, childNodes.length - 1);
  6638. }
  6639. point.push(t.dom.nodeIndex(childNodes[offset], normalized) + after);
  6640. }
  6641. for (; container && container != root; container = container.parentNode)
  6642. point.push(t.dom.nodeIndex(container, normalized));
  6643. return point;
  6644. };
  6645. bookmark.start = getPoint(rng, true);
  6646. if (!t.isCollapsed())
  6647. bookmark.end = getPoint(rng);
  6648. return bookmark;
  6649. };
  6650. if (type == 2) {
  6651. if (t.tridentSel)
  6652. return t.tridentSel.getBookmark(type);
  6653. return getLocation();
  6654. }
  6655. // Handle simple range
  6656. if (type)
  6657. return {rng : t.getRng()};
  6658. rng = t.getRng();
  6659. id = dom.uniqueId();
  6660. collapsed = tinyMCE.activeEditor.selection.isCollapsed();
  6661. styles = 'overflow:hidden;line-height:0px';
  6662. // Explorer method
  6663. if (rng.duplicate || rng.item) {
  6664. // Text selection
  6665. if (!rng.item) {
  6666. rng2 = rng.duplicate();
  6667. try {
  6668. // Insert start marker
  6669. rng.collapse();
  6670. rng.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_start" style="' + styles + '">' + chr + '</span>');
  6671. // Insert end marker
  6672. if (!collapsed) {
  6673. rng2.collapse(false);
  6674. // Detect the empty space after block elements in IE and move the end back one character <p></p>] becomes <p>]</p>
  6675. rng.moveToElementText(rng2.parentElement());
  6676. if (rng.compareEndPoints('StartToEnd', rng2) === 0)
  6677. rng2.move('character', -1);
  6678. rng2.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_end" style="' + styles + '">' + chr + '</span>');
  6679. }
  6680. } catch (ex) {
  6681. // IE might throw unspecified error so lets ignore it
  6682. return null;
  6683. }
  6684. } else {
  6685. // Control selection
  6686. element = rng.item(0);
  6687. name = element.nodeName;
  6688. return {name : name, index : findIndex(name, element)};
  6689. }
  6690. } else {
  6691. element = t.getNode();
  6692. name = element.nodeName;
  6693. if (name == 'IMG')
  6694. return {name : name, index : findIndex(name, element)};
  6695. // W3C method
  6696. rng2 = normalizeTableCellSelection(rng.cloneRange());
  6697. // Insert end marker
  6698. if (!collapsed) {
  6699. rng2.collapse(false);
  6700. rng2.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_end', style : styles}, chr));
  6701. }
  6702. rng = normalizeTableCellSelection(rng);
  6703. rng.collapse(true);
  6704. rng.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_start', style : styles}, chr));
  6705. }
  6706. t.moveToBookmark({id : id, keep : 1});
  6707. return {id : id};
  6708. },
  6709. moveToBookmark : function(bookmark) {
  6710. var t = this, dom = t.dom, marker1, marker2, rng, root, startContainer, endContainer, startOffset, endOffset;
  6711. function setEndPoint(start) {
  6712. var point = bookmark[start ? 'start' : 'end'], i, node, offset, children;
  6713. if (point) {
  6714. offset = point[0];
  6715. // Find container node
  6716. for (node = root, i = point.length - 1; i >= 1; i--) {
  6717. children = node.childNodes;
  6718. if (point[i] > children.length - 1)
  6719. return;
  6720. node = children[point[i]];
  6721. }
  6722. // Move text offset to best suitable location
  6723. if (node.nodeType === 3)
  6724. offset = Math.min(point[0], node.nodeValue.length);
  6725. // Move element offset to best suitable location
  6726. if (node.nodeType === 1)
  6727. offset = Math.min(point[0], node.childNodes.length);
  6728. // Set offset within container node
  6729. if (start)
  6730. rng.setStart(node, offset);
  6731. else
  6732. rng.setEnd(node, offset);
  6733. }
  6734. return true;
  6735. };
  6736. function restoreEndPoint(suffix) {
  6737. var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep;
  6738. if (marker) {
  6739. node = marker.parentNode;
  6740. if (suffix == 'start') {
  6741. if (!keep) {
  6742. idx = dom.nodeIndex(marker);
  6743. } else {
  6744. node = marker.firstChild;
  6745. idx = 1;
  6746. }
  6747. startContainer = endContainer = node;
  6748. startOffset = endOffset = idx;
  6749. } else {
  6750. if (!keep) {
  6751. idx = dom.nodeIndex(marker);
  6752. } else {
  6753. node = marker.firstChild;
  6754. idx = 1;
  6755. }
  6756. endContainer = node;
  6757. endOffset = idx;
  6758. }
  6759. if (!keep) {
  6760. prev = marker.previousSibling;
  6761. next = marker.nextSibling;
  6762. // Remove all marker text nodes
  6763. each(tinymce.grep(marker.childNodes), function(node) {
  6764. if (node.nodeType == 3)
  6765. node.nodeValue = node.nodeValue.replace(/\uFEFF/g, '');
  6766. });
  6767. // Remove marker but keep children if for example contents where inserted into the marker
  6768. // Also remove duplicated instances of the marker for example by a split operation or by WebKit auto split on paste feature
  6769. while (marker = dom.get(bookmark.id + '_' + suffix))
  6770. dom.remove(marker, 1);
  6771. // If siblings are text nodes then merge them unless it's Opera since it some how removes the node
  6772. // 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
  6773. if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3 && !tinymce.isOpera) {
  6774. idx = prev.nodeValue.length;
  6775. prev.appendData(next.nodeValue);
  6776. dom.remove(next);
  6777. if (suffix == 'start') {
  6778. startContainer = endContainer = prev;
  6779. startOffset = endOffset = idx;
  6780. } else {
  6781. endContainer = prev;
  6782. endOffset = idx;
  6783. }
  6784. }
  6785. }
  6786. }
  6787. };
  6788. function addBogus(node) {
  6789. // Adds a bogus BR element for empty block elements
  6790. if (dom.isBlock(node) && !node.innerHTML && !isIE)
  6791. node.innerHTML = '<br data-mce-bogus="1" />';
  6792. return node;
  6793. };
  6794. if (bookmark) {
  6795. if (bookmark.start) {
  6796. rng = dom.createRng();
  6797. root = dom.getRoot();
  6798. if (t.tridentSel)
  6799. return t.tridentSel.moveToBookmark(bookmark);
  6800. if (setEndPoint(true) && setEndPoint()) {
  6801. t.setRng(rng);
  6802. }
  6803. } else if (bookmark.id) {
  6804. // Restore start/end points
  6805. restoreEndPoint('start');
  6806. restoreEndPoint('end');
  6807. if (startContainer) {
  6808. rng = dom.createRng();
  6809. rng.setStart(addBogus(startContainer), startOffset);
  6810. rng.setEnd(addBogus(endContainer), endOffset);
  6811. t.setRng(rng);
  6812. }
  6813. } else if (bookmark.name) {
  6814. t.select(dom.select(bookmark.name)[bookmark.index]);
  6815. } else if (bookmark.rng)
  6816. t.setRng(bookmark.rng);
  6817. }
  6818. },
  6819. select : function(node, content) {
  6820. var t = this, dom = t.dom, rng = dom.createRng(), idx;
  6821. function setPoint(node, start) {
  6822. var walker = new TreeWalker(node, node);
  6823. do {
  6824. // Text node
  6825. if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length !== 0) {
  6826. if (start)
  6827. rng.setStart(node, 0);
  6828. else
  6829. rng.setEnd(node, node.nodeValue.length);
  6830. return;
  6831. }
  6832. // BR element
  6833. if (node.nodeName == 'BR') {
  6834. if (start)
  6835. rng.setStartBefore(node);
  6836. else
  6837. rng.setEndBefore(node);
  6838. return;
  6839. }
  6840. } while (node = (start ? walker.next() : walker.prev()));
  6841. };
  6842. if (node) {
  6843. idx = dom.nodeIndex(node);
  6844. rng.setStart(node.parentNode, idx);
  6845. rng.setEnd(node.parentNode, idx + 1);
  6846. // Find first/last text node or BR element
  6847. if (content) {
  6848. setPoint(node, 1);
  6849. setPoint(node);
  6850. }
  6851. t.setRng(rng);
  6852. }
  6853. return node;
  6854. },
  6855. isCollapsed : function() {
  6856. var t = this, r = t.getRng(), s = t.getSel();
  6857. if (!r || r.item)
  6858. return false;
  6859. if (r.compareEndPoints)
  6860. return r.compareEndPoints('StartToEnd', r) === 0;
  6861. return !s || r.collapsed;
  6862. },
  6863. collapse : function(to_start) {
  6864. var self = this, rng = self.getRng(), node;
  6865. // Control range on IE
  6866. if (rng.item) {
  6867. node = rng.item(0);
  6868. rng = self.win.document.body.createTextRange();
  6869. rng.moveToElementText(node);
  6870. }
  6871. rng.collapse(!!to_start);
  6872. self.setRng(rng);
  6873. },
  6874. getSel : function() {
  6875. var t = this, w = this.win;
  6876. return w.getSelection ? w.getSelection() : w.document.selection;
  6877. },
  6878. getRng : function(w3c) {
  6879. var self = this, selection, rng, elm, doc = self.win.document;
  6880. // Found tridentSel object then we need to use that one
  6881. if (w3c && self.tridentSel) {
  6882. return self.tridentSel.getRangeAt(0);
  6883. }
  6884. try {
  6885. if (selection = self.getSel()) {
  6886. rng = selection.rangeCount > 0 ? selection.getRangeAt(0) : (selection.createRange ? selection.createRange() : doc.createRange());
  6887. }
  6888. } catch (ex) {
  6889. // IE throws unspecified error here if TinyMCE is placed in a frame/iframe
  6890. }
  6891. // We have W3C ranges and it's IE then fake control selection since IE9 doesn't handle that correctly yet
  6892. if (tinymce.isIE && rng && rng.setStart && doc.selection.createRange().item) {
  6893. elm = doc.selection.createRange().item(0);
  6894. rng = doc.createRange();
  6895. rng.setStartBefore(elm);
  6896. rng.setEndAfter(elm);
  6897. }
  6898. // No range found then create an empty one
  6899. // This can occur when the editor is placed in a hidden container element on Gecko
  6900. // Or on IE when there was an exception
  6901. if (!rng) {
  6902. rng = doc.createRange ? doc.createRange() : doc.body.createTextRange();
  6903. }
  6904. // If range is at start of document then move it to start of body
  6905. if (rng.setStart && rng.startContainer.nodeType === 9 && rng.collapsed) {
  6906. elm = self.dom.getRoot();
  6907. rng.setStart(elm, 0);
  6908. rng.setEnd(elm, 0);
  6909. }
  6910. if (self.selectedRange && self.explicitRange) {
  6911. if (rng.compareBoundaryPoints(rng.START_TO_START, self.selectedRange) === 0 && rng.compareBoundaryPoints(rng.END_TO_END, self.selectedRange) === 0) {
  6912. // Safari, Opera and Chrome only ever select text which causes the range to change.
  6913. // This lets us use the originally set range if the selection hasn't been changed by the user.
  6914. rng = self.explicitRange;
  6915. } else {
  6916. self.selectedRange = null;
  6917. self.explicitRange = null;
  6918. }
  6919. }
  6920. return rng;
  6921. },
  6922. setRng : function(r, forward) {
  6923. var s, t = this;
  6924. if (!t.tridentSel) {
  6925. s = t.getSel();
  6926. if (s) {
  6927. t.explicitRange = r;
  6928. try {
  6929. s.removeAllRanges();
  6930. } catch (ex) {
  6931. // IE9 might throw errors here don't know why
  6932. }
  6933. s.addRange(r);
  6934. // Forward is set to false and we have an extend function
  6935. if (forward === false && s.extend) {
  6936. s.collapse(r.endContainer, r.endOffset);
  6937. s.extend(r.startContainer, r.startOffset);
  6938. }
  6939. // adding range isn't always successful so we need to check range count otherwise an exception can occur
  6940. t.selectedRange = s.rangeCount > 0 ? s.getRangeAt(0) : null;
  6941. }
  6942. } else {
  6943. // Is W3C Range
  6944. if (r.cloneRange) {
  6945. try {
  6946. t.tridentSel.addRange(r);
  6947. return;
  6948. } catch (ex) {
  6949. //IE9 throws an error here if called before selection is placed in the editor
  6950. }
  6951. }
  6952. // Is IE specific range
  6953. try {
  6954. r.select();
  6955. } catch (ex) {
  6956. // Needed for some odd IE bug #1843306
  6957. }
  6958. }
  6959. },
  6960. setNode : function(n) {
  6961. var t = this;
  6962. t.setContent(t.dom.getOuterHTML(n));
  6963. return n;
  6964. },
  6965. getNode : function() {
  6966. var t = this, rng = t.getRng(), sel = t.getSel(), elm, start = rng.startContainer, end = rng.endContainer;
  6967. function skipEmptyTextNodes(n, forwards) {
  6968. var orig = n;
  6969. while (n && n.nodeType === 3 && n.length === 0) {
  6970. n = forwards ? n.nextSibling : n.previousSibling;
  6971. }
  6972. return n || orig;
  6973. };
  6974. // Range maybe lost after the editor is made visible again
  6975. if (!rng)
  6976. return t.dom.getRoot();
  6977. if (rng.setStart) {
  6978. elm = rng.commonAncestorContainer;
  6979. // Handle selection a image or other control like element such as anchors
  6980. if (!rng.collapsed) {
  6981. if (rng.startContainer == rng.endContainer) {
  6982. if (rng.endOffset - rng.startOffset < 2) {
  6983. if (rng.startContainer.hasChildNodes())
  6984. elm = rng.startContainer.childNodes[rng.startOffset];
  6985. }
  6986. }
  6987. // If the anchor node is a element instead of a text node then return this element
  6988. //if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1)
  6989. // return sel.anchorNode.childNodes[sel.anchorOffset];
  6990. // Handle cases where the selection is immediately wrapped around a node and return that node instead of it's parent.
  6991. // This happens when you double click an underlined word in FireFox.
  6992. if (start.nodeType === 3 && end.nodeType === 3) {
  6993. if (start.length === rng.startOffset) {
  6994. start = skipEmptyTextNodes(start.nextSibling, true);
  6995. } else {
  6996. start = start.parentNode;
  6997. }
  6998. if (rng.endOffset === 0) {
  6999. end = skipEmptyTextNodes(end.previousSibling, false);
  7000. } else {
  7001. end = end.parentNode;
  7002. }
  7003. if (start && start === end)
  7004. return start;
  7005. }
  7006. }
  7007. if (elm && elm.nodeType == 3)
  7008. return elm.parentNode;
  7009. return elm;
  7010. }
  7011. return rng.item ? rng.item(0) : rng.parentElement();
  7012. },
  7013. getSelectedBlocks : function(st, en) {
  7014. var t = this, dom = t.dom, sb, eb, n, bl = [];
  7015. sb = dom.getParent(st || t.getStart(), dom.isBlock);
  7016. eb = dom.getParent(en || t.getEnd(), dom.isBlock);
  7017. if (sb)
  7018. bl.push(sb);
  7019. if (sb && eb && sb != eb) {
  7020. n = sb;
  7021. var walker = new TreeWalker(sb, dom.getRoot());
  7022. while ((n = walker.next()) && n != eb) {
  7023. if (dom.isBlock(n))
  7024. bl.push(n);
  7025. }
  7026. }
  7027. if (eb && sb != eb)
  7028. bl.push(eb);
  7029. return bl;
  7030. },
  7031. isForward: function(){
  7032. var dom = this.dom, sel = this.getSel(), anchorRange, focusRange;
  7033. // No support for selection direction then always return true
  7034. if (!sel || sel.anchorNode == null || sel.focusNode == null) {
  7035. return true;
  7036. }
  7037. anchorRange = dom.createRng();
  7038. anchorRange.setStart(sel.anchorNode, sel.anchorOffset);
  7039. anchorRange.collapse(true);
  7040. focusRange = dom.createRng();
  7041. focusRange.setStart(sel.focusNode, sel.focusOffset);
  7042. focusRange.collapse(true);
  7043. return anchorRange.compareBoundaryPoints(anchorRange.START_TO_START, focusRange) <= 0;
  7044. },
  7045. normalize : function() {
  7046. var self = this, rng, normalized, collapsed, node, sibling;
  7047. function normalizeEndPoint(start) {
  7048. var container, offset, walker, dom = self.dom, body = dom.getRoot(), node, nonEmptyElementsMap, nodeName;
  7049. function hasBrBeforeAfter(node, left) {
  7050. var walker = new TreeWalker(node, dom.getParent(node.parentNode, dom.isBlock) || body);
  7051. while (node = walker[left ? 'prev' : 'next']()) {
  7052. if (node.nodeName === "BR") {
  7053. return true;
  7054. }
  7055. }
  7056. };
  7057. // Walks the dom left/right to find a suitable text node to move the endpoint into
  7058. // It will only walk within the current parent block or body and will stop if it hits a block or a BR/IMG
  7059. function findTextNodeRelative(left, startNode) {
  7060. var walker, lastInlineElement;
  7061. startNode = startNode || container;
  7062. walker = new TreeWalker(startNode, dom.getParent(startNode.parentNode, dom.isBlock) || body);
  7063. // Walk left until we hit a text node we can move to or a block/br/img
  7064. while (node = walker[left ? 'prev' : 'next']()) {
  7065. // Found text node that has a length
  7066. if (node.nodeType === 3 && node.nodeValue.length > 0) {
  7067. container = node;
  7068. offset = left ? node.nodeValue.length : 0;
  7069. normalized = true;
  7070. return;
  7071. }
  7072. // Break if we find a block or a BR/IMG/INPUT etc
  7073. if (dom.isBlock(node) || nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  7074. return;
  7075. }
  7076. lastInlineElement = node;
  7077. }
  7078. // Only fetch the last inline element when in caret mode for now
  7079. if (collapsed && lastInlineElement) {
  7080. container = lastInlineElement;
  7081. normalized = true;
  7082. offset = 0;
  7083. }
  7084. };
  7085. container = rng[(start ? 'start' : 'end') + 'Container'];
  7086. offset = rng[(start ? 'start' : 'end') + 'Offset'];
  7087. nonEmptyElementsMap = dom.schema.getNonEmptyElements();
  7088. // If the container is a document move it to the body element
  7089. if (container.nodeType === 9) {
  7090. container = dom.getRoot();
  7091. offset = 0;
  7092. }
  7093. // If the container is body try move it into the closest text node or position
  7094. if (container === body) {
  7095. // If start is before/after a image, table etc
  7096. if (start) {
  7097. node = container.childNodes[offset > 0 ? offset - 1 : 0];
  7098. if (node) {
  7099. nodeName = node.nodeName.toLowerCase();
  7100. if (nonEmptyElementsMap[node.nodeName] || node.nodeName == "TABLE") {
  7101. return;
  7102. }
  7103. }
  7104. }
  7105. // Resolve the index
  7106. if (container.hasChildNodes()) {
  7107. container = container.childNodes[Math.min(!start && offset > 0 ? offset - 1 : offset, container.childNodes.length - 1)];
  7108. offset = 0;
  7109. // Don't walk into elements that doesn't have any child nodes like a IMG
  7110. if (container.hasChildNodes() && !/TABLE/.test(container.nodeName)) {
  7111. // Walk the DOM to find a text node to place the caret at or a BR
  7112. node = container;
  7113. walker = new TreeWalker(container, body);
  7114. do {
  7115. // Found a text node use that position
  7116. if (node.nodeType === 3 && node.nodeValue.length > 0) {
  7117. offset = start ? 0 : node.nodeValue.length;
  7118. container = node;
  7119. normalized = true;
  7120. break;
  7121. }
  7122. // Found a BR/IMG element that we can place the caret before
  7123. if (nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  7124. offset = dom.nodeIndex(node);
  7125. container = node.parentNode;
  7126. // Put caret after image when moving the end point
  7127. if (node.nodeName == "IMG" && !start) {
  7128. offset++;
  7129. }
  7130. normalized = true;
  7131. break;
  7132. }
  7133. } while (node = (start ? walker.next() : walker.prev()));
  7134. }
  7135. }
  7136. }
  7137. // Lean the caret to the left if possible
  7138. if (collapsed) {
  7139. // So this: <b>x</b><i>|x</i>
  7140. // Becomes: <b>x|</b><i>x</i>
  7141. // Seems that only gecko has issues with this
  7142. if (container.nodeType === 3 && offset === 0) {
  7143. findTextNodeRelative(true);
  7144. }
  7145. // Lean left into empty inline elements when the caret is before a BR
  7146. // So this: <i><b></b><i>|<br></i>
  7147. // Becomes: <i><b>|</b><i><br></i>
  7148. // Seems that only gecko has issues with this
  7149. if (container.nodeType === 1) {
  7150. node = container.childNodes[offset];
  7151. if(node && node.nodeName === 'BR' && !hasBrBeforeAfter(node) && !hasBrBeforeAfter(node, true)) {
  7152. findTextNodeRelative(true, container.childNodes[offset]);
  7153. }
  7154. }
  7155. }
  7156. // Lean the start of the selection right if possible
  7157. // So this: x[<b>x]</b>
  7158. // Becomes: x<b>[x]</b>
  7159. if (start && !collapsed && container.nodeType === 3 && offset === container.nodeValue.length) {
  7160. findTextNodeRelative(false);
  7161. }
  7162. // Set endpoint if it was normalized
  7163. if (normalized)
  7164. rng['set' + (start ? 'Start' : 'End')](container, offset);
  7165. };
  7166. // Normalize only on non IE browsers for now
  7167. if (tinymce.isIE)
  7168. return;
  7169. rng = self.getRng();
  7170. collapsed = rng.collapsed;
  7171. // Normalize the end points
  7172. normalizeEndPoint(true);
  7173. if (!collapsed)
  7174. normalizeEndPoint();
  7175. // Set the selection if it was normalized
  7176. if (normalized) {
  7177. // If it was collapsed then make sure it still is
  7178. if (collapsed) {
  7179. rng.collapse(true);
  7180. }
  7181. //console.log(self.dom.dumpRng(rng));
  7182. self.setRng(rng, self.isForward());
  7183. }
  7184. },
  7185. selectorChanged: function(selector, callback) {
  7186. var self = this, currentSelectors;
  7187. if (!self.selectorChangedData) {
  7188. self.selectorChangedData = {};
  7189. currentSelectors = {};
  7190. self.editor.onNodeChange.addToTop(function(ed, cm, node) {
  7191. var dom = self.dom, parents = dom.getParents(node, null, dom.getRoot()), matchedSelectors = {};
  7192. // Check for new matching selectors
  7193. each(self.selectorChangedData, function(callbacks, selector) {
  7194. each(parents, function(node) {
  7195. if (dom.is(node, selector)) {
  7196. if (!currentSelectors[selector]) {
  7197. // Execute callbacks
  7198. each(callbacks, function(callback) {
  7199. callback(true, {node: node, selector: selector, parents: parents});
  7200. });
  7201. currentSelectors[selector] = callbacks;
  7202. }
  7203. matchedSelectors[selector] = callbacks;
  7204. return false;
  7205. }
  7206. });
  7207. });
  7208. // Check if current selectors still match
  7209. each(currentSelectors, function(callbacks, selector) {
  7210. if (!matchedSelectors[selector]) {
  7211. delete currentSelectors[selector];
  7212. each(callbacks, function(callback) {
  7213. callback(false, {node: node, selector: selector, parents: parents});
  7214. });
  7215. }
  7216. });
  7217. });
  7218. }
  7219. // Add selector listeners
  7220. if (!self.selectorChangedData[selector]) {
  7221. self.selectorChangedData[selector] = [];
  7222. }
  7223. self.selectorChangedData[selector].push(callback);
  7224. return self;
  7225. },
  7226. scrollIntoView: function(elm) {
  7227. var y, viewPort, self = this, dom = self.dom;
  7228. viewPort = dom.getViewPort(self.editor.getWin());
  7229. y = dom.getPos(elm).y;
  7230. if (y < viewPort.y || y + 25 > viewPort.y + viewPort.h) {
  7231. self.editor.getWin().scrollTo(0, y < viewPort.y ? y : y - viewPort.h + 25);
  7232. }
  7233. },
  7234. destroy : function(manual) {
  7235. var self = this;
  7236. self.win = null;
  7237. // Manual destroy then remove unload handler
  7238. if (!manual)
  7239. tinymce.removeUnload(self.destroy);
  7240. },
  7241. // IE has an issue where you can't select/move the caret by clicking outside the body if the document is in standards mode
  7242. _fixIESelection : function() {
  7243. var dom = this.dom, doc = dom.doc, body = doc.body, started, startRng, htmlElm;
  7244. // Return range from point or null if it failed
  7245. function rngFromPoint(x, y) {
  7246. var rng = body.createTextRange();
  7247. try {
  7248. rng.moveToPoint(x, y);
  7249. } catch (ex) {
  7250. // IE sometimes throws and exception, so lets just ignore it
  7251. rng = null;
  7252. }
  7253. return rng;
  7254. };
  7255. // Fires while the selection is changing
  7256. function selectionChange(e) {
  7257. var pointRng;
  7258. // Check if the button is down or not
  7259. if (e.button) {
  7260. // Create range from mouse position
  7261. pointRng = rngFromPoint(e.x, e.y);
  7262. if (pointRng) {
  7263. // Check if pointRange is before/after selection then change the endPoint
  7264. if (pointRng.compareEndPoints('StartToStart', startRng) > 0)
  7265. pointRng.setEndPoint('StartToStart', startRng);
  7266. else
  7267. pointRng.setEndPoint('EndToEnd', startRng);
  7268. pointRng.select();
  7269. }
  7270. } else
  7271. endSelection();
  7272. }
  7273. // Removes listeners
  7274. function endSelection() {
  7275. var rng = doc.selection.createRange();
  7276. // If the range is collapsed then use the last start range
  7277. if (startRng && !rng.item && rng.compareEndPoints('StartToEnd', rng) === 0)
  7278. startRng.select();
  7279. dom.unbind(doc, 'mouseup', endSelection);
  7280. dom.unbind(doc, 'mousemove', selectionChange);
  7281. startRng = started = 0;
  7282. };
  7283. // Make HTML element unselectable since we are going to handle selection by hand
  7284. doc.documentElement.unselectable = true;
  7285. // Detect when user selects outside BODY
  7286. dom.bind(doc, ['mousedown', 'contextmenu'], function(e) {
  7287. if (e.target.nodeName === 'HTML') {
  7288. if (started)
  7289. endSelection();
  7290. // Detect vertical scrollbar, since IE will fire a mousedown on the scrollbar and have target set as HTML
  7291. htmlElm = doc.documentElement;
  7292. if (htmlElm.scrollHeight > htmlElm.clientHeight)
  7293. return;
  7294. started = 1;
  7295. // Setup start position
  7296. startRng = rngFromPoint(e.x, e.y);
  7297. if (startRng) {
  7298. // Listen for selection change events
  7299. dom.bind(doc, 'mouseup', endSelection);
  7300. dom.bind(doc, 'mousemove', selectionChange);
  7301. dom.win.focus();
  7302. startRng.select();
  7303. }
  7304. }
  7305. });
  7306. }
  7307. });
  7308. })(tinymce);
  7309. (function(tinymce) {
  7310. tinymce.dom.Serializer = function(settings, dom, schema) {
  7311. var onPreProcess, onPostProcess, isIE = tinymce.isIE, each = tinymce.each, htmlParser;
  7312. // Support the old apply_source_formatting option
  7313. if (!settings.apply_source_formatting)
  7314. settings.indent = false;
  7315. // Default DOM and Schema if they are undefined
  7316. dom = dom || tinymce.DOM;
  7317. schema = schema || new tinymce.html.Schema(settings);
  7318. settings.entity_encoding = settings.entity_encoding || 'named';
  7319. settings.remove_trailing_brs = "remove_trailing_brs" in settings ? settings.remove_trailing_brs : true;
  7320. onPreProcess = new tinymce.util.Dispatcher(self);
  7321. onPostProcess = new tinymce.util.Dispatcher(self);
  7322. htmlParser = new tinymce.html.DomParser(settings, schema);
  7323. // Convert move data-mce-src, data-mce-href and data-mce-style into nodes or process them if needed
  7324. htmlParser.addAttributeFilter('src,href,style', function(nodes, name) {
  7325. var i = nodes.length, node, value, internalName = 'data-mce-' + name, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope, undef;
  7326. while (i--) {
  7327. node = nodes[i];
  7328. value = node.attributes.map[internalName];
  7329. if (value !== undef) {
  7330. // Set external name to internal value and remove internal
  7331. node.attr(name, value.length > 0 ? value : null);
  7332. node.attr(internalName, null);
  7333. } else {
  7334. // No internal attribute found then convert the value we have in the DOM
  7335. value = node.attributes.map[name];
  7336. if (name === "style")
  7337. value = dom.serializeStyle(dom.parseStyle(value), node.name);
  7338. else if (urlConverter)
  7339. value = urlConverter.call(urlConverterScope, value, name, node.name);
  7340. node.attr(name, value.length > 0 ? value : null);
  7341. }
  7342. }
  7343. });
  7344. // Remove internal classes mceItem<..> or mceSelected
  7345. htmlParser.addAttributeFilter('class', function(nodes, name) {
  7346. var i = nodes.length, node, value;
  7347. while (i--) {
  7348. node = nodes[i];
  7349. value = node.attr('class').replace(/(?:^|\s)mce(Item\w+|Selected)(?!\S)/g, '');
  7350. node.attr('class', value.length > 0 ? value : null);
  7351. }
  7352. });
  7353. // Remove bookmark elements
  7354. htmlParser.addAttributeFilter('data-mce-type', function(nodes, name, args) {
  7355. var i = nodes.length, node;
  7356. while (i--) {
  7357. node = nodes[i];
  7358. if (node.attributes.map['data-mce-type'] === 'bookmark' && !args.cleanup)
  7359. node.remove();
  7360. }
  7361. });
  7362. // Remove expando attributes
  7363. htmlParser.addAttributeFilter('data-mce-expando', function(nodes, name, args) {
  7364. var i = nodes.length;
  7365. while (i--) {
  7366. nodes[i].attr(name, null);
  7367. }
  7368. });
  7369. htmlParser.addNodeFilter('noscript', function(nodes) {
  7370. var i = nodes.length, node;
  7371. while (i--) {
  7372. node = nodes[i].firstChild;
  7373. if (node) {
  7374. node.value = tinymce.html.Entities.decode(node.value);
  7375. }
  7376. }
  7377. });
  7378. // Force script into CDATA sections and remove the mce- prefix also add comments around styles
  7379. htmlParser.addNodeFilter('script,style', function(nodes, name) {
  7380. var i = nodes.length, node, value;
  7381. function trim(value) {
  7382. return value.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n')
  7383. .replace(/^[\r\n]*|[\r\n]*$/g, '')
  7384. .replace(/^\s*((<!--)?(\s*\/\/)?\s*<!\[CDATA\[|(<!--\s*)?\/\*\s*<!\[CDATA\[\s*\*\/|(\/\/)?\s*<!--|\/\*\s*<!--\s*\*\/)\s*[\r\n]*/gi, '')
  7385. .replace(/\s*(\/\*\s*\]\]>\s*\*\/(-->)?|\s*\/\/\s*\]\]>(-->)?|\/\/\s*(-->)?|\]\]>|\/\*\s*-->\s*\*\/|\s*-->\s*)\s*$/g, '');
  7386. };
  7387. while (i--) {
  7388. node = nodes[i];
  7389. value = node.firstChild ? node.firstChild.value : '';
  7390. if (name === "script") {
  7391. // Remove mce- prefix from script elements
  7392. node.attr('type', (node.attr('type') || 'text/javascript').replace(/^mce\-/, ''));
  7393. if (value.length > 0)
  7394. node.firstChild.value = '// <![CDATA[\n' + trim(value) + '\n// ]]>';
  7395. } else {
  7396. if (value.length > 0)
  7397. node.firstChild.value = '<!--\n' + trim(value) + '\n-->';
  7398. }
  7399. }
  7400. });
  7401. // Convert comments to cdata and handle protected comments
  7402. htmlParser.addNodeFilter('#comment', function(nodes, name) {
  7403. var i = nodes.length, node;
  7404. while (i--) {
  7405. node = nodes[i];
  7406. if (node.value.indexOf('[CDATA[') === 0) {
  7407. node.name = '#cdata';
  7408. node.type = 4;
  7409. node.value = node.value.replace(/^\[CDATA\[|\]\]$/g, '');
  7410. } else if (node.value.indexOf('mce:protected ') === 0) {
  7411. node.name = "#text";
  7412. node.type = 3;
  7413. node.raw = true;
  7414. node.value = unescape(node.value).substr(14);
  7415. }
  7416. }
  7417. });
  7418. htmlParser.addNodeFilter('xml:namespace,input', function(nodes, name) {
  7419. var i = nodes.length, node;
  7420. while (i--) {
  7421. node = nodes[i];
  7422. if (node.type === 7)
  7423. node.remove();
  7424. else if (node.type === 1) {
  7425. if (name === "input" && !("type" in node.attributes.map))
  7426. node.attr('type', 'text');
  7427. }
  7428. }
  7429. });
  7430. // Fix list elements, TODO: Replace this later
  7431. if (settings.fix_list_elements) {
  7432. htmlParser.addNodeFilter('ul,ol', function(nodes, name) {
  7433. var i = nodes.length, node, parentNode;
  7434. while (i--) {
  7435. node = nodes[i];
  7436. parentNode = node.parent;
  7437. if (parentNode.name === 'ul' || parentNode.name === 'ol') {
  7438. if (node.prev && node.prev.name === 'li') {
  7439. node.prev.append(node);
  7440. }
  7441. }
  7442. }
  7443. });
  7444. }
  7445. // Remove internal data attributes
  7446. htmlParser.addAttributeFilter('data-mce-src,data-mce-href,data-mce-style', function(nodes, name) {
  7447. var i = nodes.length;
  7448. while (i--) {
  7449. nodes[i].attr(name, null);
  7450. }
  7451. });
  7452. // Return public methods
  7453. return {
  7454. schema : schema,
  7455. addNodeFilter : htmlParser.addNodeFilter,
  7456. addAttributeFilter : htmlParser.addAttributeFilter,
  7457. onPreProcess : onPreProcess,
  7458. onPostProcess : onPostProcess,
  7459. serialize : function(node, args) {
  7460. var impl, doc, oldDoc, htmlSerializer, content;
  7461. // Explorer won't clone contents of script and style and the
  7462. // selected index of select elements are cleared on a clone operation.
  7463. if (isIE && dom.select('script,style,select,map').length > 0) {
  7464. content = node.innerHTML;
  7465. node = node.cloneNode(false);
  7466. dom.setHTML(node, content);
  7467. } else
  7468. node = node.cloneNode(true);
  7469. // Nodes needs to be attached to something in WebKit/Opera
  7470. // Older builds of Opera crashes if you attach the node to an document created dynamically
  7471. // and since we can't feature detect a crash we need to sniff the acutal build number
  7472. // This fix will make DOM ranges and make Sizzle happy!
  7473. impl = node.ownerDocument.implementation;
  7474. if (impl.createHTMLDocument) {
  7475. // Create an empty HTML document
  7476. doc = impl.createHTMLDocument("");
  7477. // Add the element or it's children if it's a body element to the new document
  7478. each(node.nodeName == 'BODY' ? node.childNodes : [node], function(node) {
  7479. doc.body.appendChild(doc.importNode(node, true));
  7480. });
  7481. // Grab first child or body element for serialization
  7482. if (node.nodeName != 'BODY')
  7483. node = doc.body.firstChild;
  7484. else
  7485. node = doc.body;
  7486. // set the new document in DOMUtils so createElement etc works
  7487. oldDoc = dom.doc;
  7488. dom.doc = doc;
  7489. }
  7490. args = args || {};
  7491. args.format = args.format || 'html';
  7492. // Pre process
  7493. if (!args.no_events) {
  7494. args.node = node;
  7495. onPreProcess.dispatch(self, args);
  7496. }
  7497. // Setup serializer
  7498. htmlSerializer = new tinymce.html.Serializer(settings, schema);
  7499. // Parse and serialize HTML
  7500. args.content = htmlSerializer.serialize(
  7501. htmlParser.parse(tinymce.trim(args.getInner ? node.innerHTML : dom.getOuterHTML(node)), args)
  7502. );
  7503. // Replace all BOM characters for now until we can find a better solution
  7504. if (!args.cleanup)
  7505. args.content = args.content.replace(/\uFEFF/g, '');
  7506. // Post process
  7507. if (!args.no_events)
  7508. onPostProcess.dispatch(self, args);
  7509. // Restore the old document if it was changed
  7510. if (oldDoc)
  7511. dom.doc = oldDoc;
  7512. args.node = null;
  7513. return args.content;
  7514. },
  7515. addRules : function(rules) {
  7516. schema.addValidElements(rules);
  7517. },
  7518. setRules : function(rules) {
  7519. schema.setValidElements(rules);
  7520. }
  7521. };
  7522. };
  7523. })(tinymce);
  7524. (function(tinymce) {
  7525. tinymce.dom.ScriptLoader = function(settings) {
  7526. var QUEUED = 0,
  7527. LOADING = 1,
  7528. LOADED = 2,
  7529. states = {},
  7530. queue = [],
  7531. scriptLoadedCallbacks = {},
  7532. queueLoadedCallbacks = [],
  7533. loading = 0,
  7534. undef;
  7535. function loadScript(url, callback) {
  7536. var t = this, dom = tinymce.DOM, elm, uri, loc, id;
  7537. // Execute callback when script is loaded
  7538. function done() {
  7539. dom.remove(id);
  7540. if (elm)
  7541. elm.onreadystatechange = elm.onload = elm = null;
  7542. callback();
  7543. };
  7544. function error() {
  7545. // Report the error so it's easier for people to spot loading errors
  7546. if (typeof(console) !== "undefined" && console.log)
  7547. console.log("Failed to load: " + url);
  7548. // We can't mark it as done if there is a load error since
  7549. // A) We don't want to produce 404 errors on the server and
  7550. // B) the onerror event won't fire on all browsers.
  7551. // done();
  7552. };
  7553. id = dom.uniqueId();
  7554. if (tinymce.isIE6) {
  7555. uri = new tinymce.util.URI(url);
  7556. loc = location;
  7557. // If script is from same domain and we
  7558. // use IE 6 then use XHR since it's more reliable
  7559. if (uri.host == loc.hostname && uri.port == loc.port && (uri.protocol + ':') == loc.protocol && uri.protocol.toLowerCase() != 'file') {
  7560. tinymce.util.XHR.send({
  7561. url : tinymce._addVer(uri.getURI()),
  7562. success : function(content) {
  7563. // Create new temp script element
  7564. var script = dom.create('script', {
  7565. type : 'text/javascript'
  7566. });
  7567. // Evaluate script in global scope
  7568. script.text = content;
  7569. document.getElementsByTagName('head')[0].appendChild(script);
  7570. dom.remove(script);
  7571. done();
  7572. },
  7573. error : error
  7574. });
  7575. return;
  7576. }
  7577. }
  7578. // Create new script element
  7579. elm = document.createElement('script');
  7580. elm.id = id;
  7581. elm.type = 'text/javascript';
  7582. elm.src = tinymce._addVer(url);
  7583. // Add onload listener for non IE browsers since IE9
  7584. // fires onload event before the script is parsed and executed
  7585. if (!tinymce.isIE)
  7586. elm.onload = done;
  7587. // Add onerror event will get fired on some browsers but not all of them
  7588. elm.onerror = error;
  7589. // Opera 9.60 doesn't seem to fire the onreadystate event at correctly
  7590. if (!tinymce.isOpera) {
  7591. elm.onreadystatechange = function() {
  7592. var state = elm.readyState;
  7593. // Loaded state is passed on IE 6 however there
  7594. // are known issues with this method but we can't use
  7595. // XHR in a cross domain loading
  7596. if (state == 'complete' || state == 'loaded')
  7597. done();
  7598. };
  7599. }
  7600. // Most browsers support this feature so we report errors
  7601. // for those at least to help users track their missing plugins etc
  7602. // todo: Removed since it produced error if the document is unloaded by navigating away, re-add it as an option
  7603. /*elm.onerror = function() {
  7604. alert('Failed to load: ' + url);
  7605. };*/
  7606. // Add script to document
  7607. (document.getElementsByTagName('head')[0] || document.body).appendChild(elm);
  7608. };
  7609. this.isDone = function(url) {
  7610. return states[url] == LOADED;
  7611. };
  7612. this.markDone = function(url) {
  7613. states[url] = LOADED;
  7614. };
  7615. this.add = this.load = function(url, callback, scope) {
  7616. var item, state = states[url];
  7617. // Add url to load queue
  7618. if (state == undef) {
  7619. queue.push(url);
  7620. states[url] = QUEUED;
  7621. }
  7622. if (callback) {
  7623. // Store away callback for later execution
  7624. if (!scriptLoadedCallbacks[url])
  7625. scriptLoadedCallbacks[url] = [];
  7626. scriptLoadedCallbacks[url].push({
  7627. func : callback,
  7628. scope : scope || this
  7629. });
  7630. }
  7631. };
  7632. this.loadQueue = function(callback, scope) {
  7633. this.loadScripts(queue, callback, scope);
  7634. };
  7635. this.loadScripts = function(scripts, callback, scope) {
  7636. var loadScripts;
  7637. function execScriptLoadedCallbacks(url) {
  7638. // Execute URL callback functions
  7639. tinymce.each(scriptLoadedCallbacks[url], function(callback) {
  7640. callback.func.call(callback.scope);
  7641. });
  7642. scriptLoadedCallbacks[url] = undef;
  7643. };
  7644. queueLoadedCallbacks.push({
  7645. func : callback,
  7646. scope : scope || this
  7647. });
  7648. loadScripts = function() {
  7649. var loadingScripts = tinymce.grep(scripts);
  7650. // Current scripts has been handled
  7651. scripts.length = 0;
  7652. // Load scripts that needs to be loaded
  7653. tinymce.each(loadingScripts, function(url) {
  7654. // Script is already loaded then execute script callbacks directly
  7655. if (states[url] == LOADED) {
  7656. execScriptLoadedCallbacks(url);
  7657. return;
  7658. }
  7659. // Is script not loading then start loading it
  7660. if (states[url] != LOADING) {
  7661. states[url] = LOADING;
  7662. loading++;
  7663. loadScript(url, function() {
  7664. states[url] = LOADED;
  7665. loading--;
  7666. execScriptLoadedCallbacks(url);
  7667. // Load more scripts if they where added by the recently loaded script
  7668. loadScripts();
  7669. });
  7670. }
  7671. });
  7672. // No scripts are currently loading then execute all pending queue loaded callbacks
  7673. if (!loading) {
  7674. tinymce.each(queueLoadedCallbacks, function(callback) {
  7675. callback.func.call(callback.scope);
  7676. });
  7677. queueLoadedCallbacks.length = 0;
  7678. }
  7679. };
  7680. loadScripts();
  7681. };
  7682. };
  7683. // Global script loader
  7684. tinymce.ScriptLoader = new tinymce.dom.ScriptLoader();
  7685. })(tinymce);
  7686. (function(tinymce) {
  7687. tinymce.dom.RangeUtils = function(dom) {
  7688. var INVISIBLE_CHAR = '\uFEFF';
  7689. this.walk = function(rng, callback) {
  7690. var startContainer = rng.startContainer,
  7691. startOffset = rng.startOffset,
  7692. endContainer = rng.endContainer,
  7693. endOffset = rng.endOffset,
  7694. ancestor, startPoint,
  7695. endPoint, node, parent, siblings, nodes;
  7696. // Handle table cell selection the table plugin enables
  7697. // you to fake select table cells and perform formatting actions on them
  7698. nodes = dom.select('td.mceSelected,th.mceSelected');
  7699. if (nodes.length > 0) {
  7700. tinymce.each(nodes, function(node) {
  7701. callback([node]);
  7702. });
  7703. return;
  7704. }
  7705. function exclude(nodes) {
  7706. var node;
  7707. // First node is excluded
  7708. node = nodes[0];
  7709. if (node.nodeType === 3 && node === startContainer && startOffset >= node.nodeValue.length) {
  7710. nodes.splice(0, 1);
  7711. }
  7712. // Last node is excluded
  7713. node = nodes[nodes.length - 1];
  7714. if (endOffset === 0 && nodes.length > 0 && node === endContainer && node.nodeType === 3) {
  7715. nodes.splice(nodes.length - 1, 1);
  7716. }
  7717. return nodes;
  7718. };
  7719. function collectSiblings(node, name, end_node) {
  7720. var siblings = [];
  7721. for (; node && node != end_node; node = node[name])
  7722. siblings.push(node);
  7723. return siblings;
  7724. };
  7725. function findEndPoint(node, root) {
  7726. do {
  7727. if (node.parentNode == root)
  7728. return node;
  7729. node = node.parentNode;
  7730. } while(node);
  7731. };
  7732. function walkBoundary(start_node, end_node, next) {
  7733. var siblingName = next ? 'nextSibling' : 'previousSibling';
  7734. for (node = start_node, parent = node.parentNode; node && node != end_node; node = parent) {
  7735. parent = node.parentNode;
  7736. siblings = collectSiblings(node == start_node ? node : node[siblingName], siblingName);
  7737. if (siblings.length) {
  7738. if (!next)
  7739. siblings.reverse();
  7740. callback(exclude(siblings));
  7741. }
  7742. }
  7743. };
  7744. // If index based start position then resolve it
  7745. if (startContainer.nodeType == 1 && startContainer.hasChildNodes())
  7746. startContainer = startContainer.childNodes[startOffset];
  7747. // If index based end position then resolve it
  7748. if (endContainer.nodeType == 1 && endContainer.hasChildNodes())
  7749. endContainer = endContainer.childNodes[Math.min(endOffset - 1, endContainer.childNodes.length - 1)];
  7750. // Same container
  7751. if (startContainer == endContainer)
  7752. return callback(exclude([startContainer]));
  7753. // Find common ancestor and end points
  7754. ancestor = dom.findCommonAncestor(startContainer, endContainer);
  7755. // Process left side
  7756. for (node = startContainer; node; node = node.parentNode) {
  7757. if (node === endContainer)
  7758. return walkBoundary(startContainer, ancestor, true);
  7759. if (node === ancestor)
  7760. break;
  7761. }
  7762. // Process right side
  7763. for (node = endContainer; node; node = node.parentNode) {
  7764. if (node === startContainer)
  7765. return walkBoundary(endContainer, ancestor);
  7766. if (node === ancestor)
  7767. break;
  7768. }
  7769. // Find start/end point
  7770. startPoint = findEndPoint(startContainer, ancestor) || startContainer;
  7771. endPoint = findEndPoint(endContainer, ancestor) || endContainer;
  7772. // Walk left leaf
  7773. walkBoundary(startContainer, startPoint, true);
  7774. // Walk the middle from start to end point
  7775. siblings = collectSiblings(
  7776. startPoint == startContainer ? startPoint : startPoint.nextSibling,
  7777. 'nextSibling',
  7778. endPoint == endContainer ? endPoint.nextSibling : endPoint
  7779. );
  7780. if (siblings.length)
  7781. callback(exclude(siblings));
  7782. // Walk right leaf
  7783. walkBoundary(endContainer, endPoint);
  7784. };
  7785. this.split = function(rng) {
  7786. var startContainer = rng.startContainer,
  7787. startOffset = rng.startOffset,
  7788. endContainer = rng.endContainer,
  7789. endOffset = rng.endOffset;
  7790. function splitText(node, offset) {
  7791. return node.splitText(offset);
  7792. };
  7793. // Handle single text node
  7794. if (startContainer == endContainer && startContainer.nodeType == 3) {
  7795. if (startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  7796. endContainer = splitText(startContainer, startOffset);
  7797. startContainer = endContainer.previousSibling;
  7798. if (endOffset > startOffset) {
  7799. endOffset = endOffset - startOffset;
  7800. startContainer = endContainer = splitText(endContainer, endOffset).previousSibling;
  7801. endOffset = endContainer.nodeValue.length;
  7802. startOffset = 0;
  7803. } else {
  7804. endOffset = 0;
  7805. }
  7806. }
  7807. } else {
  7808. // Split startContainer text node if needed
  7809. if (startContainer.nodeType == 3 && startOffset > 0 && startOffset < startContainer.nodeValue.length) {
  7810. startContainer = splitText(startContainer, startOffset);
  7811. startOffset = 0;
  7812. }
  7813. // Split endContainer text node if needed
  7814. if (endContainer.nodeType == 3 && endOffset > 0 && endOffset < endContainer.nodeValue.length) {
  7815. endContainer = splitText(endContainer, endOffset).previousSibling;
  7816. endOffset = endContainer.nodeValue.length;
  7817. }
  7818. }
  7819. return {
  7820. startContainer : startContainer,
  7821. startOffset : startOffset,
  7822. endContainer : endContainer,
  7823. endOffset : endOffset
  7824. };
  7825. };
  7826. };
  7827. tinymce.dom.RangeUtils.compareRanges = function(rng1, rng2) {
  7828. if (rng1 && rng2) {
  7829. // Compare native IE ranges
  7830. if (rng1.item || rng1.duplicate) {
  7831. // Both are control ranges and the selected element matches
  7832. if (rng1.item && rng2.item && rng1.item(0) === rng2.item(0))
  7833. return true;
  7834. // Both are text ranges and the range matches
  7835. if (rng1.isEqual && rng2.isEqual && rng2.isEqual(rng1))
  7836. return true;
  7837. } else {
  7838. // Compare w3c ranges
  7839. return rng1.startContainer == rng2.startContainer && rng1.startOffset == rng2.startOffset;
  7840. }
  7841. }
  7842. return false;
  7843. };
  7844. })(tinymce);
  7845. (function(tinymce) {
  7846. var Event = tinymce.dom.Event, each = tinymce.each;
  7847. tinymce.create('tinymce.ui.KeyboardNavigation', {
  7848. KeyboardNavigation: function(settings, dom) {
  7849. var t = this, root = settings.root, items = settings.items,
  7850. enableUpDown = settings.enableUpDown, enableLeftRight = settings.enableLeftRight || !settings.enableUpDown,
  7851. excludeFromTabOrder = settings.excludeFromTabOrder,
  7852. itemFocussed, itemBlurred, rootKeydown, rootFocussed, focussedId;
  7853. dom = dom || tinymce.DOM;
  7854. itemFocussed = function(evt) {
  7855. focussedId = evt.target.id;
  7856. };
  7857. itemBlurred = function(evt) {
  7858. dom.setAttrib(evt.target.id, 'tabindex', '-1');
  7859. };
  7860. rootFocussed = function(evt) {
  7861. var item = dom.get(focussedId);
  7862. dom.setAttrib(item, 'tabindex', '0');
  7863. item.focus();
  7864. };
  7865. t.focus = function() {
  7866. dom.get(focussedId).focus();
  7867. };
  7868. t.destroy = function() {
  7869. each(items, function(item) {
  7870. var elm = dom.get(item.id);
  7871. dom.unbind(elm, 'focus', itemFocussed);
  7872. dom.unbind(elm, 'blur', itemBlurred);
  7873. });
  7874. var rootElm = dom.get(root);
  7875. dom.unbind(rootElm, 'focus', rootFocussed);
  7876. dom.unbind(rootElm, 'keydown', rootKeydown);
  7877. items = dom = root = t.focus = itemFocussed = itemBlurred = rootKeydown = rootFocussed = null;
  7878. t.destroy = function() {};
  7879. };
  7880. t.moveFocus = function(dir, evt) {
  7881. var idx = -1, controls = t.controls, newFocus;
  7882. if (!focussedId)
  7883. return;
  7884. each(items, function(item, index) {
  7885. if (item.id === focussedId) {
  7886. idx = index;
  7887. return false;
  7888. }
  7889. });
  7890. idx += dir;
  7891. if (idx < 0) {
  7892. idx = items.length - 1;
  7893. } else if (idx >= items.length) {
  7894. idx = 0;
  7895. }
  7896. newFocus = items[idx];
  7897. dom.setAttrib(focussedId, 'tabindex', '-1');
  7898. dom.setAttrib(newFocus.id, 'tabindex', '0');
  7899. dom.get(newFocus.id).focus();
  7900. if (settings.actOnFocus) {
  7901. settings.onAction(newFocus.id);
  7902. }
  7903. if (evt)
  7904. Event.cancel(evt);
  7905. };
  7906. rootKeydown = function(evt) {
  7907. 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;
  7908. switch (evt.keyCode) {
  7909. case DOM_VK_LEFT:
  7910. if (enableLeftRight) t.moveFocus(-1);
  7911. break;
  7912. case DOM_VK_RIGHT:
  7913. if (enableLeftRight) t.moveFocus(1);
  7914. break;
  7915. case DOM_VK_UP:
  7916. if (enableUpDown) t.moveFocus(-1);
  7917. break;
  7918. case DOM_VK_DOWN:
  7919. if (enableUpDown) t.moveFocus(1);
  7920. break;
  7921. case DOM_VK_ESCAPE:
  7922. if (settings.onCancel) {
  7923. settings.onCancel();
  7924. Event.cancel(evt);
  7925. }
  7926. break;
  7927. case DOM_VK_ENTER:
  7928. case DOM_VK_RETURN:
  7929. case DOM_VK_SPACE:
  7930. if (settings.onAction) {
  7931. settings.onAction(focussedId);
  7932. Event.cancel(evt);
  7933. }
  7934. break;
  7935. }
  7936. };
  7937. // Set up state and listeners for each item.
  7938. each(items, function(item, idx) {
  7939. var tabindex, elm;
  7940. if (!item.id) {
  7941. item.id = dom.uniqueId('_mce_item_');
  7942. }
  7943. elm = dom.get(item.id);
  7944. if (excludeFromTabOrder) {
  7945. dom.bind(elm, 'blur', itemBlurred);
  7946. tabindex = '-1';
  7947. } else {
  7948. tabindex = (idx === 0 ? '0' : '-1');
  7949. }
  7950. elm.setAttribute('tabindex', tabindex);
  7951. dom.bind(elm, 'focus', itemFocussed);
  7952. });
  7953. // Setup initial state for root element.
  7954. if (items[0]){
  7955. focussedId = items[0].id;
  7956. }
  7957. dom.setAttrib(root, 'tabindex', '-1');
  7958. // Setup listeners for root element.
  7959. var rootElm = dom.get(root);
  7960. dom.bind(rootElm, 'focus', rootFocussed);
  7961. dom.bind(rootElm, 'keydown', rootKeydown);
  7962. }
  7963. });
  7964. })(tinymce);
  7965. (function(tinymce) {
  7966. // Shorten class names
  7967. var DOM = tinymce.DOM, is = tinymce.is;
  7968. tinymce.create('tinymce.ui.Control', {
  7969. Control : function(id, s, editor) {
  7970. this.id = id;
  7971. this.settings = s = s || {};
  7972. this.rendered = false;
  7973. this.onRender = new tinymce.util.Dispatcher(this);
  7974. this.classPrefix = '';
  7975. this.scope = s.scope || this;
  7976. this.disabled = 0;
  7977. this.active = 0;
  7978. this.editor = editor;
  7979. },
  7980. setAriaProperty : function(property, value) {
  7981. var element = DOM.get(this.id + '_aria') || DOM.get(this.id);
  7982. if (element) {
  7983. DOM.setAttrib(element, 'aria-' + property, !!value);
  7984. }
  7985. },
  7986. focus : function() {
  7987. DOM.get(this.id).focus();
  7988. },
  7989. setDisabled : function(s) {
  7990. if (s != this.disabled) {
  7991. this.setAriaProperty('disabled', s);
  7992. this.setState('Disabled', s);
  7993. this.setState('Enabled', !s);
  7994. this.disabled = s;
  7995. }
  7996. },
  7997. isDisabled : function() {
  7998. return this.disabled;
  7999. },
  8000. setActive : function(s) {
  8001. if (s != this.active) {
  8002. this.setState('Active', s);
  8003. this.active = s;
  8004. this.setAriaProperty('pressed', s);
  8005. }
  8006. },
  8007. isActive : function() {
  8008. return this.active;
  8009. },
  8010. setState : function(c, s) {
  8011. var n = DOM.get(this.id);
  8012. c = this.classPrefix + c;
  8013. if (s)
  8014. DOM.addClass(n, c);
  8015. else
  8016. DOM.removeClass(n, c);
  8017. },
  8018. isRendered : function() {
  8019. return this.rendered;
  8020. },
  8021. renderHTML : function() {
  8022. },
  8023. renderTo : function(n) {
  8024. DOM.setHTML(n, this.renderHTML());
  8025. },
  8026. postRender : function() {
  8027. var t = this, b;
  8028. // Set pending states
  8029. if (is(t.disabled)) {
  8030. b = t.disabled;
  8031. t.disabled = -1;
  8032. t.setDisabled(b);
  8033. }
  8034. if (is(t.active)) {
  8035. b = t.active;
  8036. t.active = -1;
  8037. t.setActive(b);
  8038. }
  8039. },
  8040. remove : function() {
  8041. DOM.remove(this.id);
  8042. this.destroy();
  8043. },
  8044. destroy : function() {
  8045. tinymce.dom.Event.clear(this.id);
  8046. }
  8047. });
  8048. })(tinymce);
  8049. tinymce.create('tinymce.ui.Container:tinymce.ui.Control', {
  8050. Container : function(id, s, editor) {
  8051. this.parent(id, s, editor);
  8052. this.controls = [];
  8053. this.lookup = {};
  8054. },
  8055. add : function(c) {
  8056. this.lookup[c.id] = c;
  8057. this.controls.push(c);
  8058. return c;
  8059. },
  8060. get : function(n) {
  8061. return this.lookup[n];
  8062. }
  8063. });
  8064. tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', {
  8065. Separator : function(id, s) {
  8066. this.parent(id, s);
  8067. this.classPrefix = 'mceSeparator';
  8068. this.setDisabled(true);
  8069. },
  8070. renderHTML : function() {
  8071. return tinymce.DOM.createHTML('span', {'class' : this.classPrefix, role : 'separator', 'aria-orientation' : 'vertical', tabindex : '-1'});
  8072. }
  8073. });
  8074. (function(tinymce) {
  8075. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  8076. tinymce.create('tinymce.ui.MenuItem:tinymce.ui.Control', {
  8077. MenuItem : function(id, s) {
  8078. this.parent(id, s);
  8079. this.classPrefix = 'mceMenuItem';
  8080. },
  8081. setSelected : function(s) {
  8082. this.setState('Selected', s);
  8083. this.setAriaProperty('checked', !!s);
  8084. this.selected = s;
  8085. },
  8086. isSelected : function() {
  8087. return this.selected;
  8088. },
  8089. postRender : function() {
  8090. var t = this;
  8091. t.parent();
  8092. // Set pending state
  8093. if (is(t.selected))
  8094. t.setSelected(t.selected);
  8095. }
  8096. });
  8097. })(tinymce);
  8098. (function(tinymce) {
  8099. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
  8100. tinymce.create('tinymce.ui.Menu:tinymce.ui.MenuItem', {
  8101. Menu : function(id, s) {
  8102. var t = this;
  8103. t.parent(id, s);
  8104. t.items = {};
  8105. t.collapsed = false;
  8106. t.menuCount = 0;
  8107. t.onAddItem = new tinymce.util.Dispatcher(this);
  8108. },
  8109. expand : function(d) {
  8110. var t = this;
  8111. if (d) {
  8112. walk(t, function(o) {
  8113. if (o.expand)
  8114. o.expand();
  8115. }, 'items', t);
  8116. }
  8117. t.collapsed = false;
  8118. },
  8119. collapse : function(d) {
  8120. var t = this;
  8121. if (d) {
  8122. walk(t, function(o) {
  8123. if (o.collapse)
  8124. o.collapse();
  8125. }, 'items', t);
  8126. }
  8127. t.collapsed = true;
  8128. },
  8129. isCollapsed : function() {
  8130. return this.collapsed;
  8131. },
  8132. add : function(o) {
  8133. if (!o.settings)
  8134. o = new tinymce.ui.MenuItem(o.id || DOM.uniqueId(), o);
  8135. this.onAddItem.dispatch(this, o);
  8136. return this.items[o.id] = o;
  8137. },
  8138. addSeparator : function() {
  8139. return this.add({separator : true});
  8140. },
  8141. addMenu : function(o) {
  8142. if (!o.collapse)
  8143. o = this.createMenu(o);
  8144. this.menuCount++;
  8145. return this.add(o);
  8146. },
  8147. hasMenus : function() {
  8148. return this.menuCount !== 0;
  8149. },
  8150. remove : function(o) {
  8151. delete this.items[o.id];
  8152. },
  8153. removeAll : function() {
  8154. var t = this;
  8155. walk(t, function(o) {
  8156. if (o.removeAll)
  8157. o.removeAll();
  8158. else
  8159. o.remove();
  8160. o.destroy();
  8161. }, 'items', t);
  8162. t.items = {};
  8163. },
  8164. createMenu : function(o) {
  8165. var m = new tinymce.ui.Menu(o.id || DOM.uniqueId(), o);
  8166. m.onAddItem.add(this.onAddItem.dispatch, this.onAddItem);
  8167. return m;
  8168. }
  8169. });
  8170. })(tinymce);
  8171. (function(tinymce) {
  8172. var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event, Element = tinymce.dom.Element;
  8173. tinymce.create('tinymce.ui.DropMenu:tinymce.ui.Menu', {
  8174. DropMenu : function(id, s) {
  8175. s = s || {};
  8176. s.container = s.container || DOM.doc.body;
  8177. s.offset_x = s.offset_x || 0;
  8178. s.offset_y = s.offset_y || 0;
  8179. s.vp_offset_x = s.vp_offset_x || 0;
  8180. s.vp_offset_y = s.vp_offset_y || 0;
  8181. if (is(s.icons) && !s.icons)
  8182. s['class'] += ' mceNoIcons';
  8183. this.parent(id, s);
  8184. this.onShowMenu = new tinymce.util.Dispatcher(this);
  8185. this.onHideMenu = new tinymce.util.Dispatcher(this);
  8186. this.classPrefix = 'mceMenu';
  8187. },
  8188. createMenu : function(s) {
  8189. var t = this, cs = t.settings, m;
  8190. s.container = s.container || cs.container;
  8191. s.parent = t;
  8192. s.constrain = s.constrain || cs.constrain;
  8193. s['class'] = s['class'] || cs['class'];
  8194. s.vp_offset_x = s.vp_offset_x || cs.vp_offset_x;
  8195. s.vp_offset_y = s.vp_offset_y || cs.vp_offset_y;
  8196. s.keyboard_focus = cs.keyboard_focus;
  8197. m = new tinymce.ui.DropMenu(s.id || DOM.uniqueId(), s);
  8198. m.onAddItem.add(t.onAddItem.dispatch, t.onAddItem);
  8199. return m;
  8200. },
  8201. focus : function() {
  8202. var t = this;
  8203. if (t.keyboardNav) {
  8204. t.keyboardNav.focus();
  8205. }
  8206. },
  8207. update : function() {
  8208. var t = this, s = t.settings, tb = DOM.get('menu_' + t.id + '_tbl'), co = DOM.get('menu_' + t.id + '_co'), tw, th;
  8209. tw = s.max_width ? Math.min(tb.offsetWidth, s.max_width) : tb.offsetWidth;
  8210. th = s.max_height ? Math.min(tb.offsetHeight, s.max_height) : tb.offsetHeight;
  8211. if (!DOM.boxModel)
  8212. t.element.setStyles({width : tw + 2, height : th + 2});
  8213. else
  8214. t.element.setStyles({width : tw, height : th});
  8215. if (s.max_width)
  8216. DOM.setStyle(co, 'width', tw);
  8217. if (s.max_height) {
  8218. DOM.setStyle(co, 'height', th);
  8219. if (tb.clientHeight < s.max_height)
  8220. DOM.setStyle(co, 'overflow', 'hidden');
  8221. }
  8222. },
  8223. showMenu : function(x, y, px) {
  8224. var t = this, s = t.settings, co, vp = DOM.getViewPort(), w, h, mx, my, ot = 2, dm, tb, cp = t.classPrefix;
  8225. t.collapse(1);
  8226. if (t.isMenuVisible)
  8227. return;
  8228. if (!t.rendered) {
  8229. co = DOM.add(t.settings.container, t.renderNode());
  8230. each(t.items, function(o) {
  8231. o.postRender();
  8232. });
  8233. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  8234. } else
  8235. co = DOM.get('menu_' + t.id);
  8236. // Move layer out of sight unless it's Opera since it scrolls to top of page due to an bug
  8237. if (!tinymce.isOpera)
  8238. DOM.setStyles(co, {left : -0xFFFF , top : -0xFFFF});
  8239. DOM.show(co);
  8240. t.update();
  8241. x += s.offset_x || 0;
  8242. y += s.offset_y || 0;
  8243. vp.w -= 4;
  8244. vp.h -= 4;
  8245. // Move inside viewport if not submenu
  8246. if (s.constrain) {
  8247. w = co.clientWidth - ot;
  8248. h = co.clientHeight - ot;
  8249. mx = vp.x + vp.w;
  8250. my = vp.y + vp.h;
  8251. if ((x + s.vp_offset_x + w) > mx)
  8252. x = px ? px - w : Math.max(0, (mx - s.vp_offset_x) - w);
  8253. if ((y + s.vp_offset_y + h) > my)
  8254. y = Math.max(0, (my - s.vp_offset_y) - h);
  8255. }
  8256. DOM.setStyles(co, {left : x , top : y});
  8257. t.element.update();
  8258. t.isMenuVisible = 1;
  8259. t.mouseClickFunc = Event.add(co, 'click', function(e) {
  8260. var m;
  8261. e = e.target;
  8262. if (e && (e = DOM.getParent(e, 'tr')) && !DOM.hasClass(e, cp + 'ItemSub')) {
  8263. m = t.items[e.id];
  8264. if (m.isDisabled())
  8265. return;
  8266. dm = t;
  8267. while (dm) {
  8268. if (dm.hideMenu)
  8269. dm.hideMenu();
  8270. dm = dm.settings.parent;
  8271. }
  8272. if (m.settings.onclick)
  8273. m.settings.onclick(e);
  8274. return false; // Cancel to fix onbeforeunload problem
  8275. }
  8276. });
  8277. if (t.hasMenus()) {
  8278. t.mouseOverFunc = Event.add(co, 'mouseover', function(e) {
  8279. var m, r, mi;
  8280. e = e.target;
  8281. if (e && (e = DOM.getParent(e, 'tr'))) {
  8282. m = t.items[e.id];
  8283. if (t.lastMenu)
  8284. t.lastMenu.collapse(1);
  8285. if (m.isDisabled())
  8286. return;
  8287. if (e && DOM.hasClass(e, cp + 'ItemSub')) {
  8288. //p = DOM.getPos(s.container);
  8289. r = DOM.getRect(e);
  8290. m.showMenu((r.x + r.w - ot), r.y - ot, r.x);
  8291. t.lastMenu = m;
  8292. DOM.addClass(DOM.get(m.id).firstChild, cp + 'ItemActive');
  8293. }
  8294. }
  8295. });
  8296. }
  8297. Event.add(co, 'keydown', t._keyHandler, t);
  8298. t.onShowMenu.dispatch(t);
  8299. if (s.keyboard_focus) {
  8300. t._setupKeyboardNav();
  8301. }
  8302. },
  8303. hideMenu : function(c) {
  8304. var t = this, co = DOM.get('menu_' + t.id), e;
  8305. if (!t.isMenuVisible)
  8306. return;
  8307. if (t.keyboardNav) t.keyboardNav.destroy();
  8308. Event.remove(co, 'mouseover', t.mouseOverFunc);
  8309. Event.remove(co, 'click', t.mouseClickFunc);
  8310. Event.remove(co, 'keydown', t._keyHandler);
  8311. DOM.hide(co);
  8312. t.isMenuVisible = 0;
  8313. if (!c)
  8314. t.collapse(1);
  8315. if (t.element)
  8316. t.element.hide();
  8317. if (e = DOM.get(t.id))
  8318. DOM.removeClass(e.firstChild, t.classPrefix + 'ItemActive');
  8319. t.onHideMenu.dispatch(t);
  8320. },
  8321. add : function(o) {
  8322. var t = this, co;
  8323. o = t.parent(o);
  8324. if (t.isRendered && (co = DOM.get('menu_' + t.id)))
  8325. t._add(DOM.select('tbody', co)[0], o);
  8326. return o;
  8327. },
  8328. collapse : function(d) {
  8329. this.parent(d);
  8330. this.hideMenu(1);
  8331. },
  8332. remove : function(o) {
  8333. DOM.remove(o.id);
  8334. this.destroy();
  8335. return this.parent(o);
  8336. },
  8337. destroy : function() {
  8338. var t = this, co = DOM.get('menu_' + t.id);
  8339. if (t.keyboardNav) t.keyboardNav.destroy();
  8340. Event.remove(co, 'mouseover', t.mouseOverFunc);
  8341. Event.remove(DOM.select('a', co), 'focus', t.mouseOverFunc);
  8342. Event.remove(co, 'click', t.mouseClickFunc);
  8343. Event.remove(co, 'keydown', t._keyHandler);
  8344. if (t.element)
  8345. t.element.remove();
  8346. DOM.remove(co);
  8347. },
  8348. renderNode : function() {
  8349. var t = this, s = t.settings, n, tb, co, w;
  8350. 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'});
  8351. if (t.settings.parent) {
  8352. DOM.setAttrib(w, 'aria-parent', 'menu_' + t.settings.parent.id);
  8353. }
  8354. co = DOM.add(w, 'div', {role: 'presentation', id : 'menu_' + t.id + '_co', 'class' : t.classPrefix + (s['class'] ? ' ' + s['class'] : '')});
  8355. t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
  8356. if (s.menu_line)
  8357. DOM.add(co, 'span', {'class' : t.classPrefix + 'Line'});
  8358. // n = DOM.add(co, 'div', {id : 'menu_' + t.id + '_co', 'class' : 'mceMenuContainer'});
  8359. n = DOM.add(co, 'table', {role: 'presentation', id : 'menu_' + t.id + '_tbl', border : 0, cellPadding : 0, cellSpacing : 0});
  8360. tb = DOM.add(n, 'tbody');
  8361. each(t.items, function(o) {
  8362. t._add(tb, o);
  8363. });
  8364. t.rendered = true;
  8365. return w;
  8366. },
  8367. // Internal functions
  8368. _setupKeyboardNav : function(){
  8369. var contextMenu, menuItems, t=this;
  8370. contextMenu = DOM.get('menu_' + t.id);
  8371. menuItems = DOM.select('a[role=option]', 'menu_' + t.id);
  8372. menuItems.splice(0,0,contextMenu);
  8373. t.keyboardNav = new tinymce.ui.KeyboardNavigation({
  8374. root: 'menu_' + t.id,
  8375. items: menuItems,
  8376. onCancel: function() {
  8377. t.hideMenu();
  8378. },
  8379. enableUpDown: true
  8380. });
  8381. contextMenu.focus();
  8382. },
  8383. _keyHandler : function(evt) {
  8384. var t = this, e;
  8385. switch (evt.keyCode) {
  8386. case 37: // Left
  8387. if (t.settings.parent) {
  8388. t.hideMenu();
  8389. t.settings.parent.focus();
  8390. Event.cancel(evt);
  8391. }
  8392. break;
  8393. case 39: // Right
  8394. if (t.mouseOverFunc)
  8395. t.mouseOverFunc(evt);
  8396. break;
  8397. }
  8398. },
  8399. _add : function(tb, o) {
  8400. var n, s = o.settings, a, ro, it, cp = this.classPrefix, ic;
  8401. if (s.separator) {
  8402. ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'ItemSeparator'});
  8403. DOM.add(ro, 'td', {'class' : cp + 'ItemSeparator'});
  8404. if (n = ro.previousSibling)
  8405. DOM.addClass(n, 'mceLast');
  8406. return;
  8407. }
  8408. n = ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'Item ' + cp + 'ItemEnabled'});
  8409. n = it = DOM.add(n, s.titleItem ? 'th' : 'td');
  8410. n = a = DOM.add(n, 'a', {id: o.id + '_aria', role: s.titleItem ? 'presentation' : 'option', href : 'javascript:;', onclick : "return false;", onmousedown : 'return false;'});
  8411. if (s.parent) {
  8412. DOM.setAttrib(a, 'aria-haspopup', 'true');
  8413. DOM.setAttrib(a, 'aria-owns', 'menu_' + o.id);
  8414. }
  8415. DOM.addClass(it, s['class']);
  8416. // n = DOM.add(n, 'span', {'class' : 'item'});
  8417. ic = DOM.add(n, 'span', {'class' : 'mceIcon' + (s.icon ? ' mce_' + s.icon : '')});
  8418. if (s.icon_src)
  8419. DOM.add(ic, 'img', {src : s.icon_src});
  8420. n = DOM.add(n, s.element || 'span', {'class' : 'mceText', title : o.settings.title}, o.settings.title);
  8421. if (o.settings.style) {
  8422. if (typeof o.settings.style == "function")
  8423. o.settings.style = o.settings.style();
  8424. DOM.setAttrib(n, 'style', o.settings.style);
  8425. }
  8426. if (tb.childNodes.length == 1)
  8427. DOM.addClass(ro, 'mceFirst');
  8428. if ((n = ro.previousSibling) && DOM.hasClass(n, cp + 'ItemSeparator'))
  8429. DOM.addClass(ro, 'mceFirst');
  8430. if (o.collapse)
  8431. DOM.addClass(ro, cp + 'ItemSub');
  8432. if (n = ro.previousSibling)
  8433. DOM.removeClass(n, 'mceLast');
  8434. DOM.addClass(ro, 'mceLast');
  8435. }
  8436. });
  8437. })(tinymce);
  8438. (function(tinymce) {
  8439. var DOM = tinymce.DOM;
  8440. tinymce.create('tinymce.ui.Button:tinymce.ui.Control', {
  8441. Button : function(id, s, ed) {
  8442. this.parent(id, s, ed);
  8443. this.classPrefix = 'mceButton';
  8444. },
  8445. renderHTML : function() {
  8446. var cp = this.classPrefix, s = this.settings, h, l;
  8447. l = DOM.encode(s.label || '');
  8448. 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) + '">';
  8449. if (s.image && !(this.editor &&this.editor.forcedHighContrastMode) )
  8450. h += '<span class="mceIcon ' + s['class'] + '"><img class="mceIcon" src="' + s.image + '" alt="' + DOM.encode(s.title) + '" /></span>' + (l ? '<span class="' + cp + 'Label">' + l + '</span>' : '');
  8451. else
  8452. h += '<span class="mceIcon ' + s['class'] + '"></span>' + (l ? '<span class="' + cp + 'Label">' + l + '</span>' : '');
  8453. h += '<span class="mceVoiceLabel mceIconOnly" style="display: none;" id="' + this.id + '_voice">' + s.title + '</span>';
  8454. h += '</a>';
  8455. return h;
  8456. },
  8457. postRender : function() {
  8458. var t = this, s = t.settings, imgBookmark;
  8459. // In IE a large image that occupies the entire editor area will be deselected when a button is clicked, so
  8460. // need to keep the selection in case the selection is lost
  8461. if (tinymce.isIE && t.editor) {
  8462. tinymce.dom.Event.add(t.id, 'mousedown', function(e) {
  8463. var nodeName = t.editor.selection.getNode().nodeName;
  8464. imgBookmark = nodeName === 'IMG' ? t.editor.selection.getBookmark() : null;
  8465. });
  8466. }
  8467. tinymce.dom.Event.add(t.id, 'click', function(e) {
  8468. if (!t.isDisabled()) {
  8469. // restore the selection in case the selection is lost in IE
  8470. if (tinymce.isIE && t.editor && imgBookmark !== null) {
  8471. t.editor.selection.moveToBookmark(imgBookmark);
  8472. }
  8473. return s.onclick.call(s.scope, e);
  8474. }
  8475. });
  8476. tinymce.dom.Event.add(t.id, 'keyup', function(e) {
  8477. if (!t.isDisabled() && e.keyCode==tinymce.VK.SPACEBAR)
  8478. return s.onclick.call(s.scope, e);
  8479. });
  8480. }
  8481. });
  8482. })(tinymce);
  8483. (function(tinymce) {
  8484. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher, undef;
  8485. tinymce.create('tinymce.ui.ListBox:tinymce.ui.Control', {
  8486. ListBox : function(id, s, ed) {
  8487. var t = this;
  8488. t.parent(id, s, ed);
  8489. t.items = [];
  8490. t.onChange = new Dispatcher(t);
  8491. t.onPostRender = new Dispatcher(t);
  8492. t.onAdd = new Dispatcher(t);
  8493. t.onRenderMenu = new tinymce.util.Dispatcher(this);
  8494. t.classPrefix = 'mceListBox';
  8495. t.marked = {};
  8496. },
  8497. select : function(va) {
  8498. var t = this, fv, f;
  8499. t.marked = {};
  8500. if (va == undef)
  8501. return t.selectByIndex(-1);
  8502. // Is string or number make function selector
  8503. if (va && typeof(va)=="function")
  8504. f = va;
  8505. else {
  8506. f = function(v) {
  8507. return v == va;
  8508. };
  8509. }
  8510. // Do we need to do something?
  8511. if (va != t.selectedValue) {
  8512. // Find item
  8513. each(t.items, function(o, i) {
  8514. if (f(o.value)) {
  8515. fv = 1;
  8516. t.selectByIndex(i);
  8517. return false;
  8518. }
  8519. });
  8520. if (!fv)
  8521. t.selectByIndex(-1);
  8522. }
  8523. },
  8524. selectByIndex : function(idx) {
  8525. var t = this, e, o, label;
  8526. t.marked = {};
  8527. if (idx != t.selectedIndex) {
  8528. e = DOM.get(t.id + '_text');
  8529. label = DOM.get(t.id + '_voiceDesc');
  8530. o = t.items[idx];
  8531. if (o) {
  8532. t.selectedValue = o.value;
  8533. t.selectedIndex = idx;
  8534. DOM.setHTML(e, DOM.encode(o.title));
  8535. DOM.setHTML(label, t.settings.title + " - " + o.title);
  8536. DOM.removeClass(e, 'mceTitle');
  8537. DOM.setAttrib(t.id, 'aria-valuenow', o.title);
  8538. } else {
  8539. DOM.setHTML(e, DOM.encode(t.settings.title));
  8540. DOM.setHTML(label, DOM.encode(t.settings.title));
  8541. DOM.addClass(e, 'mceTitle');
  8542. t.selectedValue = t.selectedIndex = null;
  8543. DOM.setAttrib(t.id, 'aria-valuenow', t.settings.title);
  8544. }
  8545. e = 0;
  8546. }
  8547. },
  8548. mark : function(value) {
  8549. this.marked[value] = true;
  8550. },
  8551. add : function(n, v, o) {
  8552. var t = this;
  8553. o = o || {};
  8554. o = tinymce.extend(o, {
  8555. title : n,
  8556. value : v
  8557. });
  8558. t.items.push(o);
  8559. t.onAdd.dispatch(t, o);
  8560. },
  8561. getLength : function() {
  8562. return this.items.length;
  8563. },
  8564. renderHTML : function() {
  8565. var h = '', t = this, s = t.settings, cp = t.classPrefix;
  8566. 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>';
  8567. h += '<td>' + DOM.createHTML('span', {id: t.id + '_voiceDesc', 'class': 'voiceLabel', style:'display:none;'}, t.settings.title);
  8568. 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>';
  8569. 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>';
  8570. h += '</tr></tbody></table></span>';
  8571. return h;
  8572. },
  8573. showMenu : function() {
  8574. var t = this, p2, e = DOM.get(this.id), m;
  8575. if (t.isDisabled() || t.items.length === 0)
  8576. return;
  8577. if (t.menu && t.menu.isMenuVisible)
  8578. return t.hideMenu();
  8579. if (!t.isMenuRendered) {
  8580. t.renderMenu();
  8581. t.isMenuRendered = true;
  8582. }
  8583. p2 = DOM.getPos(e);
  8584. m = t.menu;
  8585. m.settings.offset_x = p2.x;
  8586. m.settings.offset_y = p2.y;
  8587. m.settings.keyboard_focus = !tinymce.isOpera; // Opera is buggy when it comes to auto focus
  8588. // Select in menu
  8589. each(t.items, function(o) {
  8590. if (m.items[o.id]) {
  8591. m.items[o.id].setSelected(0);
  8592. }
  8593. });
  8594. each(t.items, function(o) {
  8595. if (m.items[o.id] && t.marked[o.value]) {
  8596. m.items[o.id].setSelected(1);
  8597. }
  8598. if (o.value === t.selectedValue) {
  8599. m.items[o.id].setSelected(1);
  8600. }
  8601. });
  8602. m.showMenu(0, e.clientHeight);
  8603. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  8604. DOM.addClass(t.id, t.classPrefix + 'Selected');
  8605. //DOM.get(t.id + '_text').focus();
  8606. },
  8607. hideMenu : function(e) {
  8608. var t = this;
  8609. if (t.menu && t.menu.isMenuVisible) {
  8610. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  8611. // Prevent double toogles by canceling the mouse click event to the button
  8612. if (e && e.type == "mousedown" && (e.target.id == t.id + '_text' || e.target.id == t.id + '_open'))
  8613. return;
  8614. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  8615. DOM.removeClass(t.id, t.classPrefix + 'Selected');
  8616. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  8617. t.menu.hideMenu();
  8618. }
  8619. }
  8620. },
  8621. renderMenu : function() {
  8622. var t = this, m;
  8623. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  8624. menu_line : 1,
  8625. 'class' : t.classPrefix + 'Menu mceNoIcons',
  8626. max_width : 250,
  8627. max_height : 150
  8628. });
  8629. m.onHideMenu.add(function() {
  8630. t.hideMenu();
  8631. t.focus();
  8632. });
  8633. m.add({
  8634. title : t.settings.title,
  8635. 'class' : 'mceMenuItemTitle',
  8636. onclick : function() {
  8637. if (t.settings.onselect('') !== false)
  8638. t.select(''); // Must be runned after
  8639. }
  8640. });
  8641. each(t.items, function(o) {
  8642. // No value then treat it as a title
  8643. if (o.value === undef) {
  8644. m.add({
  8645. title : o.title,
  8646. role : "option",
  8647. 'class' : 'mceMenuItemTitle',
  8648. onclick : function() {
  8649. if (t.settings.onselect('') !== false)
  8650. t.select(''); // Must be runned after
  8651. }
  8652. });
  8653. } else {
  8654. o.id = DOM.uniqueId();
  8655. o.role= "option";
  8656. o.onclick = function() {
  8657. if (t.settings.onselect(o.value) !== false)
  8658. t.select(o.value); // Must be runned after
  8659. };
  8660. m.add(o);
  8661. }
  8662. });
  8663. t.onRenderMenu.dispatch(t, m);
  8664. t.menu = m;
  8665. },
  8666. postRender : function() {
  8667. var t = this, cp = t.classPrefix;
  8668. Event.add(t.id, 'click', t.showMenu, t);
  8669. Event.add(t.id, 'keydown', function(evt) {
  8670. if (evt.keyCode == 32) { // Space
  8671. t.showMenu(evt);
  8672. Event.cancel(evt);
  8673. }
  8674. });
  8675. Event.add(t.id, 'focus', function() {
  8676. if (!t._focused) {
  8677. t.keyDownHandler = Event.add(t.id, 'keydown', function(e) {
  8678. if (e.keyCode == 40) {
  8679. t.showMenu();
  8680. Event.cancel(e);
  8681. }
  8682. });
  8683. t.keyPressHandler = Event.add(t.id, 'keypress', function(e) {
  8684. var v;
  8685. if (e.keyCode == 13) {
  8686. // Fake select on enter
  8687. v = t.selectedValue;
  8688. t.selectedValue = null; // Needs to be null to fake change
  8689. Event.cancel(e);
  8690. t.settings.onselect(v);
  8691. }
  8692. });
  8693. }
  8694. t._focused = 1;
  8695. });
  8696. Event.add(t.id, 'blur', function() {
  8697. Event.remove(t.id, 'keydown', t.keyDownHandler);
  8698. Event.remove(t.id, 'keypress', t.keyPressHandler);
  8699. t._focused = 0;
  8700. });
  8701. // Old IE doesn't have hover on all elements
  8702. if (tinymce.isIE6 || !DOM.boxModel) {
  8703. Event.add(t.id, 'mouseover', function() {
  8704. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  8705. DOM.addClass(t.id, cp + 'Hover');
  8706. });
  8707. Event.add(t.id, 'mouseout', function() {
  8708. if (!DOM.hasClass(t.id, cp + 'Disabled'))
  8709. DOM.removeClass(t.id, cp + 'Hover');
  8710. });
  8711. }
  8712. t.onPostRender.dispatch(t, DOM.get(t.id));
  8713. },
  8714. destroy : function() {
  8715. this.parent();
  8716. Event.clear(this.id + '_text');
  8717. Event.clear(this.id + '_open');
  8718. }
  8719. });
  8720. })(tinymce);
  8721. (function(tinymce) {
  8722. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher, undef;
  8723. tinymce.create('tinymce.ui.NativeListBox:tinymce.ui.ListBox', {
  8724. NativeListBox : function(id, s) {
  8725. this.parent(id, s);
  8726. this.classPrefix = 'mceNativeListBox';
  8727. },
  8728. setDisabled : function(s) {
  8729. DOM.get(this.id).disabled = s;
  8730. this.setAriaProperty('disabled', s);
  8731. },
  8732. isDisabled : function() {
  8733. return DOM.get(this.id).disabled;
  8734. },
  8735. select : function(va) {
  8736. var t = this, fv, f;
  8737. if (va == undef)
  8738. return t.selectByIndex(-1);
  8739. // Is string or number make function selector
  8740. if (va && typeof(va)=="function")
  8741. f = va;
  8742. else {
  8743. f = function(v) {
  8744. return v == va;
  8745. };
  8746. }
  8747. // Do we need to do something?
  8748. if (va != t.selectedValue) {
  8749. // Find item
  8750. each(t.items, function(o, i) {
  8751. if (f(o.value)) {
  8752. fv = 1;
  8753. t.selectByIndex(i);
  8754. return false;
  8755. }
  8756. });
  8757. if (!fv)
  8758. t.selectByIndex(-1);
  8759. }
  8760. },
  8761. selectByIndex : function(idx) {
  8762. DOM.get(this.id).selectedIndex = idx + 1;
  8763. this.selectedValue = this.items[idx] ? this.items[idx].value : null;
  8764. },
  8765. add : function(n, v, a) {
  8766. var o, t = this;
  8767. a = a || {};
  8768. a.value = v;
  8769. if (t.isRendered())
  8770. DOM.add(DOM.get(this.id), 'option', a, n);
  8771. o = {
  8772. title : n,
  8773. value : v,
  8774. attribs : a
  8775. };
  8776. t.items.push(o);
  8777. t.onAdd.dispatch(t, o);
  8778. },
  8779. getLength : function() {
  8780. return this.items.length;
  8781. },
  8782. renderHTML : function() {
  8783. var h, t = this;
  8784. h = DOM.createHTML('option', {value : ''}, '-- ' + t.settings.title + ' --');
  8785. each(t.items, function(it) {
  8786. h += DOM.createHTML('option', {value : it.value}, it.title);
  8787. });
  8788. h = DOM.createHTML('select', {id : t.id, 'class' : 'mceNativeListBox', 'aria-labelledby': t.id + '_aria'}, h);
  8789. h += DOM.createHTML('span', {id : t.id + '_aria', 'style': 'display: none'}, t.settings.title);
  8790. return h;
  8791. },
  8792. postRender : function() {
  8793. var t = this, ch, changeListenerAdded = true;
  8794. t.rendered = true;
  8795. function onChange(e) {
  8796. var v = t.items[e.target.selectedIndex - 1];
  8797. if (v && (v = v.value)) {
  8798. t.onChange.dispatch(t, v);
  8799. if (t.settings.onselect)
  8800. t.settings.onselect(v);
  8801. }
  8802. };
  8803. Event.add(t.id, 'change', onChange);
  8804. // Accessibility keyhandler
  8805. Event.add(t.id, 'keydown', function(e) {
  8806. var bf;
  8807. Event.remove(t.id, 'change', ch);
  8808. changeListenerAdded = false;
  8809. bf = Event.add(t.id, 'blur', function() {
  8810. if (changeListenerAdded) return;
  8811. changeListenerAdded = true;
  8812. Event.add(t.id, 'change', onChange);
  8813. Event.remove(t.id, 'blur', bf);
  8814. });
  8815. //prevent default left and right keys on chrome - so that the keyboard navigation is used.
  8816. if (tinymce.isWebKit && (e.keyCode==37 ||e.keyCode==39)) {
  8817. return Event.prevent(e);
  8818. }
  8819. if (e.keyCode == 13 || e.keyCode == 32) {
  8820. onChange(e);
  8821. return Event.cancel(e);
  8822. }
  8823. });
  8824. t.onPostRender.dispatch(t, DOM.get(t.id));
  8825. }
  8826. });
  8827. })(tinymce);
  8828. (function(tinymce) {
  8829. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  8830. tinymce.create('tinymce.ui.MenuButton:tinymce.ui.Button', {
  8831. MenuButton : function(id, s, ed) {
  8832. this.parent(id, s, ed);
  8833. this.onRenderMenu = new tinymce.util.Dispatcher(this);
  8834. s.menu_container = s.menu_container || DOM.doc.body;
  8835. },
  8836. showMenu : function() {
  8837. var t = this, p1, p2, e = DOM.get(t.id), m;
  8838. if (t.isDisabled())
  8839. return;
  8840. if (!t.isMenuRendered) {
  8841. t.renderMenu();
  8842. t.isMenuRendered = true;
  8843. }
  8844. if (t.isMenuVisible)
  8845. return t.hideMenu();
  8846. p1 = DOM.getPos(t.settings.menu_container);
  8847. p2 = DOM.getPos(e);
  8848. m = t.menu;
  8849. m.settings.offset_x = p2.x;
  8850. m.settings.offset_y = p2.y;
  8851. m.settings.vp_offset_x = p2.x;
  8852. m.settings.vp_offset_y = p2.y;
  8853. m.settings.keyboard_focus = t._focused;
  8854. m.showMenu(0, e.firstChild.clientHeight);
  8855. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  8856. t.setState('Selected', 1);
  8857. t.isMenuVisible = 1;
  8858. },
  8859. renderMenu : function() {
  8860. var t = this, m;
  8861. m = t.settings.control_manager.createDropMenu(t.id + '_menu', {
  8862. menu_line : 1,
  8863. 'class' : this.classPrefix + 'Menu',
  8864. icons : t.settings.icons
  8865. });
  8866. m.onHideMenu.add(function() {
  8867. t.hideMenu();
  8868. t.focus();
  8869. });
  8870. t.onRenderMenu.dispatch(t, m);
  8871. t.menu = m;
  8872. },
  8873. hideMenu : function(e) {
  8874. var t = this;
  8875. // Prevent double toogles by canceling the mouse click event to the button
  8876. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id || e.id === t.id + '_open';}))
  8877. return;
  8878. if (!e || !DOM.getParent(e.target, '.mceMenu')) {
  8879. t.setState('Selected', 0);
  8880. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  8881. if (t.menu)
  8882. t.menu.hideMenu();
  8883. }
  8884. t.isMenuVisible = 0;
  8885. },
  8886. postRender : function() {
  8887. var t = this, s = t.settings;
  8888. Event.add(t.id, 'click', function() {
  8889. if (!t.isDisabled()) {
  8890. if (s.onclick)
  8891. s.onclick(t.value);
  8892. t.showMenu();
  8893. }
  8894. });
  8895. }
  8896. });
  8897. })(tinymce);
  8898. (function(tinymce) {
  8899. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
  8900. tinymce.create('tinymce.ui.SplitButton:tinymce.ui.MenuButton', {
  8901. SplitButton : function(id, s, ed) {
  8902. this.parent(id, s, ed);
  8903. this.classPrefix = 'mceSplitButton';
  8904. },
  8905. renderHTML : function() {
  8906. var h, t = this, s = t.settings, h1;
  8907. h = '<tbody><tr>';
  8908. if (s.image)
  8909. h1 = DOM.createHTML('img ', {src : s.image, role: 'presentation', 'class' : 'mceAction ' + s['class']});
  8910. else
  8911. h1 = DOM.createHTML('span', {'class' : 'mceAction ' + s['class']}, '');
  8912. h1 += DOM.createHTML('span', {'class': 'mceVoiceLabel mceIconOnly', id: t.id + '_voice', style: 'display:none;'}, s.title);
  8913. 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>';
  8914. h1 = DOM.createHTML('span', {'class' : 'mceOpen ' + s['class']}, '<span style="display:none;" class="mceIconOnly" aria-hidden="true">\u25BC</span>');
  8915. 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>';
  8916. h += '</tr></tbody>';
  8917. h = DOM.createHTML('table', { role: 'presentation', 'class' : 'mceSplitButton mceSplitButtonEnabled ' + s['class'], cellpadding : '0', cellspacing : '0', title : s.title}, h);
  8918. return DOM.createHTML('div', {id : t.id, role: 'button', tabindex: '0', 'aria-labelledby': t.id + '_voice', 'aria-haspopup': 'true'}, h);
  8919. },
  8920. postRender : function() {
  8921. var t = this, s = t.settings, activate;
  8922. if (s.onclick) {
  8923. activate = function(evt) {
  8924. if (!t.isDisabled()) {
  8925. s.onclick(t.value);
  8926. Event.cancel(evt);
  8927. }
  8928. };
  8929. Event.add(t.id + '_action', 'click', activate);
  8930. Event.add(t.id, ['click', 'keydown'], function(evt) {
  8931. var DOM_VK_SPACE = 32, DOM_VK_ENTER = 14, DOM_VK_RETURN = 13, DOM_VK_UP = 38, DOM_VK_DOWN = 40;
  8932. if ((evt.keyCode === 32 || evt.keyCode === 13 || evt.keyCode === 14) && !evt.altKey && !evt.ctrlKey && !evt.metaKey) {
  8933. activate();
  8934. Event.cancel(evt);
  8935. } else if (evt.type === 'click' || evt.keyCode === DOM_VK_DOWN) {
  8936. t.showMenu();
  8937. Event.cancel(evt);
  8938. }
  8939. });
  8940. }
  8941. Event.add(t.id + '_open', 'click', function (evt) {
  8942. t.showMenu();
  8943. Event.cancel(evt);
  8944. });
  8945. Event.add([t.id, t.id + '_open'], 'focus', function() {t._focused = 1;});
  8946. Event.add([t.id, t.id + '_open'], 'blur', function() {t._focused = 0;});
  8947. // Old IE doesn't have hover on all elements
  8948. if (tinymce.isIE6 || !DOM.boxModel) {
  8949. Event.add(t.id, 'mouseover', function() {
  8950. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  8951. DOM.addClass(t.id, 'mceSplitButtonHover');
  8952. });
  8953. Event.add(t.id, 'mouseout', function() {
  8954. if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
  8955. DOM.removeClass(t.id, 'mceSplitButtonHover');
  8956. });
  8957. }
  8958. },
  8959. destroy : function() {
  8960. this.parent();
  8961. Event.clear(this.id + '_action');
  8962. Event.clear(this.id + '_open');
  8963. Event.clear(this.id);
  8964. }
  8965. });
  8966. })(tinymce);
  8967. (function(tinymce) {
  8968. var DOM = tinymce.DOM, Event = tinymce.dom.Event, is = tinymce.is, each = tinymce.each;
  8969. tinymce.create('tinymce.ui.ColorSplitButton:tinymce.ui.SplitButton', {
  8970. ColorSplitButton : function(id, s, ed) {
  8971. var t = this;
  8972. t.parent(id, s, ed);
  8973. t.settings = s = tinymce.extend({
  8974. 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',
  8975. grid_width : 8,
  8976. default_color : '#888888'
  8977. }, t.settings);
  8978. t.onShowMenu = new tinymce.util.Dispatcher(t);
  8979. t.onHideMenu = new tinymce.util.Dispatcher(t);
  8980. t.value = s.default_color;
  8981. },
  8982. showMenu : function() {
  8983. var t = this, r, p, e, p2;
  8984. if (t.isDisabled())
  8985. return;
  8986. if (!t.isMenuRendered) {
  8987. t.renderMenu();
  8988. t.isMenuRendered = true;
  8989. }
  8990. if (t.isMenuVisible)
  8991. return t.hideMenu();
  8992. e = DOM.get(t.id);
  8993. DOM.show(t.id + '_menu');
  8994. DOM.addClass(e, 'mceSplitButtonSelected');
  8995. p2 = DOM.getPos(e);
  8996. DOM.setStyles(t.id + '_menu', {
  8997. left : p2.x,
  8998. top : p2.y + e.firstChild.clientHeight,
  8999. zIndex : 200000
  9000. });
  9001. e = 0;
  9002. Event.add(DOM.doc, 'mousedown', t.hideMenu, t);
  9003. t.onShowMenu.dispatch(t);
  9004. if (t._focused) {
  9005. t._keyHandler = Event.add(t.id + '_menu', 'keydown', function(e) {
  9006. if (e.keyCode == 27)
  9007. t.hideMenu();
  9008. });
  9009. DOM.select('a', t.id + '_menu')[0].focus(); // Select first link
  9010. }
  9011. t.keyboardNav = new tinymce.ui.KeyboardNavigation({
  9012. root: t.id + '_menu',
  9013. items: DOM.select('a', t.id + '_menu'),
  9014. onCancel: function() {
  9015. t.hideMenu();
  9016. t.focus();
  9017. }
  9018. });
  9019. t.keyboardNav.focus();
  9020. t.isMenuVisible = 1;
  9021. },
  9022. hideMenu : function(e) {
  9023. var t = this;
  9024. if (t.isMenuVisible) {
  9025. // Prevent double toogles by canceling the mouse click event to the button
  9026. if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id + '_open';}))
  9027. return;
  9028. if (!e || !DOM.getParent(e.target, '.mceSplitButtonMenu')) {
  9029. DOM.removeClass(t.id, 'mceSplitButtonSelected');
  9030. Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
  9031. Event.remove(t.id + '_menu', 'keydown', t._keyHandler);
  9032. DOM.hide(t.id + '_menu');
  9033. }
  9034. t.isMenuVisible = 0;
  9035. t.onHideMenu.dispatch();
  9036. t.keyboardNav.destroy();
  9037. }
  9038. },
  9039. renderMenu : function() {
  9040. var t = this, m, i = 0, s = t.settings, n, tb, tr, w, context;
  9041. 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;'});
  9042. m = DOM.add(w, 'div', {'class' : s['class'] + ' mceSplitButtonMenu'});
  9043. DOM.add(m, 'span', {'class' : 'mceMenuLine'});
  9044. n = DOM.add(m, 'table', {role: 'presentation', 'class' : 'mceColorSplitMenu'});
  9045. tb = DOM.add(n, 'tbody');
  9046. // Generate color grid
  9047. i = 0;
  9048. each(is(s.colors, 'array') ? s.colors : s.colors.split(','), function(c) {
  9049. c = c.replace(/^#/, '');
  9050. if (!i--) {
  9051. tr = DOM.add(tb, 'tr');
  9052. i = s.grid_width - 1;
  9053. }
  9054. n = DOM.add(tr, 'td');
  9055. var settings = {
  9056. href : 'javascript:;',
  9057. style : {
  9058. backgroundColor : '#' + c
  9059. },
  9060. 'title': t.editor.getLang('colors.' + c, c),
  9061. 'data-mce-color' : '#' + c
  9062. };
  9063. // adding a proper ARIA role = button causes JAWS to read things incorrectly on IE.
  9064. if (!tinymce.isIE ) {
  9065. settings.role = 'option';
  9066. }
  9067. n = DOM.add(n, 'a', settings);
  9068. if (t.editor.forcedHighContrastMode) {
  9069. n = DOM.add(n, 'canvas', { width: 16, height: 16, 'aria-hidden': 'true' });
  9070. if (n.getContext && (context = n.getContext("2d"))) {
  9071. context.fillStyle = '#' + c;
  9072. context.fillRect(0, 0, 16, 16);
  9073. } else {
  9074. // No point leaving a canvas element around if it's not supported for drawing on anyway.
  9075. DOM.remove(n);
  9076. }
  9077. }
  9078. });
  9079. if (s.more_colors_func) {
  9080. n = DOM.add(tb, 'tr');
  9081. n = DOM.add(n, 'td', {colspan : s.grid_width, 'class' : 'mceMoreColors'});
  9082. n = DOM.add(n, 'a', {role: 'option', id : t.id + '_more', href : 'javascript:;', onclick : 'return false;', 'class' : 'mceMoreColors'}, s.more_colors_title);
  9083. Event.add(n, 'click', function(e) {
  9084. s.more_colors_func.call(s.more_colors_scope || this);
  9085. return Event.cancel(e); // Cancel to fix onbeforeunload problem
  9086. });
  9087. }
  9088. DOM.addClass(m, 'mceColorSplitMenu');
  9089. // Prevent IE from scrolling and hindering click to occur #4019
  9090. Event.add(t.id + '_menu', 'mousedown', function(e) {return Event.cancel(e);});
  9091. Event.add(t.id + '_menu', 'click', function(e) {
  9092. var c;
  9093. e = DOM.getParent(e.target, 'a', tb);
  9094. if (e && e.nodeName.toLowerCase() == 'a' && (c = e.getAttribute('data-mce-color')))
  9095. t.setColor(c);
  9096. return false; // Prevent IE auto save warning
  9097. });
  9098. return w;
  9099. },
  9100. setColor : function(c) {
  9101. this.displayColor(c);
  9102. this.hideMenu();
  9103. this.settings.onselect(c);
  9104. },
  9105. displayColor : function(c) {
  9106. var t = this;
  9107. DOM.setStyle(t.id + '_preview', 'backgroundColor', c);
  9108. t.value = c;
  9109. },
  9110. postRender : function() {
  9111. var t = this, id = t.id;
  9112. t.parent();
  9113. DOM.add(id + '_action', 'div', {id : id + '_preview', 'class' : 'mceColorPreview'});
  9114. DOM.setStyle(t.id + '_preview', 'backgroundColor', t.value);
  9115. },
  9116. destroy : function() {
  9117. var self = this;
  9118. self.parent();
  9119. Event.clear(self.id + '_menu');
  9120. Event.clear(self.id + '_more');
  9121. DOM.remove(self.id + '_menu');
  9122. if (self.keyboardNav) {
  9123. self.keyboardNav.destroy();
  9124. }
  9125. }
  9126. });
  9127. })(tinymce);
  9128. (function(tinymce) {
  9129. // Shorten class names
  9130. var dom = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event;
  9131. tinymce.create('tinymce.ui.ToolbarGroup:tinymce.ui.Container', {
  9132. renderHTML : function() {
  9133. var t = this, h = [], controls = t.controls, each = tinymce.each, settings = t.settings;
  9134. h.push('<div id="' + t.id + '" role="group" aria-labelledby="' + t.id + '_voice">');
  9135. //TODO: ACC test this out - adding a role = application for getting the landmarks working well.
  9136. h.push("<span role='application'>");
  9137. h.push('<span id="' + t.id + '_voice" class="mceVoiceLabel" style="display:none;">' + dom.encode(settings.name) + '</span>');
  9138. each(controls, function(toolbar) {
  9139. h.push(toolbar.renderHTML());
  9140. });
  9141. h.push("</span>");
  9142. h.push('</div>');
  9143. return h.join('');
  9144. },
  9145. focus : function() {
  9146. var t = this;
  9147. dom.get(t.id).focus();
  9148. },
  9149. postRender : function() {
  9150. var t = this, items = [];
  9151. each(t.controls, function(toolbar) {
  9152. each (toolbar.controls, function(control) {
  9153. if (control.id) {
  9154. items.push(control);
  9155. }
  9156. });
  9157. });
  9158. t.keyNav = new tinymce.ui.KeyboardNavigation({
  9159. root: t.id,
  9160. items: items,
  9161. onCancel: function() {
  9162. //Move focus if webkit so that navigation back will read the item.
  9163. if (tinymce.isWebKit) {
  9164. dom.get(t.editor.id+"_ifr").focus();
  9165. }
  9166. t.editor.focus();
  9167. },
  9168. excludeFromTabOrder: !t.settings.tab_focus_toolbar
  9169. });
  9170. },
  9171. destroy : function() {
  9172. var self = this;
  9173. self.parent();
  9174. self.keyNav.destroy();
  9175. Event.clear(self.id);
  9176. }
  9177. });
  9178. })(tinymce);
  9179. (function(tinymce) {
  9180. // Shorten class names
  9181. var dom = tinymce.DOM, each = tinymce.each;
  9182. tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', {
  9183. renderHTML : function() {
  9184. var t = this, h = '', c, co, s = t.settings, i, pr, nx, cl;
  9185. cl = t.controls;
  9186. for (i=0; i<cl.length; i++) {
  9187. // Get current control, prev control, next control and if the control is a list box or not
  9188. co = cl[i];
  9189. pr = cl[i - 1];
  9190. nx = cl[i + 1];
  9191. // Add toolbar start
  9192. if (i === 0) {
  9193. c = 'mceToolbarStart';
  9194. if (co.Button)
  9195. c += ' mceToolbarStartButton';
  9196. else if (co.SplitButton)
  9197. c += ' mceToolbarStartSplitButton';
  9198. else if (co.ListBox)
  9199. c += ' mceToolbarStartListBox';
  9200. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  9201. }
  9202. // Add toolbar end before list box and after the previous button
  9203. // This is to fix the o2k7 editor skins
  9204. if (pr && co.ListBox) {
  9205. if (pr.Button || pr.SplitButton)
  9206. h += dom.createHTML('td', {'class' : 'mceToolbarEnd'}, dom.createHTML('span', null, '<!-- IE -->'));
  9207. }
  9208. // Render control HTML
  9209. // IE 8 quick fix, needed to propertly generate a hit area for anchors
  9210. if (dom.stdMode)
  9211. h += '<td style="position: relative">' + co.renderHTML() + '</td>';
  9212. else
  9213. h += '<td>' + co.renderHTML() + '</td>';
  9214. // Add toolbar start after list box and before the next button
  9215. // This is to fix the o2k7 editor skins
  9216. if (nx && co.ListBox) {
  9217. if (nx.Button || nx.SplitButton)
  9218. h += dom.createHTML('td', {'class' : 'mceToolbarStart'}, dom.createHTML('span', null, '<!-- IE -->'));
  9219. }
  9220. }
  9221. c = 'mceToolbarEnd';
  9222. if (co.Button)
  9223. c += ' mceToolbarEndButton';
  9224. else if (co.SplitButton)
  9225. c += ' mceToolbarEndSplitButton';
  9226. else if (co.ListBox)
  9227. c += ' mceToolbarEndListBox';
  9228. h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
  9229. 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>');
  9230. }
  9231. });
  9232. })(tinymce);
  9233. (function(tinymce) {
  9234. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each;
  9235. tinymce.create('tinymce.AddOnManager', {
  9236. AddOnManager : function() {
  9237. var self = this;
  9238. self.items = [];
  9239. self.urls = {};
  9240. self.lookup = {};
  9241. self.onAdd = new Dispatcher(self);
  9242. },
  9243. get : function(n) {
  9244. if (this.lookup[n]) {
  9245. return this.lookup[n].instance;
  9246. } else {
  9247. return undefined;
  9248. }
  9249. },
  9250. dependencies : function(n) {
  9251. var result;
  9252. if (this.lookup[n]) {
  9253. result = this.lookup[n].dependencies;
  9254. }
  9255. return result || [];
  9256. },
  9257. requireLangPack : function(n) {
  9258. var s = tinymce.settings;
  9259. if (s && s.language && s.language_load !== false)
  9260. tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js');
  9261. },
  9262. add : function(id, o, dependencies) {
  9263. this.items.push(o);
  9264. this.lookup[id] = {instance:o, dependencies:dependencies};
  9265. this.onAdd.dispatch(this, id, o);
  9266. return o;
  9267. },
  9268. createUrl: function(baseUrl, dep) {
  9269. if (typeof dep === "object") {
  9270. return dep
  9271. } else {
  9272. return {prefix: baseUrl.prefix, resource: dep, suffix: baseUrl.suffix};
  9273. }
  9274. },
  9275. addComponents: function(pluginName, scripts) {
  9276. var pluginUrl = this.urls[pluginName];
  9277. tinymce.each(scripts, function(script){
  9278. tinymce.ScriptLoader.add(pluginUrl+"/"+script);
  9279. });
  9280. },
  9281. load : function(n, u, cb, s) {
  9282. var t = this, url = u;
  9283. function loadDependencies() {
  9284. var dependencies = t.dependencies(n);
  9285. tinymce.each(dependencies, function(dep) {
  9286. var newUrl = t.createUrl(u, dep);
  9287. t.load(newUrl.resource, newUrl, undefined, undefined);
  9288. });
  9289. if (cb) {
  9290. if (s) {
  9291. cb.call(s);
  9292. } else {
  9293. cb.call(tinymce.ScriptLoader);
  9294. }
  9295. }
  9296. }
  9297. if (t.urls[n])
  9298. return;
  9299. if (typeof u === "object")
  9300. url = u.prefix + u.resource + u.suffix;
  9301. if (url.indexOf('/') !== 0 && url.indexOf('://') == -1)
  9302. url = tinymce.baseURL + '/' + url;
  9303. t.urls[n] = url.substring(0, url.lastIndexOf('/'));
  9304. if (t.lookup[n]) {
  9305. loadDependencies();
  9306. } else {
  9307. tinymce.ScriptLoader.add(url, loadDependencies, s);
  9308. }
  9309. }
  9310. });
  9311. // Create plugin and theme managers
  9312. tinymce.PluginManager = new tinymce.AddOnManager();
  9313. tinymce.ThemeManager = new tinymce.AddOnManager();
  9314. }(tinymce));
  9315. (function(tinymce) {
  9316. // Shorten names
  9317. var each = tinymce.each, extend = tinymce.extend,
  9318. DOM = tinymce.DOM, Event = tinymce.dom.Event,
  9319. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  9320. explode = tinymce.explode,
  9321. Dispatcher = tinymce.util.Dispatcher, undef, instanceCounter = 0;
  9322. // Setup some URLs where the editor API is located and where the document is
  9323. tinymce.documentBaseURL = window.location.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
  9324. if (!/[\/\\]$/.test(tinymce.documentBaseURL))
  9325. tinymce.documentBaseURL += '/';
  9326. tinymce.baseURL = new tinymce.util.URI(tinymce.documentBaseURL).toAbsolute(tinymce.baseURL);
  9327. tinymce.baseURI = new tinymce.util.URI(tinymce.baseURL);
  9328. // Add before unload listener
  9329. // This was required since IE was leaking memory if you added and removed beforeunload listeners
  9330. // with attachEvent/detatchEvent so this only adds one listener and instances can the attach to the onBeforeUnload event
  9331. tinymce.onBeforeUnload = new Dispatcher(tinymce);
  9332. // Must be on window or IE will leak if the editor is placed in frame or iframe
  9333. Event.add(window, 'beforeunload', function(e) {
  9334. tinymce.onBeforeUnload.dispatch(tinymce, e);
  9335. });
  9336. tinymce.onAddEditor = new Dispatcher(tinymce);
  9337. tinymce.onRemoveEditor = new Dispatcher(tinymce);
  9338. tinymce.EditorManager = extend(tinymce, {
  9339. editors : [],
  9340. i18n : {},
  9341. activeEditor : null,
  9342. init : function(s) {
  9343. var t = this, pl, sl = tinymce.ScriptLoader, e, el = [], ed;
  9344. function createId(elm) {
  9345. var id = elm.id;
  9346. // Use element id, or unique name or generate a unique id
  9347. if (!id) {
  9348. id = elm.name;
  9349. if (id && !DOM.get(id)) {
  9350. id = elm.name;
  9351. } else {
  9352. // Generate unique name
  9353. id = DOM.uniqueId();
  9354. }
  9355. elm.setAttribute('id', id);
  9356. }
  9357. return id;
  9358. };
  9359. function execCallback(se, n, s) {
  9360. var f = se[n];
  9361. if (!f)
  9362. return;
  9363. if (tinymce.is(f, 'string')) {
  9364. s = f.replace(/\.\w+$/, '');
  9365. s = s ? tinymce.resolve(s) : 0;
  9366. f = tinymce.resolve(f);
  9367. }
  9368. return f.apply(s || this, Array.prototype.slice.call(arguments, 2));
  9369. };
  9370. function hasClass(n, c) {
  9371. return c.constructor === RegExp ? c.test(n.className) : DOM.hasClass(n, c);
  9372. };
  9373. t.settings = s;
  9374. // Legacy call
  9375. Event.bind(window, 'ready', function() {
  9376. var l, co;
  9377. execCallback(s, 'onpageload');
  9378. switch (s.mode) {
  9379. case "exact":
  9380. l = s.elements || '';
  9381. if(l.length > 0) {
  9382. each(explode(l), function(v) {
  9383. if (DOM.get(v)) {
  9384. ed = new tinymce.Editor(v, s);
  9385. el.push(ed);
  9386. ed.render(1);
  9387. } else {
  9388. each(document.forms, function(f) {
  9389. each(f.elements, function(e) {
  9390. if (e.name === v) {
  9391. v = 'mce_editor_' + instanceCounter++;
  9392. DOM.setAttrib(e, 'id', v);
  9393. ed = new tinymce.Editor(v, s);
  9394. el.push(ed);
  9395. ed.render(1);
  9396. }
  9397. });
  9398. });
  9399. }
  9400. });
  9401. }
  9402. break;
  9403. case "textareas":
  9404. case "specific_textareas":
  9405. each(DOM.select('textarea'), function(elm) {
  9406. if (s.editor_deselector && hasClass(elm, s.editor_deselector))
  9407. return;
  9408. if (!s.editor_selector || hasClass(elm, s.editor_selector)) {
  9409. ed = new tinymce.Editor(createId(elm), s);
  9410. el.push(ed);
  9411. ed.render(1);
  9412. }
  9413. });
  9414. break;
  9415. default:
  9416. if (s.types) {
  9417. // Process type specific selector
  9418. each(s.types, function(type) {
  9419. each(DOM.select(type.selector), function(elm) {
  9420. var editor = new tinymce.Editor(createId(elm), tinymce.extend({}, s, type));
  9421. el.push(editor);
  9422. editor.render(1);
  9423. });
  9424. });
  9425. } else if (s.selector) {
  9426. // Process global selector
  9427. each(DOM.select(s.selector), function(elm) {
  9428. var editor = new tinymce.Editor(createId(elm), s);
  9429. el.push(editor);
  9430. editor.render(1);
  9431. });
  9432. }
  9433. }
  9434. // Call onInit when all editors are initialized
  9435. if (s.oninit) {
  9436. l = co = 0;
  9437. each(el, function(ed) {
  9438. co++;
  9439. if (!ed.initialized) {
  9440. // Wait for it
  9441. ed.onInit.add(function() {
  9442. l++;
  9443. // All done
  9444. if (l == co)
  9445. execCallback(s, 'oninit');
  9446. });
  9447. } else
  9448. l++;
  9449. // All done
  9450. if (l == co)
  9451. execCallback(s, 'oninit');
  9452. });
  9453. }
  9454. });
  9455. },
  9456. get : function(id) {
  9457. if (id === undef)
  9458. return this.editors;
  9459. if (!this.editors.hasOwnProperty(id))
  9460. return undef;
  9461. return this.editors[id];
  9462. },
  9463. getInstanceById : function(id) {
  9464. return this.get(id);
  9465. },
  9466. add : function(editor) {
  9467. var self = this, editors = self.editors;
  9468. // Add named and index editor instance
  9469. editors[editor.id] = editor;
  9470. editors.push(editor);
  9471. self._setActive(editor);
  9472. self.onAddEditor.dispatch(self, editor);
  9473. // Patch the tinymce.Editor instance with jQuery adapter logic
  9474. if (tinymce.adapter)
  9475. tinymce.adapter.patchEditor(editor);
  9476. return editor;
  9477. },
  9478. remove : function(editor) {
  9479. var t = this, i, editors = t.editors;
  9480. // Not in the collection
  9481. if (!editors[editor.id])
  9482. return null;
  9483. delete editors[editor.id];
  9484. for (i = 0; i < editors.length; i++) {
  9485. if (editors[i] == editor) {
  9486. editors.splice(i, 1);
  9487. break;
  9488. }
  9489. }
  9490. // Select another editor since the active one was removed
  9491. if (t.activeEditor == editor)
  9492. t._setActive(editors[0]);
  9493. editor.destroy();
  9494. t.onRemoveEditor.dispatch(t, editor);
  9495. return editor;
  9496. },
  9497. execCommand : function(c, u, v) {
  9498. var t = this, ed = t.get(v), w;
  9499. function clr() {
  9500. ed.destroy();
  9501. w.detachEvent('onunload', clr);
  9502. w = w.tinyMCE = w.tinymce = null; // IE leak
  9503. };
  9504. // Manager commands
  9505. switch (c) {
  9506. case "mceFocus":
  9507. ed.focus();
  9508. return true;
  9509. case "mceAddEditor":
  9510. case "mceAddControl":
  9511. if (!t.get(v))
  9512. new tinymce.Editor(v, t.settings).render();
  9513. return true;
  9514. case "mceAddFrameControl":
  9515. w = v.window;
  9516. // Add tinyMCE global instance and tinymce namespace to specified window
  9517. w.tinyMCE = tinyMCE;
  9518. w.tinymce = tinymce;
  9519. tinymce.DOM.doc = w.document;
  9520. tinymce.DOM.win = w;
  9521. ed = new tinymce.Editor(v.element_id, v);
  9522. ed.render();
  9523. // Fix IE memory leaks
  9524. if (tinymce.isIE) {
  9525. w.attachEvent('onunload', clr);
  9526. }
  9527. v.page_window = null;
  9528. return true;
  9529. case "mceRemoveEditor":
  9530. case "mceRemoveControl":
  9531. if (ed)
  9532. ed.remove();
  9533. return true;
  9534. case 'mceToggleEditor':
  9535. if (!ed) {
  9536. t.execCommand('mceAddControl', 0, v);
  9537. return true;
  9538. }
  9539. if (ed.isHidden())
  9540. ed.show();
  9541. else
  9542. ed.hide();
  9543. return true;
  9544. }
  9545. // Run command on active editor
  9546. if (t.activeEditor)
  9547. return t.activeEditor.execCommand(c, u, v);
  9548. return false;
  9549. },
  9550. execInstanceCommand : function(id, c, u, v) {
  9551. var ed = this.get(id);
  9552. if (ed)
  9553. return ed.execCommand(c, u, v);
  9554. return false;
  9555. },
  9556. triggerSave : function() {
  9557. each(this.editors, function(e) {
  9558. e.save();
  9559. });
  9560. },
  9561. addI18n : function(p, o) {
  9562. var lo, i18n = this.i18n;
  9563. if (!tinymce.is(p, 'string')) {
  9564. each(p, function(o, lc) {
  9565. each(o, function(o, g) {
  9566. each(o, function(o, k) {
  9567. if (g === 'common')
  9568. i18n[lc + '.' + k] = o;
  9569. else
  9570. i18n[lc + '.' + g + '.' + k] = o;
  9571. });
  9572. });
  9573. });
  9574. } else {
  9575. each(o, function(o, k) {
  9576. i18n[p + '.' + k] = o;
  9577. });
  9578. }
  9579. },
  9580. // Private methods
  9581. _setActive : function(editor) {
  9582. this.selectedInstance = this.activeEditor = editor;
  9583. }
  9584. });
  9585. })(tinymce);
  9586. (function(tinymce) {
  9587. // Shorten these names
  9588. var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend,
  9589. each = tinymce.each, isGecko = tinymce.isGecko,
  9590. isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, is = tinymce.is,
  9591. ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager,
  9592. explode = tinymce.explode;
  9593. tinymce.create('tinymce.Editor', {
  9594. Editor : function(id, settings) {
  9595. var self = this, TRUE = true;
  9596. self.settings = settings = extend({
  9597. id : id,
  9598. language : 'en',
  9599. theme : 'advanced',
  9600. skin : 'default',
  9601. delta_width : 0,
  9602. delta_height : 0,
  9603. popup_css : '',
  9604. plugins : '',
  9605. document_base_url : tinymce.documentBaseURL,
  9606. add_form_submit_trigger : TRUE,
  9607. submit_patch : TRUE,
  9608. add_unload_trigger : TRUE,
  9609. convert_urls : TRUE,
  9610. relative_urls : TRUE,
  9611. remove_script_host : TRUE,
  9612. table_inline_editing : false,
  9613. object_resizing : TRUE,
  9614. accessibility_focus : TRUE,
  9615. doctype : tinymce.isIE6 ? '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">' : '<!DOCTYPE>', // Use old doctype on IE 6 to avoid horizontal scroll
  9616. visual : TRUE,
  9617. font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large',
  9618. 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
  9619. apply_source_formatting : TRUE,
  9620. directionality : 'ltr',
  9621. forced_root_block : 'p',
  9622. hidden_input : TRUE,
  9623. padd_empty_editor : TRUE,
  9624. render_ui : TRUE,
  9625. indentation : '30px',
  9626. fix_table_elements : TRUE,
  9627. inline_styles : TRUE,
  9628. convert_fonts_to_spans : TRUE,
  9629. indent : 'simple',
  9630. indent_before : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr,section,article,hgroup,aside,figure,option,optgroup,datalist',
  9631. indent_after : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr,section,article,hgroup,aside,figure,option,optgroup,datalist',
  9632. validate : TRUE,
  9633. entity_encoding : 'named',
  9634. url_converter : self.convertURL,
  9635. url_converter_scope : self,
  9636. ie7_compat : TRUE
  9637. }, settings);
  9638. self.id = self.editorId = id;
  9639. self.isNotDirty = false;
  9640. self.plugins = {};
  9641. self.documentBaseURI = new tinymce.util.URI(settings.document_base_url || tinymce.documentBaseURL, {
  9642. base_uri : tinyMCE.baseURI
  9643. });
  9644. self.baseURI = tinymce.baseURI;
  9645. self.contentCSS = [];
  9646. self.contentStyles = [];
  9647. // Creates all events like onClick, onSetContent etc see Editor.Events.js for the actual logic
  9648. self.setupEvents();
  9649. // Internal command handler objects
  9650. self.execCommands = {};
  9651. self.queryStateCommands = {};
  9652. self.queryValueCommands = {};
  9653. // Call setup
  9654. self.execCallback('setup', self);
  9655. },
  9656. render : function(nst) {
  9657. var t = this, s = t.settings, id = t.id, sl = tinymce.ScriptLoader;
  9658. // Page is not loaded yet, wait for it
  9659. if (!Event.domLoaded) {
  9660. Event.add(window, 'ready', function() {
  9661. t.render();
  9662. });
  9663. return;
  9664. }
  9665. tinyMCE.settings = s;
  9666. // Element not found, then skip initialization
  9667. if (!t.getElement())
  9668. return;
  9669. // Is a iPad/iPhone and not on iOS5, then skip initialization. We need to sniff
  9670. // here since the browser says it has contentEditable support but there is no visible caret.
  9671. if (tinymce.isIDevice && !tinymce.isIOS5)
  9672. return;
  9673. // Add hidden input for non input elements inside form elements
  9674. if (!/TEXTAREA|INPUT/i.test(t.getElement().nodeName) && s.hidden_input && DOM.getParent(id, 'form'))
  9675. DOM.insertAfter(DOM.create('input', {type : 'hidden', name : id}), id);
  9676. // Hide target element early to prevent content flashing
  9677. if (!s.content_editable) {
  9678. t.orgVisibility = t.getElement().style.visibility;
  9679. t.getElement().style.visibility = 'hidden';
  9680. }
  9681. if (tinymce.WindowManager)
  9682. t.windowManager = new tinymce.WindowManager(t);
  9683. if (s.encoding == 'xml') {
  9684. t.onGetContent.add(function(ed, o) {
  9685. if (o.save)
  9686. o.content = DOM.encode(o.content);
  9687. });
  9688. }
  9689. if (s.add_form_submit_trigger) {
  9690. t.onSubmit.addToTop(function() {
  9691. if (t.initialized) {
  9692. t.save();
  9693. t.isNotDirty = 1;
  9694. }
  9695. });
  9696. }
  9697. if (s.add_unload_trigger) {
  9698. t._beforeUnload = tinyMCE.onBeforeUnload.add(function() {
  9699. if (t.initialized && !t.destroyed && !t.isHidden())
  9700. t.save({format : 'raw', no_events : true});
  9701. });
  9702. }
  9703. tinymce.addUnload(t.destroy, t);
  9704. if (s.submit_patch) {
  9705. t.onBeforeRenderUI.add(function() {
  9706. var n = t.getElement().form;
  9707. if (!n)
  9708. return;
  9709. // Already patched
  9710. if (n._mceOldSubmit)
  9711. return;
  9712. // Check page uses id="submit" or name="submit" for it's submit button
  9713. if (!n.submit.nodeType && !n.submit.length) {
  9714. t.formElement = n;
  9715. n._mceOldSubmit = n.submit;
  9716. n.submit = function() {
  9717. // Save all instances
  9718. tinymce.triggerSave();
  9719. t.isNotDirty = 1;
  9720. return t.formElement._mceOldSubmit(t.formElement);
  9721. };
  9722. }
  9723. n = null;
  9724. });
  9725. }
  9726. // Load scripts
  9727. function loadScripts() {
  9728. if (s.language && s.language_load !== false)
  9729. sl.add(tinymce.baseURL + '/langs/' + s.language + '.js');
  9730. if (s.theme && typeof s.theme != "function" && s.theme.charAt(0) != '-' && !ThemeManager.urls[s.theme])
  9731. ThemeManager.load(s.theme, 'themes/' + s.theme + '/editor_template' + tinymce.suffix + '.js');
  9732. each(explode(s.plugins), function(p) {
  9733. if (p &&!PluginManager.urls[p]) {
  9734. if (p.charAt(0) == '-') {
  9735. p = p.substr(1, p.length);
  9736. var dependencies = PluginManager.dependencies(p);
  9737. each(dependencies, function(dep) {
  9738. var defaultSettings = {prefix:'plugins/', resource: dep, suffix:'/editor_plugin' + tinymce.suffix + '.js'};
  9739. dep = PluginManager.createUrl(defaultSettings, dep);
  9740. PluginManager.load(dep.resource, dep);
  9741. });
  9742. } else {
  9743. // Skip safari plugin, since it is removed as of 3.3b1
  9744. if (p == 'safari') {
  9745. return;
  9746. }
  9747. PluginManager.load(p, {prefix:'plugins/', resource: p, suffix:'/editor_plugin' + tinymce.suffix + '.js'});
  9748. }
  9749. }
  9750. });
  9751. // Init when que is loaded
  9752. sl.loadQueue(function() {
  9753. if (!t.removed)
  9754. t.init();
  9755. });
  9756. };
  9757. loadScripts();
  9758. },
  9759. init : function() {
  9760. var n, t = this, s = t.settings, w, h, mh, e = t.getElement(), o, ti, u, bi, bc, re, i, initializedPlugins = [];
  9761. tinymce.add(t);
  9762. s.aria_label = s.aria_label || DOM.getAttrib(e, 'aria-label', t.getLang('aria.rich_text_area'));
  9763. if (s.theme) {
  9764. if (typeof s.theme != "function") {
  9765. s.theme = s.theme.replace(/-/, '');
  9766. o = ThemeManager.get(s.theme);
  9767. t.theme = new o();
  9768. if (t.theme.init)
  9769. t.theme.init(t, ThemeManager.urls[s.theme] || tinymce.documentBaseURL.replace(/\/$/, ''));
  9770. } else {
  9771. t.theme = s.theme;
  9772. }
  9773. }
  9774. function initPlugin(p) {
  9775. var c = PluginManager.get(p), u = PluginManager.urls[p] || tinymce.documentBaseURL.replace(/\/$/, ''), po;
  9776. if (c && tinymce.inArray(initializedPlugins,p) === -1) {
  9777. each(PluginManager.dependencies(p), function(dep){
  9778. initPlugin(dep);
  9779. });
  9780. po = new c(t, u);
  9781. t.plugins[p] = po;
  9782. if (po.init) {
  9783. po.init(t, u);
  9784. initializedPlugins.push(p);
  9785. }
  9786. }
  9787. }
  9788. // Create all plugins
  9789. each(explode(s.plugins.replace(/\-/g, '')), initPlugin);
  9790. // Setup popup CSS path(s)
  9791. if (s.popup_css !== false) {
  9792. if (s.popup_css)
  9793. s.popup_css = t.documentBaseURI.toAbsolute(s.popup_css);
  9794. else
  9795. s.popup_css = t.baseURI.toAbsolute("themes/" + s.theme + "/skins/" + s.skin + "/dialog.css");
  9796. }
  9797. if (s.popup_css_add)
  9798. s.popup_css += ',' + t.documentBaseURI.toAbsolute(s.popup_css_add);
  9799. t.controlManager = new tinymce.ControlManager(t);
  9800. // Enables users to override the control factory
  9801. t.onBeforeRenderUI.dispatch(t, t.controlManager);
  9802. // Measure box
  9803. if (s.render_ui && t.theme) {
  9804. t.orgDisplay = e.style.display;
  9805. if (typeof s.theme != "function") {
  9806. w = s.width || e.style.width || e.offsetWidth;
  9807. h = s.height || e.style.height || e.offsetHeight;
  9808. mh = s.min_height || 100;
  9809. re = /^[0-9\.]+(|px)$/i;
  9810. if (re.test('' + w))
  9811. w = Math.max(parseInt(w, 10) + (o.deltaWidth || 0), 100);
  9812. if (re.test('' + h))
  9813. h = Math.max(parseInt(h, 10) + (o.deltaHeight || 0), mh);
  9814. // Render UI
  9815. o = t.theme.renderUI({
  9816. targetNode : e,
  9817. width : w,
  9818. height : h,
  9819. deltaWidth : s.delta_width,
  9820. deltaHeight : s.delta_height
  9821. });
  9822. // Resize editor
  9823. DOM.setStyles(o.sizeContainer || o.editorContainer, {
  9824. width : w,
  9825. height : h
  9826. });
  9827. h = (o.iframeHeight || h) + (typeof(h) == 'number' ? (o.deltaHeight || 0) : '');
  9828. if (h < mh)
  9829. h = mh;
  9830. } else {
  9831. o = s.theme(t, e);
  9832. // Convert element type to id:s
  9833. if (o.editorContainer.nodeType) {
  9834. o.editorContainer = o.editorContainer.id = o.editorContainer.id || t.id + "_parent";
  9835. }
  9836. // Convert element type to id:s
  9837. if (o.iframeContainer.nodeType) {
  9838. o.iframeContainer = o.iframeContainer.id = o.iframeContainer.id || t.id + "_iframecontainer";
  9839. }
  9840. // Use specified iframe height or the targets offsetHeight
  9841. h = o.iframeHeight || e.offsetHeight;
  9842. // Store away the selection when it's changed to it can be restored later with a editor.focus() call
  9843. if (isIE) {
  9844. t.onInit.add(function(ed) {
  9845. ed.dom.bind(ed.getBody(), 'beforedeactivate keydown', function() {
  9846. ed.lastIERng = ed.selection.getRng();
  9847. });
  9848. });
  9849. }
  9850. }
  9851. t.editorContainer = o.editorContainer;
  9852. }
  9853. // Load specified content CSS last
  9854. if (s.content_css) {
  9855. each(explode(s.content_css), function(u) {
  9856. t.contentCSS.push(t.documentBaseURI.toAbsolute(u));
  9857. });
  9858. }
  9859. // Load specified content CSS last
  9860. if (s.content_style) {
  9861. t.contentStyles.push(s.content_style);
  9862. }
  9863. // Content editable mode ends here
  9864. if (s.content_editable) {
  9865. e = n = o = null; // Fix IE leak
  9866. return t.initContentBody();
  9867. }
  9868. // User specified a document.domain value
  9869. if (document.domain && location.hostname != document.domain)
  9870. tinymce.relaxedDomain = document.domain;
  9871. t.iframeHTML = s.doctype + '<html><head xmlns="http://www.w3.org/1999/xhtml">';
  9872. // We only need to override paths if we have to
  9873. // IE has a bug where it remove site absolute urls to relative ones if this is specified
  9874. if (s.document_base_url != tinymce.documentBaseURL)
  9875. t.iframeHTML += '<base href="' + t.documentBaseURI.getURI() + '" />';
  9876. // IE8 doesn't support carets behind images setting ie7_compat would force IE8+ to run in IE7 compat mode.
  9877. if (tinymce.isIE8) {
  9878. if (s.ie7_compat)
  9879. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=7" />';
  9880. else
  9881. t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=edge" />';
  9882. }
  9883. t.iframeHTML += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
  9884. // Load the CSS by injecting them into the HTML this will reduce "flicker"
  9885. for (i = 0; i < t.contentCSS.length; i++) {
  9886. t.iframeHTML += '<link type="text/css" rel="stylesheet" href="' + t.contentCSS[i] + '" />';
  9887. }
  9888. t.contentCSS = [];
  9889. bi = s.body_id || 'tinymce';
  9890. if (bi.indexOf('=') != -1) {
  9891. bi = t.getParam('body_id', '', 'hash');
  9892. bi = bi[t.id] || bi;
  9893. }
  9894. bc = s.body_class || '';
  9895. if (bc.indexOf('=') != -1) {
  9896. bc = t.getParam('body_class', '', 'hash');
  9897. bc = bc[t.id] || '';
  9898. }
  9899. t.iframeHTML += '</head><body id="' + bi + '" class="mceContentBody ' + bc + '" onload="window.parent.tinyMCE.get(\'' + t.id + '\').onLoad.dispatch();"><br></body></html>';
  9900. // Domain relaxing enabled, then set document domain
  9901. if (tinymce.relaxedDomain && (isIE || (tinymce.isOpera && parseFloat(opera.version()) < 11))) {
  9902. // We need to write the contents here in IE since multiple writes messes up refresh button and back button
  9903. u = 'javascript:(function(){document.open();document.domain="' + document.domain + '";var ed = window.parent.tinyMCE.get("' + t.id + '");document.write(ed.iframeHTML);document.close();ed.initContentBody();})()';
  9904. }
  9905. // Create iframe
  9906. // TODO: ACC add the appropriate description on this.
  9907. n = DOM.add(o.iframeContainer, 'iframe', {
  9908. id : t.id + "_ifr",
  9909. src : u || 'javascript:""', // Workaround for HTTPS warning in IE6/7
  9910. frameBorder : '0',
  9911. allowTransparency : "true",
  9912. title : s.aria_label,
  9913. style : {
  9914. width : '100%',
  9915. height : h,
  9916. display : 'block' // Important for Gecko to render the iframe correctly
  9917. }
  9918. });
  9919. t.contentAreaContainer = o.iframeContainer;
  9920. if (o.editorContainer) {
  9921. DOM.get(o.editorContainer).style.display = t.orgDisplay;
  9922. }
  9923. // Restore visibility on target element
  9924. e.style.visibility = t.orgVisibility;
  9925. DOM.get(t.id).style.display = 'none';
  9926. DOM.setAttrib(t.id, 'aria-hidden', true);
  9927. if (!tinymce.relaxedDomain || !u)
  9928. t.initContentBody();
  9929. e = n = o = null; // Cleanup
  9930. },
  9931. initContentBody : function() {
  9932. var self = this, settings = self.settings, targetElm = DOM.get(self.id), doc = self.getDoc(), html, body, contentCssText;
  9933. // Setup iframe body
  9934. if ((!isIE || !tinymce.relaxedDomain) && !settings.content_editable) {
  9935. doc.open();
  9936. doc.write(self.iframeHTML);
  9937. doc.close();
  9938. if (tinymce.relaxedDomain)
  9939. doc.domain = tinymce.relaxedDomain;
  9940. }
  9941. if (settings.content_editable) {
  9942. DOM.addClass(targetElm, 'mceContentBody');
  9943. self.contentDocument = doc = settings.content_document || document;
  9944. self.contentWindow = settings.content_window || window;
  9945. self.bodyElement = targetElm;
  9946. // Prevent leak in IE
  9947. settings.content_document = settings.content_window = null;
  9948. }
  9949. // It will not steal focus while setting contentEditable
  9950. body = self.getBody();
  9951. body.disabled = true;
  9952. if (!settings.readonly)
  9953. body.contentEditable = self.getParam('content_editable_state', true);
  9954. body.disabled = false;
  9955. self.schema = new tinymce.html.Schema(settings);
  9956. self.dom = new tinymce.dom.DOMUtils(doc, {
  9957. keep_values : true,
  9958. url_converter : self.convertURL,
  9959. url_converter_scope : self,
  9960. hex_colors : settings.force_hex_style_colors,
  9961. class_filter : settings.class_filter,
  9962. update_styles : true,
  9963. root_element : settings.content_editable ? self.id : null,
  9964. schema : self.schema
  9965. });
  9966. self.parser = new tinymce.html.DomParser(settings, self.schema);
  9967. // Convert src and href into data-mce-src, data-mce-href and data-mce-style
  9968. self.parser.addAttributeFilter('src,href,style', function(nodes, name) {
  9969. var i = nodes.length, node, dom = self.dom, value, internalName;
  9970. while (i--) {
  9971. node = nodes[i];
  9972. value = node.attr(name);
  9973. internalName = 'data-mce-' + name;
  9974. // Add internal attribute if we need to we don't on a refresh of the document
  9975. if (!node.attributes.map[internalName]) {
  9976. if (name === "style")
  9977. node.attr(internalName, dom.serializeStyle(dom.parseStyle(value), node.name));
  9978. else
  9979. node.attr(internalName, self.convertURL(value, name, node.name));
  9980. }
  9981. }
  9982. });
  9983. // Keep scripts from executing
  9984. self.parser.addNodeFilter('script', function(nodes, name) {
  9985. var i = nodes.length, node;
  9986. while (i--) {
  9987. node = nodes[i];
  9988. node.attr('type', 'mce-' + (node.attr('type') || 'text/javascript'));
  9989. }
  9990. });
  9991. self.parser.addNodeFilter('#cdata', function(nodes, name) {
  9992. var i = nodes.length, node;
  9993. while (i--) {
  9994. node = nodes[i];
  9995. node.type = 8;
  9996. node.name = '#comment';
  9997. node.value = '[CDATA[' + node.value + ']]';
  9998. }
  9999. });
  10000. self.parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function(nodes, name) {
  10001. var i = nodes.length, node, nonEmptyElements = self.schema.getNonEmptyElements();
  10002. while (i--) {
  10003. node = nodes[i];
  10004. if (node.isEmpty(nonEmptyElements))
  10005. node.empty().append(new tinymce.html.Node('br', 1)).shortEnded = true;
  10006. }
  10007. });
  10008. self.serializer = new tinymce.dom.Serializer(settings, self.dom, self.schema);
  10009. self.selection = new tinymce.dom.Selection(self.dom, self.getWin(), self.serializer, self);
  10010. self.formatter = new tinymce.Formatter(self);
  10011. self.undoManager = new tinymce.UndoManager(self);
  10012. self.forceBlocks = new tinymce.ForceBlocks(self);
  10013. self.enterKey = new tinymce.EnterKey(self);
  10014. self.editorCommands = new tinymce.EditorCommands(self);
  10015. self.onExecCommand.add(function(editor, command) {
  10016. // Don't refresh the select lists until caret move
  10017. if (!/^(FontName|FontSize)$/.test(command))
  10018. self.nodeChanged();
  10019. });
  10020. // Pass through
  10021. self.serializer.onPreProcess.add(function(se, o) {
  10022. return self.onPreProcess.dispatch(self, o, se);
  10023. });
  10024. self.serializer.onPostProcess.add(function(se, o) {
  10025. return self.onPostProcess.dispatch(self, o, se);
  10026. });
  10027. self.onPreInit.dispatch(self);
  10028. if (!settings.browser_spellcheck && !settings.gecko_spellcheck)
  10029. doc.body.spellcheck = false;
  10030. if (!settings.readonly) {
  10031. self.bindNativeEvents();
  10032. }
  10033. self.controlManager.onPostRender.dispatch(self, self.controlManager);
  10034. self.onPostRender.dispatch(self);
  10035. self.quirks = tinymce.util.Quirks(self);
  10036. if (settings.directionality)
  10037. body.dir = settings.directionality;
  10038. if (settings.nowrap)
  10039. body.style.whiteSpace = "nowrap";
  10040. if (settings.protect) {
  10041. self.onBeforeSetContent.add(function(ed, o) {
  10042. each(settings.protect, function(pattern) {
  10043. o.content = o.content.replace(pattern, function(str) {
  10044. return '<!--mce:protected ' + escape(str) + '-->';
  10045. });
  10046. });
  10047. });
  10048. }
  10049. // Add visual aids when new contents is added
  10050. self.onSetContent.add(function() {
  10051. self.addVisual(self.getBody());
  10052. });
  10053. // Remove empty contents
  10054. if (settings.padd_empty_editor) {
  10055. self.onPostProcess.add(function(ed, o) {
  10056. o.content = o.content.replace(/^(<p[^>]*>(&nbsp;|&#160;|\s|\u00a0|)<\/p>[\r\n]*|<br \/>[\r\n]*)$/, '');
  10057. });
  10058. }
  10059. self.load({initial : true, format : 'html'});
  10060. self.startContent = self.getContent({format : 'raw'});
  10061. self.initialized = true;
  10062. self.onInit.dispatch(self);
  10063. self.execCallback('setupcontent_callback', self.id, body, doc);
  10064. self.execCallback('init_instance_callback', self);
  10065. self.focus(true);
  10066. self.nodeChanged({initial : true});
  10067. // Add editor specific CSS styles
  10068. if (self.contentStyles.length > 0) {
  10069. contentCssText = '';
  10070. each(self.contentStyles, function(style) {
  10071. contentCssText += style + "\r\n";
  10072. });
  10073. self.dom.addStyle(contentCssText);
  10074. }
  10075. // Load specified content CSS last
  10076. each(self.contentCSS, function(url) {
  10077. self.dom.loadCSS(url);
  10078. });
  10079. // Handle auto focus
  10080. if (settings.auto_focus) {
  10081. setTimeout(function () {
  10082. var ed = tinymce.get(settings.auto_focus);
  10083. ed.selection.select(ed.getBody(), 1);
  10084. ed.selection.collapse(1);
  10085. ed.getBody().focus();
  10086. ed.getWin().focus();
  10087. }, 100);
  10088. }
  10089. // Clean up references for IE
  10090. targetElm = doc = body = null;
  10091. },
  10092. focus : function(skip_focus) {
  10093. var oed, self = this, selection = self.selection, contentEditable = self.settings.content_editable, ieRng, controlElm, doc = self.getDoc(), body;
  10094. if (!skip_focus) {
  10095. if (self.lastIERng) {
  10096. selection.setRng(self.lastIERng);
  10097. }
  10098. // Get selected control element
  10099. ieRng = selection.getRng();
  10100. if (ieRng.item) {
  10101. controlElm = ieRng.item(0);
  10102. }
  10103. self._refreshContentEditable();
  10104. // Focus the window iframe
  10105. if (!contentEditable) {
  10106. self.getWin().focus();
  10107. }
  10108. // Focus the body as well since it's contentEditable
  10109. if (tinymce.isGecko || contentEditable) {
  10110. body = self.getBody();
  10111. // Check for setActive since it doesn't scroll to the element
  10112. if (body.setActive) {
  10113. body.setActive();
  10114. } else {
  10115. body.focus();
  10116. }
  10117. if (contentEditable) {
  10118. selection.normalize();
  10119. }
  10120. }
  10121. // Restore selected control element
  10122. // This is needed when for example an image is selected within a
  10123. // layer a call to focus will then remove the control selection
  10124. if (controlElm && controlElm.ownerDocument == doc) {
  10125. ieRng = doc.body.createControlRange();
  10126. ieRng.addElement(controlElm);
  10127. ieRng.select();
  10128. }
  10129. }
  10130. if (tinymce.activeEditor != self) {
  10131. if ((oed = tinymce.activeEditor) != null)
  10132. oed.onDeactivate.dispatch(oed, self);
  10133. self.onActivate.dispatch(self, oed);
  10134. }
  10135. tinymce._setActive(self);
  10136. },
  10137. execCallback : function(n) {
  10138. var t = this, f = t.settings[n], s;
  10139. if (!f)
  10140. return;
  10141. // Look through lookup
  10142. if (t.callbackLookup && (s = t.callbackLookup[n])) {
  10143. f = s.func;
  10144. s = s.scope;
  10145. }
  10146. if (is(f, 'string')) {
  10147. s = f.replace(/\.\w+$/, '');
  10148. s = s ? tinymce.resolve(s) : 0;
  10149. f = tinymce.resolve(f);
  10150. t.callbackLookup = t.callbackLookup || {};
  10151. t.callbackLookup[n] = {func : f, scope : s};
  10152. }
  10153. return f.apply(s || t, Array.prototype.slice.call(arguments, 1));
  10154. },
  10155. translate : function(s) {
  10156. var c = this.settings.language || 'en', i18n = tinymce.i18n;
  10157. if (!s)
  10158. return '';
  10159. return i18n[c + '.' + s] || s.replace(/\{\#([^\}]+)\}/g, function(a, b) {
  10160. return i18n[c + '.' + b] || '{#' + b + '}';
  10161. });
  10162. },
  10163. getLang : function(n, dv) {
  10164. return tinymce.i18n[(this.settings.language || 'en') + '.' + n] || (is(dv) ? dv : '{#' + n + '}');
  10165. },
  10166. getParam : function(n, dv, ty) {
  10167. var tr = tinymce.trim, v = is(this.settings[n]) ? this.settings[n] : dv, o;
  10168. if (ty === 'hash') {
  10169. o = {};
  10170. if (is(v, 'string')) {
  10171. each(v.indexOf('=') > 0 ? v.split(/[;,](?![^=;,]*(?:[;,]|$))/) : v.split(','), function(v) {
  10172. v = v.split('=');
  10173. if (v.length > 1)
  10174. o[tr(v[0])] = tr(v[1]);
  10175. else
  10176. o[tr(v[0])] = tr(v);
  10177. });
  10178. } else
  10179. o = v;
  10180. return o;
  10181. }
  10182. return v;
  10183. },
  10184. nodeChanged : function(o) {
  10185. var self = this, selection = self.selection, node;
  10186. // Fix for bug #1896577 it seems that this can not be fired while the editor is loading
  10187. if (self.initialized) {
  10188. o = o || {};
  10189. // Get start node
  10190. node = selection.getStart() || self.getBody();
  10191. node = isIE && node.ownerDocument != self.getDoc() ? self.getBody() : node; // Fix for IE initial state
  10192. // Get parents and add them to object
  10193. o.parents = [];
  10194. self.dom.getParent(node, function(node) {
  10195. if (node.nodeName == 'BODY')
  10196. return true;
  10197. o.parents.push(node);
  10198. });
  10199. self.onNodeChange.dispatch(
  10200. self,
  10201. o ? o.controlManager || self.controlManager : self.controlManager,
  10202. node,
  10203. selection.isCollapsed(),
  10204. o
  10205. );
  10206. }
  10207. },
  10208. addButton : function(name, settings) {
  10209. var self = this;
  10210. self.buttons = self.buttons || {};
  10211. self.buttons[name] = settings;
  10212. },
  10213. addCommand : function(name, callback, scope) {
  10214. this.execCommands[name] = {func : callback, scope : scope || this};
  10215. },
  10216. addQueryStateHandler : function(name, callback, scope) {
  10217. this.queryStateCommands[name] = {func : callback, scope : scope || this};
  10218. },
  10219. addQueryValueHandler : function(name, callback, scope) {
  10220. this.queryValueCommands[name] = {func : callback, scope : scope || this};
  10221. },
  10222. addShortcut : function(pa, desc, cmd_func, sc) {
  10223. var t = this, c;
  10224. if (t.settings.custom_shortcuts === false)
  10225. return false;
  10226. t.shortcuts = t.shortcuts || {};
  10227. if (is(cmd_func, 'string')) {
  10228. c = cmd_func;
  10229. cmd_func = function() {
  10230. t.execCommand(c, false, null);
  10231. };
  10232. }
  10233. if (is(cmd_func, 'object')) {
  10234. c = cmd_func;
  10235. cmd_func = function() {
  10236. t.execCommand(c[0], c[1], c[2]);
  10237. };
  10238. }
  10239. each(explode(pa), function(pa) {
  10240. var o = {
  10241. func : cmd_func,
  10242. scope : sc || this,
  10243. desc : t.translate(desc),
  10244. alt : false,
  10245. ctrl : false,
  10246. shift : false
  10247. };
  10248. each(explode(pa, '+'), function(v) {
  10249. switch (v) {
  10250. case 'alt':
  10251. case 'ctrl':
  10252. case 'shift':
  10253. o[v] = true;
  10254. break;
  10255. default:
  10256. o.charCode = v.charCodeAt(0);
  10257. o.keyCode = v.toUpperCase().charCodeAt(0);
  10258. }
  10259. });
  10260. t.shortcuts[(o.ctrl ? 'ctrl' : '') + ',' + (o.alt ? 'alt' : '') + ',' + (o.shift ? 'shift' : '') + ',' + o.keyCode] = o;
  10261. });
  10262. return true;
  10263. },
  10264. execCommand : function(cmd, ui, val, a) {
  10265. var t = this, s = 0, o, st;
  10266. if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint|SelectAll)$/.test(cmd) && (!a || !a.skip_focus))
  10267. t.focus();
  10268. a = extend({}, a);
  10269. t.onBeforeExecCommand.dispatch(t, cmd, ui, val, a);
  10270. if (a.terminate)
  10271. return false;
  10272. // Command callback
  10273. if (t.execCallback('execcommand_callback', t.id, t.selection.getNode(), cmd, ui, val)) {
  10274. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  10275. return true;
  10276. }
  10277. // Registred commands
  10278. if (o = t.execCommands[cmd]) {
  10279. st = o.func.call(o.scope, ui, val);
  10280. // Fall through on true
  10281. if (st !== true) {
  10282. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  10283. return st;
  10284. }
  10285. }
  10286. // Plugin commands
  10287. each(t.plugins, function(p) {
  10288. if (p.execCommand && p.execCommand(cmd, ui, val)) {
  10289. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  10290. s = 1;
  10291. return false;
  10292. }
  10293. });
  10294. if (s)
  10295. return true;
  10296. // Theme commands
  10297. if (t.theme && t.theme.execCommand && t.theme.execCommand(cmd, ui, val)) {
  10298. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  10299. return true;
  10300. }
  10301. // Editor commands
  10302. if (t.editorCommands.execCommand(cmd, ui, val)) {
  10303. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  10304. return true;
  10305. }
  10306. // Browser commands
  10307. t.getDoc().execCommand(cmd, ui, val);
  10308. t.onExecCommand.dispatch(t, cmd, ui, val, a);
  10309. },
  10310. queryCommandState : function(cmd) {
  10311. var t = this, o, s;
  10312. // Is hidden then return undefined
  10313. if (t._isHidden())
  10314. return;
  10315. // Registred commands
  10316. if (o = t.queryStateCommands[cmd]) {
  10317. s = o.func.call(o.scope);
  10318. // Fall though on true
  10319. if (s !== true)
  10320. return s;
  10321. }
  10322. // Registred commands
  10323. o = t.editorCommands.queryCommandState(cmd);
  10324. if (o !== -1)
  10325. return o;
  10326. // Browser commands
  10327. try {
  10328. return this.getDoc().queryCommandState(cmd);
  10329. } catch (ex) {
  10330. // Fails sometimes see bug: 1896577
  10331. }
  10332. },
  10333. queryCommandValue : function(c) {
  10334. var t = this, o, s;
  10335. // Is hidden then return undefined
  10336. if (t._isHidden())
  10337. return;
  10338. // Registred commands
  10339. if (o = t.queryValueCommands[c]) {
  10340. s = o.func.call(o.scope);
  10341. // Fall though on true
  10342. if (s !== true)
  10343. return s;
  10344. }
  10345. // Registred commands
  10346. o = t.editorCommands.queryCommandValue(c);
  10347. if (is(o))
  10348. return o;
  10349. // Browser commands
  10350. try {
  10351. return this.getDoc().queryCommandValue(c);
  10352. } catch (ex) {
  10353. // Fails sometimes see bug: 1896577
  10354. }
  10355. },
  10356. show : function() {
  10357. var self = this;
  10358. DOM.show(self.getContainer());
  10359. DOM.hide(self.id);
  10360. self.load();
  10361. },
  10362. hide : function() {
  10363. var self = this, doc = self.getDoc();
  10364. // Fixed bug where IE has a blinking cursor left from the editor
  10365. if (isIE && doc)
  10366. doc.execCommand('SelectAll');
  10367. // We must save before we hide so Safari doesn't crash
  10368. self.save();
  10369. // defer the call to hide to prevent an IE9 crash #4921
  10370. DOM.hide(self.getContainer());
  10371. DOM.setStyle(self.id, 'display', self.orgDisplay);
  10372. },
  10373. isHidden : function() {
  10374. return !DOM.isHidden(this.id);
  10375. },
  10376. setProgressState : function(b, ti, o) {
  10377. this.onSetProgressState.dispatch(this, b, ti, o);
  10378. return b;
  10379. },
  10380. load : function(o) {
  10381. var t = this, e = t.getElement(), h;
  10382. if (e) {
  10383. o = o || {};
  10384. o.load = true;
  10385. // Double encode existing entities in the value
  10386. h = t.setContent(is(e.value) ? e.value : e.innerHTML, o);
  10387. o.element = e;
  10388. if (!o.no_events)
  10389. t.onLoadContent.dispatch(t, o);
  10390. o.element = e = null;
  10391. return h;
  10392. }
  10393. },
  10394. save : function(o) {
  10395. var t = this, e = t.getElement(), h, f;
  10396. if (!e || !t.initialized)
  10397. return;
  10398. o = o || {};
  10399. o.save = true;
  10400. o.element = e;
  10401. h = o.content = t.getContent(o);
  10402. if (!o.no_events)
  10403. t.onSaveContent.dispatch(t, o);
  10404. h = o.content;
  10405. if (!/TEXTAREA|INPUT/i.test(e.nodeName)) {
  10406. e.innerHTML = h;
  10407. // Update hidden form element
  10408. if (f = DOM.getParent(t.id, 'form')) {
  10409. each(f.elements, function(e) {
  10410. if (e.name == t.id) {
  10411. e.value = h;
  10412. return false;
  10413. }
  10414. });
  10415. }
  10416. } else
  10417. e.value = h;
  10418. o.element = e = null;
  10419. return h;
  10420. },
  10421. setContent : function(content, args) {
  10422. var self = this, rootNode, body = self.getBody(), forcedRootBlockName;
  10423. // Setup args object
  10424. args = args || {};
  10425. args.format = args.format || 'html';
  10426. args.set = true;
  10427. args.content = content;
  10428. // Do preprocessing
  10429. if (!args.no_events)
  10430. self.onBeforeSetContent.dispatch(self, args);
  10431. content = args.content;
  10432. // Padd empty content in Gecko and Safari. Commands will otherwise fail on the content
  10433. // It will also be impossible to place the caret in the editor unless there is a BR element present
  10434. if (!tinymce.isIE && (content.length === 0 || /^\s+$/.test(content))) {
  10435. forcedRootBlockName = self.settings.forced_root_block;
  10436. if (forcedRootBlockName)
  10437. content = '<' + forcedRootBlockName + '><br data-mce-bogus="1"></' + forcedRootBlockName + '>';
  10438. else
  10439. content = '<br data-mce-bogus="1">';
  10440. body.innerHTML = content;
  10441. self.selection.select(body, true);
  10442. self.selection.collapse(true);
  10443. return;
  10444. }
  10445. // Parse and serialize the html
  10446. if (args.format !== 'raw') {
  10447. content = new tinymce.html.Serializer({}, self.schema).serialize(
  10448. self.parser.parse(content)
  10449. );
  10450. }
  10451. // Set the new cleaned contents to the editor
  10452. args.content = tinymce.trim(content);
  10453. self.dom.setHTML(body, args.content);
  10454. // Do post processing
  10455. if (!args.no_events)
  10456. self.onSetContent.dispatch(self, args);
  10457. // Don't normalize selection if the focused element isn't the body in content editable mode since it will steal focus otherwise
  10458. if (!self.settings.content_editable || document.activeElement === self.getBody()) {
  10459. self.selection.normalize();
  10460. }
  10461. return args.content;
  10462. },
  10463. getContent : function(args) {
  10464. var self = this, content, body = self.getBody();
  10465. // Setup args object
  10466. args = args || {};
  10467. args.format = args.format || 'html';
  10468. args.get = true;
  10469. args.getInner = true;
  10470. // Do preprocessing
  10471. if (!args.no_events)
  10472. self.onBeforeGetContent.dispatch(self, args);
  10473. // Get raw contents or by default the cleaned contents
  10474. if (args.format == 'raw')
  10475. content = body.innerHTML;
  10476. else if (args.format == 'text')
  10477. content = body.innerText || body.textContent;
  10478. else
  10479. content = self.serializer.serialize(body, args);
  10480. // Trim whitespace in beginning/end of HTML
  10481. if (args.format != 'text') {
  10482. args.content = tinymce.trim(content);
  10483. } else {
  10484. args.content = content;
  10485. }
  10486. // Do post processing
  10487. if (!args.no_events)
  10488. self.onGetContent.dispatch(self, args);
  10489. return args.content;
  10490. },
  10491. isDirty : function() {
  10492. var self = this;
  10493. return tinymce.trim(self.startContent) != tinymce.trim(self.getContent({format : 'raw', no_events : 1})) && !self.isNotDirty;
  10494. },
  10495. getContainer : function() {
  10496. var self = this;
  10497. if (!self.container)
  10498. self.container = DOM.get(self.editorContainer || self.id + '_parent');
  10499. return self.container;
  10500. },
  10501. getContentAreaContainer : function() {
  10502. return this.contentAreaContainer;
  10503. },
  10504. getElement : function() {
  10505. return DOM.get(this.settings.content_element || this.id);
  10506. },
  10507. getWin : function() {
  10508. var self = this, elm;
  10509. if (!self.contentWindow) {
  10510. elm = DOM.get(self.id + "_ifr");
  10511. if (elm)
  10512. self.contentWindow = elm.contentWindow;
  10513. }
  10514. return self.contentWindow;
  10515. },
  10516. getDoc : function() {
  10517. var self = this, win;
  10518. if (!self.contentDocument) {
  10519. win = self.getWin();
  10520. if (win)
  10521. self.contentDocument = win.document;
  10522. }
  10523. return self.contentDocument;
  10524. },
  10525. getBody : function() {
  10526. return this.bodyElement || this.getDoc().body;
  10527. },
  10528. convertURL : function(url, name, elm) {
  10529. var self = this, settings = self.settings;
  10530. // Use callback instead
  10531. if (settings.urlconverter_callback)
  10532. return self.execCallback('urlconverter_callback', url, elm, true, name);
  10533. // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs
  10534. if (!settings.convert_urls || (elm && elm.nodeName == 'LINK') || url.indexOf('file:') === 0)
  10535. return url;
  10536. // Convert to relative
  10537. if (settings.relative_urls)
  10538. return self.documentBaseURI.toRelative(url);
  10539. // Convert to absolute
  10540. url = self.documentBaseURI.toAbsolute(url, settings.remove_script_host);
  10541. return url;
  10542. },
  10543. addVisual : function(elm) {
  10544. var self = this, settings = self.settings, dom = self.dom, cls;
  10545. elm = elm || self.getBody();
  10546. if (!is(self.hasVisual))
  10547. self.hasVisual = settings.visual;
  10548. each(dom.select('table,a', elm), function(elm) {
  10549. var value;
  10550. switch (elm.nodeName) {
  10551. case 'TABLE':
  10552. cls = settings.visual_table_class || 'mceItemTable';
  10553. value = dom.getAttrib(elm, 'border');
  10554. if (!value || value == '0') {
  10555. if (self.hasVisual)
  10556. dom.addClass(elm, cls);
  10557. else
  10558. dom.removeClass(elm, cls);
  10559. }
  10560. return;
  10561. case 'A':
  10562. if (!dom.getAttrib(elm, 'href', false)) {
  10563. value = dom.getAttrib(elm, 'name') || elm.id;
  10564. cls = 'mceItemAnchor';
  10565. if (value) {
  10566. if (self.hasVisual)
  10567. dom.addClass(elm, cls);
  10568. else
  10569. dom.removeClass(elm, cls);
  10570. }
  10571. }
  10572. return;
  10573. }
  10574. });
  10575. self.onVisualAid.dispatch(self, elm, self.hasVisual);
  10576. },
  10577. remove : function() {
  10578. var self = this, elm = self.getContainer(), doc = self.getDoc();
  10579. if (!self.removed) {
  10580. self.removed = 1; // Cancels post remove event execution
  10581. // Fixed bug where IE has a blinking cursor left from the editor
  10582. if (isIE && doc)
  10583. doc.execCommand('SelectAll');
  10584. // We must save before we hide so Safari doesn't crash
  10585. self.save();
  10586. DOM.setStyle(self.id, 'display', self.orgDisplay);
  10587. // Don't clear the window or document if content editable
  10588. // is enabled since other instances might still be present
  10589. if (!self.settings.content_editable) {
  10590. Event.unbind(self.getWin());
  10591. Event.unbind(self.getDoc());
  10592. }
  10593. Event.unbind(self.getBody());
  10594. Event.clear(elm);
  10595. self.execCallback('remove_instance_callback', self);
  10596. self.onRemove.dispatch(self);
  10597. // Clear all execCommand listeners this is required to avoid errors if the editor was removed inside another command
  10598. self.onExecCommand.listeners = [];
  10599. tinymce.remove(self);
  10600. DOM.remove(elm);
  10601. }
  10602. },
  10603. destroy : function(s) {
  10604. var t = this;
  10605. // One time is enough
  10606. if (t.destroyed)
  10607. return;
  10608. // We must unbind on Gecko since it would otherwise produce the pesky "attempt to run compile-and-go script on a cleared scope" message
  10609. if (isGecko) {
  10610. Event.unbind(t.getDoc());
  10611. Event.unbind(t.getWin());
  10612. Event.unbind(t.getBody());
  10613. }
  10614. if (!s) {
  10615. tinymce.removeUnload(t.destroy);
  10616. tinyMCE.onBeforeUnload.remove(t._beforeUnload);
  10617. // Manual destroy
  10618. if (t.theme && t.theme.destroy)
  10619. t.theme.destroy();
  10620. // Destroy controls, selection and dom
  10621. t.controlManager.destroy();
  10622. t.selection.destroy();
  10623. t.dom.destroy();
  10624. }
  10625. if (t.formElement) {
  10626. t.formElement.submit = t.formElement._mceOldSubmit;
  10627. t.formElement._mceOldSubmit = null;
  10628. }
  10629. t.contentAreaContainer = t.formElement = t.container = t.settings.content_element = t.bodyElement = t.contentDocument = t.contentWindow = null;
  10630. if (t.selection)
  10631. t.selection = t.selection.win = t.selection.dom = t.selection.dom.doc = null;
  10632. t.destroyed = 1;
  10633. },
  10634. // Internal functions
  10635. _refreshContentEditable : function() {
  10636. var self = this, body, parent;
  10637. // Check if the editor was hidden and the re-initalize contentEditable mode by removing and adding the body again
  10638. if (self._isHidden()) {
  10639. body = self.getBody();
  10640. parent = body.parentNode;
  10641. parent.removeChild(body);
  10642. parent.appendChild(body);
  10643. body.focus();
  10644. }
  10645. },
  10646. _isHidden : function() {
  10647. var s;
  10648. if (!isGecko)
  10649. return 0;
  10650. // Weird, wheres that cursor selection?
  10651. s = this.selection.getSel();
  10652. return (!s || !s.rangeCount || s.rangeCount === 0);
  10653. }
  10654. });
  10655. })(tinymce);
  10656. (function(tinymce) {
  10657. var each = tinymce.each;
  10658. tinymce.Editor.prototype.setupEvents = function() {
  10659. var self = this, settings = self.settings;
  10660. // Add events to the editor
  10661. each([
  10662. 'onPreInit',
  10663. 'onBeforeRenderUI',
  10664. 'onPostRender',
  10665. 'onLoad',
  10666. 'onInit',
  10667. 'onRemove',
  10668. 'onActivate',
  10669. 'onDeactivate',
  10670. 'onClick',
  10671. 'onEvent',
  10672. 'onMouseUp',
  10673. 'onMouseDown',
  10674. 'onDblClick',
  10675. 'onKeyDown',
  10676. 'onKeyUp',
  10677. 'onKeyPress',
  10678. 'onContextMenu',
  10679. 'onSubmit',
  10680. 'onReset',
  10681. 'onPaste',
  10682. 'onPreProcess',
  10683. 'onPostProcess',
  10684. 'onBeforeSetContent',
  10685. 'onBeforeGetContent',
  10686. 'onSetContent',
  10687. 'onGetContent',
  10688. 'onLoadContent',
  10689. 'onSaveContent',
  10690. 'onNodeChange',
  10691. 'onChange',
  10692. 'onBeforeExecCommand',
  10693. 'onExecCommand',
  10694. 'onUndo',
  10695. 'onRedo',
  10696. 'onVisualAid',
  10697. 'onSetProgressState',
  10698. 'onSetAttrib'
  10699. ], function(name) {
  10700. self[name] = new tinymce.util.Dispatcher(self);
  10701. });
  10702. // Handle legacy cleanup_callback option
  10703. if (settings.cleanup_callback) {
  10704. self.onBeforeSetContent.add(function(ed, o) {
  10705. o.content = ed.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  10706. });
  10707. self.onPreProcess.add(function(ed, o) {
  10708. if (o.set)
  10709. ed.execCallback('cleanup_callback', 'insert_to_editor_dom', o.node, o);
  10710. if (o.get)
  10711. ed.execCallback('cleanup_callback', 'get_from_editor_dom', o.node, o);
  10712. });
  10713. self.onPostProcess.add(function(ed, o) {
  10714. if (o.set)
  10715. o.content = ed.execCallback('cleanup_callback', 'insert_to_editor', o.content, o);
  10716. if (o.get)
  10717. o.content = ed.execCallback('cleanup_callback', 'get_from_editor', o.content, o);
  10718. });
  10719. }
  10720. // Handle legacy save_callback option
  10721. if (settings.save_callback) {
  10722. self.onGetContent.add(function(ed, o) {
  10723. if (o.save)
  10724. o.content = ed.execCallback('save_callback', ed.id, o.content, ed.getBody());
  10725. });
  10726. }
  10727. // Handle legacy handle_event_callback option
  10728. if (settings.handle_event_callback) {
  10729. self.onEvent.add(function(ed, e, o) {
  10730. if (self.execCallback('handle_event_callback', e, ed, o) === false) {
  10731. e.preventDefault();
  10732. e.stopPropagation();
  10733. }
  10734. });
  10735. }
  10736. // Handle legacy handle_node_change_callback option
  10737. if (settings.handle_node_change_callback) {
  10738. self.onNodeChange.add(function(ed, cm, n) {
  10739. ed.execCallback('handle_node_change_callback', ed.id, n, -1, -1, true, ed.selection.isCollapsed());
  10740. });
  10741. }
  10742. // Handle legacy save_callback option
  10743. if (settings.save_callback) {
  10744. self.onSaveContent.add(function(ed, o) {
  10745. var h = ed.execCallback('save_callback', ed.id, o.content, ed.getBody());
  10746. if (h)
  10747. o.content = h;
  10748. });
  10749. }
  10750. // Handle legacy onchange_callback option
  10751. if (settings.onchange_callback) {
  10752. self.onChange.add(function(ed, l) {
  10753. ed.execCallback('onchange_callback', ed, l);
  10754. });
  10755. }
  10756. };
  10757. tinymce.Editor.prototype.bindNativeEvents = function() {
  10758. // 'focus', 'blur', 'dblclick', 'beforedeactivate', submit, reset
  10759. var self = this, i, settings = self.settings, dom = self.dom, nativeToDispatcherMap;
  10760. nativeToDispatcherMap = {
  10761. mouseup : 'onMouseUp',
  10762. mousedown : 'onMouseDown',
  10763. click : 'onClick',
  10764. keyup : 'onKeyUp',
  10765. keydown : 'onKeyDown',
  10766. keypress : 'onKeyPress',
  10767. submit : 'onSubmit',
  10768. reset : 'onReset',
  10769. contextmenu : 'onContextMenu',
  10770. dblclick : 'onDblClick',
  10771. paste : 'onPaste' // Doesn't work in all browsers yet
  10772. };
  10773. // Handler that takes a native event and sends it out to a dispatcher like onKeyDown
  10774. function eventHandler(evt, args) {
  10775. var type = evt.type;
  10776. // Don't fire events when it's removed
  10777. if (self.removed)
  10778. return;
  10779. // Sends the native event out to a global dispatcher then to the specific event dispatcher
  10780. if (self.onEvent.dispatch(self, evt, args) !== false) {
  10781. self[nativeToDispatcherMap[evt.fakeType || evt.type]].dispatch(self, evt, args);
  10782. }
  10783. };
  10784. // Opera doesn't support focus event for contentEditable elements so we need to fake it
  10785. function doOperaFocus(e) {
  10786. self.focus(true);
  10787. };
  10788. function nodeChanged(ed, e) {
  10789. // Normalize selection for example <b>a</b><i>|a</i> becomes <b>a|</b><i>a</i> except for Ctrl+A since it selects everything
  10790. if (e.keyCode != 65 || !tinymce.VK.metaKeyPressed(e)) {
  10791. self.selection.normalize();
  10792. }
  10793. self.nodeChanged();
  10794. }
  10795. // Add DOM events
  10796. each(nativeToDispatcherMap, function(dispatcherName, nativeName) {
  10797. var root = settings.content_editable ? self.getBody() : self.getDoc();
  10798. switch (nativeName) {
  10799. case 'contextmenu':
  10800. dom.bind(root, nativeName, eventHandler);
  10801. break;
  10802. case 'paste':
  10803. dom.bind(self.getBody(), nativeName, eventHandler);
  10804. break;
  10805. case 'submit':
  10806. case 'reset':
  10807. dom.bind(self.getElement().form || tinymce.DOM.getParent(self.id, 'form'), nativeName, eventHandler);
  10808. break;
  10809. default:
  10810. dom.bind(root, nativeName, eventHandler);
  10811. }
  10812. });
  10813. // Set the editor as active when focused
  10814. dom.bind(settings.content_editable ? self.getBody() : (tinymce.isGecko ? self.getDoc() : self.getWin()), 'focus', function(e) {
  10815. self.focus(true);
  10816. });
  10817. if (settings.content_editable && tinymce.isOpera) {
  10818. dom.bind(self.getBody(), 'click', doOperaFocus);
  10819. dom.bind(self.getBody(), 'keydown', doOperaFocus);
  10820. }
  10821. // Add node change handler
  10822. self.onMouseUp.add(nodeChanged);
  10823. self.onKeyUp.add(function(ed, e) {
  10824. var keyCode = e.keyCode;
  10825. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 13 || keyCode == 45 || keyCode == 46 || keyCode == 8 || (tinymce.isMac && (keyCode == 91 || keyCode == 93)) || e.ctrlKey)
  10826. nodeChanged(ed, e);
  10827. });
  10828. // Add reset handler
  10829. self.onReset.add(function() {
  10830. self.setContent(self.startContent, {format : 'raw'});
  10831. });
  10832. // Add shortcuts
  10833. function handleShortcut(e, execute) {
  10834. if (e.altKey || e.ctrlKey || e.metaKey) {
  10835. each(self.shortcuts, function(shortcut) {
  10836. var ctrlState = tinymce.isMac ? e.metaKey : e.ctrlKey;
  10837. if (shortcut.ctrl != ctrlState || shortcut.alt != e.altKey || shortcut.shift != e.shiftKey)
  10838. return;
  10839. if (e.keyCode == shortcut.keyCode || (e.charCode && e.charCode == shortcut.charCode)) {
  10840. e.preventDefault();
  10841. if (execute) {
  10842. shortcut.func.call(shortcut.scope);
  10843. }
  10844. return true;
  10845. }
  10846. });
  10847. }
  10848. };
  10849. self.onKeyUp.add(function(ed, e) {
  10850. handleShortcut(e);
  10851. });
  10852. self.onKeyPress.add(function(ed, e) {
  10853. handleShortcut(e);
  10854. });
  10855. self.onKeyDown.add(function(ed, e) {
  10856. handleShortcut(e, true);
  10857. });
  10858. if (tinymce.isOpera) {
  10859. self.onClick.add(function(ed, e) {
  10860. e.preventDefault();
  10861. });
  10862. }
  10863. };
  10864. })(tinymce);
  10865. (function(tinymce) {
  10866. // Added for compression purposes
  10867. var each = tinymce.each, undef, TRUE = true, FALSE = false;
  10868. tinymce.EditorCommands = function(editor) {
  10869. var dom = editor.dom,
  10870. selection = editor.selection,
  10871. commands = {state: {}, exec : {}, value : {}},
  10872. settings = editor.settings,
  10873. formatter = editor.formatter,
  10874. bookmark;
  10875. function execCommand(command, ui, value) {
  10876. var func;
  10877. command = command.toLowerCase();
  10878. if (func = commands.exec[command]) {
  10879. func(command, ui, value);
  10880. return TRUE;
  10881. }
  10882. return FALSE;
  10883. };
  10884. function queryCommandState(command) {
  10885. var func;
  10886. command = command.toLowerCase();
  10887. if (func = commands.state[command])
  10888. return func(command);
  10889. return -1;
  10890. };
  10891. function queryCommandValue(command) {
  10892. var func;
  10893. command = command.toLowerCase();
  10894. if (func = commands.value[command])
  10895. return func(command);
  10896. return FALSE;
  10897. };
  10898. function addCommands(command_list, type) {
  10899. type = type || 'exec';
  10900. each(command_list, function(callback, command) {
  10901. each(command.toLowerCase().split(','), function(command) {
  10902. commands[type][command] = callback;
  10903. });
  10904. });
  10905. };
  10906. // Expose public methods
  10907. tinymce.extend(this, {
  10908. execCommand : execCommand,
  10909. queryCommandState : queryCommandState,
  10910. queryCommandValue : queryCommandValue,
  10911. addCommands : addCommands
  10912. });
  10913. // Private methods
  10914. function execNativeCommand(command, ui, value) {
  10915. if (ui === undef)
  10916. ui = FALSE;
  10917. if (value === undef)
  10918. value = null;
  10919. return editor.getDoc().execCommand(command, ui, value);
  10920. };
  10921. function isFormatMatch(name) {
  10922. return formatter.match(name);
  10923. };
  10924. function toggleFormat(name, value) {
  10925. formatter.toggle(name, value ? {value : value} : undef);
  10926. };
  10927. function storeSelection(type) {
  10928. bookmark = selection.getBookmark(type);
  10929. };
  10930. function restoreSelection() {
  10931. selection.moveToBookmark(bookmark);
  10932. };
  10933. // Add execCommand overrides
  10934. addCommands({
  10935. // Ignore these, added for compatibility
  10936. 'mceResetDesignMode,mceBeginUndoLevel' : function() {},
  10937. // Add undo manager logic
  10938. 'mceEndUndoLevel,mceAddUndoLevel' : function() {
  10939. editor.undoManager.add();
  10940. },
  10941. 'Cut,Copy,Paste' : function(command) {
  10942. var doc = editor.getDoc(), failed;
  10943. // Try executing the native command
  10944. try {
  10945. execNativeCommand(command);
  10946. } catch (ex) {
  10947. // Command failed
  10948. failed = TRUE;
  10949. }
  10950. // Present alert message about clipboard access not being available
  10951. if (failed || !doc.queryCommandSupported(command)) {
  10952. if (tinymce.isGecko) {
  10953. editor.windowManager.confirm(editor.getLang('clipboard_msg'), function(state) {
  10954. if (state)
  10955. open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', '_blank');
  10956. });
  10957. } else
  10958. editor.windowManager.alert(editor.getLang('clipboard_no_support'));
  10959. }
  10960. },
  10961. // Override unlink command
  10962. unlink : function(command) {
  10963. if (selection.isCollapsed())
  10964. selection.select(selection.getNode());
  10965. execNativeCommand(command);
  10966. selection.collapse(FALSE);
  10967. },
  10968. // Override justify commands to use the text formatter engine
  10969. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  10970. var align = command.substring(7);
  10971. // Remove all other alignments first
  10972. each('left,center,right,full'.split(','), function(name) {
  10973. if (align != name)
  10974. formatter.remove('align' + name);
  10975. });
  10976. toggleFormat('align' + align);
  10977. execCommand('mceRepaint');
  10978. },
  10979. // Override list commands to fix WebKit bug
  10980. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  10981. var listElm, listParent;
  10982. execNativeCommand(command);
  10983. // WebKit produces lists within block elements so we need to split them
  10984. // we will replace the native list creation logic to custom logic later on
  10985. // TODO: Remove this when the list creation logic is removed
  10986. listElm = dom.getParent(selection.getNode(), 'ol,ul');
  10987. if (listElm) {
  10988. listParent = listElm.parentNode;
  10989. // If list is within a text block then split that block
  10990. if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) {
  10991. storeSelection();
  10992. dom.split(listParent, listElm);
  10993. restoreSelection();
  10994. }
  10995. }
  10996. },
  10997. // Override commands to use the text formatter engine
  10998. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  10999. toggleFormat(command);
  11000. },
  11001. // Override commands to use the text formatter engine
  11002. 'ForeColor,HiliteColor,FontName' : function(command, ui, value) {
  11003. toggleFormat(command, value);
  11004. },
  11005. FontSize : function(command, ui, value) {
  11006. var fontClasses, fontSizes;
  11007. // Convert font size 1-7 to styles
  11008. if (value >= 1 && value <= 7) {
  11009. fontSizes = tinymce.explode(settings.font_size_style_values);
  11010. fontClasses = tinymce.explode(settings.font_size_classes);
  11011. if (fontClasses)
  11012. value = fontClasses[value - 1] || value;
  11013. else
  11014. value = fontSizes[value - 1] || value;
  11015. }
  11016. toggleFormat(command, value);
  11017. },
  11018. RemoveFormat : function(command) {
  11019. formatter.remove(command);
  11020. },
  11021. mceBlockQuote : function(command) {
  11022. toggleFormat('blockquote');
  11023. },
  11024. FormatBlock : function(command, ui, value) {
  11025. return toggleFormat(value || 'p');
  11026. },
  11027. mceCleanup : function() {
  11028. var bookmark = selection.getBookmark();
  11029. editor.setContent(editor.getContent({cleanup : TRUE}), {cleanup : TRUE});
  11030. selection.moveToBookmark(bookmark);
  11031. },
  11032. mceRemoveNode : function(command, ui, value) {
  11033. var node = value || selection.getNode();
  11034. // Make sure that the body node isn't removed
  11035. if (node != editor.getBody()) {
  11036. storeSelection();
  11037. editor.dom.remove(node, TRUE);
  11038. restoreSelection();
  11039. }
  11040. },
  11041. mceSelectNodeDepth : function(command, ui, value) {
  11042. var counter = 0;
  11043. dom.getParent(selection.getNode(), function(node) {
  11044. if (node.nodeType == 1 && counter++ == value) {
  11045. selection.select(node);
  11046. return FALSE;
  11047. }
  11048. }, editor.getBody());
  11049. },
  11050. mceSelectNode : function(command, ui, value) {
  11051. selection.select(value);
  11052. },
  11053. mceInsertContent : function(command, ui, value) {
  11054. var parser, serializer, parentNode, rootNode, fragment, args,
  11055. marker, nodeRect, viewPortRect, rng, node, node2, bookmarkHtml, viewportBodyElement;
  11056. //selection.normalize();
  11057. // Setup parser and serializer
  11058. parser = editor.parser;
  11059. serializer = new tinymce.html.Serializer({}, editor.schema);
  11060. bookmarkHtml = '<span id="mce_marker" data-mce-type="bookmark">\uFEFF</span>';
  11061. // Run beforeSetContent handlers on the HTML to be inserted
  11062. args = {content: value, format: 'html'};
  11063. selection.onBeforeSetContent.dispatch(selection, args);
  11064. value = args.content;
  11065. // Add caret at end of contents if it's missing
  11066. if (value.indexOf('{$caret}') == -1)
  11067. value += '{$caret}';
  11068. // Replace the caret marker with a span bookmark element
  11069. value = value.replace(/\{\$caret\}/, bookmarkHtml);
  11070. // Insert node maker where we will insert the new HTML and get it's parent
  11071. if (!selection.isCollapsed())
  11072. editor.getDoc().execCommand('Delete', false, null);
  11073. parentNode = selection.getNode();
  11074. // Parse the fragment within the context of the parent node
  11075. args = {context : parentNode.nodeName.toLowerCase()};
  11076. fragment = parser.parse(value, args);
  11077. // Move the caret to a more suitable location
  11078. node = fragment.lastChild;
  11079. if (node.attr('id') == 'mce_marker') {
  11080. marker = node;
  11081. for (node = node.prev; node; node = node.walk(true)) {
  11082. if (node.type == 3 || !dom.isBlock(node.name)) {
  11083. node.parent.insert(marker, node, node.name === 'br');
  11084. break;
  11085. }
  11086. }
  11087. }
  11088. // If parser says valid we can insert the contents into that parent
  11089. if (!args.invalid) {
  11090. value = serializer.serialize(fragment);
  11091. // Check if parent is empty or only has one BR element then set the innerHTML of that parent
  11092. node = parentNode.firstChild;
  11093. node2 = parentNode.lastChild;
  11094. if (!node || (node === node2 && node.nodeName === 'BR'))
  11095. dom.setHTML(parentNode, value);
  11096. else
  11097. selection.setContent(value);
  11098. } else {
  11099. // If the fragment was invalid within that context then we need
  11100. // to parse and process the parent it's inserted into
  11101. // Insert bookmark node and get the parent
  11102. selection.setContent(bookmarkHtml);
  11103. parentNode = selection.getNode();
  11104. rootNode = editor.getBody();
  11105. // Opera will return the document node when selection is in root
  11106. if (parentNode.nodeType == 9)
  11107. parentNode = node = rootNode;
  11108. else
  11109. node = parentNode;
  11110. // Find the ancestor just before the root element
  11111. while (node !== rootNode) {
  11112. parentNode = node;
  11113. node = node.parentNode;
  11114. }
  11115. // Get the outer/inner HTML depending on if we are in the root and parser and serialize that
  11116. value = parentNode == rootNode ? rootNode.innerHTML : dom.getOuterHTML(parentNode);
  11117. value = serializer.serialize(
  11118. parser.parse(
  11119. // Need to replace by using a function since $ in the contents would otherwise be a problem
  11120. value.replace(/<span (id="mce_marker"|id=mce_marker).+?<\/span>/i, function() {
  11121. return serializer.serialize(fragment);
  11122. })
  11123. )
  11124. );
  11125. // Set the inner/outer HTML depending on if we are in the root or not
  11126. if (parentNode == rootNode)
  11127. dom.setHTML(rootNode, value);
  11128. else
  11129. dom.setOuterHTML(parentNode, value);
  11130. }
  11131. marker = dom.get('mce_marker');
  11132. // Scroll range into view scrollIntoView on element can't be used since it will scroll the main view port as well
  11133. nodeRect = dom.getRect(marker);
  11134. viewPortRect = dom.getViewPort(editor.getWin());
  11135. // Check if node is out side the viewport if it is then scroll to it
  11136. if ((nodeRect.y + nodeRect.h > viewPortRect.y + viewPortRect.h || nodeRect.y < viewPortRect.y) ||
  11137. (nodeRect.x > viewPortRect.x + viewPortRect.w || nodeRect.x < viewPortRect.x)) {
  11138. viewportBodyElement = tinymce.isIE ? editor.getDoc().documentElement : editor.getBody();
  11139. viewportBodyElement.scrollLeft = nodeRect.x;
  11140. viewportBodyElement.scrollTop = nodeRect.y - viewPortRect.h + 25;
  11141. }
  11142. // Move selection before marker and remove it
  11143. rng = dom.createRng();
  11144. // If previous sibling is a text node set the selection to the end of that node
  11145. node = marker.previousSibling;
  11146. if (node && node.nodeType == 3) {
  11147. rng.setStart(node, node.nodeValue.length);
  11148. } else {
  11149. // If the previous sibling isn't a text node or doesn't exist set the selection before the marker node
  11150. rng.setStartBefore(marker);
  11151. rng.setEndBefore(marker);
  11152. }
  11153. // Remove the marker node and set the new range
  11154. dom.remove(marker);
  11155. selection.setRng(rng);
  11156. // Dispatch after event and add any visual elements needed
  11157. selection.onSetContent.dispatch(selection, args);
  11158. editor.addVisual();
  11159. },
  11160. mceInsertRawHTML : function(command, ui, value) {
  11161. selection.setContent('tiny_mce_marker');
  11162. editor.setContent(editor.getContent().replace(/tiny_mce_marker/g, function() { return value }));
  11163. },
  11164. mceToggleFormat : function(command, ui, value) {
  11165. toggleFormat(value);
  11166. },
  11167. mceSetContent : function(command, ui, value) {
  11168. editor.setContent(value);
  11169. },
  11170. 'Indent,Outdent' : function(command) {
  11171. var intentValue, indentUnit, value;
  11172. // Setup indent level
  11173. intentValue = settings.indentation;
  11174. indentUnit = /[a-z%]+$/i.exec(intentValue);
  11175. intentValue = parseInt(intentValue);
  11176. if (!queryCommandState('InsertUnorderedList') && !queryCommandState('InsertOrderedList')) {
  11177. // If forced_root_blocks is set to false we don't have a block to indent so lets create a div
  11178. if (!settings.forced_root_block && !dom.getParent(selection.getNode(), dom.isBlock)) {
  11179. formatter.apply('div');
  11180. }
  11181. each(selection.getSelectedBlocks(), function(element) {
  11182. if (command == 'outdent') {
  11183. value = Math.max(0, parseInt(element.style.paddingLeft || 0) - intentValue);
  11184. dom.setStyle(element, 'paddingLeft', value ? value + indentUnit : '');
  11185. } else
  11186. dom.setStyle(element, 'paddingLeft', (parseInt(element.style.paddingLeft || 0) + intentValue) + indentUnit);
  11187. });
  11188. } else
  11189. execNativeCommand(command);
  11190. },
  11191. mceRepaint : function() {
  11192. var bookmark;
  11193. if (tinymce.isGecko) {
  11194. try {
  11195. storeSelection(TRUE);
  11196. if (selection.getSel())
  11197. selection.getSel().selectAllChildren(editor.getBody());
  11198. selection.collapse(TRUE);
  11199. restoreSelection();
  11200. } catch (ex) {
  11201. // Ignore
  11202. }
  11203. }
  11204. },
  11205. mceToggleFormat : function(command, ui, value) {
  11206. formatter.toggle(value);
  11207. },
  11208. InsertHorizontalRule : function() {
  11209. editor.execCommand('mceInsertContent', false, '<hr />');
  11210. },
  11211. mceToggleVisualAid : function() {
  11212. editor.hasVisual = !editor.hasVisual;
  11213. editor.addVisual();
  11214. },
  11215. mceReplaceContent : function(command, ui, value) {
  11216. editor.execCommand('mceInsertContent', false, value.replace(/\{\$selection\}/g, selection.getContent({format : 'text'})));
  11217. },
  11218. mceInsertLink : function(command, ui, value) {
  11219. var anchor;
  11220. if (typeof(value) == 'string')
  11221. value = {href : value};
  11222. anchor = dom.getParent(selection.getNode(), 'a');
  11223. // Spaces are never valid in URLs and it's a very common mistake for people to make so we fix it here.
  11224. value.href = value.href.replace(' ', '%20');
  11225. // Remove existing links if there could be child links or that the href isn't specified
  11226. if (!anchor || !value.href) {
  11227. formatter.remove('link');
  11228. }
  11229. // Apply new link to selection
  11230. if (value.href) {
  11231. formatter.apply('link', value, anchor);
  11232. }
  11233. },
  11234. selectAll : function() {
  11235. var root = dom.getRoot(), rng = dom.createRng();
  11236. // Old IE does a better job with selectall than new versions
  11237. if (selection.getRng().setStart) {
  11238. rng.setStart(root, 0);
  11239. rng.setEnd(root, root.childNodes.length);
  11240. selection.setRng(rng);
  11241. } else {
  11242. execNativeCommand('SelectAll');
  11243. }
  11244. }
  11245. });
  11246. // Add queryCommandState overrides
  11247. addCommands({
  11248. // Override justify commands
  11249. 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
  11250. var name = 'align' + command.substring(7);
  11251. var nodes = selection.isCollapsed() ? [dom.getParent(selection.getNode(), dom.isBlock)] : selection.getSelectedBlocks();
  11252. var matches = tinymce.map(nodes, function(node) {
  11253. return !!formatter.matchNode(node, name);
  11254. });
  11255. return tinymce.inArray(matches, TRUE) !== -1;
  11256. },
  11257. 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
  11258. return isFormatMatch(command);
  11259. },
  11260. mceBlockQuote : function() {
  11261. return isFormatMatch('blockquote');
  11262. },
  11263. Outdent : function() {
  11264. var node;
  11265. if (settings.inline_styles) {
  11266. if ((node = dom.getParent(selection.getStart(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  11267. return TRUE;
  11268. if ((node = dom.getParent(selection.getEnd(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0)
  11269. return TRUE;
  11270. }
  11271. return queryCommandState('InsertUnorderedList') || queryCommandState('InsertOrderedList') || (!settings.inline_styles && !!dom.getParent(selection.getNode(), 'BLOCKQUOTE'));
  11272. },
  11273. 'InsertUnorderedList,InsertOrderedList' : function(command) {
  11274. var list = dom.getParent(selection.getNode(), 'ul,ol');
  11275. return list &&
  11276. (command === 'insertunorderedlist' && list.tagName === 'UL'
  11277. || command === 'insertorderedlist' && list.tagName === 'OL');
  11278. }
  11279. }, 'state');
  11280. // Add queryCommandValue overrides
  11281. addCommands({
  11282. 'FontSize,FontName' : function(command) {
  11283. var value = 0, parent;
  11284. if (parent = dom.getParent(selection.getNode(), 'span')) {
  11285. if (command == 'fontsize')
  11286. value = parent.style.fontSize;
  11287. else
  11288. value = parent.style.fontFamily.replace(/, /g, ',').replace(/[\'\"]/g, '').toLowerCase();
  11289. }
  11290. return value;
  11291. }
  11292. }, 'value');
  11293. // Add undo manager logic
  11294. addCommands({
  11295. Undo : function() {
  11296. editor.undoManager.undo();
  11297. },
  11298. Redo : function() {
  11299. editor.undoManager.redo();
  11300. }
  11301. });
  11302. };
  11303. })(tinymce);
  11304. (function(tinymce) {
  11305. var Dispatcher = tinymce.util.Dispatcher;
  11306. tinymce.UndoManager = function(editor) {
  11307. var self, index = 0, data = [], beforeBookmark, onAdd, onUndo, onRedo;
  11308. function getContent() {
  11309. // Remove whitespace before/after and remove pure bogus nodes
  11310. return tinymce.trim(editor.getContent({format : 'raw', no_events : 1}).replace(/<span[^>]+data-mce-bogus[^>]+>[\u200B\uFEFF]+<\/span>/g, ''));
  11311. };
  11312. function addNonTypingUndoLevel() {
  11313. self.typing = false;
  11314. self.add();
  11315. };
  11316. // Create event instances
  11317. onBeforeAdd = new Dispatcher(self);
  11318. onAdd = new Dispatcher(self);
  11319. onUndo = new Dispatcher(self);
  11320. onRedo = new Dispatcher(self);
  11321. // Pass though onAdd event from UndoManager to Editor as onChange
  11322. onAdd.add(function(undoman, level) {
  11323. if (undoman.hasUndo())
  11324. return editor.onChange.dispatch(editor, level, undoman);
  11325. });
  11326. // Pass though onUndo event from UndoManager to Editor
  11327. onUndo.add(function(undoman, level) {
  11328. return editor.onUndo.dispatch(editor, level, undoman);
  11329. });
  11330. // Pass though onRedo event from UndoManager to Editor
  11331. onRedo.add(function(undoman, level) {
  11332. return editor.onRedo.dispatch(editor, level, undoman);
  11333. });
  11334. // Add initial undo level when the editor is initialized
  11335. editor.onInit.add(function() {
  11336. self.add();
  11337. });
  11338. // Get position before an execCommand is processed
  11339. editor.onBeforeExecCommand.add(function(ed, cmd, ui, val, args) {
  11340. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!args || !args.skip_undo)) {
  11341. self.beforeChange();
  11342. }
  11343. });
  11344. // Add undo level after an execCommand call was made
  11345. editor.onExecCommand.add(function(ed, cmd, ui, val, args) {
  11346. if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!args || !args.skip_undo)) {
  11347. self.add();
  11348. }
  11349. });
  11350. // Add undo level on save contents, drag end and blur/focusout
  11351. editor.onSaveContent.add(addNonTypingUndoLevel);
  11352. editor.dom.bind(editor.dom.getRoot(), 'dragend', addNonTypingUndoLevel);
  11353. editor.dom.bind(editor.getBody(), 'focusout', function(e) {
  11354. if (!editor.removed && self.typing) {
  11355. addNonTypingUndoLevel();
  11356. }
  11357. });
  11358. editor.onKeyUp.add(function(editor, e) {
  11359. var keyCode = e.keyCode;
  11360. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 45 || keyCode == 13 || e.ctrlKey) {
  11361. addNonTypingUndoLevel();
  11362. }
  11363. });
  11364. editor.onKeyDown.add(function(editor, e) {
  11365. var keyCode = e.keyCode;
  11366. // Is caracter positon keys left,right,up,down,home,end,pgdown,pgup,enter
  11367. if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 45) {
  11368. if (self.typing) {
  11369. addNonTypingUndoLevel();
  11370. }
  11371. return;
  11372. }
  11373. // If key isn't shift,ctrl,alt,capslock,metakey
  11374. if ((keyCode < 16 || keyCode > 20) && keyCode != 224 && keyCode != 91 && !self.typing) {
  11375. self.beforeChange();
  11376. self.typing = true;
  11377. self.add();
  11378. }
  11379. });
  11380. editor.onMouseDown.add(function(editor, e) {
  11381. if (self.typing) {
  11382. addNonTypingUndoLevel();
  11383. }
  11384. });
  11385. // Add keyboard shortcuts for undo/redo keys
  11386. editor.addShortcut('ctrl+z', 'undo_desc', 'Undo');
  11387. editor.addShortcut('ctrl+y', 'redo_desc', 'Redo');
  11388. self = {
  11389. // Explose for debugging reasons
  11390. data : data,
  11391. typing : false,
  11392. onBeforeAdd: onBeforeAdd,
  11393. onAdd : onAdd,
  11394. onUndo : onUndo,
  11395. onRedo : onRedo,
  11396. beforeChange : function() {
  11397. beforeBookmark = editor.selection.getBookmark(2, true);
  11398. },
  11399. add : function(level) {
  11400. var i, settings = editor.settings, lastLevel;
  11401. level = level || {};
  11402. level.content = getContent();
  11403. self.onBeforeAdd.dispatch(self, level);
  11404. // Add undo level if needed
  11405. lastLevel = data[index];
  11406. if (lastLevel && lastLevel.content == level.content)
  11407. return null;
  11408. // Set before bookmark on previous level
  11409. if (data[index])
  11410. data[index].beforeBookmark = beforeBookmark;
  11411. // Time to compress
  11412. if (settings.custom_undo_redo_levels) {
  11413. if (data.length > settings.custom_undo_redo_levels) {
  11414. for (i = 0; i < data.length - 1; i++)
  11415. data[i] = data[i + 1];
  11416. data.length--;
  11417. index = data.length;
  11418. }
  11419. }
  11420. // Get a non intrusive normalized bookmark
  11421. level.bookmark = editor.selection.getBookmark(2, true);
  11422. // Crop array if needed
  11423. if (index < data.length - 1)
  11424. data.length = index + 1;
  11425. data.push(level);
  11426. index = data.length - 1;
  11427. self.onAdd.dispatch(self, level);
  11428. editor.isNotDirty = 0;
  11429. return level;
  11430. },
  11431. undo : function() {
  11432. var level, i;
  11433. if (self.typing) {
  11434. self.add();
  11435. self.typing = false;
  11436. }
  11437. if (index > 0) {
  11438. level = data[--index];
  11439. editor.setContent(level.content, {format : 'raw'});
  11440. editor.selection.moveToBookmark(level.beforeBookmark);
  11441. self.onUndo.dispatch(self, level);
  11442. }
  11443. return level;
  11444. },
  11445. redo : function() {
  11446. var level;
  11447. if (index < data.length - 1) {
  11448. level = data[++index];
  11449. editor.setContent(level.content, {format : 'raw'});
  11450. editor.selection.moveToBookmark(level.bookmark);
  11451. self.onRedo.dispatch(self, level);
  11452. }
  11453. return level;
  11454. },
  11455. clear : function() {
  11456. data = [];
  11457. index = 0;
  11458. self.typing = false;
  11459. },
  11460. hasUndo : function() {
  11461. return index > 0 || this.typing;
  11462. },
  11463. hasRedo : function() {
  11464. return index < data.length - 1 && !this.typing;
  11465. }
  11466. };
  11467. return self;
  11468. };
  11469. })(tinymce);
  11470. tinymce.ForceBlocks = function(editor) {
  11471. var settings = editor.settings, dom = editor.dom, selection = editor.selection, blockElements = editor.schema.getBlockElements();
  11472. function addRootBlocks() {
  11473. var node = selection.getStart(), rootNode = editor.getBody(), rng, startContainer, startOffset, endContainer, endOffset, rootBlockNode, tempNode, offset = -0xFFFFFF, wrapped, isInEditorDocument;
  11474. if (!node || node.nodeType !== 1 || !settings.forced_root_block)
  11475. return;
  11476. // Check if node is wrapped in block
  11477. while (node && node != rootNode) {
  11478. if (blockElements[node.nodeName])
  11479. return;
  11480. node = node.parentNode;
  11481. }
  11482. // Get current selection
  11483. rng = selection.getRng();
  11484. if (rng.setStart) {
  11485. startContainer = rng.startContainer;
  11486. startOffset = rng.startOffset;
  11487. endContainer = rng.endContainer;
  11488. endOffset = rng.endOffset;
  11489. } else {
  11490. // Force control range into text range
  11491. if (rng.item) {
  11492. node = rng.item(0);
  11493. rng = editor.getDoc().body.createTextRange();
  11494. rng.moveToElementText(node);
  11495. }
  11496. isInEditorDocument = rng.parentElement().ownerDocument === editor.getDoc();
  11497. tmpRng = rng.duplicate();
  11498. tmpRng.collapse(true);
  11499. startOffset = tmpRng.move('character', offset) * -1;
  11500. if (!tmpRng.collapsed) {
  11501. tmpRng = rng.duplicate();
  11502. tmpRng.collapse(false);
  11503. endOffset = (tmpRng.move('character', offset) * -1) - startOffset;
  11504. }
  11505. }
  11506. // Wrap non block elements and text nodes
  11507. node = rootNode.firstChild;
  11508. while (node) {
  11509. if (node.nodeType === 3 || (node.nodeType == 1 && !blockElements[node.nodeName])) {
  11510. // Remove empty text nodes
  11511. if (node.nodeType === 3 && node.nodeValue.length == 0) {
  11512. tempNode = node;
  11513. node = node.nextSibling;
  11514. dom.remove(tempNode);
  11515. continue;
  11516. }
  11517. if (!rootBlockNode) {
  11518. rootBlockNode = dom.create(settings.forced_root_block);
  11519. node.parentNode.insertBefore(rootBlockNode, node);
  11520. wrapped = true;
  11521. }
  11522. tempNode = node;
  11523. node = node.nextSibling;
  11524. rootBlockNode.appendChild(tempNode);
  11525. } else {
  11526. rootBlockNode = null;
  11527. node = node.nextSibling;
  11528. }
  11529. }
  11530. if (wrapped) {
  11531. if (rng.setStart) {
  11532. rng.setStart(startContainer, startOffset);
  11533. rng.setEnd(endContainer, endOffset);
  11534. selection.setRng(rng);
  11535. } else {
  11536. // Only select if the previous selection was inside the document to prevent auto focus in quirks mode
  11537. if (isInEditorDocument) {
  11538. try {
  11539. rng = editor.getDoc().body.createTextRange();
  11540. rng.moveToElementText(rootNode);
  11541. rng.collapse(true);
  11542. rng.moveStart('character', startOffset);
  11543. if (endOffset > 0)
  11544. rng.moveEnd('character', endOffset);
  11545. rng.select();
  11546. } catch (ex) {
  11547. // Ignore
  11548. }
  11549. }
  11550. }
  11551. editor.nodeChanged();
  11552. }
  11553. };
  11554. // Force root blocks
  11555. if (settings.forced_root_block) {
  11556. editor.onKeyUp.add(addRootBlocks);
  11557. editor.onNodeChange.add(addRootBlocks);
  11558. }
  11559. };
  11560. (function(tinymce) {
  11561. // Shorten names
  11562. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, extend = tinymce.extend;
  11563. tinymce.create('tinymce.ControlManager', {
  11564. ControlManager : function(ed, s) {
  11565. var t = this, i;
  11566. s = s || {};
  11567. t.editor = ed;
  11568. t.controls = {};
  11569. t.onAdd = new tinymce.util.Dispatcher(t);
  11570. t.onPostRender = new tinymce.util.Dispatcher(t);
  11571. t.prefix = s.prefix || ed.id + '_';
  11572. t._cls = {};
  11573. t.onPostRender.add(function() {
  11574. each(t.controls, function(c) {
  11575. c.postRender();
  11576. });
  11577. });
  11578. },
  11579. get : function(id) {
  11580. return this.controls[this.prefix + id] || this.controls[id];
  11581. },
  11582. setActive : function(id, s) {
  11583. var c = null;
  11584. if (c = this.get(id))
  11585. c.setActive(s);
  11586. return c;
  11587. },
  11588. setDisabled : function(id, s) {
  11589. var c = null;
  11590. if (c = this.get(id))
  11591. c.setDisabled(s);
  11592. return c;
  11593. },
  11594. add : function(c) {
  11595. var t = this;
  11596. if (c) {
  11597. t.controls[c.id] = c;
  11598. t.onAdd.dispatch(c, t);
  11599. }
  11600. return c;
  11601. },
  11602. createControl : function(name) {
  11603. var ctrl, i, l, self = this, editor = self.editor, factories, ctrlName;
  11604. // Build control factory cache
  11605. if (!self.controlFactories) {
  11606. self.controlFactories = [];
  11607. each(editor.plugins, function(plugin) {
  11608. if (plugin.createControl) {
  11609. self.controlFactories.push(plugin);
  11610. }
  11611. });
  11612. }
  11613. // Create controls by asking cached factories
  11614. factories = self.controlFactories;
  11615. for (i = 0, l = factories.length; i < l; i++) {
  11616. ctrl = factories[i].createControl(name, self);
  11617. if (ctrl) {
  11618. return self.add(ctrl);
  11619. }
  11620. }
  11621. // Create sepearator
  11622. if (name === "|" || name === "separator") {
  11623. return self.createSeparator();
  11624. }
  11625. // Create control from button collection
  11626. if (editor.buttons && (ctrl = editor.buttons[name])) {
  11627. return self.createButton(name, ctrl);
  11628. }
  11629. return self.add(ctrl);
  11630. },
  11631. createDropMenu : function(id, s, cc) {
  11632. var t = this, ed = t.editor, c, bm, v, cls;
  11633. s = extend({
  11634. 'class' : 'mceDropDown',
  11635. constrain : ed.settings.constrain_menus
  11636. }, s);
  11637. s['class'] = s['class'] + ' ' + ed.getParam('skin') + 'Skin';
  11638. if (v = ed.getParam('skin_variant'))
  11639. s['class'] += ' ' + ed.getParam('skin') + 'Skin' + v.substring(0, 1).toUpperCase() + v.substring(1);
  11640. s['class'] += ed.settings.directionality == "rtl" ? ' mceRtl' : '';
  11641. id = t.prefix + id;
  11642. cls = cc || t._cls.dropmenu || tinymce.ui.DropMenu;
  11643. c = t.controls[id] = new cls(id, s);
  11644. c.onAddItem.add(function(c, o) {
  11645. var s = o.settings;
  11646. s.title = ed.getLang(s.title, s.title);
  11647. if (!s.onclick) {
  11648. s.onclick = function(v) {
  11649. if (s.cmd)
  11650. ed.execCommand(s.cmd, s.ui || false, s.value);
  11651. };
  11652. }
  11653. });
  11654. ed.onRemove.add(function() {
  11655. c.destroy();
  11656. });
  11657. // Fix for bug #1897785, #1898007
  11658. if (tinymce.isIE) {
  11659. c.onShowMenu.add(function() {
  11660. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  11661. ed.focus();
  11662. bm = ed.selection.getBookmark(1);
  11663. });
  11664. c.onHideMenu.add(function() {
  11665. if (bm) {
  11666. ed.selection.moveToBookmark(bm);
  11667. bm = 0;
  11668. }
  11669. });
  11670. }
  11671. return t.add(c);
  11672. },
  11673. createListBox : function(id, s, cc) {
  11674. var t = this, ed = t.editor, cmd, c, cls;
  11675. if (t.get(id))
  11676. return null;
  11677. s.title = ed.translate(s.title);
  11678. s.scope = s.scope || ed;
  11679. if (!s.onselect) {
  11680. s.onselect = function(v) {
  11681. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11682. };
  11683. }
  11684. s = extend({
  11685. title : s.title,
  11686. 'class' : 'mce_' + id,
  11687. scope : s.scope,
  11688. control_manager : t
  11689. }, s);
  11690. id = t.prefix + id;
  11691. function useNativeListForAccessibility(ed) {
  11692. return ed.settings.use_accessible_selects && !tinymce.isGecko
  11693. }
  11694. if (ed.settings.use_native_selects || useNativeListForAccessibility(ed))
  11695. c = new tinymce.ui.NativeListBox(id, s);
  11696. else {
  11697. cls = cc || t._cls.listbox || tinymce.ui.ListBox;
  11698. c = new cls(id, s, ed);
  11699. }
  11700. t.controls[id] = c;
  11701. // Fix focus problem in Safari
  11702. if (tinymce.isWebKit) {
  11703. c.onPostRender.add(function(c, n) {
  11704. // Store bookmark on mousedown
  11705. Event.add(n, 'mousedown', function() {
  11706. ed.bookmark = ed.selection.getBookmark(1);
  11707. });
  11708. // Restore on focus, since it might be lost
  11709. Event.add(n, 'focus', function() {
  11710. ed.selection.moveToBookmark(ed.bookmark);
  11711. ed.bookmark = null;
  11712. });
  11713. });
  11714. }
  11715. if (c.hideMenu)
  11716. ed.onMouseDown.add(c.hideMenu, c);
  11717. return t.add(c);
  11718. },
  11719. createButton : function(id, s, cc) {
  11720. var t = this, ed = t.editor, o, c, cls;
  11721. if (t.get(id))
  11722. return null;
  11723. s.title = ed.translate(s.title);
  11724. s.label = ed.translate(s.label);
  11725. s.scope = s.scope || ed;
  11726. if (!s.onclick && !s.menu_button) {
  11727. s.onclick = function() {
  11728. ed.execCommand(s.cmd, s.ui || false, s.value);
  11729. };
  11730. }
  11731. s = extend({
  11732. title : s.title,
  11733. 'class' : 'mce_' + id,
  11734. unavailable_prefix : ed.getLang('unavailable', ''),
  11735. scope : s.scope,
  11736. control_manager : t
  11737. }, s);
  11738. id = t.prefix + id;
  11739. if (s.menu_button) {
  11740. cls = cc || t._cls.menubutton || tinymce.ui.MenuButton;
  11741. c = new cls(id, s, ed);
  11742. ed.onMouseDown.add(c.hideMenu, c);
  11743. } else {
  11744. cls = t._cls.button || tinymce.ui.Button;
  11745. c = new cls(id, s, ed);
  11746. }
  11747. return t.add(c);
  11748. },
  11749. createMenuButton : function(id, s, cc) {
  11750. s = s || {};
  11751. s.menu_button = 1;
  11752. return this.createButton(id, s, cc);
  11753. },
  11754. createSplitButton : function(id, s, cc) {
  11755. var t = this, ed = t.editor, cmd, c, cls;
  11756. if (t.get(id))
  11757. return null;
  11758. s.title = ed.translate(s.title);
  11759. s.scope = s.scope || ed;
  11760. if (!s.onclick) {
  11761. s.onclick = function(v) {
  11762. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11763. };
  11764. }
  11765. if (!s.onselect) {
  11766. s.onselect = function(v) {
  11767. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11768. };
  11769. }
  11770. s = extend({
  11771. title : s.title,
  11772. 'class' : 'mce_' + id,
  11773. scope : s.scope,
  11774. control_manager : t
  11775. }, s);
  11776. id = t.prefix + id;
  11777. cls = cc || t._cls.splitbutton || tinymce.ui.SplitButton;
  11778. c = t.add(new cls(id, s, ed));
  11779. ed.onMouseDown.add(c.hideMenu, c);
  11780. return c;
  11781. },
  11782. createColorSplitButton : function(id, s, cc) {
  11783. var t = this, ed = t.editor, cmd, c, cls, bm;
  11784. if (t.get(id))
  11785. return null;
  11786. s.title = ed.translate(s.title);
  11787. s.scope = s.scope || ed;
  11788. if (!s.onclick) {
  11789. s.onclick = function(v) {
  11790. if (tinymce.isIE)
  11791. bm = ed.selection.getBookmark(1);
  11792. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11793. };
  11794. }
  11795. if (!s.onselect) {
  11796. s.onselect = function(v) {
  11797. ed.execCommand(s.cmd, s.ui || false, v || s.value);
  11798. };
  11799. }
  11800. s = extend({
  11801. title : s.title,
  11802. 'class' : 'mce_' + id,
  11803. 'menu_class' : ed.getParam('skin') + 'Skin',
  11804. scope : s.scope,
  11805. more_colors_title : ed.getLang('more_colors')
  11806. }, s);
  11807. id = t.prefix + id;
  11808. cls = cc || t._cls.colorsplitbutton || tinymce.ui.ColorSplitButton;
  11809. c = new cls(id, s, ed);
  11810. ed.onMouseDown.add(c.hideMenu, c);
  11811. // Remove the menu element when the editor is removed
  11812. ed.onRemove.add(function() {
  11813. c.destroy();
  11814. });
  11815. // Fix for bug #1897785, #1898007
  11816. if (tinymce.isIE) {
  11817. c.onShowMenu.add(function() {
  11818. // IE 8 needs focus in order to store away a range with the current collapsed caret location
  11819. ed.focus();
  11820. bm = ed.selection.getBookmark(1);
  11821. });
  11822. c.onHideMenu.add(function() {
  11823. if (bm) {
  11824. ed.selection.moveToBookmark(bm);
  11825. bm = 0;
  11826. }
  11827. });
  11828. }
  11829. return t.add(c);
  11830. },
  11831. createToolbar : function(id, s, cc) {
  11832. var c, t = this, cls;
  11833. id = t.prefix + id;
  11834. cls = cc || t._cls.toolbar || tinymce.ui.Toolbar;
  11835. c = new cls(id, s, t.editor);
  11836. if (t.get(id))
  11837. return null;
  11838. return t.add(c);
  11839. },
  11840. createToolbarGroup : function(id, s, cc) {
  11841. var c, t = this, cls;
  11842. id = t.prefix + id;
  11843. cls = cc || this._cls.toolbarGroup || tinymce.ui.ToolbarGroup;
  11844. c = new cls(id, s, t.editor);
  11845. if (t.get(id))
  11846. return null;
  11847. return t.add(c);
  11848. },
  11849. createSeparator : function(cc) {
  11850. var cls = cc || this._cls.separator || tinymce.ui.Separator;
  11851. return new cls();
  11852. },
  11853. setControlType : function(n, c) {
  11854. return this._cls[n.toLowerCase()] = c;
  11855. },
  11856. destroy : function() {
  11857. each(this.controls, function(c) {
  11858. c.destroy();
  11859. });
  11860. this.controls = null;
  11861. }
  11862. });
  11863. })(tinymce);
  11864. (function(tinymce) {
  11865. var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isIE = tinymce.isIE, isOpera = tinymce.isOpera;
  11866. tinymce.create('tinymce.WindowManager', {
  11867. WindowManager : function(ed) {
  11868. var t = this;
  11869. t.editor = ed;
  11870. t.onOpen = new Dispatcher(t);
  11871. t.onClose = new Dispatcher(t);
  11872. t.params = {};
  11873. t.features = {};
  11874. },
  11875. open : function(s, p) {
  11876. var t = this, f = '', x, y, mo = t.editor.settings.dialog_type == 'modal', w, sw, sh, vp = tinymce.DOM.getViewPort(), u;
  11877. // Default some options
  11878. s = s || {};
  11879. p = p || {};
  11880. sw = isOpera ? vp.w : screen.width; // Opera uses windows inside the Opera window
  11881. sh = isOpera ? vp.h : screen.height;
  11882. s.name = s.name || 'mc_' + new Date().getTime();
  11883. s.width = parseInt(s.width || 320);
  11884. s.height = parseInt(s.height || 240);
  11885. s.resizable = true;
  11886. s.left = s.left || parseInt(sw / 2.0) - (s.width / 2.0);
  11887. s.top = s.top || parseInt(sh / 2.0) - (s.height / 2.0);
  11888. p.inline = false;
  11889. p.mce_width = s.width;
  11890. p.mce_height = s.height;
  11891. p.mce_auto_focus = s.auto_focus;
  11892. if (mo) {
  11893. if (isIE) {
  11894. s.center = true;
  11895. s.help = false;
  11896. s.dialogWidth = s.width + 'px';
  11897. s.dialogHeight = s.height + 'px';
  11898. s.scroll = s.scrollbars || false;
  11899. }
  11900. }
  11901. // Build features string
  11902. each(s, function(v, k) {
  11903. if (tinymce.is(v, 'boolean'))
  11904. v = v ? 'yes' : 'no';
  11905. if (!/^(name|url)$/.test(k)) {
  11906. if (isIE && mo)
  11907. f += (f ? ';' : '') + k + ':' + v;
  11908. else
  11909. f += (f ? ',' : '') + k + '=' + v;
  11910. }
  11911. });
  11912. t.features = s;
  11913. t.params = p;
  11914. t.onOpen.dispatch(t, s, p);
  11915. u = s.url || s.file;
  11916. u = tinymce._addVer(u);
  11917. try {
  11918. if (isIE && mo) {
  11919. w = 1;
  11920. window.showModalDialog(u, window, f);
  11921. } else
  11922. w = window.open(u, s.name, f);
  11923. } catch (ex) {
  11924. // Ignore
  11925. }
  11926. if (!w)
  11927. alert(t.editor.getLang('popup_blocked'));
  11928. },
  11929. close : function(w) {
  11930. w.close();
  11931. this.onClose.dispatch(this);
  11932. },
  11933. createInstance : function(cl, a, b, c, d, e) {
  11934. var f = tinymce.resolve(cl);
  11935. return new f(a, b, c, d, e);
  11936. },
  11937. confirm : function(t, cb, s, w) {
  11938. w = w || window;
  11939. cb.call(s || this, w.confirm(this._decode(this.editor.getLang(t, t))));
  11940. },
  11941. alert : function(tx, cb, s, w) {
  11942. var t = this;
  11943. w = w || window;
  11944. w.alert(t._decode(t.editor.getLang(tx, tx)));
  11945. if (cb)
  11946. cb.call(s || t);
  11947. },
  11948. resizeBy : function(dw, dh, win) {
  11949. win.resizeBy(dw, dh);
  11950. },
  11951. // Internal functions
  11952. _decode : function(s) {
  11953. return tinymce.DOM.decode(s).replace(/\\n/g, '\n');
  11954. }
  11955. });
  11956. }(tinymce));
  11957. (function(tinymce) {
  11958. tinymce.Formatter = function(ed) {
  11959. var formats = {},
  11960. each = tinymce.each,
  11961. dom = ed.dom,
  11962. selection = ed.selection,
  11963. TreeWalker = tinymce.dom.TreeWalker,
  11964. rangeUtils = new tinymce.dom.RangeUtils(dom),
  11965. isValid = ed.schema.isValidChild,
  11966. isArray = tinymce.isArray,
  11967. isBlock = dom.isBlock,
  11968. forcedRootBlock = ed.settings.forced_root_block,
  11969. nodeIndex = dom.nodeIndex,
  11970. INVISIBLE_CHAR = '\uFEFF',
  11971. MCE_ATTR_RE = /^(src|href|style)$/,
  11972. FALSE = false,
  11973. TRUE = true,
  11974. formatChangeData,
  11975. undef,
  11976. getContentEditable = dom.getContentEditable;
  11977. function isTextBlock(name) {
  11978. return !!ed.schema.getTextBlocks()[name.toLowerCase()];
  11979. }
  11980. function getParents(node, selector) {
  11981. return dom.getParents(node, selector, dom.getRoot());
  11982. };
  11983. function isCaretNode(node) {
  11984. return node.nodeType === 1 && node.id === '_mce_caret';
  11985. };
  11986. function defaultFormats() {
  11987. register({
  11988. alignleft : [
  11989. {selector : 'figure,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}, defaultBlock: 'div'},
  11990. {selector : 'img,table', collapsed : false, styles : {'float' : 'left'}}
  11991. ],
  11992. aligncenter : [
  11993. {selector : 'figure,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}, defaultBlock: 'div'},
  11994. {selector : 'img', collapsed : false, styles : {display : 'block', marginLeft : 'auto', marginRight : 'auto'}},
  11995. {selector : 'table', collapsed : false, styles : {marginLeft : 'auto', marginRight : 'auto'}}
  11996. ],
  11997. alignright : [
  11998. {selector : 'figure,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}, defaultBlock: 'div'},
  11999. {selector : 'img,table', collapsed : false, styles : {'float' : 'right'}}
  12000. ],
  12001. alignfull : [
  12002. {selector : 'figure,p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'justify'}, defaultBlock: 'div'}
  12003. ],
  12004. bold : [
  12005. {inline : 'strong', remove : 'all'},
  12006. {inline : 'span', styles : {fontWeight : 'bold'}},
  12007. {inline : 'b', remove : 'all'}
  12008. ],
  12009. italic : [
  12010. {inline : 'em', remove : 'all'},
  12011. {inline : 'span', styles : {fontStyle : 'italic'}},
  12012. {inline : 'i', remove : 'all'}
  12013. ],
  12014. underline : [
  12015. {inline : 'span', styles : {textDecoration : 'underline'}, exact : true},
  12016. {inline : 'u', remove : 'all'}
  12017. ],
  12018. strikethrough : [
  12019. {inline : 'span', styles : {textDecoration : 'line-through'}, exact : true},
  12020. {inline : 'strike', remove : 'all'}
  12021. ],
  12022. forecolor : {inline : 'span', styles : {color : '%value'}, wrap_links : false},
  12023. hilitecolor : {inline : 'span', styles : {backgroundColor : '%value'}, wrap_links : false},
  12024. fontname : {inline : 'span', styles : {fontFamily : '%value'}},
  12025. fontsize : {inline : 'span', styles : {fontSize : '%value'}},
  12026. fontsize_class : {inline : 'span', attributes : {'class' : '%value'}},
  12027. blockquote : {block : 'blockquote', wrapper : 1, remove : 'all'},
  12028. subscript : {inline : 'sub'},
  12029. superscript : {inline : 'sup'},
  12030. link : {inline : 'a', selector : 'a', remove : 'all', split : true, deep : true,
  12031. onmatch : function(node) {
  12032. return true;
  12033. },
  12034. onformat : function(elm, fmt, vars) {
  12035. each(vars, function(value, key) {
  12036. dom.setAttrib(elm, key, value);
  12037. });
  12038. }
  12039. },
  12040. removeformat : [
  12041. {selector : 'b,strong,em,i,font,u,strike', remove : 'all', split : true, expand : false, block_expand : true, deep : true},
  12042. {selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true},
  12043. {selector : '*', attributes : ['style', 'class'], split : false, expand : false, deep : true}
  12044. ]
  12045. });
  12046. // Register default block formats
  12047. each('p h1 h2 h3 h4 h5 h6 div address pre div code dt dd samp'.split(/\s/), function(name) {
  12048. register(name, {block : name, remove : 'all'});
  12049. });
  12050. // Register user defined formats
  12051. register(ed.settings.formats);
  12052. };
  12053. function addKeyboardShortcuts() {
  12054. // Add some inline shortcuts
  12055. ed.addShortcut('ctrl+b', 'bold_desc', 'Bold');
  12056. ed.addShortcut('ctrl+i', 'italic_desc', 'Italic');
  12057. ed.addShortcut('ctrl+u', 'underline_desc', 'Underline');
  12058. // BlockFormat shortcuts keys
  12059. for (var i = 1; i <= 6; i++) {
  12060. ed.addShortcut('ctrl+' + i, '', ['FormatBlock', false, 'h' + i]);
  12061. }
  12062. ed.addShortcut('ctrl+7', '', ['FormatBlock', false, 'p']);
  12063. ed.addShortcut('ctrl+8', '', ['FormatBlock', false, 'div']);
  12064. ed.addShortcut('ctrl+9', '', ['FormatBlock', false, 'address']);
  12065. };
  12066. // Public functions
  12067. function get(name) {
  12068. return name ? formats[name] : formats;
  12069. };
  12070. function register(name, format) {
  12071. if (name) {
  12072. if (typeof(name) !== 'string') {
  12073. each(name, function(format, name) {
  12074. register(name, format);
  12075. });
  12076. } else {
  12077. // Force format into array and add it to internal collection
  12078. format = format.length ? format : [format];
  12079. each(format, function(format) {
  12080. // Set deep to false by default on selector formats this to avoid removing
  12081. // alignment on images inside paragraphs when alignment is changed on paragraphs
  12082. if (format.deep === undef)
  12083. format.deep = !format.selector;
  12084. // Default to true
  12085. if (format.split === undef)
  12086. format.split = !format.selector || format.inline;
  12087. // Default to true
  12088. if (format.remove === undef && format.selector && !format.inline)
  12089. format.remove = 'none';
  12090. // Mark format as a mixed format inline + block level
  12091. if (format.selector && format.inline) {
  12092. format.mixed = true;
  12093. format.block_expand = true;
  12094. }
  12095. // Split classes if needed
  12096. if (typeof(format.classes) === 'string')
  12097. format.classes = format.classes.split(/\s+/);
  12098. });
  12099. formats[name] = format;
  12100. }
  12101. }
  12102. };
  12103. var getTextDecoration = function(node) {
  12104. var decoration;
  12105. ed.dom.getParent(node, function(n) {
  12106. decoration = ed.dom.getStyle(n, 'text-decoration');
  12107. return decoration && decoration !== 'none';
  12108. });
  12109. return decoration;
  12110. };
  12111. var processUnderlineAndColor = function(node) {
  12112. var textDecoration;
  12113. if (node.nodeType === 1 && node.parentNode && node.parentNode.nodeType === 1) {
  12114. textDecoration = getTextDecoration(node.parentNode);
  12115. if (ed.dom.getStyle(node, 'color') && textDecoration) {
  12116. ed.dom.setStyle(node, 'text-decoration', textDecoration);
  12117. } else if (ed.dom.getStyle(node, 'textdecoration') === textDecoration) {
  12118. ed.dom.setStyle(node, 'text-decoration', null);
  12119. }
  12120. }
  12121. };
  12122. function apply(name, vars, node) {
  12123. var formatList = get(name), format = formatList[0], bookmark, rng, i, isCollapsed = selection.isCollapsed();
  12124. function setElementFormat(elm, fmt) {
  12125. fmt = fmt || format;
  12126. if (elm) {
  12127. if (fmt.onformat) {
  12128. fmt.onformat(elm, fmt, vars, node);
  12129. }
  12130. each(fmt.styles, function(value, name) {
  12131. dom.setStyle(elm, name, replaceVars(value, vars));
  12132. });
  12133. each(fmt.attributes, function(value, name) {
  12134. dom.setAttrib(elm, name, replaceVars(value, vars));
  12135. });
  12136. each(fmt.classes, function(value) {
  12137. value = replaceVars(value, vars);
  12138. if (!dom.hasClass(elm, value))
  12139. dom.addClass(elm, value);
  12140. });
  12141. }
  12142. };
  12143. function adjustSelectionToVisibleSelection() {
  12144. function findSelectionEnd(start, end) {
  12145. var walker = new TreeWalker(end);
  12146. for (node = walker.current(); node; node = walker.prev()) {
  12147. if (node.childNodes.length > 1 || node == start || node.tagName == 'BR') {
  12148. return node;
  12149. }
  12150. }
  12151. };
  12152. // Adjust selection so that a end container with a end offset of zero is not included in the selection
  12153. // as this isn't visible to the user.
  12154. var rng = ed.selection.getRng();
  12155. var start = rng.startContainer;
  12156. var end = rng.endContainer;
  12157. if (start != end && rng.endOffset === 0) {
  12158. var newEnd = findSelectionEnd(start, end);
  12159. var endOffset = newEnd.nodeType == 3 ? newEnd.length : newEnd.childNodes.length;
  12160. rng.setEnd(newEnd, endOffset);
  12161. }
  12162. return rng;
  12163. }
  12164. function applyStyleToList(node, bookmark, wrapElm, newWrappers, process){
  12165. var nodes = [], listIndex = -1, list, startIndex = -1, endIndex = -1, currentWrapElm;
  12166. // find the index of the first child list.
  12167. each(node.childNodes, function(n, index) {
  12168. if (n.nodeName === "UL" || n.nodeName === "OL") {
  12169. listIndex = index;
  12170. list = n;
  12171. return false;
  12172. }
  12173. });
  12174. // get the index of the bookmarks
  12175. each(node.childNodes, function(n, index) {
  12176. if (n.nodeName === "SPAN" && dom.getAttrib(n, "data-mce-type") == "bookmark") {
  12177. if (n.id == bookmark.id + "_start") {
  12178. startIndex = index;
  12179. } else if (n.id == bookmark.id + "_end") {
  12180. endIndex = index;
  12181. }
  12182. }
  12183. });
  12184. // if the selection spans across an embedded list, or there isn't an embedded list - handle processing normally
  12185. if (listIndex <= 0 || (startIndex < listIndex && endIndex > listIndex)) {
  12186. each(tinymce.grep(node.childNodes), process);
  12187. return 0;
  12188. } else {
  12189. currentWrapElm = dom.clone(wrapElm, FALSE);
  12190. // create a list of the nodes on the same side of the list as the selection
  12191. each(tinymce.grep(node.childNodes), function(n, index) {
  12192. if ((startIndex < listIndex && index < listIndex) || (startIndex > listIndex && index > listIndex)) {
  12193. nodes.push(n);
  12194. n.parentNode.removeChild(n);
  12195. }
  12196. });
  12197. // insert the wrapping element either before or after the list.
  12198. if (startIndex < listIndex) {
  12199. node.insertBefore(currentWrapElm, list);
  12200. } else if (startIndex > listIndex) {
  12201. node.insertBefore(currentWrapElm, list.nextSibling);
  12202. }
  12203. // add the new nodes to the list.
  12204. newWrappers.push(currentWrapElm);
  12205. each(nodes, function(node) {
  12206. currentWrapElm.appendChild(node);
  12207. });
  12208. return currentWrapElm;
  12209. }
  12210. };
  12211. function applyRngStyle(rng, bookmark, node_specific) {
  12212. var newWrappers = [], wrapName, wrapElm, contentEditable = true;
  12213. // Setup wrapper element
  12214. wrapName = format.inline || format.block;
  12215. wrapElm = dom.create(wrapName);
  12216. setElementFormat(wrapElm);
  12217. rangeUtils.walk(rng, function(nodes) {
  12218. var currentWrapElm;
  12219. function process(node) {
  12220. var nodeName, parentName, found, hasContentEditableState, lastContentEditable;
  12221. lastContentEditable = contentEditable;
  12222. nodeName = node.nodeName.toLowerCase();
  12223. parentName = node.parentNode.nodeName.toLowerCase();
  12224. // Node has a contentEditable value
  12225. if (node.nodeType === 1 && getContentEditable(node)) {
  12226. lastContentEditable = contentEditable;
  12227. contentEditable = getContentEditable(node) === "true";
  12228. hasContentEditableState = true; // We don't want to wrap the container only it's children
  12229. }
  12230. // Stop wrapping on br elements
  12231. if (isEq(nodeName, 'br')) {
  12232. currentWrapElm = 0;
  12233. // Remove any br elements when we wrap things
  12234. if (format.block)
  12235. dom.remove(node);
  12236. return;
  12237. }
  12238. // If node is wrapper type
  12239. if (format.wrapper && matchNode(node, name, vars)) {
  12240. currentWrapElm = 0;
  12241. return;
  12242. }
  12243. // Can we rename the block
  12244. if (contentEditable && !hasContentEditableState && format.block && !format.wrapper && isTextBlock(nodeName)) {
  12245. node = dom.rename(node, wrapName);
  12246. setElementFormat(node);
  12247. newWrappers.push(node);
  12248. currentWrapElm = 0;
  12249. return;
  12250. }
  12251. // Handle selector patterns
  12252. if (format.selector) {
  12253. // Look for matching formats
  12254. each(formatList, function(format) {
  12255. // Check collapsed state if it exists
  12256. if ('collapsed' in format && format.collapsed !== isCollapsed) {
  12257. return;
  12258. }
  12259. if (dom.is(node, format.selector) && !isCaretNode(node)) {
  12260. setElementFormat(node, format);
  12261. found = true;
  12262. }
  12263. });
  12264. // Continue processing if a selector match wasn't found and a inline element is defined
  12265. if (!format.inline || found) {
  12266. currentWrapElm = 0;
  12267. return;
  12268. }
  12269. }
  12270. // Is it valid to wrap this item
  12271. if (contentEditable && !hasContentEditableState && isValid(wrapName, nodeName) && isValid(parentName, wrapName) &&
  12272. !(!node_specific && node.nodeType === 3 && node.nodeValue.length === 1 && node.nodeValue.charCodeAt(0) === 65279) && !isCaretNode(node)) {
  12273. // Start wrapping
  12274. if (!currentWrapElm) {
  12275. // Wrap the node
  12276. currentWrapElm = dom.clone(wrapElm, FALSE);
  12277. node.parentNode.insertBefore(currentWrapElm, node);
  12278. newWrappers.push(currentWrapElm);
  12279. }
  12280. currentWrapElm.appendChild(node);
  12281. } else if (nodeName == 'li' && bookmark) {
  12282. // Start wrapping - if we are in a list node and have a bookmark, then we will always begin by wrapping in a new element.
  12283. currentWrapElm = applyStyleToList(node, bookmark, wrapElm, newWrappers, process);
  12284. } else {
  12285. // Start a new wrapper for possible children
  12286. currentWrapElm = 0;
  12287. each(tinymce.grep(node.childNodes), process);
  12288. if (hasContentEditableState) {
  12289. contentEditable = lastContentEditable; // Restore last contentEditable state from stack
  12290. }
  12291. // End the last wrapper
  12292. currentWrapElm = 0;
  12293. }
  12294. };
  12295. // Process siblings from range
  12296. each(nodes, process);
  12297. });
  12298. // Wrap links inside as well, for example color inside a link when the wrapper is around the link
  12299. if (format.wrap_links === false) {
  12300. each(newWrappers, function(node) {
  12301. function process(node) {
  12302. var i, currentWrapElm, children;
  12303. if (node.nodeName === 'A') {
  12304. currentWrapElm = dom.clone(wrapElm, FALSE);
  12305. newWrappers.push(currentWrapElm);
  12306. children = tinymce.grep(node.childNodes);
  12307. for (i = 0; i < children.length; i++)
  12308. currentWrapElm.appendChild(children[i]);
  12309. node.appendChild(currentWrapElm);
  12310. }
  12311. each(tinymce.grep(node.childNodes), process);
  12312. };
  12313. process(node);
  12314. });
  12315. }
  12316. // Cleanup
  12317. each(newWrappers, function(node) {
  12318. var childCount;
  12319. function getChildCount(node) {
  12320. var count = 0;
  12321. each(node.childNodes, function(node) {
  12322. if (!isWhiteSpaceNode(node) && !isBookmarkNode(node))
  12323. count++;
  12324. });
  12325. return count;
  12326. };
  12327. function mergeStyles(node) {
  12328. var child, clone;
  12329. each(node.childNodes, function(node) {
  12330. if (node.nodeType == 1 && !isBookmarkNode(node) && !isCaretNode(node)) {
  12331. child = node;
  12332. return FALSE; // break loop
  12333. }
  12334. });
  12335. // If child was found and of the same type as the current node
  12336. if (child && matchName(child, format)) {
  12337. clone = dom.clone(child, FALSE);
  12338. setElementFormat(clone);
  12339. dom.replace(clone, node, TRUE);
  12340. dom.remove(child, 1);
  12341. }
  12342. return clone || node;
  12343. };
  12344. childCount = getChildCount(node);
  12345. // Remove empty nodes but only if there is multiple wrappers and they are not block
  12346. // elements so never remove single <h1></h1> since that would remove the currrent empty block element where the caret is at
  12347. if ((newWrappers.length > 1 || !isBlock(node)) && childCount === 0) {
  12348. dom.remove(node, 1);
  12349. return;
  12350. }
  12351. if (format.inline || format.wrapper) {
  12352. // Merges the current node with it's children of similar type to reduce the number of elements
  12353. if (!format.exact && childCount === 1)
  12354. node = mergeStyles(node);
  12355. // Remove/merge children
  12356. each(formatList, function(format) {
  12357. // Merge all children of similar type will move styles from child to parent
  12358. // this: <span style="color:red"><b><span style="color:red; font-size:10px">text</span></b></span>
  12359. // will become: <span style="color:red"><b><span style="font-size:10px">text</span></b></span>
  12360. each(dom.select(format.inline, node), function(child) {
  12361. var parent;
  12362. // When wrap_links is set to false we don't want
  12363. // to remove the format on children within links
  12364. if (format.wrap_links === false) {
  12365. parent = child.parentNode;
  12366. do {
  12367. if (parent.nodeName === 'A')
  12368. return;
  12369. } while (parent = parent.parentNode);
  12370. }
  12371. removeFormat(format, vars, child, format.exact ? child : null);
  12372. });
  12373. });
  12374. // Remove child if direct parent is of same type
  12375. if (matchNode(node.parentNode, name, vars)) {
  12376. dom.remove(node, 1);
  12377. node = 0;
  12378. return TRUE;
  12379. }
  12380. // Look for parent with similar style format
  12381. if (format.merge_with_parents) {
  12382. dom.getParent(node.parentNode, function(parent) {
  12383. if (matchNode(parent, name, vars)) {
  12384. dom.remove(node, 1);
  12385. node = 0;
  12386. return TRUE;
  12387. }
  12388. });
  12389. }
  12390. // Merge next and previous siblings if they are similar <b>text</b><b>text</b> becomes <b>texttext</b>
  12391. if (node && format.merge_siblings !== false) {
  12392. node = mergeSiblings(getNonWhiteSpaceSibling(node), node);
  12393. node = mergeSiblings(node, getNonWhiteSpaceSibling(node, TRUE));
  12394. }
  12395. }
  12396. });
  12397. };
  12398. if (format) {
  12399. if (node) {
  12400. if (node.nodeType) {
  12401. rng = dom.createRng();
  12402. rng.setStartBefore(node);
  12403. rng.setEndAfter(node);
  12404. applyRngStyle(expandRng(rng, formatList), null, true);
  12405. } else {
  12406. applyRngStyle(node, null, true);
  12407. }
  12408. } else {
  12409. if (!isCollapsed || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  12410. // Obtain selection node before selection is unselected by applyRngStyle()
  12411. var curSelNode = ed.selection.getNode();
  12412. // If the formats have a default block and we can't find a parent block then start wrapping it with a DIV this is for forced_root_blocks: false
  12413. // It's kind of a hack but people should be using the default block type P since all desktop editors work that way
  12414. if (!forcedRootBlock && formatList[0].defaultBlock && !dom.getParent(curSelNode, dom.isBlock)) {
  12415. apply(formatList[0].defaultBlock);
  12416. }
  12417. // Apply formatting to selection
  12418. ed.selection.setRng(adjustSelectionToVisibleSelection());
  12419. bookmark = selection.getBookmark();
  12420. applyRngStyle(expandRng(selection.getRng(TRUE), formatList), bookmark);
  12421. // Colored nodes should be underlined so that the color of the underline matches the text color.
  12422. if (format.styles && (format.styles.color || format.styles.textDecoration)) {
  12423. tinymce.walk(curSelNode, processUnderlineAndColor, 'childNodes');
  12424. processUnderlineAndColor(curSelNode);
  12425. }
  12426. selection.moveToBookmark(bookmark);
  12427. moveStart(selection.getRng(TRUE));
  12428. ed.nodeChanged();
  12429. } else
  12430. performCaretAction('apply', name, vars);
  12431. }
  12432. }
  12433. };
  12434. function remove(name, vars, node) {
  12435. var formatList = get(name), format = formatList[0], bookmark, i, rng, contentEditable = true;
  12436. // Merges the styles for each node
  12437. function process(node) {
  12438. var children, i, l, localContentEditable, lastContentEditable, hasContentEditableState;
  12439. // Skip on text nodes as they have neither format to remove nor children
  12440. if (node.nodeType === 3) {
  12441. return;
  12442. }
  12443. // Node has a contentEditable value
  12444. if (node.nodeType === 1 && getContentEditable(node)) {
  12445. lastContentEditable = contentEditable;
  12446. contentEditable = getContentEditable(node) === "true";
  12447. hasContentEditableState = true; // We don't want to wrap the container only it's children
  12448. }
  12449. // Grab the children first since the nodelist might be changed
  12450. children = tinymce.grep(node.childNodes);
  12451. // Process current node
  12452. if (contentEditable && !hasContentEditableState) {
  12453. for (i = 0, l = formatList.length; i < l; i++) {
  12454. if (removeFormat(formatList[i], vars, node, node))
  12455. break;
  12456. }
  12457. }
  12458. // Process the children
  12459. if (format.deep) {
  12460. if (children.length) {
  12461. for (i = 0, l = children.length; i < l; i++)
  12462. process(children[i]);
  12463. if (hasContentEditableState) {
  12464. contentEditable = lastContentEditable; // Restore last contentEditable state from stack
  12465. }
  12466. }
  12467. }
  12468. };
  12469. function findFormatRoot(container) {
  12470. var formatRoot;
  12471. // Find format root
  12472. each(getParents(container.parentNode).reverse(), function(parent) {
  12473. var format;
  12474. // Find format root element
  12475. if (!formatRoot && parent.id != '_start' && parent.id != '_end') {
  12476. // Is the node matching the format we are looking for
  12477. format = matchNode(parent, name, vars);
  12478. if (format && format.split !== false)
  12479. formatRoot = parent;
  12480. }
  12481. });
  12482. return formatRoot;
  12483. };
  12484. function wrapAndSplit(format_root, container, target, split) {
  12485. var parent, clone, lastClone, firstClone, i, formatRootParent;
  12486. // Format root found then clone formats and split it
  12487. if (format_root) {
  12488. formatRootParent = format_root.parentNode;
  12489. for (parent = container.parentNode; parent && parent != formatRootParent; parent = parent.parentNode) {
  12490. clone = dom.clone(parent, FALSE);
  12491. for (i = 0; i < formatList.length; i++) {
  12492. if (removeFormat(formatList[i], vars, clone, clone)) {
  12493. clone = 0;
  12494. break;
  12495. }
  12496. }
  12497. // Build wrapper node
  12498. if (clone) {
  12499. if (lastClone)
  12500. clone.appendChild(lastClone);
  12501. if (!firstClone)
  12502. firstClone = clone;
  12503. lastClone = clone;
  12504. }
  12505. }
  12506. // Never split block elements if the format is mixed
  12507. if (split && (!format.mixed || !isBlock(format_root)))
  12508. container = dom.split(format_root, container);
  12509. // Wrap container in cloned formats
  12510. if (lastClone) {
  12511. target.parentNode.insertBefore(lastClone, target);
  12512. firstClone.appendChild(target);
  12513. }
  12514. }
  12515. return container;
  12516. };
  12517. function splitToFormatRoot(container) {
  12518. return wrapAndSplit(findFormatRoot(container), container, container, true);
  12519. };
  12520. function unwrap(start) {
  12521. var node = dom.get(start ? '_start' : '_end'),
  12522. out = node[start ? 'firstChild' : 'lastChild'];
  12523. // If the end is placed within the start the result will be removed
  12524. // So this checks if the out node is a bookmark node if it is it
  12525. // checks for another more suitable node
  12526. if (isBookmarkNode(out))
  12527. out = out[start ? 'firstChild' : 'lastChild'];
  12528. dom.remove(node, true);
  12529. return out;
  12530. };
  12531. function removeRngStyle(rng) {
  12532. var startContainer, endContainer, node;
  12533. rng = expandRng(rng, formatList, TRUE);
  12534. if (format.split) {
  12535. startContainer = getContainer(rng, TRUE);
  12536. endContainer = getContainer(rng);
  12537. if (startContainer != endContainer) {
  12538. // WebKit will render the table incorrectly if we wrap a TD in a SPAN so lets see if the can use the first child instead
  12539. // This will happen if you tripple click a table cell and use remove formatting
  12540. if (/^(TR|TD)$/.test(startContainer.nodeName) && startContainer.firstChild) {
  12541. startContainer = (startContainer.nodeName == "TD" ? startContainer.firstChild : startContainer.firstChild.firstChild) || startContainer;
  12542. }
  12543. // Wrap start/end nodes in span element since these might be cloned/moved
  12544. startContainer = wrap(startContainer, 'span', {id : '_start', 'data-mce-type' : 'bookmark'});
  12545. endContainer = wrap(endContainer, 'span', {id : '_end', 'data-mce-type' : 'bookmark'});
  12546. // Split start/end
  12547. splitToFormatRoot(startContainer);
  12548. splitToFormatRoot(endContainer);
  12549. // Unwrap start/end to get real elements again
  12550. startContainer = unwrap(TRUE);
  12551. endContainer = unwrap();
  12552. } else
  12553. startContainer = endContainer = splitToFormatRoot(startContainer);
  12554. // Update range positions since they might have changed after the split operations
  12555. rng.startContainer = startContainer.parentNode;
  12556. rng.startOffset = nodeIndex(startContainer);
  12557. rng.endContainer = endContainer.parentNode;
  12558. rng.endOffset = nodeIndex(endContainer) + 1;
  12559. }
  12560. // Remove items between start/end
  12561. rangeUtils.walk(rng, function(nodes) {
  12562. each(nodes, function(node) {
  12563. process(node);
  12564. // Remove parent span if it only contains text-decoration: underline, yet a parent node is also underlined.
  12565. if (node.nodeType === 1 && ed.dom.getStyle(node, 'text-decoration') === 'underline' && node.parentNode && getTextDecoration(node.parentNode) === 'underline') {
  12566. removeFormat({'deep': false, 'exact': true, 'inline': 'span', 'styles': {'textDecoration' : 'underline'}}, null, node);
  12567. }
  12568. });
  12569. });
  12570. };
  12571. // Handle node
  12572. if (node) {
  12573. if (node.nodeType) {
  12574. rng = dom.createRng();
  12575. rng.setStartBefore(node);
  12576. rng.setEndAfter(node);
  12577. removeRngStyle(rng);
  12578. } else {
  12579. removeRngStyle(node);
  12580. }
  12581. return;
  12582. }
  12583. if (!selection.isCollapsed() || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
  12584. bookmark = selection.getBookmark();
  12585. removeRngStyle(selection.getRng(TRUE));
  12586. selection.moveToBookmark(bookmark);
  12587. // 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
  12588. if (format.inline && match(name, vars, selection.getStart())) {
  12589. moveStart(selection.getRng(true));
  12590. }
  12591. ed.nodeChanged();
  12592. } else
  12593. performCaretAction('remove', name, vars);
  12594. };
  12595. function toggle(name, vars, node) {
  12596. var fmt = get(name);
  12597. if (match(name, vars, node) && (!('toggle' in fmt[0]) || fmt[0].toggle))
  12598. remove(name, vars, node);
  12599. else
  12600. apply(name, vars, node);
  12601. };
  12602. function matchNode(node, name, vars, similar) {
  12603. var formatList = get(name), format, i, classes;
  12604. function matchItems(node, format, item_name) {
  12605. var key, value, items = format[item_name], i;
  12606. // Custom match
  12607. if (format.onmatch) {
  12608. return format.onmatch(node, format, item_name);
  12609. }
  12610. // Check all items
  12611. if (items) {
  12612. // Non indexed object
  12613. if (items.length === undef) {
  12614. for (key in items) {
  12615. if (items.hasOwnProperty(key)) {
  12616. if (item_name === 'attributes')
  12617. value = dom.getAttrib(node, key);
  12618. else
  12619. value = getStyle(node, key);
  12620. if (similar && !value && !format.exact)
  12621. return;
  12622. if ((!similar || format.exact) && !isEq(value, replaceVars(items[key], vars)))
  12623. return;
  12624. }
  12625. }
  12626. } else {
  12627. // Only one match needed for indexed arrays
  12628. for (i = 0; i < items.length; i++) {
  12629. if (item_name === 'attributes' ? dom.getAttrib(node, items[i]) : getStyle(node, items[i]))
  12630. return format;
  12631. }
  12632. }
  12633. }
  12634. return format;
  12635. };
  12636. if (formatList && node) {
  12637. // Check each format in list
  12638. for (i = 0; i < formatList.length; i++) {
  12639. format = formatList[i];
  12640. // Name name, attributes, styles and classes
  12641. if (matchName(node, format) && matchItems(node, format, 'attributes') && matchItems(node, format, 'styles')) {
  12642. // Match classes
  12643. if (classes = format.classes) {
  12644. for (i = 0; i < classes.length; i++) {
  12645. if (!dom.hasClass(node, classes[i]))
  12646. return;
  12647. }
  12648. }
  12649. return format;
  12650. }
  12651. }
  12652. }
  12653. };
  12654. function match(name, vars, node) {
  12655. var startNode;
  12656. function matchParents(node) {
  12657. // Find first node with similar format settings
  12658. node = dom.getParent(node, function(node) {
  12659. return !!matchNode(node, name, vars, true);
  12660. });
  12661. // Do an exact check on the similar format element
  12662. return matchNode(node, name, vars);
  12663. };
  12664. // Check specified node
  12665. if (node)
  12666. return matchParents(node);
  12667. // Check selected node
  12668. node = selection.getNode();
  12669. if (matchParents(node))
  12670. return TRUE;
  12671. // Check start node if it's different
  12672. startNode = selection.getStart();
  12673. if (startNode != node) {
  12674. if (matchParents(startNode))
  12675. return TRUE;
  12676. }
  12677. return FALSE;
  12678. };
  12679. function matchAll(names, vars) {
  12680. var startElement, matchedFormatNames = [], checkedMap = {}, i, ni, name;
  12681. // Check start of selection for formats
  12682. startElement = selection.getStart();
  12683. dom.getParent(startElement, function(node) {
  12684. var i, name;
  12685. for (i = 0; i < names.length; i++) {
  12686. name = names[i];
  12687. if (!checkedMap[name] && matchNode(node, name, vars)) {
  12688. checkedMap[name] = true;
  12689. matchedFormatNames.push(name);
  12690. }
  12691. }
  12692. }, dom.getRoot());
  12693. return matchedFormatNames;
  12694. };
  12695. function canApply(name) {
  12696. var formatList = get(name), startNode, parents, i, x, selector;
  12697. if (formatList) {
  12698. startNode = selection.getStart();
  12699. parents = getParents(startNode);
  12700. for (x = formatList.length - 1; x >= 0; x--) {
  12701. selector = formatList[x].selector;
  12702. // Format is not selector based, then always return TRUE
  12703. if (!selector)
  12704. return TRUE;
  12705. for (i = parents.length - 1; i >= 0; i--) {
  12706. if (dom.is(parents[i], selector))
  12707. return TRUE;
  12708. }
  12709. }
  12710. }
  12711. return FALSE;
  12712. };
  12713. function formatChanged(formats, callback, similar) {
  12714. var currentFormats;
  12715. // Setup format node change logic
  12716. if (!formatChangeData) {
  12717. formatChangeData = {};
  12718. currentFormats = {};
  12719. ed.onNodeChange.addToTop(function(ed, cm, node) {
  12720. var parents = getParents(node), matchedFormats = {};
  12721. // Check for new formats
  12722. each(formatChangeData, function(callbacks, format) {
  12723. each(parents, function(node) {
  12724. if (matchNode(node, format, {}, callbacks.similar)) {
  12725. if (!currentFormats[format]) {
  12726. // Execute callbacks
  12727. each(callbacks, function(callback) {
  12728. callback(true, {node: node, format: format, parents: parents});
  12729. });
  12730. currentFormats[format] = callbacks;
  12731. }
  12732. matchedFormats[format] = callbacks;
  12733. return false;
  12734. }
  12735. });
  12736. });
  12737. // Check if current formats still match
  12738. each(currentFormats, function(callbacks, format) {
  12739. if (!matchedFormats[format]) {
  12740. delete currentFormats[format];
  12741. each(callbacks, function(callback) {
  12742. callback(false, {node: node, format: format, parents: parents});
  12743. });
  12744. }
  12745. });
  12746. });
  12747. }
  12748. // Add format listeners
  12749. each(formats.split(','), function(format) {
  12750. if (!formatChangeData[format]) {
  12751. formatChangeData[format] = [];
  12752. formatChangeData[format].similar = similar;
  12753. }
  12754. formatChangeData[format].push(callback);
  12755. });
  12756. return this;
  12757. };
  12758. // Expose to public
  12759. tinymce.extend(this, {
  12760. get : get,
  12761. register : register,
  12762. apply : apply,
  12763. remove : remove,
  12764. toggle : toggle,
  12765. match : match,
  12766. matchAll : matchAll,
  12767. matchNode : matchNode,
  12768. canApply : canApply,
  12769. formatChanged: formatChanged
  12770. });
  12771. // Initialize
  12772. defaultFormats();
  12773. addKeyboardShortcuts();
  12774. // Private functions
  12775. function matchName(node, format) {
  12776. // Check for inline match
  12777. if (isEq(node, format.inline))
  12778. return TRUE;
  12779. // Check for block match
  12780. if (isEq(node, format.block))
  12781. return TRUE;
  12782. // Check for selector match
  12783. if (format.selector)
  12784. return dom.is(node, format.selector);
  12785. };
  12786. function isEq(str1, str2) {
  12787. str1 = str1 || '';
  12788. str2 = str2 || '';
  12789. str1 = '' + (str1.nodeName || str1);
  12790. str2 = '' + (str2.nodeName || str2);
  12791. return str1.toLowerCase() == str2.toLowerCase();
  12792. };
  12793. function getStyle(node, name) {
  12794. var styleVal = dom.getStyle(node, name);
  12795. // Force the format to hex
  12796. if (name == 'color' || name == 'backgroundColor')
  12797. styleVal = dom.toHex(styleVal);
  12798. // Opera will return bold as 700
  12799. if (name == 'fontWeight' && styleVal == 700)
  12800. styleVal = 'bold';
  12801. return '' + styleVal;
  12802. };
  12803. function replaceVars(value, vars) {
  12804. if (typeof(value) != "string")
  12805. value = value(vars);
  12806. else if (vars) {
  12807. value = value.replace(/%(\w+)/g, function(str, name) {
  12808. return vars[name] || str;
  12809. });
  12810. }
  12811. return value;
  12812. };
  12813. function isWhiteSpaceNode(node) {
  12814. return node && node.nodeType === 3 && /^([\t \r\n]+|)$/.test(node.nodeValue);
  12815. };
  12816. function wrap(node, name, attrs) {
  12817. var wrapper = dom.create(name, attrs);
  12818. node.parentNode.insertBefore(wrapper, node);
  12819. wrapper.appendChild(node);
  12820. return wrapper;
  12821. };
  12822. function expandRng(rng, format, remove) {
  12823. var sibling, lastIdx, leaf, endPoint,
  12824. startContainer = rng.startContainer,
  12825. startOffset = rng.startOffset,
  12826. endContainer = rng.endContainer,
  12827. endOffset = rng.endOffset;
  12828. // This function walks up the tree if there is no siblings before/after the node
  12829. function findParentContainer(start) {
  12830. var container, parent, child, sibling, siblingName, root;
  12831. container = parent = start ? startContainer : endContainer;
  12832. siblingName = start ? 'previousSibling' : 'nextSibling';
  12833. root = dom.getRoot();
  12834. function isBogusBr(node) {
  12835. return node.nodeName == "BR" && node.getAttribute('data-mce-bogus') && !node.nextSibling;
  12836. };
  12837. // If it's a text node and the offset is inside the text
  12838. if (container.nodeType == 3 && !isWhiteSpaceNode(container)) {
  12839. if (start ? startOffset > 0 : endOffset < container.nodeValue.length) {
  12840. return container;
  12841. }
  12842. }
  12843. for (;;) {
  12844. // Stop expanding on block elements
  12845. if (!format[0].block_expand && isBlock(parent))
  12846. return parent;
  12847. // Walk left/right
  12848. for (sibling = parent[siblingName]; sibling; sibling = sibling[siblingName]) {
  12849. if (!isBookmarkNode(sibling) && !isWhiteSpaceNode(sibling) && !isBogusBr(sibling)) {
  12850. return parent;
  12851. }
  12852. }
  12853. // Check if we can move up are we at root level or body level
  12854. if (parent.parentNode == root) {
  12855. container = parent;
  12856. break;
  12857. }
  12858. parent = parent.parentNode;
  12859. }
  12860. return container;
  12861. };
  12862. // This function walks down the tree to find the leaf at the selection.
  12863. // The offset is also returned as if node initially a leaf, the offset may be in the middle of the text node.
  12864. function findLeaf(node, offset) {
  12865. if (offset === undef)
  12866. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  12867. while (node && node.hasChildNodes()) {
  12868. node = node.childNodes[offset];
  12869. if (node)
  12870. offset = node.nodeType === 3 ? node.length : node.childNodes.length;
  12871. }
  12872. return { node: node, offset: offset };
  12873. }
  12874. // If index based start position then resolve it
  12875. if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) {
  12876. lastIdx = startContainer.childNodes.length - 1;
  12877. startContainer = startContainer.childNodes[startOffset > lastIdx ? lastIdx : startOffset];
  12878. if (startContainer.nodeType == 3)
  12879. startOffset = 0;
  12880. }
  12881. // If index based end position then resolve it
  12882. if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) {
  12883. lastIdx = endContainer.childNodes.length - 1;
  12884. endContainer = endContainer.childNodes[endOffset > lastIdx ? lastIdx : endOffset - 1];
  12885. if (endContainer.nodeType == 3)
  12886. endOffset = endContainer.nodeValue.length;
  12887. }
  12888. // Expands the node to the closes contentEditable false element if it exists
  12889. function findParentContentEditable(node) {
  12890. var parent = node;
  12891. while (parent) {
  12892. if (parent.nodeType === 1 && getContentEditable(parent)) {
  12893. return getContentEditable(parent) === "false" ? parent : node;
  12894. }
  12895. parent = parent.parentNode;
  12896. }
  12897. return node;
  12898. };
  12899. function findWordEndPoint(container, offset, start) {
  12900. var walker, node, pos, lastTextNode;
  12901. function findSpace(node, offset) {
  12902. var pos, pos2, str = node.nodeValue;
  12903. if (typeof(offset) == "undefined") {
  12904. offset = start ? str.length : 0;
  12905. }
  12906. if (start) {
  12907. pos = str.lastIndexOf(' ', offset);
  12908. pos2 = str.lastIndexOf('\u00a0', offset);
  12909. pos = pos > pos2 ? pos : pos2;
  12910. // Include the space on remove to avoid tag soup
  12911. if (pos !== -1 && !remove) {
  12912. pos++;
  12913. }
  12914. } else {
  12915. pos = str.indexOf(' ', offset);
  12916. pos2 = str.indexOf('\u00a0', offset);
  12917. pos = pos !== -1 && (pos2 === -1 || pos < pos2) ? pos : pos2;
  12918. }
  12919. return pos;
  12920. };
  12921. if (container.nodeType === 3) {
  12922. pos = findSpace(container, offset);
  12923. if (pos !== -1) {
  12924. return {container : container, offset : pos};
  12925. }
  12926. lastTextNode = container;
  12927. }
  12928. // Walk the nodes inside the block
  12929. walker = new TreeWalker(container, dom.getParent(container, isBlock) || ed.getBody());
  12930. while (node = walker[start ? 'prev' : 'next']()) {
  12931. if (node.nodeType === 3) {
  12932. lastTextNode = node;
  12933. pos = findSpace(node);
  12934. if (pos !== -1) {
  12935. return {container : node, offset : pos};
  12936. }
  12937. } else if (isBlock(node)) {
  12938. break;
  12939. }
  12940. }
  12941. if (lastTextNode) {
  12942. if (start) {
  12943. offset = 0;
  12944. } else {
  12945. offset = lastTextNode.length;
  12946. }
  12947. return {container: lastTextNode, offset: offset};
  12948. }
  12949. };
  12950. function findSelectorEndPoint(container, sibling_name) {
  12951. var parents, i, y, curFormat;
  12952. if (container.nodeType == 3 && container.nodeValue.length === 0 && container[sibling_name])
  12953. container = container[sibling_name];
  12954. parents = getParents(container);
  12955. for (i = 0; i < parents.length; i++) {
  12956. for (y = 0; y < format.length; y++) {
  12957. curFormat = format[y];
  12958. // If collapsed state is set then skip formats that doesn't match that
  12959. if ("collapsed" in curFormat && curFormat.collapsed !== rng.collapsed)
  12960. continue;
  12961. if (dom.is(parents[i], curFormat.selector))
  12962. return parents[i];
  12963. }
  12964. }
  12965. return container;
  12966. };
  12967. function findBlockEndPoint(container, sibling_name, sibling_name2) {
  12968. var node;
  12969. // Expand to block of similar type
  12970. if (!format[0].wrapper)
  12971. node = dom.getParent(container, format[0].block);
  12972. // Expand to first wrappable block element or any block element
  12973. if (!node)
  12974. node = dom.getParent(container.nodeType == 3 ? container.parentNode : container, isTextBlock);
  12975. // Exclude inner lists from wrapping
  12976. if (node && format[0].wrapper)
  12977. node = getParents(node, 'ul,ol').reverse()[0] || node;
  12978. // Didn't find a block element look for first/last wrappable element
  12979. if (!node) {
  12980. node = container;
  12981. while (node[sibling_name] && !isBlock(node[sibling_name])) {
  12982. node = node[sibling_name];
  12983. // Break on BR but include it will be removed later on
  12984. // we can't remove it now since we need to check if it can be wrapped
  12985. if (isEq(node, 'br'))
  12986. break;
  12987. }
  12988. }
  12989. return node || container;
  12990. };
  12991. // Expand to closest contentEditable element
  12992. startContainer = findParentContentEditable(startContainer);
  12993. endContainer = findParentContentEditable(endContainer);
  12994. // Exclude bookmark nodes if possible
  12995. if (isBookmarkNode(startContainer.parentNode) || isBookmarkNode(startContainer)) {
  12996. startContainer = isBookmarkNode(startContainer) ? startContainer : startContainer.parentNode;
  12997. startContainer = startContainer.nextSibling || startContainer;
  12998. if (startContainer.nodeType == 3)
  12999. startOffset = 0;
  13000. }
  13001. if (isBookmarkNode(endContainer.parentNode) || isBookmarkNode(endContainer)) {
  13002. endContainer = isBookmarkNode(endContainer) ? endContainer : endContainer.parentNode;
  13003. endContainer = endContainer.previousSibling || endContainer;
  13004. if (endContainer.nodeType == 3)
  13005. endOffset = endContainer.length;
  13006. }
  13007. if (format[0].inline) {
  13008. if (rng.collapsed) {
  13009. // Expand left to closest word boundery
  13010. endPoint = findWordEndPoint(startContainer, startOffset, true);
  13011. if (endPoint) {
  13012. startContainer = endPoint.container;
  13013. startOffset = endPoint.offset;
  13014. }
  13015. // Expand right to closest word boundery
  13016. endPoint = findWordEndPoint(endContainer, endOffset);
  13017. if (endPoint) {
  13018. endContainer = endPoint.container;
  13019. endOffset = endPoint.offset;
  13020. }
  13021. }
  13022. // Avoid applying formatting to a trailing space.
  13023. leaf = findLeaf(endContainer, endOffset);
  13024. if (leaf.node) {
  13025. while (leaf.node && leaf.offset === 0 && leaf.node.previousSibling)
  13026. leaf = findLeaf(leaf.node.previousSibling);
  13027. if (leaf.node && leaf.offset > 0 && leaf.node.nodeType === 3 &&
  13028. leaf.node.nodeValue.charAt(leaf.offset - 1) === ' ') {
  13029. if (leaf.offset > 1) {
  13030. endContainer = leaf.node;
  13031. endContainer.splitText(leaf.offset - 1);
  13032. }
  13033. }
  13034. }
  13035. }
  13036. // Move start/end point up the tree if the leaves are sharp and if we are in different containers
  13037. // Example * becomes !: !<p><b><i>*text</i><i>text*</i></b></p>!
  13038. // This will reduce the number of wrapper elements that needs to be created
  13039. // Move start point up the tree
  13040. if (format[0].inline || format[0].block_expand) {
  13041. if (!format[0].inline || (startContainer.nodeType != 3 || startOffset === 0)) {
  13042. startContainer = findParentContainer(true);
  13043. }
  13044. if (!format[0].inline || (endContainer.nodeType != 3 || endOffset === endContainer.nodeValue.length)) {
  13045. endContainer = findParentContainer();
  13046. }
  13047. }
  13048. // Expand start/end container to matching selector
  13049. if (format[0].selector && format[0].expand !== FALSE && !format[0].inline) {
  13050. // Find new startContainer/endContainer if there is better one
  13051. startContainer = findSelectorEndPoint(startContainer, 'previousSibling');
  13052. endContainer = findSelectorEndPoint(endContainer, 'nextSibling');
  13053. }
  13054. // Expand start/end container to matching block element or text node
  13055. if (format[0].block || format[0].selector) {
  13056. // Find new startContainer/endContainer if there is better one
  13057. startContainer = findBlockEndPoint(startContainer, 'previousSibling');
  13058. endContainer = findBlockEndPoint(endContainer, 'nextSibling');
  13059. // Non block element then try to expand up the leaf
  13060. if (format[0].block) {
  13061. if (!isBlock(startContainer))
  13062. startContainer = findParentContainer(true);
  13063. if (!isBlock(endContainer))
  13064. endContainer = findParentContainer();
  13065. }
  13066. }
  13067. // Setup index for startContainer
  13068. if (startContainer.nodeType == 1) {
  13069. startOffset = nodeIndex(startContainer);
  13070. startContainer = startContainer.parentNode;
  13071. }
  13072. // Setup index for endContainer
  13073. if (endContainer.nodeType == 1) {
  13074. endOffset = nodeIndex(endContainer) + 1;
  13075. endContainer = endContainer.parentNode;
  13076. }
  13077. // Return new range like object
  13078. return {
  13079. startContainer : startContainer,
  13080. startOffset : startOffset,
  13081. endContainer : endContainer,
  13082. endOffset : endOffset
  13083. };
  13084. }
  13085. function removeFormat(format, vars, node, compare_node) {
  13086. var i, attrs, stylesModified;
  13087. // Check if node matches format
  13088. if (!matchName(node, format))
  13089. return FALSE;
  13090. // Should we compare with format attribs and styles
  13091. if (format.remove != 'all') {
  13092. // Remove styles
  13093. each(format.styles, function(value, name) {
  13094. value = replaceVars(value, vars);
  13095. // Indexed array
  13096. if (typeof(name) === 'number') {
  13097. name = value;
  13098. compare_node = 0;
  13099. }
  13100. if (!compare_node || isEq(getStyle(compare_node, name), value))
  13101. dom.setStyle(node, name, '');
  13102. stylesModified = 1;
  13103. });
  13104. // Remove style attribute if it's empty
  13105. if (stylesModified && dom.getAttrib(node, 'style') == '') {
  13106. node.removeAttribute('style');
  13107. node.removeAttribute('data-mce-style');
  13108. }
  13109. // Remove attributes
  13110. each(format.attributes, function(value, name) {
  13111. var valueOut;
  13112. value = replaceVars(value, vars);
  13113. // Indexed array
  13114. if (typeof(name) === 'number') {
  13115. name = value;
  13116. compare_node = 0;
  13117. }
  13118. if (!compare_node || isEq(dom.getAttrib(compare_node, name), value)) {
  13119. // Keep internal classes
  13120. if (name == 'class') {
  13121. value = dom.getAttrib(node, name);
  13122. if (value) {
  13123. // Build new class value where everything is removed except the internal prefixed classes
  13124. valueOut = '';
  13125. each(value.split(/\s+/), function(cls) {
  13126. if (/mce\w+/.test(cls))
  13127. valueOut += (valueOut ? ' ' : '') + cls;
  13128. });
  13129. // We got some internal classes left
  13130. if (valueOut) {
  13131. dom.setAttrib(node, name, valueOut);
  13132. return;
  13133. }
  13134. }
  13135. }
  13136. // IE6 has a bug where the attribute doesn't get removed correctly
  13137. if (name == "class")
  13138. node.removeAttribute('className');
  13139. // Remove mce prefixed attributes
  13140. if (MCE_ATTR_RE.test(name))
  13141. node.removeAttribute('data-mce-' + name);
  13142. node.removeAttribute(name);
  13143. }
  13144. });
  13145. // Remove classes
  13146. each(format.classes, function(value) {
  13147. value = replaceVars(value, vars);
  13148. if (!compare_node || dom.hasClass(compare_node, value))
  13149. dom.removeClass(node, value);
  13150. });
  13151. // Check for non internal attributes
  13152. attrs = dom.getAttribs(node);
  13153. for (i = 0; i < attrs.length; i++) {
  13154. if (attrs[i].nodeName.indexOf('_') !== 0)
  13155. return FALSE;
  13156. }
  13157. }
  13158. // Remove the inline child if it's empty for example <b> or <span>
  13159. if (format.remove != 'none') {
  13160. removeNode(node, format);
  13161. return TRUE;
  13162. }
  13163. };
  13164. function removeNode(node, format) {
  13165. var parentNode = node.parentNode, rootBlockElm;
  13166. function find(node, next, inc) {
  13167. node = getNonWhiteSpaceSibling(node, next, inc);
  13168. return !node || (node.nodeName == 'BR' || isBlock(node));
  13169. };
  13170. if (format.block) {
  13171. if (!forcedRootBlock) {
  13172. // Append BR elements if needed before we remove the block
  13173. if (isBlock(node) && !isBlock(parentNode)) {
  13174. if (!find(node, FALSE) && !find(node.firstChild, TRUE, 1))
  13175. node.insertBefore(dom.create('br'), node.firstChild);
  13176. if (!find(node, TRUE) && !find(node.lastChild, FALSE, 1))
  13177. node.appendChild(dom.create('br'));
  13178. }
  13179. } else {
  13180. // Wrap the block in a forcedRootBlock if we are at the root of document
  13181. if (parentNode == dom.getRoot()) {
  13182. if (!format.list_block || !isEq(node, format.list_block)) {
  13183. each(tinymce.grep(node.childNodes), function(node) {
  13184. if (isValid(forcedRootBlock, node.nodeName.toLowerCase())) {
  13185. if (!rootBlockElm)
  13186. rootBlockElm = wrap(node, forcedRootBlock);
  13187. else
  13188. rootBlockElm.appendChild(node);
  13189. } else
  13190. rootBlockElm = 0;
  13191. });
  13192. }
  13193. }
  13194. }
  13195. }
  13196. // Never remove nodes that isn't the specified inline element if a selector is specified too
  13197. if (format.selector && format.inline && !isEq(format.inline, node))
  13198. return;
  13199. dom.remove(node, 1);
  13200. };
  13201. function getNonWhiteSpaceSibling(node, next, inc) {
  13202. if (node) {
  13203. next = next ? 'nextSibling' : 'previousSibling';
  13204. for (node = inc ? node : node[next]; node; node = node[next]) {
  13205. if (node.nodeType == 1 || !isWhiteSpaceNode(node))
  13206. return node;
  13207. }
  13208. }
  13209. };
  13210. function isBookmarkNode(node) {
  13211. return node && node.nodeType == 1 && node.getAttribute('data-mce-type') == 'bookmark';
  13212. };
  13213. function mergeSiblings(prev, next) {
  13214. var marker, sibling, tmpSibling;
  13215. function compareElements(node1, node2) {
  13216. // Not the same name
  13217. if (node1.nodeName != node2.nodeName)
  13218. return FALSE;
  13219. function getAttribs(node) {
  13220. var attribs = {};
  13221. each(dom.getAttribs(node), function(attr) {
  13222. var name = attr.nodeName.toLowerCase();
  13223. // Don't compare internal attributes or style
  13224. if (name.indexOf('_') !== 0 && name !== 'style')
  13225. attribs[name] = dom.getAttrib(node, name);
  13226. });
  13227. return attribs;
  13228. };
  13229. function compareObjects(obj1, obj2) {
  13230. var value, name;
  13231. for (name in obj1) {
  13232. // Obj1 has item obj2 doesn't have
  13233. if (obj1.hasOwnProperty(name)) {
  13234. value = obj2[name];
  13235. // Obj2 doesn't have obj1 item
  13236. if (value === undef)
  13237. return FALSE;
  13238. // Obj2 item has a different value
  13239. if (obj1[name] != value)
  13240. return FALSE;
  13241. // Delete similar value
  13242. delete obj2[name];
  13243. }
  13244. }
  13245. // Check if obj 2 has something obj 1 doesn't have
  13246. for (name in obj2) {
  13247. // Obj2 has item obj1 doesn't have
  13248. if (obj2.hasOwnProperty(name))
  13249. return FALSE;
  13250. }
  13251. return TRUE;
  13252. };
  13253. // Attribs are not the same
  13254. if (!compareObjects(getAttribs(node1), getAttribs(node2)))
  13255. return FALSE;
  13256. // Styles are not the same
  13257. if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style'))))
  13258. return FALSE;
  13259. return TRUE;
  13260. };
  13261. function findElementSibling(node, sibling_name) {
  13262. for (sibling = node; sibling; sibling = sibling[sibling_name]) {
  13263. if (sibling.nodeType == 3 && sibling.nodeValue.length !== 0)
  13264. return node;
  13265. if (sibling.nodeType == 1 && !isBookmarkNode(sibling))
  13266. return sibling;
  13267. }
  13268. return node;
  13269. };
  13270. // Check if next/prev exists and that they are elements
  13271. if (prev && next) {
  13272. // If previous sibling is empty then jump over it
  13273. prev = findElementSibling(prev, 'previousSibling');
  13274. next = findElementSibling(next, 'nextSibling');
  13275. // Compare next and previous nodes
  13276. if (compareElements(prev, next)) {
  13277. // Append nodes between
  13278. for (sibling = prev.nextSibling; sibling && sibling != next;) {
  13279. tmpSibling = sibling;
  13280. sibling = sibling.nextSibling;
  13281. prev.appendChild(tmpSibling);
  13282. }
  13283. // Remove next node
  13284. dom.remove(next);
  13285. // Move children into prev node
  13286. each(tinymce.grep(next.childNodes), function(node) {
  13287. prev.appendChild(node);
  13288. });
  13289. return prev;
  13290. }
  13291. }
  13292. return next;
  13293. };
  13294. function isTextBlock(name) {
  13295. return /^(h[1-6]|p|div|pre|address|dl|dt|dd)$/.test(name);
  13296. };
  13297. function getContainer(rng, start) {
  13298. var container, offset, lastIdx, walker;
  13299. container = rng[start ? 'startContainer' : 'endContainer'];
  13300. offset = rng[start ? 'startOffset' : 'endOffset'];
  13301. if (container.nodeType == 1) {
  13302. lastIdx = container.childNodes.length - 1;
  13303. if (!start && offset)
  13304. offset--;
  13305. container = container.childNodes[offset > lastIdx ? lastIdx : offset];
  13306. }
  13307. // If start text node is excluded then walk to the next node
  13308. if (container.nodeType === 3 && start && offset >= container.nodeValue.length) {
  13309. container = new TreeWalker(container, ed.getBody()).next() || container;
  13310. }
  13311. // If end text node is excluded then walk to the previous node
  13312. if (container.nodeType === 3 && !start && offset === 0) {
  13313. container = new TreeWalker(container, ed.getBody()).prev() || container;
  13314. }
  13315. return container;
  13316. };
  13317. function performCaretAction(type, name, vars) {
  13318. var caretContainerId = '_mce_caret', debug = ed.settings.caret_debug;
  13319. // Creates a caret container bogus element
  13320. function createCaretContainer(fill) {
  13321. var caretContainer = dom.create('span', {id: caretContainerId, 'data-mce-bogus': true, style: debug ? 'color:red' : ''});
  13322. if (fill) {
  13323. caretContainer.appendChild(ed.getDoc().createTextNode(INVISIBLE_CHAR));
  13324. }
  13325. return caretContainer;
  13326. };
  13327. function isCaretContainerEmpty(node, nodes) {
  13328. while (node) {
  13329. if ((node.nodeType === 3 && node.nodeValue !== INVISIBLE_CHAR) || node.childNodes.length > 1) {
  13330. return false;
  13331. }
  13332. // Collect nodes
  13333. if (nodes && node.nodeType === 1) {
  13334. nodes.push(node);
  13335. }
  13336. node = node.firstChild;
  13337. }
  13338. return true;
  13339. };
  13340. // Returns any parent caret container element
  13341. function getParentCaretContainer(node) {
  13342. while (node) {
  13343. if (node.id === caretContainerId) {
  13344. return node;
  13345. }
  13346. node = node.parentNode;
  13347. }
  13348. };
  13349. // Finds the first text node in the specified node
  13350. function findFirstTextNode(node) {
  13351. var walker;
  13352. if (node) {
  13353. walker = new TreeWalker(node, node);
  13354. for (node = walker.current(); node; node = walker.next()) {
  13355. if (node.nodeType === 3) {
  13356. return node;
  13357. }
  13358. }
  13359. }
  13360. };
  13361. // Removes the caret container for the specified node or all on the current document
  13362. function removeCaretContainer(node, move_caret) {
  13363. var child, rng;
  13364. if (!node) {
  13365. node = getParentCaretContainer(selection.getStart());
  13366. if (!node) {
  13367. while (node = dom.get(caretContainerId)) {
  13368. removeCaretContainer(node, false);
  13369. }
  13370. }
  13371. } else {
  13372. rng = selection.getRng(true);
  13373. if (isCaretContainerEmpty(node)) {
  13374. if (move_caret !== false) {
  13375. rng.setStartBefore(node);
  13376. rng.setEndBefore(node);
  13377. }
  13378. dom.remove(node);
  13379. } else {
  13380. child = findFirstTextNode(node);
  13381. if (child.nodeValue.charAt(0) === INVISIBLE_CHAR) {
  13382. child = child.deleteData(0, 1);
  13383. }
  13384. dom.remove(node, 1);
  13385. }
  13386. selection.setRng(rng);
  13387. }
  13388. };
  13389. // Applies formatting to the caret postion
  13390. function applyCaretFormat() {
  13391. var rng, caretContainer, textNode, offset, bookmark, container, text;
  13392. rng = selection.getRng(true);
  13393. offset = rng.startOffset;
  13394. container = rng.startContainer;
  13395. text = container.nodeValue;
  13396. caretContainer = getParentCaretContainer(selection.getStart());
  13397. if (caretContainer) {
  13398. textNode = findFirstTextNode(caretContainer);
  13399. }
  13400. // Expand to word is caret is in the middle of a text node and the char before/after is a alpha numeric character
  13401. if (text && offset > 0 && offset < text.length && /\w/.test(text.charAt(offset)) && /\w/.test(text.charAt(offset - 1))) {
  13402. // Get bookmark of caret position
  13403. bookmark = selection.getBookmark();
  13404. // Collapse bookmark range (WebKit)
  13405. rng.collapse(true);
  13406. // Expand the range to the closest word and split it at those points
  13407. rng = expandRng(rng, get(name));
  13408. rng = rangeUtils.split(rng);
  13409. // Apply the format to the range
  13410. apply(name, vars, rng);
  13411. // Move selection back to caret position
  13412. selection.moveToBookmark(bookmark);
  13413. } else {
  13414. if (!caretContainer || textNode.nodeValue !== INVISIBLE_CHAR) {
  13415. caretContainer = createCaretContainer(true);
  13416. textNode = caretContainer.firstChild;
  13417. rng.insertNode(caretContainer);
  13418. offset = 1;
  13419. apply(name, vars, caretContainer);
  13420. } else {
  13421. apply(name, vars, caretContainer);
  13422. }
  13423. // Move selection to text node
  13424. selection.setCursorLocation(textNode, offset);
  13425. }
  13426. };
  13427. function removeCaretFormat() {
  13428. var rng = selection.getRng(true), container, offset, bookmark,
  13429. hasContentAfter, node, formatNode, parents = [], i, caretContainer;
  13430. container = rng.startContainer;
  13431. offset = rng.startOffset;
  13432. node = container;
  13433. if (container.nodeType == 3) {
  13434. if (offset != container.nodeValue.length || container.nodeValue === INVISIBLE_CHAR) {
  13435. hasContentAfter = true;
  13436. }
  13437. node = node.parentNode;
  13438. }
  13439. while (node) {
  13440. if (matchNode(node, name, vars)) {
  13441. formatNode = node;
  13442. break;
  13443. }
  13444. if (node.nextSibling) {
  13445. hasContentAfter = true;
  13446. }
  13447. parents.push(node);
  13448. node = node.parentNode;
  13449. }
  13450. // Node doesn't have the specified format
  13451. if (!formatNode) {
  13452. return;
  13453. }
  13454. // Is there contents after the caret then remove the format on the element
  13455. if (hasContentAfter) {
  13456. // Get bookmark of caret position
  13457. bookmark = selection.getBookmark();
  13458. // Collapse bookmark range (WebKit)
  13459. rng.collapse(true);
  13460. // Expand the range to the closest word and split it at those points
  13461. rng = expandRng(rng, get(name), true);
  13462. rng = rangeUtils.split(rng);
  13463. // Remove the format from the range
  13464. remove(name, vars, rng);
  13465. // Move selection back to caret position
  13466. selection.moveToBookmark(bookmark);
  13467. } else {
  13468. caretContainer = createCaretContainer();
  13469. node = caretContainer;
  13470. for (i = parents.length - 1; i >= 0; i--) {
  13471. node.appendChild(dom.clone(parents[i], false));
  13472. node = node.firstChild;
  13473. }
  13474. // Insert invisible character into inner most format element
  13475. node.appendChild(dom.doc.createTextNode(INVISIBLE_CHAR));
  13476. node = node.firstChild;
  13477. // Insert caret container after the formated node
  13478. dom.insertAfter(caretContainer, formatNode);
  13479. // Move selection to text node
  13480. selection.setCursorLocation(node, 1);
  13481. }
  13482. };
  13483. // Checks if the parent caret container node isn't empty if that is the case it
  13484. // will remove the bogus state on all children that isn't empty
  13485. function unmarkBogusCaretParents() {
  13486. var i, caretContainer, node;
  13487. caretContainer = getParentCaretContainer(selection.getStart());
  13488. if (caretContainer && !dom.isEmpty(caretContainer)) {
  13489. tinymce.walk(caretContainer, function(node) {
  13490. if (node.nodeType == 1 && node.id !== caretContainerId && !dom.isEmpty(node)) {
  13491. dom.setAttrib(node, 'data-mce-bogus', null);
  13492. }
  13493. }, 'childNodes');
  13494. }
  13495. };
  13496. // Only bind the caret events once
  13497. if (!self._hasCaretEvents) {
  13498. // Mark current caret container elements as bogus when getting the contents so we don't end up with empty elements
  13499. ed.onBeforeGetContent.addToTop(function() {
  13500. var nodes = [], i;
  13501. if (isCaretContainerEmpty(getParentCaretContainer(selection.getStart()), nodes)) {
  13502. // Mark children
  13503. i = nodes.length;
  13504. while (i--) {
  13505. dom.setAttrib(nodes[i], 'data-mce-bogus', '1');
  13506. }
  13507. }
  13508. });
  13509. // Remove caret container on mouse up and on key up
  13510. tinymce.each('onMouseUp onKeyUp'.split(' '), function(name) {
  13511. ed[name].addToTop(function() {
  13512. removeCaretContainer();
  13513. unmarkBogusCaretParents();
  13514. });
  13515. });
  13516. // Remove caret container on keydown and it's a backspace, enter or left/right arrow keys
  13517. ed.onKeyDown.addToTop(function(ed, e) {
  13518. var keyCode = e.keyCode;
  13519. if (keyCode == 8 || keyCode == 37 || keyCode == 39) {
  13520. removeCaretContainer(getParentCaretContainer(selection.getStart()));
  13521. }
  13522. unmarkBogusCaretParents();
  13523. });
  13524. // Remove bogus state if they got filled by contents using editor.selection.setContent
  13525. selection.onSetContent.add(unmarkBogusCaretParents);
  13526. self._hasCaretEvents = true;
  13527. }
  13528. // Do apply or remove caret format
  13529. if (type == "apply") {
  13530. applyCaretFormat();
  13531. } else {
  13532. removeCaretFormat();
  13533. }
  13534. };
  13535. function moveStart(rng) {
  13536. var container = rng.startContainer,
  13537. offset = rng.startOffset, isAtEndOfText,
  13538. walker, node, nodes, tmpNode;
  13539. // Convert text node into index if possible
  13540. if (container.nodeType == 3 && offset >= container.nodeValue.length) {
  13541. // Get the parent container location and walk from there
  13542. offset = nodeIndex(container);
  13543. container = container.parentNode;
  13544. isAtEndOfText = true;
  13545. }
  13546. // Move startContainer/startOffset in to a suitable node
  13547. if (container.nodeType == 1) {
  13548. nodes = container.childNodes;
  13549. container = nodes[Math.min(offset, nodes.length - 1)];
  13550. walker = new TreeWalker(container, dom.getParent(container, dom.isBlock));
  13551. // If offset is at end of the parent node walk to the next one
  13552. if (offset > nodes.length - 1 || isAtEndOfText)
  13553. walker.next();
  13554. for (node = walker.current(); node; node = walker.next()) {
  13555. if (node.nodeType == 3 && !isWhiteSpaceNode(node)) {
  13556. // IE has a "neat" feature where it moves the start node into the closest element
  13557. // we can avoid this by inserting an element before it and then remove it after we set the selection
  13558. tmpNode = dom.create('a', null, INVISIBLE_CHAR);
  13559. node.parentNode.insertBefore(tmpNode, node);
  13560. // Set selection and remove tmpNode
  13561. rng.setStart(node, 0);
  13562. selection.setRng(rng);
  13563. dom.remove(tmpNode);
  13564. return;
  13565. }
  13566. }
  13567. }
  13568. };
  13569. };
  13570. })(tinymce);
  13571. tinymce.onAddEditor.add(function(tinymce, ed) {
  13572. var filters, fontSizes, dom, settings = ed.settings;
  13573. function replaceWithSpan(node, styles) {
  13574. tinymce.each(styles, function(value, name) {
  13575. if (value)
  13576. dom.setStyle(node, name, value);
  13577. });
  13578. dom.rename(node, 'span');
  13579. };
  13580. function convert(editor, params) {
  13581. dom = editor.dom;
  13582. if (settings.convert_fonts_to_spans) {
  13583. tinymce.each(dom.select('font,u,strike', params.node), function(node) {
  13584. filters[node.nodeName.toLowerCase()](ed.dom, node);
  13585. });
  13586. }
  13587. };
  13588. if (settings.inline_styles) {
  13589. fontSizes = tinymce.explode(settings.font_size_legacy_values);
  13590. filters = {
  13591. font : function(dom, node) {
  13592. replaceWithSpan(node, {
  13593. backgroundColor : node.style.backgroundColor,
  13594. color : node.color,
  13595. fontFamily : node.face,
  13596. fontSize : fontSizes[parseInt(node.size, 10) - 1]
  13597. });
  13598. },
  13599. u : function(dom, node) {
  13600. replaceWithSpan(node, {
  13601. textDecoration : 'underline'
  13602. });
  13603. },
  13604. strike : function(dom, node) {
  13605. replaceWithSpan(node, {
  13606. textDecoration : 'line-through'
  13607. });
  13608. }
  13609. };
  13610. ed.onPreProcess.add(convert);
  13611. ed.onSetContent.add(convert);
  13612. ed.onInit.add(function() {
  13613. ed.selection.onSetContent.add(convert);
  13614. });
  13615. }
  13616. });
  13617. (function(tinymce) {
  13618. var TreeWalker = tinymce.dom.TreeWalker;
  13619. tinymce.EnterKey = function(editor) {
  13620. var dom = editor.dom, selection = editor.selection, settings = editor.settings, undoManager = editor.undoManager, nonEmptyElementsMap = editor.schema.getNonEmptyElements();
  13621. function handleEnterKey(evt) {
  13622. var rng = selection.getRng(true), tmpRng, editableRoot, container, offset, parentBlock, documentMode, shiftKey,
  13623. newBlock, fragment, containerBlock, parentBlockName, containerBlockName, newBlockName, isAfterLastNodeInContainer;
  13624. // Returns true if the block can be split into two blocks or not
  13625. function canSplitBlock(node) {
  13626. return node &&
  13627. dom.isBlock(node) &&
  13628. !/^(TD|TH|CAPTION|FORM)$/.test(node.nodeName) &&
  13629. !/^(fixed|absolute)/i.test(node.style.position) &&
  13630. dom.getContentEditable(node) !== "true";
  13631. };
  13632. // Renders empty block on IE
  13633. function renderBlockOnIE(block) {
  13634. var oldRng;
  13635. if (tinymce.isIE && dom.isBlock(block)) {
  13636. oldRng = selection.getRng();
  13637. block.appendChild(dom.create('span', null, '\u00a0'));
  13638. selection.select(block);
  13639. block.lastChild.outerHTML = '';
  13640. selection.setRng(oldRng);
  13641. }
  13642. };
  13643. // Remove the first empty inline element of the block so this: <p><b><em></em></b>x</p> becomes this: <p>x</p>
  13644. function trimInlineElementsOnLeftSideOfBlock(block) {
  13645. var node = block, firstChilds = [], i;
  13646. // Find inner most first child ex: <p><i><b>*</b></i></p>
  13647. while (node = node.firstChild) {
  13648. if (dom.isBlock(node)) {
  13649. return;
  13650. }
  13651. if (node.nodeType == 1 && !nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  13652. firstChilds.push(node);
  13653. }
  13654. }
  13655. i = firstChilds.length;
  13656. while (i--) {
  13657. node = firstChilds[i];
  13658. if (!node.hasChildNodes() || (node.firstChild == node.lastChild && node.firstChild.nodeValue === '')) {
  13659. dom.remove(node);
  13660. } else {
  13661. // Remove <a> </a> see #5381
  13662. if (node.nodeName == "A" && (node.innerText || node.textContent) === ' ') {
  13663. dom.remove(node);
  13664. }
  13665. }
  13666. }
  13667. };
  13668. // Moves the caret to a suitable position within the root for example in the first non pure whitespace text node or before an image
  13669. function moveToCaretPosition(root) {
  13670. var walker, node, rng, y, viewPort, lastNode = root, tempElm;
  13671. rng = dom.createRng();
  13672. if (root.hasChildNodes()) {
  13673. walker = new TreeWalker(root, root);
  13674. while (node = walker.current()) {
  13675. if (node.nodeType == 3) {
  13676. rng.setStart(node, 0);
  13677. rng.setEnd(node, 0);
  13678. break;
  13679. }
  13680. if (nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
  13681. rng.setStartBefore(node);
  13682. rng.setEndBefore(node);
  13683. break;
  13684. }
  13685. lastNode = node;
  13686. node = walker.next();
  13687. }
  13688. if (!node) {
  13689. rng.setStart(lastNode, 0);
  13690. rng.setEnd(lastNode, 0);
  13691. }
  13692. } else {
  13693. if (root.nodeName == 'BR') {
  13694. if (root.nextSibling && dom.isBlock(root.nextSibling)) {
  13695. // Trick on older IE versions to render the caret before the BR between two lists
  13696. if (!documentMode || documentMode < 9) {
  13697. tempElm = dom.create('br');
  13698. root.parentNode.insertBefore(tempElm, root);
  13699. }
  13700. rng.setStartBefore(root);
  13701. rng.setEndBefore(root);
  13702. } else {
  13703. rng.setStartAfter(root);
  13704. rng.setEndAfter(root);
  13705. }
  13706. } else {
  13707. rng.setStart(root, 0);
  13708. rng.setEnd(root, 0);
  13709. }
  13710. }
  13711. selection.setRng(rng);
  13712. // Remove tempElm created for old IE:s
  13713. dom.remove(tempElm);
  13714. viewPort = dom.getViewPort(editor.getWin());
  13715. // 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
  13716. y = dom.getPos(root).y;
  13717. if (y < viewPort.y || y + 25 > viewPort.y + viewPort.h) {
  13718. editor.getWin().scrollTo(0, y < viewPort.y ? y : y - viewPort.h + 25); // Needs to be hardcoded to roughly one line of text if a huge text block is broken into two blocks
  13719. }
  13720. };
  13721. // Creates a new block element by cloning the current one or creating a new one if the name is specified
  13722. // This function will also copy any text formatting from the parent block and add it to the new one
  13723. function createNewBlock(name) {
  13724. var node = container, block, clonedNode, caretNode;
  13725. block = name || parentBlockName == "TABLE" ? dom.create(name || newBlockName) : parentBlock.cloneNode(false);
  13726. caretNode = block;
  13727. // Clone any parent styles
  13728. if (settings.keep_styles !== false) {
  13729. do {
  13730. if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(node.nodeName)) {
  13731. // Never clone a caret containers
  13732. if (node.id == '_mce_caret') {
  13733. continue;
  13734. }
  13735. clonedNode = node.cloneNode(false);
  13736. dom.setAttrib(clonedNode, 'id', ''); // Remove ID since it needs to be document unique
  13737. if (block.hasChildNodes()) {
  13738. clonedNode.appendChild(block.firstChild);
  13739. block.appendChild(clonedNode);
  13740. } else {
  13741. caretNode = clonedNode;
  13742. block.appendChild(clonedNode);
  13743. }
  13744. }
  13745. } while (node = node.parentNode);
  13746. }
  13747. // BR is needed in empty blocks on non IE browsers
  13748. if (!tinymce.isIE) {
  13749. caretNode.innerHTML = '<br data-mce-bogus="1">';
  13750. }
  13751. return block;
  13752. };
  13753. // Returns true/false if the caret is at the start/end of the parent block element
  13754. function isCaretAtStartOrEndOfBlock(start) {
  13755. var walker, node, name;
  13756. // Caret is in the middle of a text node like "a|b"
  13757. if (container.nodeType == 3 && (start ? offset > 0 : offset < container.nodeValue.length)) {
  13758. return false;
  13759. }
  13760. // If after the last element in block node edge case for #5091
  13761. if (container.parentNode == parentBlock && isAfterLastNodeInContainer && !start) {
  13762. return true;
  13763. }
  13764. // If the caret if before the first element in parentBlock
  13765. if (start && container.nodeType == 1 && container == parentBlock.firstChild) {
  13766. return true;
  13767. }
  13768. // Caret can be before/after a table
  13769. if (container.nodeName === "TABLE" || (container.previousSibling && container.previousSibling.nodeName == "TABLE")) {
  13770. return (isAfterLastNodeInContainer && !start) || (!isAfterLastNodeInContainer && start);
  13771. }
  13772. // Walk the DOM and look for text nodes or non empty elements
  13773. walker = new TreeWalker(container, parentBlock);
  13774. // If caret is in beginning or end of a text block then jump to the next/previous node
  13775. if (container.nodeType == 3) {
  13776. if (start && offset == 0) {
  13777. walker.prev();
  13778. } else if (!start && offset == container.nodeValue.length) {
  13779. walker.next();
  13780. }
  13781. }
  13782. while (node = walker.current()) {
  13783. if (node.nodeType === 1) {
  13784. // Ignore bogus elements
  13785. if (!node.getAttribute('data-mce-bogus')) {
  13786. // Keep empty elements like <img /> <input /> but not trailing br:s like <p>text|<br></p>
  13787. name = node.nodeName.toLowerCase();
  13788. if (nonEmptyElementsMap[name] && name !== 'br') {
  13789. return false;
  13790. }
  13791. }
  13792. } else if (node.nodeType === 3 && !/^[ \t\r\n]*$/.test(node.nodeValue)) {
  13793. return false;
  13794. }
  13795. if (start) {
  13796. walker.prev();
  13797. } else {
  13798. walker.next();
  13799. }
  13800. }
  13801. return true;
  13802. };
  13803. // Wraps any text nodes or inline elements in the specified forced root block name
  13804. function wrapSelfAndSiblingsInDefaultBlock(container, offset) {
  13805. var newBlock, parentBlock, startNode, node, next, blockName = newBlockName || 'P';
  13806. // Not in a block element or in a table cell or caption
  13807. parentBlock = dom.getParent(container, dom.isBlock);
  13808. if (!parentBlock || !canSplitBlock(parentBlock)) {
  13809. parentBlock = parentBlock || editableRoot;
  13810. if (!parentBlock.hasChildNodes()) {
  13811. newBlock = dom.create(blockName);
  13812. parentBlock.appendChild(newBlock);
  13813. rng.setStart(newBlock, 0);
  13814. rng.setEnd(newBlock, 0);
  13815. return newBlock;
  13816. }
  13817. // Find parent that is the first child of parentBlock
  13818. node = container;
  13819. while (node.parentNode != parentBlock) {
  13820. node = node.parentNode;
  13821. }
  13822. // Loop left to find start node start wrapping at
  13823. while (node && !dom.isBlock(node)) {
  13824. startNode = node;
  13825. node = node.previousSibling;
  13826. }
  13827. if (startNode) {
  13828. newBlock = dom.create(blockName);
  13829. startNode.parentNode.insertBefore(newBlock, startNode);
  13830. // Start wrapping until we hit a block
  13831. node = startNode;
  13832. while (node && !dom.isBlock(node)) {
  13833. next = node.nextSibling;
  13834. newBlock.appendChild(node);
  13835. node = next;
  13836. }
  13837. // Restore range to it's past location
  13838. rng.setStart(container, offset);
  13839. rng.setEnd(container, offset);
  13840. }
  13841. }
  13842. return container;
  13843. };
  13844. // Inserts a block or br before/after or in the middle of a split list of the LI is empty
  13845. function handleEmptyListItem() {
  13846. function isFirstOrLastLi(first) {
  13847. var node = containerBlock[first ? 'firstChild' : 'lastChild'];
  13848. // Find first/last element since there might be whitespace there
  13849. while (node) {
  13850. if (node.nodeType == 1) {
  13851. break;
  13852. }
  13853. node = node[first ? 'nextSibling' : 'previousSibling'];
  13854. }
  13855. return node === parentBlock;
  13856. };
  13857. newBlock = newBlockName ? createNewBlock(newBlockName) : dom.create('BR');
  13858. if (isFirstOrLastLi(true) && isFirstOrLastLi()) {
  13859. // Is first and last list item then replace the OL/UL with a text block
  13860. dom.replace(newBlock, containerBlock);
  13861. } else if (isFirstOrLastLi(true)) {
  13862. // First LI in list then remove LI and add text block before list
  13863. containerBlock.parentNode.insertBefore(newBlock, containerBlock);
  13864. } else if (isFirstOrLastLi()) {
  13865. // Last LI in list then temove LI and add text block after list
  13866. dom.insertAfter(newBlock, containerBlock);
  13867. renderBlockOnIE(newBlock);
  13868. } else {
  13869. // Middle LI in list the split the list and insert a text block in the middle
  13870. // Extract after fragment and insert it after the current block
  13871. tmpRng = rng.cloneRange();
  13872. tmpRng.setStartAfter(parentBlock);
  13873. tmpRng.setEndAfter(containerBlock);
  13874. fragment = tmpRng.extractContents();
  13875. dom.insertAfter(fragment, containerBlock);
  13876. dom.insertAfter(newBlock, containerBlock);
  13877. }
  13878. dom.remove(parentBlock);
  13879. moveToCaretPosition(newBlock);
  13880. undoManager.add();
  13881. };
  13882. // Walks the parent block to the right and look for BR elements
  13883. function hasRightSideBr() {
  13884. var walker = new TreeWalker(container, parentBlock), node;
  13885. while (node = walker.current()) {
  13886. if (node.nodeName == 'BR') {
  13887. return true;
  13888. }
  13889. node = walker.next();
  13890. }
  13891. }
  13892. // Inserts a BR element if the forced_root_block option is set to false or empty string
  13893. function insertBr() {
  13894. var brElm, extraBr, marker;
  13895. if (container && container.nodeType == 3 && offset >= container.nodeValue.length) {
  13896. // Insert extra BR element at the end block elements
  13897. if (!tinymce.isIE && !hasRightSideBr()) {
  13898. brElm = dom.create('br');
  13899. rng.insertNode(brElm);
  13900. rng.setStartAfter(brElm);
  13901. rng.setEndAfter(brElm);
  13902. extraBr = true;
  13903. }
  13904. }
  13905. brElm = dom.create('br');
  13906. rng.insertNode(brElm);
  13907. // Rendering modes below IE8 doesn't display BR elements in PRE unless we have a \n before it
  13908. if (tinymce.isIE && parentBlockName == 'PRE' && (!documentMode || documentMode < 8)) {
  13909. brElm.parentNode.insertBefore(dom.doc.createTextNode('\r'), brElm);
  13910. }
  13911. // Insert temp marker and scroll to that
  13912. marker = dom.create('span', {}, '&nbsp;');
  13913. brElm.parentNode.insertBefore(marker, brElm);
  13914. selection.scrollIntoView(marker);
  13915. dom.remove(marker);
  13916. if (!extraBr) {
  13917. rng.setStartAfter(brElm);
  13918. rng.setEndAfter(brElm);
  13919. } else {
  13920. rng.setStartBefore(brElm);
  13921. rng.setEndBefore(brElm);
  13922. }
  13923. selection.setRng(rng);
  13924. undoManager.add();
  13925. };
  13926. // Trims any linebreaks at the beginning of node user for example when pressing enter in a PRE element
  13927. function trimLeadingLineBreaks(node) {
  13928. do {
  13929. if (node.nodeType === 3) {
  13930. node.nodeValue = node.nodeValue.replace(/^[\r\n]+/, '');
  13931. }
  13932. node = node.firstChild;
  13933. } while (node);
  13934. };
  13935. function getEditableRoot(node) {
  13936. var root = dom.getRoot(), parent, editableRoot;
  13937. // Get all parents until we hit a non editable parent or the root
  13938. parent = node;
  13939. while (parent !== root && dom.getContentEditable(parent) !== "false") {
  13940. if (dom.getContentEditable(parent) === "true") {
  13941. editableRoot = parent;
  13942. }
  13943. parent = parent.parentNode;
  13944. }
  13945. return parent !== root ? editableRoot : root;
  13946. };
  13947. // Adds a BR at the end of blocks that only contains an IMG or INPUT since these might be floated and then they won't expand the block
  13948. function addBrToBlockIfNeeded(block) {
  13949. var lastChild;
  13950. // IE will render the blocks correctly other browsers needs a BR
  13951. if (!tinymce.isIE) {
  13952. block.normalize(); // Remove empty text nodes that got left behind by the extract
  13953. // Check if the block is empty or contains a floated last child
  13954. lastChild = block.lastChild;
  13955. if (!lastChild || (/^(left|right)$/gi.test(dom.getStyle(lastChild, 'float', true)))) {
  13956. dom.add(block, 'br');
  13957. }
  13958. }
  13959. };
  13960. // Delete any selected contents
  13961. if (!rng.collapsed) {
  13962. editor.execCommand('Delete');
  13963. return;
  13964. }
  13965. // Event is blocked by some other handler for example the lists plugin
  13966. if (evt.isDefaultPrevented()) {
  13967. return;
  13968. }
  13969. // Setup range items and newBlockName
  13970. container = rng.startContainer;
  13971. offset = rng.startOffset;
  13972. newBlockName = (settings.force_p_newlines ? 'p' : '') || settings.forced_root_block;
  13973. newBlockName = newBlockName ? newBlockName.toUpperCase() : '';
  13974. documentMode = dom.doc.documentMode;
  13975. shiftKey = evt.shiftKey;
  13976. // Resolve node index
  13977. if (container.nodeType == 1 && container.hasChildNodes()) {
  13978. isAfterLastNodeInContainer = offset > container.childNodes.length - 1;
  13979. container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container;
  13980. if (isAfterLastNodeInContainer && container.nodeType == 3) {
  13981. offset = container.nodeValue.length;
  13982. } else {
  13983. offset = 0;
  13984. }
  13985. }
  13986. // Get editable root node normaly the body element but sometimes a div or span
  13987. editableRoot = getEditableRoot(container);
  13988. // If there is no editable root then enter is done inside a contentEditable false element
  13989. if (!editableRoot) {
  13990. return;
  13991. }
  13992. undoManager.beforeChange();
  13993. // If editable root isn't block nor the root of the editor
  13994. if (!dom.isBlock(editableRoot) && editableRoot != dom.getRoot()) {
  13995. if (!newBlockName || shiftKey) {
  13996. insertBr();
  13997. }
  13998. return;
  13999. }
  14000. // Wrap the current node and it's sibling in a default block if it's needed.
  14001. // for example this <td>text|<b>text2</b></td> will become this <td><p>text|<b>text2</p></b></td>
  14002. // This won't happen if root blocks are disabled or the shiftKey is pressed
  14003. if ((newBlockName && !shiftKey) || (!newBlockName && shiftKey)) {
  14004. container = wrapSelfAndSiblingsInDefaultBlock(container, offset);
  14005. }
  14006. // Find parent block and setup empty block paddings
  14007. parentBlock = dom.getParent(container, dom.isBlock);
  14008. containerBlock = parentBlock ? dom.getParent(parentBlock.parentNode, dom.isBlock) : null;
  14009. // Setup block names
  14010. parentBlockName = parentBlock ? parentBlock.nodeName.toUpperCase() : ''; // IE < 9 & HTML5
  14011. containerBlockName = containerBlock ? containerBlock.nodeName.toUpperCase() : ''; // IE < 9 & HTML5
  14012. // Enter inside block contained within a LI then split or insert before/after LI
  14013. if (containerBlockName == 'LI' && !evt.ctrlKey) {
  14014. parentBlock = containerBlock;
  14015. parentBlockName = containerBlockName;
  14016. }
  14017. // Handle enter in LI
  14018. if (parentBlockName == 'LI') {
  14019. if (!newBlockName && shiftKey) {
  14020. insertBr();
  14021. return;
  14022. }
  14023. // Handle enter inside an empty list item
  14024. if (dom.isEmpty(parentBlock)) {
  14025. // Let the list plugin or browser handle nested lists for now
  14026. if (/^(UL|OL|LI)$/.test(containerBlock.parentNode.nodeName)) {
  14027. return false;
  14028. }
  14029. handleEmptyListItem();
  14030. return;
  14031. }
  14032. }
  14033. // Don't split PRE tags but insert a BR instead easier when writing code samples etc
  14034. if (parentBlockName == 'PRE' && settings.br_in_pre !== false) {
  14035. if (!shiftKey) {
  14036. insertBr();
  14037. return;
  14038. }
  14039. } else {
  14040. // If no root block is configured then insert a BR by default or if the shiftKey is pressed
  14041. if ((!newBlockName && !shiftKey && parentBlockName != 'LI') || (newBlockName && shiftKey)) {
  14042. insertBr();
  14043. return;
  14044. }
  14045. }
  14046. // Default block name if it's not configured
  14047. newBlockName = newBlockName || 'P';
  14048. // Insert new block before/after the parent block depending on caret location
  14049. if (isCaretAtStartOrEndOfBlock()) {
  14050. // If the caret is at the end of a header we produce a P tag after it similar to Word unless we are in a hgroup
  14051. if (/^(H[1-6]|PRE)$/.test(parentBlockName) && containerBlockName != 'HGROUP') {
  14052. newBlock = createNewBlock(newBlockName);
  14053. } else {
  14054. newBlock = createNewBlock();
  14055. }
  14056. // Split the current container block element if enter is pressed inside an empty inner block element
  14057. if (settings.end_container_on_empty_block && canSplitBlock(containerBlock) && dom.isEmpty(parentBlock)) {
  14058. // Split container block for example a BLOCKQUOTE at the current blockParent location for example a P
  14059. newBlock = dom.split(containerBlock, parentBlock);
  14060. } else {
  14061. dom.insertAfter(newBlock, parentBlock);
  14062. }
  14063. moveToCaretPosition(newBlock);
  14064. } else if (isCaretAtStartOrEndOfBlock(true)) {
  14065. // Insert new block before
  14066. newBlock = parentBlock.parentNode.insertBefore(createNewBlock(), parentBlock);
  14067. renderBlockOnIE(newBlock);
  14068. } else {
  14069. // Extract after fragment and insert it after the current block
  14070. tmpRng = rng.cloneRange();
  14071. tmpRng.setEndAfter(parentBlock);
  14072. fragment = tmpRng.extractContents();
  14073. trimLeadingLineBreaks(fragment);
  14074. newBlock = fragment.firstChild;
  14075. dom.insertAfter(fragment, parentBlock);
  14076. trimInlineElementsOnLeftSideOfBlock(newBlock);
  14077. addBrToBlockIfNeeded(parentBlock);
  14078. moveToCaretPosition(newBlock);
  14079. }
  14080. dom.setAttrib(newBlock, 'id', ''); // Remove ID since it needs to be document unique
  14081. undoManager.add();
  14082. }
  14083. editor.onKeyDown.add(function(ed, evt) {
  14084. if (evt.keyCode == 13) {
  14085. if (handleEnterKey(evt) !== false) {
  14086. evt.preventDefault();
  14087. }
  14088. }
  14089. });
  14090. };
  14091. })(tinymce);